annotate src/share/vm/memory/filemap.cpp @ 20304:a22acf6d7598

8048112: G1 Full GC needs to support the case when the very first region is not available Summary: Refactor preparation for compaction during Full GC so that it lazily initializes the first compaction point. This also avoids problems later when the first region may not be committed. Also reviewed by K. Barrett. Reviewed-by: brutisso
author tschatzl
date Mon, 21 Jul 2014 10:00:31 +0200
parents 78bbf4d43a14
children ca6d25be853b 6e0cb14ce59b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 12157
diff changeset
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/classLoader.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/symbolTable.hpp"
7174
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
28 #include "classfile/altHashing.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/filemap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/arguments.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/os.hpp"
6882
716c64bda5ba 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 6725
diff changeset
33 #include "services/memTracker.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "utilities/defaultStream.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 # include <sys/stat.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
37 # include <errno.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #ifndef O_BINARY // if defined (Win32) use binary files.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #define O_BINARY 0 // otherwise do nothing.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
42
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 12157
diff changeset
43 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 extern address JVM_FunctionAtStart();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 extern address JVM_FunctionAtEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
47
605
98cb887364d3 6810672: Comment typos
twisti
parents: 0
diff changeset
48 // Complain and stop. All error conditions occurring during the writing of
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // an archive file should stop the process. Unrecoverable errors during
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // the reading of the archive file should stop the process.
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 static void fail(const char *msg, va_list ap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // This occurs very early during initialization: tty is not initialized.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 jio_fprintf(defaultStream::error_stream(),
605
98cb887364d3 6810672: Comment typos
twisti
parents: 0
diff changeset
55 "An error has occurred while processing the"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 " shared archive file.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
57 jio_vfprintf(defaultStream::error_stream(), msg, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 jio_fprintf(defaultStream::error_stream(), "\n");
12157
35b99e7e0af2 8023381: VM fails to initialize in runtime/CDSCompressedKPtrs/XShareAuto.java runtime/SharedArchiveFile/CdsSameObjectAlignment.java
hseigel
parents: 12056
diff changeset
59 // Do not change the text of the below message because some tests check for it.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
60 vm_exit_during_initialization("Unable to use shared archive.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void FileMapInfo::fail_stop(const char *msg, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 va_start(ap, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 fail(msg, ap); // Never returns.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 va_end(ap); // for completeness.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Complain and continue. Recoverable errors during the reading of the
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // archive file may continue (with sharing disabled).
a61af66fc99e Initial load
duke
parents:
diff changeset
74 //
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // If we continue, then disable shared spaces and close the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void FileMapInfo::fail_continue(const char *msg, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 va_start(ap, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (RequireSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 fail(msg, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 va_end(ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 UseSharedSpaces = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
7174
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
88 // Fill in the fileMapInfo structure with data about this VM instance.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
89
7174
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
90 // This method copies the vm version info into header_version. If the version is too
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
91 // long then a truncated version, which has a hash code appended to it, is copied.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
92 //
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
93 // Using a template enables this method to verify that header_version is an array of
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
94 // length JVM_IDENT_MAX. This ensures that the code that writes to the CDS file and
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
95 // the code that reads the CDS file will both use the same size buffer. Hence, will
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
96 // use identical truncation. This is necessary for matching of truncated versions.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
97 template <int N> static void get_header_version(char (&header_version) [N]) {
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
98 assert(N == JVM_IDENT_MAX, "Bad header_version size");
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
99
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
100 const char *vm_version = VM_Version::internal_vm_info_string();
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
101 const int version_len = (int)strlen(vm_version);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
102
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
103 if (version_len < (JVM_IDENT_MAX-1)) {
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
104 strcpy(header_version, vm_version);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
105
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
106 } else {
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
107 // Get the hash value. Use a static seed because the hash needs to return the same
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
108 // value over multiple jvm invocations.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
109 unsigned int hash = AltHashing::murmur3_32(8191, (const jbyte*)vm_version, version_len);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
110
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
111 // Truncate the ident, saving room for the 8 hex character hash value.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
112 strncpy(header_version, vm_version, JVM_IDENT_MAX-9);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
113
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
114 // Append the hash code as eight hex digits.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
115 sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
116 header_version[JVM_IDENT_MAX-1] = 0; // Null terminate.
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
117 }
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
118 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void FileMapInfo::populate_header(size_t alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 _header._magic = 0xf00baba2;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 _header._version = _current_version;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 _header._alignment = alignment;
7461
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
124 _header._obj_alignment = ObjectAlignmentInBytes;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // The following fields are for sanity checks for whether this archive
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // will function correctly with this JVM and the bootclasspath it's
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // invoked with.
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // JVM version string ... changes on each build.
7174
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
131 get_header_version(_header._jvm_ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Build checks on classpath and jar files
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _header._num_jars = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 for ( ; cpe != NULL; cpe = cpe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (cpe->is_jar_file()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 fail_stop("Too many jar files to share.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Jar file - record timestamp and file size.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 struct stat st;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 const char *path = cpe->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (os::stat(path, &st) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // If we can't access a jar file in the boot path, then we can't
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // make assumptions about where classes get loaded from.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 fail_stop("Unable to open jar file %s.", path);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 _header._jar[_header._num_jars]._timestamp = st.st_mtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _header._jar[_header._num_jars]._filesize = st.st_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _header._num_jars++;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // If directories appear in boot classpath, they must be empty to
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // avoid having to verify each individual class file.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 const char* name = ((ClassPathDirEntry*)cpe)->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (!os::dir_is_empty(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 fail_stop("Boot classpath directory %s is not empty.", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Read the FileMapInfo information from the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 bool FileMapInfo::init_from_file(int fd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 size_t n = read(fd, &_header, sizeof(struct FileMapHeader));
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (n != sizeof(struct FileMapHeader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 fail_continue("Unable to read the file header.");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (_header._version != current_version()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 fail_continue("The shared archive file has the wrong version.");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 _file_offset = (long)n;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Read the FileMapInfo information from the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
186 bool FileMapInfo::open_for_read() {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _full_path = Arguments::GetSharedArchivePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (fd < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (errno == ENOENT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Not locating the shared archive is ok.
a61af66fc99e Initial load
duke
parents:
diff changeset
192 fail_continue("Specified shared archive not found.");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 fail_continue("Failed to open shared archive file (%s).",
a61af66fc99e Initial load
duke
parents:
diff changeset
195 strerror(errno));
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 _fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 _file_open = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // Write the FileMapInfo information to the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 void FileMapInfo::open_for_write() {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 _full_path = Arguments::GetSharedArchivePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 tty->print_cr("Dumping shared data to file: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
212 tty->print_cr(" %s", _full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
7980
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
215 #ifdef _WINDOWS // On Windows, need WRITE permission to remove the file.
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
216 chmod(_full_path, _S_IREAD | _S_IWRITE);
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
217 #endif
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
218
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
219 // Use remove() to delete the existing file because, on Unix, this will
c4ef3380a70b 7197672: There are issues with shared data on windows
hseigel
parents: 7461
diff changeset
220 // allow processes that have it open continued access to the file.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
221 remove(_full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (fd < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 fail_stop("Unable to create shared archive file %s.", _full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 _fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 _file_offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _file_open = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // Write the header to the file, seek to the next allocation boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 void FileMapInfo::write_header() {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 write_bytes_aligned(&_header, sizeof(FileMapHeader));
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Dump shared spaces to file.
a61af66fc99e Initial load
duke
parents:
diff changeset
240
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
241 void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
242 align_file_position();
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 8804
diff changeset
243 size_t used = space->used_bytes_slow(Metaspace::NonClassType);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 8804
diff changeset
244 size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
246 write_region(i, (char*)space->bottom(), used, capacity, read_only, false);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Dump region to file.
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 void FileMapInfo::write_region(int region, char* base, size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
253 size_t capacity, bool read_only,
a61af66fc99e Initial load
duke
parents:
diff changeset
254 bool allow_exec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[region];
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (PrintSharedSpaces) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
260 tty->print_cr("Shared file region %d: 0x%6x bytes, addr " INTPTR_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
261 " file offset 0x%6x", region, size, base, _file_offset);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 si->_file_offset = _file_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 si->_base = base;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 si->_used = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 si->_capacity = capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 si->_read_only = read_only;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 si->_allow_exec = allow_exec;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 write_bytes_aligned(base, (int)size);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Dump bytes to file -- at the current file position.
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 int n = ::write(_fd, buffer, nbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if (n != nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // It is dangerous to leave the corrupted shared archive file around,
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // close and remove the file. See bug 6372906.
a61af66fc99e Initial load
duke
parents:
diff changeset
283 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 remove(_full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 fail_stop("Unable to write to shared archive file.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 _file_offset += nbytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // Align file position to an allocation unit boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void FileMapInfo::align_file_position() {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (new_file_offset != _file_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 _file_offset = new_file_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // Seek one byte back from the target and write a byte to insure
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // that the written file is the correct length.
a61af66fc99e Initial load
duke
parents:
diff changeset
301 _file_offset -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 if (lseek(_fd, _file_offset, SEEK_SET) < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 fail_stop("Unable to seek.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 char zero = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 write_bytes(&zero, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // Dump bytes to file -- at the current file position.
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 align_file_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
316 write_bytes(buffer, nbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 align_file_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // Close the shared archive file. This does NOT unmap mapped regions.
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 void FileMapInfo::close() {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 if (::close(_fd) < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 fail_stop("Unable to close the shared archive file.");
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 _file_open = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 _fd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // JVM/TI RedefineClasses() support:
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Remap the shared readonly space to shared readwrite, private.
a61af66fc99e Initial load
duke
parents:
diff changeset
336 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if (!si->_read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // the space is already readwrite so we are done
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (!open_for_read()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
348 si->_base, size, false /* !read_only */,
a61af66fc99e Initial load
duke
parents:
diff changeset
349 si->_allow_exec);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (base == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (base != si->_base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 fail_continue("Unable to remap shared readonly space at required address.");
a61af66fc99e Initial load
duke
parents:
diff changeset
357 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 si->_read_only = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
363 // Map the whole region at once, assumed to be allocated contiguously.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
364 ReservedSpace FileMapInfo::reserve_shared_memory() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
365 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0];
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
366 char* requested_addr = si->_base;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
367
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
368 size_t size = FileMapInfo::shared_spaces_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
369
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
370 // Reserve the space first, then map otherwise map will go right over some
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
371 // other reserved memory (like the code cache).
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
372 ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
373 if (!rs.is_reserved()) {
8804
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 7980
diff changeset
374 fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr));
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
375 return rs;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
376 }
6882
716c64bda5ba 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 6725
diff changeset
377 // the reserved virtual memory is for mapping class data sharing archive
7460
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
378 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
379
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
380 return rs;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
381 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // Memory map a region in the address space.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
384 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
385
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
386 char* FileMapInfo::map_region(int i) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
387 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
388 size_t used = si->_used;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
389 size_t alignment = os::vm_allocation_granularity();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
390 size_t size = align_size_up(used, alignment);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
391 char *requested_addr = si->_base;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
392
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
393 // map the contents of the CDS archive in this memory
0
a61af66fc99e Initial load
duke
parents:
diff changeset
394 char *base = os::map_memory(_fd, _full_path, si->_file_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
395 requested_addr, size, si->_read_only,
a61af66fc99e Initial load
duke
parents:
diff changeset
396 si->_allow_exec);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
397 if (base == NULL || base != si->_base) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
398 fail_continue(err_msg("Unable to map %s shared space at required address.", shared_region_name[i]));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
399 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
7460
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
401 #ifdef _WINDOWS
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
402 // This call is Windows-only because the memory_type gets recorded for the other platforms
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
403 // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
404 MemTracker::record_virtual_memory_type((address)base, mtClassShared);
6c3f47d964f3 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 7174
diff changeset
405 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
406 return base;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // Unmap a memory region in the address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 void FileMapInfo::unmap_region(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
414 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (!os::unmap_memory(si->_base, size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 fail_stop("Unable to unmap shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 void FileMapInfo::assert_mark(bool check) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 if (!check) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 fail_stop("Mark mismatch while restoring from shared file.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 FileMapInfo* FileMapInfo::_current_info = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // Open the shared archive file, read and validate the header
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // information (version, boot classpath, etc.). If initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // fails, shared spaces are disabled and the file is closed. [See
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // fail_continue.]
a61af66fc99e Initial load
duke
parents:
diff changeset
436 bool FileMapInfo::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 assert(UseSharedSpaces, "UseSharedSpaces expected.");
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 fail_continue("Tool agent requires sharing to be disabled.");
a61af66fc99e Initial load
duke
parents:
diff changeset
441 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if (!open_for_read()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 init_from_file(_fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (!validate()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452
a61af66fc99e Initial load
duke
parents:
diff changeset
453 SharedReadOnlySize = _header._space[0]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 SharedReadWriteSize = _header._space[1]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 SharedMiscDataSize = _header._space[2]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 SharedMiscCodeSize = _header._space[3]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 bool FileMapInfo::validate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (_header._version != current_version()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 fail_continue("The shared archive file is the wrong version.");
a61af66fc99e Initial load
duke
parents:
diff changeset
464 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (_header._magic != (int)0xf00baba2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 fail_continue("The shared archive file has a bad magic number.");
a61af66fc99e Initial load
duke
parents:
diff changeset
468 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
7174
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
470 char header_version[JVM_IDENT_MAX];
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
471 get_header_version(header_version);
fe81517cfb77 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 6882
diff changeset
472 if (strncmp(_header._jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
473 fail_continue("The shared archive file was created by a different"
a61af66fc99e Initial load
duke
parents:
diff changeset
474 " version or build of HotSpot.");
a61af66fc99e Initial load
duke
parents:
diff changeset
475 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
7461
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
477 if (_header._obj_alignment != ObjectAlignmentInBytes) {
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
478 fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
479 " does not equal the current ObjectAlignmentInBytes of %d.",
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
480 _header._obj_alignment, ObjectAlignmentInBytes);
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
481 return false;
561148896559 8005076: Creating a CDS archive with one alignment and running another causes a crash.
hseigel
parents: 7460
diff changeset
482 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // Cannot verify interpreter yet, as it can only be created after the GC
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // heap has been initialized.
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 fail_continue("Too many jar files to share.");
a61af66fc99e Initial load
duke
parents:
diff changeset
489 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // Build checks on classpath and jar files
a61af66fc99e Initial load
duke
parents:
diff changeset
493 int num_jars_now = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 for ( ; cpe != NULL; cpe = cpe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (cpe->is_jar_file()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 if (num_jars_now < _header._num_jars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // Jar file - verify timestamp and file size.
a61af66fc99e Initial load
duke
parents:
diff changeset
501 struct stat st;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 const char *path = cpe->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
503 if (os::stat(path, &st) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
504 fail_continue("Unable to open jar file %s.", path);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (_header._jar[num_jars_now]._timestamp != st.st_mtime ||
a61af66fc99e Initial load
duke
parents:
diff changeset
508 _header._jar[num_jars_now]._filesize != st.st_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 fail_continue("A jar file is not the one used while building"
a61af66fc99e Initial load
duke
parents:
diff changeset
510 " the shared archive file.");
a61af66fc99e Initial load
duke
parents:
diff changeset
511 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 ++num_jars_now;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // If directories appear in boot classpath, they must be empty to
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // avoid having to verify each individual class file.
a61af66fc99e Initial load
duke
parents:
diff changeset
519 const char* name = ((ClassPathDirEntry*)cpe)->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (!os::dir_is_empty(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 fail_continue("Boot classpath directory %s is not empty.", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
524 }
a61af66fc99e Initial load
duke
parents:
diff changeset
525 }
a61af66fc99e Initial load
duke
parents:
diff changeset
526 if (num_jars_now < _header._num_jars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 fail_continue("The number of jar files in the boot classpath is"
a61af66fc99e Initial load
duke
parents:
diff changeset
528 " less than the number the shared archive was created with.");
a61af66fc99e Initial load
duke
parents:
diff changeset
529 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // The following method is provided to see whether a given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // falls in the mapped shared space.
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // Param:
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // p, The given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // Return:
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // True if the p is within the mapped shared space, otherwise, false.
a61af66fc99e Initial load
duke
parents:
diff changeset
541 bool FileMapInfo::is_in_shared_space(const void* p) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1980
diff changeset
542 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
543 if (p >= _header._space[i]._base &&
a61af66fc99e Initial load
duke
parents:
diff changeset
544 p < _header._space[i]._base + _header._space[i]._used) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
546 }
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548
a61af66fc99e Initial load
duke
parents:
diff changeset
549 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
11056
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
551
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
552 void FileMapInfo::print_shared_spaces() {
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
553 gclog_or_tty->print_cr("Shared Spaces:");
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
554 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
555 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
556 gclog_or_tty->print(" %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
557 shared_region_name[i],
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
558 si->_base, si->_base + si->_used);
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
559 }
221df7e37535 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 10183
diff changeset
560 }
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
561
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
562 // Unmap mapped regions of shared space.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
563 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
564 FileMapInfo *map_info = FileMapInfo::current_info();
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
565 if (map_info) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
566 map_info->fail_continue(msg);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
567 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
568 if (map_info->_header._space[i]._base != NULL) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
569 map_info->unmap_region(i);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
570 map_info->_header._space[i]._base = NULL;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
571 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
572 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
573 } else if (DumpSharedSpaces) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
574 fail_stop(msg, NULL);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
575 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11056
diff changeset
576 }