< prev index next >

src/hotspot/share/memory/filemap.hpp

Print this page




   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_VM_MEMORY_FILEMAP_HPP
  26 #define SHARE_VM_MEMORY_FILEMAP_HPP
  27 
  28 #include "classfile/classLoader.hpp"

  29 #include "memory/metaspaceShared.hpp"
  30 #include "memory/metaspace.hpp"
  31 #include "memory/universe.hpp"
  32 #include "utilities/align.hpp"
  33 
  34 // Layout of the file:
  35 //  header: dump of archive instance plus versioning info, datestamp, etc.
  36 //   [magic # = 0xF00BABA2]
  37 //  ... padding to align on page-boundary
  38 //  read-write space
  39 //  read-only space
  40 //  misc data (block offset table, string table, symbols, dictionary, etc.)
  41 //  tag(666)
  42 
  43 static const int JVM_IDENT_MAX = 256;
  44 
  45 class SharedClassPathEntry {
  46   enum {
  47     modules_image_entry,
  48     jar_entry,


  70   bool is_modules_image()  { return _type == modules_image_entry; }
  71   bool is_jar()            { return _type == jar_entry; }
  72   bool is_signed()         { return _type == signed_jar_entry; }
  73   void set_is_signed()     {
  74     _type = signed_jar_entry;
  75   }
  76   time_t timestamp() const { return _timestamp; }
  77   long   filesize()  const { return _filesize; }
  78   const char* name() const { return _name->data(); }
  79   const char* manifest() const {
  80     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
  81   }
  82   int manifest_size() const {
  83     return (_manifest == NULL) ? 0 : _manifest->length();
  84   }
  85   void set_manifest(Array<u1>* manifest) {
  86     _manifest = manifest;
  87   }
  88 };
  89 
  90 class FileMapInfo : public CHeapObj<mtInternal> {
  91 private:
  92   friend class ManifestStream;
  93   friend class VMStructs;
  94   enum {
  95     _invalid_version = -1,
  96     _current_version = 3
  97   };
  98 
  99   bool  _file_open;
 100   int   _fd;
 101   size_t  _file_offset;
 102 
 103 private:
 104   static Array<u8>*            _shared_path_table;
 105   static int                   _shared_path_table_size;
 106   static size_t                _shared_path_entry_size;
 107   static bool                  _validating_shared_path_table;
 108 
 109   // FileMapHeader describes the shared space data in the file to be
 110   // mapped.  This structure gets written to a file.  It is not a class, so
 111   // that the compilers don't add any compiler-private data to it.
 112 
 113 public:
 114   struct FileMapHeaderBase : public CHeapObj<mtClass> {
 115     // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual
 116     // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc.
 117     intx _dummy;
 118   };
 119   struct FileMapHeader : FileMapHeaderBase {
 120     // Use data() and data_size() to memcopy to/from the FileMapHeader. We need to
 121     // avoid read/writing the C++ vtable pointer.
 122     static size_t data_size() {
 123       return sizeof(FileMapHeader) - sizeof(FileMapInfo::FileMapHeaderBase);
 124     }
 125     char* data() {
 126       return ((char*)this) + sizeof(FileMapHeaderBase);
 127     }
 128 
 129     int    _magic;                    // identify file type.
 130     int    _crc;                      // header crc checksum.
 131     int    _version;                  // (from enum, above.)
 132     size_t _alignment;                // how shared archive should be aligned
 133     int    _obj_alignment;            // value of ObjectAlignmentInBytes
 134     address _narrow_oop_base;         // compressed oop encoding base
 135     int    _narrow_oop_shift;         // compressed oop encoding shift
 136     bool    _compact_strings;         // value of CompactStrings
 137     uintx  _max_heap_size;            // java max heap size during dumping
 138     Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode
 139     int     _narrow_klass_shift;      // save narrow klass base and shift
 140     address _narrow_klass_base;
 141     char*   _misc_data_patching_start;
 142     char*   _read_only_tables_start;
 143     address _cds_i2i_entry_code_buffers;
 144     size_t  _cds_i2i_entry_code_buffers_size;
 145     size_t  _core_spaces_size;        // number of bytes allocated by the core spaces
 146                                       // (mc, md, ro, rw and od).
 147     struct space_info {
 148       int    _crc;           // crc checksum of the current space
 149       size_t _file_offset;   // sizeof(this) rounded to vm page size
 150       union {
 151         char*  _base;        // copy-on-write base address
 152         intx   _offset;      // offset from the compressed oop encoding base, only used
 153                              // by archive heap space
 154       } _addr;
 155       size_t _used;          // for setting space top on read
 156       bool   _read_only;     // read only space?
 157       bool   _allow_exec;    // executable code in space?
 158     } _space[MetaspaceShared::n_regions];
 159 
 160     // The following fields are all sanity checks for whether this archive
 161     // will function correctly with this JVM and the bootclasspath it's
 162     // invoked with.
 163     char  _jvm_ident[JVM_IDENT_MAX];      // identifier for jvm
 164 
 165     // The _paths_misc_info is a variable-size structure that records "miscellaneous"
 166     // information during dumping. It is generated and validated by the
 167     // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for
 168     // detailed description.
 169     //
 170     // The _paths_misc_info data is stored as a byte array in the archive file header,
 171     // immediately after the _header field. This information is used only when
 172     // checking the validity of the archive and is deallocated after the archive is loaded.
 173     //
 174     // Note that the _paths_misc_info does NOT include information for JAR files
 175     // that existed during dump time. Their information is stored in _shared_path_table.
 176     int _paths_misc_info_size;
 177 
 178     // The following is a table of all the class path entries that were used


 192 
 193     jshort _app_class_paths_start_index;  // Index of first app classpath entry
 194     jshort _app_module_paths_start_index; // Index of first module path entry
 195     jshort _max_used_path_index;          // max path index referenced during CDS dump
 196     bool   _verify_local;                 // BytecodeVerificationLocal setting
 197     bool   _verify_remote;                // BytecodeVerificationRemote setting
 198     bool   _has_platform_or_app_classes;  // Archive contains app classes
 199 
 200     void set_has_platform_or_app_classes(bool v) {
 201       _has_platform_or_app_classes = v;
 202     }
 203     bool has_platform_or_app_classes() { return _has_platform_or_app_classes; }
 204     jshort max_used_path_index()       { return _max_used_path_index; }
 205     jshort app_module_paths_start_index() { return _app_module_paths_start_index; }
 206 
 207     char* region_addr(int idx);
 208 
 209     bool validate();
 210     void populate(FileMapInfo* info, size_t alignment);
 211     int compute_crc();




























 212   };
 213 

 214   FileMapHeader * _header;
 215 
 216   const char* _full_path;
 217   char* _paths_misc_info;
 218 
 219   static FileMapInfo* _current_info;
 220 
 221   bool  init_from_file(int fd);
 222   void  align_file_position();
 223   bool  validate_header_impl();
 224   static void metaspace_pointers_do(MetaspaceClosure* it);
 225 
 226 public:
 227   FileMapInfo();
 228   ~FileMapInfo();
 229 
 230   static int current_version()        { return _current_version; }
 231   int    compute_header_crc()         { return _header->compute_crc(); }
 232   void   set_header_crc(int crc)      { _header->_crc = crc; }
 233   void   populate_header(size_t alignment);
 234   bool   validate_header();
 235   void   invalidate();
 236   int    version()                    { return _header->_version; }
 237   size_t alignment()                  { return _header->_alignment; }
 238   Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; }
 239   address narrow_oop_base()    const  { return _header->_narrow_oop_base; }
 240   int     narrow_oop_shift()   const  { return _header->_narrow_oop_shift; }
 241   uintx   max_heap_size()      const  { return _header->_max_heap_size; }
 242   address narrow_klass_base()  const  { return _header->_narrow_klass_base; }
 243   int     narrow_klass_shift() const  { return _header->_narrow_klass_shift; }
 244   struct  FileMapHeader* header()     { return _header; }
 245   char*   misc_data_patching_start()          { return _header->_misc_data_patching_start; }
 246   void set_misc_data_patching_start(char* p)  { _header->_misc_data_patching_start = p; }
 247   char* read_only_tables_start()              { return _header->_read_only_tables_start; }
 248   void set_read_only_tables_start(char* p)    { _header->_read_only_tables_start = p; }
 249 
 250   address cds_i2i_entry_code_buffers() {


 261   }
 262   void set_core_spaces_size(size_t s)    {  _header->_core_spaces_size = s; }
 263   size_t core_spaces_size()              { return _header->_core_spaces_size; }
 264 
 265   static FileMapInfo* current_info() {
 266     CDS_ONLY(return _current_info;)
 267     NOT_CDS(return NULL;)
 268   }
 269 
 270   static void assert_mark(bool check);
 271 
 272   // File manipulation.
 273   bool  initialize() NOT_CDS_RETURN_(false);
 274   bool  open_for_read();
 275   void  open_for_write();
 276   void  write_header();
 277   void  write_region(int region, char* base, size_t size,
 278                      bool read_only, bool allow_exec);
 279   size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
 280                                     int first_region_id, int max_num_regions);
 281   void  write_bytes(const void* buffer, int count);
 282   void  write_bytes_aligned(const void* buffer, int count);
 283   char* map_region(int i, char** top_ret);
 284   void  map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 285   void  fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 286   void  unmap_region(int i);
 287   bool  verify_region_checksum(int i);
 288   void  close();
 289   bool  is_open() { return _file_open; }
 290   ReservedSpace reserve_shared_memory();
 291 
 292   // JVM/TI RedefineClasses() support:
 293   // Remap the shared readonly space to shared readwrite, private.
 294   bool  remap_shared_readonly_as_readwrite();
 295 
 296   // Errors.
 297   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 298   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 299 
 300   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 301   void print_shared_spaces() NOT_CDS_RETURN;
 302 


 315     assert(index < _shared_path_table_size, "sanity");
 316     char* p = (char*)_shared_path_table->data();
 317     p += _shared_path_entry_size * index;
 318     return (SharedClassPathEntry*)p;
 319   }
 320 
 321   static const char* shared_path_name(int index) {
 322     assert(index >= 0, "Sanity");
 323     return shared_path(index)->name();
 324   }
 325 
 326   static int get_number_of_shared_paths() {
 327     return _shared_path_table_size;
 328   }
 329 
 330  private:
 331   bool  map_heap_data(MemRegion **heap_mem, int first, int max, int* num,
 332                       bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false);
 333   bool  verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false);
 334   void  dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN;





 335 };
 336 
 337 #endif // SHARE_VM_MEMORY_FILEMAP_HPP


   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_VM_MEMORY_FILEMAP_HPP
  26 #define SHARE_VM_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 "memory/universe.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,


  71   bool is_modules_image()  { return _type == modules_image_entry; }
  72   bool is_jar()            { return _type == jar_entry; }
  73   bool is_signed()         { return _type == signed_jar_entry; }
  74   void set_is_signed()     {
  75     _type = signed_jar_entry;
  76   }
  77   time_t timestamp() const { return _timestamp; }
  78   long   filesize()  const { return _filesize; }
  79   const char* name() const { return _name->data(); }
  80   const char* manifest() const {
  81     return (_manifest == NULL) ? NULL : (const char*)_manifest->data();
  82   }
  83   int manifest_size() const {
  84     return (_manifest == NULL) ? 0 : _manifest->length();
  85   }
  86   void set_manifest(Array<u1>* manifest) {
  87     _manifest = manifest;
  88   }
  89 };
  90 
  91 struct FileMapHeader : public CDSFileMapHeaderBase {









































  92   size_t _alignment;                // how shared archive should be aligned
  93   int    _obj_alignment;            // value of ObjectAlignmentInBytes
  94   address _narrow_oop_base;         // compressed oop encoding base
  95   int    _narrow_oop_shift;         // compressed oop encoding shift
  96   bool    _compact_strings;         // value of CompactStrings
  97   uintx  _max_heap_size;            // java max heap size during dumping
  98   Universe::NARROW_OOP_MODE _narrow_oop_mode; // compressed oop encoding mode
  99   int     _narrow_klass_shift;      // save narrow klass base and shift
 100   address _narrow_klass_base;
 101   char*   _misc_data_patching_start;
 102   char*   _read_only_tables_start;
 103   address _cds_i2i_entry_code_buffers;
 104   size_t  _cds_i2i_entry_code_buffers_size;
 105   size_t  _core_spaces_size;        // number of bytes allocated by the core spaces
 106                                     // (mc, md, ro, rw and od).












 107 
 108   // The following fields are all sanity checks for whether this archive
 109   // will function correctly with this JVM and the bootclasspath it's
 110   // invoked with.
 111   char  _jvm_ident[JVM_IDENT_MAX];      // identifier for jvm
 112 
 113   // The _paths_misc_info is a variable-size structure that records "miscellaneous"
 114   // information during dumping. It is generated and validated by the
 115   // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp for
 116   // detailed description.
 117   //
 118   // The _paths_misc_info data is stored as a byte array in the archive file header,
 119   // immediately after the _header field. This information is used only when
 120   // checking the validity of the archive and is deallocated after the archive is loaded.
 121   //
 122   // Note that the _paths_misc_info does NOT include information for JAR files
 123   // that existed during dump time. Their information is stored in _shared_path_table.
 124   int _paths_misc_info_size;
 125 
 126   // The following is a table of all the class path entries that were used


 140 
 141   jshort _app_class_paths_start_index;  // Index of first app classpath entry
 142   jshort _app_module_paths_start_index; // Index of first module path entry
 143   jshort _max_used_path_index;          // max path index referenced during CDS dump
 144   bool   _verify_local;                 // BytecodeVerificationLocal setting
 145   bool   _verify_remote;                // BytecodeVerificationRemote setting
 146   bool   _has_platform_or_app_classes;  // Archive contains app classes
 147 
 148   void set_has_platform_or_app_classes(bool v) {
 149     _has_platform_or_app_classes = v;
 150   }
 151   bool has_platform_or_app_classes() { return _has_platform_or_app_classes; }
 152   jshort max_used_path_index()       { return _max_used_path_index; }
 153   jshort app_module_paths_start_index() { return _app_module_paths_start_index; }
 154 
 155   char* region_addr(int idx);
 156 
 157   bool validate();
 158   void populate(FileMapInfo* info, size_t alignment);
 159   int compute_crc();
 160 };
 161 
 162 
 163 class FileMapInfo : public CHeapObj<mtInternal> {
 164 private:
 165   friend class ManifestStream;
 166   friend class VMStructs;
 167   friend struct FileMapHeader;
 168 
 169   bool    _file_open;
 170   int     _fd;
 171   size_t  _file_offset;
 172 
 173 private:
 174   static Array<u8>*            _shared_path_table;
 175   static int                   _shared_path_table_size;
 176   static size_t                _shared_path_entry_size;
 177   static bool                  _validating_shared_path_table;
 178 
 179   // FileMapHeader describes the shared space data in the file to be
 180   // mapped.  This structure gets written to a file.  It is not a class, so
 181   // that the compilers don't add any compiler-private data to it.
 182 
 183 public:
 184   struct FileMapHeaderBase : public CHeapObj<mtClass> {
 185     // Need to put something here. Otherwise, in product build, because CHeapObj has no virtual
 186     // methods, we would get sizeof(FileMapHeaderBase) == 1 with gcc.
 187     intx _dummy;
 188   };
 189 
 190 
 191   FileMapHeader * _header;
 192 
 193   const char* _full_path;
 194   char* _paths_misc_info;
 195 
 196   static FileMapInfo* _current_info;
 197 
 198   bool  init_from_file(int fd);
 199   void  align_file_position();
 200   bool  validate_header_impl();
 201   static void metaspace_pointers_do(MetaspaceClosure* it);
 202 
 203 public:
 204   FileMapInfo();
 205   ~FileMapInfo();
 206 

 207   int    compute_header_crc()         { return _header->compute_crc(); }
 208   void   set_header_crc(int crc)      { _header->_crc = crc; }
 209   void   populate_header(size_t alignment);
 210   bool   validate_header();
 211   void   invalidate();
 212   int    version()                    { return _header->_version; }
 213   size_t alignment()                  { return _header->_alignment; }
 214   Universe::NARROW_OOP_MODE narrow_oop_mode() { return _header->_narrow_oop_mode; }
 215   address narrow_oop_base()    const  { return _header->_narrow_oop_base; }
 216   int     narrow_oop_shift()   const  { return _header->_narrow_oop_shift; }
 217   uintx   max_heap_size()      const  { return _header->_max_heap_size; }
 218   address narrow_klass_base()  const  { return _header->_narrow_klass_base; }
 219   int     narrow_klass_shift() const  { return _header->_narrow_klass_shift; }
 220   struct  FileMapHeader* header()     { return _header; }
 221   char*   misc_data_patching_start()          { return _header->_misc_data_patching_start; }
 222   void set_misc_data_patching_start(char* p)  { _header->_misc_data_patching_start = p; }
 223   char* read_only_tables_start()              { return _header->_read_only_tables_start; }
 224   void set_read_only_tables_start(char* p)    { _header->_read_only_tables_start = p; }
 225 
 226   address cds_i2i_entry_code_buffers() {


 237   }
 238   void set_core_spaces_size(size_t s)    {  _header->_core_spaces_size = s; }
 239   size_t core_spaces_size()              { return _header->_core_spaces_size; }
 240 
 241   static FileMapInfo* current_info() {
 242     CDS_ONLY(return _current_info;)
 243     NOT_CDS(return NULL;)
 244   }
 245 
 246   static void assert_mark(bool check);
 247 
 248   // File manipulation.
 249   bool  initialize() NOT_CDS_RETURN_(false);
 250   bool  open_for_read();
 251   void  open_for_write();
 252   void  write_header();
 253   void  write_region(int region, char* base, size_t size,
 254                      bool read_only, bool allow_exec);
 255   size_t write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
 256                                     int first_region_id, int max_num_regions);
 257   void  write_bytes(const void* buffer, size_t count);
 258   void  write_bytes_aligned(const void* buffer, size_t count);
 259   char* map_region(int i, char** top_ret);
 260   void  map_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 261   void  fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 262   void  unmap_region(int i);
 263   bool  verify_region_checksum(int i);
 264   void  close();
 265   bool  is_open() { return _file_open; }
 266   ReservedSpace reserve_shared_memory();
 267 
 268   // JVM/TI RedefineClasses() support:
 269   // Remap the shared readonly space to shared readwrite, private.
 270   bool  remap_shared_readonly_as_readwrite();
 271 
 272   // Errors.
 273   static void fail_stop(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 274   static void fail_continue(const char *msg, ...) ATTRIBUTE_PRINTF(1, 2);
 275 
 276   bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 277   void print_shared_spaces() NOT_CDS_RETURN;
 278 


 291     assert(index < _shared_path_table_size, "sanity");
 292     char* p = (char*)_shared_path_table->data();
 293     p += _shared_path_entry_size * index;
 294     return (SharedClassPathEntry*)p;
 295   }
 296 
 297   static const char* shared_path_name(int index) {
 298     assert(index >= 0, "Sanity");
 299     return shared_path(index)->name();
 300   }
 301 
 302   static int get_number_of_shared_paths() {
 303     return _shared_path_table_size;
 304   }
 305 
 306  private:
 307   bool  map_heap_data(MemRegion **heap_mem, int first, int max, int* num,
 308                       bool is_open = false) NOT_CDS_JAVA_HEAP_RETURN_(false);
 309   bool  verify_mapped_heap_regions(int first, int num) NOT_CDS_JAVA_HEAP_RETURN_(false);
 310   void  dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) NOT_CDS_JAVA_HEAP_RETURN;
 311 
 312   CDSFileMapRegion* space_at(int i) {
 313     assert(i >= 0 && i < NUM_CDS_REGIONS, "invalid region");
 314     return &_header->_space[i];
 315   }
 316 };
 317 
 318 #endif // SHARE_VM_MEMORY_FILEMAP_HPP
< prev index next >