< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

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

  61 #include "runtime/safepointVerifiers.hpp"
  62 #include "utilities/bitMap.inline.hpp"
  63 #include "utilities/copy.hpp"
  64 #if INCLUDE_G1GC
  65 #include "gc/g1/g1CollectedHeap.hpp"
  66 #endif
  67 
  68 #if INCLUDE_CDS_JAVA_HEAP
  69 
  70 bool HeapShared::_closed_archive_heap_region_mapped = false;
  71 bool HeapShared::_open_archive_heap_region_mapped = false;
  72 bool HeapShared::_archive_heap_region_fixed = false;
  73 address   HeapShared::_narrow_oop_base;
  74 int       HeapShared::_narrow_oop_shift;
  75 DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
  76 
  77 //
  78 // If you add new entries to the following tables, you should know what you're doing!
  79 //
  80 

 258     return ao;
 259   }
 260 
 261   int len = obj->size();
 262   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 263     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 264                          p2i(obj), (size_t)obj->size());
 265     return NULL;
 266   }
 267 
 268   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 269   if (archived_oop != NULL) {
 270     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 271     // Reinitialize markword to remove age/marking/locking/etc.
 272     //
 273     // We need to retain the identity_hash, because it may have been used by some hashtables
 274     // in the shared heap. This also has the side effect of pre-initializing the
 275     // identity_hash for all shared objects, so they are less likely to be written
 276     // into during run time, increasing the potential of memory sharing.
 277     int hash_original = obj->identity_hash();
 278     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));









 279     assert(archived_oop->mark().is_unlocked(), "sanity");
 280 
 281     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 282     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 283 
 284     ArchivedObjectCache* cache = archived_object_cache();
 285     cache->put(obj, archived_oop);
 286     if (log_is_enabled(Debug, cds, heap)) {
 287       ResourceMark rm;
 288       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 289                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 290     }
 291   } else {
 292     log_error(cds, heap)(
 293       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 294       p2i(obj));
 295     vm_direct_exit(-1,
 296       err_msg("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 297               SIZE_FORMAT "M", MaxHeapSize/M));
 298   }

 401   }
 402 
 403   copy_roots();
 404 
 405   G1CollectedHeap::heap()->end_archive_alloc_range(open_archive,
 406                                                    os::vm_allocation_granularity());
 407 }
 408 
 409 // Copy _pending_archive_roots into an objArray
 410 void HeapShared::copy_roots() {
 411   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 412   int size = objArrayOopDesc::object_size(length);
 413   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 414   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 415 
 416   memset(mem, 0, size * BytesPerWord);
 417   {
 418     // This is copied from MemAllocator::finish
 419     if (UseBiasedLocking) {
 420       oopDesc::set_mark(mem, k->prototype_header());


 421     } else {
 422       oopDesc::set_mark(mem, markWord::prototype());
 423     }
 424     oopDesc::release_set_klass(mem, k);


 425   }
 426   {
 427     // This is copied from ObjArrayAllocator::initialize
 428     arrayOopDesc::set_length(mem, length);
 429   }
 430 
 431   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 432   for (int i = 0; i < length; i++) {
 433     roots()->obj_at_put(i, _pending_roots->at(i));
 434   }
 435   log_info(cds)("archived obj roots[%d] = %d words, klass = %p, obj = %p", length, size, k, mem);
 436 }
 437 
 438 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
 439   _narrow_oop_base = base;
 440   _narrow_oop_shift = shift;
 441 }
 442 
 443 //
 444 // Subgraph archiving support

  41 #include "gc/shared/gcLocker.hpp"
  42 #include "gc/shared/gcVMOperations.hpp"
  43 #include "logging/log.hpp"
  44 #include "logging/logMessage.hpp"
  45 #include "logging/logStream.hpp"
  46 #include "memory/iterator.inline.hpp"
  47 #include "memory/metadataFactory.hpp"
  48 #include "memory/metaspaceClosure.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/compressedOops.inline.hpp"
  52 #include "oops/fieldStreams.inline.hpp"
  53 #include "oops/objArrayOop.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "prims/jvmtiExport.hpp"
  56 #include "runtime/fieldDescriptor.inline.hpp"
  57 #include "runtime/globals_extension.hpp"
  58 #include "runtime/init.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/javaCalls.hpp"
  61 #include "runtime/safepoint.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_archive_heap_region_mapped = false;
  72 bool HeapShared::_open_archive_heap_region_mapped = false;
  73 bool HeapShared::_archive_heap_region_fixed = false;
  74 address   HeapShared::_narrow_oop_base;
  75 int       HeapShared::_narrow_oop_shift;
  76 DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
  77 
  78 //
  79 // If you add new entries to the following tables, you should know what you're doing!
  80 //
  81 

 259     return ao;
 260   }
 261 
 262   int len = obj->size();
 263   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 264     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 265                          p2i(obj), (size_t)obj->size());
 266     return NULL;
 267   }
 268 
 269   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 270   if (archived_oop != NULL) {
 271     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 272     // Reinitialize markword to remove age/marking/locking/etc.
 273     //
 274     // We need to retain the identity_hash, because it may have been used by some hashtables
 275     // in the shared heap. This also has the side effect of pre-initializing the
 276     // identity_hash for all shared objects, so they are less likely to be written
 277     // into during run time, increasing the potential of memory sharing.
 278     int hash_original = obj->identity_hash();
 279     if (UseCompactObjectHeaders) {
 280       markWord mark = obj->mark();
 281       if (mark.has_displaced_mark_helper()) {
 282         mark = mark.displaced_mark_helper();
 283       }
 284       narrowKlass nklass = mark.narrow_klass();
 285       archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original) LP64_ONLY(.set_narrow_klass(nklass)));
 286     } else {
 287       archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));
 288     }
 289     assert(archived_oop->mark().is_unlocked(), "sanity");
 290 
 291     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 292     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 293 
 294     ArchivedObjectCache* cache = archived_object_cache();
 295     cache->put(obj, archived_oop);
 296     if (log_is_enabled(Debug, cds, heap)) {
 297       ResourceMark rm;
 298       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 299                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 300     }
 301   } else {
 302     log_error(cds, heap)(
 303       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 304       p2i(obj));
 305     vm_direct_exit(-1,
 306       err_msg("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 307               SIZE_FORMAT "M", MaxHeapSize/M));
 308   }

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