src/share/vm/memory/filemap.hpp

changeset 7089
6e0cb14ce59b
parent 5863
85c1ca43713f
child 7241
8cb56c8cb30d
     1.1 --- a/src/share/vm/memory/filemap.hpp	Fri Aug 22 12:03:49 2014 -0700
     1.2 +++ b/src/share/vm/memory/filemap.hpp	Thu Aug 21 13:57:51 2014 -0700
     1.3 @@ -37,30 +37,55 @@
     1.4  //  misc data (block offset table, string table, symbols, dictionary, etc.)
     1.5  //  tag(666)
     1.6  
     1.7 -static const int JVM_SHARED_JARS_MAX = 128;
     1.8 -static const int JVM_SPACENAME_MAX = 128;
     1.9  static const int JVM_IDENT_MAX = 256;
    1.10 -static const int JVM_ARCH_MAX = 12;
    1.11 -
    1.12  
    1.13  class Metaspace;
    1.14  
    1.15 +class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC {
    1.16 +public:
    1.17 +  const char *_name;
    1.18 +  time_t _timestamp;          // jar timestamp,  0 if is directory
    1.19 +  long   _filesize;           // jar file size, -1 if is directory
    1.20 +  bool is_dir() {
    1.21 +    return _filesize == -1;
    1.22 +  }
    1.23 +};
    1.24 +
    1.25  class FileMapInfo : public CHeapObj<mtInternal> {
    1.26  private:
    1.27 +  friend class ManifestStream;
    1.28    enum {
    1.29      _invalid_version = -1,
    1.30 -    _current_version = 1
    1.31 +    _current_version = 2
    1.32    };
    1.33  
    1.34    bool  _file_open;
    1.35    int   _fd;
    1.36    long  _file_offset;
    1.37  
    1.38 +private:
    1.39 +  static SharedClassPathEntry* _classpath_entry_table;
    1.40 +  static int                   _classpath_entry_table_size;
    1.41 +  static size_t                _classpath_entry_size;
    1.42 +  static bool                  _validating_classpath_entry_table;
    1.43 +
    1.44    // FileMapHeader describes the shared space data in the file to be
    1.45    // mapped.  This structure gets written to a file.  It is not a class, so
    1.46    // that the compilers don't add any compiler-private data to it.
    1.47  
    1.48 -  struct FileMapHeader {
    1.49 +public:
    1.50 +  struct FileMapHeaderBase : public CHeapObj<mtClass> {
    1.51 +    virtual bool validate() = 0;
    1.52 +    virtual void populate(FileMapInfo* info, size_t alignment) = 0;
    1.53 +  };
    1.54 +  struct FileMapHeader : FileMapHeaderBase {
    1.55 +    // Use data() and data_size() to memcopy to/from the FileMapHeader. We need to
    1.56 +    // avoid read/writing the C++ vtable pointer.
    1.57 +    static size_t data_size();
    1.58 +    char* data() {
    1.59 +      return ((char*)this) + sizeof(FileMapHeaderBase);
    1.60 +    }
    1.61 +
    1.62      int    _magic;                    // identify file type.
    1.63      int    _version;                  // (from enum, above.)
    1.64      size_t _alignment;                // how shared archive should be aligned
    1.65 @@ -78,44 +103,64 @@
    1.66      // The following fields are all sanity checks for whether this archive
    1.67      // will function correctly with this JVM and the bootclasspath it's
    1.68      // invoked with.
    1.69 -    char  _arch[JVM_ARCH_MAX];            // architecture
    1.70      char  _jvm_ident[JVM_IDENT_MAX];      // identifier for jvm
    1.71 -    int   _num_jars;              // Number of jars in bootclasspath
    1.72  
    1.73 -    // Per jar file data:  timestamp, size.
    1.74 +    // The _paths_misc_info is a variable-size structure that records "miscellaneous"
    1.75 +    // information during dumping. It is generated and validated by the
    1.76 +    // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp and sharedClassUtil.hpp for
    1.77 +    // detailed description.
    1.78 +    //
    1.79 +    // The _paths_misc_info data is stored as a byte array in the archive file header,
    1.80 +    // immediately after the _header field. This information is used only when
    1.81 +    // checking the validity of the archive and is deallocated after the archive is loaded.
    1.82 +    //
    1.83 +    // Note that the _paths_misc_info does NOT include information for JAR files
    1.84 +    // that existed during dump time. Their information is stored in _classpath_entry_table.
    1.85 +    int _paths_misc_info_size;
    1.86  
    1.87 -    struct {
    1.88 -      time_t _timestamp;          // jar timestamp.
    1.89 -      long   _filesize;           // jar file size.
    1.90 -    } _jar[JVM_SHARED_JARS_MAX];
    1.91 -  } _header;
    1.92 +    // The following is a table of all the class path entries that were used
    1.93 +    // during dumping. At run time, we require these files to exist and have the same
    1.94 +    // size/modification time, or else the archive will refuse to load.
    1.95 +    //
    1.96 +    // All of these entries must be JAR files. The dumping process would fail if a non-empty
    1.97 +    // directory was specified in the classpaths. If an empty directory was specified
    1.98 +    // it is checked by the _paths_misc_info as described above.
    1.99 +    //
   1.100 +    // FIXME -- if JAR files in the tail of the list were specified but not used during dumping,
   1.101 +    // they should be removed from this table, to save space and to avoid spurious
   1.102 +    // loading failures during runtime.
   1.103 +    int _classpath_entry_table_size;
   1.104 +    size_t _classpath_entry_size;
   1.105 +    SharedClassPathEntry* _classpath_entry_table;
   1.106 +
   1.107 +    virtual bool validate();
   1.108 +    virtual void populate(FileMapInfo* info, size_t alignment);
   1.109 +  };
   1.110 +
   1.111 +  FileMapHeader * _header;
   1.112 +
   1.113    const char* _full_path;
   1.114 +  char* _paths_misc_info;
   1.115  
   1.116    static FileMapInfo* _current_info;
   1.117  
   1.118    bool  init_from_file(int fd);
   1.119    void  align_file_position();
   1.120 +  bool  validate_header_impl();
   1.121  
   1.122  public:
   1.123 -  FileMapInfo() {
   1.124 -    _file_offset = 0;
   1.125 -    _file_open = false;
   1.126 -    _header._version = _invalid_version;
   1.127 -  }
   1.128 +  FileMapInfo();
   1.129 +  ~FileMapInfo();
   1.130  
   1.131    static int current_version()        { return _current_version; }
   1.132    void   populate_header(size_t alignment);
   1.133 -  bool   validate();
   1.134 +  bool   validate_header();
   1.135    void   invalidate();
   1.136 -  int    version()                    { return _header._version; }
   1.137 -  size_t alignment()                  { return _header._alignment; }
   1.138 -  size_t space_capacity(int i)        { return _header._space[i]._capacity; }
   1.139 -  char*  region_base(int i)           { return _header._space[i]._base; }
   1.140 -  struct FileMapHeader* header()      { return &_header; }
   1.141 -
   1.142 -  static void set_current_info(FileMapInfo* info) {
   1.143 -    CDS_ONLY(_current_info = info;)
   1.144 -  }
   1.145 +  int    version()                    { return _header->_version; }
   1.146 +  size_t alignment()                  { return _header->_alignment; }
   1.147 +  size_t space_capacity(int i)        { return _header->_space[i]._capacity; }
   1.148 +  char*  region_base(int i)           { return _header->_space[i]._base; }
   1.149 +  struct FileMapHeader* header()      { return _header; }
   1.150  
   1.151    static FileMapInfo* current_info() {
   1.152      CDS_ONLY(return _current_info;)
   1.153 @@ -146,7 +191,7 @@
   1.154  
   1.155    // Errors.
   1.156    static void fail_stop(const char *msg, ...);
   1.157 -  void fail_continue(const char *msg, ...);
   1.158 +  static void fail_continue(const char *msg, ...);
   1.159  
   1.160    // Return true if given address is in the mapped shared space.
   1.161    bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
   1.162 @@ -160,6 +205,22 @@
   1.163  
   1.164    // Stop CDS sharing and unmap CDS regions.
   1.165    static void stop_sharing_and_unmap(const char* msg);
   1.166 +
   1.167 +  static void allocate_classpath_entry_table();
   1.168 +  bool validate_classpath_entry_table();
   1.169 +
   1.170 +  static SharedClassPathEntry* shared_classpath(int index) {
   1.171 +    char* p = (char*)_classpath_entry_table;
   1.172 +    p += _classpath_entry_size * index;
   1.173 +    return (SharedClassPathEntry*)p;
   1.174 +  }
   1.175 +  static const char* shared_classpath_name(int index) {
   1.176 +    return shared_classpath(index)->_name;
   1.177 +  }
   1.178 +
   1.179 +  static int get_number_of_share_classpaths() {
   1.180 +    return _classpath_entry_table_size;
   1.181 +  }
   1.182  };
   1.183  
   1.184  #endif // SHARE_VM_MEMORY_FILEMAP_HPP

mercurial