< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

 144 //
 145 ////////////////////////////////////////////////////////////////
 146 void HeapShared::fixup_regions() {
 147   FileMapInfo* mapinfo = FileMapInfo::current_info();
 148   if (is_mapped()) {
 149     mapinfo->fixup_mapped_heap_regions();
 150   } else if (_loading_failed) {
 151     fill_failed_loaded_region();
 152   }
 153   if (is_fully_available()) {
 154     _roots = OopHandle(Universe::vm_global(), decode_from_archive(_roots_narrow));
 155     if (!MetaspaceShared::use_full_module_graph()) {
 156       // Need to remove all the archived java.lang.Module objects from HeapShared::roots().
 157       ClassLoaderDataShared::clear_archived_oops();
 158     }
 159   }
 160   SystemDictionaryShared::update_archived_mirror_native_pointers();
 161 }
 162 
 163 unsigned HeapShared::oop_hash(oop const& p) {
 164   unsigned hash = (unsigned)p->identity_hash();
 165   return hash;



 166 }
 167 
 168 static void reset_states(oop obj, TRAPS) {
 169   Handle h_obj(THREAD, obj);
 170   InstanceKlass* klass = InstanceKlass::cast(obj->klass());
 171   TempNewSymbol method_name = SymbolTable::new_symbol("resetArchivedStates");
 172   Symbol* method_sig = vmSymbols::void_method_signature();
 173 
 174   while (klass != NULL) {
 175     Method* method = klass->find_method(method_name, method_sig);
 176     if (method != NULL) {
 177       assert(method->is_private(), "must be");
 178       if (log_is_enabled(Debug, cds)) {
 179         ResourceMark rm(THREAD);
 180         log_debug(cds)("  calling %s", method->name_and_sig_as_C_string());
 181       }
 182       JavaValue result(T_VOID);
 183       JavaCalls::call_special(&result, h_obj, klass,
 184                               method_name, method_sig, CHECK);
 185     }

 279     // already archived
 280     return ao;
 281   }
 282 
 283   int len = obj->size();
 284   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 285     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 286                          p2i(obj), (size_t)obj->size());
 287     return NULL;
 288   }
 289 
 290   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 291   if (archived_oop != NULL) {
 292     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 293     // Reinitialize markword to remove age/marking/locking/etc.
 294     //
 295     // We need to retain the identity_hash, because it may have been used by some hashtables
 296     // in the shared heap. This also has the side effect of pre-initializing the
 297     // identity_hash for all shared objects, so they are less likely to be written
 298     // into during run time, increasing the potential of memory sharing.
 299     int hash_original = obj->identity_hash();
 300     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));
 301     assert(archived_oop->mark().is_unlocked(), "sanity");

 302 
 303     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 304     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);

 305 
 306     ArchivedObjectCache* cache = archived_object_cache();
 307     cache->put(obj, archived_oop);
 308     if (log_is_enabled(Debug, cds, heap)) {
 309       ResourceMark rm;
 310       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 311                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 312     }
 313   } else {
 314     log_error(cds, heap)(
 315       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 316       p2i(obj));
 317     vm_direct_exit(-1,
 318       err_msg("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 319               SIZE_FORMAT "M", MaxHeapSize/M));
 320   }
 321   return archived_oop;
 322 }
 323 
 324 void HeapShared::archive_klass_objects() {

 419                              true /* is_full_module_graph */);
 420     ClassLoaderDataShared::init_archived_oops();
 421   }
 422 
 423   copy_roots();
 424 
 425   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 426                                                    os::vm_allocation_granularity());
 427 }
 428 
 429 // Copy _pending_archive_roots into an objArray
 430 void HeapShared::copy_roots() {
 431   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 432   int size = objArrayOopDesc::object_size(length);
 433   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 434   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 435 
 436   memset(mem, 0, size * BytesPerWord);
 437   {
 438     // This is copied from MemAllocator::finish
 439     oopDesc::set_mark(mem, markWord::prototype());
 440     oopDesc::release_set_klass(mem, k);
 441   }
 442   {
 443     // This is copied from ObjArrayAllocator::initialize
 444     arrayOopDesc::set_length(mem, length);
 445   }
 446 
 447   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 448   for (int i = 0; i < length; i++) {
 449     roots()->obj_at_put(i, _pending_roots->at(i));
 450   }
 451   log_info(cds)("archived obj roots[%d] = %d words, klass = %p, obj = %p", length, size, k, mem);
 452 }
 453 
 454 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 455   _narrow_oop_base = base;
 456   _narrow_oop_shift = shift;
 457 }
 458 
 459 //

 144 //
 145 ////////////////////////////////////////////////////////////////
 146 void HeapShared::fixup_regions() {
 147   FileMapInfo* mapinfo = FileMapInfo::current_info();
 148   if (is_mapped()) {
 149     mapinfo->fixup_mapped_heap_regions();
 150   } else if (_loading_failed) {
 151     fill_failed_loaded_region();
 152   }
 153   if (is_fully_available()) {
 154     _roots = OopHandle(Universe::vm_global(), decode_from_archive(_roots_narrow));
 155     if (!MetaspaceShared::use_full_module_graph()) {
 156       // Need to remove all the archived java.lang.Module objects from HeapShared::roots().
 157       ClassLoaderDataShared::clear_archived_oops();
 158     }
 159   }
 160   SystemDictionaryShared::update_archived_mirror_native_pointers();
 161 }
 162 
 163 unsigned HeapShared::oop_hash(oop const& p) {
 164   // We are at a safepoint, so the object won't move. It's OK to use its
 165   // address as the hashcode.
 166   // We can't use p->identity_hash() as it's not available for primitive oops.
 167   assert_at_safepoint();
 168   return (unsigned)(p2i(p) >> LogBytesPerWord);
 169 }
 170 
 171 static void reset_states(oop obj, TRAPS) {
 172   Handle h_obj(THREAD, obj);
 173   InstanceKlass* klass = InstanceKlass::cast(obj->klass());
 174   TempNewSymbol method_name = SymbolTable::new_symbol("resetArchivedStates");
 175   Symbol* method_sig = vmSymbols::void_method_signature();
 176 
 177   while (klass != NULL) {
 178     Method* method = klass->find_method(method_name, method_sig);
 179     if (method != NULL) {
 180       assert(method->is_private(), "must be");
 181       if (log_is_enabled(Debug, cds)) {
 182         ResourceMark rm(THREAD);
 183         log_debug(cds)("  calling %s", method->name_and_sig_as_C_string());
 184       }
 185       JavaValue result(T_VOID);
 186       JavaCalls::call_special(&result, h_obj, klass,
 187                               method_name, method_sig, CHECK);
 188     }

 282     // already archived
 283     return ao;
 284   }
 285 
 286   int len = obj->size();
 287   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 288     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 289                          p2i(obj), (size_t)obj->size());
 290     return NULL;
 291   }
 292 
 293   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 294   if (archived_oop != NULL) {
 295     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 296     // Reinitialize markword to remove age/marking/locking/etc.
 297     //
 298     // We need to retain the identity_hash, because it may have been used by some hashtables
 299     // in the shared heap. This also has the side effect of pre-initializing the
 300     // identity_hash for all shared objects, so they are less likely to be written
 301     // into during run time, increasing the potential of memory sharing.
 302     if (!(EnableValhalla && obj->mark().is_inline_type())) {
 303       int hash_original = obj->identity_hash();
 304       archived_oop->set_mark(archived_oop->klass()->prototype_header().copy_set_hash(hash_original));
 305       assert(archived_oop->mark().is_unlocked(), "sanity");
 306 
 307       DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 308       assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 309     }
 310 
 311     ArchivedObjectCache* cache = archived_object_cache();
 312     cache->put(obj, archived_oop);
 313     if (log_is_enabled(Debug, cds, heap)) {
 314       ResourceMark rm;
 315       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 316                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 317     }
 318   } else {
 319     log_error(cds, heap)(
 320       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 321       p2i(obj));
 322     vm_direct_exit(-1,
 323       err_msg("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 324               SIZE_FORMAT "M", MaxHeapSize/M));
 325   }
 326   return archived_oop;
 327 }
 328 
 329 void HeapShared::archive_klass_objects() {

 424                              true /* is_full_module_graph */);
 425     ClassLoaderDataShared::init_archived_oops();
 426   }
 427 
 428   copy_roots();
 429 
 430   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 431                                                    os::vm_allocation_granularity());
 432 }
 433 
 434 // Copy _pending_archive_roots into an objArray
 435 void HeapShared::copy_roots() {
 436   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 437   int size = objArrayOopDesc::object_size(length);
 438   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 439   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 440 
 441   memset(mem, 0, size * BytesPerWord);
 442   {
 443     // This is copied from MemAllocator::finish
 444     oopDesc::set_mark(mem, k->prototype_header());
 445     oopDesc::release_set_klass(mem, k);
 446   }
 447   {
 448     // This is copied from ObjArrayAllocator::initialize
 449     arrayOopDesc::set_length(mem, length);
 450   }
 451 
 452   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 453   for (int i = 0; i < length; i++) {
 454     roots()->obj_at_put(i, _pending_roots->at(i));
 455   }
 456   log_info(cds)("archived obj roots[%d] = %d words, klass = %p, obj = %p", length, size, k, mem);
 457 }
 458 
 459 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 460   _narrow_oop_base = base;
 461   _narrow_oop_shift = shift;
 462 }
 463 
 464 //
< prev index next >