hotspot/src/share/vm/oops/cpCacheKlass.cpp
changeset 8296 b1c2163e4e59
parent 7397 5b173b4ca846
child 8297 f05d10c1c4b8
equal deleted inserted replaced
8295:a2b2a8a3aaee 8296:b1c2163e4e59
    47   return constantPoolCacheOop(obj)->object_size();
    47   return constantPoolCacheOop(obj)->object_size();
    48 }
    48 }
    49 
    49 
    50 
    50 
    51 constantPoolCacheOop constantPoolCacheKlass::allocate(int length,
    51 constantPoolCacheOop constantPoolCacheKlass::allocate(int length,
    52                                                       bool is_conc_safe,
       
    53                                                       TRAPS) {
    52                                                       TRAPS) {
    54   // allocate memory
    53   // allocate memory
    55   int size = constantPoolCacheOopDesc::object_size(length);
    54   int size = constantPoolCacheOopDesc::object_size(length);
    56 
    55 
    57   KlassHandle klass (THREAD, as_klassOop());
    56   KlassHandle klass (THREAD, as_klassOop());
    58 
    57 
    59   // This is the original code.  The code from permanent_obj_allocate()
    58   // Commented out below is the original code.  The code from
    60   // was in-lined to allow the setting of is_conc_safe before the klass
    59   // permanent_obj_allocate() was in-lined so that we could
    61   // is installed.
    60   // set the _length field, necessary to correctly compute its
       
    61   // size(), before setting its klass word further below.
    62   // constantPoolCacheOop cache = (constantPoolCacheOop)
    62   // constantPoolCacheOop cache = (constantPoolCacheOop)
    63   //   CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL);
    63   //   CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL);
    64 
    64 
    65   oop obj = CollectedHeap::permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL);
    65   oop obj = CollectedHeap::permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL);
    66   constantPoolCacheOop cache = (constantPoolCacheOop) obj;
       
    67   cache->set_is_conc_safe(is_conc_safe);
       
    68   // The store to is_conc_safe must be visible before the klass
       
    69   // is set.  This should be done safely because _is_conc_safe has
       
    70   // been declared volatile.  If there are any problems, consider adding
       
    71   // OrderAccess::storestore();
       
    72   CollectedHeap::post_allocation_install_obj_klass(klass, obj, size);
       
    73   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj,
    66   NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj,
    74                                                               size));
    67                                                               size));
    75 
    68   constantPoolCacheOop cache = (constantPoolCacheOop) obj;
    76   // The length field affects the size of the object.  The allocation
    69   assert(!UseConcMarkSweepGC || obj->klass_or_null() == NULL,
    77   // above allocates the correct size (see calculation of "size") but
    70          "klass should be NULL here when using CMS");
    78   // the size() method of the constant pool cache oop will not reflect
    71   cache->set_length(length);  // should become visible before klass is set below.
    79   // that size until the correct length is set.
       
    80   cache->set_length(length);
       
    81 
       
    82   // The store of the length must be visible before is_conc_safe is
       
    83   // set to a safe state.
       
    84   // This should be done safely because _is_conc_safe has
       
    85   // been declared volatile.  If there are any problems, consider adding
       
    86   // OrderAccess::storestore();
       
    87   cache->set_is_conc_safe(methodOopDesc::IsSafeConc);
       
    88   cache->set_constant_pool(NULL);
    72   cache->set_constant_pool(NULL);
       
    73 
       
    74   OrderAccess::storestore();
       
    75   obj->set_klass(klass());
       
    76   assert(cache->size() == size, "Incorrect cache->size()");
    89   return cache;
    77   return cache;
    90 }
    78 }
    91 
    79 
    92 klassOop constantPoolCacheKlass::create_klass(TRAPS) {
    80 klassOop constantPoolCacheKlass::create_klass(TRAPS) {
    93   constantPoolCacheKlass o;
    81   constantPoolCacheKlass o;
   172   MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr());
   160   MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr());
   173   // iteration over constant pool cache entries
   161   // iteration over constant pool cache entries
   174   for (int i = 0; i < cache->length(); i++)
   162   for (int i = 0; i < cache->length(); i++)
   175     cache->entry_at(i)->adjust_pointers();
   163     cache->entry_at(i)->adjust_pointers();
   176   return size;
   164   return size;
   177 }
       
   178 
       
   179 bool constantPoolCacheKlass::oop_is_conc_safe(oop obj) const {
       
   180   assert(obj->is_constantPoolCache(), "should be constant pool");
       
   181   return constantPoolCacheOop(obj)->is_conc_safe();
       
   182 }
   165 }
   183 
   166 
   184 #ifndef SERIALGC
   167 #ifndef SERIALGC
   185 void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm,
   168 void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm,
   186                                                oop obj) {
   169                                                oop obj) {