Fri, 15 Apr 2011 09:36:28 -0400
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
Summary: Make CDS reorder vtables so that dump time vtables match run time order, so when redefine classes reinitializes them, they aren't in the wrong order.
Reviewed-by: dcubed, acorn
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 1997, 2011, 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 "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 28 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 29 | #include "memory/oopFactory.hpp" |
stefank@2314 | 30 | #include "memory/resourceArea.hpp" |
stefank@2314 | 31 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 32 | #include "oops/klass.inline.hpp" |
stefank@2314 | 33 | #include "oops/klassOop.hpp" |
stefank@2314 | 34 | #include "oops/oop.inline.hpp" |
stefank@2314 | 35 | #include "oops/oop.inline2.hpp" |
stefank@2314 | 36 | #include "runtime/atomic.hpp" |
duke@435 | 37 | |
coleenp@2497 | 38 | void Klass::set_name(Symbol* n) { |
coleenp@2497 | 39 | _name = n; |
coleenp@2497 | 40 | if (_name != NULL) _name->increment_refcount(); |
coleenp@2497 | 41 | } |
duke@435 | 42 | |
duke@435 | 43 | bool Klass::is_subclass_of(klassOop k) const { |
duke@435 | 44 | // Run up the super chain and check |
duke@435 | 45 | klassOop t = as_klassOop(); |
duke@435 | 46 | |
duke@435 | 47 | if (t == k) return true; |
duke@435 | 48 | t = Klass::cast(t)->super(); |
duke@435 | 49 | |
duke@435 | 50 | while (t != NULL) { |
duke@435 | 51 | if (t == k) return true; |
duke@435 | 52 | t = Klass::cast(t)->super(); |
duke@435 | 53 | } |
duke@435 | 54 | return false; |
duke@435 | 55 | } |
duke@435 | 56 | |
duke@435 | 57 | bool Klass::search_secondary_supers(klassOop k) const { |
duke@435 | 58 | // Put some extra logic here out-of-line, before the search proper. |
duke@435 | 59 | // This cuts down the size of the inline method. |
duke@435 | 60 | |
duke@435 | 61 | // This is necessary, since I am never in my own secondary_super list. |
duke@435 | 62 | if (this->as_klassOop() == k) |
duke@435 | 63 | return true; |
duke@435 | 64 | // Scan the array-of-objects for a match |
duke@435 | 65 | int cnt = secondary_supers()->length(); |
duke@435 | 66 | for (int i = 0; i < cnt; i++) { |
duke@435 | 67 | if (secondary_supers()->obj_at(i) == k) { |
duke@435 | 68 | ((Klass*)this)->set_secondary_super_cache(k); |
duke@435 | 69 | return true; |
duke@435 | 70 | } |
duke@435 | 71 | } |
duke@435 | 72 | return false; |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | // Return self, except for abstract classes with exactly 1 |
duke@435 | 76 | // implementor. Then return the 1 concrete implementation. |
duke@435 | 77 | Klass *Klass::up_cast_abstract() { |
duke@435 | 78 | Klass *r = this; |
duke@435 | 79 | while( r->is_abstract() ) { // Receiver is abstract? |
duke@435 | 80 | Klass *s = r->subklass(); // Check for exactly 1 subklass |
duke@435 | 81 | if( !s || s->next_sibling() ) // Oops; wrong count; give up |
duke@435 | 82 | return this; // Return 'this' as a no-progress flag |
duke@435 | 83 | r = s; // Loop till find concrete class |
duke@435 | 84 | } |
duke@435 | 85 | return r; // Return the 1 concrete class |
duke@435 | 86 | } |
duke@435 | 87 | |
twisti@1040 | 88 | // Find LCA in class hierarchy |
duke@435 | 89 | Klass *Klass::LCA( Klass *k2 ) { |
duke@435 | 90 | Klass *k1 = this; |
duke@435 | 91 | while( 1 ) { |
duke@435 | 92 | if( k1->is_subtype_of(k2->as_klassOop()) ) return k2; |
duke@435 | 93 | if( k2->is_subtype_of(k1->as_klassOop()) ) return k1; |
duke@435 | 94 | k1 = k1->super()->klass_part(); |
duke@435 | 95 | k2 = k2->super()->klass_part(); |
duke@435 | 96 | } |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | |
duke@435 | 100 | void Klass::check_valid_for_instantiation(bool throwError, TRAPS) { |
duke@435 | 101 | ResourceMark rm(THREAD); |
duke@435 | 102 | THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
duke@435 | 103 | : vmSymbols::java_lang_InstantiationException(), external_name()); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | |
duke@435 | 107 | void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) { |
duke@435 | 108 | THROW(vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 109 | } |
duke@435 | 110 | |
duke@435 | 111 | |
duke@435 | 112 | void Klass::initialize(TRAPS) { |
duke@435 | 113 | ShouldNotReachHere(); |
duke@435 | 114 | } |
duke@435 | 115 | |
duke@435 | 116 | bool Klass::compute_is_subtype_of(klassOop k) { |
duke@435 | 117 | assert(k->is_klass(), "argument must be a class"); |
duke@435 | 118 | return is_subclass_of(k); |
duke@435 | 119 | } |
duke@435 | 120 | |
duke@435 | 121 | |
coleenp@2497 | 122 | methodOop Klass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
duke@435 | 123 | #ifdef ASSERT |
duke@435 | 124 | tty->print_cr("Error: uncached_lookup_method called on a klass oop." |
duke@435 | 125 | " Likely error: reflection method does not correctly" |
duke@435 | 126 | " wrap return value in a mirror object."); |
duke@435 | 127 | #endif |
duke@435 | 128 | ShouldNotReachHere(); |
duke@435 | 129 | return NULL; |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size, |
duke@435 | 133 | const Klass_vtbl& vtbl, TRAPS) { |
duke@435 | 134 | size = align_object_size(size); |
duke@435 | 135 | // allocate and initialize vtable |
duke@435 | 136 | Klass* kl = (Klass*) vtbl.allocate_permanent(klass, size, CHECK_NULL); |
duke@435 | 137 | klassOop k = kl->as_klassOop(); |
duke@435 | 138 | |
duke@435 | 139 | { // Preinitialize supertype information. |
duke@435 | 140 | // A later call to initialize_supers() may update these settings: |
duke@435 | 141 | kl->set_super(NULL); |
duke@435 | 142 | for (juint i = 0; i < Klass::primary_super_limit(); i++) { |
duke@435 | 143 | kl->_primary_supers[i] = NULL; |
duke@435 | 144 | } |
duke@435 | 145 | kl->set_secondary_supers(NULL); |
duke@435 | 146 | oop_store_without_check((oop*) &kl->_primary_supers[0], k); |
duke@435 | 147 | kl->set_super_check_offset(primary_supers_offset_in_bytes() + sizeof(oopDesc)); |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | kl->set_java_mirror(NULL); |
duke@435 | 151 | kl->set_modifier_flags(0); |
duke@435 | 152 | kl->set_layout_helper(Klass::_lh_neutral_value); |
duke@435 | 153 | kl->set_name(NULL); |
duke@435 | 154 | AccessFlags af; |
duke@435 | 155 | af.set_flags(0); |
duke@435 | 156 | kl->set_access_flags(af); |
duke@435 | 157 | kl->set_subklass(NULL); |
duke@435 | 158 | kl->set_next_sibling(NULL); |
duke@435 | 159 | kl->set_alloc_count(0); |
duke@435 | 160 | kl->set_alloc_size(0); |
duke@435 | 161 | |
duke@435 | 162 | kl->set_prototype_header(markOopDesc::prototype()); |
duke@435 | 163 | kl->set_biased_lock_revocation_count(0); |
duke@435 | 164 | kl->set_last_biased_lock_bulk_revocation_time(0); |
duke@435 | 165 | |
duke@435 | 166 | return k; |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | KlassHandle Klass::base_create_klass(KlassHandle& klass, int size, |
duke@435 | 170 | const Klass_vtbl& vtbl, TRAPS) { |
duke@435 | 171 | klassOop ek = base_create_klass_oop(klass, size, vtbl, THREAD); |
duke@435 | 172 | return KlassHandle(THREAD, ek); |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | void Klass_vtbl::post_new_init_klass(KlassHandle& klass, |
duke@435 | 176 | klassOop new_klass, |
duke@435 | 177 | int size) const { |
duke@435 | 178 | assert(!new_klass->klass_part()->null_vtbl(), "Not a complete klass"); |
duke@435 | 179 | CollectedHeap::post_allocation_install_obj_klass(klass, new_klass, size); |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass, |
duke@435 | 183 | int size, TRAPS) { |
duke@435 | 184 | // The vtable pointer is installed during the execution of |
duke@435 | 185 | // constructors in the call to permanent_obj_allocate(). Delay |
duke@435 | 186 | // the installation of the klass pointer into the new klass "k" |
duke@435 | 187 | // until after the vtable pointer has been installed (i.e., until |
duke@435 | 188 | // after the return of permanent_obj_allocate(). |
duke@435 | 189 | klassOop k = |
duke@435 | 190 | (klassOop) CollectedHeap::permanent_obj_allocate_no_klass_install(klass, |
duke@435 | 191 | size, CHECK_NULL); |
duke@435 | 192 | return k->klass_part(); |
duke@435 | 193 | } |
duke@435 | 194 | |
duke@435 | 195 | jint Klass::array_layout_helper(BasicType etype) { |
duke@435 | 196 | assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype"); |
duke@435 | 197 | // Note that T_ARRAY is not allowed here. |
duke@435 | 198 | int hsize = arrayOopDesc::base_offset_in_bytes(etype); |
kvn@464 | 199 | int esize = type2aelembytes(etype); |
duke@435 | 200 | bool isobj = (etype == T_OBJECT); |
duke@435 | 201 | int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value; |
duke@435 | 202 | int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize)); |
duke@435 | 203 | |
duke@435 | 204 | assert(lh < (int)_lh_neutral_value, "must look like an array layout"); |
duke@435 | 205 | assert(layout_helper_is_javaArray(lh), "correct kind"); |
duke@435 | 206 | assert(layout_helper_is_objArray(lh) == isobj, "correct kind"); |
duke@435 | 207 | assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind"); |
duke@435 | 208 | assert(layout_helper_header_size(lh) == hsize, "correct decode"); |
duke@435 | 209 | assert(layout_helper_element_type(lh) == etype, "correct decode"); |
duke@435 | 210 | assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode"); |
duke@435 | 211 | |
duke@435 | 212 | return lh; |
duke@435 | 213 | } |
duke@435 | 214 | |
duke@435 | 215 | bool Klass::can_be_primary_super_slow() const { |
duke@435 | 216 | if (super() == NULL) |
duke@435 | 217 | return true; |
duke@435 | 218 | else if (super()->klass_part()->super_depth() >= primary_super_limit()-1) |
duke@435 | 219 | return false; |
duke@435 | 220 | else |
duke@435 | 221 | return true; |
duke@435 | 222 | } |
duke@435 | 223 | |
duke@435 | 224 | void Klass::initialize_supers(klassOop k, TRAPS) { |
duke@435 | 225 | if (FastSuperclassLimit == 0) { |
duke@435 | 226 | // None of the other machinery matters. |
duke@435 | 227 | set_super(k); |
duke@435 | 228 | return; |
duke@435 | 229 | } |
duke@435 | 230 | if (k == NULL) { |
duke@435 | 231 | set_super(NULL); |
duke@435 | 232 | oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop()); |
duke@435 | 233 | assert(super_depth() == 0, "Object must already be initialized properly"); |
never@1577 | 234 | } else if (k != super() || k == SystemDictionary::Object_klass()) { |
never@1577 | 235 | assert(super() == NULL || super() == SystemDictionary::Object_klass(), |
duke@435 | 236 | "initialize this only once to a non-trivial value"); |
duke@435 | 237 | set_super(k); |
duke@435 | 238 | Klass* sup = k->klass_part(); |
duke@435 | 239 | int sup_depth = sup->super_depth(); |
duke@435 | 240 | juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit()); |
duke@435 | 241 | if (!can_be_primary_super_slow()) |
duke@435 | 242 | my_depth = primary_super_limit(); |
duke@435 | 243 | for (juint i = 0; i < my_depth; i++) { |
duke@435 | 244 | oop_store_without_check((oop*) &_primary_supers[i], (oop) sup->_primary_supers[i]); |
duke@435 | 245 | } |
duke@435 | 246 | klassOop *super_check_cell; |
duke@435 | 247 | if (my_depth < primary_super_limit()) { |
duke@435 | 248 | oop_store_without_check((oop*) &_primary_supers[my_depth], (oop) this->as_klassOop()); |
duke@435 | 249 | super_check_cell = &_primary_supers[my_depth]; |
duke@435 | 250 | } else { |
duke@435 | 251 | // Overflow of the primary_supers array forces me to be secondary. |
duke@435 | 252 | super_check_cell = &_secondary_super_cache; |
duke@435 | 253 | } |
duke@435 | 254 | set_super_check_offset((address)super_check_cell - (address) this->as_klassOop()); |
duke@435 | 255 | |
duke@435 | 256 | #ifdef ASSERT |
duke@435 | 257 | { |
duke@435 | 258 | juint j = super_depth(); |
duke@435 | 259 | assert(j == my_depth, "computed accessor gets right answer"); |
duke@435 | 260 | klassOop t = as_klassOop(); |
duke@435 | 261 | while (!Klass::cast(t)->can_be_primary_super()) { |
duke@435 | 262 | t = Klass::cast(t)->super(); |
duke@435 | 263 | j = Klass::cast(t)->super_depth(); |
duke@435 | 264 | } |
duke@435 | 265 | for (juint j1 = j+1; j1 < primary_super_limit(); j1++) { |
duke@435 | 266 | assert(primary_super_of_depth(j1) == NULL, "super list padding"); |
duke@435 | 267 | } |
duke@435 | 268 | while (t != NULL) { |
duke@435 | 269 | assert(primary_super_of_depth(j) == t, "super list initialization"); |
duke@435 | 270 | t = Klass::cast(t)->super(); |
duke@435 | 271 | --j; |
duke@435 | 272 | } |
duke@435 | 273 | assert(j == (juint)-1, "correct depth count"); |
duke@435 | 274 | } |
duke@435 | 275 | #endif |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | if (secondary_supers() == NULL) { |
duke@435 | 279 | KlassHandle this_kh (THREAD, this); |
duke@435 | 280 | |
duke@435 | 281 | // Now compute the list of secondary supertypes. |
duke@435 | 282 | // Secondaries can occasionally be on the super chain, |
duke@435 | 283 | // if the inline "_primary_supers" array overflows. |
duke@435 | 284 | int extras = 0; |
duke@435 | 285 | klassOop p; |
duke@435 | 286 | for (p = super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) { |
duke@435 | 287 | ++extras; |
duke@435 | 288 | } |
duke@435 | 289 | |
duke@435 | 290 | // Compute the "real" non-extra secondaries. |
duke@435 | 291 | objArrayOop secondary_oops = compute_secondary_supers(extras, CHECK); |
duke@435 | 292 | objArrayHandle secondaries (THREAD, secondary_oops); |
duke@435 | 293 | |
duke@435 | 294 | // Store the extra secondaries in the first array positions: |
duke@435 | 295 | int fillp = extras; |
duke@435 | 296 | for (p = this_kh->super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) { |
duke@435 | 297 | int i; // Scan for overflow primaries being duplicates of 2nd'arys |
duke@435 | 298 | |
duke@435 | 299 | // This happens frequently for very deeply nested arrays: the |
duke@435 | 300 | // primary superclass chain overflows into the secondary. The |
duke@435 | 301 | // secondary list contains the element_klass's secondaries with |
duke@435 | 302 | // an extra array dimension added. If the element_klass's |
duke@435 | 303 | // secondary list already contains some primary overflows, they |
duke@435 | 304 | // (with the extra level of array-ness) will collide with the |
duke@435 | 305 | // normal primary superclass overflows. |
duke@435 | 306 | for( i = extras; i < secondaries->length(); i++ ) |
duke@435 | 307 | if( secondaries->obj_at(i) == p ) |
duke@435 | 308 | break; |
duke@435 | 309 | if( i < secondaries->length() ) |
duke@435 | 310 | continue; // It's a dup, don't put it in |
duke@435 | 311 | secondaries->obj_at_put(--fillp, p); |
duke@435 | 312 | } |
duke@435 | 313 | // See if we had some dup's, so the array has holes in it. |
duke@435 | 314 | if( fillp > 0 ) { |
duke@435 | 315 | // Pack the array. Drop the old secondaries array on the floor |
duke@435 | 316 | // and let GC reclaim it. |
duke@435 | 317 | objArrayOop s2 = oopFactory::new_system_objArray(secondaries->length() - fillp, CHECK); |
duke@435 | 318 | for( int i = 0; i < s2->length(); i++ ) |
duke@435 | 319 | s2->obj_at_put( i, secondaries->obj_at(i+fillp) ); |
duke@435 | 320 | secondaries = objArrayHandle(THREAD, s2); |
duke@435 | 321 | } |
duke@435 | 322 | |
duke@435 | 323 | #ifdef ASSERT |
duke@435 | 324 | if (secondaries() != Universe::the_array_interfaces_array()) { |
duke@435 | 325 | // We must not copy any NULL placeholders left over from bootstrap. |
duke@435 | 326 | for (int j = 0; j < secondaries->length(); j++) { |
duke@435 | 327 | assert(secondaries->obj_at(j) != NULL, "correct bootstrapping order"); |
duke@435 | 328 | } |
duke@435 | 329 | } |
duke@435 | 330 | #endif |
duke@435 | 331 | |
duke@435 | 332 | this_kh->set_secondary_supers(secondaries()); |
duke@435 | 333 | } |
duke@435 | 334 | } |
duke@435 | 335 | |
duke@435 | 336 | objArrayOop Klass::compute_secondary_supers(int num_extra_slots, TRAPS) { |
duke@435 | 337 | assert(num_extra_slots == 0, "override for complex klasses"); |
duke@435 | 338 | return Universe::the_empty_system_obj_array(); |
duke@435 | 339 | } |
duke@435 | 340 | |
duke@435 | 341 | |
duke@435 | 342 | Klass* Klass::subklass() const { |
duke@435 | 343 | return _subklass == NULL ? NULL : Klass::cast(_subklass); |
duke@435 | 344 | } |
duke@435 | 345 | |
duke@435 | 346 | instanceKlass* Klass::superklass() const { |
duke@435 | 347 | assert(super() == NULL || super()->klass_part()->oop_is_instance(), "must be instance klass"); |
duke@435 | 348 | return _super == NULL ? NULL : instanceKlass::cast(_super); |
duke@435 | 349 | } |
duke@435 | 350 | |
duke@435 | 351 | Klass* Klass::next_sibling() const { |
duke@435 | 352 | return _next_sibling == NULL ? NULL : Klass::cast(_next_sibling); |
duke@435 | 353 | } |
duke@435 | 354 | |
duke@435 | 355 | void Klass::set_subklass(klassOop s) { |
duke@435 | 356 | assert(s != as_klassOop(), "sanity check"); |
duke@435 | 357 | oop_store_without_check((oop*)&_subklass, s); |
duke@435 | 358 | } |
duke@435 | 359 | |
duke@435 | 360 | void Klass::set_next_sibling(klassOop s) { |
duke@435 | 361 | assert(s != as_klassOop(), "sanity check"); |
duke@435 | 362 | oop_store_without_check((oop*)&_next_sibling, s); |
duke@435 | 363 | } |
duke@435 | 364 | |
duke@435 | 365 | void Klass::append_to_sibling_list() { |
duke@435 | 366 | debug_only(if (!SharedSkipVerify) as_klassOop()->verify();) |
duke@435 | 367 | // add ourselves to superklass' subklass list |
duke@435 | 368 | instanceKlass* super = superklass(); |
duke@435 | 369 | if (super == NULL) return; // special case: class Object |
duke@435 | 370 | assert(SharedSkipVerify || |
duke@435 | 371 | (!super->is_interface() // interfaces cannot be supers |
duke@435 | 372 | && (super->superklass() == NULL || !is_interface())), |
duke@435 | 373 | "an interface can only be a subklass of Object"); |
duke@435 | 374 | klassOop prev_first_subklass = super->subklass_oop(); |
duke@435 | 375 | if (prev_first_subklass != NULL) { |
duke@435 | 376 | // set our sibling to be the superklass' previous first subklass |
duke@435 | 377 | set_next_sibling(prev_first_subklass); |
duke@435 | 378 | } |
duke@435 | 379 | // make ourselves the superklass' first subklass |
duke@435 | 380 | super->set_subklass(as_klassOop()); |
duke@435 | 381 | debug_only(if (!SharedSkipVerify) as_klassOop()->verify();) |
duke@435 | 382 | } |
duke@435 | 383 | |
duke@435 | 384 | void Klass::remove_from_sibling_list() { |
duke@435 | 385 | // remove receiver from sibling list |
duke@435 | 386 | instanceKlass* super = superklass(); |
never@1577 | 387 | assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super"); |
duke@435 | 388 | if (super == NULL) return; // special case: class Object |
duke@435 | 389 | if (super->subklass() == this) { |
duke@435 | 390 | // first subklass |
duke@435 | 391 | super->set_subklass(_next_sibling); |
duke@435 | 392 | } else { |
duke@435 | 393 | Klass* sib = super->subklass(); |
duke@435 | 394 | while (sib->next_sibling() != this) { |
duke@435 | 395 | sib = sib->next_sibling(); |
duke@435 | 396 | }; |
duke@435 | 397 | sib->set_next_sibling(_next_sibling); |
duke@435 | 398 | } |
duke@435 | 399 | } |
duke@435 | 400 | |
duke@435 | 401 | void Klass::follow_weak_klass_links( BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
duke@435 | 402 | // This klass is alive but the subklass and siblings are not followed/updated. |
duke@435 | 403 | // We update the subklass link and the subklass' sibling links here. |
duke@435 | 404 | // Our own sibling link will be updated by our superclass (which must be alive |
duke@435 | 405 | // since we are). |
duke@435 | 406 | assert(is_alive->do_object_b(as_klassOop()), "just checking, this should be live"); |
duke@435 | 407 | if (ClassUnloading) { |
duke@435 | 408 | klassOop sub = subklass_oop(); |
duke@435 | 409 | if (sub != NULL && !is_alive->do_object_b(sub)) { |
duke@435 | 410 | // first subklass not alive, find first one alive |
duke@435 | 411 | do { |
duke@435 | 412 | #ifndef PRODUCT |
duke@435 | 413 | if (TraceClassUnloading && WizardMode) { |
duke@435 | 414 | ResourceMark rm; |
duke@435 | 415 | tty->print_cr("[Unlinking class (subclass) %s]", sub->klass_part()->external_name()); |
duke@435 | 416 | } |
duke@435 | 417 | #endif |
duke@435 | 418 | sub = sub->klass_part()->next_sibling_oop(); |
duke@435 | 419 | } while (sub != NULL && !is_alive->do_object_b(sub)); |
duke@435 | 420 | set_subklass(sub); |
duke@435 | 421 | } |
duke@435 | 422 | // now update the subklass' sibling list |
duke@435 | 423 | while (sub != NULL) { |
duke@435 | 424 | klassOop next = sub->klass_part()->next_sibling_oop(); |
duke@435 | 425 | if (next != NULL && !is_alive->do_object_b(next)) { |
duke@435 | 426 | // first sibling not alive, find first one alive |
duke@435 | 427 | do { |
duke@435 | 428 | #ifndef PRODUCT |
duke@435 | 429 | if (TraceClassUnloading && WizardMode) { |
duke@435 | 430 | ResourceMark rm; |
duke@435 | 431 | tty->print_cr("[Unlinking class (sibling) %s]", next->klass_part()->external_name()); |
duke@435 | 432 | } |
duke@435 | 433 | #endif |
duke@435 | 434 | next = next->klass_part()->next_sibling_oop(); |
duke@435 | 435 | } while (next != NULL && !is_alive->do_object_b(next)); |
duke@435 | 436 | sub->klass_part()->set_next_sibling(next); |
duke@435 | 437 | } |
duke@435 | 438 | sub = next; |
duke@435 | 439 | } |
duke@435 | 440 | } else { |
duke@435 | 441 | // Always follow subklass and sibling link. This will prevent any klasses from |
duke@435 | 442 | // being unloaded (all classes are transitively linked from java.lang.Object). |
duke@435 | 443 | keep_alive->do_oop(adr_subklass()); |
duke@435 | 444 | keep_alive->do_oop(adr_next_sibling()); |
duke@435 | 445 | } |
duke@435 | 446 | } |
duke@435 | 447 | |
duke@435 | 448 | |
duke@435 | 449 | void Klass::remove_unshareable_info() { |
duke@435 | 450 | if (oop_is_instance()) { |
duke@435 | 451 | instanceKlass* ik = (instanceKlass*)this; |
duke@435 | 452 | if (ik->is_linked()) { |
duke@435 | 453 | ik->unlink_class(); |
duke@435 | 454 | } |
duke@435 | 455 | } |
coleenp@2777 | 456 | // Clear the Java vtable if the oop has one. |
coleenp@2777 | 457 | // The vtable isn't shareable because it's in the wrong order wrt the methods |
coleenp@2777 | 458 | // once the method names get moved and resorted. |
coleenp@2777 | 459 | klassVtable* vt = vtable(); |
coleenp@2777 | 460 | if (vt != NULL) { |
coleenp@2777 | 461 | assert(oop_is_instance() || oop_is_array(), "nothing else has vtable"); |
coleenp@2777 | 462 | vt->clear_vtable(); |
coleenp@2777 | 463 | } |
duke@435 | 464 | set_subklass(NULL); |
duke@435 | 465 | set_next_sibling(NULL); |
duke@435 | 466 | } |
duke@435 | 467 | |
duke@435 | 468 | |
coleenp@2497 | 469 | void Klass::shared_symbols_iterate(SymbolClosure* closure) { |
coleenp@2497 | 470 | closure->do_symbol(&_name); |
coleenp@2497 | 471 | } |
coleenp@2497 | 472 | |
coleenp@2497 | 473 | |
duke@435 | 474 | klassOop Klass::array_klass_or_null(int rank) { |
duke@435 | 475 | EXCEPTION_MARK; |
duke@435 | 476 | // No exception can be thrown by array_klass_impl when called with or_null == true. |
duke@435 | 477 | // (In anycase, the execption mark will fail if it do so) |
duke@435 | 478 | return array_klass_impl(true, rank, THREAD); |
duke@435 | 479 | } |
duke@435 | 480 | |
duke@435 | 481 | |
duke@435 | 482 | klassOop Klass::array_klass_or_null() { |
duke@435 | 483 | EXCEPTION_MARK; |
duke@435 | 484 | // No exception can be thrown by array_klass_impl when called with or_null == true. |
duke@435 | 485 | // (In anycase, the execption mark will fail if it do so) |
duke@435 | 486 | return array_klass_impl(true, THREAD); |
duke@435 | 487 | } |
duke@435 | 488 | |
duke@435 | 489 | |
duke@435 | 490 | klassOop Klass::array_klass_impl(bool or_null, int rank, TRAPS) { |
duke@435 | 491 | fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass"); |
duke@435 | 492 | return NULL; |
duke@435 | 493 | } |
duke@435 | 494 | |
duke@435 | 495 | |
duke@435 | 496 | klassOop Klass::array_klass_impl(bool or_null, TRAPS) { |
duke@435 | 497 | fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass"); |
duke@435 | 498 | return NULL; |
duke@435 | 499 | } |
duke@435 | 500 | |
duke@435 | 501 | |
duke@435 | 502 | void Klass::with_array_klasses_do(void f(klassOop k)) { |
duke@435 | 503 | f(as_klassOop()); |
duke@435 | 504 | } |
duke@435 | 505 | |
duke@435 | 506 | |
duke@435 | 507 | const char* Klass::external_name() const { |
jrose@866 | 508 | if (oop_is_instance()) { |
jrose@866 | 509 | instanceKlass* ik = (instanceKlass*) this; |
jrose@866 | 510 | if (ik->is_anonymous()) { |
twisti@2698 | 511 | assert(EnableInvokeDynamic, ""); |
jrose@866 | 512 | intptr_t hash = ik->java_mirror()->identity_hash(); |
jrose@866 | 513 | char hash_buf[40]; |
jrose@866 | 514 | sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash); |
jrose@866 | 515 | size_t hash_len = strlen(hash_buf); |
jrose@866 | 516 | |
jrose@866 | 517 | size_t result_len = name()->utf8_length(); |
jrose@866 | 518 | char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1); |
jrose@866 | 519 | name()->as_klass_external_name(result, (int) result_len + 1); |
jrose@866 | 520 | assert(strlen(result) == result_len, ""); |
jrose@866 | 521 | strcpy(result + result_len, hash_buf); |
jrose@866 | 522 | assert(strlen(result) == result_len + hash_len, ""); |
jrose@866 | 523 | return result; |
jrose@866 | 524 | } |
jrose@866 | 525 | } |
jrose@1474 | 526 | if (name() == NULL) return "<unknown>"; |
duke@435 | 527 | return name()->as_klass_external_name(); |
duke@435 | 528 | } |
duke@435 | 529 | |
duke@435 | 530 | |
jrose@1474 | 531 | const char* Klass::signature_name() const { |
jrose@1474 | 532 | if (name() == NULL) return "<unknown>"; |
duke@435 | 533 | return name()->as_C_string(); |
duke@435 | 534 | } |
duke@435 | 535 | |
duke@435 | 536 | // Unless overridden, modifier_flags is 0. |
duke@435 | 537 | jint Klass::compute_modifier_flags(TRAPS) const { |
duke@435 | 538 | return 0; |
duke@435 | 539 | } |
duke@435 | 540 | |
duke@435 | 541 | int Klass::atomic_incr_biased_lock_revocation_count() { |
duke@435 | 542 | return (int) Atomic::add(1, &_biased_lock_revocation_count); |
duke@435 | 543 | } |
duke@435 | 544 | |
duke@435 | 545 | // Unless overridden, jvmti_class_status has no flags set. |
duke@435 | 546 | jint Klass::jvmti_class_status() const { |
duke@435 | 547 | return 0; |
duke@435 | 548 | } |
duke@435 | 549 | |
duke@435 | 550 | // Printing |
duke@435 | 551 | |
duke@435 | 552 | void Klass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 553 | ResourceMark rm; |
duke@435 | 554 | // print title |
duke@435 | 555 | st->print_cr("%s ", internal_name()); |
duke@435 | 556 | obj->print_address_on(st); |
duke@435 | 557 | |
duke@435 | 558 | if (WizardMode) { |
duke@435 | 559 | // print header |
duke@435 | 560 | obj->mark()->print_on(st); |
duke@435 | 561 | } |
duke@435 | 562 | |
duke@435 | 563 | // print class |
duke@435 | 564 | st->print(" - klass: "); |
duke@435 | 565 | obj->klass()->print_value_on(st); |
duke@435 | 566 | st->cr(); |
duke@435 | 567 | } |
duke@435 | 568 | |
duke@435 | 569 | void Klass::oop_print_value_on(oop obj, outputStream* st) { |
duke@435 | 570 | // print title |
duke@435 | 571 | ResourceMark rm; // Cannot print in debug mode without this |
duke@435 | 572 | st->print("%s", internal_name()); |
duke@435 | 573 | obj->print_address_on(st); |
duke@435 | 574 | } |
duke@435 | 575 | |
duke@435 | 576 | // Verification |
duke@435 | 577 | |
duke@435 | 578 | void Klass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 579 | guarantee(obj->is_oop(), "should be oop"); |
duke@435 | 580 | guarantee(obj->klass()->is_perm(), "should be in permspace"); |
duke@435 | 581 | guarantee(obj->klass()->is_klass(), "klass field is not a klass"); |
duke@435 | 582 | } |
duke@435 | 583 | |
duke@435 | 584 | |
duke@435 | 585 | void Klass::oop_verify_old_oop(oop obj, oop* p, bool allow_dirty) { |
duke@435 | 586 | /* $$$ I think this functionality should be handled by verification of |
duke@435 | 587 | RememberedSet::verify_old_oop(obj, p, allow_dirty, false); |
duke@435 | 588 | the card table. */ |
duke@435 | 589 | } |
coleenp@548 | 590 | void Klass::oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty) { } |
duke@435 | 591 | |
duke@435 | 592 | #ifndef PRODUCT |
duke@435 | 593 | |
duke@435 | 594 | void Klass::verify_vtable_index(int i) { |
duke@435 | 595 | assert(oop_is_instance() || oop_is_array(), "only instanceKlass and arrayKlass have vtables"); |
duke@435 | 596 | if (oop_is_instance()) { |
duke@435 | 597 | assert(i>=0 && i<((instanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); |
duke@435 | 598 | } else { |
duke@435 | 599 | assert(i>=0 && i<((arrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); |
duke@435 | 600 | } |
duke@435 | 601 | } |
duke@435 | 602 | |
duke@435 | 603 | #endif |