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