src/share/vm/oops/instanceKlassKlass.cpp

Mon, 25 Jun 2012 21:33:35 -0400

author
coleenp
date
Mon, 25 Jun 2012 21:33:35 -0400
changeset 3875
246d977b51f2
parent 3741
8bafad97cd26
child 3906
04ade88d9712
permissions
-rw-r--r--

7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
Summary: Cannot delete _buckets and HashtableEntries in shared space (CDS)
Reviewed-by: acorn, kvn, dlong, dcubed, kamg

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

mercurial