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 size_t ptrmap_offset() const { return _ptrmap_offset; }
161 size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
162
163 void set_file_offset(size_t s) { _file_offset = s; }
164 void set_read_only(bool v) { _read_only = v; }
165 void set_mapped_base(char* p) { _mapped_base = p; }
166 void set_mapped_from_file(bool v) { _mapped_from_file = v; }
167 void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
168 bool allow_exec, int crc);
169 void init_oopmap(size_t offset, size_t size_in_bits);
170 void init_ptrmap(size_t offset, size_t size_in_bits);
171 bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
172
173 bool check_region_crc(char* base) 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 bool _use_secondary_supers_table; // save the flag UseSecondarySupersTable
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()
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 size_t _heap_roots_offset; // Offset of the HeapShared::roots() object, from the bottom
229 // of the archived heap objects, in bytes.
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
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
|
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 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 #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 bool _use_secondary_supers_table; // save the flag UseSecondarySupersTable
224 size_t _cloned_vtables_offset; // The address of the first cloned vtable
225 size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
237 // SharedClassPathEntry::_type. See:
238 // check_nonempty_dir_in_shared_path_table()
239 // validate_shared_path_table()
240 // validate_non_existent_class_paths()
241 size_t _shared_path_table_offset;
242
243 jshort _app_class_paths_start_index; // Index of first app classpath entry
244 jshort _app_module_paths_start_index; // Index of first module path entry
245 jshort _max_used_path_index; // max path index referenced during CDS dump
246 int _num_module_paths; // number of module path entries
247 bool _verify_local; // BytecodeVerificationLocal setting
248 bool _verify_remote; // BytecodeVerificationRemote setting
249 bool _has_platform_or_app_classes; // Archive contains app classes
250 char* _requested_base_address; // Archive relocation is not necessary if we map with this base address.
251 char* _mapped_base_address; // Actual base address where archive is mapped.
252
253 bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
254 bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
255 // some expensive operations.
256 bool _has_full_module_graph; // Does this CDS archive contain the full archived module graph?
257 bool _has_valhalla_patched_classes; // Is this archived dumped with --enable-preview -XX:+EnableValhalla?
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 size_t _heap_oopmap_start_pos; // The first bit in the oopmap corresponds to this position in the heap.
262 size_t _heap_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the heap.
263 size_t _rw_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the rw region
264 size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region
265 char* from_mapped_offset(size_t offset) const {
266 return mapped_base_address() + offset;
267 }
268 void set_as_offset(char* p, size_t *offset);
269 public:
270 // Accessors -- fields declared in GenericCDSFileMapHeader
271 unsigned int magic() const { return _generic_header._magic; }
272 int crc() const { return _generic_header._crc; }
273 int version() const { return _generic_header._version; }
274 unsigned int header_size() const { return _generic_header._header_size; }
275 unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
276 unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }
277 unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size; }
278
335 SharedPathTable shared_path_table() const {
336 return SharedPathTable((Array<SharedClassPathEntry*>*)
337 from_mapped_offset(_shared_path_table_offset));
338 }
339
340 bool validate();
341 int compute_crc();
342
343 FileMapRegion* region_at(int i) {
344 assert(is_valid_region(i), "invalid region");
345 return FileMapRegion::cast(&_regions[i]);
346 }
347
348 void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
349 size_t base_archive_name_size, size_t base_archive_name_offset,
350 size_t common_app_classpath_size);
351 static bool is_valid_region(int region) {
352 return (0 <= region && region < NUM_CDS_REGIONS);
353 }
354
355 bool check_must_match_flags() const {
356 return _must_match.runtime_check();
357 }
358
359 void print(outputStream* st);
360 };
361
362 class FileMapInfo : public CHeapObj<mtInternal> {
363 private:
364 friend class ManifestStream;
365 friend class VMStructs;
366 friend class ArchiveBuilder;
367 friend class CDSOffsets;
368 friend class FileMapHeader;
369
370 bool _is_static;
371 bool _file_open;
372 bool _is_mapped;
373 int _fd;
374 size_t _file_offset;
375 const char* _full_path;
376 const char* _base_archive_name;
377 FileMapHeader* _header;
378
|