annotate hotspot/src/share/vm/oops/arrayKlass.cpp @ 22794:f1c014ad3754

8027146: Class loading verification failure if GC occurs in Universe::flush_dependents_on Summary: Remove search in system dictionary and hacks, replace with verifying in CLD::_klasses list. Reviewed-by: dcubed, acorn
author coleenp
date Sat, 15 Feb 2014 13:03:38 -0500
parents da823d78ad65
children 22eb7be3d99d
rev   line source
duke@1 1 /*
coleenp@22794 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@7397 26 #include "classfile/javaClasses.hpp"
stefank@7397 27 #include "classfile/systemDictionary.hpp"
stefank@7397 28 #include "classfile/vmSymbols.hpp"
stefank@7397 29 #include "gc_interface/collectedHeap.inline.hpp"
stefank@7397 30 #include "jvmtifiles/jvmti.h"
stefank@7397 31 #include "memory/gcLocker.hpp"
stefank@7397 32 #include "memory/universe.inline.hpp"
stefank@7397 33 #include "oops/arrayKlass.hpp"
stefank@7397 34 #include "oops/arrayOop.hpp"
stefank@7397 35 #include "oops/instanceKlass.hpp"
stefank@7397 36 #include "oops/objArrayOop.hpp"
stefank@7397 37 #include "oops/oop.inline.hpp"
duke@1 38
coleenp@13952 39 int ArrayKlass::static_size(int header_size) {
duke@1 40 // size of an array klass object
coleenp@13728 41 assert(header_size <= InstanceKlass::header_size(), "bad header size");
duke@1 42 // If this assert fails, see comments in base_create_array_klass.
coleenp@13728 43 header_size = InstanceKlass::header_size();
coleenp@13728 44 int vtable_len = Universe::base_vtable_size();
duke@1 45 #ifdef _LP64
coleenp@13728 46 int size = header_size + align_object_offset(vtable_len);
duke@1 47 #else
coleenp@13728 48 int size = header_size + vtable_len;
duke@1 49 #endif
duke@1 50 return align_object_size(size);
duke@1 51 }
duke@1 52
duke@1 53
coleenp@13952 54 Klass* ArrayKlass::java_super() const {
duke@1 55 if (super() == NULL) return NULL; // bootstrap case
duke@1 56 // Array klasses have primary supertypes which are not reported to Java.
duke@1 57 // Example super chain: String[][] -> Object[][] -> Object[] -> Object
never@4571 58 return SystemDictionary::Object_klass();
duke@1 59 }
duke@1 60
duke@1 61
coleenp@13952 62 oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
duke@1 63 ShouldNotReachHere();
duke@1 64 return NULL;
duke@1 65 }
duke@1 66
coleenp@13952 67 Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
duke@1 68 // There are no methods in an array klass but the super class (Object) has some
duke@1 69 assert(super(), "super klass must be present");
hseigel@14488 70 return super()->uncached_lookup_method(name, signature);
duke@1 71 }
duke@1 72
coleenp@13952 73 ArrayKlass::ArrayKlass(Symbol* name) {
coleenp@13728 74 set_name(name);
duke@1 75
coleenp@13728 76 set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass());
coleenp@13728 77 set_layout_helper(Klass::_lh_neutral_value);
coleenp@13728 78 set_dimension(1);
coleenp@13728 79 set_higher_dimension(NULL);
coleenp@13728 80 set_lower_dimension(NULL);
coleenp@13728 81 set_component_mirror(NULL);
duke@1 82 // Arrays don't add any new methods, so their vtable is the same size as
duke@1 83 // the vtable of klass Object.
duke@1 84 int vtable_size = Universe::base_vtable_size();
coleenp@13728 85 set_vtable_length(vtable_size);
coleenp@13728 86 set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
duke@1 87 }
duke@1 88
duke@1 89
duke@1 90 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
coleenp@13952 91 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
coleenp@13952 92 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) {
duke@1 93 ResourceMark rm(THREAD);
duke@1 94 k->initialize_supers(super_klass(), CHECK);
duke@1 95 k->vtable()->initialize_vtable(false, CHECK);
coleenp@17826 96 java_lang_Class::create_mirror(k, Handle(NULL), CHECK);
duke@1 97 }
duke@1 98
coleenp@13952 99 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) {
duke@1 100 // interfaces = { cloneable_klass, serializable_klass };
duke@1 101 assert(num_extra_slots == 0, "sanity of primitive array type");
duke@1 102 // Must share this for correct bootstrapping!
coleenp@13728 103 set_secondary_supers(Universe::the_array_interfaces_array());
coleenp@13728 104 return NULL;
duke@1 105 }
duke@1 106
coleenp@13952 107 bool ArrayKlass::compute_is_subtype_of(Klass* k) {
duke@1 108 // An array is a subtype of Serializable, Clonable, and Object
never@4571 109 return k == SystemDictionary::Object_klass()
never@4571 110 || k == SystemDictionary::Cloneable_klass()
never@4571 111 || k == SystemDictionary::Serializable_klass();
duke@1 112 }
duke@1 113
duke@1 114
coleenp@13952 115 inline intptr_t* ArrayKlass::start_of_vtable() const {
coleenp@13728 116 // all vtables start at the same place, that's why we use InstanceKlass::header_size here
coleenp@13728 117 return ((intptr_t*)this) + InstanceKlass::header_size();
duke@1 118 }
duke@1 119
duke@1 120
coleenp@13952 121 klassVtable* ArrayKlass::vtable() const {
coleenp@13728 122 KlassHandle kh(Thread::current(), this);
duke@1 123 return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
duke@1 124 }
duke@1 125
duke@1 126
coleenp@13952 127 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
duke@1 128 if (length < 0) {
duke@1 129 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@1 130 }
duke@1 131 if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
martin@3576 132 report_java_out_of_memory("Requested array size exceeds VM limit");
sspitsyn@12114 133 JvmtiExport::post_array_size_exhausted();
duke@1 134 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@1 135 }
duke@1 136 int size = objArrayOopDesc::object_size(length);
coleenp@13728 137 Klass* k = array_klass(n+dimension(), CHECK_0);
coleenp@13952 138 ArrayKlass* ak = ArrayKlass::cast(k);
duke@1 139 objArrayOop o =
duke@1 140 (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
duke@1 141 // initialization to NULL not necessary, area already cleared
duke@1 142 return o;
duke@1 143 }
duke@1 144
coleenp@13952 145 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
coleenp@13728 146 Klass* k = this;
coleenp@13728 147 // Iterate over this array klass and all higher dimensions
coleenp@13728 148 while (k != NULL) {
coleenp@13728 149 f(k, CHECK);
coleenp@13952 150 k = ArrayKlass::cast(k)->higher_dimension();
coleenp@13728 151 }
coleenp@13728 152 }
duke@1 153
coleenp@13952 154 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
coleenp@13728 155 Klass* k = this;
duke@1 156 // Iterate over this array klass and all higher dimensions
duke@1 157 while (k != NULL) {
duke@1 158 f(k);
coleenp@13952 159 k = ArrayKlass::cast(k)->higher_dimension();
duke@1 160 }
duke@1 161 }
duke@1 162
coleenp@13728 163 // GC support
coleenp@13728 164
coleenp@13952 165 void ArrayKlass::oops_do(OopClosure* cl) {
coleenp@13728 166 Klass::oops_do(cl);
coleenp@13728 167
coleenp@13728 168 cl->do_oop(adr_component_mirror());
coleenp@13728 169 }
coleenp@13728 170
duke@1 171 // JVM support
duke@1 172
coleenp@13952 173 jint ArrayKlass::compute_modifier_flags(TRAPS) const {
duke@1 174 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@1 175 }
duke@1 176
duke@1 177 // JVMTI support
duke@1 178
coleenp@13952 179 jint ArrayKlass::jvmti_class_status() const {
duke@1 180 return JVMTI_CLASS_STATUS_ARRAY;
duke@1 181 }
duke@1 182
coleenp@13952 183 void ArrayKlass::remove_unshareable_info() {
coleenp@13728 184 Klass::remove_unshareable_info();
coleenp@13728 185 // Clear the java mirror
coleenp@13728 186 set_component_mirror(NULL);
coleenp@13728 187 }
coleenp@13728 188
coleenp@13952 189 void ArrayKlass::restore_unshareable_info(TRAPS) {
coleenp@13728 190 Klass::restore_unshareable_info(CHECK);
coleenp@13728 191 // Klass recreates the component mirror also
coleenp@13728 192 }
coleenp@13728 193
duke@1 194 // Printing
duke@1 195
coleenp@13952 196 void ArrayKlass::print_on(outputStream* st) const {
coleenp@13728 197 assert(is_klass(), "must be klass");
coleenp@13728 198 Klass::print_on(st);
coleenp@13728 199 }
coleenp@13728 200
coleenp@13952 201 void ArrayKlass::print_value_on(outputStream* st) const {
coleenp@13728 202 assert(is_klass(), "must be klass");
coleenp@13728 203 for(int index = 0; index < dimension(); index++) {
coleenp@13728 204 st->print("[]");
coleenp@13728 205 }
coleenp@13728 206 }
coleenp@13728 207
coleenp@13952 208 void ArrayKlass::oop_print_on(oop obj, outputStream* st) {
duke@1 209 assert(obj->is_array(), "must be array");
duke@1 210 Klass::oop_print_on(obj, st);
duke@1 211 st->print_cr(" - length: %d", arrayOop(obj)->length());
duke@1 212 }
duke@1 213
coleenp@13728 214
duke@1 215 // Verification
duke@1 216
coleenp@22794 217 void ArrayKlass::verify_on(outputStream* st) {
coleenp@22794 218 Klass::verify_on(st);
coleenp@13728 219
coleenp@13728 220 if (component_mirror() != NULL) {
coleenp@13728 221 guarantee(component_mirror()->klass() != NULL, "should have a class");
coleenp@13728 222 }
coleenp@13728 223 }
coleenp@13728 224
coleenp@13952 225 void ArrayKlass::oop_verify_on(oop obj, outputStream* st) {
duke@1 226 guarantee(obj->is_array(), "must be array");
duke@1 227 arrayOop a = arrayOop(obj);
duke@1 228 guarantee(a->length() >= 0, "array with negative length?");
duke@1 229 }