45
46 public:
47 ArchiveHeapInfo() : _buffer_region(), _oopmap(128, mtClassShared), _ptrmap(128, mtClassShared) {}
48 bool is_used() { return !_buffer_region.is_empty(); }
49
50 MemRegion buffer_region() { return _buffer_region; }
51 void set_buffer_region(MemRegion r) { _buffer_region = r; }
52
53 char* buffer_start() { return (char*)_buffer_region.start(); }
54 size_t buffer_byte_size() { return _buffer_region.byte_size(); }
55
56 CHeapBitMap* oopmap() { return &_oopmap; }
57 CHeapBitMap* ptrmap() { return &_ptrmap; }
58
59 void set_heap_root_segments(HeapRootSegments segments) { _heap_root_segments = segments; };
60 HeapRootSegments heap_root_segments() { return _heap_root_segments; }
61 };
62
63 #if INCLUDE_CDS_JAVA_HEAP
64 class ArchiveHeapWriter : AllStatic {
65 // ArchiveHeapWriter manipulates three types of addresses:
66 //
67 // "source" vs "buffered" vs "requested"
68 //
69 // (Note: the design and convention is the same as for the archiving of Metaspace objects.
70 // See archiveBuilder.hpp.)
71 //
72 // - "source objects" are regular Java objects allocated during the execution
73 // of "java -Xshare:dump". They can be used as regular oops.
74 //
75 // Between HeapShared::start_scanning_for_oops() and HeapShared::end_scanning_for_oops(),
76 // we recursively search for the oops that need to be stored into the CDS archive.
77 // These are entered into HeapShared::archived_object_cache().
78 //
79 // - "buffered objects" are copies of the "source objects", and are stored in into
80 // ArchiveHeapWriter::_buffer, which is a GrowableArray that sits outside of
81 // the valid heap range. Therefore we avoid using the addresses of these copies
82 // as oops. They are usually called "buffered_addr" in the code (of the type "address").
83 //
84 // The buffered objects are stored contiguously, possibly with interleaving fillers
179
180 // The exclusive end of the last object that was copied into the buffer.
181 static address buffer_top() {
182 return buffer_bottom() + _buffer_used;
183 }
184
185 static bool in_buffer(address buffered_addr) {
186 return (buffer_bottom() <= buffered_addr) && (buffered_addr < buffer_top());
187 }
188
189 static size_t buffered_address_to_offset(address buffered_addr) {
190 assert(in_buffer(buffered_addr), "sanity");
191 return buffered_addr - buffer_bottom();
192 }
193
194 static void root_segment_at_put(objArrayOop segment, int index, oop root);
195 static objArrayOop allocate_root_segment(size_t offset, int element_count);
196 static void copy_roots_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
197 static void copy_source_objs_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
198 static size_t copy_one_source_obj_to_buffer(oop src_obj);
199
200 static void maybe_fill_gc_region_gap(size_t required_byte_size);
201 static size_t filler_array_byte_size(int length);
202 static int filler_array_length(size_t fill_bytes);
203 static HeapWord* init_filler_array_at_buffer_top(int array_length, size_t fill_bytes);
204
205 static void set_requested_address(ArchiveHeapInfo* info);
206 static void relocate_embedded_oops(GrowableArrayCHeap<oop, mtClassShared>* roots, ArchiveHeapInfo* info);
207 static void compute_ptrmap(ArchiveHeapInfo *info);
208 static bool is_in_requested_range(oop o);
209 static oop requested_obj_from_buffer_offset(size_t offset);
210
211 static oop load_oop_from_buffer(oop* buffered_addr);
212 static oop load_oop_from_buffer(narrowOop* buffered_addr);
213 inline static void store_oop_in_buffer(oop* buffered_addr, oop requested_obj);
214 inline static void store_oop_in_buffer(narrowOop* buffered_addr, oop requested_obj);
215
216 template <typename T> static oop load_source_oop_from_buffer(T* buffered_addr);
217 template <typename T> static void store_requested_oop_in_buffer(T* buffered_addr, oop request_oop);
218
|
45
46 public:
47 ArchiveHeapInfo() : _buffer_region(), _oopmap(128, mtClassShared), _ptrmap(128, mtClassShared) {}
48 bool is_used() { return !_buffer_region.is_empty(); }
49
50 MemRegion buffer_region() { return _buffer_region; }
51 void set_buffer_region(MemRegion r) { _buffer_region = r; }
52
53 char* buffer_start() { return (char*)_buffer_region.start(); }
54 size_t buffer_byte_size() { return _buffer_region.byte_size(); }
55
56 CHeapBitMap* oopmap() { return &_oopmap; }
57 CHeapBitMap* ptrmap() { return &_ptrmap; }
58
59 void set_heap_root_segments(HeapRootSegments segments) { _heap_root_segments = segments; };
60 HeapRootSegments heap_root_segments() { return _heap_root_segments; }
61 };
62
63 #if INCLUDE_CDS_JAVA_HEAP
64 class ArchiveHeapWriter : AllStatic {
65 friend class HeapShared;
66 // ArchiveHeapWriter manipulates three types of addresses:
67 //
68 // "source" vs "buffered" vs "requested"
69 //
70 // (Note: the design and convention is the same as for the archiving of Metaspace objects.
71 // See archiveBuilder.hpp.)
72 //
73 // - "source objects" are regular Java objects allocated during the execution
74 // of "java -Xshare:dump". They can be used as regular oops.
75 //
76 // Between HeapShared::start_scanning_for_oops() and HeapShared::end_scanning_for_oops(),
77 // we recursively search for the oops that need to be stored into the CDS archive.
78 // These are entered into HeapShared::archived_object_cache().
79 //
80 // - "buffered objects" are copies of the "source objects", and are stored in into
81 // ArchiveHeapWriter::_buffer, which is a GrowableArray that sits outside of
82 // the valid heap range. Therefore we avoid using the addresses of these copies
83 // as oops. They are usually called "buffered_addr" in the code (of the type "address").
84 //
85 // The buffered objects are stored contiguously, possibly with interleaving fillers
180
181 // The exclusive end of the last object that was copied into the buffer.
182 static address buffer_top() {
183 return buffer_bottom() + _buffer_used;
184 }
185
186 static bool in_buffer(address buffered_addr) {
187 return (buffer_bottom() <= buffered_addr) && (buffered_addr < buffer_top());
188 }
189
190 static size_t buffered_address_to_offset(address buffered_addr) {
191 assert(in_buffer(buffered_addr), "sanity");
192 return buffered_addr - buffer_bottom();
193 }
194
195 static void root_segment_at_put(objArrayOop segment, int index, oop root);
196 static objArrayOop allocate_root_segment(size_t offset, int element_count);
197 static void copy_roots_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
198 static void copy_source_objs_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
199 static size_t copy_one_source_obj_to_buffer(oop src_obj);
200 static void update_stats(oop src_obj);
201
202 static void maybe_fill_gc_region_gap(size_t required_byte_size);
203 static size_t filler_array_byte_size(int length);
204 static int filler_array_length(size_t fill_bytes);
205 static HeapWord* init_filler_array_at_buffer_top(int array_length, size_t fill_bytes);
206
207 static void set_requested_address(ArchiveHeapInfo* info);
208 static void relocate_embedded_oops(GrowableArrayCHeap<oop, mtClassShared>* roots, ArchiveHeapInfo* info);
209 static void compute_ptrmap(ArchiveHeapInfo *info);
210 static bool is_in_requested_range(oop o);
211 static oop requested_obj_from_buffer_offset(size_t offset);
212
213 static oop load_oop_from_buffer(oop* buffered_addr);
214 static oop load_oop_from_buffer(narrowOop* buffered_addr);
215 inline static void store_oop_in_buffer(oop* buffered_addr, oop requested_obj);
216 inline static void store_oop_in_buffer(narrowOop* buffered_addr, oop requested_obj);
217
218 template <typename T> static oop load_source_oop_from_buffer(T* buffered_addr);
219 template <typename T> static void store_requested_oop_in_buffer(T* buffered_addr, oop request_oop);
220
|