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 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 size_t ptrmap_offset() const { return _ptrmap_offset; }
162 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
163
164 void set_file_offset(size_t s) { _file_offset = s; }
165 void set_read_only(bool v) { _read_only = v; }
166 void set_mapped_base(char* p) { _mapped_base = p; }
167 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
168 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
169 bool allow_exec, int crc);
170 void init_oopmap(size_t offset, size_t size_in_bits);
171 void init_ptrmap(size_t offset, size_t size_in_bits);
172 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
173
174 bool check_region_crc(char* base) const;
175 void print(outputStream* st, int region_index);
176 };
177
178 class FileMapHeader: private CDSFileMapHeaderBase {
179 friend class CDSConstants;
180 friend class VMStructs;
181
182 private:
183 // The following fields record the states of the VM during dump time.
184 // They are compared with the runtime states to see if the archive
185 // can be used.
186 size_t _core_region_alignment; // how shared archive should be aligned
187 int _obj_alignment; // value of ObjectAlignmentInBytes
188 address _narrow_oop_base; // compressed oop encoding base
189 int _narrow_oop_shift; // compressed oop encoding shift
190 bool _compact_strings; // value of CompactStrings
191 uintx _max_heap_size; // java max heap size during dumping
192 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
193 bool _compressed_oops; // save the flag UseCompressedOops
194 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
195 size_t _cloned_vtables_offset; // The address of the first cloned vtable
196 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
197 bool _has_non_jar_in_classpath; // non-jar file entry exists in classpath
208 // SharedClassPathEntry::_type. See:
209 // check_nonempty_dir_in_shared_path_table()
210 // validate_shared_path_table()
211 // validate_non_existent_class_paths()
212 size_t _shared_path_table_offset;
213
214 jshort _app_class_paths_start_index; // Index of first app classpath entry
215 jshort _app_module_paths_start_index; // Index of first module path entry
216 jshort _max_used_path_index; // max path index referenced during CDS dump
217 int _num_module_paths; // number of module path entries
218 bool _verify_local; // BytecodeVerificationLocal setting
219 bool _verify_remote; // BytecodeVerificationRemote setting
220 bool _has_platform_or_app_classes; // Archive contains app classes
221 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
222 char* _mapped_base_address; // Actual base address where archive is mapped.
223
224 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
225 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
226 // some expensive operations.
227 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
228 HeapRootSegments _heap_root_segments; // Heap root segments info
229 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
230 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
231 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
232 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
233 char* from_mapped_offset(size_t offset) const {
234 return mapped_base_address() + offset;
235 }
236 void set_as_offset(char* p, size_t *offset);
237 public:
238 // Accessors -- fields declared in GenericCDSFileMapHeader
239 unsigned int magic() const { return _generic_header._magic; }
240 int crc() const { return _generic_header._crc; }
241 int version() const { return _generic_header._version; }
242 unsigned int header_size() const { return _generic_header._header_size; }
243 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
244 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
245 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
246
247 void set_magic(unsigned int m) { _generic_header._magic = m; }
304 SharedPathTable shared_path_table() const {
305 return SharedPathTable((Array<SharedClassPathEntry*>*)
306 from_mapped_offset(_shared_path_table_offset));
307 }
308
309 bool validate();
310 int compute_crc();
311
312 FileMapRegion* region_at(int i) {
313 assert(is_valid_region(i), "invalid region");
314 return FileMapRegion::cast(&_regions[i]);
315 }
316
317 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
318 size_t base_archive_name_size, size_t base_archive_name_offset,
319 size_t common_app_classpath_size);
320 static bool is_valid_region(int region) {
321 return (0 <= region && region < NUM_CDS_REGIONS);
322 }
323
324 void print(outputStream* st);
325 };
326
327 class FileMapInfo : public CHeapObj<mtInternal> {
328 private:
329 friend class ManifestStream;
330 friend class VMStructs;
331 friend class ArchiveBuilder;
332 friend class CDSOffsets;
333 friend class FileMapHeader;
334
335 bool _is_static;
336 bool _file_open;
337 bool _is_mapped;
338 int _fd;
339 size_t _file_offset;
340 const char* _full_path;
341 const char* _base_archive_name;
342 FileMapHeader* _header;
343
|
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 ArchiveHeapInfo;
47 class BitMapView;
48 class CHeapBitMap;
49 class ClassFileStream;
50 class ClassLoaderData;
51 class ClassPathEntry;
52 class outputStream;
53
54 class SharedClassPathEntry : public MetaspaceObj {
55 enum {
159 bool mapped_from_file() const { return _mapped_from_file != 0; }
160 size_t oopmap_offset() const { assert_is_heap_region(); return _oopmap_offset; }
161 size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
162 size_t ptrmap_offset() const { return _ptrmap_offset; }
163 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
164
165 void set_file_offset(size_t s) { _file_offset = s; }
166 void set_read_only(bool v) { _read_only = v; }
167 void set_mapped_base(char* p) { _mapped_base = p; }
168 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
169 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
170 bool allow_exec, int crc);
171 void init_oopmap(size_t offset, size_t size_in_bits);
172 void init_ptrmap(size_t offset, size_t size_in_bits);
173 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
174
175 bool check_region_crc(char* base) const;
176 void print(outputStream* st, int region_index);
177 };
178
179 #define CDS_MUST_MATCH_FLAGS_DO(f) \
180 f(EnableValhalla) \
181 f(FlatArrayElementMaxOops) \
182 f(FlatArrayElementMaxSize) \
183 f(InlineFieldMaxFlatSize) \
184 f(InlineTypePassFieldsAsArgs) \
185 f(InlineTypeReturnedAsFields) \
186 f(AtomicFieldFlattening) \
187 f(NullableFieldFlattening)
188
189 class CDSMustMatchFlags {
190 private:
191 size_t _max_name_width;
192 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
193 decltype(n) _v_##n;
194 CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
195 #undef DECLARE_CDS_MUST_MATCH_FLAG
196
197 inline static void do_print(outputStream* st, bool v);
198 inline static void do_print(outputStream* st, intx v);
199 inline static void do_print(outputStream* st, uintx v);
200 inline static void do_print(outputStream* st, double v);
201 void print_info() const;
202
203 public:
204 void init();
205 bool runtime_check() const;
206 void print(outputStream* st) const;
207 };
208
209 class FileMapHeader: private CDSFileMapHeaderBase {
210 friend class CDSConstants;
211 friend class VMStructs;
212
213 private:
214 // The following fields record the states of the VM during dump time.
215 // They are compared with the runtime states to see if the archive
216 // can be used.
217 size_t _core_region_alignment; // how shared archive should be aligned
218 int _obj_alignment; // value of ObjectAlignmentInBytes
219 address _narrow_oop_base; // compressed oop encoding base
220 int _narrow_oop_shift; // compressed oop encoding shift
221 bool _compact_strings; // value of CompactStrings
222 uintx _max_heap_size; // java max heap size during dumping
223 CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
224 bool _compressed_oops; // save the flag UseCompressedOops
225 bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
226 size_t _cloned_vtables_offset; // The address of the first cloned vtable
227 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
228 bool _has_non_jar_in_classpath; // non-jar file entry exists in classpath
239 // SharedClassPathEntry::_type. See:
240 // check_nonempty_dir_in_shared_path_table()
241 // validate_shared_path_table()
242 // validate_non_existent_class_paths()
243 size_t _shared_path_table_offset;
244
245 jshort _app_class_paths_start_index; // Index of first app classpath entry
246 jshort _app_module_paths_start_index; // Index of first module path entry
247 jshort _max_used_path_index; // max path index referenced during CDS dump
248 int _num_module_paths; // number of module path entries
249 bool _verify_local; // BytecodeVerificationLocal setting
250 bool _verify_remote; // BytecodeVerificationRemote setting
251 bool _has_platform_or_app_classes; // Archive contains app classes
252 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
253 char* _mapped_base_address; // Actual base address where archive is mapped.
254
255 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
256 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
257 // some expensive operations.
258 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
259 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview -XX:+EnableValhalla?
260 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
261 HeapRootSegments _heap_root_segments; // Heap root segments info
262 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
263 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
264 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
265 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
266 char* from_mapped_offset(size_t offset) const {
267 return mapped_base_address() + offset;
268 }
269 void set_as_offset(char* p, size_t *offset);
270 public:
271 // Accessors -- fields declared in GenericCDSFileMapHeader
272 unsigned int magic() const { return _generic_header._magic; }
273 int crc() const { return _generic_header._crc; }
274 int version() const { return _generic_header._version; }
275 unsigned int header_size() const { return _generic_header._header_size; }
276 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
277 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
278 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
279
280 void set_magic(unsigned int m) { _generic_header._magic = m; }
337 SharedPathTable shared_path_table() const {
338 return SharedPathTable((Array<SharedClassPathEntry*>*)
339 from_mapped_offset(_shared_path_table_offset));
340 }
341
342 bool validate();
343 int compute_crc();
344
345 FileMapRegion* region_at(int i) {
346 assert(is_valid_region(i), "invalid region");
347 return FileMapRegion::cast(&_regions[i]);
348 }
349
350 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
351 size_t base_archive_name_size, size_t base_archive_name_offset,
352 size_t common_app_classpath_size);
353 static bool is_valid_region(int region) {
354 return (0 <= region && region < NUM_CDS_REGIONS);
355 }
356
357 bool check_must_match_flags() const {
358 return _must_match.runtime_check();
359 }
360
361 void print(outputStream* st);
362 };
363
364 class FileMapInfo : public CHeapObj<mtInternal> {
365 private:
366 friend class ManifestStream;
367 friend class VMStructs;
368 friend class ArchiveBuilder;
369 friend class CDSOffsets;
370 friend class FileMapHeader;
371
372 bool _is_static;
373 bool _file_open;
374 bool _is_mapped;
375 int _fd;
376 size_t _file_offset;
377 const char* _full_path;
378 const char* _base_archive_name;
379 FileMapHeader* _header;
380
|