src/share/vm/memory/filemap.hpp

Mon, 15 Sep 2014 16:39:00 -0400

author
jiangli
date
Mon, 15 Sep 2014 16:39:00 -0400
changeset 7241
8cb56c8cb30d
parent 7089
6e0cb14ce59b
parent 6868
ca6d25be853b
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

Merge

duke@435 1 /*
hseigel@5528 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_MEMORY_FILEMAP_HPP
stefank@2314 26 #define SHARE_VM_MEMORY_FILEMAP_HPP
stefank@2314 27
coleenp@4037 28 #include "memory/metaspaceShared.hpp"
stefank@5863 29 #include "memory/metaspace.hpp"
stefank@2314 30
duke@435 31 // Layout of the file:
duke@435 32 // header: dump of archive instance plus versioning info, datestamp, etc.
duke@435 33 // [magic # = 0xF00BABA2]
duke@435 34 // ... padding to align on page-boundary
duke@435 35 // read-write space from CompactingPermGenGen
duke@435 36 // read-only space from CompactingPermGenGen
duke@435 37 // misc data (block offset table, string table, symbols, dictionary, etc.)
duke@435 38 // tag(666)
duke@435 39
duke@435 40 static const int JVM_IDENT_MAX = 256;
duke@435 41
coleenp@4037 42 class Metaspace;
duke@435 43
iklam@7089 44 class SharedClassPathEntry VALUE_OBJ_CLASS_SPEC {
iklam@7089 45 public:
iklam@7089 46 const char *_name;
iklam@7089 47 time_t _timestamp; // jar timestamp, 0 if is directory
iklam@7089 48 long _filesize; // jar file size, -1 if is directory
iklam@7089 49 bool is_dir() {
iklam@7089 50 return _filesize == -1;
iklam@7089 51 }
iklam@7089 52 };
iklam@7089 53
zgu@3900 54 class FileMapInfo : public CHeapObj<mtInternal> {
duke@435 55 private:
iklam@7089 56 friend class ManifestStream;
duke@435 57 enum {
duke@435 58 _invalid_version = -1,
iklam@7089 59 _current_version = 2
duke@435 60 };
duke@435 61
duke@435 62 bool _file_open;
duke@435 63 int _fd;
jiangli@6868 64 size_t _file_offset;
duke@435 65
iklam@7089 66 private:
iklam@7089 67 static SharedClassPathEntry* _classpath_entry_table;
iklam@7089 68 static int _classpath_entry_table_size;
iklam@7089 69 static size_t _classpath_entry_size;
iklam@7089 70 static bool _validating_classpath_entry_table;
iklam@7089 71
duke@435 72 // FileMapHeader describes the shared space data in the file to be
duke@435 73 // mapped. This structure gets written to a file. It is not a class, so
duke@435 74 // that the compilers don't add any compiler-private data to it.
duke@435 75
iklam@7089 76 public:
iklam@7089 77 struct FileMapHeaderBase : public CHeapObj<mtClass> {
iklam@7089 78 virtual bool validate() = 0;
iklam@7089 79 virtual void populate(FileMapInfo* info, size_t alignment) = 0;
iklam@7089 80 };
iklam@7089 81 struct FileMapHeader : FileMapHeaderBase {
iklam@7089 82 // Use data() and data_size() to memcopy to/from the FileMapHeader. We need to
iklam@7089 83 // avoid read/writing the C++ vtable pointer.
iklam@7089 84 static size_t data_size();
iklam@7089 85 char* data() {
iklam@7089 86 return ((char*)this) + sizeof(FileMapHeaderBase);
iklam@7089 87 }
iklam@7089 88
duke@435 89 int _magic; // identify file type.
jiangli@6868 90 int _crc; // header crc checksum.
duke@435 91 int _version; // (from enum, above.)
duke@435 92 size_t _alignment; // how shared archive should be aligned
hseigel@4397 93 int _obj_alignment; // value of ObjectAlignmentInBytes
duke@435 94
duke@435 95 struct space_info {
jiangli@6868 96 int _crc; // crc checksum of the current space
jiangli@6868 97 size_t _file_offset; // sizeof(this) rounded to vm page size
duke@435 98 char* _base; // copy-on-write base address
duke@435 99 size_t _capacity; // for validity checking
duke@435 100 size_t _used; // for setting space top on read
duke@435 101 bool _read_only; // read only space?
duke@435 102 bool _allow_exec; // executable code in space?
coleenp@4037 103 } _space[MetaspaceShared::n_regions];
duke@435 104
duke@435 105 // The following fields are all sanity checks for whether this archive
duke@435 106 // will function correctly with this JVM and the bootclasspath it's
duke@435 107 // invoked with.
duke@435 108 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm
duke@435 109
iklam@7089 110 // The _paths_misc_info is a variable-size structure that records "miscellaneous"
iklam@7089 111 // information during dumping. It is generated and validated by the
iklam@7089 112 // SharedPathsMiscInfo class. See SharedPathsMiscInfo.hpp and sharedClassUtil.hpp for
iklam@7089 113 // detailed description.
iklam@7089 114 //
iklam@7089 115 // The _paths_misc_info data is stored as a byte array in the archive file header,
iklam@7089 116 // immediately after the _header field. This information is used only when
iklam@7089 117 // checking the validity of the archive and is deallocated after the archive is loaded.
iklam@7089 118 //
iklam@7089 119 // Note that the _paths_misc_info does NOT include information for JAR files
iklam@7089 120 // that existed during dump time. Their information is stored in _classpath_entry_table.
iklam@7089 121 int _paths_misc_info_size;
duke@435 122
iklam@7089 123 // The following is a table of all the class path entries that were used
iklam@7089 124 // during dumping. At run time, we require these files to exist and have the same
iklam@7089 125 // size/modification time, or else the archive will refuse to load.
iklam@7089 126 //
iklam@7089 127 // All of these entries must be JAR files. The dumping process would fail if a non-empty
iklam@7089 128 // directory was specified in the classpaths. If an empty directory was specified
iklam@7089 129 // it is checked by the _paths_misc_info as described above.
iklam@7089 130 //
iklam@7089 131 // FIXME -- if JAR files in the tail of the list were specified but not used during dumping,
iklam@7089 132 // they should be removed from this table, to save space and to avoid spurious
iklam@7089 133 // loading failures during runtime.
iklam@7089 134 int _classpath_entry_table_size;
iklam@7089 135 size_t _classpath_entry_size;
iklam@7089 136 SharedClassPathEntry* _classpath_entry_table;
iklam@7089 137
iklam@7089 138 virtual bool validate();
iklam@7089 139 virtual void populate(FileMapInfo* info, size_t alignment);
jiangli@7241 140 int compute_crc();
iklam@7089 141 };
iklam@7089 142
iklam@7089 143 FileMapHeader * _header;
iklam@7089 144
duke@435 145 const char* _full_path;
iklam@7089 146 char* _paths_misc_info;
duke@435 147
duke@435 148 static FileMapInfo* _current_info;
duke@435 149
duke@435 150 bool init_from_file(int fd);
duke@435 151 void align_file_position();
iklam@7089 152 bool validate_header_impl();
duke@435 153
duke@435 154 public:
iklam@7089 155 FileMapInfo();
iklam@7089 156 ~FileMapInfo();
duke@435 157
duke@435 158 static int current_version() { return _current_version; }
jiangli@6868 159 int compute_header_crc();
jiangli@7241 160 void set_header_crc(int crc) { _header->_crc = crc; }
duke@435 161 void populate_header(size_t alignment);
iklam@7089 162 bool validate_header();
duke@435 163 void invalidate();
iklam@7089 164 int version() { return _header->_version; }
iklam@7089 165 size_t alignment() { return _header->_alignment; }
iklam@7089 166 size_t space_capacity(int i) { return _header->_space[i]._capacity; }
iklam@7089 167 char* region_base(int i) { return _header->_space[i]._base; }
iklam@7089 168 struct FileMapHeader* header() { return _header; }
jprovino@4720 169
jprovino@4720 170 static FileMapInfo* current_info() {
jprovino@4720 171 CDS_ONLY(return _current_info;)
jprovino@4720 172 NOT_CDS(return NULL;)
jprovino@4720 173 }
jprovino@4720 174
duke@435 175 static void assert_mark(bool check);
duke@435 176
duke@435 177 // File manipulation.
jprovino@4720 178 bool initialize() NOT_CDS_RETURN_(false);
duke@435 179 bool open_for_read();
duke@435 180 void open_for_write();
duke@435 181 void write_header();
coleenp@4037 182 void write_space(int i, Metaspace* space, bool read_only);
duke@435 183 void write_region(int region, char* base, size_t size,
duke@435 184 size_t capacity, bool read_only, bool allow_exec);
duke@435 185 void write_bytes(const void* buffer, int count);
duke@435 186 void write_bytes_aligned(const void* buffer, int count);
coleenp@4037 187 char* map_region(int i);
duke@435 188 void unmap_region(int i);
jiangli@6868 189 bool verify_region_checksum(int i);
duke@435 190 void close();
duke@435 191 bool is_open() { return _file_open; }
coleenp@4037 192 ReservedSpace reserve_shared_memory();
duke@435 193
duke@435 194 // JVM/TI RedefineClasses() support:
duke@435 195 // Remap the shared readonly space to shared readwrite, private.
duke@435 196 bool remap_shared_readonly_as_readwrite();
duke@435 197
duke@435 198 // Errors.
duke@435 199 static void fail_stop(const char *msg, ...);
iklam@7089 200 static void fail_continue(const char *msg, ...);
duke@435 201
duke@435 202 // Return true if given address is in the mapped shared space.
jprovino@4720 203 bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
iklam@5329 204 void print_shared_spaces() NOT_CDS_RETURN;
hseigel@5528 205
hseigel@5528 206 static size_t shared_spaces_size() {
hseigel@5528 207 return align_size_up(SharedReadOnlySize + SharedReadWriteSize +
hseigel@5528 208 SharedMiscDataSize + SharedMiscCodeSize,
hseigel@5528 209 os::vm_allocation_granularity());
hseigel@5528 210 }
hseigel@5528 211
hseigel@5528 212 // Stop CDS sharing and unmap CDS regions.
hseigel@5528 213 static void stop_sharing_and_unmap(const char* msg);
iklam@7089 214
iklam@7089 215 static void allocate_classpath_entry_table();
iklam@7089 216 bool validate_classpath_entry_table();
iklam@7089 217
iklam@7089 218 static SharedClassPathEntry* shared_classpath(int index) {
iklam@7089 219 char* p = (char*)_classpath_entry_table;
iklam@7089 220 p += _classpath_entry_size * index;
iklam@7089 221 return (SharedClassPathEntry*)p;
iklam@7089 222 }
iklam@7089 223 static const char* shared_classpath_name(int index) {
iklam@7089 224 return shared_classpath(index)->_name;
iklam@7089 225 }
iklam@7089 226
iklam@7089 227 static int get_number_of_share_classpaths() {
iklam@7089 228 return _classpath_entry_table_size;
iklam@7089 229 }
duke@435 230 };
stefank@2314 231
stefank@2314 232 #endif // SHARE_VM_MEMORY_FILEMAP_HPP

mercurial