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 "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 {
 54     modules_image_entry,
 55     jar_entry,
 56     dir_entry,
 57     non_existent_entry,
 58     unknown_entry
 59   };
 60 
 61   void set_name(const char* name, TRAPS);
 62 
 63   u1     _type;
 64   bool   _is_module_path;
 65   bool   _from_class_path_attr;
 66   time_t _timestamp;          // jar timestamp,  0 if is directory, modules image or other
 67   int64_t      _filesize;     // jar/jimage file size, -1 if is directory, -2 if other
 68   Array<char>* _name;
 69   Array<u1>*   _manifest;
 70 
 71 public:
 72   SharedClassPathEntry() : _type(0), _is_module_path(false),
 73                            _from_class_path_attr(false), _timestamp(0),
 74                            _filesize(0), _name(nullptr), _manifest(nullptr) {}
 75   static int size() {
 76     static_assert(is_aligned(sizeof(SharedClassPathEntry), wordSize), "must be");
 77     return (int)(sizeof(SharedClassPathEntry) / wordSize);
 78   }
 79   void init(bool is_modules_image, bool is_module_path, ClassPathEntry* cpe, TRAPS);
 80   void init_as_non_existent(const char* path, TRAPS);
 81   void metaspace_pointers_do(MetaspaceClosure* it);
 82   MetaspaceObj::Type type() const { return SharedClassPathEntryType; }
 83   bool validate(bool is_class_path = true) const;
 84 
 85   // The _timestamp only gets set for jar files.
 86   bool has_timestamp() const {
 87     return _timestamp != 0;
 88   }
 89   bool is_dir()           const { return _type == dir_entry; }
 90   bool is_modules_image() const { return _type == modules_image_entry; }
 91   bool is_jar()           const { return _type == jar_entry; }
 92   bool is_non_existent()  const { return _type == non_existent_entry; }
 93   bool from_class_path_attr() { return _from_class_path_attr; }
 94   time_t timestamp() const { return _timestamp; }
 95   const char* name() const;
 96   const char* manifest() const {
 97     return (_manifest == nullptr) ? nullptr : (const char*)_manifest->data();
 98   }
 99   int manifest_size() const {
100     return (_manifest == nullptr) ? 0 : _manifest->length();
101   }
102   void set_manifest(Array<u1>* manifest) {
103     _manifest = manifest;
104   }
105   bool check_non_existent() const;
106   void copy_from(SharedClassPathEntry* ent, ClassLoaderData* loader_data, TRAPS);
107   bool in_named_module() {
108     return is_modules_image() || // modules image doesn't contain unnamed modules
109            _is_module_path;      // module path doesn't contain unnamed modules
110   }
111 };
112 
113 class SharedPathTable {
114   Array<SharedClassPathEntry*>* _entries;
115 public:
116   SharedPathTable() : _entries(nullptr) {}
117   SharedPathTable(Array<SharedClassPathEntry*>* entries) : _entries(entries) {}
118 
119   void dumptime_init(ClassLoaderData* loader_data, TRAPS);
120   void metaspace_pointers_do(MetaspaceClosure* it);
121 
122   int size() {
123     return _entries == nullptr ? 0 : _entries->length();
124   }
125   SharedClassPathEntry* path_at(int index) {
126     return _entries->at(index);
127   }
128   Array<SharedClassPathEntry*>* table() {return _entries;}
129   void set_table(Array<SharedClassPathEntry*>* table) {_entries = table;}
130 };
131 
132 
133 class FileMapRegion: private CDSFileMapRegion {
134 public:
135   void assert_is_heap_region() const {
136     assert(_is_heap_region, "must be heap region");
137   }
138   void assert_is_not_heap_region() const {
139     assert(!_is_heap_region, "must not be heap region");
140   }
141 
142   static FileMapRegion* cast(CDSFileMapRegion* p) {
143     return (FileMapRegion*)p;
144   }
145 
146   // Accessors
147   int crc()                         const { return _crc; }
148   size_t file_offset()              const { return _file_offset; }
149   size_t mapping_offset()           const { return _mapping_offset; }
150   size_t mapping_end_offset()       const { return _mapping_offset + used_aligned(); }
151   size_t used()                     const { return _used; }
152   size_t used_aligned()             const; // aligned up to MetaspaceShared::core_region_alignment()
153   char*  mapped_base()              const { return _mapped_base; }
154   char*  mapped_end()               const { return mapped_base()        + used_aligned(); }
155   bool   read_only()                const { return _read_only != 0; }
156   bool   allow_exec()               const { return _allow_exec != 0; }
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()
197   bool _has_non_jar_in_classpath;                 // non-jar file entry exists in classpath
198   unsigned int _common_app_classpath_prefix_size; // size of the common prefix of app class paths
199                                                   //    0 if no common prefix exists
200 
201   // The following fields are all sanity checks for whether this archive
202   // will function correctly with this JVM and the bootclasspath it's
203   // invoked with.
204   char  _jvm_ident[JVM_IDENT_MAX];  // identifier string of the jvm that created this dump
205 
206   // The following is a table of all the boot/app/module path entries that were used
207   // during dumping. At run time, we validate these entries according to their
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_preloaded_classes;        // Does the CDS archive have preloaded classes?
228   bool   _has_full_module_graph;        // Does this CDS archive contain the full archived module graph?
229   bool   _has_archived_invokedynamic;   // Does the archive have preresolved invokedynamic CP entries?
230   bool   _has_archived_packages;
231   int    _gc_kind;                      // Universe::heap()->kind();
232   char   _gc_name[32];                  // Universe::heap()->name();
233   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
234   size_t _heap_roots_offset;            // Offset of the HeapShared::roots() object, from the bottom
235                                         // of the archived heap objects, in bytes.
236   size_t _heap_oopmap_start_pos;        // The first bit in the oopmap corresponds to this position in the heap.
237   size_t _heap_ptrmap_start_pos;        // The first bit in the ptrmap corresponds to this position in the heap.
238   size_t _rw_ptrmap_start_pos;          // The first bit in the ptrmap corresponds to this position in the rw region
239   size_t _ro_ptrmap_start_pos;          // The first bit in the ptrmap corresponds to this position in the ro region
240   char* from_mapped_offset(size_t offset) const {
241     return mapped_base_address() + offset;
242   }
243   void set_as_offset(char* p, size_t *offset);
244 public:
245   // Accessors -- fields declared in GenericCDSFileMapHeader
246   unsigned int magic()                            const { return _generic_header._magic;                    }
247   int crc()                                       const { return _generic_header._crc;                      }
248   int version()                                   const { return _generic_header._version;                  }
249   unsigned int header_size()                      const { return _generic_header._header_size;              }
250   unsigned int base_archive_name_offset()         const { return _generic_header._base_archive_name_offset; }
251   unsigned int base_archive_name_size()           const { return _generic_header._base_archive_name_size;   }
252   unsigned int common_app_classpath_prefix_size() const { return _common_app_classpath_prefix_size;         }
253 
254   void set_magic(unsigned int m)                            { _generic_header._magic = m;                    }
255   void set_crc(int crc_value)                               { _generic_header._crc = crc_value;              }
256   void set_version(int v)                                   { _generic_header._version = v;                  }
257   void set_header_size(unsigned int s)                      { _generic_header._header_size = s;              }
258   void set_base_archive_name_offset(unsigned int s)         { _generic_header._base_archive_name_offset = s; }
259   void set_base_archive_name_size(unsigned int s)           { _generic_header._base_archive_name_size = s;   }
260   void set_common_app_classpath_prefix_size(unsigned int s) { _common_app_classpath_prefix_size = s;         }
261 
262   bool is_static()                         const { return magic() == CDS_ARCHIVE_MAGIC; }
263   size_t core_region_alignment()           const { return _core_region_alignment; }
264   int obj_alignment()                      const { return _obj_alignment; }
265   address narrow_oop_base()                const { return _narrow_oop_base; }
266   int narrow_oop_shift()                   const { return _narrow_oop_shift; }
267   bool compact_strings()                   const { return _compact_strings; }
268   uintx max_heap_size()                    const { return _max_heap_size; }
269   CompressedOops::Mode narrow_oop_mode()   const { return _narrow_oop_mode; }
270   char* cloned_vtables()                   const { return from_mapped_offset(_cloned_vtables_offset); }
271   char* serialized_data()                  const { return from_mapped_offset(_serialized_data_offset); }
272   const char* jvm_ident()                  const { return _jvm_ident; }
273   char* requested_base_address()           const { return _requested_base_address; }
274   char* mapped_base_address()              const { return _mapped_base_address; }
275   bool has_platform_or_app_classes()       const { return _has_platform_or_app_classes; }
276   bool has_non_jar_in_classpath()          const { return _has_non_jar_in_classpath; }
277   bool has_preloaded_classes()             const { return _has_preloaded_classes; }
278   int gc_kind()                            const { return _gc_kind; }
279   const char* gc_name()                    const { return _gc_name; }
280   size_t ptrmap_size_in_bits()             const { return _ptrmap_size_in_bits; }
281   bool compressed_oops()                   const { return _compressed_oops; }
282   bool compressed_class_pointers()         const { return _compressed_class_ptrs; }
283   size_t heap_roots_offset()               const { return _heap_roots_offset; }
284   size_t heap_oopmap_start_pos()           const { return _heap_oopmap_start_pos; }
285   size_t heap_ptrmap_start_pos()           const { return _heap_ptrmap_start_pos; }
286   size_t rw_ptrmap_start_pos()             const { return _rw_ptrmap_start_pos; }
287   size_t ro_ptrmap_start_pos()             const { return _ro_ptrmap_start_pos; }
288   // FIXME: These should really return int
289   jshort max_used_path_index()             const { return _max_used_path_index; }
290   jshort app_module_paths_start_index()    const { return _app_module_paths_start_index; }
291   jshort app_class_paths_start_index()     const { return _app_class_paths_start_index; }
292   int    num_module_paths()                const { return _num_module_paths; }
293 
294   void set_has_platform_or_app_classes(bool v)   { _has_platform_or_app_classes = v; }
295   void set_cloned_vtables(char* p)               { set_as_offset(p, &_cloned_vtables_offset); }
296   void set_serialized_data(char* p)              { set_as_offset(p, &_serialized_data_offset); }
297   void set_mapped_base_address(char* p)          { _mapped_base_address = p; }
298   void set_heap_roots_offset(size_t n)           { _heap_roots_offset = n; }
299   void set_heap_oopmap_start_pos(size_t n)       { _heap_oopmap_start_pos = n; }
300   void set_heap_ptrmap_start_pos(size_t n)       { _heap_ptrmap_start_pos = n; }
301   void set_rw_ptrmap_start_pos(size_t n)         { _rw_ptrmap_start_pos = n; }
302   void set_ro_ptrmap_start_pos(size_t n)         { _ro_ptrmap_start_pos = n; }
303   void copy_base_archive_name(const char* name);
304 
305   void set_shared_path_table(SharedPathTable table) {
306     set_as_offset((char*)table.table(), &_shared_path_table_offset);
307   }
308 
309   void set_requested_base(char* b) {
310     _requested_base_address = b;
311     _mapped_base_address = 0;
312   }
313 
314   SharedPathTable shared_path_table() const {
315     return SharedPathTable((Array<SharedClassPathEntry*>*)
316                            from_mapped_offset(_shared_path_table_offset));
317   }
318 
319   bool validate();
320   int compute_crc();
321 
322   FileMapRegion* region_at(int i) {
323     assert(is_valid_region(i), "invalid region");
324     return FileMapRegion::cast(&_regions[i]);
325   }
326 
327   void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
328                 size_t base_archive_name_size, size_t base_archive_name_offset,
329                 size_t common_app_classpath_size);
330   static bool is_valid_region(int region) {
331     return (0 <= region && region < NUM_CDS_REGIONS);
332   }
333 
334   void print(outputStream* st);
335 };
336 
337 class FileMapInfo : public CHeapObj<mtInternal> {
338 private:
339   friend class ManifestStream;
340   friend class VMStructs;
341   friend class ArchiveBuilder;
342   friend class CDSOffsets;
343   friend class FileMapHeader;
344 
345   bool           _is_static;
346   bool           _file_open;
347   bool           _is_mapped;
348   int            _fd;
349   size_t         _file_offset;
350   const char*    _full_path;
351   const char*    _base_archive_name;
352   FileMapHeader* _header;
353 
354   static SharedPathTable       _shared_path_table;
355   static bool                  _validating_shared_path_table;
356 
357   // FileMapHeader describes the shared space data in the file to be
358   // mapped.  This structure gets written to a file.  It is not a class, so
359   // that the compilers don't add any compiler-private data to it.
360 
361   static FileMapInfo* _current_info;
362   static FileMapInfo* _dynamic_archive_info;
363   static bool _heap_pointers_need_patching;
364   static bool _memory_mapping_failed;
365   static GrowableArray<const char*>* _non_existent_class_paths;
366 
367 public:
368   FileMapHeader *header() const       { return _header; }
369   static bool get_base_archive_name_from_header(const char* archive_name,
370                                                 char** base_archive_name);
371   static SharedPathTable shared_path_table() {
372     return _shared_path_table;
373   }
374 
375   bool init_from_file(int fd);
376   static void metaspace_pointers_do(MetaspaceClosure* it) {
377     _shared_path_table.metaspace_pointers_do(it);
378   }
379 
380   void log_paths(const char* msg, int start_idx, int end_idx);
381 
382   FileMapInfo(const char* full_apth, bool is_static);
383   ~FileMapInfo();
384 
385   // Accessors
386   int    compute_header_crc()  const { return header()->compute_crc(); }
387   void   set_header_crc(int crc)     { header()->set_crc(crc); }
388   int    region_crc(int i)     const { return region_at(i)->crc(); }
389   void   populate_header(size_t core_region_alignment);
390   bool   validate_header();
391   void   invalidate();
392   int    crc()                 const { return header()->crc(); }
393   int    version()             const { return header()->version(); }
394   unsigned int magic()         const { return header()->magic(); }
395   address narrow_oop_base()    const { return header()->narrow_oop_base(); }
396   int     narrow_oop_shift()   const { return header()->narrow_oop_shift(); }
397   uintx   max_heap_size()      const { return header()->max_heap_size(); }
398   size_t  heap_roots_offset()  const { return header()->heap_roots_offset(); }
399   size_t  core_region_alignment() const { return header()->core_region_alignment(); }
400   size_t  heap_oopmap_start_pos() const { return header()->heap_oopmap_start_pos(); }
401   size_t  heap_ptrmap_start_pos() const { return header()->heap_ptrmap_start_pos(); }
402 
403   CompressedOops::Mode narrow_oop_mode()      const { return header()->narrow_oop_mode(); }
404   jshort app_module_paths_start_index()       const { return header()->app_module_paths_start_index(); }
405   jshort app_class_paths_start_index()        const { return header()->app_class_paths_start_index(); }
406 
407   char* cloned_vtables()                      const { return header()->cloned_vtables(); }
408   void  set_cloned_vtables(char* p)           const { header()->set_cloned_vtables(p); }
409   char* serialized_data()                     const { return header()->serialized_data(); }
410   void  set_serialized_data(char* p)          const { header()->set_serialized_data(p); }
411 
412   bool  is_file_position_aligned() const;
413   void  align_file_position();
414 
415   bool is_static()                            const { return _is_static; }
416   bool is_mapped()                            const { return _is_mapped; }
417   void set_is_mapped(bool v)                        { _is_mapped = v; }
418   const char* full_path()                     const { return _full_path; }
419 
420   void set_requested_base(char* b)                  { header()->set_requested_base(b); }
421   char* requested_base_address()           const    { return header()->requested_base_address(); }
422 
423   class DynamicArchiveHeader* dynamic_header() const {
424     assert(!is_static(), "must be");
425     return (DynamicArchiveHeader*)header();
426   }
427 
428   void set_has_platform_or_app_classes(bool v) {
429     header()->set_has_platform_or_app_classes(v);
430   }
431   bool has_platform_or_app_classes() const {
432     return header()->has_platform_or_app_classes();
433   }
434 
435   static FileMapInfo* current_info() {
436     CDS_ONLY(return _current_info;)
437     NOT_CDS(return nullptr;)
438   }
439 
440   static void set_current_info(FileMapInfo* info) {
441     CDS_ONLY(_current_info = info;)
442   }
443 
444   static FileMapInfo* dynamic_info() {
445     CDS_ONLY(return _dynamic_archive_info;)
446     NOT_CDS(return nullptr;)
447   }
448 
449   static void assert_mark(bool check);
450 
451   // File manipulation.
452   bool  initialize() NOT_CDS_RETURN_(false);
453   bool  open_for_read();
454   void  open_for_write();
455   void  write_header();
456   void  write_region(int region, char* base, size_t size,
457                      bool read_only, bool allow_exec);
458   size_t remove_bitmap_leading_zeros(CHeapBitMap* map);
459   char* write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap,
460                             CHeapBitMap* cc_ptrmap, ArchiveHeapInfo* heap_info,
461                             size_t &size_in_bytes);
462   size_t write_heap_region(ArchiveHeapInfo* heap_info);
463   void  write_bytes(const void* buffer, size_t count);
464   void  write_bytes_aligned(const void* buffer, size_t count);
465   size_t  read_bytes(void* buffer, size_t count);
466   static size_t readonly_total();
467   MapArchiveResult map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs);
468   void  unmap_regions(int regions[], int num_regions);
469   void  map_or_load_heap_region() NOT_CDS_JAVA_HEAP_RETURN;
470   void  fixup_mapped_heap_region() NOT_CDS_JAVA_HEAP_RETURN;
471   void  patch_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN;
472   bool  has_heap_region()  NOT_CDS_JAVA_HEAP_RETURN_(false);
473   MemRegion get_heap_region_requested_range() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion());
474   bool  read_region(int i, char* base, size_t size, bool do_commit);
475   char* map_bitmap_region();
476   bool map_cached_code_region(ReservedSpace rs);
477   void  unmap_region(int i);
478   void  close();
479   bool  is_open() { return _file_open; }
480   ReservedSpace reserve_shared_memory();
481 
482   // JVM/TI RedefineClasses() support:
483   // Remap the shared readonly space to shared readwrite, private.
484   bool  remap_shared_readonly_as_readwrite();
485 
486   static bool memory_mapping_failed() {
487     CDS_ONLY(return _memory_mapping_failed;)
488     NOT_CDS(return false;)
489   }
490 
491   static void allocate_shared_path_table(TRAPS);
492   static int add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS);
493   static void check_nonempty_dir_in_shared_path_table();
494   bool check_module_paths();
495   bool validate_shared_path_table();
496   void validate_non_existent_class_paths();
497   bool validate_leyden_config();
498   static void set_shared_path_table(FileMapInfo* info) {
499     _shared_path_table = info->header()->shared_path_table();
500   }
501   static void update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
502   static int num_non_existent_class_paths();
503   static void record_non_existent_class_path_entry(const char* path);
504 
505 #if INCLUDE_JVMTI
506   // Caller needs a ResourceMark because parts of the returned cfs are resource-allocated.
507   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
508 #endif
509 
510   static SharedClassPathEntry* shared_path(int index) {
511     return _shared_path_table.path_at(index);
512   }
513 
514   static const char* shared_path_name(int index) {
515     assert(index >= 0, "Sanity");
516     return shared_path(index)->name();
517   }
518 
519   static int get_number_of_shared_paths() {
520     return _shared_path_table.size();
521   }
522 
523   static int get_module_shared_path_index(Symbol* location) NOT_CDS_RETURN_(-1);
524 
525   // The offset of the first core region in the archive, relative to SharedBaseAddress
526   size_t mapping_base_offset() const { return first_core_region()->mapping_offset();    }
527   // The offset of the (exclusive) end of the last core region in this archive, relative to SharedBaseAddress
528   size_t mapping_end_offset()  const { return last_core_region()->mapping_end_offset(); }
529 
530   char* mapped_base()    const { return first_core_region()->mapped_base(); }
531   char* mapped_end()     const { return last_core_region()->mapped_end();   }
532 
533   // Non-zero if the archive needs to be mapped a non-default location due to ASLR.
534   intx relocation_delta() const {
535     return header()->mapped_base_address() - header()->requested_base_address();
536   }
537 
538   FileMapRegion* first_core_region() const;
539   FileMapRegion* last_core_region()  const;
540 
541   FileMapRegion* region_at(int i) const {
542     return header()->region_at(i);
543   }
544 
545   BitMapView bitmap_view(int region_index, bool is_oopmap);
546   BitMapView oopmap_view(int region_index);
547   BitMapView ptrmap_view(int region_index);
548 
549   void print(outputStream* st) const;
550 
551   const char* vm_version() {
552     return header()->jvm_ident();
553   }
554 
555  private:
556   void  seek_to_position(size_t pos);
557   char* skip_first_path_entry(const char* path) NOT_CDS_RETURN_(nullptr);
558   int   num_paths(const char* path) NOT_CDS_RETURN_(0);
559   bool  check_paths_existence(const char* paths) NOT_CDS_RETURN_(false);
560   GrowableArray<const char*>* create_dumptime_app_classpath_array() NOT_CDS_RETURN_(nullptr);
561   GrowableArray<const char*>* create_path_array(const char* path) NOT_CDS_RETURN_(nullptr);
562   bool  classpath_failure(const char* msg, const char* name) NOT_CDS_RETURN_(false);
563   unsigned int longest_common_app_classpath_prefix_len(int num_paths,
564                                                        GrowableArray<const char*>* rp_array)
565                                                        NOT_CDS_RETURN_(0);
566   bool  check_paths(int shared_path_start_idx, int num_paths,
567                     GrowableArray<const char*>* rp_array,
568                     unsigned int dumptime_prefix_len,
569                     unsigned int runtime_prefix_len) NOT_CDS_RETURN_(false);
570   bool  validate_boot_class_paths() NOT_CDS_RETURN_(false);
571   bool  validate_app_class_paths(int shared_app_paths_len) NOT_CDS_RETURN_(false);
572   bool  map_heap_region_impl() NOT_CDS_JAVA_HEAP_RETURN_(false);
573   void  dealloc_heap_region() NOT_CDS_JAVA_HEAP_RETURN;
574   bool  can_use_heap_region();
575   bool  load_heap_region() NOT_CDS_JAVA_HEAP_RETURN_(false);
576   bool  map_heap_region() NOT_CDS_JAVA_HEAP_RETURN_(false);
577   void  init_heap_region_relocation();
578   MapArchiveResult map_region(int i, intx addr_delta, char* mapped_base_address, ReservedSpace rs);
579   bool  relocate_pointers_in_core_regions(intx addr_delta);
580   void  relocate_pointers_in_cached_code_region();
581   static MemRegion _mapped_heap_memregion;
582 
583 public:
584   address heap_region_dumptime_address() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
585   address heap_region_requested_address() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
586   narrowOop encoded_heap_region_dumptime_address();
587 
588 private:
589 
590 #if INCLUDE_JVMTI
591   static ClassPathEntry** _classpath_entries_for_jvmti;
592   static ClassPathEntry* get_classpath_entry_for_jvmti(int i, TRAPS);
593 #endif
594 };
595 
596 #endif // SHARE_CDS_FILEMAP_HPP