src/share/vm/memory/filemap.hpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_MEMORY_FILEMAP_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_FILEMAP_HPP
aoqi@0 27
aoqi@0 28 #include "memory/metaspaceShared.hpp"
aoqi@0 29 #include "memory/metaspace.hpp"
aoqi@0 30
aoqi@0 31 // Layout of the file:
aoqi@0 32 // header: dump of archive instance plus versioning info, datestamp, etc.
aoqi@0 33 // [magic # = 0xF00BABA2]
aoqi@0 34 // ... padding to align on page-boundary
aoqi@0 35 // read-write space from CompactingPermGenGen
aoqi@0 36 // read-only space from CompactingPermGenGen
aoqi@0 37 // misc data (block offset table, string table, symbols, dictionary, etc.)
aoqi@0 38 // tag(666)
aoqi@0 39
aoqi@0 40 static const int JVM_IDENT_MAX = 256;
aoqi@0 41
aoqi@0 42 class Metaspace;
aoqi@0 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
aoqi@0 54 class FileMapInfo : public CHeapObj<mtInternal> {
aoqi@0 55 private:
iklam@7089 56 friend class ManifestStream;
aoqi@0 57 enum {
aoqi@0 58 _invalid_version = -1,
iklam@7089 59 _current_version = 2
aoqi@0 60 };
aoqi@0 61
aoqi@0 62 bool _file_open;
aoqi@0 63 int _fd;
aoqi@0 64 size_t _file_offset;
aoqi@0 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
aoqi@0 72 // FileMapHeader describes the shared space data in the file to be
aoqi@0 73 // mapped. This structure gets written to a file. It is not a class, so
aoqi@0 74 // that the compilers don't add any compiler-private data to it.
aoqi@0 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
aoqi@0 89 int _magic; // identify file type.
aoqi@0 90 int _crc; // header crc checksum.
aoqi@0 91 int _version; // (from enum, above.)
aoqi@0 92 size_t _alignment; // how shared archive should be aligned
aoqi@0 93 int _obj_alignment; // value of ObjectAlignmentInBytes
aoqi@0 94
aoqi@0 95 struct space_info {
aoqi@0 96 int _crc; // crc checksum of the current space
aoqi@0 97 size_t _file_offset; // sizeof(this) rounded to vm page size
aoqi@0 98 char* _base; // copy-on-write base address
aoqi@0 99 size_t _capacity; // for validity checking
aoqi@0 100 size_t _used; // for setting space top on read
aoqi@0 101 bool _read_only; // read only space?
aoqi@0 102 bool _allow_exec; // executable code in space?
aoqi@0 103 } _space[MetaspaceShared::n_regions];
aoqi@0 104
aoqi@0 105 // The following fields are all sanity checks for whether this archive
aoqi@0 106 // will function correctly with this JVM and the bootclasspath it's
aoqi@0 107 // invoked with.
aoqi@0 108 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm
aoqi@0 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;
aoqi@0 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
aoqi@0 145 const char* _full_path;
iklam@7089 146 char* _paths_misc_info;
aoqi@0 147
aoqi@0 148 static FileMapInfo* _current_info;
aoqi@0 149
aoqi@0 150 bool init_from_file(int fd);
aoqi@0 151 void align_file_position();
iklam@7089 152 bool validate_header_impl();
aoqi@0 153
aoqi@0 154 public:
iklam@7089 155 FileMapInfo();
iklam@7089 156 ~FileMapInfo();
aoqi@0 157
aoqi@0 158 static int current_version() { return _current_version; }
aoqi@0 159 int compute_header_crc();
jiangli@7241 160 void set_header_crc(int crc) { _header->_crc = crc; }
aoqi@0 161 void populate_header(size_t alignment);
iklam@7089 162 bool validate_header();
aoqi@0 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; }
aoqi@0 169
aoqi@0 170 static FileMapInfo* current_info() {
aoqi@0 171 CDS_ONLY(return _current_info;)
aoqi@0 172 NOT_CDS(return NULL;)
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 static void assert_mark(bool check);
aoqi@0 176
aoqi@0 177 // File manipulation.
aoqi@0 178 bool initialize() NOT_CDS_RETURN_(false);
aoqi@0 179 bool open_for_read();
aoqi@0 180 void open_for_write();
aoqi@0 181 void write_header();
aoqi@0 182 void write_space(int i, Metaspace* space, bool read_only);
aoqi@0 183 void write_region(int region, char* base, size_t size,
aoqi@0 184 size_t capacity, bool read_only, bool allow_exec);
aoqi@0 185 void write_bytes(const void* buffer, int count);
aoqi@0 186 void write_bytes_aligned(const void* buffer, int count);
aoqi@0 187 char* map_region(int i);
aoqi@0 188 void unmap_region(int i);
aoqi@0 189 bool verify_region_checksum(int i);
aoqi@0 190 void close();
aoqi@0 191 bool is_open() { return _file_open; }
aoqi@0 192 ReservedSpace reserve_shared_memory();
aoqi@0 193
aoqi@0 194 // JVM/TI RedefineClasses() support:
aoqi@0 195 // Remap the shared readonly space to shared readwrite, private.
aoqi@0 196 bool remap_shared_readonly_as_readwrite();
aoqi@0 197
aoqi@0 198 // Errors.
aoqi@0 199 static void fail_stop(const char *msg, ...);
iklam@7089 200 static void fail_continue(const char *msg, ...);
aoqi@0 201
aoqi@0 202 // Return true if given address is in the mapped shared space.
aoqi@0 203 bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
aoqi@0 204 void print_shared_spaces() NOT_CDS_RETURN;
aoqi@0 205
aoqi@0 206 static size_t shared_spaces_size() {
aoqi@0 207 return align_size_up(SharedReadOnlySize + SharedReadWriteSize +
aoqi@0 208 SharedMiscDataSize + SharedMiscCodeSize,
aoqi@0 209 os::vm_allocation_granularity());
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 // Stop CDS sharing and unmap CDS regions.
aoqi@0 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 }
aoqi@0 230 };
aoqi@0 231
aoqi@0 232 #endif // SHARE_VM_MEMORY_FILEMAP_HPP

mercurial