duke@435: /* duke@435: * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_ciSignature.cpp.incl" duke@435: duke@435: // ciSignature duke@435: // duke@435: // This class represents the signature of a method. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSignature::ciSignature duke@435: ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol) { duke@435: ASSERT_IN_VM; duke@435: EXCEPTION_CONTEXT; duke@435: _accessing_klass = accessing_klass; duke@435: _symbol = symbol; duke@435: duke@435: ciEnv* env = CURRENT_ENV; duke@435: Arena* arena = env->arena(); duke@435: _types = new (arena) GrowableArray(arena, 8, 0, NULL); duke@435: duke@435: int size = 0; duke@435: int count = 0; duke@435: symbolHandle sh (THREAD, symbol->get_symbolOop()); duke@435: SignatureStream ss(sh); duke@435: for (; ; ss.next()) { duke@435: // Process one element of the signature duke@435: ciType* type; duke@435: if (!ss.is_object()) { duke@435: type = ciType::make(ss.type()); duke@435: } else { duke@435: symbolOop name = ss.as_symbol(THREAD); duke@435: if (HAS_PENDING_EXCEPTION) { duke@435: type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass() duke@435: : (ciType*)ciEnv::unloaded_ciinstance_klass(); duke@435: env->record_out_of_memory_failure(); duke@435: CLEAR_PENDING_EXCEPTION; duke@435: } else { duke@435: ciSymbol* klass_name = env->get_object(name)->as_symbol(); duke@435: type = env->get_klass_by_name_impl(_accessing_klass, klass_name, false); duke@435: } duke@435: } duke@435: _types->append(type); duke@435: if (ss.at_return_type()) { duke@435: // Done processing the return type; do not add it into the count. duke@435: break; duke@435: } duke@435: size += type->size(); duke@435: count++; duke@435: } duke@435: _size = size; duke@435: _count = count; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSignature::return_ciType duke@435: // duke@435: // What is the return type of this signature? duke@435: ciType* ciSignature::return_type() const { duke@435: return _types->at(_count); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSignature::ciType_at duke@435: // duke@435: // What is the type of the index'th element of this duke@435: // signature? duke@435: ciType* ciSignature::type_at(int index) const { duke@435: assert(index < _count, "out of bounds"); duke@435: // The first _klasses element holds the return klass. duke@435: return _types->at(index); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSignature::print_signature duke@435: void ciSignature::print_signature() { duke@435: _symbol->print_symbol(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciSignature::print duke@435: void ciSignature::print() { duke@435: tty->print("", (address)this); duke@435: }