Thu, 21 Aug 2014 13:57:51 -0700
8046070: Class Data Sharing clean up and refactoring
Summary: Cleaned up CDS to be more configurable, maintainable and extensible
Reviewed-by: dholmes, coleenp, acorn, mchung
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/sharedClassUtil.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionaryShared.hpp"
30 #include "classfile/altHashing.hpp"
31 #include "memory/filemap.hpp"
32 #include "memory/metadataFactory.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "oops/objArrayOop.hpp"
35 #include "runtime/arguments.hpp"
36 #include "runtime/java.hpp"
37 #include "runtime/os.hpp"
38 #include "services/memTracker.hpp"
39 #include "utilities/defaultStream.hpp"
41 # include <sys/stat.h>
42 # include <errno.h>
44 #ifndef O_BINARY // if defined (Win32) use binary files.
45 #define O_BINARY 0 // otherwise do nothing.
46 #endif
48 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
49 extern address JVM_FunctionAtStart();
50 extern address JVM_FunctionAtEnd();
52 // Complain and stop. All error conditions occurring during the writing of
53 // an archive file should stop the process. Unrecoverable errors during
54 // the reading of the archive file should stop the process.
56 static void fail(const char *msg, va_list ap) {
57 // This occurs very early during initialization: tty is not initialized.
58 jio_fprintf(defaultStream::error_stream(),
59 "An error has occurred while processing the"
60 " shared archive file.\n");
61 jio_vfprintf(defaultStream::error_stream(), msg, ap);
62 jio_fprintf(defaultStream::error_stream(), "\n");
63 // Do not change the text of the below message because some tests check for it.
64 vm_exit_during_initialization("Unable to use shared archive.", NULL);
65 }
68 void FileMapInfo::fail_stop(const char *msg, ...) {
69 va_list ap;
70 va_start(ap, msg);
71 fail(msg, ap); // Never returns.
72 va_end(ap); // for completeness.
73 }
76 // Complain and continue. Recoverable errors during the reading of the
77 // archive file may continue (with sharing disabled).
78 //
79 // If we continue, then disable shared spaces and close the file.
81 void FileMapInfo::fail_continue(const char *msg, ...) {
82 va_list ap;
83 va_start(ap, msg);
84 MetaspaceShared::set_archive_loading_failed();
85 if (PrintSharedArchiveAndExit && _validating_classpath_entry_table) {
86 // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
87 // do not validate, we can still continue "limping" to validate the remaining
88 // entries. No need to quit.
89 tty->print("[");
90 tty->vprint(msg, ap);
91 tty->print_cr("]");
92 } else {
93 if (RequireSharedSpaces) {
94 fail(msg, ap);
95 } else {
96 if (PrintSharedSpaces) {
97 tty->print_cr("UseSharedSpaces: %s", msg);
98 }
99 }
100 }
101 va_end(ap);
102 UseSharedSpaces = false;
103 assert(current_info() != NULL, "singleton must be registered");
104 current_info()->close();
105 }
107 // Fill in the fileMapInfo structure with data about this VM instance.
109 // This method copies the vm version info into header_version. If the version is too
110 // long then a truncated version, which has a hash code appended to it, is copied.
111 //
112 // Using a template enables this method to verify that header_version is an array of
113 // length JVM_IDENT_MAX. This ensures that the code that writes to the CDS file and
114 // the code that reads the CDS file will both use the same size buffer. Hence, will
115 // use identical truncation. This is necessary for matching of truncated versions.
116 template <int N> static void get_header_version(char (&header_version) [N]) {
117 assert(N == JVM_IDENT_MAX, "Bad header_version size");
119 const char *vm_version = VM_Version::internal_vm_info_string();
120 const int version_len = (int)strlen(vm_version);
122 if (version_len < (JVM_IDENT_MAX-1)) {
123 strcpy(header_version, vm_version);
125 } else {
126 // Get the hash value. Use a static seed because the hash needs to return the same
127 // value over multiple jvm invocations.
128 unsigned int hash = AltHashing::murmur3_32(8191, (const jbyte*)vm_version, version_len);
130 // Truncate the ident, saving room for the 8 hex character hash value.
131 strncpy(header_version, vm_version, JVM_IDENT_MAX-9);
133 // Append the hash code as eight hex digits.
134 sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
135 header_version[JVM_IDENT_MAX-1] = 0; // Null terminate.
136 }
137 }
139 FileMapInfo::FileMapInfo() {
140 assert(_current_info == NULL, "must be singleton"); // not thread safe
141 _current_info = this;
142 memset(this, 0, sizeof(FileMapInfo));
143 _file_offset = 0;
144 _file_open = false;
145 _header = SharedClassUtil::allocate_file_map_header();
146 _header->_version = _invalid_version;
147 }
149 FileMapInfo::~FileMapInfo() {
150 assert(_current_info == this, "must be singleton"); // not thread safe
151 _current_info = NULL;
152 }
154 void FileMapInfo::populate_header(size_t alignment) {
155 _header->populate(this, alignment);
156 }
158 size_t FileMapInfo::FileMapHeader::data_size() {
159 return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase);
160 }
162 void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
163 _magic = 0xf00baba2;
164 _version = _current_version;
165 _alignment = alignment;
166 _obj_alignment = ObjectAlignmentInBytes;
167 _classpath_entry_table_size = mapinfo->_classpath_entry_table_size;
168 _classpath_entry_table = mapinfo->_classpath_entry_table;
169 _classpath_entry_size = mapinfo->_classpath_entry_size;
171 // The following fields are for sanity checks for whether this archive
172 // will function correctly with this JVM and the bootclasspath it's
173 // invoked with.
175 // JVM version string ... changes on each build.
176 get_header_version(_jvm_ident);
177 }
179 void FileMapInfo::allocate_classpath_entry_table() {
180 int bytes = 0;
181 int count = 0;
182 char* strptr = NULL;
183 char* strptr_max = NULL;
184 Thread* THREAD = Thread::current();
186 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
187 size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
189 for (int pass=0; pass<2; pass++) {
190 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
192 for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
193 const char *name = cpe->name();
194 int name_bytes = (int)(strlen(name) + 1);
196 if (pass == 0) {
197 count ++;
198 bytes += (int)entry_size;
199 bytes += name_bytes;
200 if (TraceClassPaths || (TraceClassLoading && Verbose)) {
201 tty->print_cr("[Add main shared path (%s) %s]", (cpe->is_jar_file() ? "jar" : "dir"), name);
202 }
203 } else {
204 SharedClassPathEntry* ent = shared_classpath(cur_entry);
205 if (cpe->is_jar_file()) {
206 struct stat st;
207 if (os::stat(name, &st) != 0) {
208 // The file/dir must exist, or it would not have been added
209 // into ClassLoader::classpath_entry().
210 //
211 // If we can't access a jar file in the boot path, then we can't
212 // make assumptions about where classes get loaded from.
213 FileMapInfo::fail_stop("Unable to open jar file %s.", name);
214 }
216 EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
217 SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
218 } else {
219 ent->_filesize = -1;
220 if (!os::dir_is_empty(name)) {
221 ClassLoader::exit_with_path_failure("Cannot have non-empty directory in archived classpaths", name);
222 }
223 }
224 ent->_name = strptr;
225 if (strptr + name_bytes <= strptr_max) {
226 strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0.
227 strptr += name_bytes;
228 } else {
229 assert(0, "miscalculated buffer size");
230 }
231 }
232 }
234 if (pass == 0) {
235 EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
236 Array<u8>* arr = MetadataFactory::new_array<u8>(loader_data, (bytes + 7)/8, THREAD);
237 strptr = (char*)(arr->data());
238 strptr_max = strptr + bytes;
239 SharedClassPathEntry* table = (SharedClassPathEntry*)strptr;
240 strptr += entry_size * count;
242 _classpath_entry_table_size = count;
243 _classpath_entry_table = table;
244 _classpath_entry_size = entry_size;
245 }
246 }
247 }
249 bool FileMapInfo::validate_classpath_entry_table() {
250 _validating_classpath_entry_table = true;
252 int count = _header->_classpath_entry_table_size;
254 _classpath_entry_table = _header->_classpath_entry_table;
255 _classpath_entry_size = _header->_classpath_entry_size;
257 for (int i=0; i<count; i++) {
258 SharedClassPathEntry* ent = shared_classpath(i);
259 struct stat st;
260 const char* name = ent->_name;
261 bool ok = true;
262 if (TraceClassPaths || (TraceClassLoading && Verbose)) {
263 tty->print_cr("[Checking shared classpath entry: %s]", name);
264 }
265 if (os::stat(name, &st) != 0) {
266 fail_continue("Required classpath entry does not exist: %s", name);
267 ok = false;
268 } else if (ent->is_dir()) {
269 if (!os::dir_is_empty(name)) {
270 fail_continue("directory is not empty: %s", name);
271 ok = false;
272 }
273 } else {
274 if (ent->_timestamp != st.st_mtime ||
275 ent->_filesize != st.st_size) {
276 ok = false;
277 if (PrintSharedArchiveAndExit) {
278 fail_continue(ent->_timestamp != st.st_mtime ?
279 "Timestamp mismatch" :
280 "File size mismatch");
281 } else {
282 fail_continue("A jar file is not the one used while building"
283 " the shared archive file: %s", name);
284 }
285 }
286 }
287 if (ok) {
288 if (TraceClassPaths || (TraceClassLoading && Verbose)) {
289 tty->print_cr("[ok]");
290 }
291 } else if (!PrintSharedArchiveAndExit) {
292 _validating_classpath_entry_table = false;
293 return false;
294 }
295 }
297 _classpath_entry_table_size = _header->_classpath_entry_table_size;
298 _validating_classpath_entry_table = false;
299 return true;
300 }
303 // Read the FileMapInfo information from the file.
305 bool FileMapInfo::init_from_file(int fd) {
306 size_t sz = _header->data_size();
307 char* addr = _header->data();
308 size_t n = os::read(fd, addr, (unsigned int)sz);
309 if (n != sz) {
310 fail_continue("Unable to read the file header.");
311 return false;
312 }
313 if (_header->_version != current_version()) {
314 fail_continue("The shared archive file has the wrong version.");
315 return false;
316 }
317 _file_offset = (long)n;
319 size_t info_size = _header->_paths_misc_info_size;
320 _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);
321 if (_paths_misc_info == NULL) {
322 fail_continue("Unable to read the file header.");
323 return false;
324 }
325 n = os::read(fd, _paths_misc_info, (unsigned int)info_size);
326 if (n != info_size) {
327 fail_continue("Unable to read the shared path info header.");
328 FREE_C_HEAP_ARRAY(char, _paths_misc_info, mtClass);
329 _paths_misc_info = NULL;
330 return false;
331 }
333 _file_offset += (long)n;
334 return true;
335 }
338 // Read the FileMapInfo information from the file.
339 bool FileMapInfo::open_for_read() {
340 _full_path = Arguments::GetSharedArchivePath();
341 int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
342 if (fd < 0) {
343 if (errno == ENOENT) {
344 // Not locating the shared archive is ok.
345 fail_continue("Specified shared archive not found.");
346 } else {
347 fail_continue("Failed to open shared archive file (%s).",
348 strerror(errno));
349 }
350 return false;
351 }
353 _fd = fd;
354 _file_open = true;
355 return true;
356 }
359 // Write the FileMapInfo information to the file.
361 void FileMapInfo::open_for_write() {
362 _full_path = Arguments::GetSharedArchivePath();
363 if (PrintSharedSpaces) {
364 tty->print_cr("Dumping shared data to file: ");
365 tty->print_cr(" %s", _full_path);
366 }
368 #ifdef _WINDOWS // On Windows, need WRITE permission to remove the file.
369 chmod(_full_path, _S_IREAD | _S_IWRITE);
370 #endif
372 // Use remove() to delete the existing file because, on Unix, this will
373 // allow processes that have it open continued access to the file.
374 remove(_full_path);
375 int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
376 if (fd < 0) {
377 fail_stop("Unable to create shared archive file %s.", _full_path);
378 }
379 _fd = fd;
380 _file_offset = 0;
381 _file_open = true;
382 }
385 // Write the header to the file, seek to the next allocation boundary.
387 void FileMapInfo::write_header() {
388 int info_size = ClassLoader::get_shared_paths_misc_info_size();
390 _header->_paths_misc_info_size = info_size;
392 align_file_position();
393 size_t sz = _header->data_size();
394 char* addr = _header->data();
395 write_bytes(addr, (int)sz); // skip the C++ vtable
396 write_bytes(ClassLoader::get_shared_paths_misc_info(), info_size);
397 align_file_position();
398 }
401 // Dump shared spaces to file.
403 void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) {
404 align_file_position();
405 size_t used = space->used_bytes_slow(Metaspace::NonClassType);
406 size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType);
407 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
408 write_region(i, (char*)space->bottom(), used, capacity, read_only, false);
409 }
412 // Dump region to file.
414 void FileMapInfo::write_region(int region, char* base, size_t size,
415 size_t capacity, bool read_only,
416 bool allow_exec) {
417 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region];
419 if (_file_open) {
420 guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
421 if (PrintSharedSpaces) {
422 tty->print_cr("Shared file region %d: 0x%6x bytes, addr " INTPTR_FORMAT
423 " file offset 0x%6x", region, size, base, _file_offset);
424 }
425 } else {
426 si->_file_offset = _file_offset;
427 }
428 si->_base = base;
429 si->_used = size;
430 si->_capacity = capacity;
431 si->_read_only = read_only;
432 si->_allow_exec = allow_exec;
433 write_bytes_aligned(base, (int)size);
434 }
437 // Dump bytes to file -- at the current file position.
439 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
440 if (_file_open) {
441 int n = ::write(_fd, buffer, nbytes);
442 if (n != nbytes) {
443 // It is dangerous to leave the corrupted shared archive file around,
444 // close and remove the file. See bug 6372906.
445 close();
446 remove(_full_path);
447 fail_stop("Unable to write to shared archive file.", NULL);
448 }
449 }
450 _file_offset += nbytes;
451 }
454 // Align file position to an allocation unit boundary.
456 void FileMapInfo::align_file_position() {
457 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity());
458 if (new_file_offset != _file_offset) {
459 _file_offset = new_file_offset;
460 if (_file_open) {
461 // Seek one byte back from the target and write a byte to insure
462 // that the written file is the correct length.
463 _file_offset -= 1;
464 if (lseek(_fd, _file_offset, SEEK_SET) < 0) {
465 fail_stop("Unable to seek.", NULL);
466 }
467 char zero = 0;
468 write_bytes(&zero, 1);
469 }
470 }
471 }
474 // Dump bytes to file -- at the current file position.
476 void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
477 align_file_position();
478 write_bytes(buffer, nbytes);
479 align_file_position();
480 }
483 // Close the shared archive file. This does NOT unmap mapped regions.
485 void FileMapInfo::close() {
486 if (_file_open) {
487 if (::close(_fd) < 0) {
488 fail_stop("Unable to close the shared archive file.");
489 }
490 _file_open = false;
491 _fd = -1;
492 }
493 }
496 // JVM/TI RedefineClasses() support:
497 // Remap the shared readonly space to shared readwrite, private.
498 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
499 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0];
500 if (!si->_read_only) {
501 // the space is already readwrite so we are done
502 return true;
503 }
504 size_t used = si->_used;
505 size_t size = align_size_up(used, os::vm_allocation_granularity());
506 if (!open_for_read()) {
507 return false;
508 }
509 char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
510 si->_base, size, false /* !read_only */,
511 si->_allow_exec);
512 close();
513 if (base == NULL) {
514 fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
515 return false;
516 }
517 if (base != si->_base) {
518 fail_continue("Unable to remap shared readonly space at required address.");
519 return false;
520 }
521 si->_read_only = false;
522 return true;
523 }
525 // Map the whole region at once, assumed to be allocated contiguously.
526 ReservedSpace FileMapInfo::reserve_shared_memory() {
527 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0];
528 char* requested_addr = si->_base;
530 size_t size = FileMapInfo::shared_spaces_size();
532 // Reserve the space first, then map otherwise map will go right over some
533 // other reserved memory (like the code cache).
534 ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
535 if (!rs.is_reserved()) {
536 fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr));
537 return rs;
538 }
539 // the reserved virtual memory is for mapping class data sharing archive
540 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
542 return rs;
543 }
545 // Memory map a region in the address space.
546 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"};
548 char* FileMapInfo::map_region(int i) {
549 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
550 size_t used = si->_used;
551 size_t alignment = os::vm_allocation_granularity();
552 size_t size = align_size_up(used, alignment);
553 char *requested_addr = si->_base;
555 // map the contents of the CDS archive in this memory
556 char *base = os::map_memory(_fd, _full_path, si->_file_offset,
557 requested_addr, size, si->_read_only,
558 si->_allow_exec);
559 if (base == NULL || base != si->_base) {
560 fail_continue(err_msg("Unable to map %s shared space at required address.", shared_region_name[i]));
561 return NULL;
562 }
563 #ifdef _WINDOWS
564 // This call is Windows-only because the memory_type gets recorded for the other platforms
565 // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
566 MemTracker::record_virtual_memory_type((address)base, mtClassShared);
567 #endif
568 return base;
569 }
572 // Unmap a memory region in the address space.
574 void FileMapInfo::unmap_region(int i) {
575 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
576 size_t used = si->_used;
577 size_t size = align_size_up(used, os::vm_allocation_granularity());
578 if (!os::unmap_memory(si->_base, size)) {
579 fail_stop("Unable to unmap shared space.");
580 }
581 }
584 void FileMapInfo::assert_mark(bool check) {
585 if (!check) {
586 fail_stop("Mark mismatch while restoring from shared file.", NULL);
587 }
588 }
591 FileMapInfo* FileMapInfo::_current_info = NULL;
592 SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL;
593 int FileMapInfo::_classpath_entry_table_size = 0;
594 size_t FileMapInfo::_classpath_entry_size = 0x1234baad;
595 bool FileMapInfo::_validating_classpath_entry_table = false;
597 // Open the shared archive file, read and validate the header
598 // information (version, boot classpath, etc.). If initialization
599 // fails, shared spaces are disabled and the file is closed. [See
600 // fail_continue.]
601 //
602 // Validation of the archive is done in two steps:
603 //
604 // [1] validate_header() - done here. This checks the header, including _paths_misc_info.
605 // [2] validate_classpath_entry_table - this is done later, because the table is in the RW
606 // region of the archive, which is not mapped yet.
607 bool FileMapInfo::initialize() {
608 assert(UseSharedSpaces, "UseSharedSpaces expected.");
610 if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
611 fail_continue("Tool agent requires sharing to be disabled.");
612 return false;
613 }
615 if (!open_for_read()) {
616 return false;
617 }
619 init_from_file(_fd);
620 if (!validate_header()) {
621 return false;
622 }
624 SharedReadOnlySize = _header->_space[0]._capacity;
625 SharedReadWriteSize = _header->_space[1]._capacity;
626 SharedMiscDataSize = _header->_space[2]._capacity;
627 SharedMiscCodeSize = _header->_space[3]._capacity;
628 return true;
629 }
631 bool FileMapInfo::FileMapHeader::validate() {
632 if (_version != current_version()) {
633 FileMapInfo::fail_continue("The shared archive file is the wrong version.");
634 return false;
635 }
636 if (_magic != (int)0xf00baba2) {
637 FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
638 return false;
639 }
640 char header_version[JVM_IDENT_MAX];
641 get_header_version(header_version);
642 if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
643 if (TraceClassPaths) {
644 tty->print_cr("Expected: %s", header_version);
645 tty->print_cr("Actual: %s", _jvm_ident);
646 }
647 FileMapInfo::fail_continue("The shared archive file was created by a different"
648 " version or build of HotSpot");
649 return false;
650 }
651 if (_obj_alignment != ObjectAlignmentInBytes) {
652 FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
653 " does not equal the current ObjectAlignmentInBytes of %d.",
654 _obj_alignment, ObjectAlignmentInBytes);
655 return false;
656 }
658 return true;
659 }
661 bool FileMapInfo::validate_header() {
662 bool status = _header->validate();
664 if (status) {
665 if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
666 if (!PrintSharedArchiveAndExit) {
667 fail_continue("shared class paths mismatch (hint: enable -XX:+TraceClassPaths to diagnose the failure)");
668 status = false;
669 }
670 }
671 }
673 if (_paths_misc_info != NULL) {
674 FREE_C_HEAP_ARRAY(char, _paths_misc_info, mtClass);
675 _paths_misc_info = NULL;
676 }
677 return status;
678 }
680 // The following method is provided to see whether a given pointer
681 // falls in the mapped shared space.
682 // Param:
683 // p, The given pointer
684 // Return:
685 // True if the p is within the mapped shared space, otherwise, false.
686 bool FileMapInfo::is_in_shared_space(const void* p) {
687 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
688 if (p >= _header->_space[i]._base &&
689 p < _header->_space[i]._base + _header->_space[i]._used) {
690 return true;
691 }
692 }
694 return false;
695 }
697 void FileMapInfo::print_shared_spaces() {
698 gclog_or_tty->print_cr("Shared Spaces:");
699 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
700 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
701 gclog_or_tty->print(" %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
702 shared_region_name[i],
703 si->_base, si->_base + si->_used);
704 }
705 }
707 // Unmap mapped regions of shared space.
708 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
709 FileMapInfo *map_info = FileMapInfo::current_info();
710 if (map_info) {
711 map_info->fail_continue(msg);
712 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
713 if (map_info->_header->_space[i]._base != NULL) {
714 map_info->unmap_region(i);
715 map_info->_header->_space[i]._base = NULL;
716 }
717 }
718 } else if (DumpSharedSpaces) {
719 fail_stop(msg, NULL);
720 }
721 }