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