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 _compressed_class_ptrs; // save the flag UseCompressedClassPointers
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(UseNonAtomicValueFlattening) \
112 f(UseAtomicValueFlattening) \
113 f(UseNullableValueFlattening) \
114 f(UseNullableNonAtomicValueFlattening)
115
116
117 class CDSMustMatchFlags {
118 private:
119 size_t _max_name_width;
120 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
121 decltype(n) _v_##n;
122 CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
123 #undef DECLARE_CDS_MUST_MATCH_FLAG
124
125 inline static void do_print(outputStream* st, bool v);
126 inline static void do_print(outputStream* st, intx v);
127 inline static void do_print(outputStream* st, uintx v);
128 inline static void do_print(outputStream* st, double v);
129 void print_info() const;
130
131 public:
132 void init();
133 bool runtime_check() const;
134 void print(outputStream* st) const;
135 };
136
137 class FileMapHeader: private CDSFileMapHeaderBase {
138 friend class CDSConstants;
139 friend class VMStructs;
140 using narrowPtr = AOTCompressedPointers::narrowPtr;
141 private:
142 // The following fields record the states of the VM during dump time.
143 // They are compared with the runtime states to see if the archive
144 // can be used.
145 size_t _core_region_alignment; // how shared archive should be aligned
146 int _obj_alignment; // value of ObjectAlignmentInBytes
147 address _narrow_oop_base; // compressed oop encoding base
148 int _narrow_oop_shift; // compressed oop encoding shift
149 bool _compact_strings; // value of CompactStrings
150 bool _compact_headers; // value of UseCompactObjectHeaders
151 uintx _max_heap_size; // java max heap size during dumping
152 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
153 bool _object_streaming_mode; // dump was created for object streaming
154 bool _compressed_oops; // save the flag UseCompressedOops
155 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
156 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
159 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
160 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
161
162 // The following fields are all sanity checks for whether this archive
163 // will function correctly with this JVM and the bootclasspath it's
164 // invoked with.
165 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
166
167 narrowPtr _class_location_config;
168
169 bool _verify_local; // BytecodeVerificationLocal setting
170 bool _verify_remote; // BytecodeVerificationRemote setting
171 bool _has_platform_or_app_classes; // Archive contains app or platform classes
172 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
173 char* _mapped_base_address; // Actual base address where archive is mapped.
174
175 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
176 // some expensive operations.
177 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
178 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
179 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview?
180 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
181 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
182 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
183
184 AOTMappedHeapHeader _mapped_heap_header;
185 AOTStreamedHeapHeader _streamed_heap_header;
186
187 // The following are parameters that affect MethodData layout.
188 u1 _compiler_type;
189 uint _type_profile_level;
190 int _type_profile_args_limit;
191 int _type_profile_parms_limit;
192 intx _type_profile_width;
193 intx _bci_profile_width;
194 bool _profile_traps;
195 bool _type_profile_casts;
196 int _spec_trap_limit_extra_entries;
197
198 template <typename T> T decode(narrowPtr narrowp) const {
199 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
200 }
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
|