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 "runtime/globals.hpp"
 33 #include "utilities/align.hpp"
 34 
 35 // To understand the layout of the CDS archive file:
 36 //
 37 // java -Xlog:cds+map=info:file=cds.map:none:filesize=0
 38 // java -Xlog:cds+map=debug:file=cds.map:none:filesize=0
 39 // java -Xlog:cds+map=trace:file=cds.map:none:filesize=0
 40 
 41 static const int JVM_IDENT_MAX = 256;
 42 
 43 class CHeapBitMap;
 44 class ClassFileStream;
 45 class ClassLoaderData;
 46 class ClassPathEntry;
 47 class outputStream;
 48 
 49 class SharedClassPathEntry {
 50   enum {
 51     modules_image_entry,
 52     jar_entry,
 53     signed_jar_entry,
 54     dir_entry,
 55     non_existent_entry,
 56     unknown_entry
 57   };
 58 
 59   void set_name(const char* name, TRAPS);
 60 
 61   u1     _type;
 62   bool   _is_module_path;
 63   bool   _from_class_path_attr;
 64   time_t _timestamp;          // jar timestamp,  0 if is directory, modules image or other
 65   int64_t      _filesize;     // jar/jimage file size, -1 if is directory, -2 if other
 66   Array<char>* _name;
 67   Array<u1>*   _manifest;
 68 
 69 public:
 70   void init(bool is_modules_image, bool is_module_path, ClassPathEntry* cpe, TRAPS);
 71   void init_as_non_existent(const char* path, TRAPS);
 72   void metaspace_pointers_do(MetaspaceClosure* it);
 73   bool validate(bool is_class_path = true) const;
 74 
 75   // The _timestamp only gets set for jar files.
 76   bool has_timestamp() const {
 77     return _timestamp != 0;
 78   }
 79   bool is_dir()           const { return _type == dir_entry; }
 80   bool is_modules_image() const { return _type == modules_image_entry; }
 81   bool is_jar()           const { return _type == jar_entry; }
 82   bool is_signed()        const { return _type == signed_jar_entry; }
 83   void set_is_signed() {
 84     _type = signed_jar_entry;
 85   }
 86   bool from_class_path_attr() { return _from_class_path_attr; }
 87   time_t timestamp() const { return _timestamp; }
 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, TRAPS);
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 public:
142   void assert_is_heap_region() const {
143     assert(_is_heap_region, "must be heap region");
144   }
145   void assert_is_not_heap_region() const {
146     assert(!_is_heap_region, "must not be heap region");
147   }
148 
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 MetaspaceShared::core_region_alignment()
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, size_t mapping_offset, 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   void print(outputStream* st, int region_index);
181 };
182 
183 #define CDS_MUST_MATCH_FLAGS_DO(f) \
184   f(EnableValhalla) \
185   f(FlatArrayElementMaxOops) \
186   f(FlatArrayElementMaxSize) \
187   f(InlineFieldMaxFlatSize) \
188   f(InlineTypePassFieldsAsArgs) \
189   f(InlineTypeReturnedAsFields)
190 
191 class CDSMustMatchFlags {
192 private:
193   size_t _max_name_width;
194 #define DECLARE_CDS_MUST_MATCH_FLAG(n) \
195   decltype(n) _v_##n;
196   CDS_MUST_MATCH_FLAGS_DO(DECLARE_CDS_MUST_MATCH_FLAG);
197 #undef DECLARE_CDS_MUST_MATCH_FLAG
198 
199   inline static void do_print(outputStream* st, bool v);
200   inline static void do_print(outputStream* st, intx v);
201   inline static void do_print(outputStream* st, uintx v);
202   inline static void do_print(outputStream* st, double v);
203   void print_info() const;
204 
205 public:
206   void init();
207   bool runtime_check() const;
208   void print(outputStream* st) const;
209 };
210 
211 class FileMapHeader: private CDSFileMapHeaderBase {
212   friend class CDSConstants;
213   friend class VMStructs;
214 
215 private:
216   size_t _header_size;
217 
218   // The following fields record the states of the VM during dump time.
219   // They are compared with the runtime states to see if the archive
220   // can be used.
221   size_t _core_region_alignment;    // how shared archive should be aligned
222   int    _obj_alignment;            // value of ObjectAlignmentInBytes
223   address _narrow_oop_base;         // compressed oop encoding base
224   int    _narrow_oop_shift;         // compressed oop encoding shift
225   bool   _compact_strings;          // value of CompactStrings
226   uintx  _max_heap_size;            // java max heap size during dumping
227   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
228   int     _narrow_klass_shift;      // save narrow klass base and shift
229   bool    _compressed_oops;         // save the flag UseCompressedOops
230   bool    _compressed_class_ptrs;   // save the flag UseCompressedClassPointers
231   size_t  _cloned_vtables_offset;   // The address of the first cloned vtable
232   size_t  _serialized_data_offset;  // Data accessed using {ReadClosure,WriteClosure}::serialize()
233   address _heap_begin;              // heap begin at dump time.
234   address _heap_end;                // heap end at dump time.
235   bool _base_archive_is_default;    // indicates if the base archive is the system default one
236   bool _has_non_jar_in_classpath;   // non-jar file entry exists in classpath
237 
238   // The following fields are all sanity checks for whether this archive
239   // will function correctly with this JVM and the bootclasspath it's
240   // invoked with.
241   char  _jvm_ident[JVM_IDENT_MAX];  // identifier string of the jvm that created this dump
242   // size of the base archive name including NULL terminator
243   size_t _base_archive_name_size;
244 
245   // The following is a table of all the boot/app/module path entries that were used
246   // during dumping. At run time, we validate these entries according to their
247   // SharedClassPathEntry::_type. See:
248   //      check_nonempty_dir_in_shared_path_table()
249   //      validate_shared_path_table()
250   //      validate_non_existent_class_paths()
251   size_t _shared_path_table_offset;
252   int    _shared_path_table_size;
253 
254   jshort _app_class_paths_start_index;  // Index of first app classpath entry
255   jshort _app_module_paths_start_index; // Index of first module path entry
256   jshort _num_module_paths;             // number of module path entries
257   jshort _max_used_path_index;          // max path index referenced during CDS dump
258   bool   _verify_local;                 // BytecodeVerificationLocal setting
259   bool   _verify_remote;                // BytecodeVerificationRemote setting
260   bool   _has_platform_or_app_classes;  // Archive contains app classes
261   char*  _requested_base_address;       // Archive relocation is not necessary if we map with this base address.
262   char*  _mapped_base_address;          // Actual base address where archive is mapped.
263 
264   bool   _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
265   bool   _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
266                                         // some expensive operations.
267   bool   _use_full_module_graph;        // Can we use the full archived module graph?
268   size_t _ptrmap_size_in_bits;          // Size of pointer relocation bitmap
269   narrowOop _heap_obj_roots;            // An objArray that stores all the roots of archived heap objects
270   CDSMustMatchFlags _must_match;        // These flags must be the same between dumptime and runtime
271   char* from_mapped_offset(size_t offset) const {
272     return mapped_base_address() + offset;
273   }
274   void set_as_offset(char* p, size_t *offset);
275 public:
276   // Accessors -- fields declared in CDSFileMapHeaderBase
277   unsigned int magic()                    const { return _magic; }
278   int crc()                               const { return _crc; }
279   int version()                           const { return _version; }
280 
281   void set_crc(int crc_value)                   { _crc = crc_value; }
282   void set_version(int v)                       { _version = v; }
283 
284   // Accessors -- fields declared in FileMapHeader
285 
286   size_t header_size()                     const { return _header_size; }
287   size_t core_region_alignment()           const { return _core_region_alignment; }
288   int obj_alignment()                      const { return _obj_alignment; }
289   address narrow_oop_base()                const { return _narrow_oop_base; }
290   int narrow_oop_shift()                   const { return _narrow_oop_shift; }
291   bool compact_strings()                   const { return _compact_strings; }
292   uintx max_heap_size()                    const { return _max_heap_size; }
293   CompressedOops::Mode narrow_oop_mode()   const { return _narrow_oop_mode; }
294   int narrow_klass_shift()                 const { return _narrow_klass_shift; }
295   address narrow_klass_base()              const { return (address)mapped_base_address(); }
296   char* cloned_vtables()                   const { return from_mapped_offset(_cloned_vtables_offset); }
297   char* serialized_data()                  const { return from_mapped_offset(_serialized_data_offset); }
298   address heap_begin()                     const { return _heap_begin; }
299   address heap_end()                       const { return _heap_end; }
300   bool base_archive_is_default()           const { return _base_archive_is_default; }
301   const char* jvm_ident()                  const { return _jvm_ident; }
302   size_t base_archive_name_size()          const { return _base_archive_name_size; }
303   char* requested_base_address()           const { return _requested_base_address; }
304   char* mapped_base_address()              const { return _mapped_base_address; }
305   bool has_platform_or_app_classes()       const { return _has_platform_or_app_classes; }
306   bool has_non_jar_in_classpath()          const { return _has_non_jar_in_classpath; }
307   size_t ptrmap_size_in_bits()             const { return _ptrmap_size_in_bits; }
308   bool compressed_oops()                   const { return _compressed_oops; }
309   bool compressed_class_pointers()         const { return _compressed_class_ptrs; }
310   // FIXME: These should really return int
311   jshort max_used_path_index()             const { return _max_used_path_index; }
312   jshort app_module_paths_start_index()    const { return _app_module_paths_start_index; }
313   jshort app_class_paths_start_index()     const { return _app_class_paths_start_index; }
314   jshort num_module_paths()                const { return _num_module_paths; }
315   narrowOop heap_obj_roots()               const { return _heap_obj_roots; }
316 
317   void set_has_platform_or_app_classes(bool v)   { _has_platform_or_app_classes = v; }
318   void set_cloned_vtables(char* p)               { set_as_offset(p, &_cloned_vtables_offset); }
319   void set_serialized_data(char* p)              { set_as_offset(p, &_serialized_data_offset); }
320   void set_base_archive_name_size(size_t s)      { _base_archive_name_size = s; }
321   void set_base_archive_is_default(bool b)       { _base_archive_is_default = b; }
322   void set_header_size(size_t s)                 { _header_size = s; }
323   void set_ptrmap_size_in_bits(size_t s)         { _ptrmap_size_in_bits = s; }
324   void set_mapped_base_address(char* p)          { _mapped_base_address = p; }
325   void set_heap_obj_roots(narrowOop r)           { _heap_obj_roots = r; }
326 
327   void set_shared_path_table(SharedPathTable table) {
328     set_as_offset((char*)table.table(), &_shared_path_table_offset);
329     _shared_path_table_size = table.size();
330   }
331 
332   void set_requested_base(char* b) {
333     _requested_base_address = b;
334     _mapped_base_address = 0;
335   }
336 
337   SharedPathTable shared_path_table() const {
338     return SharedPathTable((Array<u8>*)from_mapped_offset(_shared_path_table_offset),
339                            _shared_path_table_size);
340   }
341 
342   bool validate();
343   int compute_crc();
344 
345   FileMapRegion* space_at(int i) {
346     assert(is_valid_region(i), "invalid region");
347     return FileMapRegion::cast(&_space[i]);
348   }
349 
350   void populate(FileMapInfo* info, size_t core_region_alignment);
351 
352   static bool is_valid_region(int region) {
353     return (0 <= region && region < NUM_CDS_REGIONS);
354   }
355 
356   bool check_must_match_flags() const {
357     return _must_match.runtime_check();
358   }
359 
360   void print(outputStream* st);
361 };
362 
363 class FileMapInfo : public CHeapObj<mtInternal> {
364 private:
365   friend class ManifestStream;
366   friend class VMStructs;
367   friend class ArchiveBuilder;
368   friend class CDSOffsets;
369   friend class FileMapHeader;
370 
371   bool           _is_static;
372   bool           _file_open;
373   bool           _is_mapped;
374   int            _fd;
375   size_t         _file_offset;
376   const char*    _full_path;
377   const char*    _base_archive_name;
378   FileMapHeader* _header;
379 
380   // TODO: Probably change the following to be non-static
381   static SharedPathTable       _shared_path_table;
382   static SharedPathTable       _saved_shared_path_table;
383   static Array<u8>*            _saved_shared_path_table_array;  // remember the table array for cleanup
384   static bool                  _validating_shared_path_table;
385 
386   // FileMapHeader describes the shared space data in the file to be
387   // mapped.  This structure gets written to a file.  It is not a class, so
388   // that the compilers don't add any compiler-private data to it.
389 
390   static FileMapInfo* _current_info;
391   static FileMapInfo* _dynamic_archive_info;
392   static bool _heap_pointers_need_patching;
393   static bool _memory_mapping_failed;
394   static GrowableArray<const char*>* _non_existent_class_paths;
395 
396   FileMapHeader *header() const       { return _header; }
397 
398 public:
399   static bool get_base_archive_name_from_header(const char* archive_name,
400                                                 int* size, char** base_archive_name);
401   static bool check_archive(const char* archive_name, bool is_static);
402   static SharedPathTable shared_path_table() {
403     return _shared_path_table;
404   }
405   static SharedPathTable saved_shared_path_table() {
406     assert(_saved_shared_path_table.size() >= 0, "Sanity check");
407     return _saved_shared_path_table;
408   }
409 
410   bool init_from_file(int fd);
411   static void metaspace_pointers_do(MetaspaceClosure* it, bool use_copy = true);
412 
413   void log_paths(const char* msg, int start_idx, int end_idx);
414 
415   FileMapInfo(bool is_static);
416   ~FileMapInfo();
417 
418   // Accessors
419   int    compute_header_crc()  const { return header()->compute_crc(); }
420   void   set_header_crc(int crc)     { header()->set_crc(crc); }
421   int    space_crc(int i)      const { return space_at(i)->crc(); }
422   void   populate_header(size_t core_region_alignment);
423   bool   validate_header();
424   void   invalidate();
425   int    crc()                 const { return header()->crc(); }
426   int    version()             const { return header()->version(); }
427   unsigned int magic()         const { return header()->magic(); }
428   address narrow_oop_base()    const { return header()->narrow_oop_base(); }
429   int     narrow_oop_shift()   const { return header()->narrow_oop_shift(); }
430   uintx   max_heap_size()      const { return header()->max_heap_size(); }
431   address narrow_klass_base()  const { return header()->narrow_klass_base(); }
432   int     narrow_klass_shift() const { return header()->narrow_klass_shift(); }
433   size_t  core_region_alignment() const { return header()->core_region_alignment(); }
434 
435   void   set_header_base_archive_name_size(size_t size)      { header()->set_base_archive_name_size(size); }
436   void   set_header_base_archive_is_default(bool is_default) { header()->set_base_archive_is_default(is_default); }
437 
438   CompressedOops::Mode narrow_oop_mode()      const { return header()->narrow_oop_mode(); }
439   jshort app_module_paths_start_index()       const { return header()->app_module_paths_start_index(); }
440   jshort app_class_paths_start_index()        const { return header()->app_class_paths_start_index(); }
441 
442   char* cloned_vtables()                      const { return header()->cloned_vtables(); }
443   void  set_cloned_vtables(char* p)           const { header()->set_cloned_vtables(p); }
444   char* serialized_data()                     const { return header()->serialized_data(); }
445   void  set_serialized_data(char* p)          const { header()->set_serialized_data(p); }
446 
447   bool  is_file_position_aligned() const;
448   void  align_file_position();
449 
450   bool is_static()                            const { return _is_static; }
451   bool is_mapped()                            const { return _is_mapped; }
452   void set_is_mapped(bool v)                        { _is_mapped = v; }
453   const char* full_path()                     const { return _full_path; }
454 
455   void set_requested_base(char* b)                  { header()->set_requested_base(b); }
456   char* requested_base_address()           const    { return header()->requested_base_address(); }
457 
458   narrowOop heap_obj_roots()               const    { return header()->heap_obj_roots(); }
459 
460   class DynamicArchiveHeader* dynamic_header() const {
461     assert(!is_static(), "must be");
462     return (DynamicArchiveHeader*)header();
463   }
464 
465   void set_has_platform_or_app_classes(bool v) {
466     header()->set_has_platform_or_app_classes(v);
467   }
468   bool has_platform_or_app_classes() const {
469     return header()->has_platform_or_app_classes();
470   }
471 
472   static FileMapInfo* current_info() {
473     CDS_ONLY(return _current_info;)
474     NOT_CDS(return NULL;)
475   }
476 
477   static void set_current_info(FileMapInfo* info) {
478     CDS_ONLY(_current_info = info;)
479   }
480 
481   static FileMapInfo* dynamic_info() {
482     CDS_ONLY(return _dynamic_archive_info;)
483     NOT_CDS(return NULL;)
484   }
485 
486   static void assert_mark(bool check);
487 
488   // File manipulation.
489   bool  initialize() NOT_CDS_RETURN_(false);
490   bool  open_for_read();
491   void  open_for_write(const char* path = NULL);
492   void  write_header();
493   void  write_region(int region, char* base, size_t size,
494                      bool read_only, bool allow_exec);
495   char* write_bitmap_region(const CHeapBitMap* ptrmap,
496                             GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
497                             GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps,
498                             size_t &size_in_bytes);
499   size_t write_heap_regions(GrowableArray<MemRegion>* regions,
500                             GrowableArray<ArchiveHeapOopmapInfo>* oopmaps,
501                             int first_region_id, int max_num_regions);
502   void  write_bytes(const void* buffer, size_t count);
503   void  write_bytes_aligned(const void* buffer, size_t count);
504   size_t  read_bytes(void* buffer, size_t count);
505   MapArchiveResult map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs);
506   void  unmap_regions(int regions[], int num_regions);
507   void  map_or_load_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
508   void  fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
509   void  patch_heap_embedded_pointers() NOT_CDS_JAVA_HEAP_RETURN;
510   void  patch_heap_embedded_pointers(MemRegion* regions, int num_regions,
511                                      int first_region_idx) NOT_CDS_JAVA_HEAP_RETURN;
512   bool  has_heap_regions()  NOT_CDS_JAVA_HEAP_RETURN_(false);
513   MemRegion get_heap_regions_range_with_current_oop_encoding_mode() NOT_CDS_JAVA_HEAP_RETURN_(MemRegion());
514   bool  read_region(int i, char* base, size_t size, bool do_commit);
515   char* map_bitmap_region();
516   void  unmap_region(int i);
517   bool  verify_region_checksum(int i);
518   void  close();
519   bool  is_open() { return _file_open; }
520   ReservedSpace reserve_shared_memory();
521 
522   // JVM/TI RedefineClasses() support:
523   // Remap the shared readonly space to shared readwrite, private.
524   bool  remap_shared_readonly_as_readwrite();
525 
526   // Errors.
527   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
528   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
529   static bool memory_mapping_failed() {
530     CDS_ONLY(return _memory_mapping_failed;)
531     NOT_CDS(return false;)
532   }
533   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
534 
535   // Stop CDS sharing and unmap CDS regions.
536   static void stop_sharing_and_unmap(const char* msg);
537 
538   static void allocate_shared_path_table(TRAPS);
539   static void copy_shared_path_table(ClassLoaderData* loader_data, TRAPS);
540   static void clone_shared_path_table(TRAPS);
541   static int add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS);
542   static void check_nonempty_dir_in_shared_path_table();
543   bool validate_shared_path_table();
544   void validate_non_existent_class_paths();
545   static void set_shared_path_table(FileMapInfo* info) {
546     _shared_path_table = info->header()->shared_path_table();
547   }
548   static void update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
549   static int num_non_existent_class_paths();
550   static void record_non_existent_class_path_entry(const char* path);
551 
552 #if INCLUDE_JVMTI
553   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
554 #endif
555 
556   static SharedClassPathEntry* shared_path(int index) {
557     return _shared_path_table.path_at(index);
558   }
559 
560   static const char* shared_path_name(int index) {
561     assert(index >= 0, "Sanity");
562     return shared_path(index)->name();
563   }
564 
565   static int get_number_of_shared_paths() {
566     return _shared_path_table.size();
567   }
568 
569   static int get_module_shared_path_index(Symbol* location) NOT_CDS_RETURN_(-1);
570 
571   char* region_addr(int idx);
572 
573   // The offset of the first core region in the archive, relative to SharedBaseAddress
574   size_t mapping_base_offset() const { return first_core_space()->mapping_offset(); }
575   // The offset of the (exclusive) end of the last core region in this archive, relative to SharedBaseAddress
576   size_t mapping_end_offset()  const { return last_core_space()->mapping_end_offset(); }
577 
578   char* mapped_base()    const { return first_core_space()->mapped_base(); }
579   char* mapped_end()     const { return last_core_space()->mapped_end();   }
580 
581   // Non-zero if the archive needs to be mapped a non-default location due to ASLR.
582   intx relocation_delta() const {
583     return header()->mapped_base_address() - header()->requested_base_address();
584   }
585 
586   FileMapRegion* first_core_space() const;
587   FileMapRegion* last_core_space() const;
588 
589   FileMapRegion* space_at(int i) const {
590     return header()->space_at(i);
591   }
592 
593   void print(outputStream* st) {
594     header()->print(st);
595   }
596 
597   const char* vm_version() {
598     return header()->jvm_ident();
599   }
600 
601  private:
602   void  seek_to_position(size_t pos);
603   char* skip_first_path_entry(const char* path) NOT_CDS_RETURN_(NULL);
604   int   num_paths(const char* path) NOT_CDS_RETURN_(0);
605   GrowableArray<const char*>* create_path_array(const char* path) NOT_CDS_RETURN_(NULL);
606   bool  classpath_failure(const char* msg, const char* name) NOT_CDS_RETURN_(false);
607   bool  check_paths(int shared_path_start_idx, int num_paths,
608                     GrowableArray<const char*>* rp_array) NOT_CDS_RETURN_(false);
609   bool  validate_boot_class_paths() NOT_CDS_RETURN_(false);
610   bool  validate_app_class_paths(int shared_app_paths_len) NOT_CDS_RETURN_(false);
611   bool  map_heap_regions(int first, int max, bool is_open_archive,
612                          MemRegion** regions_ret, int* num_regions_ret) NOT_CDS_JAVA_HEAP_RETURN_(false);
613   bool  region_crc_check(char* buf, size_t size, int expected_crc) NOT_CDS_RETURN_(false);
614   void  dealloc_heap_regions(MemRegion* regions, int num) NOT_CDS_JAVA_HEAP_RETURN;
615   bool  can_use_heap_regions();
616   bool  load_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false);
617   bool  map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN_(false);
618   void  map_heap_regions_impl() NOT_CDS_JAVA_HEAP_RETURN;
619   MapArchiveResult map_region(int i, intx addr_delta, char* mapped_base_address, ReservedSpace rs);
620   bool  relocate_pointers_in_core_regions(intx addr_delta);
621   static size_t set_oopmaps_offset(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_size);
622   static size_t write_oopmaps(GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, size_t curr_offset, char* buffer);
623 
624   address decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode);
625 
626   // The starting address of spc, as calculated with CompressedOop::decode_non_null()
627   address start_address_as_decoded_with_current_oop_encoding_mode(FileMapRegion* spc) {
628     return decode_start_address(spc, true);
629   }
630 public:
631   // The starting address of spc, as calculated with HeapShared::decode_from_archive()
632   address start_address_as_decoded_from_archive(FileMapRegion* spc) {
633     return decode_start_address(spc, false);
634   }
635 
636 private:
637 
638 #if INCLUDE_JVMTI
639   static ClassPathEntry** _classpath_entries_for_jvmti;
640   static ClassPathEntry* get_classpath_entry_for_jvmti(int i, TRAPS);
641 #endif
642 };
643 
644 #endif // SHARE_CDS_FILEMAP_HPP
--- EOF ---