Wed, 03 Sep 2014 09:25:44 +0200
Merge
duke@435 | 1 | /* |
coleenp@6316 | 2 | * Copyright (c) 1997, 2014, 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" |
coleenp@4037 | 26 | #include "classfile/javaClasses.hpp" |
coleenp@4037 | 27 | #include "classfile/dictionary.hpp" |
stefank@2314 | 28 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 29 | #include "classfile/vmSymbols.hpp" |
coleenp@4037 | 30 | #include "gc_implementation/shared/markSweep.inline.hpp" |
stefank@2314 | 31 | #include "gc_interface/collectedHeap.inline.hpp" |
acorn@4497 | 32 | #include "memory/heapInspection.hpp" |
coleenp@4037 | 33 | #include "memory/metadataFactory.hpp" |
stefank@2314 | 34 | #include "memory/oopFactory.hpp" |
stefank@2314 | 35 | #include "memory/resourceArea.hpp" |
stefank@2314 | 36 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 37 | #include "oops/klass.inline.hpp" |
stefank@2314 | 38 | #include "oops/oop.inline2.hpp" |
goetz@6911 | 39 | #include "runtime/atomic.inline.hpp" |
goetz@6911 | 40 | #include "runtime/orderAccess.inline.hpp" |
sla@5237 | 41 | #include "trace/traceMacros.hpp" |
coleenp@4037 | 42 | #include "utilities/stack.hpp" |
jprovino@4542 | 43 | #include "utilities/macros.hpp" |
jprovino@4542 | 44 | #if INCLUDE_ALL_GCS |
stefank@6992 | 45 | #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
coleenp@4037 | 46 | #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" |
coleenp@4037 | 47 | #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" |
coleenp@4037 | 48 | #include "gc_implementation/parallelScavenge/psScavenge.hpp" |
jprovino@4542 | 49 | #endif // INCLUDE_ALL_GCS |
duke@435 | 50 | |
coleenp@2497 | 51 | void Klass::set_name(Symbol* n) { |
coleenp@2497 | 52 | _name = n; |
coleenp@2497 | 53 | if (_name != NULL) _name->increment_refcount(); |
coleenp@2497 | 54 | } |
duke@435 | 55 | |
minqi@5097 | 56 | bool Klass::is_subclass_of(const Klass* k) const { |
duke@435 | 57 | // Run up the super chain and check |
coleenp@4037 | 58 | if (this == k) return true; |
duke@435 | 59 | |
coleenp@4037 | 60 | Klass* t = const_cast<Klass*>(this)->super(); |
duke@435 | 61 | |
duke@435 | 62 | while (t != NULL) { |
duke@435 | 63 | if (t == k) return true; |
hseigel@4278 | 64 | t = t->super(); |
duke@435 | 65 | } |
duke@435 | 66 | return false; |
duke@435 | 67 | } |
duke@435 | 68 | |
coleenp@4037 | 69 | bool Klass::search_secondary_supers(Klass* k) const { |
duke@435 | 70 | // Put some extra logic here out-of-line, before the search proper. |
duke@435 | 71 | // This cuts down the size of the inline method. |
duke@435 | 72 | |
duke@435 | 73 | // This is necessary, since I am never in my own secondary_super list. |
coleenp@4037 | 74 | if (this == k) |
duke@435 | 75 | return true; |
duke@435 | 76 | // Scan the array-of-objects for a match |
duke@435 | 77 | int cnt = secondary_supers()->length(); |
duke@435 | 78 | for (int i = 0; i < cnt; i++) { |
coleenp@4037 | 79 | if (secondary_supers()->at(i) == k) { |
duke@435 | 80 | ((Klass*)this)->set_secondary_super_cache(k); |
duke@435 | 81 | return true; |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | return false; |
duke@435 | 85 | } |
duke@435 | 86 | |
duke@435 | 87 | // Return self, except for abstract classes with exactly 1 |
duke@435 | 88 | // implementor. Then return the 1 concrete implementation. |
duke@435 | 89 | Klass *Klass::up_cast_abstract() { |
duke@435 | 90 | Klass *r = this; |
duke@435 | 91 | while( r->is_abstract() ) { // Receiver is abstract? |
duke@435 | 92 | Klass *s = r->subklass(); // Check for exactly 1 subklass |
duke@435 | 93 | if( !s || s->next_sibling() ) // Oops; wrong count; give up |
duke@435 | 94 | return this; // Return 'this' as a no-progress flag |
duke@435 | 95 | r = s; // Loop till find concrete class |
duke@435 | 96 | } |
duke@435 | 97 | return r; // Return the 1 concrete class |
duke@435 | 98 | } |
duke@435 | 99 | |
twisti@1040 | 100 | // Find LCA in class hierarchy |
duke@435 | 101 | Klass *Klass::LCA( Klass *k2 ) { |
duke@435 | 102 | Klass *k1 = this; |
duke@435 | 103 | while( 1 ) { |
coleenp@4037 | 104 | if( k1->is_subtype_of(k2) ) return k2; |
coleenp@4037 | 105 | if( k2->is_subtype_of(k1) ) return k1; |
coleenp@4037 | 106 | k1 = k1->super(); |
coleenp@4037 | 107 | k2 = k2->super(); |
duke@435 | 108 | } |
duke@435 | 109 | } |
duke@435 | 110 | |
duke@435 | 111 | |
duke@435 | 112 | void Klass::check_valid_for_instantiation(bool throwError, TRAPS) { |
duke@435 | 113 | ResourceMark rm(THREAD); |
duke@435 | 114 | THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
duke@435 | 115 | : vmSymbols::java_lang_InstantiationException(), external_name()); |
duke@435 | 116 | } |
duke@435 | 117 | |
duke@435 | 118 | |
duke@435 | 119 | void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) { |
duke@435 | 120 | THROW(vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | |
duke@435 | 124 | void Klass::initialize(TRAPS) { |
duke@435 | 125 | ShouldNotReachHere(); |
duke@435 | 126 | } |
duke@435 | 127 | |
coleenp@4037 | 128 | bool Klass::compute_is_subtype_of(Klass* k) { |
duke@435 | 129 | assert(k->is_klass(), "argument must be a class"); |
duke@435 | 130 | return is_subclass_of(k); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | |
lfoltan@6632 | 134 | Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const { |
duke@435 | 135 | #ifdef ASSERT |
duke@435 | 136 | tty->print_cr("Error: uncached_lookup_method called on a klass oop." |
duke@435 | 137 | " Likely error: reflection method does not correctly" |
duke@435 | 138 | " wrap return value in a mirror object."); |
duke@435 | 139 | #endif |
duke@435 | 140 | ShouldNotReachHere(); |
duke@435 | 141 | return NULL; |
duke@435 | 142 | } |
duke@435 | 143 | |
coleenp@5614 | 144 | void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() { |
coleenp@4037 | 145 | return Metaspace::allocate(loader_data, word_size, /*read_only*/false, |
iklam@5208 | 146 | MetaspaceObj::ClassType, CHECK_NULL); |
coleenp@4037 | 147 | } |
coleenp@4037 | 148 | |
coleenp@4037 | 149 | Klass::Klass() { |
coleenp@4037 | 150 | Klass* k = this; |
duke@435 | 151 | |
coleenp@4712 | 152 | // Preinitialize supertype information. |
coleenp@4712 | 153 | // A later call to initialize_supers() may update these settings: |
coleenp@4712 | 154 | set_super(NULL); |
coleenp@4712 | 155 | for (juint i = 0; i < Klass::primary_super_limit(); i++) { |
coleenp@4712 | 156 | _primary_supers[i] = NULL; |
duke@435 | 157 | } |
coleenp@4712 | 158 | set_secondary_supers(NULL); |
coleenp@4712 | 159 | set_secondary_super_cache(NULL); |
coleenp@4712 | 160 | _primary_supers[0] = k; |
coleenp@4712 | 161 | set_super_check_offset(in_bytes(primary_supers_offset())); |
duke@435 | 162 | |
stefank@6992 | 163 | // The constructor is used from init_self_patching_vtbl_list, |
stefank@6992 | 164 | // which doesn't zero out the memory before calling the constructor. |
stefank@6992 | 165 | // Need to set the field explicitly to not hit an assert that the field |
stefank@6992 | 166 | // should be NULL before setting it. |
stefank@6992 | 167 | _java_mirror = NULL; |
stefank@6992 | 168 | |
coleenp@4037 | 169 | set_modifier_flags(0); |
coleenp@4037 | 170 | set_layout_helper(Klass::_lh_neutral_value); |
coleenp@4037 | 171 | set_name(NULL); |
duke@435 | 172 | AccessFlags af; |
duke@435 | 173 | af.set_flags(0); |
coleenp@4037 | 174 | set_access_flags(af); |
coleenp@4037 | 175 | set_subklass(NULL); |
coleenp@4037 | 176 | set_next_sibling(NULL); |
coleenp@4037 | 177 | set_next_link(NULL); |
sla@5237 | 178 | TRACE_INIT_ID(this); |
duke@435 | 179 | |
coleenp@4037 | 180 | set_prototype_header(markOopDesc::prototype()); |
coleenp@4037 | 181 | set_biased_lock_revocation_count(0); |
coleenp@4037 | 182 | set_last_biased_lock_bulk_revocation_time(0); |
duke@435 | 183 | |
coleenp@4037 | 184 | // The klass doesn't have any references at this point. |
coleenp@4037 | 185 | clear_modified_oops(); |
coleenp@4037 | 186 | clear_accumulated_modified_oops(); |
iklam@7089 | 187 | _shared_class_path_index = -1; |
duke@435 | 188 | } |
duke@435 | 189 | |
duke@435 | 190 | jint Klass::array_layout_helper(BasicType etype) { |
duke@435 | 191 | assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype"); |
duke@435 | 192 | // Note that T_ARRAY is not allowed here. |
duke@435 | 193 | int hsize = arrayOopDesc::base_offset_in_bytes(etype); |
kvn@464 | 194 | int esize = type2aelembytes(etype); |
duke@435 | 195 | bool isobj = (etype == T_OBJECT); |
duke@435 | 196 | int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value; |
duke@435 | 197 | int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize)); |
duke@435 | 198 | |
duke@435 | 199 | assert(lh < (int)_lh_neutral_value, "must look like an array layout"); |
coleenp@4037 | 200 | assert(layout_helper_is_array(lh), "correct kind"); |
duke@435 | 201 | assert(layout_helper_is_objArray(lh) == isobj, "correct kind"); |
duke@435 | 202 | assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind"); |
duke@435 | 203 | assert(layout_helper_header_size(lh) == hsize, "correct decode"); |
duke@435 | 204 | assert(layout_helper_element_type(lh) == etype, "correct decode"); |
duke@435 | 205 | assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode"); |
duke@435 | 206 | |
duke@435 | 207 | return lh; |
duke@435 | 208 | } |
duke@435 | 209 | |
duke@435 | 210 | bool Klass::can_be_primary_super_slow() const { |
duke@435 | 211 | if (super() == NULL) |
duke@435 | 212 | return true; |
coleenp@4037 | 213 | else if (super()->super_depth() >= primary_super_limit()-1) |
duke@435 | 214 | return false; |
duke@435 | 215 | else |
duke@435 | 216 | return true; |
duke@435 | 217 | } |
duke@435 | 218 | |
coleenp@4037 | 219 | void Klass::initialize_supers(Klass* k, TRAPS) { |
duke@435 | 220 | if (FastSuperclassLimit == 0) { |
duke@435 | 221 | // None of the other machinery matters. |
duke@435 | 222 | set_super(k); |
duke@435 | 223 | return; |
duke@435 | 224 | } |
duke@435 | 225 | if (k == NULL) { |
duke@435 | 226 | set_super(NULL); |
coleenp@4037 | 227 | _primary_supers[0] = this; |
duke@435 | 228 | assert(super_depth() == 0, "Object must already be initialized properly"); |
never@1577 | 229 | } else if (k != super() || k == SystemDictionary::Object_klass()) { |
never@1577 | 230 | assert(super() == NULL || super() == SystemDictionary::Object_klass(), |
duke@435 | 231 | "initialize this only once to a non-trivial value"); |
duke@435 | 232 | set_super(k); |
coleenp@4037 | 233 | Klass* sup = k; |
duke@435 | 234 | int sup_depth = sup->super_depth(); |
duke@435 | 235 | juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit()); |
duke@435 | 236 | if (!can_be_primary_super_slow()) |
duke@435 | 237 | my_depth = primary_super_limit(); |
duke@435 | 238 | for (juint i = 0; i < my_depth; i++) { |
coleenp@4037 | 239 | _primary_supers[i] = sup->_primary_supers[i]; |
duke@435 | 240 | } |
coleenp@4037 | 241 | Klass* *super_check_cell; |
duke@435 | 242 | if (my_depth < primary_super_limit()) { |
coleenp@4037 | 243 | _primary_supers[my_depth] = this; |
duke@435 | 244 | super_check_cell = &_primary_supers[my_depth]; |
duke@435 | 245 | } else { |
duke@435 | 246 | // Overflow of the primary_supers array forces me to be secondary. |
duke@435 | 247 | super_check_cell = &_secondary_super_cache; |
duke@435 | 248 | } |
coleenp@4037 | 249 | set_super_check_offset((address)super_check_cell - (address) this); |
duke@435 | 250 | |
duke@435 | 251 | #ifdef ASSERT |
duke@435 | 252 | { |
duke@435 | 253 | juint j = super_depth(); |
duke@435 | 254 | assert(j == my_depth, "computed accessor gets right answer"); |
coleenp@4037 | 255 | Klass* t = this; |
hseigel@4278 | 256 | while (!t->can_be_primary_super()) { |
hseigel@4278 | 257 | t = t->super(); |
hseigel@4278 | 258 | j = t->super_depth(); |
duke@435 | 259 | } |
duke@435 | 260 | for (juint j1 = j+1; j1 < primary_super_limit(); j1++) { |
duke@435 | 261 | assert(primary_super_of_depth(j1) == NULL, "super list padding"); |
duke@435 | 262 | } |
duke@435 | 263 | while (t != NULL) { |
duke@435 | 264 | assert(primary_super_of_depth(j) == t, "super list initialization"); |
hseigel@4278 | 265 | t = t->super(); |
duke@435 | 266 | --j; |
duke@435 | 267 | } |
duke@435 | 268 | assert(j == (juint)-1, "correct depth count"); |
duke@435 | 269 | } |
duke@435 | 270 | #endif |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | if (secondary_supers() == NULL) { |
duke@435 | 274 | KlassHandle this_kh (THREAD, this); |
duke@435 | 275 | |
duke@435 | 276 | // Now compute the list of secondary supertypes. |
duke@435 | 277 | // Secondaries can occasionally be on the super chain, |
duke@435 | 278 | // if the inline "_primary_supers" array overflows. |
duke@435 | 279 | int extras = 0; |
coleenp@4037 | 280 | Klass* p; |
coleenp@4037 | 281 | for (p = super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) { |
duke@435 | 282 | ++extras; |
duke@435 | 283 | } |
duke@435 | 284 | |
coleenp@4037 | 285 | ResourceMark rm(THREAD); // need to reclaim GrowableArrays allocated below |
coleenp@4037 | 286 | |
duke@435 | 287 | // Compute the "real" non-extra secondaries. |
coleenp@4037 | 288 | GrowableArray<Klass*>* secondaries = compute_secondary_supers(extras); |
coleenp@4037 | 289 | if (secondaries == NULL) { |
coleenp@4037 | 290 | // secondary_supers set by compute_secondary_supers |
coleenp@4037 | 291 | return; |
coleenp@4037 | 292 | } |
duke@435 | 293 | |
coleenp@4037 | 294 | GrowableArray<Klass*>* primaries = new GrowableArray<Klass*>(extras); |
coleenp@4037 | 295 | |
coleenp@4037 | 296 | for (p = this_kh->super(); !(p == NULL || p->can_be_primary_super()); p = p->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. |
coleenp@4037 | 306 | for( i = 0; i < secondaries->length(); i++ ) { |
coleenp@4037 | 307 | if( secondaries->at(i) == p ) |
duke@435 | 308 | break; |
coleenp@4037 | 309 | } |
duke@435 | 310 | if( i < secondaries->length() ) |
duke@435 | 311 | continue; // It's a dup, don't put it in |
coleenp@4037 | 312 | primaries->push(p); |
duke@435 | 313 | } |
coleenp@4037 | 314 | // Combine the two arrays into a metadata object to pack the array. |
coleenp@4037 | 315 | // The primaries are added in the reverse order, then the secondaries. |
coleenp@4037 | 316 | int new_length = primaries->length() + secondaries->length(); |
coleenp@4037 | 317 | Array<Klass*>* s2 = MetadataFactory::new_array<Klass*>( |
coleenp@4037 | 318 | class_loader_data(), new_length, CHECK); |
coleenp@4037 | 319 | int fill_p = primaries->length(); |
coleenp@4037 | 320 | for (int j = 0; j < fill_p; j++) { |
coleenp@4037 | 321 | s2->at_put(j, primaries->pop()); // add primaries in reverse order. |
coleenp@4037 | 322 | } |
coleenp@4037 | 323 | for( int j = 0; j < secondaries->length(); j++ ) { |
coleenp@4037 | 324 | s2->at_put(j+fill_p, secondaries->at(j)); // add secondaries on the end. |
duke@435 | 325 | } |
duke@435 | 326 | |
duke@435 | 327 | #ifdef ASSERT |
duke@435 | 328 | // We must not copy any NULL placeholders left over from bootstrap. |
coleenp@4037 | 329 | for (int j = 0; j < s2->length(); j++) { |
coleenp@4037 | 330 | assert(s2->at(j) != NULL, "correct bootstrapping order"); |
duke@435 | 331 | } |
duke@435 | 332 | #endif |
duke@435 | 333 | |
coleenp@4037 | 334 | this_kh->set_secondary_supers(s2); |
duke@435 | 335 | } |
duke@435 | 336 | } |
duke@435 | 337 | |
coleenp@4037 | 338 | GrowableArray<Klass*>* Klass::compute_secondary_supers(int num_extra_slots) { |
duke@435 | 339 | assert(num_extra_slots == 0, "override for complex klasses"); |
coleenp@4037 | 340 | set_secondary_supers(Universe::the_empty_klass_array()); |
coleenp@4037 | 341 | return NULL; |
duke@435 | 342 | } |
duke@435 | 343 | |
duke@435 | 344 | |
duke@435 | 345 | Klass* Klass::subklass() const { |
hseigel@4278 | 346 | return _subklass == NULL ? NULL : _subklass; |
duke@435 | 347 | } |
duke@435 | 348 | |
coleenp@4037 | 349 | InstanceKlass* Klass::superklass() const { |
coleenp@4037 | 350 | assert(super() == NULL || super()->oop_is_instance(), "must be instance klass"); |
coleenp@4037 | 351 | return _super == NULL ? NULL : InstanceKlass::cast(_super); |
duke@435 | 352 | } |
duke@435 | 353 | |
duke@435 | 354 | Klass* Klass::next_sibling() const { |
hseigel@4278 | 355 | return _next_sibling == NULL ? NULL : _next_sibling; |
duke@435 | 356 | } |
duke@435 | 357 | |
coleenp@4037 | 358 | void Klass::set_subklass(Klass* s) { |
coleenp@4037 | 359 | assert(s != this, "sanity check"); |
coleenp@4037 | 360 | _subklass = s; |
duke@435 | 361 | } |
duke@435 | 362 | |
coleenp@4037 | 363 | void Klass::set_next_sibling(Klass* s) { |
coleenp@4037 | 364 | assert(s != this, "sanity check"); |
coleenp@4037 | 365 | _next_sibling = s; |
duke@435 | 366 | } |
duke@435 | 367 | |
duke@435 | 368 | void Klass::append_to_sibling_list() { |
coleenp@4178 | 369 | debug_only(verify();) |
duke@435 | 370 | // add ourselves to superklass' subklass list |
coleenp@4037 | 371 | InstanceKlass* super = superklass(); |
duke@435 | 372 | if (super == NULL) return; // special case: class Object |
coleenp@4178 | 373 | assert((!super->is_interface() // interfaces cannot be supers |
duke@435 | 374 | && (super->superklass() == NULL || !is_interface())), |
duke@435 | 375 | "an interface can only be a subklass of Object"); |
coleenp@4037 | 376 | Klass* prev_first_subklass = super->subklass_oop(); |
duke@435 | 377 | if (prev_first_subklass != NULL) { |
duke@435 | 378 | // set our sibling to be the superklass' previous first subklass |
duke@435 | 379 | set_next_sibling(prev_first_subklass); |
duke@435 | 380 | } |
duke@435 | 381 | // make ourselves the superklass' first subklass |
coleenp@4037 | 382 | super->set_subklass(this); |
coleenp@4178 | 383 | debug_only(verify();) |
duke@435 | 384 | } |
duke@435 | 385 | |
coleenp@4037 | 386 | bool Klass::is_loader_alive(BoolObjectClosure* is_alive) { |
coleenp@4304 | 387 | #ifdef ASSERT |
coleenp@4037 | 388 | // The class is alive iff the class loader is alive. |
coleenp@4037 | 389 | oop loader = class_loader(); |
coleenp@4304 | 390 | bool loader_alive = (loader == NULL) || is_alive->do_object_b(loader); |
coleenp@4304 | 391 | #endif // ASSERT |
coleenp@4304 | 392 | |
coleenp@4304 | 393 | // The class is alive if it's mirror is alive (which should be marked if the |
coleenp@4304 | 394 | // loader is alive) unless it's an anoymous class. |
coleenp@4304 | 395 | bool mirror_alive = is_alive->do_object_b(java_mirror()); |
coleenp@4304 | 396 | assert(!mirror_alive || loader_alive, "loader must be alive if the mirror is" |
coleenp@4304 | 397 | " but not the other way around with anonymous classes"); |
coleenp@4304 | 398 | return mirror_alive; |
coleenp@4037 | 399 | } |
coleenp@4037 | 400 | |
stefank@6992 | 401 | void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses) { |
coleenp@4037 | 402 | if (!ClassUnloading) { |
coleenp@4037 | 403 | return; |
coleenp@4037 | 404 | } |
coleenp@4037 | 405 | |
coleenp@4037 | 406 | Klass* root = SystemDictionary::Object_klass(); |
coleenp@4037 | 407 | Stack<Klass*, mtGC> stack; |
coleenp@4037 | 408 | |
coleenp@4037 | 409 | stack.push(root); |
coleenp@4037 | 410 | while (!stack.is_empty()) { |
coleenp@4037 | 411 | Klass* current = stack.pop(); |
coleenp@4037 | 412 | |
coleenp@4037 | 413 | assert(current->is_loader_alive(is_alive), "just checking, this should be live"); |
coleenp@4037 | 414 | |
coleenp@4037 | 415 | // Find and set the first alive subklass |
coleenp@4037 | 416 | Klass* sub = current->subklass_oop(); |
coleenp@4037 | 417 | while (sub != NULL && !sub->is_loader_alive(is_alive)) { |
duke@435 | 418 | #ifndef PRODUCT |
coleenp@4304 | 419 | if (TraceClassUnloading && WizardMode) { |
coleenp@4304 | 420 | ResourceMark rm; |
coleenp@4037 | 421 | tty->print_cr("[Unlinking class (subclass) %s]", sub->external_name()); |
coleenp@4304 | 422 | } |
duke@435 | 423 | #endif |
coleenp@4037 | 424 | sub = sub->next_sibling_oop(); |
duke@435 | 425 | } |
coleenp@4037 | 426 | current->set_subklass(sub); |
coleenp@4037 | 427 | if (sub != NULL) { |
coleenp@4037 | 428 | stack.push(sub); |
coleenp@4037 | 429 | } |
coleenp@4037 | 430 | |
coleenp@4037 | 431 | // Find and set the first alive sibling |
coleenp@4037 | 432 | Klass* sibling = current->next_sibling_oop(); |
coleenp@4037 | 433 | while (sibling != NULL && !sibling->is_loader_alive(is_alive)) { |
coleenp@4304 | 434 | if (TraceClassUnloading && WizardMode) { |
coleenp@4304 | 435 | ResourceMark rm; |
coleenp@4037 | 436 | tty->print_cr("[Unlinking class (sibling) %s]", sibling->external_name()); |
coleenp@4304 | 437 | } |
coleenp@4037 | 438 | sibling = sibling->next_sibling_oop(); |
coleenp@4304 | 439 | } |
coleenp@4037 | 440 | current->set_next_sibling(sibling); |
coleenp@4037 | 441 | if (sibling != NULL) { |
coleenp@4037 | 442 | stack.push(sibling); |
coleenp@4304 | 443 | } |
coleenp@4037 | 444 | |
coleenp@4037 | 445 | // Clean the implementors list and method data. |
stefank@6992 | 446 | if (clean_alive_klasses && current->oop_is_instance()) { |
coleenp@4037 | 447 | InstanceKlass* ik = InstanceKlass::cast(current); |
coleenp@4037 | 448 | ik->clean_implementors_list(is_alive); |
coleenp@4037 | 449 | ik->clean_method_data(is_alive); |
duke@435 | 450 | } |
duke@435 | 451 | } |
duke@435 | 452 | } |
duke@435 | 453 | |
coleenp@4037 | 454 | void Klass::klass_update_barrier_set(oop v) { |
coleenp@4037 | 455 | record_modified_oops(); |
coleenp@4037 | 456 | } |
coleenp@4037 | 457 | |
stefank@6992 | 458 | // This barrier is used by G1 to remember the old oop values, so |
stefank@6992 | 459 | // that we don't forget any objects that were live at the snapshot at |
stefank@6992 | 460 | // the beginning. This function is only used when we write oops into Klasses. |
stefank@6992 | 461 | void Klass::klass_update_barrier_set_pre(oop* p, oop v) { |
stefank@6992 | 462 | #if INCLUDE_ALL_GCS |
stefank@6992 | 463 | if (UseG1GC) { |
stefank@6992 | 464 | oop obj = *p; |
stefank@6992 | 465 | if (obj != NULL) { |
stefank@6992 | 466 | G1SATBCardTableModRefBS::enqueue(obj); |
stefank@6992 | 467 | } |
stefank@6992 | 468 | } |
stefank@6992 | 469 | #endif |
coleenp@4037 | 470 | } |
coleenp@4037 | 471 | |
coleenp@4037 | 472 | void Klass::klass_oop_store(oop* p, oop v) { |
coleenp@4037 | 473 | assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata"); |
coleenp@4037 | 474 | assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object"); |
coleenp@4037 | 475 | |
coleenp@4037 | 476 | // do the store |
coleenp@4037 | 477 | if (always_do_update_barrier) { |
coleenp@4037 | 478 | klass_oop_store((volatile oop*)p, v); |
coleenp@4037 | 479 | } else { |
stefank@6992 | 480 | klass_update_barrier_set_pre(p, v); |
coleenp@4037 | 481 | *p = v; |
coleenp@4037 | 482 | klass_update_barrier_set(v); |
coleenp@4037 | 483 | } |
coleenp@4037 | 484 | } |
coleenp@4037 | 485 | |
coleenp@4037 | 486 | void Klass::klass_oop_store(volatile oop* p, oop v) { |
coleenp@4037 | 487 | assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata"); |
coleenp@4037 | 488 | assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object"); |
coleenp@4037 | 489 | |
stefank@6992 | 490 | klass_update_barrier_set_pre((oop*)p, v); // Cast away volatile. |
coleenp@4037 | 491 | OrderAccess::release_store_ptr(p, v); |
coleenp@4037 | 492 | klass_update_barrier_set(v); |
coleenp@4037 | 493 | } |
coleenp@4037 | 494 | |
coleenp@4037 | 495 | void Klass::oops_do(OopClosure* cl) { |
coleenp@4037 | 496 | cl->do_oop(&_java_mirror); |
coleenp@4037 | 497 | } |
duke@435 | 498 | |
duke@435 | 499 | void Klass::remove_unshareable_info() { |
coleenp@6626 | 500 | assert (DumpSharedSpaces, "only called for DumpSharedSpaces"); |
coleenp@6626 | 501 | |
duke@435 | 502 | set_subklass(NULL); |
duke@435 | 503 | set_next_sibling(NULL); |
coleenp@4037 | 504 | // Clear the java mirror |
coleenp@4037 | 505 | set_java_mirror(NULL); |
coleenp@4037 | 506 | set_next_link(NULL); |
coleenp@4037 | 507 | |
coleenp@4037 | 508 | // Null out class_loader_data because we don't share that yet. |
coleenp@4037 | 509 | set_class_loader_data(NULL); |
duke@435 | 510 | } |
duke@435 | 511 | |
iklam@7089 | 512 | void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
mgronlun@6659 | 513 | TRACE_INIT_ID(this); |
coleenp@6626 | 514 | // If an exception happened during CDS restore, some of these fields may already be |
coleenp@6626 | 515 | // set. We leave the class on the CLD list, even if incomplete so that we don't |
coleenp@6626 | 516 | // modify the CLD list outside a safepoint. |
coleenp@6626 | 517 | if (class_loader_data() == NULL) { |
iklam@7089 | 518 | // Restore class_loader_data |
coleenp@6626 | 519 | set_class_loader_data(loader_data); |
duke@435 | 520 | |
iklam@7089 | 521 | // Add to class loader list first before creating the mirror |
coleenp@6626 | 522 | // (same order as class file parsing) |
coleenp@6626 | 523 | loader_data->add_class(this); |
coleenp@6626 | 524 | } |
coleenp@4037 | 525 | |
iklam@7089 | 526 | // Recreate the class mirror. |
coleenp@6626 | 527 | // Only recreate it if not present. A previous attempt to restore may have |
coleenp@6626 | 528 | // gotten an OOM later but keep the mirror if it was created. |
coleenp@6626 | 529 | if (java_mirror() == NULL) { |
iklam@7089 | 530 | java_lang_Class::create_mirror(this, protection_domain, CHECK); |
coleenp@6626 | 531 | } |
coleenp@2497 | 532 | } |
coleenp@2497 | 533 | |
coleenp@4037 | 534 | Klass* Klass::array_klass_or_null(int rank) { |
duke@435 | 535 | EXCEPTION_MARK; |
duke@435 | 536 | // No exception can be thrown by array_klass_impl when called with or_null == true. |
duke@435 | 537 | // (In anycase, the execption mark will fail if it do so) |
duke@435 | 538 | return array_klass_impl(true, rank, THREAD); |
duke@435 | 539 | } |
duke@435 | 540 | |
duke@435 | 541 | |
coleenp@4037 | 542 | Klass* Klass::array_klass_or_null() { |
duke@435 | 543 | EXCEPTION_MARK; |
duke@435 | 544 | // No exception can be thrown by array_klass_impl when called with or_null == true. |
duke@435 | 545 | // (In anycase, the execption mark will fail if it do so) |
duke@435 | 546 | return array_klass_impl(true, THREAD); |
duke@435 | 547 | } |
duke@435 | 548 | |
duke@435 | 549 | |
coleenp@4037 | 550 | Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) { |
coleenp@4142 | 551 | fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); |
duke@435 | 552 | return NULL; |
duke@435 | 553 | } |
duke@435 | 554 | |
duke@435 | 555 | |
coleenp@4037 | 556 | Klass* Klass::array_klass_impl(bool or_null, TRAPS) { |
coleenp@4142 | 557 | fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); |
duke@435 | 558 | return NULL; |
duke@435 | 559 | } |
duke@435 | 560 | |
coleenp@4037 | 561 | oop Klass::class_loader() const { return class_loader_data()->class_loader(); } |
coleenp@4037 | 562 | |
duke@435 | 563 | const char* Klass::external_name() const { |
jrose@866 | 564 | if (oop_is_instance()) { |
coleenp@4037 | 565 | InstanceKlass* ik = (InstanceKlass*) this; |
jrose@866 | 566 | if (ik->is_anonymous()) { |
twisti@2698 | 567 | assert(EnableInvokeDynamic, ""); |
coleenp@4304 | 568 | intptr_t hash = 0; |
coleenp@4304 | 569 | if (ik->java_mirror() != NULL) { |
coleenp@4304 | 570 | // java_mirror might not be created yet, return 0 as hash. |
coleenp@4304 | 571 | hash = ik->java_mirror()->identity_hash(); |
coleenp@4304 | 572 | } |
jrose@866 | 573 | char hash_buf[40]; |
jrose@866 | 574 | sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash); |
jrose@866 | 575 | size_t hash_len = strlen(hash_buf); |
jrose@866 | 576 | |
jrose@866 | 577 | size_t result_len = name()->utf8_length(); |
jrose@866 | 578 | char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1); |
jrose@866 | 579 | name()->as_klass_external_name(result, (int) result_len + 1); |
jrose@866 | 580 | assert(strlen(result) == result_len, ""); |
jrose@866 | 581 | strcpy(result + result_len, hash_buf); |
jrose@866 | 582 | assert(strlen(result) == result_len + hash_len, ""); |
jrose@866 | 583 | return result; |
jrose@866 | 584 | } |
jrose@866 | 585 | } |
jrose@1474 | 586 | if (name() == NULL) return "<unknown>"; |
duke@435 | 587 | return name()->as_klass_external_name(); |
duke@435 | 588 | } |
duke@435 | 589 | |
duke@435 | 590 | |
jrose@1474 | 591 | const char* Klass::signature_name() const { |
jrose@1474 | 592 | if (name() == NULL) return "<unknown>"; |
duke@435 | 593 | return name()->as_C_string(); |
duke@435 | 594 | } |
duke@435 | 595 | |
duke@435 | 596 | // Unless overridden, modifier_flags is 0. |
duke@435 | 597 | jint Klass::compute_modifier_flags(TRAPS) const { |
duke@435 | 598 | return 0; |
duke@435 | 599 | } |
duke@435 | 600 | |
duke@435 | 601 | int Klass::atomic_incr_biased_lock_revocation_count() { |
duke@435 | 602 | return (int) Atomic::add(1, &_biased_lock_revocation_count); |
duke@435 | 603 | } |
duke@435 | 604 | |
duke@435 | 605 | // Unless overridden, jvmti_class_status has no flags set. |
duke@435 | 606 | jint Klass::jvmti_class_status() const { |
duke@435 | 607 | return 0; |
duke@435 | 608 | } |
duke@435 | 609 | |
coleenp@4037 | 610 | |
duke@435 | 611 | // Printing |
duke@435 | 612 | |
coleenp@4037 | 613 | void Klass::print_on(outputStream* st) const { |
coleenp@4037 | 614 | ResourceMark rm; |
coleenp@4037 | 615 | // print title |
coleenp@4037 | 616 | st->print("%s", internal_name()); |
coleenp@4037 | 617 | print_address_on(st); |
coleenp@4037 | 618 | st->cr(); |
coleenp@4037 | 619 | } |
coleenp@4037 | 620 | |
duke@435 | 621 | void Klass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 622 | ResourceMark rm; |
duke@435 | 623 | // print title |
duke@435 | 624 | st->print_cr("%s ", internal_name()); |
duke@435 | 625 | obj->print_address_on(st); |
duke@435 | 626 | |
duke@435 | 627 | if (WizardMode) { |
duke@435 | 628 | // print header |
duke@435 | 629 | obj->mark()->print_on(st); |
duke@435 | 630 | } |
duke@435 | 631 | |
duke@435 | 632 | // print class |
duke@435 | 633 | st->print(" - klass: "); |
duke@435 | 634 | obj->klass()->print_value_on(st); |
duke@435 | 635 | st->cr(); |
duke@435 | 636 | } |
duke@435 | 637 | |
duke@435 | 638 | void Klass::oop_print_value_on(oop obj, outputStream* st) { |
duke@435 | 639 | // print title |
duke@435 | 640 | ResourceMark rm; // Cannot print in debug mode without this |
duke@435 | 641 | st->print("%s", internal_name()); |
duke@435 | 642 | obj->print_address_on(st); |
duke@435 | 643 | } |
duke@435 | 644 | |
acorn@4497 | 645 | #if INCLUDE_SERVICES |
acorn@4497 | 646 | // Size Statistics |
acorn@4497 | 647 | void Klass::collect_statistics(KlassSizeStats *sz) const { |
acorn@4497 | 648 | sz->_klass_bytes = sz->count(this); |
acorn@4497 | 649 | sz->_mirror_bytes = sz->count(java_mirror()); |
acorn@4497 | 650 | sz->_secondary_supers_bytes = sz->count_array(secondary_supers()); |
acorn@4497 | 651 | |
acorn@4497 | 652 | sz->_ro_bytes += sz->_secondary_supers_bytes; |
acorn@4497 | 653 | sz->_rw_bytes += sz->_klass_bytes + sz->_mirror_bytes; |
acorn@4497 | 654 | } |
acorn@4497 | 655 | #endif // INCLUDE_SERVICES |
coleenp@4037 | 656 | |
duke@435 | 657 | // Verification |
duke@435 | 658 | |
coleenp@6316 | 659 | void Klass::verify_on(outputStream* st) { |
coleenp@4037 | 660 | |
coleenp@5307 | 661 | // This can be expensive, but it is worth checking that this klass is actually |
coleenp@5307 | 662 | // in the CLD graph but not in production. |
coleenp@6678 | 663 | assert(Metaspace::contains((address)this), "Should be"); |
coleenp@4037 | 664 | |
coleenp@4037 | 665 | guarantee(this->is_klass(),"should be klass"); |
coleenp@4037 | 666 | |
coleenp@4037 | 667 | if (super() != NULL) { |
coleenp@4037 | 668 | guarantee(super()->is_klass(), "should be klass"); |
coleenp@4037 | 669 | } |
coleenp@4037 | 670 | if (secondary_super_cache() != NULL) { |
coleenp@4037 | 671 | Klass* ko = secondary_super_cache(); |
coleenp@4037 | 672 | guarantee(ko->is_klass(), "should be klass"); |
coleenp@4037 | 673 | } |
coleenp@4037 | 674 | for ( uint i = 0; i < primary_super_limit(); i++ ) { |
coleenp@4037 | 675 | Klass* ko = _primary_supers[i]; |
coleenp@4037 | 676 | if (ko != NULL) { |
coleenp@4037 | 677 | guarantee(ko->is_klass(), "should be klass"); |
coleenp@4037 | 678 | } |
coleenp@4037 | 679 | } |
coleenp@4037 | 680 | |
coleenp@4037 | 681 | if (java_mirror() != NULL) { |
coleenp@4037 | 682 | guarantee(java_mirror()->is_oop(), "should be instance"); |
coleenp@4037 | 683 | } |
coleenp@4037 | 684 | } |
coleenp@4037 | 685 | |
duke@435 | 686 | void Klass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 687 | guarantee(obj->is_oop(), "should be oop"); |
duke@435 | 688 | guarantee(obj->klass()->is_klass(), "klass field is not a klass"); |
duke@435 | 689 | } |
duke@435 | 690 | |
duke@435 | 691 | #ifndef PRODUCT |
duke@435 | 692 | |
drchase@5732 | 693 | bool Klass::verify_vtable_index(int i) { |
duke@435 | 694 | if (oop_is_instance()) { |
drchase@5732 | 695 | int limit = ((InstanceKlass*)this)->vtable_length()/vtableEntry::size(); |
drchase@5732 | 696 | assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); |
duke@435 | 697 | } else { |
coleenp@4037 | 698 | assert(oop_is_array(), "Must be"); |
drchase@5732 | 699 | int limit = ((ArrayKlass*)this)->vtable_length()/vtableEntry::size(); |
drchase@5732 | 700 | assert(i >= 0 && i < limit, err_msg("index %d out of bounds %d", i, limit)); |
duke@435 | 701 | } |
drchase@5732 | 702 | return true; |
drchase@5732 | 703 | } |
drchase@5732 | 704 | |
drchase@5732 | 705 | bool Klass::verify_itable_index(int i) { |
drchase@5732 | 706 | assert(oop_is_instance(), ""); |
drchase@5732 | 707 | int method_count = klassItable::method_count_for_interface(this); |
drchase@5732 | 708 | assert(i >= 0 && i < method_count, "index out of bounds"); |
drchase@5732 | 709 | return true; |
duke@435 | 710 | } |
duke@435 | 711 | |
duke@435 | 712 | #endif |
stefank@6976 | 713 | |
stefank@6976 | 714 | /////////////// Unit tests /////////////// |
stefank@6976 | 715 | |
stefank@6976 | 716 | #ifndef PRODUCT |
stefank@6976 | 717 | |
stefank@6976 | 718 | class TestKlass { |
stefank@6976 | 719 | public: |
stefank@6976 | 720 | static void test_oop_is_instanceClassLoader() { |
stefank@6976 | 721 | assert(SystemDictionary::ClassLoader_klass()->oop_is_instanceClassLoader(), "assert"); |
stefank@6976 | 722 | assert(!SystemDictionary::String_klass()->oop_is_instanceClassLoader(), "assert"); |
stefank@6976 | 723 | } |
stefank@6976 | 724 | }; |
stefank@6976 | 725 | |
stefank@6976 | 726 | void TestKlass_test() { |
stefank@6976 | 727 | TestKlass::test_oop_is_instanceClassLoader(); |
stefank@6976 | 728 | } |
stefank@6976 | 729 | |
stefank@6976 | 730 | #endif |