Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "ci/ciMethodType.hpp" |
aoqi@0 | 27 | #include "ci/ciSignature.hpp" |
aoqi@0 | 28 | #include "ci/ciUtilities.hpp" |
aoqi@0 | 29 | #include "memory/allocation.inline.hpp" |
aoqi@0 | 30 | #include "oops/oop.inline.hpp" |
aoqi@0 | 31 | #include "runtime/signature.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | // ciSignature |
aoqi@0 | 34 | // |
aoqi@0 | 35 | // This class represents the signature of a method. |
aoqi@0 | 36 | |
aoqi@0 | 37 | // ------------------------------------------------------------------ |
aoqi@0 | 38 | // ciSignature::ciSignature |
aoqi@0 | 39 | ciSignature::ciSignature(ciKlass* accessing_klass, constantPoolHandle cpool, ciSymbol* symbol) { |
aoqi@0 | 40 | ASSERT_IN_VM; |
aoqi@0 | 41 | EXCEPTION_CONTEXT; |
aoqi@0 | 42 | _accessing_klass = accessing_klass; |
aoqi@0 | 43 | _symbol = symbol; |
aoqi@0 | 44 | |
aoqi@0 | 45 | ciEnv* env = CURRENT_ENV; |
aoqi@0 | 46 | Arena* arena = env->arena(); |
aoqi@0 | 47 | _types = new (arena) GrowableArray<ciType*>(arena, 8, 0, NULL); |
aoqi@0 | 48 | |
aoqi@0 | 49 | int size = 0; |
aoqi@0 | 50 | int count = 0; |
aoqi@0 | 51 | ResourceMark rm(THREAD); |
aoqi@0 | 52 | Symbol* sh = symbol->get_symbol(); |
aoqi@0 | 53 | SignatureStream ss(sh); |
aoqi@0 | 54 | for (; ; ss.next()) { |
aoqi@0 | 55 | // Process one element of the signature |
aoqi@0 | 56 | ciType* type; |
aoqi@0 | 57 | if (!ss.is_object()) { |
aoqi@0 | 58 | type = ciType::make(ss.type()); |
aoqi@0 | 59 | } else { |
aoqi@0 | 60 | Symbol* name = ss.as_symbol(THREAD); |
aoqi@0 | 61 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 62 | type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass() |
aoqi@0 | 63 | : (ciType*)ciEnv::unloaded_ciinstance_klass(); |
aoqi@0 | 64 | env->record_out_of_memory_failure(); |
aoqi@0 | 65 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 66 | } else { |
aoqi@0 | 67 | ciSymbol* klass_name = env->get_symbol(name); |
aoqi@0 | 68 | type = env->get_klass_by_name_impl(_accessing_klass, cpool, klass_name, false); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | } |
aoqi@0 | 71 | _types->append(type); |
aoqi@0 | 72 | if (ss.at_return_type()) { |
aoqi@0 | 73 | // Done processing the return type; do not add it into the count. |
aoqi@0 | 74 | break; |
aoqi@0 | 75 | } |
aoqi@0 | 76 | size += type->size(); |
aoqi@0 | 77 | count++; |
aoqi@0 | 78 | } |
aoqi@0 | 79 | _size = size; |
aoqi@0 | 80 | _count = count; |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | // ------------------------------------------------------------------ |
aoqi@0 | 84 | // ciSignature::ciSignature |
aoqi@0 | 85 | ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol, ciMethodType* method_type) : |
aoqi@0 | 86 | _symbol(symbol), |
aoqi@0 | 87 | _accessing_klass(accessing_klass), |
aoqi@0 | 88 | _size( method_type->ptype_slot_count()), |
aoqi@0 | 89 | _count(method_type->ptype_count()) |
aoqi@0 | 90 | { |
aoqi@0 | 91 | ASSERT_IN_VM; |
aoqi@0 | 92 | EXCEPTION_CONTEXT; |
aoqi@0 | 93 | Arena* arena = CURRENT_ENV->arena(); |
aoqi@0 | 94 | _types = new (arena) GrowableArray<ciType*>(arena, _count + 1, 0, NULL); |
aoqi@0 | 95 | for (int i = 0; i < _count; i++) { |
aoqi@0 | 96 | _types->append(method_type->ptype_at(i)); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | _types->append(method_type->rtype()); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | // ------------------------------------------------------------------ |
aoqi@0 | 102 | // ciSignature::return_type |
aoqi@0 | 103 | // |
aoqi@0 | 104 | // What is the return type of this signature? |
aoqi@0 | 105 | ciType* ciSignature::return_type() const { |
aoqi@0 | 106 | return _types->at(_count); |
aoqi@0 | 107 | } |
aoqi@0 | 108 | |
aoqi@0 | 109 | // ------------------------------------------------------------------ |
aoqi@0 | 110 | // ciSignature::type_at |
aoqi@0 | 111 | // |
aoqi@0 | 112 | // What is the type of the index'th element of this |
aoqi@0 | 113 | // signature? |
aoqi@0 | 114 | ciType* ciSignature::type_at(int index) const { |
aoqi@0 | 115 | assert(index < _count, "out of bounds"); |
aoqi@0 | 116 | // The first _klasses element holds the return klass. |
aoqi@0 | 117 | return _types->at(index); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | // ------------------------------------------------------------------ |
aoqi@0 | 121 | // ciSignature::equals |
aoqi@0 | 122 | // |
aoqi@0 | 123 | // Compare this signature to another one. Signatures with different |
aoqi@0 | 124 | // accessing classes but with signature-types resolved to the same |
aoqi@0 | 125 | // types are defined to be equal. |
aoqi@0 | 126 | bool ciSignature::equals(ciSignature* that) { |
aoqi@0 | 127 | // Compare signature |
aoqi@0 | 128 | if (!this->as_symbol()->equals(that->as_symbol())) return false; |
aoqi@0 | 129 | // Compare all types of the arguments |
aoqi@0 | 130 | for (int i = 0; i < _count; i++) { |
aoqi@0 | 131 | if (this->type_at(i) != that->type_at(i)) return false; |
aoqi@0 | 132 | } |
aoqi@0 | 133 | // Compare the return type |
aoqi@0 | 134 | if (this->return_type() != that->return_type()) return false; |
aoqi@0 | 135 | return true; |
aoqi@0 | 136 | } |
aoqi@0 | 137 | |
aoqi@0 | 138 | // ------------------------------------------------------------------ |
aoqi@0 | 139 | // ciSignature::print_signature |
aoqi@0 | 140 | void ciSignature::print_signature() { |
aoqi@0 | 141 | _symbol->print_symbol(); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | // ------------------------------------------------------------------ |
aoqi@0 | 145 | // ciSignature::print |
aoqi@0 | 146 | void ciSignature::print() { |
aoqi@0 | 147 | tty->print("<ciSignature symbol="); |
aoqi@0 | 148 | print_signature(); |
aoqi@0 | 149 | tty->print(" accessing_klass="); |
aoqi@0 | 150 | _accessing_klass->print(); |
aoqi@0 | 151 | tty->print(" address=" INTPTR_FORMAT ">", p2i((address)this)); |
aoqi@0 | 152 | } |