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
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 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
156 int _narrow_klass_shift; // save shift width used to pre-compute narrowKlass IDs in archived heap objects
158 narrowPtr _early_serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
159 narrowPtr _serialized_data; // Data accessed using {ReadClosure,WriteClosure}::serialize()
160
161 // The following fields are all sanity checks for whether this archive
162 // will function correctly with this JVM and the bootclasspath it's
163 // invoked with.
164 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
165
166 narrowPtr _class_location_config;
167
168 bool _verify_local; // BytecodeVerificationLocal setting
169 bool _verify_remote; // BytecodeVerificationRemote setting
170 bool _has_platform_or_app_classes; // Archive contains app or platform classes
171 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
172 char* _mapped_base_address; // Actual base address where archive is mapped.
173
174 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
175 // some expensive operations.
176 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
177 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
178 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview?
179 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
180 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
181 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
182
183 AOTMappedHeapHeader _mapped_heap_header;
184 AOTStreamedHeapHeader _streamed_heap_header;
185
186 // The following are parameters that affect MethodData layout.
187 u1 _compiler_type;
188 uint _type_profile_level;
189 int _type_profile_args_limit;
190 int _type_profile_parms_limit;
191 intx _type_profile_width;
192 intx _bci_profile_width;
193 bool _profile_traps;
194 bool _type_profile_casts;
195 int _spec_trap_limit_extra_entries;
196
197 template <typename T> T decode(narrowPtr narrowp) const {
198 return AOTCompressedPointers::decode_not_null<T>(narrowp, reinterpret_cast<address>(mapped_base_address()));
199 }
266
267 void set_requested_base(char* b) {
268 _requested_base_address = b;
269 _mapped_base_address = nullptr;
270 }
271
272 bool validate();
273 int compute_crc();
274
275 FileMapRegion* region_at(int i) {
276 assert(is_valid_region(i), "invalid region");
277 return FileMapRegion::cast(&_regions[i]);
278 }
279
280 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
281 size_t base_archive_name_size, size_t base_archive_name_offset);
282 static bool is_valid_region(int region) {
283 return (0 <= region && region < NUM_CDS_REGIONS);
284 }
285
286 bool check_must_match_flags() const {
287 return _must_match.runtime_check();
288 }
289
290 void print(outputStream* st);
291 };
292
293 class FileMapInfo : public CHeapObj<mtInternal> {
294 private:
295 friend class ManifestStream;
296 friend class VMStructs;
297 friend class ArchiveBuilder;
298 friend class CDSOffsets;
299 friend class FileMapHeader;
300
301 bool _is_static;
302 bool _file_open;
303 bool _is_mapped;
304 int _fd;
305 size_t _file_offset;
306 const char* _full_path;
307 const char* _base_archive_name;
308 FileMapHeader* _header;
309
|