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 bool _compatible_oop_compression; // value of AOTCompatibleOopCompression at dump time
124 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
127 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
128 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
129
130 // The following fields are all sanity checks for whether this archive
131 // will function correctly with this JVM and the bootclasspath it's
132 // invoked with.
133 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
134
135 narrowPtr _class_location_config;
136
137 bool _verify_local; // BytecodeVerificationLocal setting
138 bool _verify_remote; // BytecodeVerificationRemote setting
139 bool _has_platform_or_app_classes; // Archive contains app or platform classes
140 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
141 char* _mapped_base_address; // Actual base address where archive is mapped.
142
143 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
144 // some expensive operations.
145 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
146 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
147 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
148 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
149
150 AOTMappedHeapHeader _mapped_heap_header;
151 AOTStreamedHeapHeader _streamed_heap_header;
152
153 // The following are parameters that affect MethodData layout.
154 u1 _compiler_type;
155 uint _type_profile_level;
156 int _type_profile_args_limit;
157 int _type_profile_parms_limit;
158 intx _type_profile_width;
159 intx _bci_profile_width;
160 bool _profile_traps;
161 bool _type_profile_casts;
162 int _spec_trap_limit_extra_entries;
163
164 template <typename T> T decode(narrowPtr narrowp) const {
165 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
166 }
234
235 void set_requested_base(char* b) {
236 _requested_base_address = b;
237 _mapped_base_address = nullptr;
238 }
239
240 bool validate();
241 int compute_crc();
242
243 FileMapRegion* region_at(int i) {
244 assert(is_valid_region(i), "invalid region");
245 return FileMapRegion::cast(&_regions[i]);
246 }
247
248 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
249 size_t base_archive_name_size, size_t base_archive_name_offset);
250 static bool is_valid_region(int region) {
251 return (0 <= region && region < NUM_CDS_REGIONS);
252 }
253
254 void print(outputStream* st);
255 };
256
257 class FileMapInfo : public CHeapObj<mtInternal> {
258 private:
259 friend class ManifestStream;
260 friend class VMStructs;
261 friend class ArchiveBuilder;
262 friend class CDSOffsets;
263 friend class FileMapHeader;
264
265 bool _is_static;
266 bool _file_open;
267 bool _is_mapped;
268 int _fd;
269 size_t _file_offset;
270 const char* _full_path;
271 const char* _base_archive_name;
272 FileMapHeader* _header;
273
|
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 bool _compatible_oop_compression; // value of AOTCompatibleOopCompression at dump time
158 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
161 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
162 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
163
164 // The following fields are all sanity checks for whether this archive
165 // will function correctly with this JVM and the bootclasspath it's
166 // invoked with.
167 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
168
169 narrowPtr _class_location_config;
170
171 bool _verify_local; // BytecodeVerificationLocal setting
172 bool _verify_remote; // BytecodeVerificationRemote setting
173 bool _has_platform_or_app_classes; // Archive contains app or platform classes
174 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
175 char* _mapped_base_address; // Actual base address where archive is mapped.
176
177 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
178 // some expensive operations.
179 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
180 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
181 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview?
182 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
183 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
184 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
185
186 AOTMappedHeapHeader _mapped_heap_header;
187 AOTStreamedHeapHeader _streamed_heap_header;
188
189 // The following are parameters that affect MethodData layout.
190 u1 _compiler_type;
191 uint _type_profile_level;
192 int _type_profile_args_limit;
193 int _type_profile_parms_limit;
194 intx _type_profile_width;
195 intx _bci_profile_width;
196 bool _profile_traps;
197 bool _type_profile_casts;
198 int _spec_trap_limit_extra_entries;
199
200 template <typename T> T decode(narrowPtr narrowp) const {
201 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
202 }
270
271 void set_requested_base(char* b) {
272 _requested_base_address = b;
273 _mapped_base_address = nullptr;
274 }
275
276 bool validate();
277 int compute_crc();
278
279 FileMapRegion* region_at(int i) {
280 assert(is_valid_region(i), "invalid region");
281 return FileMapRegion::cast(&_regions[i]);
282 }
283
284 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
285 size_t base_archive_name_size, size_t base_archive_name_offset);
286 static bool is_valid_region(int region) {
287 return (0 <= region && region < NUM_CDS_REGIONS);
288 }
289
290 bool check_must_match_flags() const {
291 return _must_match.runtime_check();
292 }
293
294 void print(outputStream* st);
295 };
296
297 class FileMapInfo : public CHeapObj<mtInternal> {
298 private:
299 friend class ManifestStream;
300 friend class VMStructs;
301 friend class ArchiveBuilder;
302 friend class CDSOffsets;
303 friend class FileMapHeader;
304
305 bool _is_static;
306 bool _file_open;
307 bool _is_mapped;
308 int _fd;
309 size_t _file_offset;
310 const char* _full_path;
311 const char* _base_archive_name;
312 FileMapHeader* _header;
313
|