1 /*
2 * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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/metaspaceShared.hpp"
29 #include "include/cds.h"
30 #include "logging/logLevel.hpp"
31 #include "memory/allocation.hpp"
32 #include "oops/array.hpp"
33 #include "oops/compressedOops.hpp"
34 #include "utilities/align.hpp"
35
36 // To understand the layout of the CDS archive file:
37 //
38 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
39 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
40 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
41
42 static const int JVM_IDENT_MAX = 256;
43
44 class ArchiveHeapInfo;
45 class BitMapView;
46 class CHeapBitMap;
47 class ClassFileStream;
48 class ClassLoaderData;
49 class ClassPathEntry;
50 class outputStream;
51
52 class SharedClassPathEntry : public MetaspaceObj {
53 enum {
157 bool mapped_from_file() const { return _mapped_from_file != 0; }
158 size_t oopmap_offset() const { assert_is_heap_region(); return _oopmap_offset; }
159 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
160
161 void set_file_offset(size_t s) { _file_offset = s; }
162 void set_read_only(bool v) { _read_only = v; }
163 void set_mapped_base(char* p) { _mapped_base = p; }
164 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
165 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
166 bool allow_exec, int crc);
167 void init_oopmap(size_t offset, size_t size_in_bits);
168 void init_ptrmap(size_t offset, size_t size_in_bits);
169 BitMapView oopmap_view();
170 BitMapView ptrmap_view();
171 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
172
173 bool check_region_crc() const;
174 void print(outputStream* st, int region_index);
175 };
176
177 class FileMapHeader: private CDSFileMapHeaderBase {
178 friend class CDSConstants;
179 friend class VMStructs;
180
181 private:
182 // The following fields record the states of the VM during dump time.
183 // They are compared with the runtime states to see if the archive
184 // can be used.
185 size_t _core_region_alignment; // how shared archive should be aligned
186 int _obj_alignment; // value of ObjectAlignmentInBytes
187 address _narrow_oop_base; // compressed oop encoding base
188 int _narrow_oop_shift; // compressed oop encoding shift
189 bool _compact_strings; // value of CompactStrings
190 uintx _max_heap_size; // java max heap size during dumping
191 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
192 bool _compressed_oops; // save the flag UseCompressedOops
193 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
194 size_t _cloned_vtables_offset; // The address of the first cloned vtable
195 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
196 bool _has_non_jar_in_classpath; // non-jar file entry exists in classpath
207 // SharedClassPathEntry::_type. See:
208 // check_nonempty_dir_in_shared_path_table()
209 // validate_shared_path_table()
210 // validate_non_existent_class_paths()
211 size_t _shared_path_table_offset;
212
213 jshort _app_class_paths_start_index; // Index of first app classpath entry
214 jshort _app_module_paths_start_index; // Index of first module path entry
215 jshort _max_used_path_index; // max path index referenced during CDS dump
216 int _num_module_paths; // number of module path entries
217 bool _verify_local; // BytecodeVerificationLocal setting
218 bool _verify_remote; // BytecodeVerificationRemote setting
219 bool _has_platform_or_app_classes; // Archive contains app classes
220 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
221 char* _mapped_base_address; // Actual base address where archive is mapped.
222
223 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
224 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
225 // some expensive operations.
226 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
227 size_t _ptrmap_size_in_bits; // Size of pointer relocation bitmap
228 size_t _heap_roots_offset; // Offset of the HeapShared::roots() object, from the bottom
229 // of the archived heap objects, in bytes.
230 char* from_mapped_offset(size_t offset) const {
231 return mapped_base_address() + offset;
232 }
233 void set_as_offset(char* p, size_t *offset);
234 public:
235 // Accessors -- fields declared in GenericCDSFileMapHeader
236 unsigned int magic() const { return _generic_header._magic; }
237 int crc() const { return _generic_header._crc; }
238 int version() const { return _generic_header._version; }
239 unsigned int header_size() const { return _generic_header._header_size; }
240 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
241 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
242 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
243
244 void set_magic(unsigned int m) { _generic_header._magic = m; }
245 void set_crc(int crc_value) { _generic_header._crc = crc_value; }
246 void set_version(int v) { _generic_header._version = v; }
247 void set_header_size(unsigned int s) { _generic_header._header_size = s; }
294 SharedPathTable shared_path_table() const {
295 return SharedPathTable((Array<SharedClassPathEntry*>*)
296 from_mapped_offset(_shared_path_table_offset));
297 }
298
299 bool validate();
300 int compute_crc();
301
302 FileMapRegion* region_at(int i) {
303 assert(is_valid_region(i), "invalid region");
304 return FileMapRegion::cast(&_regions[i]);
305 }
306
307 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
308 size_t base_archive_name_size, size_t base_archive_name_offset,
309 size_t common_app_classpath_size);
310 static bool is_valid_region(int region) {
311 return (0 <= region && region < NUM_CDS_REGIONS);
312 }
313
314 void print(outputStream* st);
315 };
316
317 class FileMapInfo : public CHeapObj<mtInternal> {
318 private:
319 friend class ManifestStream;
320 friend class VMStructs;
321 friend class ArchiveBuilder;
322 friend class CDSOffsets;
323 friend class FileMapHeader;
324
325 bool _is_static;
326 bool _file_open;
327 bool _is_mapped;
328 int _fd;
329 size_t _file_offset;
330 const char* _full_path;
331 const char* _base_archive_name;
332 FileMapHeader* _header;
333
|
1 /*
2 * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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/metaspaceShared.hpp"
29 #include "include/cds.h"
30 #include "logging/logLevel.hpp"
31 #include "memory/allocation.hpp"
32 #include "oops/array.hpp"
33 #include "oops/compressedOops.hpp"
34 #include "runtime/globals.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 ArchiveHeapInfo;
46 class BitMapView;
47 class CHeapBitMap;
48 class ClassFileStream;
49 class ClassLoaderData;
50 class ClassPathEntry;
51 class outputStream;
52
53 class SharedClassPathEntry : public MetaspaceObj {
54 enum {
158 bool mapped_from_file() const { return _mapped_from_file != 0; }
159 size_t oopmap_offset() const { assert_is_heap_region(); return _oopmap_offset; }
160 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
161
162 void set_file_offset(size_t s) { _file_offset = s; }
163 void set_read_only(bool v) { _read_only = v; }
164 void set_mapped_base(char* p) { _mapped_base = p; }
165 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
166 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
167 bool allow_exec, int crc);
168 void init_oopmap(size_t offset, size_t size_in_bits);
169 void init_ptrmap(size_t offset, size_t size_in_bits);
170 BitMapView oopmap_view();
171 BitMapView ptrmap_view();
172 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
173
174 bool check_region_crc() const;
175 void print(outputStream* st, int region_index);
176 };
177
178 #define CDS_MUST_MATCH_FLAGS_DO(f) \
179 f(EnableValhalla) \
180 f(FlatArrayElementMaxOops) \
181 f(FlatArrayElementMaxSize) \
182 f(InlineFieldMaxFlatSize) \
183 f(InlineTypePassFieldsAsArgs) \
184 f(InlineTypeReturnedAsFields)
185
186 class CDSMustMatchFlags {
187 private:
188 size_t _max_name_width;
189 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
190 decltype(n) _v_##n;
191 CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
192 #undef DECLARE_CDS_MUST_MATCH_FLAG
193
194 inline static void do_print(outputStream* st, bool v);
195 inline static void do_print(outputStream* st, intx v);
196 inline static void do_print(outputStream* st, uintx v);
197 inline static void do_print(outputStream* st, double v);
198 void print_info() const;
199
200 public:
201 void init();
202 bool runtime_check() const;
203 void print(outputStream* st) const;
204 };
205
206 class FileMapHeader: private CDSFileMapHeaderBase {
207 friend class CDSConstants;
208 friend class VMStructs;
209
210 private:
211 // The following fields record the states of the VM during dump time.
212 // They are compared with the runtime states to see if the archive
213 // can be used.
214 size_t _core_region_alignment; // how shared archive should be aligned
215 int _obj_alignment; // value of ObjectAlignmentInBytes
216 address _narrow_oop_base; // compressed oop encoding base
217 int _narrow_oop_shift; // compressed oop encoding shift
218 bool _compact_strings; // value of CompactStrings
219 uintx _max_heap_size; // java max heap size during dumping
220 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
221 bool _compressed_oops; // save the flag UseCompressedOops
222 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
223 size_t _cloned_vtables_offset; // The address of the first cloned vtable
224 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
225 bool _has_non_jar_in_classpath; // non-jar file entry exists in classpath
236 // SharedClassPathEntry::_type. See:
237 // check_nonempty_dir_in_shared_path_table()
238 // validate_shared_path_table()
239 // validate_non_existent_class_paths()
240 size_t _shared_path_table_offset;
241
242 jshort _app_class_paths_start_index; // Index of first app classpath entry
243 jshort _app_module_paths_start_index; // Index of first module path entry
244 jshort _max_used_path_index; // max path index referenced during CDS dump
245 int _num_module_paths; // number of module path entries
246 bool _verify_local; // BytecodeVerificationLocal setting
247 bool _verify_remote; // BytecodeVerificationRemote setting
248 bool _has_platform_or_app_classes; // Archive contains app classes
249 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
250 char* _mapped_base_address; // Actual base address where archive is mapped.
251
252 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
253 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
254 // some expensive operations.
255 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
256 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview -XX:+EnableValhalla?
257 size_t _ptrmap_size_in_bits; // Size of pointer relocation bitmap
258 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
259 size_t _heap_roots_offset; // Offset of the HeapShared::roots() object, from the bottom
260 // of the archived heap objects, in bytes.
261 char* from_mapped_offset(size_t offset) const {
262 return mapped_base_address() + offset;
263 }
264 void set_as_offset(char* p, size_t *offset);
265 public:
266 // Accessors -- fields declared in GenericCDSFileMapHeader
267 unsigned int magic() const { return _generic_header._magic; }
268 int crc() const { return _generic_header._crc; }
269 int version() const { return _generic_header._version; }
270 unsigned int header_size() const { return _generic_header._header_size; }
271 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
272 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
273 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
274
275 void set_magic(unsigned int m) { _generic_header._magic = m; }
276 void set_crc(int crc_value) { _generic_header._crc = crc_value; }
277 void set_version(int v) { _generic_header._version = v; }
278 void set_header_size(unsigned int s) { _generic_header._header_size = s; }
325 SharedPathTable shared_path_table() const {
326 return SharedPathTable((Array<SharedClassPathEntry*>*)
327 from_mapped_offset(_shared_path_table_offset));
328 }
329
330 bool validate();
331 int compute_crc();
332
333 FileMapRegion* region_at(int i) {
334 assert(is_valid_region(i), "invalid region");
335 return FileMapRegion::cast(&_regions[i]);
336 }
337
338 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
339 size_t base_archive_name_size, size_t base_archive_name_offset,
340 size_t common_app_classpath_size);
341 static bool is_valid_region(int region) {
342 return (0 <= region && region < NUM_CDS_REGIONS);
343 }
344
345 bool check_must_match_flags() const {
346 return _must_match.runtime_check();
347 }
348
349 void print(outputStream* st);
350 };
351
352 class FileMapInfo : public CHeapObj<mtInternal> {
353 private:
354 friend class ManifestStream;
355 friend class VMStructs;
356 friend class ArchiveBuilder;
357 friend class CDSOffsets;
358 friend class FileMapHeader;
359
360 bool _is_static;
361 bool _file_open;
362 bool _is_mapped;
363 int _fd;
364 size_t _file_offset;
365 const char* _full_path;
366 const char* _base_archive_name;
367 FileMapHeader* _header;
368
|