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