src/share/vm/oops/instanceKlassKlass.cpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 866
a45484ea312d
child 1161
be93aad57795
permissions
-rw-r--r--

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

mercurial