< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

 161                                    num_fmg_open_archive_subgraph_entry_fields, ik);
 162 }
 163 
 164 void HeapShared::fixup_regions() {
 165   FileMapInfo* mapinfo = FileMapInfo::current_info();
 166   if (is_mapped()) {
 167     mapinfo->fixup_mapped_heap_regions();
 168   } else if (_loading_failed) {
 169     fill_failed_loaded_region();
 170   }
 171   if (is_fully_available()) {
 172     if (!MetaspaceShared::use_full_module_graph()) {
 173       // Need to remove all the archived java.lang.Module objects from HeapShared::roots().
 174       ClassLoaderDataShared::clear_archived_oops();
 175     }
 176   }
 177   SystemDictionaryShared::update_archived_mirror_native_pointers();
 178 }
 179 
 180 unsigned HeapShared::oop_hash(oop const& p) {
 181   unsigned hash = (unsigned)p->identity_hash();
 182   return hash;



 183 }
 184 
 185 static void reset_states(oop obj, TRAPS) {
 186   Handle h_obj(THREAD, obj);
 187   InstanceKlass* klass = InstanceKlass::cast(obj->klass());
 188   TempNewSymbol method_name = SymbolTable::new_symbol("resetArchivedStates");
 189   Symbol* method_sig = vmSymbols::void_method_signature();
 190 
 191   while (klass != NULL) {
 192     Method* method = klass->find_method(method_name, method_sig);
 193     if (method != NULL) {
 194       assert(method->is_private(), "must be");
 195       if (log_is_enabled(Debug, cds)) {
 196         ResourceMark rm(THREAD);
 197         log_debug(cds)("  calling %s", method->name_and_sig_as_C_string());
 198       }
 199       JavaValue result(T_VOID);
 200       JavaCalls::call_special(&result, h_obj, klass,
 201                               method_name, method_sig, CHECK);
 202     }

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

 313 
 314     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 315     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);

 316 
 317     ArchivedObjectCache* cache = archived_object_cache();
 318     CachedOopInfo info = make_cached_oop_info(archived_oop);
 319     cache->put(obj, info);
 320     if (log_is_enabled(Debug, cds, heap)) {
 321       ResourceMark rm;
 322       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 323                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 324     }
 325   } else {
 326     log_error(cds, heap)(
 327       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 328       p2i(obj));
 329     vm_direct_exit(-1,
 330       err_msg("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 331               SIZE_FORMAT "M", MaxHeapSize/M));
 332   }
 333   return archived_oop;
 334 }
 335 

 523                              true /* is_full_module_graph */);
 524     ClassLoaderDataShared::init_archived_oops();
 525   }
 526 
 527   copy_roots();
 528 
 529   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 530                                                    os::vm_allocation_granularity());
 531 }
 532 
 533 // Copy _pending_archive_roots into an objArray
 534 void HeapShared::copy_roots() {
 535   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 536   size_t size = objArrayOopDesc::object_size(length);
 537   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 538   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 539 
 540   memset(mem, 0, size * BytesPerWord);
 541   {
 542     // This is copied from MemAllocator::finish
 543     oopDesc::set_mark(mem, markWord::prototype());
 544     oopDesc::release_set_klass(mem, k);
 545   }
 546   {
 547     // This is copied from ObjArrayAllocator::initialize
 548     arrayOopDesc::set_length(mem, length);
 549   }
 550 
 551   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 552   for (int i = 0; i < length; i++) {
 553     roots()->obj_at_put(i, _pending_roots->at(i));
 554   }
 555   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 556 }
 557 
 558 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 559   _narrow_oop_base = base;
 560   _narrow_oop_shift = shift;
 561 }
 562 
 563 //

 161                                    num_fmg_open_archive_subgraph_entry_fields, ik);
 162 }
 163 
 164 void HeapShared::fixup_regions() {
 165   FileMapInfo* mapinfo = FileMapInfo::current_info();
 166   if (is_mapped()) {
 167     mapinfo->fixup_mapped_heap_regions();
 168   } else if (_loading_failed) {
 169     fill_failed_loaded_region();
 170   }
 171   if (is_fully_available()) {
 172     if (!MetaspaceShared::use_full_module_graph()) {
 173       // Need to remove all the archived java.lang.Module objects from HeapShared::roots().
 174       ClassLoaderDataShared::clear_archived_oops();
 175     }
 176   }
 177   SystemDictionaryShared::update_archived_mirror_native_pointers();
 178 }
 179 
 180 unsigned HeapShared::oop_hash(oop const& p) {
 181   // We are at a safepoint, so the object won't move. It's OK to use its
 182   // address as the hashcode.
 183   // We can't use p->identity_hash() as it's not available for primitive oops.
 184   assert_at_safepoint();
 185   return (unsigned)(p2i(p) >> LogBytesPerWord);
 186 }
 187 
 188 static void reset_states(oop obj, TRAPS) {
 189   Handle h_obj(THREAD, obj);
 190   InstanceKlass* klass = InstanceKlass::cast(obj->klass());
 191   TempNewSymbol method_name = SymbolTable::new_symbol("resetArchivedStates");
 192   Symbol* method_sig = vmSymbols::void_method_signature();
 193 
 194   while (klass != NULL) {
 195     Method* method = klass->find_method(method_name, method_sig);
 196     if (method != NULL) {
 197       assert(method->is_private(), "must be");
 198       if (log_is_enabled(Debug, cds)) {
 199         ResourceMark rm(THREAD);
 200         log_debug(cds)("  calling %s", method->name_and_sig_as_C_string());
 201       }
 202       JavaValue result(T_VOID);
 203       JavaCalls::call_special(&result, h_obj, klass,
 204                               method_name, method_sig, CHECK);
 205     }

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

 528                              true /* is_full_module_graph */);
 529     ClassLoaderDataShared::init_archived_oops();
 530   }
 531 
 532   copy_roots();
 533 
 534   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 535                                                    os::vm_allocation_granularity());
 536 }
 537 
 538 // Copy _pending_archive_roots into an objArray
 539 void HeapShared::copy_roots() {
 540   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 541   size_t size = objArrayOopDesc::object_size(length);
 542   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 543   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 544 
 545   memset(mem, 0, size * BytesPerWord);
 546   {
 547     // This is copied from MemAllocator::finish
 548     oopDesc::set_mark(mem, k->prototype_header());
 549     oopDesc::release_set_klass(mem, k);
 550   }
 551   {
 552     // This is copied from ObjArrayAllocator::initialize
 553     arrayOopDesc::set_length(mem, length);
 554   }
 555 
 556   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 557   for (int i = 0; i < length; i++) {
 558     roots()->obj_at_put(i, _pending_roots->at(i));
 559   }
 560   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 561 }
 562 
 563 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 564   _narrow_oop_base = base;
 565   _narrow_oop_shift = shift;
 566 }
 567 
 568 //
< prev index next >