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::name 65 // 66 // Return the name of this type 67 const char* ciType::name() { 68 if (is_primitive_type()) { 69 return type2name(basic_type()); 70 } else { 71 assert(is_klass(), "must be"); 72 return as_klass()->name()->as_utf8(); 73 } 74 } 75 76 // ------------------------------------------------------------------ 77 // ciType::print_impl 78 // 79 // Implementation of the print method. 80 void ciType::print_impl(outputStream* st) { 81 st->print(" type="); 82 print_name_on(st); 83 } 84 85 // ------------------------------------------------------------------ 86 // ciType::print_name 87 // 88 // Print the name of this type 89 void ciType::print_name_on(outputStream* st) { 90 ResourceMark rm; 91 st->print("%s", name()); 92 } 93 94 95 96 // ------------------------------------------------------------------ 97 // ciType::java_mirror 98 // 99 ciInstance* ciType::java_mirror() { 100 VM_ENTRY_MARK; 101 return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type())); 102 } 103 104 // ------------------------------------------------------------------ 105 // ciType::box_klass 106 // 107 ciKlass* ciType::box_klass() { 108 assert(basic_type() != T_VALUETYPE, "value type boxing not yet supported"); 109 if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" 110 111 // Void is "boxed" with a null. 112 if (basic_type() == T_VOID) return NULL; 113 114 VM_ENTRY_MARK; 115 return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type())); 116 } 117 118 119 // ------------------------------------------------------------------ 120 // ciType::make 121 // 122 // Produce the ciType for a given primitive BasicType. 123 // As a bonus, produce the right reference type for T_OBJECT. 124 // Does not work on T_ARRAY. 125 ciType* ciType::make(BasicType t) { 126 // short, etc. 127 // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. 128 assert((uint)t < T_CONFLICT+1, "range check"); 129 if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object 130 assert(_basic_types[t] != NULL, "domain check"); 131 return _basic_types[t]; 132 } 133 134 // ciReturnAddress 135 // 136 // This class represents the type of a specific return address in the 137 // bytecodes. 138 139 // ------------------------------------------------------------------ 140 // ciReturnAddress::ciReturnAddress 141 // 142 ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { 143 assert(0 <= bci, "bci cannot be negative"); 144 _bci = bci; 145 } 146 147 // ------------------------------------------------------------------ 148 // ciReturnAddress::print_impl 149 // 150 // Implementation of the print method. 151 void ciReturnAddress::print_impl(outputStream* st) { 152 st->print(" bci=%d", _bci); 153 } 154 155 // ------------------------------------------------------------------ 156 // ciReturnAddress::make 157 ciReturnAddress* ciReturnAddress::make(int bci) { 158 GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) 159 }