src/share/vm/oops/instanceKlassKlass.cpp

Wed, 17 Mar 2010 11:01:05 +0100

author
fparain
date
Wed, 17 Mar 2010 11:01:05 +0100
changeset 1759
e392695de029
parent 1590
4e6abf09f540
child 1845
f03d0a26bf83
permissions
-rw-r--r--

6935224: Adding new DTrace probes to work with Palantir
Summary: Adding probes related to thread scheduling and class initialization
Reviewed-by: kamg, never

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

mercurial