Tue, 20 Aug 2013 09:37:01 +0200
8022283: Assertion failed: assert(is_loaded() && field->holder()->is_loaded() && klass()->is_subclass_of (field->holder())) failed: invalid access
Reviewed-by: roland, twisti
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1999, 2012, 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/ciConstant.hpp" |
stefank@2314 | 27 | #include "ci/ciField.hpp" |
stefank@2314 | 28 | #include "ci/ciInstance.hpp" |
stefank@2314 | 29 | #include "ci/ciInstanceKlass.hpp" |
stefank@2314 | 30 | #include "ci/ciUtilities.hpp" |
stefank@2314 | 31 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 32 | #include "oops/oop.inline.hpp" |
duke@435 | 33 | |
duke@435 | 34 | // ciInstance |
duke@435 | 35 | // |
duke@435 | 36 | // This class represents an instanceOop in the HotSpot virtual |
duke@435 | 37 | // machine. |
duke@435 | 38 | |
duke@435 | 39 | // ------------------------------------------------------------------ |
duke@435 | 40 | // ciObject::java_mirror_type |
duke@435 | 41 | ciType* ciInstance::java_mirror_type() { |
duke@435 | 42 | VM_ENTRY_MARK; |
duke@435 | 43 | oop m = get_oop(); |
duke@435 | 44 | // Return NULL if it is not java.lang.Class. |
never@1577 | 45 | if (m == NULL || m->klass() != SystemDictionary::Class_klass()) { |
duke@435 | 46 | return NULL; |
duke@435 | 47 | } |
duke@435 | 48 | // Return either a primitive type or a klass. |
duke@435 | 49 | if (java_lang_Class::is_primitive(m)) { |
duke@435 | 50 | return ciType::make(java_lang_Class::primitive_type(m)); |
duke@435 | 51 | } else { |
coleenp@4037 | 52 | Klass* k = java_lang_Class::as_Klass(m); |
duke@435 | 53 | assert(k != NULL, ""); |
coleenp@4037 | 54 | return CURRENT_THREAD_ENV->get_klass(k); |
duke@435 | 55 | } |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | // ------------------------------------------------------------------ |
duke@435 | 59 | // ciInstance::field_value |
duke@435 | 60 | // |
duke@435 | 61 | // Constant value of a field. |
duke@435 | 62 | ciConstant ciInstance::field_value(ciField* field) { |
rbackman@5633 | 63 | assert(is_loaded(), "invalid access - must be loaded"); |
rbackman@5633 | 64 | assert(field->holder()->is_loaded(), "invalid access - holder must be loaded"); |
rbackman@5633 | 65 | assert(klass()->is_subclass_of(field->holder()), "invalid access - must be subclass"); |
rbackman@5633 | 66 | |
duke@435 | 67 | VM_ENTRY_MARK; |
duke@435 | 68 | ciConstant result; |
never@2749 | 69 | Handle obj = get_oop(); |
never@2749 | 70 | assert(!obj.is_null(), "bad oop"); |
duke@435 | 71 | BasicType field_btype = field->type()->basic_type(); |
duke@435 | 72 | int offset = field->offset(); |
duke@435 | 73 | |
duke@435 | 74 | switch(field_btype) { |
duke@435 | 75 | case T_BYTE: |
duke@435 | 76 | return ciConstant(field_btype, obj->byte_field(offset)); |
duke@435 | 77 | break; |
duke@435 | 78 | case T_CHAR: |
duke@435 | 79 | return ciConstant(field_btype, obj->char_field(offset)); |
duke@435 | 80 | break; |
duke@435 | 81 | case T_SHORT: |
duke@435 | 82 | return ciConstant(field_btype, obj->short_field(offset)); |
duke@435 | 83 | break; |
duke@435 | 84 | case T_BOOLEAN: |
duke@435 | 85 | return ciConstant(field_btype, obj->bool_field(offset)); |
duke@435 | 86 | break; |
duke@435 | 87 | case T_INT: |
duke@435 | 88 | return ciConstant(field_btype, obj->int_field(offset)); |
duke@435 | 89 | break; |
duke@435 | 90 | case T_FLOAT: |
duke@435 | 91 | return ciConstant(obj->float_field(offset)); |
duke@435 | 92 | break; |
duke@435 | 93 | case T_DOUBLE: |
duke@435 | 94 | return ciConstant(obj->double_field(offset)); |
duke@435 | 95 | break; |
duke@435 | 96 | case T_LONG: |
duke@435 | 97 | return ciConstant(obj->long_field(offset)); |
duke@435 | 98 | break; |
duke@435 | 99 | case T_OBJECT: |
duke@435 | 100 | case T_ARRAY: |
duke@435 | 101 | { |
duke@435 | 102 | oop o = obj->obj_field(offset); |
duke@435 | 103 | |
duke@435 | 104 | // A field will be "constant" if it is known always to be |
duke@435 | 105 | // a non-null reference to an instance of a particular class, |
duke@435 | 106 | // or to a particular array. This can happen even if the instance |
duke@435 | 107 | // or array is not perm. In such a case, an "unloaded" ciArray |
duke@435 | 108 | // or ciInstance is created. The compiler may be able to use |
duke@435 | 109 | // information about the object's class (which is exact) or length. |
duke@435 | 110 | |
duke@435 | 111 | if (o == NULL) { |
duke@435 | 112 | return ciConstant(field_btype, ciNullObject::make()); |
duke@435 | 113 | } else { |
duke@435 | 114 | return ciConstant(field_btype, CURRENT_ENV->get_object(o)); |
duke@435 | 115 | } |
duke@435 | 116 | } |
duke@435 | 117 | } |
duke@435 | 118 | ShouldNotReachHere(); |
duke@435 | 119 | // to shut up the compiler |
duke@435 | 120 | return ciConstant(); |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | // ------------------------------------------------------------------ |
duke@435 | 124 | // ciInstance::field_value_by_offset |
duke@435 | 125 | // |
duke@435 | 126 | // Constant value of a field at the specified offset. |
duke@435 | 127 | ciConstant ciInstance::field_value_by_offset(int field_offset) { |
duke@435 | 128 | ciInstanceKlass* ik = klass()->as_instance_klass(); |
duke@435 | 129 | ciField* field = ik->get_field_by_offset(field_offset, false); |
duke@435 | 130 | return field_value(field); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | // ------------------------------------------------------------------ |
duke@435 | 134 | // ciInstance::print_impl |
duke@435 | 135 | // |
duke@435 | 136 | // Implementation of the print method. |
duke@435 | 137 | void ciInstance::print_impl(outputStream* st) { |
duke@435 | 138 | st->print(" type="); |
duke@435 | 139 | klass()->print(st); |
duke@435 | 140 | } |
never@2658 | 141 | |
never@2658 | 142 | |
never@2658 | 143 | ciKlass* ciInstance::java_lang_Class_klass() { |
never@2658 | 144 | VM_ENTRY_MARK; |
coleenp@4037 | 145 | return CURRENT_ENV->get_metadata(java_lang_Class::as_Klass(get_oop()))->as_klass(); |
never@2658 | 146 | } |