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 bool _use_secondary_supers_table; // save the flag UseSecondarySupersTable
196 size_t _cloned_vtables_offset; // The address of the first cloned vtable
197 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
209 // SharedClassPathEntry::_type. See:
210 // check_nonempty_dir_in_shared_path_table()
211 // validate_shared_path_table()
212 // validate_non_existent_class_paths()
213 size_t _shared_path_table_offset;
214
215 jshort _app_class_paths_start_index; // Index of first app classpath entry
216 jshort _app_module_paths_start_index; // Index of first module path entry
217 jshort _max_used_path_index; // max path index referenced during CDS dump
218 int _num_module_paths; // number of module path entries
219 bool _verify_local; // BytecodeVerificationLocal setting
220 bool _verify_remote; // BytecodeVerificationRemote setting
221 bool _has_platform_or_app_classes; // Archive contains app classes
222 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
223 char* _mapped_base_address; // Actual base address where archive is mapped.
224
225 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
226 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
227 // some expensive operations.
228 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
229 HeapRootSegments _heap_root_segments; // Heap root segments info
230 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
231 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
232 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
233 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
234 char* from_mapped_offset(size_t offset) const {
235 return mapped_base_address() + offset;
236 }
237 void set_as_offset(char* p, size_t *offset);
238 public:
239 // Accessors -- fields declared in GenericCDSFileMapHeader
240 unsigned int magic() const { return _generic_header._magic; }
241 int crc() const { return _generic_header._crc; }
242 int version() const { return _generic_header._version; }
243 unsigned int header_size() const { return _generic_header._header_size; }
244 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
245 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
246 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
247
248 void set_magic(unsigned int m) { _generic_header._magic = m; }
305 SharedPathTable shared_path_table() const {
306 return SharedPathTable((Array<SharedClassPathEntry*>*)
307 from_mapped_offset(_shared_path_table_offset));
308 }
309
310 bool validate();
311 int compute_crc();
312
313 FileMapRegion* region_at(int i) {
314 assert(is_valid_region(i), "invalid region");
315 return FileMapRegion::cast(&_regions[i]);
316 }
317
318 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
319 size_t base_archive_name_size, size_t base_archive_name_offset,
320 size_t common_app_classpath_size);
321 static bool is_valid_region(int region) {
322 return (0 <= region && region < NUM_CDS_REGIONS);
323 }
324
325 void print(outputStream* st);
326 };
327
328 class FileMapInfo : public CHeapObj<mtInternal> {
329 private:
330 friend class ManifestStream;
331 friend class VMStructs;
332 friend class ArchiveBuilder;
333 friend class CDSOffsets;
334 friend class FileMapHeader;
335
336 bool _is_static;
337 bool _file_open;
338 bool _is_mapped;
339 int _fd;
340 size_t _file_offset;
341 const char* _full_path;
342 const char* _base_archive_name;
343 FileMapHeader* _header;
344
|
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 bool _use_secondary_supers_table; // save the flag UseSecondarySupersTable
227 size_t _cloned_vtables_offset; // The address of the first cloned vtable
228 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
240 // SharedClassPathEntry::_type. See:
241 // check_nonempty_dir_in_shared_path_table()
242 // validate_shared_path_table()
243 // validate_non_existent_class_paths()
244 size_t _shared_path_table_offset;
245
246 jshort _app_class_paths_start_index; // Index of first app classpath entry
247 jshort _app_module_paths_start_index; // Index of first module path entry
248 jshort _max_used_path_index; // max path index referenced during CDS dump
249 int _num_module_paths; // number of module path entries
250 bool _verify_local; // BytecodeVerificationLocal setting
251 bool _verify_remote; // BytecodeVerificationRemote setting
252 bool _has_platform_or_app_classes; // Archive contains app classes
253 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
254 char* _mapped_base_address; // Actual base address where archive is mapped.
255
256 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
257 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
258 // some expensive operations.
259 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
260 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview -XX:+EnableValhalla?
261 CDSMustMatchFlags _must_match; // These flags must be the same between dumptime and runtime
262 HeapRootSegments _heap_root_segments; // Heap root segments info
263 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
264 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
265 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
266 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
267 char* from_mapped_offset(size_t offset) const {
268 return mapped_base_address() + offset;
269 }
270 void set_as_offset(char* p, size_t *offset);
271 public:
272 // Accessors -- fields declared in GenericCDSFileMapHeader
273 unsigned int magic() const { return _generic_header._magic; }
274 int crc() const { return _generic_header._crc; }
275 int version() const { return _generic_header._version; }
276 unsigned int header_size() const { return _generic_header._header_size; }
277 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
278 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
279 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
280
281 void set_magic(unsigned int m) { _generic_header._magic = m; }
338 SharedPathTable shared_path_table() const {
339 return SharedPathTable((Array<SharedClassPathEntry*>*)
340 from_mapped_offset(_shared_path_table_offset));
341 }
342
343 bool validate();
344 int compute_crc();
345
346 FileMapRegion* region_at(int i) {
347 assert(is_valid_region(i), "invalid region");
348 return FileMapRegion::cast(&_regions[i]);
349 }
350
351 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
352 size_t base_archive_name_size, size_t base_archive_name_offset,
353 size_t common_app_classpath_size);
354 static bool is_valid_region(int region) {
355 return (0 <= region && region < NUM_CDS_REGIONS);
356 }
357
358 bool check_must_match_flags() const {
359 return _must_match.runtime_check();
360 }
361
362 void print(outputStream* st);
363 };
364
365 class FileMapInfo : public CHeapObj<mtInternal> {
366 private:
367 friend class ManifestStream;
368 friend class VMStructs;
369 friend class ArchiveBuilder;
370 friend class CDSOffsets;
371 friend class FileMapHeader;
372
373 bool _is_static;
374 bool _file_open;
375 bool _is_mapped;
376 int _fd;
377 size_t _file_offset;
378 const char* _full_path;
379 const char* _base_archive_name;
380 FileMapHeader* _header;
381
|