1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 // HeapShared::archive_objects() recursively searches for the oops that need to be
76 // stored into the CDS archive. These are entered into HeapShared::archived_object_cache().
77 //
78 // - "buffered objects" are copies of the "source objects", and are stored in into
79 // ArchiveHeapWriter::_buffer, which is a GrowableArray that sits outside of
80 // the valid heap range. Therefore we avoid using the addresses of these copies
81 // as oops. They are usually called "buffered_addr" in the code (of the type "address").
82 //
83 // The buffered objects are stored contiguously, possibly with interleaving fillers
84 // to make sure no objects span across boundaries of MIN_GC_REGION_ALIGNMENT.
178
179 // The exclusive end of the last object that was copied into the buffer.
180 static address buffer_top() {
181 return buffer_bottom() + _buffer_used;
182 }
183
184 static bool in_buffer(address buffered_addr) {
185 return (buffer_bottom() <= buffered_addr) && (buffered_addr < buffer_top());
186 }
187
188 static size_t buffered_address_to_offset(address buffered_addr) {
189 assert(in_buffer(buffered_addr), "sanity");
190 return buffered_addr - buffer_bottom();
191 }
192
193 static void root_segment_at_put(objArrayOop segment, int index, oop root);
194 static objArrayOop allocate_root_segment(size_t offset, int element_count);
195 static void copy_roots_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
196 static void copy_source_objs_to_buffer(GrowableArrayCHeap<oop, mtClassShared>* roots);
197 static size_t copy_one_source_obj_to_buffer(oop src_obj);
198
199 static void maybe_fill_gc_region_gap(size_t required_byte_size);
200 static size_t filler_array_byte_size(int length);
201 static int filler_array_length(size_t fill_bytes);
202 static HeapWord* init_filler_array_at_buffer_top(int array_length, size_t fill_bytes);
203
204 static void set_requested_address(ArchiveHeapInfo* info);
205 static void relocate_embedded_oops(GrowableArrayCHeap<oop, mtClassShared>* roots, ArchiveHeapInfo* info);
206 static void compute_ptrmap(ArchiveHeapInfo *info);
207 static bool is_in_requested_range(oop o);
208 static oop requested_obj_from_buffer_offset(size_t offset);
209
210 static oop load_oop_from_buffer(oop* buffered_addr);
211 static oop load_oop_from_buffer(narrowOop* buffered_addr);
212 inline static void store_oop_in_buffer(oop* buffered_addr, oop requested_obj);
213 inline static void store_oop_in_buffer(narrowOop* buffered_addr, oop requested_obj);
214
215 template <typename T> static oop load_source_oop_from_buffer(T* buffered_addr);
216 template <typename T> static void store_requested_oop_in_buffer(T* buffered_addr, oop request_oop);
217
|
1 /*
2 * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 // HeapShared::archive_objects() recursively searches for the oops that need to be
77 // stored into the CDS archive. 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
85 // to make sure no objects span across boundaries of MIN_GC_REGION_ALIGNMENT.
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 static void update_stats(oop src_obj);
200
201 static void maybe_fill_gc_region_gap(size_t required_byte_size);
202 static size_t filler_array_byte_size(int length);
203 static int filler_array_length(size_t fill_bytes);
204 static HeapWord* init_filler_array_at_buffer_top(int array_length, size_t fill_bytes);
205
206 static void set_requested_address(ArchiveHeapInfo* info);
207 static void relocate_embedded_oops(GrowableArrayCHeap<oop, mtClassShared>* roots, ArchiveHeapInfo* info);
208 static void compute_ptrmap(ArchiveHeapInfo *info);
209 static bool is_in_requested_range(oop o);
210 static oop requested_obj_from_buffer_offset(size_t offset);
211
212 static oop load_oop_from_buffer(oop* buffered_addr);
213 static oop load_oop_from_buffer(narrowOop* buffered_addr);
214 inline static void store_oop_in_buffer(oop* buffered_addr, oop requested_obj);
215 inline static void store_oop_in_buffer(narrowOop* buffered_addr, oop requested_obj);
216
217 template <typename T> static oop load_source_oop_from_buffer(T* buffered_addr);
218 template <typename T> static void store_requested_oop_in_buffer(T* buffered_addr, oop request_oop);
219
|