1 /*
  2  * Copyright (c) 2003, 2021, 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 "oops/array.hpp"
 31 #include "oops/compressedOops.hpp"

 32 #include "utilities/align.hpp"
 33 
 34 // To understand the layout of the CDS archive file:
 35 //
 36 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
 37 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
 38 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
 39 
 40 static const int JVM_IDENT_MAX = 256;
 41 
 42 class CHeapBitMap;
 43 class ClassFileStream;
 44 class ClassLoaderData;
 45 class ClassPathEntry;
 46 class outputStream;
 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   int64_t      _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   const char* name() const;
 88   const char* manifest() const {
 89     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
 90   }
 91   int manifest_size() const {
 92     return (_manifest == NULL) ? 0 : _manifest->length();
 93   }
 94   void set_manifest(Array<u1>* manifest) {
 95     _manifest = manifest;
 96   }
 97   bool check_non_existent() const;
 98   void copy_from(SharedClassPathEntry* ent, ClassLoaderData* loader_data, TRAPS);
 99   bool in_named_module() {
100     return is_modules_image() || // modules image doesn't contain unnamed modules
101            _is_module_path;      // module path doesn't contain unnamed modules
102   }
103 };
104 
105 struct ArchiveHeapOopmapInfo {
106   address _oopmap;               // bitmap for relocating embedded oops
107   size_t  _offset;               // this oopmap is stored at this offset from the bottom of the BM region
108   size_t  _oopmap_size_in_bits;
109   size_t  _oopmap_size_in_bytes;
110 };
111 
112 class SharedPathTable {
113   Array<u8>* _table;
114   int _size;
115 public:
116   SharedPathTable() : _table(NULL), _size(0) {}
117   SharedPathTable(Array<u8>* table, int size) : _table(table), _size(size) {}
118 
119   void dumptime_init(ClassLoaderData* loader_data, TRAPS);
120   void metaspace_pointers_do(MetaspaceClosure* it);
121 
122   int size() {
123     return _size;
124   }
125   SharedClassPathEntry* path_at(int index) {
126     if (index < 0) {
127       return NULL;
128     }
129     assert(index < _size, "sanity");
130     char* p = (char*)_table->data();
131     p += sizeof(SharedClassPathEntry) * index;
132     return (SharedClassPathEntry*)p;
133   }
134   Array<u8>* table() {return _table;}
135   void set_table(Array<u8>* table) {_table = table;}
136 };
137 
138 
139 class FileMapRegion: private CDSFileMapRegion {
140 public:
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   static FileMapRegion* cast(CDSFileMapRegion* p) {
149     return (FileMapRegion*)p;
150   }
151 
152   // Accessors
153   int crc()                         const { return _crc; }
154   size_t file_offset()              const { return _file_offset; }
155   size_t mapping_offset()           const { return _mapping_offset; }
156   size_t mapping_end_offset()       const { return _mapping_offset + used_aligned(); }
157   size_t used()                     const { return _used; }
158   size_t used_aligned()             const; // aligned up to MetaspaceShared::core_region_alignment()
159   char*  mapped_base()              const { assert_is_not_heap_region(); return _mapped_base; }
160   char*  mapped_end()               const { return mapped_base()        + used_aligned(); }
161   bool   read_only()                const { return _read_only != 0; }
162   bool   allow_exec()               const { return _allow_exec != 0; }
163   bool   mapped_from_file()         const { return _mapped_from_file != 0; }
164   size_t oopmap_offset()            const { assert_is_heap_region();     return _oopmap_offset; }
165   size_t oopmap_size_in_bits()      const { assert_is_heap_region();     return _oopmap_size_in_bits; }
166 
167   void set_file_offset(size_t s)     { _file_offset = s; }
168   void set_read_only(bool v)         { _read_only = v; }
169   void set_mapped_base(char* p)      { _mapped_base = p; }
170   void set_mapped_from_file(bool v)  { _mapped_from_file = v; }
171   void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
172             bool allow_exec, int crc);
173 
174   void init_oopmap(size_t oopmap_offset, size_t size_in_bits) {
175     _oopmap_offset = oopmap_offset;
176     _oopmap_size_in_bits = size_in_bits;
177   }
178 
179   void print(outputStream* st, int region_index);
180 };
181 




























182 class FileMapHeader: private CDSFileMapHeaderBase {
183   friend class CDSConstants;
184   friend class VMStructs;
185 
186 private:
187   size_t _header_size;
188 
189   // The following fields record the states of the VM during dump time.
190   // They are compared with the runtime states to see if the archive
191   // can be used.
192   size_t _core_region_alignment;    // how shared archive should be aligned
193   int    _obj_alignment;            // value of ObjectAlignmentInBytes
194   address _narrow_oop_base;         // compressed oop encoding base
195   int    _narrow_oop_shift;         // compressed oop encoding shift
196   bool   _compact_strings;          // value of CompactStrings
197   uintx  _max_heap_size;            // java max heap size during dumping
198   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
199   int     _narrow_klass_shift;      // save narrow klass base and shift
200   bool    _compressed_oops;         // save the flag UseCompressedOops
201   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers
202   size_t  _cloned_vtables_offset;   // The address of the first cloned vtable
203   size_t  _serialized_data_offset;  // Data accessed using {ReadClosure,WriteClosure}::serialize()
204   address _heap_begin;              // heap begin at dump time.
205   address _heap_end;                // heap end at dump time.
206   bool _base_archive_is_default;    // indicates if the base archive is the system default one
207   bool _has_non_jar_in_classpath;   // non-jar file entry exists in classpath
208 
209   // The following fields are all sanity checks for whether this archive
210   // will function correctly with this JVM and the bootclasspath it's
211   // invoked with.
212   char  _jvm_ident[JVM_IDENT_MAX];  // identifier string of the jvm that created this dump
213   // size of the base archive name including NULL terminator
214   size_t _base_archive_name_size;
215 
216   // The following is a table of all the boot/app/module path entries that were used
217   // during dumping. At run time, we validate these entries according to their
218   // SharedClassPathEntry::_type. See:
219   //      check_nonempty_dir_in_shared_path_table()
220   //      validate_shared_path_table()
221   //      validate_non_existent_class_paths()
222   size_t _shared_path_table_offset;
223   int    _shared_path_table_size;
224 
225   jshort _app_class_paths_start_index;  // Index of first app classpath entry
226   jshort _app_module_paths_start_index; // Index of first module path entry
227   jshort _num_module_paths;             // number of module path entries
228   jshort _max_used_path_index;          // max path index referenced during CDS dump
229   bool   _verify_local;                 // BytecodeVerificationLocal setting
230   bool   _verify_remote;                // BytecodeVerificationRemote setting
231   bool   _has_platform_or_app_classes;  // Archive contains app classes
232   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
233   char*  _mapped_base_address;          // Actual base address where archive is mapped.
234 
235   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
236   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
237                                         // some expensive operations.
238   bool   _use_full_module_graph;        // Can we use the full archived module graph?
239   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
240   narrowOop _heap_obj_roots;            // An objArray that stores all the roots of archived heap objects

241   char* from_mapped_offset(size_t offset) const {
242     return mapped_base_address() + offset;
243   }
244   void set_as_offset(char* p, size_t *offset);
245 public:
246   // Accessors -- fields declared in CDSFileMapHeaderBase
247   unsigned int magic()                    const { return _magic; }
248   int crc()                               const { return _crc; }
249   int version()                           const { return _version; }
250 
251   void set_crc(int crc_value)                   { _crc = crc_value; }
252   void set_version(int v)                       { _version = v; }
253 
254   // Accessors -- fields declared in FileMapHeader
255 
256   size_t header_size()                     const { return _header_size; }
257   size_t core_region_alignment()           const { return _core_region_alignment; }
258   int obj_alignment()                      const { return _obj_alignment; }
259   address narrow_oop_base()                const { return _narrow_oop_base; }
260   int narrow_oop_shift()                   const { return _narrow_oop_shift; }
261   bool compact_strings()                   const { return _compact_strings; }
262   uintx max_heap_size()                    const { return _max_heap_size; }
263   CompressedOops::Mode narrow_oop_mode()   const { return _narrow_oop_mode; }
264   int narrow_klass_shift()                 const { return _narrow_klass_shift; }
265   address narrow_klass_base()              const { return (address)mapped_base_address(); }
266   char* cloned_vtables()                   const { return from_mapped_offset(_cloned_vtables_offset); }
267   char* serialized_data()                  const { return from_mapped_offset(_serialized_data_offset); }
268   address heap_begin()                     const { return _heap_begin; }
269   address heap_end()                       const { return _heap_end; }
270   bool base_archive_is_default()           const { return _base_archive_is_default; }
271   const char* jvm_ident()                  const { return _jvm_ident; }
272   size_t base_archive_name_size()          const { return _base_archive_name_size; }
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   size_t ptrmap_size_in_bits()             const { return _ptrmap_size_in_bits; }
278   bool compressed_oops()                   const { return _compressed_oops; }
279   bool compressed_class_pointers()         const { return _compressed_class_ptrs; }
280   // FIXME: These should really return int
281   jshort max_used_path_index()             const { return _max_used_path_index; }
282   jshort app_module_paths_start_index()    const { return _app_module_paths_start_index; }
283   jshort app_class_paths_start_index()     const { return _app_class_paths_start_index; }
284   jshort num_module_paths()                const { return _num_module_paths; }
285   narrowOop heap_obj_roots()               const { return _heap_obj_roots; }
286 
287   void set_has_platform_or_app_classes(bool v)   { _has_platform_or_app_classes = v; }
288   void set_cloned_vtables(char* p)               { set_as_offset(p, &_cloned_vtables_offset); }
289   void set_serialized_data(char* p)              { set_as_offset(p, &_serialized_data_offset); }
290   void set_base_archive_name_size(size_t s)      { _base_archive_name_size = s; }
291   void set_base_archive_is_default(bool b)       { _base_archive_is_default = b; }
292   void set_header_size(size_t s)                 { _header_size = s; }
293   void set_ptrmap_size_in_bits(size_t s)         { _ptrmap_size_in_bits = s; }
294   void set_mapped_base_address(char* p)          { _mapped_base_address = p; }
295   void set_heap_obj_roots(narrowOop r)           { _heap_obj_roots = r; }
296 
297   void set_shared_path_table(SharedPathTable table) {
298     set_as_offset((char*)table.table(), &_shared_path_table_offset);
299     _shared_path_table_size = table.size();
300   }
301 
302   void set_requested_base(char* b) {
303     _requested_base_address = b;
304     _mapped_base_address = 0;
305   }
306 
307   SharedPathTable shared_path_table() const {
308     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
309                            _shared_path_table_size);
310   }
311 
312   bool validate();
313   int compute_crc();
314 
315   FileMapRegion* space_at(int i) {
316     assert(is_valid_region(i), "invalid region");
317     return FileMapRegion::cast(&_space[i]);
318   }
319 
320   void populate(FileMapInfo* info, size_t core_region_alignment);
321 
322   static bool is_valid_region(int region) {
323     return (0 <= region && region < NUM_CDS_REGIONS);
324   }
325 




326   void print(outputStream* st);
327 };
328 
329 class FileMapInfo : public CHeapObj<mtInternal> {
330 private:
331   friend class ManifestStream;
332   friend class VMStructs;
333   friend class ArchiveBuilder;
334   friend class CDSOffsets;
335   friend class FileMapHeader;
336 
337   bool           _is_static;
338   bool           _file_open;
339   bool           _is_mapped;
340   int            _fd;
341   size_t         _file_offset;
342   const char*    _full_path;
343   const char*    _base_archive_name;
344   FileMapHeader* _header;
345 
346   // TODO: Probably change the following to be non-static
347   static SharedPathTable       _shared_path_table;
348   static SharedPathTable       _saved_shared_path_table;
349   static Array<u8>*            _saved_shared_path_table_array;  // remember the table array for cleanup
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     assert(_saved_shared_path_table.size() >= 0, "Sanity check");
373     return _saved_shared_path_table;
374   }
375 
376   bool init_from_file(int fd);
377   static void metaspace_pointers_do(MetaspaceClosure* it, bool use_copy = true);
378 
379   void log_paths(const char* msg, int start_idx, int end_idx);
380 
381   FileMapInfo(bool is_static);
382   ~FileMapInfo();
383 
384   // Accessors
385   int    compute_header_crc()  const { return header()->compute_crc(); }
386   void   set_header_crc(int crc)     { header()->set_crc(crc); }
387   int    space_crc(int i)      const { return space_at(i)->crc(); }
388   void   populate_header(size_t core_region_alignment);
389   bool   validate_header();
390   void   invalidate();
391   int    crc()                 const { return header()->crc(); }
392   int    version()             const { return header()->version(); }
393   unsigned int magic()         const { return header()->magic(); }
394   address narrow_oop_base()    const { return header()->narrow_oop_base(); }
395   int     narrow_oop_shift()   const { return header()->narrow_oop_shift(); }
396   uintx   max_heap_size()      const { return header()->max_heap_size(); }
397   address narrow_klass_base()  const { return header()->narrow_klass_base(); }
398   int     narrow_klass_shift() const { return header()->narrow_klass_shift(); }
399   size_t  core_region_alignment() const { return header()->core_region_alignment(); }
400 
401   void   set_header_base_archive_name_size(size_t size)      { header()->set_base_archive_name_size(size); }
402   void   set_header_base_archive_is_default(bool is_default) { header()->set_base_archive_is_default(is_default); }
403 
404   CompressedOops::Mode narrow_oop_mode()      const { return header()->narrow_oop_mode(); }
405   jshort app_module_paths_start_index()       const { return header()->app_module_paths_start_index(); }
406   jshort app_class_paths_start_index()        const { return header()->app_class_paths_start_index(); }
407 
408   char* cloned_vtables()                      const { return header()->cloned_vtables(); }
409   void  set_cloned_vtables(char* p)           const { header()->set_cloned_vtables(p); }
410   char* serialized_data()                     const { return header()->serialized_data(); }
411   void  set_serialized_data(char* p)          const { header()->set_serialized_data(p); }
412 
413   bool  is_file_position_aligned() const;
414   void  align_file_position();
415 
416   bool is_static()                            const { return _is_static; }
417   bool is_mapped()                            const { return _is_mapped; }
418   void set_is_mapped(bool v)                        { _is_mapped = v; }
419   const char* full_path()                     const { return _full_path; }
420 
421   void set_requested_base(char* b)                  { header()->set_requested_base(b); }
422   char* requested_base_address()           const    { return header()->requested_base_address(); }
423 
424   narrowOop heap_obj_roots()               const    { return header()->heap_obj_roots(); }
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   char* write_bitmap_region(const CHeapBitMap* ptrmap,
462                             GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
463                             GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps,
464                             size_t &size_in_bytes);
465   size_t write_heap_regions(GrowableArray<MemRegion>* regions,
466                             GrowableArray<ArchiveHeapOopmapInfo>* oopmaps,
467                             int first_region_id, int max_num_regions);
468   void  write_bytes(const void* buffer, size_t count);
469   void  write_bytes_aligned(const void* buffer, size_t count);
470   size_t  read_bytes(void* buffer, size_t count);
471   MapArchiveResult map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs);
472   void  unmap_regions(int regions[], int num_regions);
473   void  map_or_load_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
474   void  fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
475   void  patch_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN;
476   void  patch_heap_embedded_pointers(MemRegion* regions, int num_regions,
477                                      int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN;
478   bool  has_heap_regions()  NOT_CDS_JAVA_HEAP_RETURN_(false);
479   MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion());
480   bool  read_region(int i, char* base, size_t size, bool do_commit);
481   char* map_bitmap_region();
482   void  unmap_region(int i);
483   bool  verify_region_checksum(int i);
484   void  close();
485   bool  is_open() { return _file_open; }
486   ReservedSpace reserve_shared_memory();
487 
488   // JVM/TI RedefineClasses() support:
489   // Remap the shared readonly space to shared readwrite, private.
490   bool  remap_shared_readonly_as_readwrite();
491 
492   // Errors.
493   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
494   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
495   static bool memory_mapping_failed() {
496     CDS_ONLY(return _memory_mapping_failed;)
497     NOT_CDS(return false;)
498   }
499   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
500 
501   // Stop CDS sharing and unmap CDS regions.
502   static void stop_sharing_and_unmap(const char* msg);
503 
504   static void allocate_shared_path_table(TRAPS);
505   static void copy_shared_path_table(ClassLoaderData* loader_data, TRAPS);
506   static void clone_shared_path_table(TRAPS);
507   static int add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS);
508   static void check_nonempty_dir_in_shared_path_table();
509   bool validate_shared_path_table();
510   void validate_non_existent_class_paths();
511   static void set_shared_path_table(FileMapInfo* info) {
512     _shared_path_table = info->header()->shared_path_table();
513   }
514   static void update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
515   static int num_non_existent_class_paths();
516   static void record_non_existent_class_path_entry(const char* path);
517 
518 #if INCLUDE_JVMTI
519   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
520 #endif
521 
522   static SharedClassPathEntry* shared_path(int index) {
523     return _shared_path_table.path_at(index);
524   }
525 
526   static const char* shared_path_name(int index) {
527     assert(index >= 0, "Sanity");
528     return shared_path(index)->name();
529   }
530 
531   static int get_number_of_shared_paths() {
532     return _shared_path_table.size();
533   }
534 
535   static int get_module_shared_path_index(Symbol* location) NOT_CDS_RETURN_(-1);
536 
537   char* region_addr(int idx);
538 
539   // The offset of the first core region in the archive, relative to SharedBaseAddress
540   size_t mapping_base_offset() const { return first_core_space()->mapping_offset(); }
541   // The offset of the (exclusive) end of the last core region in this archive, relative to SharedBaseAddress
542   size_t mapping_end_offset()  const { return last_core_space()->mapping_end_offset(); }
543 
544   char* mapped_base()    const { return first_core_space()->mapped_base(); }
545   char* mapped_end()     const { return last_core_space()->mapped_end();   }
546 
547   // Non-zero if the archive needs to be mapped a non-default location due to ASLR.
548   intx relocation_delta() const {
549     return header()->mapped_base_address() - header()->requested_base_address();
550   }
551 
552   FileMapRegion* first_core_space() const;
553   FileMapRegion* last_core_space() const;
554 
555   FileMapRegion* space_at(int i) const {
556     return header()->space_at(i);
557   }
558 
559   void print(outputStream* st) {
560     header()->print(st);
561   }
562 
563   const char* vm_version() {
564     return header()->jvm_ident();
565   }
566 
567  private:
568   void  seek_to_position(size_t pos);
569   char* skip_first_path_entry(const char* path) NOT_CDS_RETURN_(NULL);
570   int   num_paths(const char* path) NOT_CDS_RETURN_(0);
571   GrowableArray<const char*>* create_path_array(const char* path) NOT_CDS_RETURN_(NULL);
572   bool  classpath_failure(const char* msg, const char* name) NOT_CDS_RETURN_(false);
573   bool  check_paths(int shared_path_start_idx, int num_paths,
574                     GrowableArray<const char*>* rp_array) NOT_CDS_RETURN_(false);
575   bool  validate_boot_class_paths() NOT_CDS_RETURN_(false);
576   bool  validate_app_class_paths(int shared_app_paths_len) NOT_CDS_RETURN_(false);
577   bool  map_heap_regions(int first, int max, bool is_open_archive,
578                          MemRegion** regions_ret, int* num_regions_ret) NOT_CDS_JAVA_HEAP_RETURN_(false);
579   bool  region_crc_check(char* buf, size_t size, int expected_crc) NOT_CDS_RETURN_(false);
580   void  dealloc_heap_regions(MemRegion* regions, int num) NOT_CDS_JAVA_HEAP_RETURN;
581   bool  can_use_heap_regions();
582   bool  load_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false);
583   bool  map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false);
584   void  map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN;
585   MapArchiveResult map_region(int i, intx addr_delta, char* mapped_base_address, ReservedSpace rs);
586   bool  relocate_pointers_in_core_regions(intx addr_delta);
587   static size_t set_oopmaps_offset(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_size);
588   static size_t write_oopmaps(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_offset, char* buffer);
589 
590   address decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode);
591 
592   // The starting address of spc, as calculated with CompressedOop::decode_non_null()
593   address start_address_as_decoded_with_current_oop_encoding_mode(FileMapRegion* spc) {
594     return decode_start_address(spc, true);
595   }
596 public:
597   // The starting address of spc, as calculated with HeapShared::decode_from_archive()
598   address start_address_as_decoded_from_archive(FileMapRegion* spc) {
599     return decode_start_address(spc, false);
600   }
601 
602 private:
603 
604 #if INCLUDE_JVMTI
605   static ClassPathEntry** _classpath_entries_for_jvmti;
606   static ClassPathEntry* get_classpath_entry_for_jvmti(int i, TRAPS);
607 #endif
608 };
609 
610 #endif // SHARE_CDS_FILEMAP_HPP
--- EOF ---