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_FILEMAP_HPP
26 #define SHARE_CDS_FILEMAP_HPP
27
28 #include "cds/aotCompressedPointers.hpp"
29 #include "cds/aotMappedHeap.hpp"
30 #include "cds/aotMetaspace.hpp"
31 #include "cds/aotStreamedHeap.hpp"
32 #include "cds/archiveUtils.hpp"
33 #include "cds/heapShared.hpp"
34 #include "include/cds.h"
35 #include "logging/logLevel.hpp"
36 #include "memory/allocation.hpp"
37 #include "oops/array.hpp"
38 #include "oops/compressedOops.hpp"
39 #include "utilities/align.hpp"
40 #include "utilities/bitMap.hpp"
41
42 // To understand the layout of the CDS archive file:
43 //
44 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
45 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
46 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
47
48 static const int JVM_IDENT_MAX = 256;
49
50 class AOTClassLocationConfig;
51 class BitMapView;
52 class CHeapBitMap;
53 class ClassFileStream;
54 class ClassLoaderData;
55 class ClassPathEntry;
56 class outputStream;
57 class ReservedSpace;
58
85 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
86 size_t ptrmap_offset() const { return _ptrmap_offset; }
87 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
88 bool in_reserved_space() const { return _in_reserved_space; }
89
90 void set_file_offset(size_t s) { _file_offset = s; }
91 void set_read_only(bool v) { _read_only = v; }
92 void set_mapped_base(char* p) { _mapped_base = p; }
93 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
94 void set_in_reserved_space(bool is_reserved) { _in_reserved_space = is_reserved; }
95 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
96 bool allow_exec, int crc);
97 void init_oopmap(size_t offset, size_t size_in_bits);
98 void init_ptrmap(size_t offset, size_t size_in_bits);
99 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
100
101 bool check_region_crc(char* base) const;
102 void print(outputStream* st, int region_index);
103 };
104
105 class FileMapHeader: private CDSFileMapHeaderBase {
106 friend class CDSConstants;
107 friend class VMStructs;
108 using narrowPtr = AOTCompressedPointers::narrowPtr;
109 private:
110 // The following fields record the states of the VM during dump time.
111 // They are compared with the runtime states to see if the archive
112 // can be used.
113 size_t _core_region_alignment; // how shared archive should be aligned
114 int _obj_alignment; // value of ObjectAlignmentInBytes
115 address _narrow_oop_base; // compressed oop encoding base
116 int _narrow_oop_shift; // compressed oop encoding shift
117 bool _compact_strings; // value of CompactStrings
118 bool _compact_headers; // value of UseCompactObjectHeaders
119 uintx _max_heap_size; // java max heap size during dumping
120 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
121 bool _object_streaming_mode; // dump was created for object streaming
122 bool _compressed_oops; // save the flag UseCompressedOops
123 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
124 int _narrow_klass_shift; // save shift width used to pre-compute narrowKlass IDs in archived heap objects
126 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
127 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
128
129 // The following fields are all sanity checks for whether this archive
130 // will function correctly with this JVM and the bootclasspath it's
131 // invoked with.
132 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
133
134 narrowPtr _class_location_config;
135
136 bool _verify_local; // BytecodeVerificationLocal setting
137 bool _verify_remote; // BytecodeVerificationRemote setting
138 bool _has_platform_or_app_classes; // Archive contains app or platform classes
139 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
140 char* _mapped_base_address; // Actual base address where archive is mapped.
141
142 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
143 // some expensive operations.
144 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
145 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
146 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
147 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
148
149 AOTMappedHeapHeader _mapped_heap_header;
150 AOTStreamedHeapHeader _streamed_heap_header;
151
152 // The following are parameters that affect MethodData layout.
153 u1 _compiler_type;
154 uint _type_profile_level;
155 int _type_profile_args_limit;
156 int _type_profile_parms_limit;
157 intx _type_profile_width;
158 intx _bci_profile_width;
159 bool _profile_traps;
160 bool _type_profile_casts;
161 int _spec_trap_limit_extra_entries;
162
163 template <typename T> T decode(narrowPtr narrowp) const {
164 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
165 }
232
233 void set_requested_base(char* b) {
234 _requested_base_address = b;
235 _mapped_base_address = nullptr;
236 }
237
238 bool validate();
239 int compute_crc();
240
241 FileMapRegion* region_at(int i) {
242 assert(is_valid_region(i), "invalid region");
243 return FileMapRegion::cast(&_regions[i]);
244 }
245
246 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
247 size_t base_archive_name_size, size_t base_archive_name_offset);
248 static bool is_valid_region(int region) {
249 return (0 <= region && region < NUM_CDS_REGIONS);
250 }
251
252 void print(outputStream* st);
253 };
254
255 class FileMapInfo : public CHeapObj<mtInternal> {
256 private:
257 friend class ManifestStream;
258 friend class VMStructs;
259 friend class ArchiveBuilder;
260 friend class CDSOffsets;
261 friend class FileMapHeader;
262
263 bool _is_static;
264 bool _file_open;
265 bool _is_mapped;
266 int _fd;
267 size_t _file_offset;
268 const char* _full_path;
269 const char* _base_archive_name;
270 FileMapHeader* _header;
271
|
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_FILEMAP_HPP
26 #define SHARE_CDS_FILEMAP_HPP
27
28 #include "cds/aotCompressedPointers.hpp"
29 #include "cds/aotMappedHeap.hpp"
30 #include "cds/aotMetaspace.hpp"
31 #include "cds/aotStreamedHeap.hpp"
32 #include "cds/archiveUtils.hpp"
33 #include "cds/heapShared.hpp"
34 #include "include/cds.h"
35 #include "logging/logLevel.hpp"
36 #include "memory/allocation.hpp"
37 #include "oops/array.hpp"
38 #include "oops/compressedOops.hpp"
39 #include "runtime/globals.hpp"
40 #include "utilities/align.hpp"
41 #include "utilities/bitMap.hpp"
42
43 // To understand the layout of the CDS archive file:
44 //
45 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
46 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
47 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
48
49 static const int JVM_IDENT_MAX = 256;
50
51 class AOTClassLocationConfig;
52 class BitMapView;
53 class CHeapBitMap;
54 class ClassFileStream;
55 class ClassLoaderData;
56 class ClassPathEntry;
57 class outputStream;
58 class ReservedSpace;
59
86 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
87 size_t ptrmap_offset() const { return _ptrmap_offset; }
88 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
89 bool in_reserved_space() const { return _in_reserved_space; }
90
91 void set_file_offset(size_t s) { _file_offset = s; }
92 void set_read_only(bool v) { _read_only = v; }
93 void set_mapped_base(char* p) { _mapped_base = p; }
94 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
95 void set_in_reserved_space(bool is_reserved) { _in_reserved_space = is_reserved; }
96 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
97 bool allow_exec, int crc);
98 void init_oopmap(size_t offset, size_t size_in_bits);
99 void init_ptrmap(size_t offset, size_t size_in_bits);
100 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
101
102 bool check_region_crc(char* base) const;
103 void print(outputStream* st, int region_index);
104 };
105
106 #define CDS_MUST_MATCH_FLAGS_DO(f) \
107 f(UseArrayFlattening) \
108 f(UseFieldFlattening) \
109 f(InlineTypePassFieldsAsArgs) \
110 f(InlineTypeReturnedAsFields) \
111 f(UseNullFreeNonAtomicValueFlattening) \
112 f(UseNullFreeAtomicValueFlattening) \
113 f(UseNullableAtomicValueFlattening) \
114 f(UseNullableNonAtomicValueFlattening) \
115 f(FlatteningBudget)
116
117
118 class CDSMustMatchFlags {
119 private:
120 size_t _max_name_width;
121 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
122 decltype(n) _v_##n;
123 CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
124 #undef DECLARE_CDS_MUST_MATCH_FLAG
125
126 inline static void do_print(outputStream* st, bool v);
127 LP64_ONLY(inline static void do_print(outputStream* st, uint v);)
128 inline static void do_print(outputStream* st, intx v);
129 inline static void do_print(outputStream* st, uintx v);
130 inline static void do_print(outputStream* st, double v);
131 void print_info() const;
132
133 public:
134 void init();
135 bool runtime_check() const;
136 void print(outputStream* st) const;
137 };
138
139 class FileMapHeader: private CDSFileMapHeaderBase {
140 friend class CDSConstants;
141 friend class VMStructs;
142 using narrowPtr = AOTCompressedPointers::narrowPtr;
143 private:
144 // The following fields record the states of the VM during dump time.
145 // They are compared with the runtime states to see if the archive
146 // can be used.
147 size_t _core_region_alignment; // how shared archive should be aligned
148 int _obj_alignment; // value of ObjectAlignmentInBytes
149 address _narrow_oop_base; // compressed oop encoding base
150 int _narrow_oop_shift; // compressed oop encoding shift
151 bool _compact_strings; // value of CompactStrings
152 bool _compact_headers; // value of UseCompactObjectHeaders
153 uintx _max_heap_size; // java max heap size during dumping
154 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
155 bool _object_streaming_mode; // dump was created for object streaming
156 bool _compressed_oops; // save the flag UseCompressedOops
157 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
158 int _narrow_klass_shift; // save shift width used to pre-compute narrowKlass IDs in archived heap objects
160 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
161 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
162
163 // The following fields are all sanity checks for whether this archive
164 // will function correctly with this JVM and the bootclasspath it's
165 // invoked with.
166 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
167
168 narrowPtr _class_location_config;
169
170 bool _verify_local; // BytecodeVerificationLocal setting
171 bool _verify_remote; // BytecodeVerificationRemote setting
172 bool _has_platform_or_app_classes; // Archive contains app or platform classes
173 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
174 char* _mapped_base_address; // Actual base address where archive is mapped.
175
176 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
177 // some expensive operations.
178 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
179 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
180 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview?
181 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
182 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
183 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
184
185 AOTMappedHeapHeader _mapped_heap_header;
186 AOTStreamedHeapHeader _streamed_heap_header;
187
188 // The following are parameters that affect MethodData layout.
189 u1 _compiler_type;
190 uint _type_profile_level;
191 int _type_profile_args_limit;
192 int _type_profile_parms_limit;
193 intx _type_profile_width;
194 intx _bci_profile_width;
195 bool _profile_traps;
196 bool _type_profile_casts;
197 int _spec_trap_limit_extra_entries;
198
199 template <typename T> T decode(narrowPtr narrowp) const {
200 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
201 }
268
269 void set_requested_base(char* b) {
270 _requested_base_address = b;
271 _mapped_base_address = nullptr;
272 }
273
274 bool validate();
275 int compute_crc();
276
277 FileMapRegion* region_at(int i) {
278 assert(is_valid_region(i), "invalid region");
279 return FileMapRegion::cast(&_regions[i]);
280 }
281
282 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
283 size_t base_archive_name_size, size_t base_archive_name_offset);
284 static bool is_valid_region(int region) {
285 return (0 <= region && region < NUM_CDS_REGIONS);
286 }
287
288 bool check_must_match_flags() const {
289 return _must_match.runtime_check();
290 }
291
292 void print(outputStream* st);
293 };
294
295 class FileMapInfo : public CHeapObj<mtInternal> {
296 private:
297 friend class ManifestStream;
298 friend class VMStructs;
299 friend class ArchiveBuilder;
300 friend class CDSOffsets;
301 friend class FileMapHeader;
302
303 bool _is_static;
304 bool _file_open;
305 bool _is_mapped;
306 int _fd;
307 size_t _file_offset;
308 const char* _full_path;
309 const char* _base_archive_name;
310 FileMapHeader* _header;
311
|