1 /* 2 * Copyright (c) 2000, 2025, 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 "ci/ciEnv.hpp" 26 #include "ci/ciType.hpp" 27 #include "ci/ciUtilities.inline.hpp" 28 #include "memory/resourceArea.hpp" 29 #include "memory/universe.hpp" 30 #include "oops/oop.inline.hpp" 31 32 ciType* ciType::_basic_types[T_CONFLICT+1]; 33 34 // ciType 35 // 36 // This class represents a Java reference, inline type or primitive type. 37 38 // ------------------------------------------------------------------ 39 // ciType::ciType 40 // 41 ciType::ciType(BasicType basic_type) : ciMetadata() { 42 assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check"); 43 _basic_type = basic_type; 44 } 45 46 ciType::ciType(Klass* k) : ciMetadata(k) { 47 _basic_type = k->is_array_klass() ? T_ARRAY : T_OBJECT; 48 } 49 50 51 // ------------------------------------------------------------------ 52 // ciType::is_subtype_of 53 // 54 bool ciType::is_subtype_of(ciType* type) { 55 if (this == type) return true; 56 if (is_klass() && type->is_klass()) 57 return this->as_klass()->is_subtype_of(type->as_klass()); 58 return false; 59 } 60 61 // ------------------------------------------------------------------ 62 // ciType::name 63 // 64 // Return the name of this type 65 const char* ciType::name() { 66 if (is_primitive_type()) { 67 return type2name(basic_type()); 68 } else { 69 assert(is_klass(), "must be"); 70 return as_klass()->name()->as_utf8(); 71 } 72 } 73 74 // ------------------------------------------------------------------ 75 // ciType::print_impl 76 // 77 // Implementation of the print method. 78 void ciType::print_impl(outputStream* st) { 79 st->print(" type="); 80 print_name_on(st); 81 } 82 83 // ------------------------------------------------------------------ 84 // ciType::print_name 85 // 86 // Print the name of this type 87 void ciType::print_name_on(outputStream* st) { 88 ResourceMark rm; 89 st->print("%s", name()); 90 } 91 92 93 94 // ------------------------------------------------------------------ 95 // ciType::java_mirror 96 // 97 ciInstance* ciType::java_mirror() { 98 VM_ENTRY_MARK; 99 return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type())); 100 } 101 102 // ------------------------------------------------------------------ 103 // ciType::make 104 // 105 // Produce the ciType for a given primitive BasicType. 106 // As a bonus, produce the right reference type for T_OBJECT. 107 // Does not work on T_ARRAY. 108 ciType* ciType::make(BasicType t) { 109 // short, etc. 110 // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. 111 assert((uint)t < T_CONFLICT+1, "range check"); 112 if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object 113 assert(_basic_types[t] != nullptr, "domain check"); 114 return _basic_types[t]; 115 } 116 117 // ciReturnAddress 118 // 119 // This class represents the type of a specific return address in the 120 // bytecodes. 121 122 // ------------------------------------------------------------------ 123 // ciReturnAddress::ciReturnAddress 124 // 125 ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { 126 assert(0 <= bci, "bci cannot be negative"); 127 _bci = bci; 128 } 129 130 // ------------------------------------------------------------------ 131 // ciReturnAddress::print_impl 132 // 133 // Implementation of the print method. 134 void ciReturnAddress::print_impl(outputStream* st) { 135 st->print(" bci=%d", _bci); 136 } 137 138 // ------------------------------------------------------------------ 139 // ciReturnAddress::make 140 ciReturnAddress* ciReturnAddress::make(int bci) { 141 GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) 142 }