duke@435: /* trims@2708: * Copyright (c) 1999, 2011, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" twisti@4133: #include "ci/ciMethodType.hpp" stefank@2314: #include "ci/ciSignature.hpp" stefank@2314: #include "ci/ciUtilities.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/signature.hpp" 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 jrose@2982: ciSignature::ciSignature(ciKlass* accessing_klass, constantPoolHandle cpool, 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; coleenp@2497: ResourceMark rm(THREAD); coleenp@2497: Symbol* sh = symbol->get_symbol(); 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 { coleenp@2497: Symbol* 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 { coleenp@2497: ciSymbol* klass_name = env->get_symbol(name); jrose@2982: type = env->get_klass_by_name_impl(_accessing_klass, cpool, 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: // ------------------------------------------------------------------ twisti@4133: // ciSignature::ciSignature twisti@4133: ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol, ciMethodType* method_type) : twisti@4133: _symbol(symbol), twisti@4133: _accessing_klass(accessing_klass), twisti@4133: _size( method_type->ptype_slot_count()), twisti@4133: _count(method_type->ptype_count()) twisti@4133: { twisti@4133: ASSERT_IN_VM; twisti@4133: EXCEPTION_CONTEXT; twisti@4133: Arena* arena = CURRENT_ENV->arena(); twisti@4133: _types = new (arena) GrowableArray(arena, _count + 1, 0, NULL); twisti@4133: for (int i = 0; i < _count; i++) { twisti@4133: _types->append(method_type->ptype_at(i)); twisti@4133: } twisti@4133: _types->append(method_type->rtype()); twisti@4133: } twisti@4133: twisti@4133: // ------------------------------------------------------------------ twisti@3197: // ciSignature::return_type 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: // ------------------------------------------------------------------ twisti@3197: // ciSignature::type_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: // ------------------------------------------------------------------ twisti@3197: // ciSignature::equals twisti@3197: // twisti@3197: // Compare this signature to another one. Signatures with different twisti@3197: // accessing classes but with signature-types resolved to the same twisti@3197: // types are defined to be equal. twisti@3197: bool ciSignature::equals(ciSignature* that) { twisti@3197: // Compare signature twisti@3197: if (!this->as_symbol()->equals(that->as_symbol())) return false; twisti@3197: // Compare all types of the arguments twisti@3197: for (int i = 0; i < _count; i++) { twisti@3197: if (this->type_at(i) != that->type_at(i)) return false; twisti@3197: } twisti@3197: // Compare the return type twisti@3197: if (this->return_type() != that->return_type()) return false; twisti@3197: return true; twisti@3197: } twisti@3197: twisti@3197: // ------------------------------------------------------------------ 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: }