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;
310 return ao;
311 }
312
313 int len = obj->size();
314 if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
315 log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
316 p2i(obj), (size_t)obj->size());
317 return NULL;
318 }
319
320 oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
321 if (archived_oop != NULL) {
322 Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
323 // Reinitialize markword to remove age/marking/locking/etc.
324 //
325 // We need to retain the identity_hash, because it may have been used by some hashtables
326 // in the shared heap. This also has the side effect of pre-initializing the
327 // identity_hash for all shared objects, so they are less likely to be written
328 // into during run time, increasing the potential of memory sharing.
329 int hash_original = obj->identity_hash();
330 archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));
331 assert(archived_oop->mark().is_unlocked(), "sanity");
332
333 DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
334 assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
335
336 ArchivedObjectCache* cache = archived_object_cache();
337 CachedOopInfo info = make_cached_oop_info(archived_oop);
338 cache->put(obj, info);
339 if (_original_object_table != NULL) {
340 _original_object_table->put(archived_oop, obj);
341 }
342 if (log_is_enabled(Debug, cds, heap)) {
343 ResourceMark rm;
344 log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
345 p2i(obj), p2i(archived_oop), obj->klass()->external_name());
346 }
347 } else {
348 log_error(cds, heap)(
349 "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
350 p2i(obj));
550 G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
551 os::vm_allocation_granularity());
552 }
553
554 // Copy _pending_archive_roots into an objArray
555 void HeapShared::copy_roots() {
556 // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
557 // objects in this array are discovered during HeapShared::archive_objects(). For example,
558 // in HeapShared::archive_reachable_objects_from() -> HeapShared::check_enum_obj().
559 // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
560 // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
561 // Instead, we have to roll our own alloc/copy routine here.
562 int length = _pending_roots != NULL ? _pending_roots->length() : 0;
563 size_t size = objArrayOopDesc::object_size(length);
564 Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
565 HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
566
567 memset(mem, 0, size * BytesPerWord);
568 {
569 // This is copied from MemAllocator::finish
570 oopDesc::set_mark(mem, markWord::prototype());
571 oopDesc::release_set_klass(mem, k);
572 }
573 {
574 // This is copied from ObjArrayAllocator::initialize
575 arrayOopDesc::set_length(mem, length);
576 }
577
578 _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
579 for (int i = 0; i < length; i++) {
580 roots()->obj_at_put(i, _pending_roots->at(i));
581 }
582 log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
583 }
584
585 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
586 _narrow_oop_base = base;
587 _narrow_oop_shift = shift;
588 }
589
590 //
591 // 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;
311 return ao;
312 }
313
314 int len = obj->size();
315 if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
316 log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
317 p2i(obj), (size_t)obj->size());
318 return NULL;
319 }
320
321 oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
322 if (archived_oop != NULL) {
323 Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
324 // Reinitialize markword to remove age/marking/locking/etc.
325 //
326 // We need to retain the identity_hash, because it may have been used by some hashtables
327 // in the shared heap. This also has the side effect of pre-initializing the
328 // identity_hash for all shared objects, so they are less likely to be written
329 // into during run time, increasing the potential of memory sharing.
330 int hash_original = obj->identity_hash();
331
332 assert(SafepointSynchronize::is_at_safepoint(), "resolving displaced headers only at safepoint");
333 markWord mark = obj->mark();
334 if (mark.has_displaced_mark_helper()) {
335 mark = mark.displaced_mark_helper();
336 }
337 narrowKlass nklass = mark.narrow_klass();
338 archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original) LP64_ONLY(.set_narrow_klass(nklass)));
339 assert(archived_oop->mark().is_unlocked(), "sanity");
340
341 DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
342 assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
343
344 ArchivedObjectCache* cache = archived_object_cache();
345 CachedOopInfo info = make_cached_oop_info(archived_oop);
346 cache->put(obj, info);
347 if (_original_object_table != NULL) {
348 _original_object_table->put(archived_oop, obj);
349 }
350 if (log_is_enabled(Debug, cds, heap)) {
351 ResourceMark rm;
352 log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
353 p2i(obj), p2i(archived_oop), obj->klass()->external_name());
354 }
355 } else {
356 log_error(cds, heap)(
357 "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
358 p2i(obj));
558 G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
559 os::vm_allocation_granularity());
560 }
561
562 // Copy _pending_archive_roots into an objArray
563 void HeapShared::copy_roots() {
564 // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
565 // objects in this array are discovered during HeapShared::archive_objects(). For example,
566 // in HeapShared::archive_reachable_objects_from() -> HeapShared::check_enum_obj().
567 // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
568 // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
569 // Instead, we have to roll our own alloc/copy routine here.
570 int length = _pending_roots != NULL ? _pending_roots->length() : 0;
571 size_t size = objArrayOopDesc::object_size(length);
572 Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
573 HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
574
575 memset(mem, 0, size * BytesPerWord);
576 {
577 // This is copied from MemAllocator::finish
578 oopDesc::set_mark(mem, k->prototype_header());
579 #ifndef _LP64
580 oopDesc::release_set_klass(mem, k);
581 #endif
582 }
583 {
584 // This is copied from ObjArrayAllocator::initialize
585 arrayOopDesc::set_length(mem, length);
586 }
587
588 _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
589 for (int i = 0; i < length; i++) {
590 roots()->obj_at_put(i, _pending_roots->at(i));
591 }
592 log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
593 }
594
595 void HeapShared::init_narrow_oop_decoding(address base, int shift) {
596 _narrow_oop_base = base;
597 _narrow_oop_shift = shift;
598 }
599
600 //
601 // Subgraph archiving support
|