src/share/vm/oops/instanceKlassKlass.cpp

Wed, 30 Mar 2011 07:47:19 -0700

author
never
date
Wed, 30 Mar 2011 07:47:19 -0700
changeset 2693
63997f575155
parent 2658
c7f3d0b4570f
child 2742
ed69575596ac
permissions
-rw-r--r--

7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
Reviewed-by: kvn, dcubed

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "classfile/javaClasses.hpp"
    27 #include "classfile/systemDictionary.hpp"
    28 #include "gc_implementation/shared/markSweep.inline.hpp"
    29 #include "gc_interface/collectedHeap.inline.hpp"
    30 #include "interpreter/oopMapCache.hpp"
    31 #include "memory/gcLocker.hpp"
    32 #include "oops/constantPoolOop.hpp"
    33 #include "oops/instanceKlass.hpp"
    34 #include "oops/instanceMirrorKlass.hpp"
    35 #include "oops/instanceKlassKlass.hpp"
    36 #include "oops/instanceRefKlass.hpp"
    37 #include "oops/objArrayKlassKlass.hpp"
    38 #include "oops/objArrayOop.hpp"
    39 #include "oops/oop.inline.hpp"
    40 #include "oops/oop.inline2.hpp"
    41 #include "oops/symbol.hpp"
    42 #include "oops/typeArrayOop.hpp"
    43 #include "prims/jvmtiExport.hpp"
    44 #include "runtime/fieldDescriptor.hpp"
    45 #ifndef SERIALGC
    46 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
    47 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
    48 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
    49 #include "memory/cardTableRS.hpp"
    50 #include "oops/oop.pcgc.inline.hpp"
    51 #endif
    53 klassOop instanceKlassKlass::create_klass(TRAPS) {
    54   instanceKlassKlass o;
    55   KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
    56   KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
    57   // Make sure size calculation is right
    58   assert(k()->size() == align_object_size(header_size()), "wrong size for object");
    59   java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
    60   return k();
    61 }
    63 int instanceKlassKlass::oop_size(oop obj) const {
    64   assert(obj->is_klass(), "must be klass");
    65   return instanceKlass::cast(klassOop(obj))->object_size();
    66 }
    68 bool instanceKlassKlass::oop_is_parsable(oop obj) const {
    69   assert(obj->is_klass(), "must be klass");
    70   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
    71   return (!ik->null_vtbl()) && ik->object_is_parsable();
    72 }
    74 void instanceKlassKlass::iterate_c_heap_oops(instanceKlass* ik,
    75                                              OopClosure* closure) {
    76   if (ik->oop_map_cache() != NULL) {
    77     ik->oop_map_cache()->oop_iterate(closure);
    78   }
    80   if (ik->jni_ids() != NULL) {
    81     ik->jni_ids()->oops_do(closure);
    82   }
    83 }
    85 void instanceKlassKlass::oop_follow_contents(oop obj) {
    86   assert(obj->is_klass(),"must be a klass");
    87   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
    89   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
    90   {
    91     HandleMark hm;
    92     ik->vtable()->oop_follow_contents();
    93     ik->itable()->oop_follow_contents();
    94   }
    96   MarkSweep::mark_and_push(ik->adr_array_klasses());
    97   MarkSweep::mark_and_push(ik->adr_methods());
    98   MarkSweep::mark_and_push(ik->adr_method_ordering());
    99   MarkSweep::mark_and_push(ik->adr_local_interfaces());
   100   MarkSweep::mark_and_push(ik->adr_transitive_interfaces());
   101   MarkSweep::mark_and_push(ik->adr_fields());
   102   MarkSweep::mark_and_push(ik->adr_constants());
   103   MarkSweep::mark_and_push(ik->adr_class_loader());
   104   MarkSweep::mark_and_push(ik->adr_inner_classes());
   105   MarkSweep::mark_and_push(ik->adr_protection_domain());
   106   MarkSweep::mark_and_push(ik->adr_host_klass());
   107   MarkSweep::mark_and_push(ik->adr_signers());
   108   MarkSweep::mark_and_push(ik->adr_bootstrap_method());
   109   MarkSweep::mark_and_push(ik->adr_class_annotations());
   110   MarkSweep::mark_and_push(ik->adr_fields_annotations());
   111   MarkSweep::mark_and_push(ik->adr_methods_annotations());
   112   MarkSweep::mark_and_push(ik->adr_methods_parameter_annotations());
   113   MarkSweep::mark_and_push(ik->adr_methods_default_annotations());
   115   // We do not follow adr_implementors() here. It is followed later
   116   // in instanceKlass::follow_weak_klass_links()
   118   klassKlass::oop_follow_contents(obj);
   120   iterate_c_heap_oops(ik, &MarkSweep::mark_and_push_closure);
   121 }
   123 #ifndef SERIALGC
   124 void instanceKlassKlass::oop_follow_contents(ParCompactionManager* cm,
   125                                              oop obj) {
   126   assert(obj->is_klass(),"must be a klass");
   127   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   129   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   130   ik->vtable()->oop_follow_contents(cm);
   131   ik->itable()->oop_follow_contents(cm);
   133   PSParallelCompact::mark_and_push(cm, ik->adr_array_klasses());
   134   PSParallelCompact::mark_and_push(cm, ik->adr_methods());
   135   PSParallelCompact::mark_and_push(cm, ik->adr_method_ordering());
   136   PSParallelCompact::mark_and_push(cm, ik->adr_local_interfaces());
   137   PSParallelCompact::mark_and_push(cm, ik->adr_transitive_interfaces());
   138   PSParallelCompact::mark_and_push(cm, ik->adr_fields());
   139   PSParallelCompact::mark_and_push(cm, ik->adr_constants());
   140   PSParallelCompact::mark_and_push(cm, ik->adr_class_loader());
   141   PSParallelCompact::mark_and_push(cm, ik->adr_inner_classes());
   142   PSParallelCompact::mark_and_push(cm, ik->adr_protection_domain());
   143   PSParallelCompact::mark_and_push(cm, ik->adr_host_klass());
   144   PSParallelCompact::mark_and_push(cm, ik->adr_signers());
   145   PSParallelCompact::mark_and_push(cm, ik->adr_bootstrap_method());
   146   PSParallelCompact::mark_and_push(cm, ik->adr_class_annotations());
   147   PSParallelCompact::mark_and_push(cm, ik->adr_fields_annotations());
   148   PSParallelCompact::mark_and_push(cm, ik->adr_methods_annotations());
   149   PSParallelCompact::mark_and_push(cm, ik->adr_methods_parameter_annotations());
   150   PSParallelCompact::mark_and_push(cm, ik->adr_methods_default_annotations());
   152   // We do not follow adr_implementor() here. It is followed later
   153   // in instanceKlass::follow_weak_klass_links()
   155   klassKlass::oop_follow_contents(cm, obj);
   157   PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm);
   158   iterate_c_heap_oops(ik, &mark_and_push_closure);
   159 }
   160 #endif // SERIALGC
   162 int instanceKlassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
   163   assert(obj->is_klass(),"must be a klass");
   164   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   165   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   166   // Get size before changing pointers.
   167   // Don't call size() or oop_size() since that is a virtual call.
   168   int size = ik->object_size();
   170   ik->vtable()->oop_oop_iterate(blk);
   171   ik->itable()->oop_oop_iterate(blk);
   173   blk->do_oop(ik->adr_array_klasses());
   174   blk->do_oop(ik->adr_methods());
   175   blk->do_oop(ik->adr_method_ordering());
   176   blk->do_oop(ik->adr_local_interfaces());
   177   blk->do_oop(ik->adr_transitive_interfaces());
   178   blk->do_oop(ik->adr_fields());
   179   blk->do_oop(ik->adr_constants());
   180   blk->do_oop(ik->adr_class_loader());
   181   blk->do_oop(ik->adr_protection_domain());
   182   blk->do_oop(ik->adr_host_klass());
   183   blk->do_oop(ik->adr_signers());
   184   blk->do_oop(ik->adr_inner_classes());
   185   for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   186     blk->do_oop(&ik->adr_implementors()[i]);
   187   }
   188   blk->do_oop(ik->adr_bootstrap_method());
   189   blk->do_oop(ik->adr_class_annotations());
   190   blk->do_oop(ik->adr_fields_annotations());
   191   blk->do_oop(ik->adr_methods_annotations());
   192   blk->do_oop(ik->adr_methods_parameter_annotations());
   193   blk->do_oop(ik->adr_methods_default_annotations());
   195   klassKlass::oop_oop_iterate(obj, blk);
   197   if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk);
   198   return size;
   199 }
   201 int instanceKlassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk,
   202                                            MemRegion mr) {
   203   assert(obj->is_klass(),"must be a klass");
   204   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   205   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   206   // Get size before changing pointers.
   207   // Don't call size() or oop_size() since that is a virtual call.
   208   int size = ik->object_size();
   210   ik->vtable()->oop_oop_iterate_m(blk, mr);
   211   ik->itable()->oop_oop_iterate_m(blk, mr);
   213   oop* adr;
   214   adr = ik->adr_array_klasses();
   215   if (mr.contains(adr)) blk->do_oop(adr);
   216   adr = ik->adr_methods();
   217   if (mr.contains(adr)) blk->do_oop(adr);
   218   adr = ik->adr_method_ordering();
   219   if (mr.contains(adr)) blk->do_oop(adr);
   220   adr = ik->adr_local_interfaces();
   221   if (mr.contains(adr)) blk->do_oop(adr);
   222   adr = ik->adr_transitive_interfaces();
   223   if (mr.contains(adr)) blk->do_oop(adr);
   224   adr = ik->adr_fields();
   225   if (mr.contains(adr)) blk->do_oop(adr);
   226   adr = ik->adr_constants();
   227   if (mr.contains(adr)) blk->do_oop(adr);
   228   adr = ik->adr_class_loader();
   229   if (mr.contains(adr)) blk->do_oop(adr);
   230   adr = ik->adr_protection_domain();
   231   if (mr.contains(adr)) blk->do_oop(adr);
   232   adr = ik->adr_host_klass();
   233   if (mr.contains(adr)) blk->do_oop(adr);
   234   adr = ik->adr_signers();
   235   if (mr.contains(adr)) blk->do_oop(adr);
   236   adr = ik->adr_inner_classes();
   237   if (mr.contains(adr)) blk->do_oop(adr);
   238   adr = ik->adr_implementors();
   239   for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   240     if (mr.contains(&adr[i])) blk->do_oop(&adr[i]);
   241   }
   242   adr = ik->adr_bootstrap_method();
   243   if (mr.contains(adr)) blk->do_oop(adr);
   244   adr = ik->adr_class_annotations();
   245   if (mr.contains(adr)) blk->do_oop(adr);
   246   adr = ik->adr_fields_annotations();
   247   if (mr.contains(adr)) blk->do_oop(adr);
   248   adr = ik->adr_methods_annotations();
   249   if (mr.contains(adr)) blk->do_oop(adr);
   250   adr = ik->adr_methods_parameter_annotations();
   251   if (mr.contains(adr)) blk->do_oop(adr);
   252   adr = ik->adr_methods_default_annotations();
   253   if (mr.contains(adr)) blk->do_oop(adr);
   255   klassKlass::oop_oop_iterate_m(obj, blk, mr);
   257   if(ik->oop_map_cache() != NULL) ik->oop_map_cache()->oop_iterate(blk, mr);
   258   return size;
   259 }
   261 int instanceKlassKlass::oop_adjust_pointers(oop obj) {
   262   assert(obj->is_klass(),"must be a klass");
   263   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(), "must be instance klass");
   265   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   266   ik->vtable()->oop_adjust_pointers();
   267   ik->itable()->oop_adjust_pointers();
   269   MarkSweep::adjust_pointer(ik->adr_array_klasses());
   270   MarkSweep::adjust_pointer(ik->adr_methods());
   271   MarkSweep::adjust_pointer(ik->adr_method_ordering());
   272   MarkSweep::adjust_pointer(ik->adr_local_interfaces());
   273   MarkSweep::adjust_pointer(ik->adr_transitive_interfaces());
   274   MarkSweep::adjust_pointer(ik->adr_fields());
   275   MarkSweep::adjust_pointer(ik->adr_constants());
   276   MarkSweep::adjust_pointer(ik->adr_class_loader());
   277   MarkSweep::adjust_pointer(ik->adr_protection_domain());
   278   MarkSweep::adjust_pointer(ik->adr_host_klass());
   279   MarkSweep::adjust_pointer(ik->adr_signers());
   280   MarkSweep::adjust_pointer(ik->adr_inner_classes());
   281   for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   282     MarkSweep::adjust_pointer(&ik->adr_implementors()[i]);
   283   }
   284   MarkSweep::adjust_pointer(ik->adr_bootstrap_method());
   285   MarkSweep::adjust_pointer(ik->adr_class_annotations());
   286   MarkSweep::adjust_pointer(ik->adr_fields_annotations());
   287   MarkSweep::adjust_pointer(ik->adr_methods_annotations());
   288   MarkSweep::adjust_pointer(ik->adr_methods_parameter_annotations());
   289   MarkSweep::adjust_pointer(ik->adr_methods_default_annotations());
   291   iterate_c_heap_oops(ik, &MarkSweep::adjust_root_pointer_closure);
   293   return klassKlass::oop_adjust_pointers(obj);
   294 }
   296 #ifndef SERIALGC
   297 void instanceKlassKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
   298   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   300   oop* loader_addr = ik->adr_class_loader();
   301   if (PSScavenge::should_scavenge(loader_addr)) {
   302     pm->claim_or_forward_depth(loader_addr);
   303   }
   305   oop* pd_addr = ik->adr_protection_domain();
   306   if (PSScavenge::should_scavenge(pd_addr)) {
   307     pm->claim_or_forward_depth(pd_addr);
   308   }
   310   oop* hk_addr = ik->adr_host_klass();
   311   if (PSScavenge::should_scavenge(hk_addr)) {
   312     pm->claim_or_forward_depth(hk_addr);
   313   }
   315   oop* sg_addr = ik->adr_signers();
   316   if (PSScavenge::should_scavenge(sg_addr)) {
   317     pm->claim_or_forward_depth(sg_addr);
   318   }
   320   oop* bsm_addr = ik->adr_bootstrap_method();
   321   if (PSScavenge::should_scavenge(bsm_addr)) {
   322     pm->claim_or_forward_depth(bsm_addr);
   323   }
   325   klassKlass::oop_push_contents(pm, obj);
   326 }
   328 int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   329   assert(obj->is_klass(),"must be a klass");
   330   assert(klassOop(obj)->klass_part()->oop_is_instance_slow(),
   331          "must be instance klass");
   333   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   334   ik->vtable()->oop_update_pointers(cm);
   335   ik->itable()->oop_update_pointers(cm);
   337   oop* const beg_oop = ik->oop_block_beg();
   338   oop* const end_oop = ik->oop_block_end();
   339   for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
   340     PSParallelCompact::adjust_pointer(cur_oop);
   341   }
   343   OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure();
   344   iterate_c_heap_oops(ik, closure);
   346   klassKlass::oop_update_pointers(cm, obj);
   347   return ik->object_size();
   348 }
   350 #endif // SERIALGC
   352 klassOop
   353 instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int itable_len,
   354                                             int static_field_size,
   355                                             unsigned nonstatic_oop_map_count,
   356                                             ReferenceType rt, TRAPS) {
   358   const int nonstatic_oop_map_size =
   359     instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count);
   360   int size = instanceKlass::object_size(align_object_offset(vtable_len) + align_object_offset(itable_len) + nonstatic_oop_map_size);
   362   // Allocation
   363   KlassHandle h_this_klass(THREAD, as_klassOop());
   364   KlassHandle k;
   365   if (rt == REF_NONE) {
   366     if (name != vmSymbols::java_lang_Class()) {
   367       // regular klass
   368       instanceKlass o;
   369       k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL);
   370     } else {
   371       // Class
   372       instanceMirrorKlass o;
   373       k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL);
   374     }
   375   } else {
   376     // reference klass
   377     instanceRefKlass o;
   378     k = base_create_klass(h_this_klass, size, o.vtbl_value(), CHECK_NULL);
   379   }
   380   {
   381     No_Safepoint_Verifier no_safepoint; // until k becomes parsable
   382     instanceKlass* ik = (instanceKlass*) k()->klass_part();
   383     assert(!k()->is_parsable(), "not expecting parsability yet.");
   385     // The sizes of these these three variables are used for determining the
   386     // size of the instanceKlassOop. It is critical that these are set to the right
   387     // sizes before the first GC, i.e., when we allocate the mirror.
   388     ik->set_vtable_length(vtable_len);
   389     ik->set_itable_length(itable_len);
   390     ik->set_static_field_size(static_field_size);
   391     ik->set_nonstatic_oop_map_size(nonstatic_oop_map_size);
   392     assert(k()->size() == size, "wrong size for object");
   394     ik->set_array_klasses(NULL);
   395     ik->set_methods(NULL);
   396     ik->set_method_ordering(NULL);
   397     ik->set_local_interfaces(NULL);
   398     ik->set_transitive_interfaces(NULL);
   399     ik->init_implementor();
   400     ik->set_fields(NULL);
   401     ik->set_constants(NULL);
   402     ik->set_class_loader(NULL);
   403     ik->set_protection_domain(NULL);
   404     ik->set_host_klass(NULL);
   405     ik->set_signers(NULL);
   406     ik->set_source_file_name(NULL);
   407     ik->set_source_debug_extension(NULL);
   408     ik->set_source_debug_extension(NULL);
   409     ik->set_array_name(NULL);
   410     ik->set_inner_classes(NULL);
   411     ik->set_static_oop_field_count(0);
   412     ik->set_nonstatic_field_size(0);
   413     ik->set_is_marked_dependent(false);
   414     ik->set_init_state(instanceKlass::allocated);
   415     ik->set_init_thread(NULL);
   416     ik->set_reference_type(rt);
   417     ik->set_oop_map_cache(NULL);
   418     ik->set_jni_ids(NULL);
   419     ik->set_osr_nmethods_head(NULL);
   420     ik->set_breakpoints(NULL);
   421     ik->init_previous_versions();
   422     ik->set_generic_signature(NULL);
   423     ik->set_bootstrap_method(NULL);
   424     ik->release_set_methods_jmethod_ids(NULL);
   425     ik->release_set_methods_cached_itable_indices(NULL);
   426     ik->set_class_annotations(NULL);
   427     ik->set_fields_annotations(NULL);
   428     ik->set_methods_annotations(NULL);
   429     ik->set_methods_parameter_annotations(NULL);
   430     ik->set_methods_default_annotations(NULL);
   431     ik->set_enclosing_method_indices(0, 0);
   432     ik->set_jvmti_cached_class_field_map(NULL);
   433     ik->set_initial_method_idnum(0);
   434     assert(k()->is_parsable(), "should be parsable here.");
   436     // initialize the non-header words to zero
   437     intptr_t* p = (intptr_t*)k();
   438     for (int index = instanceKlass::header_size(); index < size; index++) {
   439       p[index] = NULL_WORD;
   440     }
   442     // To get verify to work - must be set to partial loaded before first GC point.
   443     k()->set_partially_loaded();
   444   }
   445   return k();
   446 }
   450 #ifndef PRODUCT
   452 // Printing
   454 #define BULLET  " - "
   456 static const char* state_names[] = {
   457   "unparseable_by_gc", "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
   458 };
   461 void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
   462   assert(obj->is_klass(), "must be klass");
   463   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   464   klassKlass::oop_print_on(obj, st);
   466   st->print(BULLET"instance size:     %d", ik->size_helper());                        st->cr();
   467   st->print(BULLET"klass size:        %d", ik->object_size());                        st->cr();
   468   st->print(BULLET"access:            "); ik->access_flags().print_on(st);            st->cr();
   469   st->print(BULLET"state:             "); st->print_cr(state_names[ik->_init_state]);
   470   st->print(BULLET"name:              "); ik->name()->print_value_on(st);             st->cr();
   471   st->print(BULLET"super:             "); ik->super()->print_value_on(st);            st->cr();
   472   st->print(BULLET"sub:               ");
   473   Klass* sub = ik->subklass();
   474   int n;
   475   for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
   476     if (n < MaxSubklassPrintSize) {
   477       sub->as_klassOop()->print_value_on(st);
   478       st->print("   ");
   479     }
   480   }
   481   if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize);
   482   st->cr();
   484   if (ik->is_interface()) {
   485     st->print_cr(BULLET"nof implementors:  %d", ik->nof_implementors());
   486     int print_impl = 0;
   487     for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   488       if (ik->implementor(i) != NULL) {
   489         if (++print_impl == 1)
   490           st->print_cr(BULLET"implementor:    ");
   491         st->print("   ");
   492         ik->implementor(i)->print_value_on(st);
   493       }
   494     }
   495     if (print_impl > 0)  st->cr();
   496   }
   498   st->print(BULLET"arrays:            "); ik->array_klasses()->print_value_on(st);     st->cr();
   499   st->print(BULLET"methods:           "); ik->methods()->print_value_on(st);           st->cr();
   500   if (Verbose) {
   501     objArrayOop methods = ik->methods();
   502     for(int i = 0; i < methods->length(); i++) {
   503       tty->print("%d : ", i); methods->obj_at(i)->print_value(); tty->cr();
   504     }
   505   }
   506   st->print(BULLET"method ordering:   "); ik->method_ordering()->print_value_on(st);       st->cr();
   507   st->print(BULLET"local interfaces:  "); ik->local_interfaces()->print_value_on(st);      st->cr();
   508   st->print(BULLET"trans. interfaces: "); ik->transitive_interfaces()->print_value_on(st); st->cr();
   509   st->print(BULLET"constants:         "); ik->constants()->print_value_on(st);         st->cr();
   510   st->print(BULLET"class loader:      "); ik->class_loader()->print_value_on(st);      st->cr();
   511   st->print(BULLET"protection domain: "); ik->protection_domain()->print_value_on(st); st->cr();
   512   st->print(BULLET"host class:        "); ik->host_klass()->print_value_on(st);        st->cr();
   513   st->print(BULLET"signers:           "); ik->signers()->print_value_on(st);           st->cr();
   514   if (ik->source_file_name() != NULL) {
   515     st->print(BULLET"source file:       ");
   516     ik->source_file_name()->print_value_on(st);
   517     st->cr();
   518   }
   519   if (ik->source_debug_extension() != NULL) {
   520     st->print(BULLET"source debug extension:       ");
   521     ik->source_debug_extension()->print_value_on(st);
   522     st->cr();
   523   }
   525   {
   526     ResourceMark rm;
   527     // PreviousVersionInfo objects returned via PreviousVersionWalker
   528     // contain a GrowableArray of handles. We have to clean up the
   529     // GrowableArray _after_ the PreviousVersionWalker destructor
   530     // has destroyed the handles.
   531     {
   532       bool have_pv = false;
   533       PreviousVersionWalker pvw(ik);
   534       for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
   535            pv_info != NULL; pv_info = pvw.next_previous_version()) {
   536         if (!have_pv)
   537           st->print(BULLET"previous version:  ");
   538         have_pv = true;
   539         pv_info->prev_constant_pool_handle()()->print_value_on(st);
   540       }
   541       if (have_pv)  st->cr();
   542     } // pvw is cleaned up
   543   } // rm is cleaned up
   545   if (ik->bootstrap_method() != NULL) {
   546     st->print(BULLET"bootstrap method:  ");
   547     ik->bootstrap_method()->print_value_on(st);
   548     st->cr();
   549   }
   550   if (ik->generic_signature() != NULL) {
   551     st->print(BULLET"generic signature: ");
   552     ik->generic_signature()->print_value_on(st);
   553     st->cr();
   554   }
   555   st->print(BULLET"inner classes:     "); ik->inner_classes()->print_value_on(st);     st->cr();
   556   st->print(BULLET"java mirror:       "); ik->java_mirror()->print_value_on(st);       st->cr();
   557   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", ik->vtable_length(), ik->start_of_vtable());  st->cr();
   558   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", ik->itable_length(), ik->start_of_itable()); st->cr();
   559   st->print_cr(BULLET"---- static fields (%d words):", ik->static_field_size());
   560   FieldPrinter print_static_field(st);
   561   ik->do_local_static_fields(&print_static_field);
   562   st->print_cr(BULLET"---- non-static fields (%d words):", ik->nonstatic_field_size());
   563   FieldPrinter print_nonstatic_field(st);
   564   ik->do_nonstatic_fields(&print_nonstatic_field);
   566   st->print(BULLET"non-static oop maps: ");
   567   OopMapBlock* map     = ik->start_of_nonstatic_oop_maps();
   568   OopMapBlock* end_map = map + ik->nonstatic_oop_map_count();
   569   while (map < end_map) {
   570     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
   571     map++;
   572   }
   573   st->cr();
   574 }
   576 #endif //PRODUCT
   578 void instanceKlassKlass::oop_print_value_on(oop obj, outputStream* st) {
   579   assert(obj->is_klass(), "must be klass");
   580   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   581   ik->name()->print_value_on(st);
   582 }
   584 const char* instanceKlassKlass::internal_name() const {
   585   return "{instance class}";
   586 }
   588 // Verification
   590 class VerifyFieldClosure: public OopClosure {
   591  protected:
   592   template <class T> void do_oop_work(T* p) {
   593     guarantee(Universe::heap()->is_in(p), "should be in heap");
   594     oop obj = oopDesc::load_decode_heap_oop(p);
   595     guarantee(obj->is_oop_or_null(), "should be in heap");
   596   }
   597  public:
   598   virtual void do_oop(oop* p)       { VerifyFieldClosure::do_oop_work(p); }
   599   virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); }
   600 };
   602 void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
   603   klassKlass::oop_verify_on(obj, st);
   604   if (!obj->partially_loaded()) {
   605     Thread *thread = Thread::current();
   606     instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   608 #ifndef PRODUCT
   609     // Avoid redundant verifies
   610     if (ik->_verify_count == Universe::verify_count()) return;
   611     ik->_verify_count = Universe::verify_count();
   612 #endif
   613     // Verify that klass is present in SystemDictionary
   614     if (ik->is_loaded() && !ik->is_anonymous()) {
   615       Symbol* h_name = ik->name();
   616       Handle h_loader (thread, ik->class_loader());
   617       Handle h_obj(thread, obj);
   618       SystemDictionary::verify_obj_klass_present(h_obj, h_name, h_loader);
   619     }
   621     // Verify static fields
   622     VerifyFieldClosure blk;
   624     // Verify vtables
   625     if (ik->is_linked()) {
   626       ResourceMark rm(thread);
   627       // $$$ This used to be done only for m/s collections.  Doing it
   628       // always seemed a valid generalization.  (DLD -- 6/00)
   629       ik->vtable()->verify(st);
   630     }
   632     // Verify oop map cache
   633     if (ik->oop_map_cache() != NULL) {
   634       ik->oop_map_cache()->verify();
   635     }
   637     // Verify first subklass
   638     if (ik->subklass_oop() != NULL) {
   639       guarantee(ik->subklass_oop()->is_perm(),  "should be in permspace");
   640       guarantee(ik->subklass_oop()->is_klass(), "should be klass");
   641     }
   643     // Verify siblings
   644     klassOop super = ik->super();
   645     Klass* sib = ik->next_sibling();
   646     int sib_count = 0;
   647     while (sib != NULL) {
   648       if (sib == ik) {
   649         fatal(err_msg("subclass cycle of length %d", sib_count));
   650       }
   651       if (sib_count >= 100000) {
   652         fatal(err_msg("suspiciously long subclass list %d", sib_count));
   653       }
   654       guarantee(sib->as_klassOop()->is_klass(), "should be klass");
   655       guarantee(sib->as_klassOop()->is_perm(),  "should be in permspace");
   656       guarantee(sib->super() == super, "siblings should have same superklass");
   657       sib = sib->next_sibling();
   658     }
   660     // Verify implementor fields
   661     bool saw_null_impl = false;
   662     for (int i = 0; i < instanceKlass::implementors_limit; i++) {
   663       klassOop im = ik->implementor(i);
   664       if (im == NULL) { saw_null_impl = true; continue; }
   665       guarantee(!saw_null_impl, "non-nulls must preceded all nulls");
   666       guarantee(ik->is_interface(), "only interfaces should have implementor set");
   667       guarantee(i < ik->nof_implementors(), "should only have one implementor");
   668       guarantee(im->is_perm(),  "should be in permspace");
   669       guarantee(im->is_klass(), "should be klass");
   670       guarantee(!Klass::cast(klassOop(im))->is_interface(), "implementors cannot be interfaces");
   671     }
   673     // Verify local interfaces
   674     objArrayOop local_interfaces = ik->local_interfaces();
   675     guarantee(local_interfaces->is_perm(),          "should be in permspace");
   676     guarantee(local_interfaces->is_objArray(),      "should be obj array");
   677     int j;
   678     for (j = 0; j < local_interfaces->length(); j++) {
   679       oop e = local_interfaces->obj_at(j);
   680       guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid local interface");
   681     }
   683     // Verify transitive interfaces
   684     objArrayOop transitive_interfaces = ik->transitive_interfaces();
   685     guarantee(transitive_interfaces->is_perm(),          "should be in permspace");
   686     guarantee(transitive_interfaces->is_objArray(),      "should be obj array");
   687     for (j = 0; j < transitive_interfaces->length(); j++) {
   688       oop e = transitive_interfaces->obj_at(j);
   689       guarantee(e->is_klass() && Klass::cast(klassOop(e))->is_interface(), "invalid transitive interface");
   690     }
   692     // Verify methods
   693     objArrayOop methods = ik->methods();
   694     guarantee(methods->is_perm(),              "should be in permspace");
   695     guarantee(methods->is_objArray(),          "should be obj array");
   696     for (j = 0; j < methods->length(); j++) {
   697       guarantee(methods->obj_at(j)->is_method(), "non-method in methods array");
   698     }
   699     for (j = 0; j < methods->length() - 1; j++) {
   700       methodOop m1 = methodOop(methods->obj_at(j));
   701       methodOop m2 = methodOop(methods->obj_at(j + 1));
   702       guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
   703     }
   705     // Verify method ordering
   706     typeArrayOop method_ordering = ik->method_ordering();
   707     guarantee(method_ordering->is_perm(),              "should be in permspace");
   708     guarantee(method_ordering->is_typeArray(),         "should be type array");
   709     int length = method_ordering->length();
   710     if (JvmtiExport::can_maintain_original_method_order()) {
   711       guarantee(length == methods->length(),           "invalid method ordering length");
   712       jlong sum = 0;
   713       for (j = 0; j < length; j++) {
   714         int original_index = method_ordering->int_at(j);
   715         guarantee(original_index >= 0 && original_index < length, "invalid method ordering index");
   716         sum += original_index;
   717       }
   718       // Verify sum of indices 0,1,...,length-1
   719       guarantee(sum == ((jlong)length*(length-1))/2,   "invalid method ordering sum");
   720     } else {
   721       guarantee(length == 0,                           "invalid method ordering length");
   722     }
   724     // Verify JNI static field identifiers
   725     if (ik->jni_ids() != NULL) {
   726       ik->jni_ids()->verify(ik->as_klassOop());
   727     }
   729     // Verify other fields
   730     if (ik->array_klasses() != NULL) {
   731       guarantee(ik->array_klasses()->is_perm(),      "should be in permspace");
   732       guarantee(ik->array_klasses()->is_klass(),     "should be klass");
   733     }
   734     guarantee(ik->fields()->is_perm(),               "should be in permspace");
   735     guarantee(ik->fields()->is_typeArray(),          "should be type array");
   736     guarantee(ik->constants()->is_perm(),            "should be in permspace");
   737     guarantee(ik->constants()->is_constantPool(),    "should be constant pool");
   738     guarantee(ik->inner_classes()->is_perm(),        "should be in permspace");
   739     guarantee(ik->inner_classes()->is_typeArray(),   "should be type array");
   740     if (ik->protection_domain() != NULL) {
   741       guarantee(ik->protection_domain()->is_oop(),  "should be oop");
   742     }
   743     if (ik->host_klass() != NULL) {
   744       guarantee(ik->host_klass()->is_oop(),  "should be oop");
   745     }
   746     if (ik->signers() != NULL) {
   747       guarantee(ik->signers()->is_objArray(),       "should be obj array");
   748     }
   749     if (ik->class_annotations() != NULL) {
   750       guarantee(ik->class_annotations()->is_typeArray(), "should be type array");
   751     }
   752     if (ik->fields_annotations() != NULL) {
   753       guarantee(ik->fields_annotations()->is_objArray(), "should be obj array");
   754     }
   755     if (ik->methods_annotations() != NULL) {
   756       guarantee(ik->methods_annotations()->is_objArray(), "should be obj array");
   757     }
   758     if (ik->methods_parameter_annotations() != NULL) {
   759       guarantee(ik->methods_parameter_annotations()->is_objArray(), "should be obj array");
   760     }
   761     if (ik->methods_default_annotations() != NULL) {
   762       guarantee(ik->methods_default_annotations()->is_objArray(), "should be obj array");
   763     }
   764   }
   765 }
   768 bool instanceKlassKlass::oop_partially_loaded(oop obj) const {
   769   assert(obj->is_klass(), "object must be klass");
   770   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   771   assert(ik->oop_is_instance(), "object must be instanceKlass");
   772   return ik->transitive_interfaces() == (objArrayOop) obj;   // Check whether transitive_interfaces points to self
   773 }
   776 // The transitive_interfaces is the last field set when loading an object.
   777 void instanceKlassKlass::oop_set_partially_loaded(oop obj) {
   778   assert(obj->is_klass(), "object must be klass");
   779   instanceKlass* ik = instanceKlass::cast(klassOop(obj));
   780   // Set the layout helper to a place-holder value, until fuller initialization.
   781   // (This allows asserts in oop_is_instance to succeed.)
   782   ik->set_layout_helper(Klass::instance_layout_helper(0, true));
   783   assert(ik->oop_is_instance(), "object must be instanceKlass");
   784   assert(ik->transitive_interfaces() == NULL, "just checking");
   785   ik->set_transitive_interfaces((objArrayOop) obj);   // Temporarily set transitive_interfaces to point to self
   786 }

mercurial