Wed, 12 Oct 2011 21:00:13 -0700
7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
Reviewed-by: jrose, never
duke@435 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "ci/ciType.hpp" |
stefank@2314 | 27 | #include "ci/ciUtilities.hpp" |
stefank@2314 | 28 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 29 | #include "oops/oop.inline.hpp" |
duke@435 | 30 | |
duke@435 | 31 | ciType* ciType::_basic_types[T_CONFLICT+1]; |
duke@435 | 32 | |
duke@435 | 33 | // ciType |
duke@435 | 34 | // |
duke@435 | 35 | // This class represents either a class (T_OBJECT), array (T_ARRAY), |
duke@435 | 36 | // or one of the primitive types such as T_INT. |
duke@435 | 37 | |
duke@435 | 38 | // ------------------------------------------------------------------ |
duke@435 | 39 | // ciType::ciType |
duke@435 | 40 | // |
duke@435 | 41 | ciType::ciType(BasicType basic_type) : ciObject() { |
duke@435 | 42 | assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check"); |
duke@435 | 43 | assert(basic_type != T_OBJECT && basic_type != T_ARRAY, "not a reference type"); |
duke@435 | 44 | _basic_type = basic_type; |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | ciType::ciType(KlassHandle k) : ciObject(k) { |
duke@435 | 48 | _basic_type = Klass::cast(k())->oop_is_array() ? T_ARRAY : T_OBJECT; |
duke@435 | 49 | } |
duke@435 | 50 | |
duke@435 | 51 | ciType::ciType(ciKlass* klass) : ciObject(klass) { |
duke@435 | 52 | _basic_type = klass->is_array_klass_klass() ? T_ARRAY : T_OBJECT; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | |
duke@435 | 56 | // ------------------------------------------------------------------ |
duke@435 | 57 | // ciType::is_subtype_of |
duke@435 | 58 | // |
duke@435 | 59 | bool ciType::is_subtype_of(ciType* type) { |
duke@435 | 60 | if (this == type) return true; |
duke@435 | 61 | if (is_klass() && type->is_klass()) |
duke@435 | 62 | return this->as_klass()->is_subtype_of(type->as_klass()); |
duke@435 | 63 | return false; |
duke@435 | 64 | } |
duke@435 | 65 | |
duke@435 | 66 | // ------------------------------------------------------------------ |
duke@435 | 67 | // ciType::print_impl |
duke@435 | 68 | // |
duke@435 | 69 | // Implementation of the print method. |
duke@435 | 70 | void ciType::print_impl(outputStream* st) { |
duke@435 | 71 | st->print(" type="); |
duke@435 | 72 | print_name_on(st); |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | // ------------------------------------------------------------------ |
duke@435 | 76 | // ciType::print_name |
duke@435 | 77 | // |
duke@435 | 78 | // Print the name of this type |
duke@435 | 79 | void ciType::print_name_on(outputStream* st) { |
duke@435 | 80 | st->print(type2name(basic_type())); |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | |
duke@435 | 84 | |
duke@435 | 85 | // ------------------------------------------------------------------ |
duke@435 | 86 | // ciType::java_mirror |
duke@435 | 87 | // |
duke@435 | 88 | ciInstance* ciType::java_mirror() { |
duke@435 | 89 | VM_ENTRY_MARK; |
duke@435 | 90 | return CURRENT_THREAD_ENV->get_object(Universe::java_mirror(basic_type()))->as_instance(); |
duke@435 | 91 | } |
duke@435 | 92 | |
duke@435 | 93 | // ------------------------------------------------------------------ |
duke@435 | 94 | // ciType::box_klass |
duke@435 | 95 | // |
duke@435 | 96 | ciKlass* ciType::box_klass() { |
duke@435 | 97 | if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" |
duke@435 | 98 | |
duke@435 | 99 | // Void is "boxed" with a null. |
duke@435 | 100 | if (basic_type() == T_VOID) return NULL; |
duke@435 | 101 | |
duke@435 | 102 | VM_ENTRY_MARK; |
duke@435 | 103 | return CURRENT_THREAD_ENV->get_object(SystemDictionary::box_klass(basic_type()))->as_instance_klass(); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | |
duke@435 | 107 | // ------------------------------------------------------------------ |
duke@435 | 108 | // ciType::make |
duke@435 | 109 | // |
duke@435 | 110 | // Produce the ciType for a given primitive BasicType. |
duke@435 | 111 | // As a bonus, produce the right reference type for T_OBJECT. |
duke@435 | 112 | // Does not work on T_ARRAY. |
duke@435 | 113 | ciType* ciType::make(BasicType t) { |
duke@435 | 114 | // short, etc. |
duke@435 | 115 | // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. |
duke@435 | 116 | assert((uint)t < T_CONFLICT+1, "range check"); |
never@1577 | 117 | if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object |
duke@435 | 118 | assert(_basic_types[t] != NULL, "domain check"); |
duke@435 | 119 | return _basic_types[t]; |
duke@435 | 120 | } |
duke@435 | 121 | |
duke@435 | 122 | // ciReturnAddress |
duke@435 | 123 | // |
duke@435 | 124 | // This class represents the type of a specific return address in the |
duke@435 | 125 | // bytecodes. |
duke@435 | 126 | |
duke@435 | 127 | // ------------------------------------------------------------------ |
duke@435 | 128 | // ciReturnAddress::ciReturnAddress |
duke@435 | 129 | // |
duke@435 | 130 | ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { |
duke@435 | 131 | assert(0 <= bci, "bci cannot be negative"); |
duke@435 | 132 | _bci = bci; |
duke@435 | 133 | } |
duke@435 | 134 | |
duke@435 | 135 | // ------------------------------------------------------------------ |
duke@435 | 136 | // ciReturnAddress::print_impl |
duke@435 | 137 | // |
duke@435 | 138 | // Implementation of the print method. |
duke@435 | 139 | void ciReturnAddress::print_impl(outputStream* st) { |
duke@435 | 140 | st->print(" bci=%d", _bci); |
duke@435 | 141 | } |
duke@435 | 142 | |
duke@435 | 143 | // ------------------------------------------------------------------ |
duke@435 | 144 | // ciReturnAddress::make |
duke@435 | 145 | ciReturnAddress* ciReturnAddress::make(int bci) { |
duke@435 | 146 | GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) |
duke@435 | 147 | } |