15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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/archiveUtils.hpp"
29 #include "cds/metaspaceShared.hpp"
30 #include "include/cds.h"
31 #include "logging/logLevel.hpp"
32 #include "memory/allocation.hpp"
33 #include "oops/array.hpp"
34 #include "oops/compressedOops.hpp"
35 #include "utilities/align.hpp"
36
37 // To understand the layout of the CDS archive file:
38 //
39 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
40 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
41 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
42
43 static const int JVM_IDENT_MAX = 256;
44
45 class AOTClassLocationConfig;
46 class ArchiveHeapInfo;
47 class BitMapView;
48 class CHeapBitMap;
49 class ClassFileStream;
50 class ClassLoaderData;
51 class ClassPathEntry;
52 class outputStream;
53 class ReservedSpace;
54
81 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
82 size_t ptrmap_offset() const { return _ptrmap_offset; }
83 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
84 bool in_reserved_space() const { return _in_reserved_space; }
85
86 void set_file_offset(size_t s) { _file_offset = s; }
87 void set_read_only(bool v) { _read_only = v; }
88 void set_mapped_base(char* p) { _mapped_base = p; }
89 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
90 void set_in_reserved_space(bool is_reserved) { _in_reserved_space = is_reserved; }
91 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
92 bool allow_exec, int crc);
93 void init_oopmap(size_t offset, size_t size_in_bits);
94 void init_ptrmap(size_t offset, size_t size_in_bits);
95 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
96
97 bool check_region_crc(char* base) const;
98 void print(outputStream* st, int region_index);
99 };
100
101 class FileMapHeader: private CDSFileMapHeaderBase {
102 friend class CDSConstants;
103 friend class VMStructs;
104
105 private:
106 // The following fields record the states of the VM during dump time.
107 // They are compared with the runtime states to see if the archive
108 // can be used.
109 size_t _core_region_alignment; // how shared archive should be aligned
110 int _obj_alignment; // value of ObjectAlignmentInBytes
111 address _narrow_oop_base; // compressed oop encoding base
112 int _narrow_oop_shift; // compressed oop encoding shift
113 bool _compact_strings; // value of CompactStrings
114 bool _compact_headers; // value of UseCompactObjectHeaders
115 uintx _max_heap_size; // java max heap size during dumping
116 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
117 bool _compressed_oops; // save the flag UseCompressedOops
118 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
119 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
120 int _narrow_klass_shift; // save shift width used to pre-compute narrowKlass IDs in archived heap objects
123 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
124
125 // The following fields are all sanity checks for whether this archive
126 // will function correctly with this JVM and the bootclasspath it's
127 // invoked with.
128 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
129
130 size_t _class_location_config_offset;
131
132 bool _verify_local; // BytecodeVerificationLocal setting
133 bool _verify_remote; // BytecodeVerificationRemote setting
134 bool _has_platform_or_app_classes; // Archive contains app or platform classes
135 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
136 char* _mapped_base_address; // Actual base address where archive is mapped.
137
138 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
139 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
140 // some expensive operations.
141 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
142 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
143 HeapRootSegments _heap_root_segments; // Heap root segments info
144 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
145 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
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 template <typename T> T from_mapped_offset(size_t offset) const {
149 return (T)(mapped_base_address() + offset);
150 }
151 void set_as_offset(char* p, size_t *offset);
152 template <typename T> void set_as_offset(T p, size_t *offset) {
153 set_as_offset((char*)p, offset);
154 }
155
156 public:
157 // Accessors -- fields declared in GenericCDSFileMapHeader
158 unsigned int magic() const { return _generic_header._magic; }
159 int crc() const { return _generic_header._crc; }
160 int version() const { return _generic_header._version; }
161 unsigned int header_size() const { return _generic_header._header_size; }
162 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
219
220 void set_requested_base(char* b) {
221 _requested_base_address = b;
222 _mapped_base_address = nullptr;
223 }
224
225 bool validate();
226 int compute_crc();
227
228 FileMapRegion* region_at(int i) {
229 assert(is_valid_region(i), "invalid region");
230 return FileMapRegion::cast(&_regions[i]);
231 }
232
233 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
234 size_t base_archive_name_size, size_t base_archive_name_offset);
235 static bool is_valid_region(int region) {
236 return (0 <= region && region < NUM_CDS_REGIONS);
237 }
238
239 void print(outputStream* st);
240 };
241
242 class FileMapInfo : public CHeapObj<mtInternal> {
243 private:
244 friend class ManifestStream;
245 friend class VMStructs;
246 friend class ArchiveBuilder;
247 friend class CDSOffsets;
248 friend class FileMapHeader;
249
250 bool _is_static;
251 bool _file_open;
252 bool _is_mapped;
253 int _fd;
254 size_t _file_offset;
255 const char* _full_path;
256 const char* _base_archive_name;
257 FileMapHeader* _header;
258
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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/archiveUtils.hpp"
29 #include "cds/metaspaceShared.hpp"
30 #include "include/cds.h"
31 #include "logging/logLevel.hpp"
32 #include "memory/allocation.hpp"
33 #include "oops/array.hpp"
34 #include "oops/compressedOops.hpp"
35 #include "runtime/globals.hpp"
36 #include "utilities/align.hpp"
37
38 // To understand the layout of the CDS archive file:
39 //
40 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
41 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
42 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
43
44 static const int JVM_IDENT_MAX = 256;
45
46 class AOTClassLocationConfig;
47 class ArchiveHeapInfo;
48 class BitMapView;
49 class CHeapBitMap;
50 class ClassFileStream;
51 class ClassLoaderData;
52 class ClassPathEntry;
53 class outputStream;
54 class ReservedSpace;
55
82 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
83 size_t ptrmap_offset() const { return _ptrmap_offset; }
84 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
85 bool in_reserved_space() const { return _in_reserved_space; }
86
87 void set_file_offset(size_t s) { _file_offset = s; }
88 void set_read_only(bool v) { _read_only = v; }
89 void set_mapped_base(char* p) { _mapped_base = p; }
90 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
91 void set_in_reserved_space(bool is_reserved) { _in_reserved_space = is_reserved; }
92 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
93 bool allow_exec, int crc);
94 void init_oopmap(size_t offset, size_t size_in_bits);
95 void init_ptrmap(size_t offset, size_t size_in_bits);
96 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
97
98 bool check_region_crc(char* base) const;
99 void print(outputStream* st, int region_index);
100 };
101
102 #define CDS_MUST_MATCH_FLAGS_DO(f) \
103 f(EnableValhalla) \
104 f(UseArrayFlattening) \
105 f(UseFieldFlattening) \
106 f(InlineTypePassFieldsAsArgs) \
107 f(InlineTypeReturnedAsFields) \
108 f(UseNonAtomicValueFlattening) \
109 f(UseAtomicValueFlattening) \
110 f(UseNullableValueFlattening)
111
112
113 class CDSMustMatchFlags {
114 private:
115 size_t _max_name_width;
116 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
117 decltype(n) _v_##n;
118 CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
119 #undef DECLARE_CDS_MUST_MATCH_FLAG
120
121 inline static void do_print(outputStream* st, bool v);
122 inline static void do_print(outputStream* st, intx v);
123 inline static void do_print(outputStream* st, uintx v);
124 inline static void do_print(outputStream* st, double v);
125 void print_info() const;
126
127 public:
128 void init();
129 bool runtime_check() const;
130 void print(outputStream* st) const;
131 };
132
133 class FileMapHeader: private CDSFileMapHeaderBase {
134 friend class CDSConstants;
135 friend class VMStructs;
136
137 private:
138 // The following fields record the states of the VM during dump time.
139 // They are compared with the runtime states to see if the archive
140 // can be used.
141 size_t _core_region_alignment; // how shared archive should be aligned
142 int _obj_alignment; // value of ObjectAlignmentInBytes
143 address _narrow_oop_base; // compressed oop encoding base
144 int _narrow_oop_shift; // compressed oop encoding shift
145 bool _compact_strings; // value of CompactStrings
146 bool _compact_headers; // value of UseCompactObjectHeaders
147 uintx _max_heap_size; // java max heap size during dumping
148 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
149 bool _compressed_oops; // save the flag UseCompressedOops
150 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
151 int _narrow_klass_pointer_bits; // save number of bits in narrowKlass
152 int _narrow_klass_shift; // save shift width used to pre-compute narrowKlass IDs in archived heap objects
155 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
156
157 // The following fields are all sanity checks for whether this archive
158 // will function correctly with this JVM and the bootclasspath it's
159 // invoked with.
160 char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
161
162 size_t _class_location_config_offset;
163
164 bool _verify_local; // BytecodeVerificationLocal setting
165 bool _verify_remote; // BytecodeVerificationRemote setting
166 bool _has_platform_or_app_classes; // Archive contains app or platform classes
167 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
168 char* _mapped_base_address; // Actual base address where archive is mapped.
169
170 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
171 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
172 // some expensive operations.
173 bool _has_aot_linked_classes; // Was the CDS archive created with -XX:+AOTClassLinking
174 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
175 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview -XX:+EnableValhalla?
176 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
177 HeapRootSegments _heap_root_segments; // Heap root segments info
178 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
179 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
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 template <typename T> T from_mapped_offset(size_t offset) const {
183 return (T)(mapped_base_address() + offset);
184 }
185 void set_as_offset(char* p, size_t *offset);
186 template <typename T> void set_as_offset(T p, size_t *offset) {
187 set_as_offset((char*)p, offset);
188 }
189
190 public:
191 // Accessors -- fields declared in GenericCDSFileMapHeader
192 unsigned int magic() const { return _generic_header._magic; }
193 int crc() const { return _generic_header._crc; }
194 int version() const { return _generic_header._version; }
195 unsigned int header_size() const { return _generic_header._header_size; }
196 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
253
254 void set_requested_base(char* b) {
255 _requested_base_address = b;
256 _mapped_base_address = nullptr;
257 }
258
259 bool validate();
260 int compute_crc();
261
262 FileMapRegion* region_at(int i) {
263 assert(is_valid_region(i), "invalid region");
264 return FileMapRegion::cast(&_regions[i]);
265 }
266
267 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
268 size_t base_archive_name_size, size_t base_archive_name_offset);
269 static bool is_valid_region(int region) {
270 return (0 <= region && region < NUM_CDS_REGIONS);
271 }
272
273 bool check_must_match_flags() const {
274 return _must_match.runtime_check();
275 }
276
277 void print(outputStream* st);
278 };
279
280 class FileMapInfo : public CHeapObj<mtInternal> {
281 private:
282 friend class ManifestStream;
283 friend class VMStructs;
284 friend class ArchiveBuilder;
285 friend class CDSOffsets;
286 friend class FileMapHeader;
287
288 bool _is_static;
289 bool _file_open;
290 bool _is_mapped;
291 int _fd;
292 size_t _file_offset;
293 const char* _full_path;
294 const char* _base_archive_name;
295 FileMapHeader* _header;
296
|