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