aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "ci/ciMethodType.hpp" aoqi@0: #include "ci/ciSignature.hpp" aoqi@0: #include "ci/ciUtilities.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "runtime/signature.hpp" aoqi@0: aoqi@0: // ciSignature aoqi@0: // aoqi@0: // This class represents the signature of a method. aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::ciSignature aoqi@0: ciSignature::ciSignature(ciKlass* accessing_klass, constantPoolHandle cpool, ciSymbol* symbol) { aoqi@0: ASSERT_IN_VM; aoqi@0: EXCEPTION_CONTEXT; aoqi@0: _accessing_klass = accessing_klass; aoqi@0: _symbol = symbol; aoqi@0: aoqi@0: ciEnv* env = CURRENT_ENV; aoqi@0: Arena* arena = env->arena(); aoqi@0: _types = new (arena) GrowableArray(arena, 8, 0, NULL); aoqi@0: aoqi@0: int size = 0; aoqi@0: int count = 0; aoqi@0: ResourceMark rm(THREAD); aoqi@0: Symbol* sh = symbol->get_symbol(); aoqi@0: SignatureStream ss(sh); aoqi@0: for (; ; ss.next()) { aoqi@0: // Process one element of the signature aoqi@0: ciType* type; aoqi@0: if (!ss.is_object()) { aoqi@0: type = ciType::make(ss.type()); aoqi@0: } else { aoqi@0: Symbol* name = ss.as_symbol(THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass() aoqi@0: : (ciType*)ciEnv::unloaded_ciinstance_klass(); aoqi@0: env->record_out_of_memory_failure(); aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } else { aoqi@0: ciSymbol* klass_name = env->get_symbol(name); aoqi@0: type = env->get_klass_by_name_impl(_accessing_klass, cpool, klass_name, false); aoqi@0: } aoqi@0: } aoqi@0: _types->append(type); aoqi@0: if (ss.at_return_type()) { aoqi@0: // Done processing the return type; do not add it into the count. aoqi@0: break; aoqi@0: } aoqi@0: size += type->size(); aoqi@0: count++; aoqi@0: } aoqi@0: _size = size; aoqi@0: _count = count; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::ciSignature aoqi@0: ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol, ciMethodType* method_type) : aoqi@0: _symbol(symbol), aoqi@0: _accessing_klass(accessing_klass), aoqi@0: _size( method_type->ptype_slot_count()), aoqi@0: _count(method_type->ptype_count()) aoqi@0: { aoqi@0: ASSERT_IN_VM; aoqi@0: EXCEPTION_CONTEXT; aoqi@0: Arena* arena = CURRENT_ENV->arena(); aoqi@0: _types = new (arena) GrowableArray(arena, _count + 1, 0, NULL); aoqi@0: for (int i = 0; i < _count; i++) { aoqi@0: _types->append(method_type->ptype_at(i)); aoqi@0: } aoqi@0: _types->append(method_type->rtype()); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::return_type aoqi@0: // aoqi@0: // What is the return type of this signature? aoqi@0: ciType* ciSignature::return_type() const { aoqi@0: return _types->at(_count); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::type_at aoqi@0: // aoqi@0: // What is the type of the index'th element of this aoqi@0: // signature? aoqi@0: ciType* ciSignature::type_at(int index) const { aoqi@0: assert(index < _count, "out of bounds"); aoqi@0: // The first _klasses element holds the return klass. aoqi@0: return _types->at(index); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::equals aoqi@0: // aoqi@0: // Compare this signature to another one. Signatures with different aoqi@0: // accessing classes but with signature-types resolved to the same aoqi@0: // types are defined to be equal. aoqi@0: bool ciSignature::equals(ciSignature* that) { aoqi@0: // Compare signature aoqi@0: if (!this->as_symbol()->equals(that->as_symbol())) return false; aoqi@0: // Compare all types of the arguments aoqi@0: for (int i = 0; i < _count; i++) { aoqi@0: if (this->type_at(i) != that->type_at(i)) return false; aoqi@0: } aoqi@0: // Compare the return type aoqi@0: if (this->return_type() != that->return_type()) return false; aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::print_signature aoqi@0: void ciSignature::print_signature() { aoqi@0: _symbol->print_symbol(); aoqi@0: } aoqi@0: aoqi@0: // ------------------------------------------------------------------ aoqi@0: // ciSignature::print aoqi@0: void ciSignature::print() { aoqi@0: tty->print("", p2i((address)this)); aoqi@0: }