< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

  42 #include "gc/shared/gcLocker.hpp"
  43 #include "gc/shared/gcVMOperations.hpp"
  44 #include "logging/log.hpp"
  45 #include "logging/logMessage.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.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "prims/jvmtiExport.hpp"
  57 #include "runtime/fieldDescriptor.inline.hpp"
  58 #include "runtime/globals_extension.hpp"
  59 #include "runtime/init.hpp"
  60 #include "runtime/java.hpp"
  61 #include "runtime/javaCalls.hpp"

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

 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   }

 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   size_t 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] = " SIZE_FORMAT " 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 //

  42 #include "gc/shared/gcLocker.hpp"
  43 #include "gc/shared/gcVMOperations.hpp"
  44 #include "logging/log.hpp"
  45 #include "logging/logMessage.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.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "prims/jvmtiExport.hpp"
  57 #include "runtime/fieldDescriptor.inline.hpp"
  58 #include "runtime/globals_extension.hpp"
  59 #include "runtime/init.hpp"
  60 #include "runtime/java.hpp"
  61 #include "runtime/javaCalls.hpp"
  62 #include "runtime/safepoint.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 address   HeapShared::_narrow_oop_base;
  76 int       HeapShared::_narrow_oop_shift;
  77 DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
  78 
  79 uintptr_t HeapShared::_loaded_heap_bottom = 0;
  80 uintptr_t HeapShared::_loaded_heap_top = 0;
  81 uintptr_t HeapShared::_dumptime_base_0 = UINTPTR_MAX;
  82 uintptr_t HeapShared::_dumptime_base_1 = UINTPTR_MAX;

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

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