Wed, 06 Jan 2010 14:22:39 -0800
6914300: ciEnv should export all well known classes
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_ciType.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | ciType* ciType::_basic_types[T_CONFLICT+1]; |
duke@435 | 29 | |
duke@435 | 30 | // ciType |
duke@435 | 31 | // |
duke@435 | 32 | // This class represents either a class (T_OBJECT), array (T_ARRAY), |
duke@435 | 33 | // or one of the primitive types such as T_INT. |
duke@435 | 34 | |
duke@435 | 35 | // ------------------------------------------------------------------ |
duke@435 | 36 | // ciType::ciType |
duke@435 | 37 | // |
duke@435 | 38 | ciType::ciType(BasicType basic_type) : ciObject() { |
duke@435 | 39 | assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check"); |
duke@435 | 40 | assert(basic_type != T_OBJECT && basic_type != T_ARRAY, "not a reference type"); |
duke@435 | 41 | _basic_type = basic_type; |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | ciType::ciType(KlassHandle k) : ciObject(k) { |
duke@435 | 45 | _basic_type = Klass::cast(k())->oop_is_array() ? T_ARRAY : T_OBJECT; |
duke@435 | 46 | } |
duke@435 | 47 | |
duke@435 | 48 | ciType::ciType(ciKlass* klass) : ciObject(klass) { |
duke@435 | 49 | _basic_type = klass->is_array_klass_klass() ? T_ARRAY : T_OBJECT; |
duke@435 | 50 | } |
duke@435 | 51 | |
duke@435 | 52 | |
duke@435 | 53 | // ------------------------------------------------------------------ |
duke@435 | 54 | // ciType::is_subtype_of |
duke@435 | 55 | // |
duke@435 | 56 | bool ciType::is_subtype_of(ciType* type) { |
duke@435 | 57 | if (this == type) return true; |
duke@435 | 58 | if (is_klass() && type->is_klass()) |
duke@435 | 59 | return this->as_klass()->is_subtype_of(type->as_klass()); |
duke@435 | 60 | return false; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | // ------------------------------------------------------------------ |
duke@435 | 64 | // ciType::print_impl |
duke@435 | 65 | // |
duke@435 | 66 | // Implementation of the print method. |
duke@435 | 67 | void ciType::print_impl(outputStream* st) { |
duke@435 | 68 | st->print(" type="); |
duke@435 | 69 | print_name_on(st); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | // ------------------------------------------------------------------ |
duke@435 | 73 | // ciType::print_name |
duke@435 | 74 | // |
duke@435 | 75 | // Print the name of this type |
duke@435 | 76 | void ciType::print_name_on(outputStream* st) { |
duke@435 | 77 | st->print(type2name(basic_type())); |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | |
duke@435 | 81 | |
duke@435 | 82 | // ------------------------------------------------------------------ |
duke@435 | 83 | // ciType::java_mirror |
duke@435 | 84 | // |
duke@435 | 85 | ciInstance* ciType::java_mirror() { |
duke@435 | 86 | VM_ENTRY_MARK; |
duke@435 | 87 | return CURRENT_THREAD_ENV->get_object(Universe::java_mirror(basic_type()))->as_instance(); |
duke@435 | 88 | } |
duke@435 | 89 | |
duke@435 | 90 | // ------------------------------------------------------------------ |
duke@435 | 91 | // ciType::box_klass |
duke@435 | 92 | // |
duke@435 | 93 | ciKlass* ciType::box_klass() { |
duke@435 | 94 | if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" |
duke@435 | 95 | |
duke@435 | 96 | // Void is "boxed" with a null. |
duke@435 | 97 | if (basic_type() == T_VOID) return NULL; |
duke@435 | 98 | |
duke@435 | 99 | VM_ENTRY_MARK; |
duke@435 | 100 | return CURRENT_THREAD_ENV->get_object(SystemDictionary::box_klass(basic_type()))->as_instance_klass(); |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | |
duke@435 | 104 | // ------------------------------------------------------------------ |
duke@435 | 105 | // ciType::make |
duke@435 | 106 | // |
duke@435 | 107 | // Produce the ciType for a given primitive BasicType. |
duke@435 | 108 | // As a bonus, produce the right reference type for T_OBJECT. |
duke@435 | 109 | // Does not work on T_ARRAY. |
duke@435 | 110 | ciType* ciType::make(BasicType t) { |
duke@435 | 111 | // short, etc. |
duke@435 | 112 | // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. |
duke@435 | 113 | assert((uint)t < T_CONFLICT+1, "range check"); |
never@1577 | 114 | if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object |
duke@435 | 115 | assert(_basic_types[t] != NULL, "domain check"); |
duke@435 | 116 | return _basic_types[t]; |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // ciReturnAddress |
duke@435 | 120 | // |
duke@435 | 121 | // This class represents the type of a specific return address in the |
duke@435 | 122 | // bytecodes. |
duke@435 | 123 | |
duke@435 | 124 | // ------------------------------------------------------------------ |
duke@435 | 125 | // ciReturnAddress::ciReturnAddress |
duke@435 | 126 | // |
duke@435 | 127 | ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { |
duke@435 | 128 | assert(0 <= bci, "bci cannot be negative"); |
duke@435 | 129 | _bci = bci; |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | // ------------------------------------------------------------------ |
duke@435 | 133 | // ciReturnAddress::print_impl |
duke@435 | 134 | // |
duke@435 | 135 | // Implementation of the print method. |
duke@435 | 136 | void ciReturnAddress::print_impl(outputStream* st) { |
duke@435 | 137 | st->print(" bci=%d", _bci); |
duke@435 | 138 | } |
duke@435 | 139 | |
duke@435 | 140 | // ------------------------------------------------------------------ |
duke@435 | 141 | // ciReturnAddress::make |
duke@435 | 142 | ciReturnAddress* ciReturnAddress::make(int bci) { |
duke@435 | 143 | GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) |
duke@435 | 144 | } |