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 *
23 */
24
25 #ifndef SHARE_CDS_ARCHIVEUTILS_HPP
26 #define SHARE_CDS_ARCHIVEUTILS_HPP
27
28 #include "cds/serializeClosure.hpp"
29 #include "logging/log.hpp"
30 #include "memory/virtualspace.hpp"
31 #include "utilities/bitMap.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/macros.hpp"
34
35 class BootstrapInfo;
36 class ReservedSpace;
37 class VirtualSpace;
38
39 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
40 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
41 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
42 // fixed, but _ptr_end can be expanded as more objects are dumped.
43 class ArchivePtrMarker : AllStatic {
44 static CHeapBitMap* _ptrmap;
45 static CHeapBitMap* _rw_ptrmap;
46 static CHeapBitMap* _ro_ptrmap;
47 static VirtualSpace* _vs;
48
49 // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
50 // avoid unintentional copy operations after the bitmap has been finalized and written.
51 static bool _compacted;
52
53 static address* ptr_base() { return (address*)_vs->low(); } // committed lower bound (inclusive)
54 static address* ptr_end() { return (address*)_vs->high(); } // committed upper bound (exclusive)
55
56 public:
57 static void initialize(CHeapBitMap* ptrmap, VirtualSpace* vs);
58 static void initialize_rw_ro_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap);
59 static void mark_pointer(address* ptr_loc);
60 static void clear_pointer(address* ptr_loc);
61 static void compact(address relocatable_base, address relocatable_end);
62 static void compact(size_t max_non_null_offset);
63
64 template <typename T>
65 static void mark_pointer(T* ptr_loc) {
66 mark_pointer((address*)ptr_loc);
67 }
68
69 template <typename T>
70 static void set_and_mark_pointer(T* ptr_loc, T ptr_value) {
71 *ptr_loc = ptr_value;
72 mark_pointer(ptr_loc);
73 }
74
75 static CHeapBitMap* ptrmap() {
76 return _ptrmap;
77 }
78
79 static CHeapBitMap* rw_ptrmap() {
80 return _rw_ptrmap;
81 }
82
83 static CHeapBitMap* ro_ptrmap() {
84 return _ro_ptrmap;
85 }
86
87 static void reset_map_and_vs() {
88 _ptrmap = nullptr;
89 _rw_ptrmap = nullptr;
90 _ro_ptrmap = nullptr;
91 _vs = nullptr;
92 }
93 };
94
95 // SharedDataRelocator is used to shift pointers in the CDS archive.
96 //
97 // The CDS archive is basically a contiguous block of memory (divided into several regions)
98 // that contains multiple objects. The objects may contain direct pointers that point to other objects
99 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
100 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
101 //
102 // The contents of the archive assumes that it’s mapped at the default SharedBaseAddress (e.g. 0x800000000).
103 // If the archive ends up being mapped at a different address (e.g. 0x810000000), SharedDataRelocator
104 // is used to shift each marked pointer by a delta (0x10000000 in this example), so that it points to
105 // the actually mapped location of the target object.
106 class SharedDataRelocator: public BitMapClosure {
107 // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; }
108
109 // Patch all pointers within this region that are marked.
110 address* _patch_base;
231
232 inline intptr_t nextPtr() {
233 return *(*_ptr_array)++;
234 }
235
236 public:
237 ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
238
239 void do_ptr(void** p);
240 void do_u4(u4* p);
241 void do_int(int* p);
242 void do_bool(bool *p);
243 void do_tag(int tag);
244 bool reading() const { return true; }
245 char* region_top() { return nullptr; }
246 };
247
248 class ArchiveUtils {
249 public:
250 static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
251 };
252
253 class HeapRootSegments {
254 private:
255 size_t _base_offset;
256 size_t _count;
257 int _roots_count;
258 int _max_size_in_bytes;
259 int _max_size_in_elems;
260
261 public:
262 size_t base_offset() { return _base_offset; }
263 size_t count() { return _count; }
264 int roots_count() { return _roots_count; }
265 int max_size_in_bytes() { return _max_size_in_bytes; }
266 int max_size_in_elems() { return _max_size_in_elems; }
267
268 size_t size_in_bytes(size_t seg_idx);
269 int size_in_elems(size_t seg_idx);
270 size_t segment_offset(size_t seg_idx);
|
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 *
23 */
24
25 #ifndef SHARE_CDS_ARCHIVEUTILS_HPP
26 #define SHARE_CDS_ARCHIVEUTILS_HPP
27
28 #include "cds/serializeClosure.hpp"
29 #include "logging/log.hpp"
30 #include "memory/virtualspace.hpp"
31 #include "utilities/bitMap.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/macros.hpp"
34
35 class BootstrapInfo;
36 class ReservedSpace;
37 class VirtualSpace;
38
39 template<class E> class Array;
40 template<class E> class GrowableArray;
41
42 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
43 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
44 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
45 // fixed, but _ptr_end can be expanded as more objects are dumped.
46 class ArchivePtrMarker : AllStatic {
47 static CHeapBitMap* _ptrmap;
48 static CHeapBitMap* _rw_ptrmap;
49 static CHeapBitMap* _ro_ptrmap;
50 static CHeapBitMap* _cc_ptrmap;
51 static VirtualSpace* _vs;
52
53 // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
54 // avoid unintentional copy operations after the bitmap has been finalized and written.
55 static bool _compacted;
56
57 static address* ptr_base() { return (address*)_vs->low(); } // committed lower bound (inclusive)
58 static address* ptr_end() { return (address*)_vs->high(); } // committed upper bound (exclusive)
59
60 public:
61 static void initialize(CHeapBitMap* ptrmap, VirtualSpace* vs);
62 static void initialize_rw_ro_cc_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, CHeapBitMap* cc_ptrmap);
63 static void mark_pointer(address* ptr_loc);
64 static void clear_pointer(address* ptr_loc);
65 static void compact(address relocatable_base, address relocatable_end);
66 static void compact(size_t max_non_null_offset);
67
68 template <typename T>
69 static void mark_pointer(T* ptr_loc) {
70 mark_pointer((address*)ptr_loc);
71 }
72
73 template <typename T>
74 static void set_and_mark_pointer(T* ptr_loc, T ptr_value) {
75 *ptr_loc = ptr_value;
76 mark_pointer(ptr_loc);
77 }
78
79 static CHeapBitMap* ptrmap() {
80 return _ptrmap;
81 }
82
83 static CHeapBitMap* rw_ptrmap() {
84 return _rw_ptrmap;
85 }
86
87 static CHeapBitMap* ro_ptrmap() {
88 return _ro_ptrmap;
89 }
90
91 static CHeapBitMap* cc_ptrmap() {
92 return _cc_ptrmap;
93 }
94
95 static void reset_map_and_vs() {
96 _ptrmap = nullptr;
97 _rw_ptrmap = nullptr;
98 _ro_ptrmap = nullptr;
99 _cc_ptrmap = nullptr;
100 _vs = nullptr;
101 }
102 };
103
104 // SharedDataRelocator is used to shift pointers in the CDS archive.
105 //
106 // The CDS archive is basically a contiguous block of memory (divided into several regions)
107 // that contains multiple objects. The objects may contain direct pointers that point to other objects
108 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
109 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
110 //
111 // The contents of the archive assumes that it’s mapped at the default SharedBaseAddress (e.g. 0x800000000).
112 // If the archive ends up being mapped at a different address (e.g. 0x810000000), SharedDataRelocator
113 // is used to shift each marked pointer by a delta (0x10000000 in this example), so that it points to
114 // the actually mapped location of the target object.
115 class SharedDataRelocator: public BitMapClosure {
116 // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; }
117
118 // Patch all pointers within this region that are marked.
119 address* _patch_base;
240
241 inline intptr_t nextPtr() {
242 return *(*_ptr_array)++;
243 }
244
245 public:
246 ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
247
248 void do_ptr(void** p);
249 void do_u4(u4* p);
250 void do_int(int* p);
251 void do_bool(bool *p);
252 void do_tag(int tag);
253 bool reading() const { return true; }
254 char* region_top() { return nullptr; }
255 };
256
257 class ArchiveUtils {
258 public:
259 static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
260
261 template <typename T> static Array<T>* archive_array(GrowableArray<T>* tmp_array);
262
263 // Used in logging: "boot", "boot2", "plat", "app" and "unreg";
264 static const char* class_category(Klass* k);
265
266 static const char* builtin_loader_name_or_null(oop loader); // "boot", "platform", "app", or nullptr
267 static const char* builtin_loader_name(oop loader); // "boot", "platform", or "app". Asserts if not a built-in-loader.
268
269 static bool builtin_loader_from_type(const char* loader_type, oop* value_ret);
270 static oop builtin_loader_from_type(int loader_type);
271 };
272
273 class HeapRootSegments {
274 private:
275 size_t _base_offset;
276 size_t _count;
277 int _roots_count;
278 int _max_size_in_bytes;
279 int _max_size_in_elems;
280
281 public:
282 size_t base_offset() { return _base_offset; }
283 size_t count() { return _count; }
284 int roots_count() { return _roots_count; }
285 int max_size_in_bytes() { return _max_size_in_bytes; }
286 int max_size_in_elems() { return _max_size_in_elems; }
287
288 size_t size_in_bytes(size_t seg_idx);
289 int size_in_elems(size_t seg_idx);
290 size_t segment_offset(size_t seg_idx);
|