src/share/vm/memory/filemap.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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_SHARED_JARS_MAX = 128;
aoqi@0 41 static const int JVM_SPACENAME_MAX = 128;
aoqi@0 42 static const int JVM_IDENT_MAX = 256;
aoqi@0 43 static const int JVM_ARCH_MAX = 12;
aoqi@0 44
aoqi@0 45
aoqi@0 46 class Metaspace;
aoqi@0 47
aoqi@0 48 class FileMapInfo : public CHeapObj<mtInternal> {
aoqi@0 49 private:
aoqi@0 50 enum {
aoqi@0 51 _invalid_version = -1,
aoqi@0 52 _current_version = 1
aoqi@0 53 };
aoqi@0 54
aoqi@0 55 bool _file_open;
aoqi@0 56 int _fd;
aoqi@0 57 size_t _file_offset;
aoqi@0 58
aoqi@0 59 // FileMapHeader describes the shared space data in the file to be
aoqi@0 60 // mapped. This structure gets written to a file. It is not a class, so
aoqi@0 61 // that the compilers don't add any compiler-private data to it.
aoqi@0 62
aoqi@0 63 struct FileMapHeader {
aoqi@0 64 int _magic; // identify file type.
aoqi@0 65 int _crc; // header crc checksum.
aoqi@0 66 int _version; // (from enum, above.)
aoqi@0 67 size_t _alignment; // how shared archive should be aligned
aoqi@0 68 int _obj_alignment; // value of ObjectAlignmentInBytes
aoqi@0 69
aoqi@0 70 struct space_info {
aoqi@0 71 int _crc; // crc checksum of the current space
aoqi@0 72 size_t _file_offset; // sizeof(this) rounded to vm page size
aoqi@0 73 char* _base; // copy-on-write base address
aoqi@0 74 size_t _capacity; // for validity checking
aoqi@0 75 size_t _used; // for setting space top on read
aoqi@0 76 bool _read_only; // read only space?
aoqi@0 77 bool _allow_exec; // executable code in space?
aoqi@0 78 } _space[MetaspaceShared::n_regions];
aoqi@0 79
aoqi@0 80 // The following fields are all sanity checks for whether this archive
aoqi@0 81 // will function correctly with this JVM and the bootclasspath it's
aoqi@0 82 // invoked with.
aoqi@0 83 char _arch[JVM_ARCH_MAX]; // architecture
aoqi@0 84 char _jvm_ident[JVM_IDENT_MAX]; // identifier for jvm
aoqi@0 85 int _num_jars; // Number of jars in bootclasspath
aoqi@0 86
aoqi@0 87 // Per jar file data: timestamp, size.
aoqi@0 88
aoqi@0 89 struct {
aoqi@0 90 time_t _timestamp; // jar timestamp.
aoqi@0 91 long _filesize; // jar file size.
aoqi@0 92 } _jar[JVM_SHARED_JARS_MAX];
aoqi@0 93 } _header;
aoqi@0 94 const char* _full_path;
aoqi@0 95
aoqi@0 96 static FileMapInfo* _current_info;
aoqi@0 97
aoqi@0 98 bool init_from_file(int fd);
aoqi@0 99 void align_file_position();
aoqi@0 100
aoqi@0 101 public:
aoqi@0 102 FileMapInfo() {
aoqi@0 103 _file_offset = 0;
aoqi@0 104 _file_open = false;
aoqi@0 105 _header._version = _invalid_version;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 static int current_version() { return _current_version; }
aoqi@0 109 int compute_header_crc();
aoqi@0 110 void set_header_crc(int crc) { _header._crc = crc; }
aoqi@0 111 void populate_header(size_t alignment);
aoqi@0 112 bool validate();
aoqi@0 113 void invalidate();
aoqi@0 114 int version() { return _header._version; }
aoqi@0 115 size_t alignment() { return _header._alignment; }
aoqi@0 116 size_t space_capacity(int i) { return _header._space[i]._capacity; }
aoqi@0 117 char* region_base(int i) { return _header._space[i]._base; }
aoqi@0 118 struct FileMapHeader* header() { return &_header; }
aoqi@0 119
aoqi@0 120 static void set_current_info(FileMapInfo* info) {
aoqi@0 121 CDS_ONLY(_current_info = info;)
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 static FileMapInfo* current_info() {
aoqi@0 125 CDS_ONLY(return _current_info;)
aoqi@0 126 NOT_CDS(return NULL;)
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 static void assert_mark(bool check);
aoqi@0 130
aoqi@0 131 // File manipulation.
aoqi@0 132 bool initialize() NOT_CDS_RETURN_(false);
aoqi@0 133 bool open_for_read();
aoqi@0 134 void open_for_write();
aoqi@0 135 void write_header();
aoqi@0 136 void write_space(int i, Metaspace* space, bool read_only);
aoqi@0 137 void write_region(int region, char* base, size_t size,
aoqi@0 138 size_t capacity, bool read_only, bool allow_exec);
aoqi@0 139 void write_bytes(const void* buffer, int count);
aoqi@0 140 void write_bytes_aligned(const void* buffer, int count);
aoqi@0 141 char* map_region(int i);
aoqi@0 142 void unmap_region(int i);
aoqi@0 143 bool verify_region_checksum(int i);
aoqi@0 144 void close();
aoqi@0 145 bool is_open() { return _file_open; }
aoqi@0 146 ReservedSpace reserve_shared_memory();
aoqi@0 147
aoqi@0 148 // JVM/TI RedefineClasses() support:
aoqi@0 149 // Remap the shared readonly space to shared readwrite, private.
aoqi@0 150 bool remap_shared_readonly_as_readwrite();
aoqi@0 151
aoqi@0 152 // Errors.
aoqi@0 153 static void fail_stop(const char *msg, ...);
aoqi@0 154 void fail_continue(const char *msg, ...);
aoqi@0 155
aoqi@0 156 // Return true if given address is in the mapped shared space.
aoqi@0 157 bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
aoqi@0 158 void print_shared_spaces() NOT_CDS_RETURN;
aoqi@0 159
aoqi@0 160 static size_t shared_spaces_size() {
aoqi@0 161 return align_size_up(SharedReadOnlySize + SharedReadWriteSize +
aoqi@0 162 SharedMiscDataSize + SharedMiscCodeSize,
aoqi@0 163 os::vm_allocation_granularity());
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 // Stop CDS sharing and unmap CDS regions.
aoqi@0 167 static void stop_sharing_and_unmap(const char* msg);
aoqi@0 168 };
aoqi@0 169
aoqi@0 170 #endif // SHARE_VM_MEMORY_FILEMAP_HPP

mercurial