< prev index next >

src/hotspot/share/memory/filemap.hpp

Print this page


  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 SharedClassPathEntry {
  47   enum {
  48     modules_image_entry,
  49     jar_entry,
  50     signed_jar_entry,
  51     dir_entry,

  52     unknown_entry
  53   };



  54 protected:
  55   u1     _type;
  56   bool   _from_class_path_attr;
  57   time_t _timestamp;          // jar timestamp,  0 if is directory, modules image or other
  58   long   _filesize;           // jar/jimage file size, -1 if is directory, -2 if other
  59   Array<char>* _name;
  60   Array<u1>*   _manifest;
  61 
  62 public:
  63   void init(bool is_modules_image, ClassPathEntry* cpe, TRAPS);

  64   void metaspace_pointers_do(MetaspaceClosure* it);
  65   bool validate(bool is_class_path = true);
  66 
  67   // The _timestamp only gets set for jar files.
  68   bool has_timestamp() {
  69     return _timestamp != 0;
  70   }
  71   bool is_dir()            { return _type == dir_entry; }
  72   bool is_modules_image()  { return _type == modules_image_entry; }
  73   bool is_jar()            { return _type == jar_entry; }
  74   bool is_signed()         { return _type == signed_jar_entry; }
  75   void set_is_signed()     {
  76     _type = signed_jar_entry;
  77   }
  78   bool from_class_path_attr() { return _from_class_path_attr; }
  79   time_t timestamp() const { return _timestamp; }
  80   long   filesize()  const { return _filesize; }
  81   const char* name() const { return _name->data(); }
  82   const char* manifest() const {
  83     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
  84   }
  85   int manifest_size() const {
  86     return (_manifest == NULL) ? 0 : _manifest->length();
  87   }
  88   void set_manifest(Array<u1>* manifest) {
  89     _manifest = manifest;
  90   }

  91 };
  92 
  93 struct ArchiveHeapOopmapInfo {
  94   address _oopmap;               // bitmap for relocating embedded oops
  95   size_t  _oopmap_size_in_bits;
  96 };
  97 
  98 class SharedPathTable {
  99   Array<u8>* _table;
 100   int _size;
 101 public:
 102   void dumptime_init(ClassLoaderData* loader_data, Thread* THREAD);
 103   void metaspace_pointers_do(MetaspaceClosure* it);
 104 
 105   int size() {
 106     return _size;
 107   }
 108   SharedClassPathEntry* path_at(int index) {
 109     if (index < 0) {
 110       return NULL;


 130   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
 131   int     _narrow_klass_shift;      // save narrow klass base and shift
 132   address _narrow_klass_base;
 133   char*   _misc_data_patching_start;
 134   char*   _read_only_tables_start;
 135   address _cds_i2i_entry_code_buffers;
 136   size_t  _cds_i2i_entry_code_buffers_size;
 137   size_t  _core_spaces_size;        // number of bytes allocated by the core spaces
 138                                     // (mc, md, ro, rw and od).
 139   MemRegion _heap_reserved;         // reserved region for the entire heap at dump time.
 140   bool _base_archive_is_default;    // indicates if the base archive is the system default one
 141 
 142   // The following fields are all sanity checks for whether this archive
 143   // will function correctly with this JVM and the bootclasspath it's
 144   // invoked with.
 145   char  _jvm_ident[JVM_IDENT_MAX];      // identifier for jvm
 146 
 147   // size of the base archive name including NULL terminator
 148   int _base_archive_name_size;
 149 
 150   // The _paths_misc_info is a variable-size structure that records "miscellaneous"
 151   // information during dumping. It is generated and validated by the
 152   // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for
 153   // detailed description.
 154   //
 155   // The _paths_misc_info data is stored as a byte array in the archive file header,
 156   // immediately after the _header field. This information is used only when
 157   // checking the validity of the archive and is deallocated after the archive is loaded.
 158   //
 159   // Note that the _paths_misc_info does NOT include information for JAR files
 160   // that existed during dump time. Their information is stored in _shared_path_table.
 161   int _paths_misc_info_size;
 162 
 163   // The following is a table of all the class path entries that were used
 164   // during dumping. At run time, we require these files to exist and have the same
 165   // size/modification time, or else the archive will refuse to load.
 166   //
 167   // All of these entries must be JAR files. The dumping process would fail if a non-empty
 168   // directory was specified in the classpaths. If an empty directory was specified
 169   // it is checked by the _paths_misc_info as described above.
 170   //
 171   // FIXME -- if JAR files in the tail of the list were specified but not used during dumping,
 172   // they should be removed from this table, to save space and to avoid spurious
 173   // loading failures during runtime.
 174   SharedPathTable _shared_path_table;
 175 
 176   jshort _app_class_paths_start_index;  // Index of first app classpath entry
 177   jshort _app_module_paths_start_index; // Index of first module path entry
 178   jshort _num_module_paths;             // number of module path entries
 179   jshort _max_used_path_index;          // max path index referenced during CDS dump
 180   bool   _verify_local;                 // BytecodeVerificationLocal setting
 181   bool   _verify_remote;                // BytecodeVerificationRemote setting
 182   bool   _has_platform_or_app_classes;  // Archive contains app classes


 222   // that the compilers don't add any compiler-private data to it.
 223 
 224 public:
 225   struct FileMapHeaderBase : public CHeapObj<mtClass> {
 226     // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual
 227     // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc.
 228     intx _dummy;
 229   };
 230 
 231 
 232   FileMapHeader * _header;
 233 
 234   const char* _full_path;
 235   char* _paths_misc_info;
 236   char* _base_archive_name;
 237 
 238   static FileMapInfo* _current_info;
 239   static FileMapInfo* _dynamic_archive_info;
 240   static bool _heap_pointers_need_patching;
 241   static bool _memory_mapping_failed;


 242   static bool get_base_archive_name_from_header(const char* archive_name,
 243                                                 int* size, char** base_archive_name);
 244   static bool check_archive(const char* archive_name, bool is_static);
 245   void restore_shared_path_table();
 246   bool  init_from_file(int fd, bool is_static);
 247   static void metaspace_pointers_do(MetaspaceClosure* it);
 248 


 249 public:
 250   FileMapInfo(bool is_static);
 251   ~FileMapInfo();
 252 
 253   int    compute_header_crc()         { return _header->compute_crc(); }
 254   void   set_header_crc(int crc)      { _header->_crc = crc; }
 255   int    space_crc(int i)             { return space_at(i)->_crc; }
 256   void   populate_header(size_t alignment);
 257   bool   validate_header(bool is_static);
 258   void   invalidate();
 259   int    crc()                        { return _header->_crc; }
 260   int    version()                    { return _header->_version; }
 261   size_t alignment()                  { return _header->_alignment; }
 262   CompressedOops::Mode narrow_oop_mode() { return _header->_narrow_oop_mode; }
 263   address narrow_oop_base()    const  { return _header->_narrow_oop_base; }
 264   int     narrow_oop_shift()   const  { return _header->_narrow_oop_shift; }
 265   uintx   max_heap_size()      const  { return _header->_max_heap_size; }
 266   address narrow_klass_base()  const  { return _header->_narrow_klass_base; }
 267   int     narrow_klass_shift() const  { return _header->_narrow_klass_shift; }
 268   struct  FileMapHeader* header()     { return _header; }


 336   bool  is_open() { return _file_open; }
 337   ReservedSpace reserve_shared_memory();
 338 
 339   // JVM/TI RedefineClasses() support:
 340   // Remap the shared readonly space to shared readwrite, private.
 341   bool  remap_shared_readonly_as_readwrite();
 342 
 343   // Errors.
 344   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 345   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 346   static bool memory_mapping_failed() {
 347     CDS_ONLY(return _memory_mapping_failed;)
 348     NOT_CDS(return false;)
 349   }
 350   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 351 
 352   // Stop CDS sharing and unmap CDS regions.
 353   static void stop_sharing_and_unmap(const char* msg);
 354 
 355   static void allocate_shared_path_table();

 356   static void check_nonempty_dir_in_shared_path_table();
 357   bool validate_shared_path_table();
 358   static void update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);



 359 
 360 #if INCLUDE_JVMTI
 361   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
 362 #endif
 363 
 364   static SharedClassPathEntry* shared_path(int index) {
 365     return _shared_path_table.path_at(index);
 366   }
 367 
 368   static const char* shared_path_name(int index) {
 369     assert(index >= 0, "Sanity");
 370     return shared_path(index)->name();
 371   }
 372 
 373   static int get_number_of_shared_paths() {
 374     return _shared_path_table.size();
 375   }
 376 
 377   char* region_addr(int idx);
 378 




  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 SharedClassPathEntry {
  47   enum {
  48     modules_image_entry,
  49     jar_entry,
  50     signed_jar_entry,
  51     dir_entry,
  52     non_existent_entry,
  53     unknown_entry
  54   };
  55 
  56   void set_name(const char* name, TRAPS);
  57 
  58 protected:
  59   u1     _type;
  60   bool   _from_class_path_attr;
  61   time_t _timestamp;          // jar timestamp,  0 if is directory, modules image or other
  62   long   _filesize;           // jar/jimage file size, -1 if is directory, -2 if other
  63   Array<char>* _name;
  64   Array<u1>*   _manifest;
  65 
  66 public:
  67   void init(bool is_modules_image, ClassPathEntry* cpe, TRAPS);
  68   void init_as_non_existent(const char* path, TRAPS);
  69   void metaspace_pointers_do(MetaspaceClosure* it);
  70   bool validate(bool is_class_path = true) const;
  71 
  72   // The _timestamp only gets set for jar files.
  73   bool has_timestamp() const {
  74     return _timestamp != 0;
  75   }
  76   bool is_dir()           const { return _type == dir_entry; }
  77   bool is_modules_image() const { return _type == modules_image_entry; }
  78   bool is_jar()           const { return _type == jar_entry; }
  79   bool is_signed()        const { return _type == signed_jar_entry; }
  80   void set_is_signed() {
  81     _type = signed_jar_entry;
  82   }
  83   bool from_class_path_attr() { return _from_class_path_attr; }
  84   time_t timestamp() const { return _timestamp; }
  85   long   filesize()  const { return _filesize; }
  86   const char* name() const;
  87   const char* manifest() const {
  88     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
  89   }
  90   int manifest_size() const {
  91     return (_manifest == NULL) ? 0 : _manifest->length();
  92   }
  93   void set_manifest(Array<u1>* manifest) {
  94     _manifest = manifest;
  95   }
  96   bool check_non_existent() const;
  97 };
  98 
  99 struct ArchiveHeapOopmapInfo {
 100   address _oopmap;               // bitmap for relocating embedded oops
 101   size_t  _oopmap_size_in_bits;
 102 };
 103 
 104 class SharedPathTable {
 105   Array<u8>* _table;
 106   int _size;
 107 public:
 108   void dumptime_init(ClassLoaderData* loader_data, Thread* THREAD);
 109   void metaspace_pointers_do(MetaspaceClosure* it);
 110 
 111   int size() {
 112     return _size;
 113   }
 114   SharedClassPathEntry* path_at(int index) {
 115     if (index < 0) {
 116       return NULL;


 136   CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
 137   int     _narrow_klass_shift;      // save narrow klass base and shift
 138   address _narrow_klass_base;
 139   char*   _misc_data_patching_start;
 140   char*   _read_only_tables_start;
 141   address _cds_i2i_entry_code_buffers;
 142   size_t  _cds_i2i_entry_code_buffers_size;
 143   size_t  _core_spaces_size;        // number of bytes allocated by the core spaces
 144                                     // (mc, md, ro, rw and od).
 145   MemRegion _heap_reserved;         // reserved region for the entire heap at dump time.
 146   bool _base_archive_is_default;    // indicates if the base archive is the system default one
 147 
 148   // The following fields are all sanity checks for whether this archive
 149   // will function correctly with this JVM and the bootclasspath it's
 150   // invoked with.
 151   char  _jvm_ident[JVM_IDENT_MAX];      // identifier for jvm
 152 
 153   // size of the base archive name including NULL terminator
 154   int _base_archive_name_size;
 155 













 156   // The following is a table of all the class path entries that were used
 157   // during dumping. At run time, we require these files to exist and have the same
 158   // size/modification time, or else the archive will refuse to load.
 159   //
 160   // All of these entries must be JAR files. The dumping process would fail if a non-empty
 161   // directory was specified in the classpaths. If an empty directory was specified
 162   // it is checked by the _paths_misc_info as described above.
 163   //
 164   // FIXME -- if JAR files in the tail of the list were specified but not used during dumping,
 165   // they should be removed from this table, to save space and to avoid spurious
 166   // loading failures during runtime.
 167   SharedPathTable _shared_path_table;
 168 
 169   jshort _app_class_paths_start_index;  // Index of first app classpath entry
 170   jshort _app_module_paths_start_index; // Index of first module path entry
 171   jshort _num_module_paths;             // number of module path entries
 172   jshort _max_used_path_index;          // max path index referenced during CDS dump
 173   bool   _verify_local;                 // BytecodeVerificationLocal setting
 174   bool   _verify_remote;                // BytecodeVerificationRemote setting
 175   bool   _has_platform_or_app_classes;  // Archive contains app classes


 215   // that the compilers don't add any compiler-private data to it.
 216 
 217 public:
 218   struct FileMapHeaderBase : public CHeapObj<mtClass> {
 219     // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual
 220     // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc.
 221     intx _dummy;
 222   };
 223 
 224 
 225   FileMapHeader * _header;
 226 
 227   const char* _full_path;
 228   char* _paths_misc_info;
 229   char* _base_archive_name;
 230 
 231   static FileMapInfo* _current_info;
 232   static FileMapInfo* _dynamic_archive_info;
 233   static bool _heap_pointers_need_patching;
 234   static bool _memory_mapping_failed;
 235   static GrowableArray<const char*>* _non_existent_class_paths;
 236 
 237   static bool get_base_archive_name_from_header(const char* archive_name,
 238                                                 int* size, char** base_archive_name);
 239   static bool check_archive(const char* archive_name, bool is_static);
 240   void restore_shared_path_table();
 241   bool  init_from_file(int fd, bool is_static);
 242   static void metaspace_pointers_do(MetaspaceClosure* it);
 243 
 244   void log_paths(const char* msg, int start_idx, int end_idx);
 245 
 246 public:
 247   FileMapInfo(bool is_static);
 248   ~FileMapInfo();
 249 
 250   int    compute_header_crc()         { return _header->compute_crc(); }
 251   void   set_header_crc(int crc)      { _header->_crc = crc; }
 252   int    space_crc(int i)             { return space_at(i)->_crc; }
 253   void   populate_header(size_t alignment);
 254   bool   validate_header(bool is_static);
 255   void   invalidate();
 256   int    crc()                        { return _header->_crc; }
 257   int    version()                    { return _header->_version; }
 258   size_t alignment()                  { return _header->_alignment; }
 259   CompressedOops::Mode narrow_oop_mode() { return _header->_narrow_oop_mode; }
 260   address narrow_oop_base()    const  { return _header->_narrow_oop_base; }
 261   int     narrow_oop_shift()   const  { return _header->_narrow_oop_shift; }
 262   uintx   max_heap_size()      const  { return _header->_max_heap_size; }
 263   address narrow_klass_base()  const  { return _header->_narrow_klass_base; }
 264   int     narrow_klass_shift() const  { return _header->_narrow_klass_shift; }
 265   struct  FileMapHeader* header()     { return _header; }


 333   bool  is_open() { return _file_open; }
 334   ReservedSpace reserve_shared_memory();
 335 
 336   // JVM/TI RedefineClasses() support:
 337   // Remap the shared readonly space to shared readwrite, private.
 338   bool  remap_shared_readonly_as_readwrite();
 339 
 340   // Errors.
 341   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 342   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 343   static bool memory_mapping_failed() {
 344     CDS_ONLY(return _memory_mapping_failed;)
 345     NOT_CDS(return false;)
 346   }
 347   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 348 
 349   // Stop CDS sharing and unmap CDS regions.
 350   static void stop_sharing_and_unmap(const char* msg);
 351 
 352   static void allocate_shared_path_table();
 353   static int add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS);
 354   static void check_nonempty_dir_in_shared_path_table();
 355   bool validate_shared_path_table();
 356   bool validate_non_existent_class_paths() const;
 357   static void update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
 358   static int num_non_existent_class_paths();
 359   static void record_non_existent_class_path_entry(const char* path);
 360 
 361 #if INCLUDE_JVMTI
 362   static ClassFileStream* open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS);
 363 #endif
 364 
 365   static SharedClassPathEntry* shared_path(int index) {
 366     return _shared_path_table.path_at(index);
 367   }
 368 
 369   static const char* shared_path_name(int index) {
 370     assert(index >= 0, "Sanity");
 371     return shared_path(index)->name();
 372   }
 373 
 374   static int get_number_of_shared_paths() {
 375     return _shared_path_table.size();
 376   }
 377 
 378   char* region_addr(int idx);
 379 


< prev index next >