1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)instanceKlassKlass.cpp 1.157 07/07/27 16:19:58 JVM" 3 #endif 4 /* 5 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 # include "incls/_precompiled.incl" 29 # include "incls/_instanceKlassKlass.cpp.incl" 30 31 klassOop instanceKlassKlass::create_klass(TRAPS) { 32 instanceKlassKlass o; 33 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); 34 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); 35 // Make sure size calculation is right 36 assert(k()->size() == align_object_size(header_size()), "wrong size for object"); 37 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror 38 return k(); 39 } 40 41 int instanceKlassKlass::oop_size(oop obj) const { 42 assert(obj->is_klass(), "must be klass"); 43 return instanceKlass::cast(klassOop(obj))->object_size(); 44 } 45 46 bool instanceKlassKlass::oop_is_parsable(oop obj) const { 47 assert(obj->is_klass(), "must be klass"); 48 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 49 return (!ik->null_vtbl()) && ik->object_is_parsable(); 50 } 51 52 void instanceKlassKlass::iterate_c_heap_oops(instanceKlass* ik, 53 OopClosure* closure) { 54 if (ik->oop_map_cache() != NULL) { 55 ik->oop_map_cache()->oop_iterate(closure); 56 } 57 58 if (ik->jni_ids() != NULL) { 59 ik->jni_ids()->oops_do(closure); 60 } 61 } 62 63 void instanceKlassKlass::oop_follow_contents(oop obj) { 64 assert(obj->is_klass(),"must be a klass"); 65 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass"); 66 67 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 68 ik->follow_static_fields(); 69 { 70 HandleMark hm; 71 ik->vtable()->oop_follow_contents(); 72 ik->itable()->oop_follow_contents(); 73 } 74 75 MarkSweep::mark_and_push(ik->adr_array_klasses()); 76 MarkSweep::mark_and_push(ik->adr_methods()); 77 MarkSweep::mark_and_push(ik->adr_method_ordering()); 78 MarkSweep::mark_and_push(ik->adr_local_interfaces()); 79 MarkSweep::mark_and_push(ik->adr_transitive_interfaces()); 80 MarkSweep::mark_and_push(ik->adr_fields()); 81 MarkSweep::mark_and_push(ik->adr_constants()); 82 MarkSweep::mark_and_push(ik->adr_class_loader()); 83 MarkSweep::mark_and_push(ik->adr_source_file_name()); 84 MarkSweep::mark_and_push(ik->adr_source_debug_extension()); 85 MarkSweep::mark_and_push(ik->adr_inner_classes()); 86 MarkSweep::mark_and_push(ik->adr_protection_domain()); 87 MarkSweep::mark_and_push(ik->adr_host_klass()); 88 MarkSweep::mark_and_push(ik->adr_signers()); 89 MarkSweep::mark_and_push(ik->adr_generic_signature()); 90 MarkSweep::mark_and_push(ik->adr_class_annotations()); 91 MarkSweep::mark_and_push(ik->adr_fields_annotations()); 92 MarkSweep::mark_and_push(ik->adr_methods_annotations()); 93 MarkSweep::mark_and_push(ik->adr_methods_parameter_annotations()); 94 MarkSweep::mark_and_push(ik->adr_methods_default_annotations()); 95 96 // We do not follow adr_implementors() here. It is followed later 97 // in instanceKlass::follow_weak_klass_links() 98 99 klassKlass::oop_follow_contents(obj); 100 101 iterate_c_heap_oops(ik, &MarkSweep::mark_and_push_closure); 102 } 103 104 #ifndef SERIALGC 105 void instanceKlassKlass::oop_follow_contents(ParCompactionManager* cm, 106 oop obj) { 107 assert(obj->is_klass(),"must be a klass"); 108 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass"); 109 110 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 111 ik->follow_static_fields(cm); 112 ik->vtable()->oop_follow_contents(cm); 113 ik->itable()->oop_follow_contents(cm); 114 115 PSParallelCompact::mark_and_push(cm, ik->adr_array_klasses()); 116 PSParallelCompact::mark_and_push(cm, ik->adr_methods()); 117 PSParallelCompact::mark_and_push(cm, ik->adr_method_ordering()); 118 PSParallelCompact::mark_and_push(cm, ik->adr_local_interfaces()); 119 PSParallelCompact::mark_and_push(cm, ik->adr_transitive_interfaces()); 120 PSParallelCompact::mark_and_push(cm, ik->adr_fields()); 121 PSParallelCompact::mark_and_push(cm, ik->adr_constants()); 122 PSParallelCompact::mark_and_push(cm, ik->adr_class_loader()); 123 PSParallelCompact::mark_and_push(cm, ik->adr_source_file_name()); 124 PSParallelCompact::mark_and_push(cm, ik->adr_source_debug_extension()); 125 PSParallelCompact::mark_and_push(cm, ik->adr_inner_classes()); 126 PSParallelCompact::mark_and_push(cm, ik->adr_protection_domain()); 127 PSParallelCompact::mark_and_push(cm, ik->adr_host_klass()); 128 PSParallelCompact::mark_and_push(cm, ik->adr_signers()); 129 PSParallelCompact::mark_and_push(cm, ik->adr_generic_signature()); 130 PSParallelCompact::mark_and_push(cm, ik->adr_class_annotations()); 131 PSParallelCompact::mark_and_push(cm, ik->adr_fields_annotations()); 132 PSParallelCompact::mark_and_push(cm, ik->adr_methods_annotations()); 133 PSParallelCompact::mark_and_push(cm, ik->adr_methods_parameter_annotations()); 134 PSParallelCompact::mark_and_push(cm, ik->adr_methods_default_annotations()); 135 136 // We do not follow adr_implementor() here. It is followed later 137 // in instanceKlass::follow_weak_klass_links() 138 139 klassKlass::oop_follow_contents(cm, obj); 140 141 PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); 142 iterate_c_heap_oops(ik, &mark_and_push_closure); 143 } 144 #endif // SERIALGC 145 146 int instanceKlassKlass::oop_oop_iterate(oop obj, OopClosure* blk) { 147 assert(obj->is_klass(),"must be a klass"); 148 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass"); 149 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 150 // Get size before changing pointers. 151 // Don't call size() or oop_size() since that is a virtual call. 152 int size = ik->object_size(); 153 154 ik->iterate_static_fields(blk); 155 ik->vtable()->oop_oop_iterate(blk); 156 ik->itable()->oop_oop_iterate(blk); 157 158 blk->do_oop(ik->adr_array_klasses()); 159 blk->do_oop(ik->adr_methods()); 160 blk->do_oop(ik->adr_method_ordering()); 161 blk->do_oop(ik->adr_local_interfaces()); 162 blk->do_oop(ik->adr_transitive_interfaces()); 163 blk->do_oop(ik->adr_fields()); 164 blk->do_oop(ik->adr_constants()); 165 blk->do_oop(ik->adr_class_loader()); 166 blk->do_oop(ik->adr_protection_domain()); 167 blk->do_oop(ik->adr_host_klass()); 168 blk->do_oop(ik->adr_signers()); 169 blk->do_oop(ik->adr_source_file_name()); 170 blk->do_oop(ik->adr_source_debug_extension()); 171 blk->do_oop(ik->adr_inner_classes()); 172 for (int i = 0; i < instanceKlass::implementors_limit; i++) { 173 blk->do_oop(&ik->adr_implementors()[i]); 174 } 175 blk->do_oop(ik->adr_generic_signature()); 176 blk->do_oop(ik->adr_class_annotations()); 177 blk->do_oop(ik->adr_fields_annotations()); 178 blk->do_oop(ik->adr_methods_annotations()); 179 blk->do_oop(ik->adr_methods_parameter_annotations()); 180 blk->do_oop(ik->adr_methods_default_annotations()); 181 182 klassKlass::oop_oop_iterate(obj, blk); 183 184 if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk); 185 return size; 186 } 187 188 int instanceKlassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, 189 MemRegion mr) { 190 assert(obj->is_klass(),"must be a klass"); 191 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass"); 192 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 193 // Get size before changing pointers. 194 // Don't call size() or oop_size() since that is a virtual call. 195 int size = ik->object_size(); 196 197 ik->iterate_static_fields(blk, mr); 198 ik->vtable()->oop_oop_iterate_m(blk, mr); 199 ik->itable()->oop_oop_iterate_m(blk, mr); 200 201 oop* adr; 202 adr = ik->adr_array_klasses(); 203 if (mr.contains(adr)) blk->do_oop(adr); 204 adr = ik->adr_methods(); 205 if (mr.contains(adr)) blk->do_oop(adr); 206 adr = ik->adr_method_ordering(); 207 if (mr.contains(adr)) blk->do_oop(adr); 208 adr = ik->adr_local_interfaces(); 209 if (mr.contains(adr)) blk->do_oop(adr); 210 adr = ik->adr_transitive_interfaces(); 211 if (mr.contains(adr)) blk->do_oop(adr); 212 adr = ik->adr_fields(); 213 if (mr.contains(adr)) blk->do_oop(adr); 214 adr = ik->adr_constants(); 215 if (mr.contains(adr)) blk->do_oop(adr); 216 adr = ik->adr_class_loader(); 217 if (mr.contains(adr)) blk->do_oop(adr); 218 adr = ik->adr_protection_domain(); 219 if (mr.contains(adr)) blk->do_oop(adr); 220 adr = ik->adr_host_klass(); 221 if (mr.contains(adr)) blk->do_oop(adr); 222 adr = ik->adr_signers(); 223 if (mr.contains(adr)) blk->do_oop(adr); 224 adr = ik->adr_source_file_name(); 225 if (mr.contains(adr)) blk->do_oop(adr); 226 adr = ik->adr_source_debug_extension(); 227 if (mr.contains(adr)) blk->do_oop(adr); 228 adr = ik->adr_inner_classes(); 229 if (mr.contains(adr)) blk->do_oop(adr); 230 adr = ik->adr_implementors(); 231 for (int i = 0; i < instanceKlass::implementors_limit; i++) { 232 if (mr.contains(&adr[i])) blk->do_oop(&adr[i]); 233 } 234 adr = ik->adr_generic_signature(); 235 if (mr.contains(adr)) blk->do_oop(adr); 236 adr = ik->adr_class_annotations(); 237 if (mr.contains(adr)) blk->do_oop(adr); 238 adr = ik->adr_fields_annotations(); 239 if (mr.contains(adr)) blk->do_oop(adr); 240 adr = ik->adr_methods_annotations(); 241 if (mr.contains(adr)) blk->do_oop(adr); 242 adr = ik->adr_methods_parameter_annotations(); 243 if (mr.contains(adr)) blk->do_oop(adr); 244 adr = ik->adr_methods_default_annotations(); 245 if (mr.contains(adr)) blk->do_oop(adr); 246 247 klassKlass::oop_oop_iterate_m(obj, blk, mr); 248 249 if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk, mr); 250 return size; 251 } 252 253 int instanceKlassKlass::oop_adjust_pointers(oop obj) { 254 assert(obj->is_klass(),"must be a klass"); 255 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass"); 256 257 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 258 ik->adjust_static_fields(); 259 ik->vtable()->oop_adjust_pointers(); 260 ik->itable()->oop_adjust_pointers(); 261 262 MarkSweep::adjust_pointer(ik->adr_array_klasses()); 263 MarkSweep::adjust_pointer(ik->adr_methods()); 264 MarkSweep::adjust_pointer(ik->adr_method_ordering()); 265 MarkSweep::adjust_pointer(ik->adr_local_interfaces()); 266 MarkSweep::adjust_pointer(ik->adr_transitive_interfaces()); 267 MarkSweep::adjust_pointer(ik->adr_fields()); 268 MarkSweep::adjust_pointer(ik->adr_constants()); 269 MarkSweep::adjust_pointer(ik->adr_class_loader()); 270 MarkSweep::adjust_pointer(ik->adr_protection_domain()); 271 MarkSweep::adjust_pointer(ik->adr_host_klass()); 272 MarkSweep::adjust_pointer(ik->adr_signers()); 273 MarkSweep::adjust_pointer(ik->adr_source_file_name()); 274 MarkSweep::adjust_pointer(ik->adr_source_debug_extension()); 275 MarkSweep::adjust_pointer(ik->adr_inner_classes()); 276 for (int i = 0; i < instanceKlass::implementors_limit; i++) { 277 MarkSweep::adjust_pointer(&ik->adr_implementors()[i]); 278 } 279 MarkSweep::adjust_pointer(ik->adr_generic_signature()); 280 MarkSweep::adjust_pointer(ik->adr_class_annotations()); 281 MarkSweep::adjust_pointer(ik->adr_fields_annotations()); 282 MarkSweep::adjust_pointer(ik->adr_methods_annotations()); 283 MarkSweep::adjust_pointer(ik->adr_methods_parameter_annotations()); 284 MarkSweep::adjust_pointer(ik->adr_methods_default_annotations()); 285 286 iterate_c_heap_oops(ik, &MarkSweep::adjust_root_pointer_closure); 287 288 return klassKlass::oop_adjust_pointers(obj); 289 } 290 291 #ifndef SERIALGC 292 void instanceKlassKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) { 293 assert(!pm->depth_first(), "invariant"); 294 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 295 ik->copy_static_fields(pm); 296 297 oop* loader_addr = ik->adr_class_loader(); 298 if (PSScavenge::should_scavenge(loader_addr)) { 299 pm->claim_or_forward_breadth(loader_addr); 300 } 301 302 oop* pd_addr = ik->adr_protection_domain(); 303 if (PSScavenge::should_scavenge(pd_addr)) { 304 pm->claim_or_forward_breadth(pd_addr); 305 } 306 307 oop* hk_addr = ik->adr_host_klass(); 308 if (PSScavenge::should_scavenge(hk_addr)) { 309 pm->claim_or_forward_breadth(hk_addr); 310 } 311 312 oop* sg_addr = ik->adr_signers(); 313 if (PSScavenge::should_scavenge(sg_addr)) { 314 pm->claim_or_forward_breadth(sg_addr); 315 } 316 317 klassKlass::oop_copy_contents(pm, obj); 318 } 319 320 void instanceKlassKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { 321 assert(pm->depth_first(), "invariant"); 322 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 323 ik->push_static_fields(pm); 324 325 oop* loader_addr = ik->adr_class_loader(); 326 if (PSScavenge::should_scavenge(loader_addr)) { 327 pm->claim_or_forward_depth(loader_addr); 328 } 329 330 oop* pd_addr = ik->adr_protection_domain(); 331 if (PSScavenge::should_scavenge(pd_addr)) { 332 pm->claim_or_forward_depth(pd_addr); 333 } 334 335 oop* hk_addr = ik->adr_host_klass(); 336 if (PSScavenge::should_scavenge(hk_addr)) { 337 pm->claim_or_forward_depth(hk_addr); 338 } 339 340 oop* sg_addr = ik->adr_signers(); 341 if (PSScavenge::should_scavenge(sg_addr)) { 342 pm->claim_or_forward_depth(sg_addr); 343 } 344 345 klassKlass::oop_copy_contents(pm, obj); 346 } 347 348 int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { 349 assert(obj->is_klass(),"must be a klass"); 350 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), 351 "must be instance klass"); 352 353 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 354 ik->update_static_fields(); 355 ik->vtable()->oop_update_pointers(cm); 356 ik->itable()->oop_update_pointers(cm); 357 358 oop* const beg_oop = ik->oop_block_beg(); 359 oop* const end_oop = ik->oop_block_end(); 360 for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { 361 PSParallelCompact::adjust_pointer(cur_oop); 362 } 363 364 OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure(); 365 iterate_c_heap_oops(ik, closure); 366 367 klassKlass::oop_update_pointers(cm, obj); 368 return ik->object_size(); 369 } 370 371 int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, 372 HeapWord* beg_addr, 373 HeapWord* end_addr) { 374 assert(obj->is_klass(),"must be a klass"); 375 assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), 376 "must be instance klass"); 377 378 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 379 ik->update_static_fields(beg_addr, end_addr); 380 ik->vtable()->oop_update_pointers(cm, beg_addr, end_addr); 381 ik->itable()->oop_update_pointers(cm, beg_addr, end_addr); 382 383 oop* const beg_oop = MAX2((oop*)beg_addr, ik->oop_block_beg()); 384 oop* const end_oop = MIN2((oop*)end_addr, ik->oop_block_end()); 385 for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { 386 PSParallelCompact::adjust_pointer(cur_oop); 387 } 388 389 // The oop_map_cache, jni_ids and jni_id_map are allocated from the C heap, 390 // and so don't lie within any 'Chunk' boundaries. Update them when the 391 // lowest addressed oop in the instanceKlass 'oop_block' is updated. 392 if (beg_oop == ik->oop_block_beg()) { 393 OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure(); 394 iterate_c_heap_oops(ik, closure); 395 } 396 397 klassKlass::oop_update_pointers(cm, obj, beg_addr, end_addr); 398 return ik->object_size(); 399 } 400 #endif // SERIALGC 401 402 klassOop instanceKlassKlass::allocate_instance_klass(int vtable_len, int itable_len, int static_field_size, 403 int nonstatic_oop_map_size, ReferenceType rt, TRAPS) { 404 405 int size = instanceKlass::object_size(align_object_offset(vtable_len) + align_object_offset(itable_len) + static_field_size + nonstatic_oop_map_size); 406 407 // Allocation 408 KlassHandle h_this_klass(THREAD, as_klassOop()); 409 KlassHandle k; 410 if (rt == REF_NONE) { 411 // regular klass 412 instanceKlass o; 413 k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL); 414 } else { 415 // reference klass 416 instanceRefKlass o; 417 k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL); 418 } 419 { 420 No_Safepoint_Verifier no_safepoint; // until k becomes parsable 421 instanceKlass* ik = (instanceKlass*) k()->klass_part(); 422 assert(!k()->is_parsable(), "not expecting parsability yet."); 423 424 // The sizes of these these three variables are used for determining the 425 // size of the instanceKlassOop. It is critical that these are set to the right 426 // sizes before the first GC, i.e., when we allocate the mirror. 427 ik->set_vtable_length(vtable_len); 428 ik->set_itable_length(itable_len); 429 ik->set_static_field_size(static_field_size); 430 ik->set_nonstatic_oop_map_size(nonstatic_oop_map_size); 431 assert(k()->size() == size, "wrong size for object"); 432 433 ik->set_array_klasses(NULL); 434 ik->set_methods(NULL); 435 ik->set_method_ordering(NULL); 436 ik->set_local_interfaces(NULL); 437 ik->set_transitive_interfaces(NULL); 438 ik->init_implementor(); 439 ik->set_fields(NULL); 440 ik->set_constants(NULL); 441 ik->set_class_loader(NULL); 442 ik->set_protection_domain(NULL); 443 ik->set_host_klass(NULL); 444 ik->set_signers(NULL); 445 ik->set_source_file_name(NULL); 446 ik->set_source_debug_extension(NULL); 447 ik->set_inner_classes(NULL); 448 ik->set_static_oop_field_size(0); 449 ik->set_nonstatic_field_size(0); 450 ik->set_is_marked_dependent(false); 451 ik->set_init_state(instanceKlass::allocated); 452 ik->set_init_thread(NULL); 453 ik->set_reference_type(rt); 454 ik->set_oop_map_cache(NULL); 455 ik->set_jni_ids(NULL); 456 ik->set_osr_nmethods_head(NULL); 457 ik->set_breakpoints(NULL); 458 ik->init_previous_versions(); 459 ik->set_generic_signature(NULL); 460 ik->release_set_methods_jmethod_ids(NULL); 461 ik->release_set_methods_cached_itable_indices(NULL); 462 ik->set_class_annotations(NULL); 463 ik->set_fields_annotations(NULL); 464 ik->set_methods_annotations(NULL); 465 ik->set_methods_parameter_annotations(NULL); 466 ik->set_methods_default_annotations(NULL); 467 ik->set_enclosing_method_indices(0, 0); 468 ik->set_jvmti_cached_class_field_map(NULL); 469 ik->set_initial_method_idnum(0); 470 assert(k()->is_parsable(), "should be parsable here."); 471 472 // initialize the non-header words to zero 473 intptr_t* p = (intptr_t*)k(); 474 for (int index = instanceKlass::header_size(); index < size; index++) { 475 p[index] = NULL_WORD; 476 } 477 478 // To get verify to work - must be set to partial loaded before first GC point. 479 k()->set_partially_loaded(); 480 } 481 482 // GC can happen here 483 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror 484 return k(); 485 } 486 487 488 489 #ifndef PRODUCT 490 491 // Printing 492 493 static const char* state_names[] = { 494 "unparseable_by_gc", "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" 495 }; 496 497 498 void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) { 499 assert(obj->is_klass(), "must be klass"); 500 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 501 klassKlass::oop_print_on(obj, st); 502 503 st->print(" - instance size: %d", ik->size_helper()); st->cr(); 504 st->print(" - klass size: %d", ik->object_size()); st->cr(); 505 st->print(" - access: "); ik->access_flags().print_on(st); st->cr(); 506 st->print(" - state: "); st->print_cr(state_names[ik->_init_state]); 507 st->print(" - name: "); ik->name()->print_value_on(st); st->cr(); 508 st->print(" - super: "); ik->super()->print_value_on(st); st->cr(); 509 st->print(" - sub: "); 510 Klass* sub = ik->subklass(); 511 int n; 512 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) { 513 if (n < MaxSubklassPrintSize) { 514 sub->as_klassOop()->print_value_on(st); 515 st->print(" "); 516 } 517 } 518 if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize); 519 st->cr(); 520 521 if (ik->is_interface()) { 522 st->print_cr(" - nof implementors: %d", ik->nof_implementors()); 523 int print_impl = 0; 524 for (int i = 0; i < instanceKlass::implementors_limit; i++) { 525 if (ik->implementor(i) != NULL) { 526 if (++print_impl == 1) 527 st->print_cr(" - implementor: "); 528 st->print(" "); 529 ik->implementor(i)->print_value_on(st); 530 } 531 } 532 if (print_impl > 0) st->cr(); 533 } 534 535 st->print(" - arrays: "); ik->array_klasses()->print_value_on(st); st->cr(); 536 st->print(" - methods: "); ik->methods()->print_value_on(st); st->cr(); 537 if (Verbose) { 538 objArrayOop methods = ik->methods(); 539 for(int i = 0; i < methods->length(); i++) { 540 tty->print("%d : ", i); methods->obj_at(i)->print_value(); tty->cr(); 541 } 542 } 543 st->print(" - method ordering: "); ik->method_ordering()->print_value_on(st); st->cr(); 544 st->print(" - local interfaces: "); ik->local_interfaces()->print_value_on(st); st->cr(); 545 st->print(" - trans. interfaces: "); ik->transitive_interfaces()->print_value_on(st); st->cr(); 546 st->print(" - constants: "); ik->constants()->print_value_on(st); st->cr(); 547 st->print(" - class loader: "); ik->class_loader()->print_value_on(st); st->cr(); 548 st->print(" - protection domain: "); ik->protection_domain()->print_value_on(st); st->cr(); 549 st->print(" - host class: "); ik->host_klass()->print_value_on(st); st->cr(); 550 st->print(" - signers: "); ik->signers()->print_value_on(st); st->cr(); 551 if (ik->source_file_name() != NULL) { 552 st->print(" - source file: "); 553 ik->source_file_name()->print_value_on(st); 554 st->cr(); 555 } 556 if (ik->source_debug_extension() != NULL) { 557 st->print(" - source debug extension: "); 558 ik->source_debug_extension()->print_value_on(st); 559 st->cr(); 560 } 561 562 st->print_cr(" - previous version: "); 563 { 564 ResourceMark rm; 565 // PreviousVersionInfo objects returned via PreviousVersionWalker 566 // contain a GrowableArray of handles. We have to clean up the 567 // GrowableArray _after_ the PreviousVersionWalker destructor 568 // has destroyed the handles. 569 { 570 PreviousVersionWalker pvw(ik); 571 for (PreviousVersionInfo * pv_info = pvw.next_previous_version(); 572 pv_info != NULL; pv_info = pvw.next_previous_version()) { 573 pv_info->prev_constant_pool_handle()()->print_value_on(st); 574 } 575 st->cr(); 576 } // pvw is cleaned up 577 } // rm is cleaned up 578 579 if (ik->generic_signature() != NULL) { 580 st->print(" - generic signature: "); 581 ik->generic_signature()->print_value_on(st); 582 } 583 st->print(" - inner classes: "); ik->inner_classes()->print_value_on(st); st->cr(); 584 st->print(" - java mirror: "); ik->java_mirror()->print_value_on(st); st->cr(); 585 st->print(" - vtable length %d (start addr: " INTPTR_FORMAT ")", ik->vtable_length(), ik->start_of_vtable()); st->cr(); 586 st->print(" - itable length %d (start addr: " INTPTR_FORMAT ")", ik->itable_length(), ik->start_of_itable()); st->cr(); 587 st->print_cr(" - static fields:"); 588 FieldPrinter print_static_field(st); 589 ik->do_local_static_fields(&print_static_field); 590 st->print_cr(" - non-static fields:"); 591 FieldPrinter print_nonstatic_field(st, obj); 592 ik->do_nonstatic_fields(&print_nonstatic_field); 593 594 st->print(" - static oop maps: "); 595 if (ik->static_oop_field_size() > 0) { 596 int first_offset = ik->offset_of_static_fields(); 597 st->print("%d-%d", first_offset, first_offset + ik->static_oop_field_size() - 1); 598 } 599 st->cr(); 600 601 st->print(" - non-static oop maps: "); 602 OopMapBlock* map = ik->start_of_nonstatic_oop_maps(); 603 OopMapBlock* end_map = map + ik->nonstatic_oop_map_size(); 604 while (map < end_map) { 605 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->length() - 1)); 606 map++; 607 } 608 st->cr(); 609 } 610 611 612 void instanceKlassKlass::oop_print_value_on(oop obj, outputStream* st) { 613 assert(obj->is_klass(), "must be klass"); 614 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 615 ik->name()->print_value_on(st); 616 } 617 618 #endif // PRODUCT 619 620 const char* instanceKlassKlass::internal_name() const { 621 return "{instance class}"; 622 } 623 624 // Verification 625 626 class VerifyFieldClosure: public OopClosure { 627 protected: 628 template <class T> void do_oop_work(T* p) { 629 guarantee(Universe::heap()->is_in(p), "should be in heap"); 630 oop obj = oopDesc::load_decode_heap_oop(p); 631 guarantee(obj->is_oop_or_null(), "should be in heap"); 632 } 633 public: 634 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } 635 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } 636 }; 637 638 void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) { 639 klassKlass::oop_verify_on(obj, st); 640 if (!obj->partially_loaded()) { 641 Thread *thread = Thread::current(); 642 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 643 644 #ifndef PRODUCT 645 // Avoid redundant verifies 646 if (ik->_verify_count == Universe::verify_count()) return; 647 ik->_verify_count = Universe::verify_count(); 648 #endif 649 // Verify that klass is present in SystemDictionary 650 if (ik->is_loaded() && !ik->is_anonymous()) { 651 symbolHandle h_name (thread, ik->name()); 652 Handle h_loader (thread, ik->class_loader()); 653 Handle h_obj(thread, obj); 654 SystemDictionary::verify_obj_klass_present(h_obj, h_name, h_loader); 655 } 656 657 // Verify static fields 658 VerifyFieldClosure blk; 659 ik->iterate_static_fields(&blk); 660 661 // Verify vtables 662 if (ik->is_linked()) { 663 ResourceMark rm(thread); 664 // $$$ This used to be done only for m/s collections. Doing it 665 // always seemed a valid generalization. (DLD -- 6/00) 666 ik->vtable()->verify(st); 667 } 668 669 // Verify oop map cache 670 if (ik->oop_map_cache() != NULL) { 671 ik->oop_map_cache()->verify(); 672 } 673 674 // Verify first subklass 675 if (ik->subklass_oop() != NULL) { 676 guarantee(ik->subklass_oop()->is_perm(), "should be in permspace"); 677 guarantee(ik->subklass_oop()->is_klass(), "should be klass"); 678 } 679 680 // Verify siblings 681 klassOop super = ik->super(); 682 Klass* sib = ik->next_sibling(); 683 int sib_count = 0; 684 while (sib != NULL) { 685 if (sib == ik) { 686 fatal1("subclass cycle of length %d", sib_count); 687 } 688 if (sib_count >= 100000) { 689 fatal1("suspiciously long subclass list %d", sib_count); 690 } 691 guarantee(sib->as_klassOop()->is_klass(), "should be klass"); 692 guarantee(sib->as_klassOop()->is_perm(), "should be in permspace"); 693 guarantee(sib->super() == super, "siblings should have same superklass"); 694 sib = sib->next_sibling(); 695 } 696 697 // Verify implementor fields 698 bool saw_null_impl = false; 699 for (int i = 0; i < instanceKlass::implementors_limit; i++) { 700 klassOop im = ik->implementor(i); 701 if (im == NULL) { saw_null_impl = true; continue; } 702 guarantee(!saw_null_impl, "non-nulls must preceded all nulls"); 703 guarantee(ik->is_interface(), "only interfaces should have implementor set"); 704 guarantee(i < ik->nof_implementors(), "should only have one implementor"); 705 guarantee(im->is_perm(), "should be in permspace"); 706 guarantee(im->is_klass(), "should be klass"); 707 guarantee(!Klass::cast(klassOop(im))->is_interface(), "implementors cannot be interfaces"); 708 } 709 710 // Verify local interfaces 711 objArrayOop local_interfaces = ik->local_interfaces(); 712 guarantee(local_interfaces->is_perm(), "should be in permspace"); 713 guarantee(local_interfaces->is_objArray(), "should be obj array"); 714 int j; 715 for (j = 0; j < local_interfaces->length(); j++) { 716 oop e = local_interfaces->obj_at(j); 717 guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid local interface"); 718 } 719 720 // Verify transitive interfaces 721 objArrayOop transitive_interfaces = ik->transitive_interfaces(); 722 guarantee(transitive_interfaces->is_perm(), "should be in permspace"); 723 guarantee(transitive_interfaces->is_objArray(), "should be obj array"); 724 for (j = 0; j < transitive_interfaces->length(); j++) { 725 oop e = transitive_interfaces->obj_at(j); 726 guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid transitive interface"); 727 } 728 729 // Verify methods 730 objArrayOop methods = ik->methods(); 731 guarantee(methods->is_perm(), "should be in permspace"); 732 guarantee(methods->is_objArray(), "should be obj array"); 733 for (j = 0; j < methods->length(); j++) { 734 guarantee(methods->obj_at(j)->is_method(), "non-method in methods array"); 735 } 736 for (j = 0; j < methods->length() - 1; j++) { 737 methodOop m1 = methodOop(methods->obj_at(j)); 738 methodOop m2 = methodOop(methods->obj_at(j + 1)); 739 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly"); 740 } 741 742 // Verify method ordering 743 typeArrayOop method_ordering = ik->method_ordering(); 744 guarantee(method_ordering->is_perm(), "should be in permspace"); 745 guarantee(method_ordering->is_typeArray(), "should be type array"); 746 int length = method_ordering->length(); 747 if (JvmtiExport::can_maintain_original_method_order()) { 748 guarantee(length == methods->length(), "invalid method ordering length"); 749 jlong sum = 0; 750 for (j = 0; j < length; j++) { 751 int original_index = method_ordering->int_at(j); 752 guarantee(original_index >= 0 && original_index < length, "invalid method ordering index"); 753 sum += original_index; 754 } 755 // Verify sum of indices 0,1,...,length-1 756 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); 757 } else { 758 guarantee(length == 0, "invalid method ordering length"); 759 } 760 761 // Verify JNI static field identifiers 762 if (ik->jni_ids() != NULL) { 763 ik->jni_ids()->verify(ik->as_klassOop()); 764 } 765 766 // Verify other fields 767 if (ik->array_klasses() != NULL) { 768 guarantee(ik->array_klasses()->is_perm(), "should be in permspace"); 769 guarantee(ik->array_klasses()->is_klass(), "should be klass"); 770 } 771 guarantee(ik->fields()->is_perm(), "should be in permspace"); 772 guarantee(ik->fields()->is_typeArray(), "should be type array"); 773 guarantee(ik->constants()->is_perm(), "should be in permspace"); 774 guarantee(ik->constants()->is_constantPool(), "should be constant pool"); 775 guarantee(ik->inner_classes()->is_perm(), "should be in permspace"); 776 guarantee(ik->inner_classes()->is_typeArray(), "should be type array"); 777 if (ik->source_file_name() != NULL) { 778 guarantee(ik->source_file_name()->is_perm(), "should be in permspace"); 779 guarantee(ik->source_file_name()->is_symbol(), "should be symbol"); 780 } 781 if (ik->source_debug_extension() != NULL) { 782 guarantee(ik->source_debug_extension()->is_perm(), "should be in permspace"); 783 guarantee(ik->source_debug_extension()->is_symbol(), "should be symbol"); 784 } 785 if (ik->protection_domain() != NULL) { 786 guarantee(ik->protection_domain()->is_oop(), "should be oop"); 787 } 788 if (ik->host_klass() != NULL) { 789 guarantee(ik->host_klass()->is_oop(), "should be oop"); 790 } 791 if (ik->signers() != NULL) { 792 guarantee(ik->signers()->is_objArray(), "should be obj array"); 793 } 794 if (ik->generic_signature() != NULL) { 795 guarantee(ik->generic_signature()->is_perm(), "should be in permspace"); 796 guarantee(ik->generic_signature()->is_symbol(), "should be symbol"); 797 } 798 if (ik->class_annotations() != NULL) { 799 guarantee(ik->class_annotations()->is_typeArray(), "should be type array"); 800 } 801 if (ik->fields_annotations() != NULL) { 802 guarantee(ik->fields_annotations()->is_objArray(), "should be obj array"); 803 } 804 if (ik->methods_annotations() != NULL) { 805 guarantee(ik->methods_annotations()->is_objArray(), "should be obj array"); 806 } 807 if (ik->methods_parameter_annotations() != NULL) { 808 guarantee(ik->methods_parameter_annotations()->is_objArray(), "should be obj array"); 809 } 810 if (ik->methods_default_annotations() != NULL) { 811 guarantee(ik->methods_default_annotations()->is_objArray(), "should be obj array"); 812 } 813 } 814 } 815 816 817 bool instanceKlassKlass::oop_partially_loaded(oop obj) const { 818 assert(obj->is_klass(), "object must be klass"); 819 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 820 assert(ik->oop_is_instance(), "object must be instanceKlass"); 821 return ik->transitive_interfaces() == (objArrayOop) obj; // Check whether transitive_interfaces points to self 822 } 823 824 825 // The transitive_interfaces is the last field set when loading an object. 826 void instanceKlassKlass::oop_set_partially_loaded(oop obj) { 827 assert(obj->is_klass(), "object must be klass"); 828 instanceKlass* ik = instanceKlass::cast(klassOop(obj)); 829 // Set the layout helper to a place-holder value, until fuller initialization. 830 // (This allows asserts in oop_is_instance to succeed.) 831 ik->set_layout_helper(Klass::instance_layout_helper(0, true)); 832 assert(ik->oop_is_instance(), "object must be instanceKlass"); 833 assert(ik->transitive_interfaces() == NULL, "just checking"); 834 ik->set_transitive_interfaces((objArrayOop) obj); // Temporarily set transitive_interfaces to point to self 835 } 836