Mercurial > hg > truffle
annotate src/share/vm/memory/filemap.cpp @ 7403:807f1d348f7b
Merge
author | collins |
---|---|
date | Fri, 14 Dec 2012 11:45:55 -0800 |
parents | fe81517cfb77 |
children | 6c3f47d964f3 |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
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 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
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 | 29 #include "memory/filemap.hpp" |
30 #include "runtime/arguments.hpp" | |
31 #include "runtime/java.hpp" | |
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 | 34 #include "utilities/defaultStream.hpp" |
35 | |
0 | 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 | |
605 | 47 // Complain and stop. All error conditions occurring during the writing of |
0 | 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(), | |
605 | 54 "An error has occurred while processing the" |
0 | 55 " shared archive file.\n"); |
56 jio_vfprintf(defaultStream::error_stream(), msg, ap); | |
57 jio_fprintf(defaultStream::error_stream(), "\n"); | |
58 vm_exit_during_initialization("Unable to use shared archive.", NULL); | |
59 } | |
60 | |
61 | |
62 void FileMapInfo::fail_stop(const char *msg, ...) { | |
63 va_list ap; | |
64 va_start(ap, msg); | |
65 fail(msg, ap); // Never returns. | |
66 va_end(ap); // for completeness. | |
67 } | |
68 | |
69 | |
70 // Complain and continue. Recoverable errors during the reading of the | |
71 // archive file may continue (with sharing disabled). | |
72 // | |
73 // If we continue, then disable shared spaces and close the file. | |
74 | |
75 void FileMapInfo::fail_continue(const char *msg, ...) { | |
76 va_list ap; | |
77 va_start(ap, msg); | |
78 if (RequireSharedSpaces) { | |
79 fail(msg, ap); | |
80 } | |
81 va_end(ap); | |
82 UseSharedSpaces = false; | |
83 close(); | |
84 } | |
85 | |
7174
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
86 // Fill in the fileMapInfo structure with data about this VM instance. |
0 | 87 |
7174
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
88 // 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
|
89 // 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
|
90 // |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
91 // 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
|
92 // 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
|
93 // 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
|
94 // 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
|
95 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
|
96 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
|
97 |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
98 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
|
99 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
|
100 |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
101 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
|
102 strcpy(header_version, vm_version); |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
103 |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
104 } else { |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
105 // 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
|
106 // value over multiple jvm invocations. |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
107 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
|
108 |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
109 // 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
|
110 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
|
111 |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
112 // 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
|
113 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
|
114 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
|
115 } |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
116 } |
0 | 117 |
118 void FileMapInfo::populate_header(size_t alignment) { | |
119 _header._magic = 0xf00baba2; | |
120 _header._version = _current_version; | |
121 _header._alignment = alignment; | |
122 | |
123 // The following fields are for sanity checks for whether this archive | |
124 // will function correctly with this JVM and the bootclasspath it's | |
125 // invoked with. | |
126 | |
127 // 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
|
128 get_header_version(_header._jvm_ident); |
0 | 129 |
130 // Build checks on classpath and jar files | |
131 _header._num_jars = 0; | |
132 ClassPathEntry *cpe = ClassLoader::classpath_entry(0); | |
133 for ( ; cpe != NULL; cpe = cpe->next()) { | |
134 | |
135 if (cpe->is_jar_file()) { | |
136 if (_header._num_jars >= JVM_SHARED_JARS_MAX) { | |
137 fail_stop("Too many jar files to share.", NULL); | |
138 } | |
139 | |
140 // Jar file - record timestamp and file size. | |
141 struct stat st; | |
142 const char *path = cpe->name(); | |
143 if (os::stat(path, &st) != 0) { | |
144 // If we can't access a jar file in the boot path, then we can't | |
145 // make assumptions about where classes get loaded from. | |
146 fail_stop("Unable to open jar file %s.", path); | |
147 } | |
148 _header._jar[_header._num_jars]._timestamp = st.st_mtime; | |
149 _header._jar[_header._num_jars]._filesize = st.st_size; | |
150 _header._num_jars++; | |
151 } else { | |
152 | |
153 // If directories appear in boot classpath, they must be empty to | |
154 // avoid having to verify each individual class file. | |
155 const char* name = ((ClassPathDirEntry*)cpe)->name(); | |
156 if (!os::dir_is_empty(name)) { | |
157 fail_stop("Boot classpath directory %s is not empty.", name); | |
158 } | |
159 } | |
160 } | |
161 } | |
162 | |
163 | |
164 // Read the FileMapInfo information from the file. | |
165 | |
166 bool FileMapInfo::init_from_file(int fd) { | |
167 | |
168 size_t n = read(fd, &_header, sizeof(struct FileMapHeader)); | |
169 if (n != sizeof(struct FileMapHeader)) { | |
170 fail_continue("Unable to read the file header."); | |
171 return false; | |
172 } | |
173 if (_header._version != current_version()) { | |
174 fail_continue("The shared archive file has the wrong version."); | |
175 return false; | |
176 } | |
177 _file_offset = (long)n; | |
178 return true; | |
179 } | |
180 | |
181 | |
182 // Read the FileMapInfo information from the file. | |
183 bool FileMapInfo::open_for_read() { | |
184 _full_path = Arguments::GetSharedArchivePath(); | |
185 int fd = open(_full_path, O_RDONLY | O_BINARY, 0); | |
186 if (fd < 0) { | |
187 if (errno == ENOENT) { | |
188 // Not locating the shared archive is ok. | |
189 fail_continue("Specified shared archive not found."); | |
190 } else { | |
191 fail_continue("Failed to open shared archive file (%s).", | |
192 strerror(errno)); | |
193 } | |
194 return false; | |
195 } | |
196 | |
197 _fd = fd; | |
198 _file_open = true; | |
199 return true; | |
200 } | |
201 | |
202 | |
203 // Write the FileMapInfo information to the file. | |
204 | |
205 void FileMapInfo::open_for_write() { | |
206 _full_path = Arguments::GetSharedArchivePath(); | |
207 if (PrintSharedSpaces) { | |
208 tty->print_cr("Dumping shared data to file: "); | |
209 tty->print_cr(" %s", _full_path); | |
210 } | |
211 | |
212 // Remove the existing file in case another process has it open. | |
213 remove(_full_path); | |
214 int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444); | |
215 if (fd < 0) { | |
216 fail_stop("Unable to create shared archive file %s.", _full_path); | |
217 } | |
218 _fd = fd; | |
219 _file_offset = 0; | |
220 _file_open = true; | |
221 } | |
222 | |
223 | |
224 // Write the header to the file, seek to the next allocation boundary. | |
225 | |
226 void FileMapInfo::write_header() { | |
227 write_bytes_aligned(&_header, sizeof(FileMapHeader)); | |
228 } | |
229 | |
230 | |
231 // Dump shared spaces to file. | |
232 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
233 void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) { |
0 | 234 align_file_position(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
235 size_t used = space->used_words(Metaspace::NonClassType) * BytesPerWord; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
236 size_t capacity = space->capacity_words(Metaspace::NonClassType) * BytesPerWord; |
0 | 237 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
|
238 write_region(i, (char*)space->bottom(), used, capacity, read_only, false); |
0 | 239 } |
240 | |
241 | |
242 // Dump region to file. | |
243 | |
244 void FileMapInfo::write_region(int region, char* base, size_t size, | |
245 size_t capacity, bool read_only, | |
246 bool allow_exec) { | |
247 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[region]; | |
248 | |
249 if (_file_open) { | |
250 guarantee(si->_file_offset == _file_offset, "file offset mismatch."); | |
251 if (PrintSharedSpaces) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
252 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
|
253 " file offset 0x%6x", region, size, base, _file_offset); |
0 | 254 } |
255 } else { | |
256 si->_file_offset = _file_offset; | |
257 } | |
258 si->_base = base; | |
259 si->_used = size; | |
260 si->_capacity = capacity; | |
261 si->_read_only = read_only; | |
262 si->_allow_exec = allow_exec; | |
263 write_bytes_aligned(base, (int)size); | |
264 } | |
265 | |
266 | |
267 // Dump bytes to file -- at the current file position. | |
268 | |
269 void FileMapInfo::write_bytes(const void* buffer, int nbytes) { | |
270 if (_file_open) { | |
271 int n = ::write(_fd, buffer, nbytes); | |
272 if (n != nbytes) { | |
273 // It is dangerous to leave the corrupted shared archive file around, | |
274 // close and remove the file. See bug 6372906. | |
275 close(); | |
276 remove(_full_path); | |
277 fail_stop("Unable to write to shared archive file.", NULL); | |
278 } | |
279 } | |
280 _file_offset += nbytes; | |
281 } | |
282 | |
283 | |
284 // Align file position to an allocation unit boundary. | |
285 | |
286 void FileMapInfo::align_file_position() { | |
287 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity()); | |
288 if (new_file_offset != _file_offset) { | |
289 _file_offset = new_file_offset; | |
290 if (_file_open) { | |
291 // Seek one byte back from the target and write a byte to insure | |
292 // that the written file is the correct length. | |
293 _file_offset -= 1; | |
294 if (lseek(_fd, _file_offset, SEEK_SET) < 0) { | |
295 fail_stop("Unable to seek.", NULL); | |
296 } | |
297 char zero = 0; | |
298 write_bytes(&zero, 1); | |
299 } | |
300 } | |
301 } | |
302 | |
303 | |
304 // Dump bytes to file -- at the current file position. | |
305 | |
306 void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) { | |
307 align_file_position(); | |
308 write_bytes(buffer, nbytes); | |
309 align_file_position(); | |
310 } | |
311 | |
312 | |
313 // Close the shared archive file. This does NOT unmap mapped regions. | |
314 | |
315 void FileMapInfo::close() { | |
316 if (_file_open) { | |
317 if (::close(_fd) < 0) { | |
318 fail_stop("Unable to close the shared archive file."); | |
319 } | |
320 _file_open = false; | |
321 _fd = -1; | |
322 } | |
323 } | |
324 | |
325 | |
326 // JVM/TI RedefineClasses() support: | |
327 // Remap the shared readonly space to shared readwrite, private. | |
328 bool FileMapInfo::remap_shared_readonly_as_readwrite() { | |
329 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0]; | |
330 if (!si->_read_only) { | |
331 // the space is already readwrite so we are done | |
332 return true; | |
333 } | |
334 size_t used = si->_used; | |
335 size_t size = align_size_up(used, os::vm_allocation_granularity()); | |
336 if (!open_for_read()) { | |
337 return false; | |
338 } | |
339 char *base = os::remap_memory(_fd, _full_path, si->_file_offset, | |
340 si->_base, size, false /* !read_only */, | |
341 si->_allow_exec); | |
342 close(); | |
343 if (base == NULL) { | |
344 fail_continue("Unable to remap shared readonly space (errno=%d).", errno); | |
345 return false; | |
346 } | |
347 if (base != si->_base) { | |
348 fail_continue("Unable to remap shared readonly space at required address."); | |
349 return false; | |
350 } | |
351 si->_read_only = false; | |
352 return true; | |
353 } | |
354 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
355 // 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
|
356 ReservedSpace FileMapInfo::reserve_shared_memory() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
357 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
|
358 char* requested_addr = si->_base; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
359 size_t alignment = os::vm_allocation_granularity(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
360 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
361 size_t size = align_size_up(SharedReadOnlySize + SharedReadWriteSize + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
362 SharedMiscDataSize + SharedMiscCodeSize, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
363 alignment); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
364 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
365 // 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
|
366 // other reserved memory (like the code cache). |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
367 ReservedSpace rs(size, alignment, false, requested_addr); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
368 if (!rs.is_reserved()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
369 fail_continue(err_msg("Unable to reserved shared space at required address " INTPTR_FORMAT, requested_addr)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
370 return rs; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
371 } |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6725
diff
changeset
|
372 // the reserved virtual memory is for mapping class data sharing archive |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6725
diff
changeset
|
373 if (MemTracker::is_on()) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6725
diff
changeset
|
374 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6725
diff
changeset
|
375 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
376 return rs; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
377 } |
0 | 378 |
379 // 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
|
380 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"}; |
0 | 381 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
382 char* FileMapInfo::map_region(int i) { |
0 | 383 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; |
384 size_t used = si->_used; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
385 size_t alignment = os::vm_allocation_granularity(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
386 size_t size = align_size_up(used, alignment); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
387 char *requested_addr = si->_base; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
388 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
389 // map the contents of the CDS archive in this memory |
0 | 390 char *base = os::map_memory(_fd, _full_path, si->_file_offset, |
391 requested_addr, size, si->_read_only, | |
392 si->_allow_exec); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
393 if (base == NULL || base != si->_base) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1980
diff
changeset
|
394 fail_continue(err_msg("Unable to map %s shared space at required address.", shared_region_name[i])); |
0 | 395 return NULL; |
396 } | |
397 return base; | |
398 } | |
399 | |
400 | |
401 // Unmap a memory region in the address space. | |
402 | |
403 void FileMapInfo::unmap_region(int i) { | |
404 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i]; | |
405 size_t used = si->_used; | |
406 size_t size = align_size_up(used, os::vm_allocation_granularity()); | |
407 if (!os::unmap_memory(si->_base, size)) { | |
408 fail_stop("Unable to unmap shared space."); | |
409 } | |
410 } | |
411 | |
412 | |
413 void FileMapInfo::assert_mark(bool check) { | |
414 if (!check) { | |
415 fail_stop("Mark mismatch while restoring from shared file.", NULL); | |
416 } | |
417 } | |
418 | |
419 | |
420 FileMapInfo* FileMapInfo::_current_info = NULL; | |
421 | |
422 | |
423 // Open the shared archive file, read and validate the header | |
424 // information (version, boot classpath, etc.). If initialization | |
425 // fails, shared spaces are disabled and the file is closed. [See | |
426 // fail_continue.] | |
427 bool FileMapInfo::initialize() { | |
428 assert(UseSharedSpaces, "UseSharedSpaces expected."); | |
429 | |
430 if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) { | |
431 fail_continue("Tool agent requires sharing to be disabled."); | |
432 return false; | |
433 } | |
434 | |
435 if (!open_for_read()) { | |
436 return false; | |
437 } | |
438 | |
439 init_from_file(_fd); | |
440 if (!validate()) { | |
441 return false; | |
442 } | |
443 | |
444 SharedReadOnlySize = _header._space[0]._capacity; | |
445 SharedReadWriteSize = _header._space[1]._capacity; | |
446 SharedMiscDataSize = _header._space[2]._capacity; | |
447 SharedMiscCodeSize = _header._space[3]._capacity; | |
448 return true; | |
449 } | |
450 | |
451 | |
452 bool FileMapInfo::validate() { | |
453 if (_header._version != current_version()) { | |
454 fail_continue("The shared archive file is the wrong version."); | |
455 return false; | |
456 } | |
457 if (_header._magic != (int)0xf00baba2) { | |
458 fail_continue("The shared archive file has a bad magic number."); | |
459 return false; | |
460 } | |
7174
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
461 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
|
462 get_header_version(header_version); |
fe81517cfb77
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
6882
diff
changeset
|
463 if (strncmp(_header._jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { |
0 | 464 fail_continue("The shared archive file was created by a different" |
465 " version or build of HotSpot."); | |
466 return false; | |
467 } | |
468 | |
469 // Cannot verify interpreter yet, as it can only be created after the GC | |
470 // heap has been initialized. | |
471 | |
472 if (_header._num_jars >= JVM_SHARED_JARS_MAX) { | |
473 fail_continue("Too many jar files to share."); | |
474 return false; | |
475 } | |
476 | |
477 // Build checks on classpath and jar files | |
478 int num_jars_now = 0; | |
479 ClassPathEntry *cpe = ClassLoader::classpath_entry(0); | |
480 for ( ; cpe != NULL; cpe = cpe->next()) { | |
481 | |
482 if (cpe->is_jar_file()) { | |
483 if (num_jars_now < _header._num_jars) { | |
484 | |
485 // Jar file - verify timestamp and file size. | |
486 struct stat st; | |
487 const char *path = cpe->name(); | |
488 if (os::stat(path, &st) != 0) { | |
489 fail_continue("Unable to open jar file %s.", path); | |
490 return false; | |
491 } | |
492 if (_header._jar[num_jars_now]._timestamp != st.st_mtime || | |
493 _header._jar[num_jars_now]._filesize != st.st_size) { | |
494 fail_continue("A jar file is not the one used while building" | |
495 " the shared archive file."); | |
496 return false; | |
497 } | |
498 } | |
499 ++num_jars_now; | |
500 } else { | |
501 | |
502 // If directories appear in boot classpath, they must be empty to | |
503 // avoid having to verify each individual class file. | |
504 const char* name = ((ClassPathDirEntry*)cpe)->name(); | |
505 if (!os::dir_is_empty(name)) { | |
506 fail_continue("Boot classpath directory %s is not empty.", name); | |
507 return false; | |
508 } | |
509 } | |
510 } | |
511 if (num_jars_now < _header._num_jars) { | |
512 fail_continue("The number of jar files in the boot classpath is" | |
513 " less than the number the shared archive was created with."); | |
514 return false; | |
515 } | |
516 | |
517 return true; | |
518 } | |
519 | |
520 // The following method is provided to see whether a given pointer | |
521 // falls in the mapped shared space. | |
522 // Param: | |
523 // p, The given pointer | |
524 // Return: | |
525 // True if the p is within the mapped shared space, otherwise, false. | |
526 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
|
527 for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
0 | 528 if (p >= _header._space[i]._base && |
529 p < _header._space[i]._base + _header._space[i]._used) { | |
530 return true; | |
531 } | |
532 } | |
533 | |
534 return false; | |
535 } |