< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

  43 #include "gc/shared/gcLocker.hpp"
  44 #include "gc/shared/gcVMOperations.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/iterator.inline.hpp"
  48 #include "memory/metadataFactory.hpp"
  49 #include "memory/metaspaceClosure.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/compressedOops.inline.hpp"
  53 #include "oops/fieldStreams.inline.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "oops/typeArrayOop.inline.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "runtime/fieldDescriptor.inline.hpp"
  59 #include "runtime/globals_extension.hpp"
  60 #include "runtime/init.hpp"
  61 #include "runtime/java.hpp"
  62 #include "runtime/javaCalls.hpp"

  63 #include "runtime/safepointVerifiers.hpp"
  64 #include "utilities/bitMap.inline.hpp"
  65 #include "utilities/copy.hpp"
  66 #if INCLUDE_G1GC
  67 #include "gc/g1/g1CollectedHeap.hpp"
  68 #endif
  69 
  70 #if INCLUDE_CDS_JAVA_HEAP
  71 
  72 bool HeapShared::_closed_regions_mapped = false;
  73 bool HeapShared::_open_regions_mapped = false;
  74 bool HeapShared::_is_loaded = false;
  75 bool HeapShared::_disable_writing = false;
  76 address   HeapShared::_narrow_oop_base;
  77 int       HeapShared::_narrow_oop_shift;
  78 DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
  79 
  80 // Support for loaded heap.
  81 uintptr_t HeapShared::_loaded_heap_bottom = 0;
  82 uintptr_t HeapShared::_loaded_heap_top = 0;

 313     return ao;
 314   }
 315 
 316   int len = obj->size();
 317   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 318     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 319                          p2i(obj), (size_t)obj->size());
 320     return NULL;
 321   }
 322 
 323   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 324   if (archived_oop != NULL) {
 325     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 326     // Reinitialize markword to remove age/marking/locking/etc.
 327     //
 328     // We need to retain the identity_hash, because it may have been used by some hashtables
 329     // in the shared heap. This also has the side effect of pre-initializing the
 330     // identity_hash for all shared objects, so they are less likely to be written
 331     // into during run time, increasing the potential of memory sharing.
 332     int hash_original = obj->identity_hash();
 333     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));







 334     assert(archived_oop->mark().is_unlocked(), "sanity");
 335 
 336     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 337     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 338 
 339     ArchivedObjectCache* cache = archived_object_cache();
 340     CachedOopInfo info = make_cached_oop_info(archived_oop);
 341     cache->put(obj, info);
 342     if (_original_object_table != NULL) {
 343       _original_object_table->put(archived_oop, obj);
 344     }
 345     if (log_is_enabled(Debug, cds, heap)) {
 346       ResourceMark rm;
 347       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 348                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 349     }
 350   } else {
 351     log_error(cds, heap)(
 352       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 353       p2i(obj));

 553   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 554                                                    os::vm_allocation_granularity());
 555 }
 556 
 557 // Copy _pending_archive_roots into an objArray
 558 void HeapShared::copy_roots() {
 559   // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
 560   // objects in this array are discovered during HeapShared::archive_objects(). For example,
 561   // in HeapShared::archive_reachable_objects_from() ->  HeapShared::check_enum_obj().
 562   // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
 563   // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
 564   // Instead, we have to roll our own alloc/copy routine here.
 565   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 566   size_t size = objArrayOopDesc::object_size(length);
 567   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 568   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 569 
 570   memset(mem, 0, size * BytesPerWord);
 571   {
 572     // This is copied from MemAllocator::finish
 573     oopDesc::set_mark(mem, markWord::prototype());

 574     oopDesc::release_set_klass(mem, k);

 575   }
 576   {
 577     // This is copied from ObjArrayAllocator::initialize
 578     arrayOopDesc::set_length(mem, length);
 579   }
 580 
 581   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 582   for (int i = 0; i < length; i++) {
 583     roots()->obj_at_put(i, _pending_roots->at(i));
 584   }
 585   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 586 }
 587 
 588 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 589   _narrow_oop_base = base;
 590   _narrow_oop_shift = shift;
 591 }
 592 
 593 //
 594 // Subgraph archiving support

  43 #include "gc/shared/gcLocker.hpp"
  44 #include "gc/shared/gcVMOperations.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/iterator.inline.hpp"
  48 #include "memory/metadataFactory.hpp"
  49 #include "memory/metaspaceClosure.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/compressedOops.inline.hpp"
  53 #include "oops/fieldStreams.inline.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "oops/typeArrayOop.inline.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "runtime/fieldDescriptor.inline.hpp"
  59 #include "runtime/globals_extension.hpp"
  60 #include "runtime/init.hpp"
  61 #include "runtime/java.hpp"
  62 #include "runtime/javaCalls.hpp"
  63 #include "runtime/safepoint.hpp"
  64 #include "runtime/safepointVerifiers.hpp"
  65 #include "utilities/bitMap.inline.hpp"
  66 #include "utilities/copy.hpp"
  67 #if INCLUDE_G1GC
  68 #include "gc/g1/g1CollectedHeap.hpp"
  69 #endif
  70 
  71 #if INCLUDE_CDS_JAVA_HEAP
  72 
  73 bool HeapShared::_closed_regions_mapped = false;
  74 bool HeapShared::_open_regions_mapped = false;
  75 bool HeapShared::_is_loaded = false;
  76 bool HeapShared::_disable_writing = false;
  77 address   HeapShared::_narrow_oop_base;
  78 int       HeapShared::_narrow_oop_shift;
  79 DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
  80 
  81 // Support for loaded heap.
  82 uintptr_t HeapShared::_loaded_heap_bottom = 0;
  83 uintptr_t HeapShared::_loaded_heap_top = 0;

 314     return ao;
 315   }
 316 
 317   int len = obj->size();
 318   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 319     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 320                          p2i(obj), (size_t)obj->size());
 321     return NULL;
 322   }
 323 
 324   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 325   if (archived_oop != NULL) {
 326     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 327     // Reinitialize markword to remove age/marking/locking/etc.
 328     //
 329     // We need to retain the identity_hash, because it may have been used by some hashtables
 330     // in the shared heap. This also has the side effect of pre-initializing the
 331     // identity_hash for all shared objects, so they are less likely to be written
 332     // into during run time, increasing the potential of memory sharing.
 333     int hash_original = obj->identity_hash();
 334 
 335     assert(SafepointSynchronize::is_at_safepoint(), "resolving displaced headers only at safepoint");
 336     markWord mark = obj->mark();
 337     if (mark.has_displaced_mark_helper()) {
 338       mark = mark.displaced_mark_helper();
 339     }
 340     narrowKlass nklass = mark.narrow_klass();
 341     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original) LP64_ONLY(.set_narrow_klass(nklass)));
 342     assert(archived_oop->mark().is_unlocked(), "sanity");
 343 
 344     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 345     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 346 
 347     ArchivedObjectCache* cache = archived_object_cache();
 348     CachedOopInfo info = make_cached_oop_info(archived_oop);
 349     cache->put(obj, info);
 350     if (_original_object_table != NULL) {
 351       _original_object_table->put(archived_oop, obj);
 352     }
 353     if (log_is_enabled(Debug, cds, heap)) {
 354       ResourceMark rm;
 355       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 356                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 357     }
 358   } else {
 359     log_error(cds, heap)(
 360       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 361       p2i(obj));

 561   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 562                                                    os::vm_allocation_granularity());
 563 }
 564 
 565 // Copy _pending_archive_roots into an objArray
 566 void HeapShared::copy_roots() {
 567   // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
 568   // objects in this array are discovered during HeapShared::archive_objects(). For example,
 569   // in HeapShared::archive_reachable_objects_from() ->  HeapShared::check_enum_obj().
 570   // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
 571   // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
 572   // Instead, we have to roll our own alloc/copy routine here.
 573   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 574   size_t size = objArrayOopDesc::object_size(length);
 575   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 576   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 577 
 578   memset(mem, 0, size * BytesPerWord);
 579   {
 580     // This is copied from MemAllocator::finish
 581     oopDesc::set_mark(mem, k->prototype_header());
 582 #ifndef _LP64
 583     oopDesc::release_set_klass(mem, k);
 584 #endif
 585   }
 586   {
 587     // This is copied from ObjArrayAllocator::initialize
 588     arrayOopDesc::set_length(mem, length);
 589   }
 590 
 591   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 592   for (int i = 0; i < length; i++) {
 593     roots()->obj_at_put(i, _pending_roots->at(i));
 594   }
 595   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 596 }
 597 
 598 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 599   _narrow_oop_base = base;
 600   _narrow_oop_shift = shift;
 601 }
 602 
 603 //
 604 // Subgraph archiving support
< prev index next >