1 /*
   2  * Copyright (c) 2003, 2020, 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_MEMORY_FILEMAP_HPP
  26 #define SHARE_MEMORY_FILEMAP_HPP
  27 
  28 #include "classfile/classLoader.hpp"
  29 #include "include/cds.h"
  30 #include "memory/metaspaceShared.hpp"
  31 #include "memory/metaspace.hpp"
  32 #include "oops/compressedOops.hpp"
  33 #include "utilities/align.hpp"
  34 
  35 // Layout of the file:
  36 //  header: dump of archive instance plus versioning info, datestamp, etc.
  37 //   [magic # = 0xF00BABA2]
  38 //  ... padding to align on page-boundary
  39 //  read-write space
  40 //  read-only space
  41 //  misc data (block offset table, string table, symbols, dictionary, etc.)
  42 //  tag(666)
  43 
  44 static const int JVM_IDENT_MAX = 256;
  45 
  46 class CHeapBitMap;
  47 
  48 class SharedClassPathEntry {
  49   enum {
  50     modules_image_entry,
  51     jar_entry,
  52     signed_jar_entry,
  53     dir_entry,
  54     non_existent_entry,
  55     unknown_entry
  56   };
  57 
  58   void set_name(const char* name, TRAPS);
  59 
  60   u1     _type;
  61   bool   _is_module_path;
  62   bool   _from_class_path_attr;
  63   time_t _timestamp;          // jar timestamp,  0 if is directory, modules image or other
  64   long   _filesize;           // jar/jimage file size, -1 if is directory, -2 if other
  65   Array<char>* _name;
  66   Array<u1>*   _manifest;
  67 
  68 public:
  69   void init(bool is_modules_image, bool is_module_path, ClassPathEntry* cpe, TRAPS);
  70   void init_as_non_existent(const char* path, TRAPS);
  71   void metaspace_pointers_do(MetaspaceClosure* it);
  72   bool validate(bool is_class_path = true) const;
  73 
  74   // The _timestamp only gets set for jar files.
  75   bool has_timestamp() const {
  76     return _timestamp != 0;
  77   }
  78   bool is_dir()           const { return _type == dir_entry; }
  79   bool is_modules_image() const { return _type == modules_image_entry; }
  80   bool is_jar()           const { return _type == jar_entry; }
  81   bool is_signed()        const { return _type == signed_jar_entry; }
  82   void set_is_signed() {
  83     _type = signed_jar_entry;
  84   }
  85   bool from_class_path_attr() { return _from_class_path_attr; }
  86   time_t timestamp() const { return _timestamp; }
  87   long   filesize()  const { return _filesize; }
  88   const char* name() const;
  89   const char* manifest() const {
  90     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
  91   }
  92   int manifest_size() const {
  93     return (_manifest == NULL) ? 0 : _manifest->length();
  94   }
  95   void set_manifest(Array<u1>* manifest) {
  96     _manifest = manifest;
  97   }
  98   bool check_non_existent() const;
  99   void copy_from(SharedClassPathEntry* ent, ClassLoaderData* loader_data, TRAPS);
 100   bool in_named_module() {
 101     return is_modules_image() || // modules image doesn't contain unnamed modules
 102            _is_module_path;      // module path doesn't contain unnamed modules
 103   }
 104 };
 105 
 106 struct ArchiveHeapOopmapInfo {
 107   address _oopmap;               // bitmap for relocating embedded oops
 108   size_t  _offset;               // this oopmap is stored at this offset from the bottom of the BM region
 109   size_t  _oopmap_size_in_bits;
 110   size_t  _oopmap_size_in_bytes;
 111 };
 112 
 113 class SharedPathTable {
 114   Array<u8>* _table;
 115   int _size;
 116 public:
 117   SharedPathTable() : _table(NULL), _size(0) {}
 118   SharedPathTable(Array<u8>* table, int size) : _table(table), _size(size) {}
 119 
 120   void dumptime_init(ClassLoaderData* loader_data, Thread* THREAD);
 121   void metaspace_pointers_do(MetaspaceClosure* it);
 122 
 123   int size() {
 124     return _size;
 125   }
 126   SharedClassPathEntry* path_at(int index) {
 127     if (index < 0) {
 128       return NULL;
 129     }
 130     assert(index < _size, "sanity");
 131     char* p = (char*)_table->data();
 132     p += sizeof(SharedClassPathEntry) * index;
 133     return (SharedClassPathEntry*)p;
 134   }
 135   Array<u8>* table() {return _table;}
 136   void set_table(Array<u8>* table) {_table = table;}
 137 };
 138 
 139 
 140 class FileMapRegion: private CDSFileMapRegion {
 141   void assert_is_heap_region() const {
 142     assert(_is_heap_region, "must be heap region");
 143   }
 144   void assert_is_not_heap_region() const {
 145     assert(!_is_heap_region, "must not be heap region");
 146   }
 147 
 148 public:
 149   static FileMapRegion* cast(CDSFileMapRegion* p) {
 150     return (FileMapRegion*)p;
 151   }
 152 
 153   // Accessors
 154   int crc()                         const { return _crc; }
 155   size_t file_offset()              const { return _file_offset; }
 156   size_t mapping_offset()           const { return _mapping_offset; }
 157   size_t mapping_end_offset()       const { return _mapping_offset + used_aligned(); }
 158   size_t used()                     const { return _used; }
 159   size_t used_aligned()             const; // aligned up to os::vm_allocation_granularity()
 160   char*  mapped_base()              const { assert_is_not_heap_region(); return _mapped_base; }
 161   char*  mapped_end()               const { return mapped_base()        + used_aligned(); }
 162   bool   read_only()                const { return _read_only != 0; }
 163   bool   allow_exec()               const { return _allow_exec != 0; }
 164   bool   mapped_from_file()         const { return _mapped_from_file != 0; }
 165   size_t oopmap_offset()            const { assert_is_heap_region();     return _oopmap_offset; }
 166   size_t oopmap_size_in_bits()      const { assert_is_heap_region();     return _oopmap_size_in_bits; }
 167 
 168   void set_file_offset(size_t s)     { _file_offset = s; }
 169   void set_read_only(bool v)         { _read_only = v; }
 170   void set_mapped_base(char* p)      { _mapped_base = p; }
 171   void set_mapped_from_file(bool v)  { _mapped_from_file = v; }
 172   void init(int region_index, char* base, size_t size, bool read_only,
 173             bool allow_exec, int crc);
 174 
 175   void init_oopmap(size_t oopmap_offset, size_t size_in_bits) {
 176     _oopmap_offset = oopmap_offset;
 177     _oopmap_size_in_bits = size_in_bits;
 178   }
 179 };
 180 
 181 class FileMapHeader: private CDSFileMapHeaderBase {
 182   friend class CDSOffsets;
 183   friend class VMStructs;
 184 
 185   size_t _header_size;
 186 
 187   // The following fields record the states of the VM during dump time.
 188   // They are compared with the runtime states to see if the archive
 189   // can be used.
 190   size_t _alignment;                // how shared archive should be aligned
 191   int    _obj_alignment;            // value of ObjectAlignmentInBytes
 192   address _narrow_oop_base;         // compressed oop encoding base
 193   int    _narrow_oop_shift;         // compressed oop encoding shift
 194   bool   _compact_strings;          // value of CompactStrings
 195   uintx  _max_heap_size;            // java max heap size during dumping
 196   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
 197   int     _narrow_klass_shift;      // save narrow klass base and shift
 198   bool    _compressed_oops;         // save the flag UseCompressedOops
 199   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers
 200   size_t  _cloned_vtables_offset;   // The address of the first cloned vtable
 201   size_t  _serialized_data_offset;  // Data accessed using {ReadClosure,WriteClosure}::serialize()
 202   size_t  _i2i_entry_code_buffers_offset;
 203   size_t  _i2i_entry_code_buffers_size;
 204   address _heap_end;                // heap end at dump time.
 205   bool _base_archive_is_default;    // indicates if the base archive is the system default one
 206 
 207   // The following fields are all sanity checks for whether this archive
 208   // will function correctly with this JVM and the bootclasspath it's
 209   // invoked with.
 210   char  _jvm_ident[JVM_IDENT_MAX];  // identifier string of the jvm that created this dump
 211 
 212   // size of the base archive name including NULL terminator
 213   size_t _base_archive_name_size;
 214 
 215   // The following is a table of all the boot/app/module path entries that were used
 216   // during dumping. At run time, we validate these entries according to their
 217   // SharedClassPathEntry::_type. See:
 218   //      check_nonempty_dir_in_shared_path_table()
 219   //      validate_shared_path_table()
 220   //      validate_non_existent_class_paths()
 221   size_t _shared_path_table_offset;
 222   int    _shared_path_table_size;
 223 
 224   jshort _app_class_paths_start_index;  // Index of first app classpath entry
 225   jshort _app_module_paths_start_index; // Index of first module path entry
 226   jshort _num_module_paths;             // number of module path entries
 227   jshort _max_used_path_index;          // max path index referenced during CDS dump
 228   bool   _verify_local;                 // BytecodeVerificationLocal setting
 229   bool   _verify_remote;                // BytecodeVerificationRemote setting
 230   bool   _has_platform_or_app_classes;  // Archive contains app classes
 231   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
 232   char*  _mapped_base_address;          // Actual base address where archive is mapped.
 233 
 234   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
 235   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
 236                                         // some expensive operations.
 237   bool   _use_full_module_graph;        // Can we use the full archived module graph?
 238   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
 239 
 240   char* from_mapped_offset(size_t offset) const {
 241     return mapped_base_address() + offset;
 242   }
 243   void set_mapped_offset(char* p, size_t *offset) {
 244     assert(p >= mapped_base_address(), "sanity");
 245     *offset = p - mapped_base_address();
 246   }
 247 public:
 248   // Accessors -- fields declared in CDSFileMapHeaderBase
 249   unsigned int magic() const {return _magic;}
 250   int crc()                               const { return _crc; }
 251   int version()                           const { return _version; }
 252 
 253   void set_crc(int crc_value)                   { _crc = crc_value; }
 254   void set_version(int v)                       { _version = v; }
 255 
 256   // Accessors -- fields declared in FileMapHeader
 257 
 258   size_t header_size()                     const { return _header_size; }
 259   size_t alignment()                       const { return _alignment; }
 260   int obj_alignment()                      const { return _obj_alignment; }
 261   address narrow_oop_base()                const { return _narrow_oop_base; }
 262   int narrow_oop_shift()                   const { return _narrow_oop_shift; }
 263   bool compact_strings()                   const { return _compact_strings; }
 264   uintx max_heap_size()                    const { return _max_heap_size; }
 265   CompressedOops::Mode narrow_oop_mode()   const { return _narrow_oop_mode; }
 266   int narrow_klass_shift()                 const { return _narrow_klass_shift; }
 267   address narrow_klass_base()              const { return (address)mapped_base_address(); }
 268   char* cloned_vtables()                   const { return from_mapped_offset(_cloned_vtables_offset); }
 269   char* serialized_data()                  const { return from_mapped_offset(_serialized_data_offset); }
 270   address i2i_entry_code_buffers()         const { return (address)from_mapped_offset(_i2i_entry_code_buffers_offset); }
 271   size_t i2i_entry_code_buffers_size()     const { return _i2i_entry_code_buffers_size; }
 272   address heap_end()                       const { return _heap_end; }
 273   bool base_archive_is_default()           const { return _base_archive_is_default; }
 274   const char* jvm_ident()                  const { return _jvm_ident; }
 275   size_t base_archive_name_size()          const { return _base_archive_name_size; }
 276   char* requested_base_address()           const { return _requested_base_address; }
 277   char* mapped_base_address()              const { return _mapped_base_address; }
 278   bool has_platform_or_app_classes()       const { return _has_platform_or_app_classes; }
 279   size_t ptrmap_size_in_bits()             const { return _ptrmap_size_in_bits; }
 280   bool compressed_oops()                   const { return _compressed_oops; }
 281   bool compressed_class_pointers()         const { return _compressed_class_ptrs; }
 282   // FIXME: These should really return int
 283   jshort max_used_path_index()             const { return _max_used_path_index; }
 284   jshort app_module_paths_start_index()    const { return _app_module_paths_start_index; }
 285   jshort app_class_paths_start_index()     const { return _app_class_paths_start_index; }
 286   jshort num_module_paths()                const { return _num_module_paths; }
 287 
 288   void set_has_platform_or_app_classes(bool v)   { _has_platform_or_app_classes = v; }
 289   void set_cloned_vtables(char* p)               { set_mapped_offset(p, &_cloned_vtables_offset); }
 290   void set_serialized_data(char* p)              { set_mapped_offset(p, &_serialized_data_offset); }
 291   void set_base_archive_name_size(size_t s)      { _base_archive_name_size = s; }
 292   void set_base_archive_is_default(bool b)       { _base_archive_is_default = b; }
 293   void set_header_size(size_t s)                 { _header_size = s; }
 294   void set_ptrmap_size_in_bits(size_t s)         { _ptrmap_size_in_bits = s; }
 295   void set_mapped_base_address(char* p)          { _mapped_base_address = p; }
 296   void set_i2i_entry_code_buffers(address p, size_t s) {
 297     set_mapped_offset((char*)p, &_i2i_entry_code_buffers_offset);
 298     _i2i_entry_code_buffers_size = s;
 299   }
 300 
 301   void set_shared_path_table(SharedPathTable table) {
 302     set_mapped_offset((char*)table.table(), &_shared_path_table_offset);
 303     _shared_path_table_size = table.size();
 304   }
 305 
 306   void set_final_requested_base(char* b) {
 307     _requested_base_address = b;
 308     _mapped_base_address = 0;
 309   }
 310 
 311   SharedPathTable shared_path_table() const {
 312     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
 313                            _shared_path_table_size);
 314   }
 315 
 316   bool validate();
 317   int compute_crc();
 318 
 319   FileMapRegion* space_at(int i) {
 320     assert(is_valid_region(i), "invalid region");
 321     return FileMapRegion::cast(&_space[i]);
 322   }
 323 
 324   void populate(FileMapInfo* info, size_t alignment);
 325 
 326   static bool is_valid_region(int region) {
 327     return (0 <= region && region < NUM_CDS_REGIONS);
 328   }
 329 };
 330 
 331 class FileMapInfo : public CHeapObj<mtInternal> {
 332 private:
 333   friend class ManifestStream;
 334   friend class VMStructs;
 335   friend class CDSOffsets;
 336   friend class FileMapHeader;
 337 
 338   bool           _is_static;
 339   bool           _file_open;
 340   bool           _is_mapped;
 341   int            _fd;
 342   size_t         _file_offset;
 343   const char*    _full_path;
 344   const char*    _base_archive_name;
 345   FileMapHeader* _header;
 346 
 347   // TODO: Probably change the following to be non-static
 348   static SharedPathTable       _shared_path_table;
 349   static SharedPathTable       _saved_shared_path_table;
 350   static bool                  _validating_shared_path_table;
 351 
 352   // FileMapHeader describes the shared space data in the file to be
 353   // mapped.  This structure gets written to a file.  It is not a class, so
 354   // that the compilers don't add any compiler-private data to it.
 355 
 356   static FileMapInfo* _current_info;
 357   static FileMapInfo* _dynamic_archive_info;
 358   static bool _heap_pointers_need_patching;
 359   static bool _memory_mapping_failed;
 360   static GrowableArray<const char*>* _non_existent_class_paths;
 361 
 362   FileMapHeader *header() const       { return _header; }
 363 
 364 public:
 365   static bool get_base_archive_name_from_header(const char* archive_name,
 366                                                 int* size, char** base_archive_name);
 367   static bool check_archive(const char* archive_name, bool is_static);
 368   static SharedPathTable shared_path_table() {
 369     return _shared_path_table;
 370   }
 371   static SharedPathTable saved_shared_path_table() {
 372     return _saved_shared_path_table;
 373   }
 374 
 375   bool init_from_file(int fd);
 376   static void metaspace_pointers_do(MetaspaceClosure* it, bool use_copy = true);
 377 
 378   void log_paths(const char* msg, int start_idx, int end_idx);
 379 
 380   FileMapInfo(bool is_static);
 381   ~FileMapInfo();
 382 
 383   // Accessors
 384   int    compute_header_crc()  const { return header()->compute_crc(); }
 385   void   set_header_crc(int crc)     { header()->set_crc(crc); }
 386   int    space_crc(int i)      const { return space_at(i)->crc(); }
 387   void   populate_header(size_t alignment);
 388   bool   validate_header();
 389   void   invalidate();
 390   int    crc()                 const { return header()->crc(); }
 391   int    version()             const { return header()->version(); }
 392   size_t alignment()           const { return header()->alignment(); }
 393   address narrow_oop_base()    const { return header()->narrow_oop_base(); }
 394   int     narrow_oop_shift()   const { return header()->narrow_oop_shift(); }
 395   uintx   max_heap_size()      const { return header()->max_heap_size(); }
 396   address narrow_klass_base()  const { return header()->narrow_klass_base(); }
 397   int     narrow_klass_shift() const { return header()->narrow_klass_shift(); }
 398 
 399   CompressedOops::Mode narrow_oop_mode()      const { return header()->narrow_oop_mode(); }
 400   jshort app_module_paths_start_index()       const { return header()->app_module_paths_start_index(); }
 401   jshort app_class_paths_start_index()        const { return header()->app_class_paths_start_index(); }
 402 
 403   char* cloned_vtables()                      const { return header()->cloned_vtables(); }
 404   void  set_cloned_vtables(char* p)           const { header()->set_cloned_vtables(p); }
 405   char* serialized_data()                     const { return header()->serialized_data(); }
 406   void  set_serialized_data(char* p)          const { header()->set_serialized_data(p); }
 407 
 408   bool  is_file_position_aligned() const;
 409   void  align_file_position();
 410 
 411   address i2i_entry_code_buffers()            const { return header()->i2i_entry_code_buffers();  }
 412   size_t i2i_entry_code_buffers_size()        const { return header()->i2i_entry_code_buffers_size(); }
 413   void set_i2i_entry_code_buffers(address addr, size_t s) const {
 414     header()->set_i2i_entry_code_buffers(addr, s);
 415   }
 416 
 417   bool is_static()                            const { return _is_static; }
 418   bool is_mapped()                            const { return _is_mapped; }
 419   void set_is_mapped(bool v)                        { _is_mapped = v; }
 420   const char* full_path()                     const { return _full_path; }
 421   void set_final_requested_base(char* b);
 422 
 423   char* requested_base_address()           const { return header()->requested_base_address(); }
 424 
 425 
 426   class DynamicArchiveHeader* dynamic_header() const {
 427     assert(!is_static(), "must be");
 428     return (DynamicArchiveHeader*)header();
 429   }
 430 
 431   void set_has_platform_or_app_classes(bool v) {
 432     header()->set_has_platform_or_app_classes(v);
 433   }
 434   bool has_platform_or_app_classes() const {
 435     return header()->has_platform_or_app_classes();
 436   }
 437 
 438   static FileMapInfo* current_info() {
 439     CDS_ONLY(return _current_info;)
 440     NOT_CDS(return NULL;)
 441   }
 442 
 443   static void set_current_info(FileMapInfo* info) {
 444     CDS_ONLY(_current_info = info;)
 445   }
 446 
 447   static FileMapInfo* dynamic_info() {
 448     CDS_ONLY(return _dynamic_archive_info;)
 449     NOT_CDS(return NULL;)
 450   }
 451 
 452   static void assert_mark(bool check);
 453 
 454   // File manipulation.
 455   bool  initialize() NOT_CDS_RETURN_(false);
 456   bool  open_for_read();
 457   void  open_for_write(const char* path = NULL);
 458   void  write_header();
 459   void  write_region(int region, char* base, size_t size,
 460                      bool read_only, bool allow_exec);
 461   void  write_bitmap_region(const CHeapBitMap* ptrmap,
 462                             GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
 463                             GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps);
 464   size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
 465                                     GrowableArray<ArchiveHeapOopmapInfo> *oopmaps,
 466                                     int first_region_id, int max_num_regions);
 467   void  write_bytes(const void* buffer, size_t count);
 468   void  write_bytes_aligned(const void* buffer, size_t count);
 469   size_t  read_bytes(void* buffer, size_t count);
 470   MapArchiveResult map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs);
 471   void  unmap_regions(int regions[], int num_regions);
 472   void  map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 473   void  fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 474   void  patch_archived_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN;
 475   void  patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges,
 476                                               int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN;
 477   bool  has_heap_regions()  NOT_CDS_JAVA_HEAP_RETURN_(false);
 478   MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion());
 479   void  unmap_region(int i);
 480   bool  verify_region_checksum(int i);
 481   void  close();
 482   bool  is_open() { return _file_open; }
 483   ReservedSpace reserve_shared_memory();
 484 
 485   // JVM/TI RedefineClasses() support:
 486   // Remap the shared readonly space to shared readwrite, private.
 487   bool  remap_shared_readonly_as_readwrite();
 488 
 489   // Errors.
 490   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 491   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 492   static bool memory_mapping_failed() {
 493     CDS_ONLY(return _memory_mapping_failed;)
 494     NOT_CDS(return false;)
 495   }
 496   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 497 
 498   // Stop CDS sharing and unmap CDS regions.
 499   static void stop_sharing_and_unmap(const char* msg);
 500 
 501   static void allocate_shared_path_table();
 502   static void copy_shared_path_table(ClassLoaderData* loader_data, Thread* THREAD);
 503   static int add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS);
 504   static void check_nonempty_dir_in_shared_path_table();
 505   bool validate_shared_path_table();
 506   void validate_non_existent_class_paths();
 507   static void set_shared_path_table(FileMapInfo* info) {
 508     _shared_path_table = info->header()->shared_path_table();
 509   }
 510   static void update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
 511   static int num_non_existent_class_paths();
 512   static void record_non_existent_class_path_entry(const char* path);
 513 
 514 #if INCLUDE_JVMTI
 515   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
 516 #endif
 517 
 518   static SharedClassPathEntry* shared_path(int index) {
 519     return _shared_path_table.path_at(index);
 520   }
 521 
 522   static const char* shared_path_name(int index) {
 523     assert(index >= 0, "Sanity");
 524     return shared_path(index)->name();
 525   }
 526 
 527   static int get_number_of_shared_paths() {
 528     return _shared_path_table.size();
 529   }
 530 
 531   static int get_module_shared_path_index(Symbol* location) NOT_CDS_RETURN_(-1);
 532 
 533   char* region_addr(int idx);
 534 
 535   // The offset of the first core region in the archive, relative to SharedBaseAddress
 536   size_t mapping_base_offset() const { return first_core_space()->mapping_offset(); }
 537   // The offset of the (exclusive) end of the last core region in this archive, relative to SharedBaseAddress
 538   size_t mapping_end_offset()  const { return last_core_space()->mapping_end_offset(); }
 539 
 540   char* mapped_base()    const { return first_core_space()->mapped_base(); }
 541   char* mapped_end()     const { return last_core_space()->mapped_end();   }
 542 
 543   // Non-zero if the archive needs to be mapped a non-default location due to ASLR.
 544   intx relocation_delta() const {
 545     return header()->mapped_base_address() - header()->requested_base_address();
 546   }
 547 
 548   FileMapRegion* first_core_space() const;
 549   FileMapRegion* last_core_space() const;
 550 
 551   FileMapRegion* space_at(int i) const {
 552     return header()->space_at(i);
 553   }
 554 
 555  private:
 556   void  seek_to_position(size_t pos);
 557   char* skip_first_path_entry(const char* path) NOT_CDS_RETURN_(NULL);
 558   int   num_paths(const char* path) NOT_CDS_RETURN_(0);
 559   GrowableArray<const char*>* create_path_array(const char* path) NOT_CDS_RETURN_(NULL);
 560   bool  classpath_failure(const char* msg, const char* name) NOT_CDS_RETURN_(false);
 561   bool  check_paths(int shared_path_start_idx, int num_paths,
 562                     GrowableArray<const char*>* rp_array) NOT_CDS_RETURN_(false);
 563   bool  validate_boot_class_paths() NOT_CDS_RETURN_(false);
 564   bool  validate_app_class_paths(int shared_app_paths_len) NOT_CDS_RETURN_(false);
 565   bool  map_heap_data(MemRegion **heap_mem, int first, int max, int* num,
 566                       bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false);
 567   bool  region_crc_check(char* buf, size_t size, int expected_crc) NOT_CDS_RETURN_(false);
 568   void  dealloc_archive_heap_regions(MemRegion* regions, int num) NOT_CDS_JAVA_HEAP_RETURN;
 569   void  map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN;
 570   char* map_bitmap_region();
 571   MapArchiveResult map_region(int i, intx addr_delta, char* mapped_base_address, ReservedSpace rs);
 572   bool  read_region(int i, char* base, size_t size);
 573   bool  relocate_pointers(intx addr_delta);
 574   static size_t set_oopmaps_offset(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_size);
 575   static size_t write_oopmaps(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_offset, uintptr_t* buffer);
 576 
 577   // The starting address of spc, as calculated with CompressedOop::decode_non_null()
 578   address start_address_as_decoded_with_current_oop_encoding_mode(FileMapRegion* spc) {
 579     return decode_start_address(spc, true);
 580   }
 581 
 582   // The starting address of spc, as calculated with HeapShared::decode_from_archive()
 583   address start_address_as_decoded_from_archive(FileMapRegion* spc) {
 584     return decode_start_address(spc, false);
 585   }
 586 
 587   address decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode);
 588 
 589 #if INCLUDE_JVMTI
 590   static ClassPathEntry** _classpath_entries_for_jvmti;
 591   static ClassPathEntry* get_classpath_entry_for_jvmti(int i, TRAPS);
 592 #endif
 593 };
 594 
 595 #endif // SHARE_MEMORY_FILEMAP_HPP