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