src/share/vm/oops/constantPoolKlass.cpp

Tue, 14 Oct 2008 10:15:33 -0400

author
coleenp
date
Tue, 14 Oct 2008 10:15:33 -0400
changeset 833
443791f333a2
parent 631
d1605aabd0a1
child 866
a45484ea312d
permissions
-rw-r--r--

6700107: java/lang/Class/forName/TooManyDimensions.java crashes with SIGSEGV in c2 compiler with fastdebug
Summary: objArrayKlass::compute_modifier_flags was unnecessarily recursive
Reviewed-by: kamg

     1 /*
     2  * Copyright 1997-2008 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/_constantPoolKlass.cpp.incl"
    28 constantPoolOop constantPoolKlass::allocate(int length, TRAPS) {
    29   int size = constantPoolOopDesc::object_size(length);
    30   KlassHandle klass (THREAD, as_klassOop());
    31   constantPoolOop c =
    32     (constantPoolOop)CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL);
    34   c->set_length(length);
    35   c->set_tags(NULL);
    36   c->set_cache(NULL);
    37   c->set_pool_holder(NULL);
    38   // only set to non-zero if constant pool is merged by RedefineClasses
    39   c->set_orig_length(0);
    40   // all fields are initialized; needed for GC
    42   // initialize tag array
    43   // Note: cannot introduce constant pool handle before since it is not
    44   //       completely initialized (no class) -> would cause assertion failure
    45   constantPoolHandle pool (THREAD, c);
    46   typeArrayOop t_oop = oopFactory::new_permanent_byteArray(length, CHECK_NULL);
    47   typeArrayHandle tags (THREAD, t_oop);
    48   for (int index = 0; index < length; index++) {
    49     tags()->byte_at_put(index, JVM_CONSTANT_Invalid);
    50   }
    51   pool->set_tags(tags());
    53   return pool();
    54 }
    56 klassOop constantPoolKlass::create_klass(TRAPS) {
    57   constantPoolKlass o;
    58   KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
    59   KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
    60   // Make sure size calculation is right
    61   assert(k()->size() == align_object_size(header_size()), "wrong size for object");
    62   java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
    63   return k();
    64 }
    66 int constantPoolKlass::oop_size(oop obj) const {
    67   assert(obj->is_constantPool(), "must be constantPool");
    68   return constantPoolOop(obj)->object_size();
    69 }
    72 void constantPoolKlass::oop_follow_contents(oop obj) {
    73   assert (obj->is_constantPool(), "obj must be constant pool");
    74   constantPoolOop cp = (constantPoolOop) obj;
    75   // Performance tweak: We skip iterating over the klass pointer since we
    76   // know that Universe::constantPoolKlassObj never moves.
    78   // If the tags array is null we are in the middle of allocating this constant pool
    79   if (cp->tags() != NULL) {
    80     // gc of constant pool contents
    81     oop* base = (oop*)cp->base();
    82     for (int i = 0; i < cp->length(); i++) {
    83       if (cp->is_pointer_entry(i)) {
    84         if (*base != NULL) MarkSweep::mark_and_push(base);
    85       }
    86       base++;
    87     }
    88     // gc of constant pool instance variables
    89     MarkSweep::mark_and_push(cp->tags_addr());
    90     MarkSweep::mark_and_push(cp->cache_addr());
    91     MarkSweep::mark_and_push(cp->pool_holder_addr());
    92   }
    93 }
    95 #ifndef SERIALGC
    96 void constantPoolKlass::oop_follow_contents(ParCompactionManager* cm,
    97                                             oop obj) {
    98   assert (obj->is_constantPool(), "obj must be constant pool");
    99   constantPoolOop cp = (constantPoolOop) obj;
   100   // Performance tweak: We skip iterating over the klass pointer since we
   101   // know that Universe::constantPoolKlassObj never moves.
   103   // If the tags array is null we are in the middle of allocating this constant
   104   // pool.
   105   if (cp->tags() != NULL) {
   106     // gc of constant pool contents
   107     oop* base = (oop*)cp->base();
   108     for (int i = 0; i < cp->length(); i++) {
   109       if (cp->is_pointer_entry(i)) {
   110         if (*base != NULL) PSParallelCompact::mark_and_push(cm, base);
   111       }
   112       base++;
   113     }
   114     // gc of constant pool instance variables
   115     PSParallelCompact::mark_and_push(cm, cp->tags_addr());
   116     PSParallelCompact::mark_and_push(cm, cp->cache_addr());
   117     PSParallelCompact::mark_and_push(cm, cp->pool_holder_addr());
   118   }
   119 }
   120 #endif // SERIALGC
   123 int constantPoolKlass::oop_adjust_pointers(oop obj) {
   124   assert (obj->is_constantPool(), "obj must be constant pool");
   125   constantPoolOop cp = (constantPoolOop) obj;
   126   // Get size before changing pointers.
   127   // Don't call size() or oop_size() since that is a virtual call.
   128   int size = cp->object_size();
   129   // Performance tweak: We skip iterating over the klass pointer since we
   130   // know that Universe::constantPoolKlassObj never moves.
   132   // If the tags array is null we are in the middle of allocating this constant
   133   // pool.
   134   if (cp->tags() != NULL) {
   135     oop* base = (oop*)cp->base();
   136     for (int i = 0; i< cp->length();  i++) {
   137       if (cp->is_pointer_entry(i)) {
   138         MarkSweep::adjust_pointer(base);
   139       }
   140       base++;
   141     }
   142   }
   143   MarkSweep::adjust_pointer(cp->tags_addr());
   144   MarkSweep::adjust_pointer(cp->cache_addr());
   145   MarkSweep::adjust_pointer(cp->pool_holder_addr());
   146   return size;
   147 }
   150 int constantPoolKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
   151   assert (obj->is_constantPool(), "obj must be constant pool");
   152   // Performance tweak: We skip iterating over the klass pointer since we
   153   // know that Universe::constantPoolKlassObj never moves.
   154   constantPoolOop cp = (constantPoolOop) obj;
   155   // Get size before changing pointers.
   156   // Don't call size() or oop_size() since that is a virtual call.
   157   int size = cp->object_size();
   159   // If the tags array is null we are in the middle of allocating this constant
   160   // pool.
   161   if (cp->tags() != NULL) {
   162     oop* base = (oop*)cp->base();
   163     for (int i = 0; i < cp->length(); i++) {
   164       if (cp->is_pointer_entry(i)) {
   165         blk->do_oop(base);
   166       }
   167       base++;
   168     }
   169   }
   170   blk->do_oop(cp->tags_addr());
   171   blk->do_oop(cp->cache_addr());
   172   blk->do_oop(cp->pool_holder_addr());
   173   return size;
   174 }
   177 int constantPoolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
   178   assert (obj->is_constantPool(), "obj must be constant pool");
   179   // Performance tweak: We skip iterating over the klass pointer since we
   180   // know that Universe::constantPoolKlassObj never moves.
   181   constantPoolOop cp = (constantPoolOop) obj;
   182   // Get size before changing pointers.
   183   // Don't call size() or oop_size() since that is a virtual call.
   184   int size = cp->object_size();
   186   // If the tags array is null we are in the middle of allocating this constant
   187   // pool.
   188   if (cp->tags() != NULL) {
   189     oop* base = (oop*)cp->base();
   190     for (int i = 0; i < cp->length(); i++) {
   191       if (mr.contains(base)) {
   192         if (cp->is_pointer_entry(i)) {
   193           blk->do_oop(base);
   194         }
   195       }
   196       base++;
   197     }
   198   }
   199   oop* addr;
   200   addr = cp->tags_addr();
   201   blk->do_oop(addr);
   202   addr = cp->cache_addr();
   203   blk->do_oop(addr);
   204   addr = cp->pool_holder_addr();
   205   blk->do_oop(addr);
   206   return size;
   207 }
   209 #ifndef SERIALGC
   210 int constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   211   assert (obj->is_constantPool(), "obj must be constant pool");
   212   constantPoolOop cp = (constantPoolOop) obj;
   214   // If the tags array is null we are in the middle of allocating this constant
   215   // pool.
   216   if (cp->tags() != NULL) {
   217     oop* base = (oop*)cp->base();
   218     for (int i = 0; i < cp->length(); ++i, ++base) {
   219       if (cp->is_pointer_entry(i)) {
   220         PSParallelCompact::adjust_pointer(base);
   221       }
   222     }
   223   }
   224   PSParallelCompact::adjust_pointer(cp->tags_addr());
   225   PSParallelCompact::adjust_pointer(cp->cache_addr());
   226   PSParallelCompact::adjust_pointer(cp->pool_holder_addr());
   227   return cp->object_size();
   228 }
   230 int
   231 constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
   232                                        HeapWord* beg_addr, HeapWord* end_addr) {
   233   assert (obj->is_constantPool(), "obj must be constant pool");
   234   constantPoolOop cp = (constantPoolOop) obj;
   236   // If the tags array is null we are in the middle of allocating this constant
   237   // pool.
   238   if (cp->tags() != NULL) {
   239     oop* base = (oop*)cp->base();
   240     oop* const beg_oop = MAX2((oop*)beg_addr, base);
   241     oop* const end_oop = MIN2((oop*)end_addr, base + cp->length());
   242     const size_t beg_idx = pointer_delta(beg_oop, base, sizeof(oop*));
   243     const size_t end_idx = pointer_delta(end_oop, base, sizeof(oop*));
   244     for (size_t cur_idx = beg_idx; cur_idx < end_idx; ++cur_idx, ++base) {
   245       if (cp->is_pointer_entry(int(cur_idx))) {
   246         PSParallelCompact::adjust_pointer(base);
   247       }
   248     }
   249   }
   251   oop* p;
   252   p = cp->tags_addr();
   253   PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
   254   p = cp->cache_addr();
   255   PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
   256   p = cp->pool_holder_addr();
   257   PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
   259   return cp->object_size();
   260 }
   262 void constantPoolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
   263   assert(obj->is_constantPool(), "should be constant pool");
   264 }
   266 void constantPoolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
   267   assert(obj->is_constantPool(), "should be constant pool");
   268 }
   269 #endif // SERIALGC
   271 #ifndef PRODUCT
   273 // Printing
   275 void constantPoolKlass::oop_print_on(oop obj, outputStream* st) {
   276   EXCEPTION_MARK;
   277   oop anObj;
   278   assert(obj->is_constantPool(), "must be constantPool");
   279   Klass::oop_print_on(obj, st);
   280   constantPoolOop cp = constantPoolOop(obj);
   282   // Temp. remove cache so we can do lookups with original indicies.
   283   constantPoolCacheHandle cache (THREAD, cp->cache());
   284   cp->set_cache(NULL);
   286   for (int index = 1; index < cp->length(); index++) {      // Index 0 is unused
   287     st->print(" - %3d : ", index);
   288     cp->tag_at(index).print_on(st);
   289     st->print(" : ");
   290     switch (cp->tag_at(index).value()) {
   291       case JVM_CONSTANT_Class :
   292         { anObj = cp->klass_at(index, CATCH);
   293           anObj->print_value_on(st);
   294           st->print(" {0x%lx}", (address)anObj);
   295         }
   296         break;
   297       case JVM_CONSTANT_Fieldref :
   298       case JVM_CONSTANT_Methodref :
   299       case JVM_CONSTANT_InterfaceMethodref :
   300         st->print("klass_index=%d", cp->klass_ref_index_at(index));
   301         st->print(" name_and_type_index=%d", cp->name_and_type_ref_index_at(index));
   302         break;
   303       case JVM_CONSTANT_UnresolvedString :
   304       case JVM_CONSTANT_String :
   305         anObj = cp->string_at(index, CATCH);
   306         anObj->print_value_on(st);
   307         st->print(" {0x%lx}", (address)anObj);
   308         break;
   309       case JVM_CONSTANT_Integer :
   310         st->print("%d", cp->int_at(index));
   311         break;
   312       case JVM_CONSTANT_Float :
   313         st->print("%f", cp->float_at(index));
   314         break;
   315       case JVM_CONSTANT_Long :
   316         st->print_jlong(cp->long_at(index));
   317         index++;   // Skip entry following eigth-byte constant
   318         break;
   319       case JVM_CONSTANT_Double :
   320         st->print("%lf", cp->double_at(index));
   321         index++;   // Skip entry following eigth-byte constant
   322         break;
   323       case JVM_CONSTANT_NameAndType :
   324         st->print("name_index=%d", cp->name_ref_index_at(index));
   325         st->print(" signature_index=%d", cp->signature_ref_index_at(index));
   326         break;
   327       case JVM_CONSTANT_Utf8 :
   328         cp->symbol_at(index)->print_value_on(st);
   329         break;
   330       case JVM_CONSTANT_UnresolvedClass :               // fall-through
   331       case JVM_CONSTANT_UnresolvedClassInError: {
   332         // unresolved_klass_at requires lock or safe world.
   333         oop entry = *cp->obj_at_addr(index);
   334         entry->print_value_on(st);
   335         }
   336         break;
   337       default:
   338         ShouldNotReachHere();
   339         break;
   340     }
   341     st->cr();
   342   }
   343   st->cr();
   345   // Restore cache
   346   cp->set_cache(cache());
   347 }
   350 #endif
   352 const char* constantPoolKlass::internal_name() const {
   353   return "{constant pool}";
   354 }
   356 // Verification
   358 void constantPoolKlass::oop_verify_on(oop obj, outputStream* st) {
   359   Klass::oop_verify_on(obj, st);
   360   guarantee(obj->is_constantPool(), "object must be constant pool");
   361   constantPoolOop cp = constantPoolOop(obj);
   362   guarantee(cp->is_perm(), "should be in permspace");
   363   if (!cp->partially_loaded()) {
   364     oop* base = (oop*)cp->base();
   365     for (int i = 0; i< cp->length();  i++) {
   366       if (cp->tag_at(i).is_klass()) {
   367         guarantee((*base)->is_perm(),     "should be in permspace");
   368         guarantee((*base)->is_klass(),    "should be klass");
   369       }
   370       if (cp->tag_at(i).is_unresolved_klass()) {
   371         guarantee((*base)->is_perm(),     "should be in permspace");
   372         guarantee((*base)->is_symbol() || (*base)->is_klass(),
   373                   "should be symbol or klass");
   374       }
   375       if (cp->tag_at(i).is_symbol()) {
   376         guarantee((*base)->is_perm(),     "should be in permspace");
   377         guarantee((*base)->is_symbol(),   "should be symbol");
   378       }
   379       if (cp->tag_at(i).is_unresolved_string()) {
   380         guarantee((*base)->is_perm(),     "should be in permspace");
   381         guarantee((*base)->is_symbol() || (*base)->is_instance(),
   382                   "should be symbol or instance");
   383       }
   384       if (cp->tag_at(i).is_string()) {
   385         guarantee((*base)->is_perm(),     "should be in permspace");
   386         guarantee((*base)->is_instance(), "should be instance");
   387       }
   388       base++;
   389     }
   390     guarantee(cp->tags()->is_perm(),         "should be in permspace");
   391     guarantee(cp->tags()->is_typeArray(),    "should be type array");
   392     if (cp->cache() != NULL) {
   393       // Note: cache() can be NULL before a class is completely setup or
   394       // in temporary constant pools used during constant pool merging
   395       guarantee(cp->cache()->is_perm(),              "should be in permspace");
   396       guarantee(cp->cache()->is_constantPoolCache(), "should be constant pool cache");
   397     }
   398     if (cp->pool_holder() != NULL) {
   399       // Note: pool_holder() can be NULL in temporary constant pools
   400       // used during constant pool merging
   401       guarantee(cp->pool_holder()->is_perm(),  "should be in permspace");
   402       guarantee(cp->pool_holder()->is_klass(), "should be klass");
   403     }
   404   }
   405 }
   407 bool constantPoolKlass::oop_partially_loaded(oop obj) const {
   408   assert(obj->is_constantPool(), "object must be constant pool");
   409   constantPoolOop cp = constantPoolOop(obj);
   410   return cp->tags() == NULL || cp->pool_holder() == (klassOop) cp;   // Check whether pool holder points to self
   411 }
   414 void constantPoolKlass::oop_set_partially_loaded(oop obj) {
   415   assert(obj->is_constantPool(), "object must be constant pool");
   416   constantPoolOop cp = constantPoolOop(obj);
   417   assert(cp->pool_holder() == NULL, "just checking");
   418   cp->set_pool_holder((klassOop) cp);   // Temporarily set pool holder to point to self
   419 }
   421 #ifndef PRODUCT
   422 // CompileTheWorld support. Preload all classes loaded references in the passed in constantpool
   423 void constantPoolKlass::preload_and_initialize_all_classes(oop obj, TRAPS) {
   424   guarantee(obj->is_constantPool(), "object must be constant pool");
   425   constantPoolHandle cp(THREAD, (constantPoolOop)obj);
   426   guarantee(!cp->partially_loaded(), "must be fully loaded");
   428   for (int i = 0; i< cp->length();  i++) {
   429     if (cp->tag_at(i).is_unresolved_klass()) {
   430       // This will force loading of the class
   431       klassOop klass = cp->klass_at(i, CHECK);
   432       if (klass->is_instance()) {
   433         // Force initialization of class
   434         instanceKlass::cast(klass)->initialize(CHECK);
   435       }
   436     }
   437   }
   438 }
   440 #endif

mercurial