author | cjplummer |
Fri, 05 Jun 2015 13:40:09 -0700 | |
changeset 31332 | dc17890f352d |
parent 28950 | 693ae3d5e1ff |
child 31345 | 1bba15125d8d |
permissions | -rw-r--r-- |
1 | 1 |
/* |
28950
693ae3d5e1ff
8072694: Need errno info when CDS archive creation fails
hseigel
parents:
28023
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, 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" |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
27 |
#include "classfile/sharedClassUtil.hpp" |
7397 | 28 |
#include "classfile/symbolTable.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
29 |
#include "classfile/systemDictionaryShared.hpp" |
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
30 |
#include "classfile/altHashing.hpp" |
7397 | 31 |
#include "memory/filemap.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
32 |
#include "memory/metadataFactory.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
33 |
#include "memory/oopFactory.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
34 |
#include "oops/objArrayOop.hpp" |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
35 |
#include "prims/jvmtiExport.hpp" |
7397 | 36 |
#include "runtime/arguments.hpp" |
37 |
#include "runtime/java.hpp" |
|
38 |
#include "runtime/os.hpp" |
|
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
24424
diff
changeset
|
39 |
#include "runtime/vm_version.hpp" |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13728
diff
changeset
|
40 |
#include "services/memTracker.hpp" |
7397 | 41 |
#include "utilities/defaultStream.hpp" |
42 |
||
1 | 43 |
# include <sys/stat.h> |
44 |
# include <errno.h> |
|
45 |
||
46 |
#ifndef O_BINARY // if defined (Win32) use binary files. |
|
47 |
#define O_BINARY 0 // otherwise do nothing. |
|
48 |
#endif |
|
49 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23186
diff
changeset
|
50 |
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
1 | 51 |
extern address JVM_FunctionAtStart(); |
52 |
extern address JVM_FunctionAtEnd(); |
|
53 |
||
2131 | 54 |
// Complain and stop. All error conditions occurring during the writing of |
1 | 55 |
// an archive file should stop the process. Unrecoverable errors during |
56 |
// the reading of the archive file should stop the process. |
|
57 |
||
58 |
static void fail(const char *msg, va_list ap) { |
|
59 |
// This occurs very early during initialization: tty is not initialized. |
|
60 |
jio_fprintf(defaultStream::error_stream(), |
|
2131 | 61 |
"An error has occurred while processing the" |
1 | 62 |
" shared archive file.\n"); |
63 |
jio_vfprintf(defaultStream::error_stream(), msg, ap); |
|
64 |
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
|
65 |
// Do not change the text of the below message because some tests check for it. |
1 | 66 |
vm_exit_during_initialization("Unable to use shared archive.", NULL); |
67 |
} |
|
68 |
||
69 |
||
70 |
void FileMapInfo::fail_stop(const char *msg, ...) { |
|
71 |
va_list ap; |
|
72 |
va_start(ap, msg); |
|
73 |
fail(msg, ap); // Never returns. |
|
74 |
va_end(ap); // for completeness. |
|
75 |
} |
|
76 |
||
77 |
||
78 |
// Complain and continue. Recoverable errors during the reading of the |
|
79 |
// archive file may continue (with sharing disabled). |
|
80 |
// |
|
81 |
// If we continue, then disable shared spaces and close the file. |
|
82 |
||
83 |
void FileMapInfo::fail_continue(const char *msg, ...) { |
|
84 |
va_list ap; |
|
85 |
va_start(ap, msg); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
86 |
MetaspaceShared::set_archive_loading_failed(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
87 |
if (PrintSharedArchiveAndExit && _validating_classpath_entry_table) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
88 |
// If we are doing PrintSharedArchiveAndExit and some of the classpath entries |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
89 |
// do not validate, we can still continue "limping" to validate the remaining |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
90 |
// entries. No need to quit. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
91 |
tty->print("["); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
92 |
tty->vprint(msg, ap); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
93 |
tty->print_cr("]"); |
23186
9396c6fb571b
8033990: Add message to verbose output to indicate when JVM was unable to use shared archive (with -Xshare:auto)
mseledtsov
parents:
19707
diff
changeset
|
94 |
} else { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
95 |
if (RequireSharedSpaces) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
96 |
fail(msg, ap); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
97 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
98 |
if (PrintSharedSpaces) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
99 |
tty->print_cr("UseSharedSpaces: %s", msg); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
100 |
} |
23186
9396c6fb571b
8033990: Add message to verbose output to indicate when JVM was unable to use shared archive (with -Xshare:auto)
mseledtsov
parents:
19707
diff
changeset
|
101 |
} |
28017
84009002b566
8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
27880
diff
changeset
|
102 |
UseSharedSpaces = false; |
84009002b566
8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
27880
diff
changeset
|
103 |
assert(current_info() != NULL, "singleton must be registered"); |
84009002b566
8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
27880
diff
changeset
|
104 |
current_info()->close(); |
1 | 105 |
} |
106 |
va_end(ap); |
|
107 |
} |
|
108 |
||
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
109 |
// Fill in the fileMapInfo structure with data about this VM instance. |
1 | 110 |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
111 |
// 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
|
112 |
// 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
|
113 |
// |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
114 |
// 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
|
115 |
// 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
|
116 |
// 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
|
117 |
// 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
|
118 |
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
|
119 |
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
|
120 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
124 |
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
|
125 |
strcpy(header_version, vm_version); |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
126 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
127 |
} else { |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
128 |
// 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
|
129 |
// value over multiple jvm invocations. |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
130 |
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
|
131 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
132 |
// 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
|
133 |
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
|
134 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
135 |
// 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
|
136 |
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
|
137 |
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
|
138 |
} |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
139 |
} |
1 | 140 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
141 |
FileMapInfo::FileMapInfo() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
142 |
assert(_current_info == NULL, "must be singleton"); // not thread safe |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
143 |
_current_info = this; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
144 |
memset(this, 0, sizeof(FileMapInfo)); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
145 |
_file_offset = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
146 |
_file_open = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
147 |
_header = SharedClassUtil::allocate_file_map_header(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
148 |
_header->_version = _invalid_version; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
149 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
150 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
151 |
FileMapInfo::~FileMapInfo() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
152 |
assert(_current_info == this, "must be singleton"); // not thread safe |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
153 |
_current_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
154 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
155 |
|
1 | 156 |
void FileMapInfo::populate_header(size_t alignment) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
157 |
_header->populate(this, alignment); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
158 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
159 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
160 |
size_t FileMapInfo::FileMapHeader::data_size() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
161 |
return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
162 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
163 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
164 |
void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
165 |
_magic = 0xf00baba2; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
166 |
_version = _current_version; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
167 |
_alignment = alignment; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
168 |
_obj_alignment = ObjectAlignmentInBytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
169 |
_classpath_entry_table_size = mapinfo->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
170 |
_classpath_entry_table = mapinfo->_classpath_entry_table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
171 |
_classpath_entry_size = mapinfo->_classpath_entry_size; |
1 | 172 |
|
173 |
// The following fields are for sanity checks for whether this archive |
|
174 |
// will function correctly with this JVM and the bootclasspath it's |
|
175 |
// invoked with. |
|
176 |
||
177 |
// JVM version string ... changes on each build. |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
178 |
get_header_version(_jvm_ident); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
179 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
180 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
181 |
void FileMapInfo::allocate_classpath_entry_table() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
182 |
int bytes = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
183 |
int count = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
184 |
char* strptr = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
185 |
char* strptr_max = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
186 |
Thread* THREAD = Thread::current(); |
1 | 187 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
188 |
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
189 |
size_t entry_size = SharedClassUtil::shared_class_path_entry_size(); |
1 | 190 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
191 |
for (int pass=0; pass<2; pass++) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
192 |
ClassPathEntry *cpe = ClassLoader::classpath_entry(0); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
193 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
194 |
for (int cur_entry = 0 ; cpe != NULL; cpe = cpe->next(), cur_entry++) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
195 |
const char *name = cpe->name(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
196 |
int name_bytes = (int)(strlen(name) + 1); |
1 | 197 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
198 |
if (pass == 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
199 |
count ++; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
200 |
bytes += (int)entry_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
201 |
bytes += name_bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
202 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
203 |
tty->print_cr("[Add main shared path (%s) %s]", (cpe->is_jar_file() ? "jar" : "dir"), name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
204 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
205 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
206 |
SharedClassPathEntry* ent = shared_classpath(cur_entry); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
207 |
if (cpe->is_jar_file()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
208 |
struct stat st; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
209 |
if (os::stat(name, &st) != 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
210 |
// The file/dir must exist, or it would not have been added |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
211 |
// into ClassLoader::classpath_entry(). |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
212 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
213 |
// If we can't access a jar file in the boot path, then we can't |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
214 |
// make assumptions about where classes get loaded from. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
215 |
FileMapInfo::fail_stop("Unable to open jar file %s.", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
216 |
} |
1 | 217 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
218 |
EXCEPTION_MARK; // The following call should never throw, but would exit VM on error. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
219 |
SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
220 |
} else { |
27562 | 221 |
struct stat st; |
222 |
if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) { |
|
223 |
if (!os::dir_is_empty(name)) { |
|
224 |
ClassLoader::exit_with_path_failure("Cannot have non-empty directory in archived classpaths", name); |
|
225 |
} |
|
226 |
ent->_filesize = -1; |
|
227 |
} else { |
|
228 |
ent->_filesize = -2; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
229 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
230 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
231 |
ent->_name = strptr; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
232 |
if (strptr + name_bytes <= strptr_max) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
233 |
strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
234 |
strptr += name_bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
235 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
236 |
assert(0, "miscalculated buffer size"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
237 |
} |
1 | 238 |
} |
239 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
240 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
241 |
if (pass == 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
242 |
EXCEPTION_MARK; // The following call should never throw, but would exit VM on error. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
243 |
Array<u8>* arr = MetadataFactory::new_array<u8>(loader_data, (bytes + 7)/8, THREAD); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
244 |
strptr = (char*)(arr->data()); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
245 |
strptr_max = strptr + bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
246 |
SharedClassPathEntry* table = (SharedClassPathEntry*)strptr; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
247 |
strptr += entry_size * count; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
248 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
249 |
_classpath_entry_table_size = count; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
250 |
_classpath_entry_table = table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
251 |
_classpath_entry_size = entry_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
252 |
} |
1 | 253 |
} |
254 |
} |
|
255 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
256 |
bool FileMapInfo::validate_classpath_entry_table() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
257 |
_validating_classpath_entry_table = true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
258 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
259 |
int count = _header->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
260 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
261 |
_classpath_entry_table = _header->_classpath_entry_table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
262 |
_classpath_entry_size = _header->_classpath_entry_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
263 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
264 |
for (int i=0; i<count; i++) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
265 |
SharedClassPathEntry* ent = shared_classpath(i); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
266 |
struct stat st; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
267 |
const char* name = ent->_name; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
268 |
bool ok = true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
269 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
270 |
tty->print_cr("[Checking shared classpath entry: %s]", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
271 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
272 |
if (os::stat(name, &st) != 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
273 |
fail_continue("Required classpath entry does not exist: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
274 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
275 |
} else if (ent->is_dir()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
276 |
if (!os::dir_is_empty(name)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
277 |
fail_continue("directory is not empty: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
278 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
279 |
} |
27562 | 280 |
} else if (ent->is_jar()) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
281 |
if (ent->_timestamp != st.st_mtime || |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
282 |
ent->_filesize != st.st_size) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
283 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
284 |
if (PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
285 |
fail_continue(ent->_timestamp != st.st_mtime ? |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
286 |
"Timestamp mismatch" : |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
287 |
"File size mismatch"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
288 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
289 |
fail_continue("A jar file is not the one used while building" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
290 |
" the shared archive file: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
291 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
292 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
293 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
294 |
if (ok) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
295 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
296 |
tty->print_cr("[ok]"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
297 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
298 |
} else if (!PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
299 |
_validating_classpath_entry_table = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
300 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
301 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
302 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
303 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
304 |
_classpath_entry_table_size = _header->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
305 |
_validating_classpath_entry_table = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
306 |
return true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
307 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
308 |
|
1 | 309 |
|
310 |
// Read the FileMapInfo information from the file. |
|
311 |
||
312 |
bool FileMapInfo::init_from_file(int fd) { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
313 |
size_t sz = _header->data_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
314 |
char* addr = _header->data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
315 |
size_t n = os::read(fd, addr, (unsigned int)sz); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
316 |
if (n != sz) { |
1 | 317 |
fail_continue("Unable to read the file header."); |
318 |
return false; |
|
319 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
320 |
if (_header->_version != current_version()) { |
1 | 321 |
fail_continue("The shared archive file has the wrong version."); |
322 |
return false; |
|
323 |
} |
|
324 |
_file_offset = (long)n; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
325 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
326 |
size_t info_size = _header->_paths_misc_info_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
327 |
_paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
328 |
if (_paths_misc_info == NULL) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
329 |
fail_continue("Unable to read the file header."); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
330 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
331 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
332 |
n = os::read(fd, _paths_misc_info, (unsigned int)info_size); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
333 |
if (n != info_size) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
334 |
fail_continue("Unable to read the shared path info header."); |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27025
diff
changeset
|
335 |
FREE_C_HEAP_ARRAY(char, _paths_misc_info); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
336 |
_paths_misc_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
337 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
338 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
339 |
|
27025 | 340 |
size_t len = lseek(fd, 0, SEEK_END); |
341 |
struct FileMapInfo::FileMapHeader::space_info* si = |
|
342 |
&_header->_space[MetaspaceShared::mc]; |
|
343 |
if (si->_file_offset >= len || len - si->_file_offset < si->_used) { |
|
344 |
fail_continue("The shared archive file has been truncated."); |
|
345 |
return false; |
|
346 |
} |
|
347 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
348 |
_file_offset += (long)n; |
1 | 349 |
return true; |
350 |
} |
|
351 |
||
352 |
||
353 |
// Read the FileMapInfo information from the file. |
|
354 |
bool FileMapInfo::open_for_read() { |
|
355 |
_full_path = Arguments::GetSharedArchivePath(); |
|
356 |
int fd = open(_full_path, O_RDONLY | O_BINARY, 0); |
|
357 |
if (fd < 0) { |
|
358 |
if (errno == ENOENT) { |
|
359 |
// Not locating the shared archive is ok. |
|
360 |
fail_continue("Specified shared archive not found."); |
|
361 |
} else { |
|
362 |
fail_continue("Failed to open shared archive file (%s).", |
|
363 |
strerror(errno)); |
|
364 |
} |
|
365 |
return false; |
|
366 |
} |
|
367 |
||
368 |
_fd = fd; |
|
369 |
_file_open = true; |
|
370 |
return true; |
|
371 |
} |
|
372 |
||
373 |
||
374 |
// Write the FileMapInfo information to the file. |
|
375 |
||
376 |
void FileMapInfo::open_for_write() { |
|
377 |
_full_path = Arguments::GetSharedArchivePath(); |
|
378 |
if (PrintSharedSpaces) { |
|
379 |
tty->print_cr("Dumping shared data to file: "); |
|
380 |
tty->print_cr(" %s", _full_path); |
|
381 |
} |
|
382 |
||
15461
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
383 |
#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
|
384 |
chmod(_full_path, _S_IREAD | _S_IWRITE); |
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
385 |
#endif |
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
386 |
|
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
387 |
// 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
|
388 |
// allow processes that have it open continued access to the file. |
1 | 389 |
remove(_full_path); |
390 |
int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444); |
|
391 |
if (fd < 0) { |
|
28950
693ae3d5e1ff
8072694: Need errno info when CDS archive creation fails
hseigel
parents:
28023
diff
changeset
|
392 |
fail_stop("Unable to create shared archive file %s: (%s).", _full_path, |
693ae3d5e1ff
8072694: Need errno info when CDS archive creation fails
hseigel
parents:
28023
diff
changeset
|
393 |
strerror(errno)); |
1 | 394 |
} |
395 |
_fd = fd; |
|
396 |
_file_offset = 0; |
|
397 |
_file_open = true; |
|
398 |
} |
|
399 |
||
400 |
||
401 |
// Write the header to the file, seek to the next allocation boundary. |
|
402 |
||
403 |
void FileMapInfo::write_header() { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
404 |
int info_size = ClassLoader::get_shared_paths_misc_info_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
405 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
406 |
_header->_paths_misc_info_size = info_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
407 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
408 |
align_file_position(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
409 |
size_t sz = _header->data_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
410 |
char* addr = _header->data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
411 |
write_bytes(addr, (int)sz); // skip the C++ vtable |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
412 |
write_bytes(ClassLoader::get_shared_paths_misc_info(), info_size); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
413 |
align_file_position(); |
1 | 414 |
} |
415 |
||
416 |
||
417 |
// Dump shared spaces to file. |
|
418 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
419 |
void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) { |
1 | 420 |
align_file_position(); |
17109
90e6c31bbbe4
8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents:
16430
diff
changeset
|
421 |
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
|
422 |
size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
423 |
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
|
424 |
write_region(i, (char*)space->bottom(), used, capacity, read_only, false); |
1 | 425 |
} |
426 |
||
427 |
||
428 |
// Dump region to file. |
|
429 |
||
430 |
void FileMapInfo::write_region(int region, char* base, size_t size, |
|
431 |
size_t capacity, bool read_only, |
|
432 |
bool allow_exec) { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
433 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region]; |
1 | 434 |
|
435 |
if (_file_open) { |
|
436 |
guarantee(si->_file_offset == _file_offset, "file offset mismatch."); |
|
437 |
if (PrintSharedSpaces) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
438 |
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
|
439 |
" file offset 0x%6x", region, size, base, _file_offset); |
1 | 440 |
} |
441 |
} else { |
|
442 |
si->_file_offset = _file_offset; |
|
443 |
} |
|
444 |
si->_base = base; |
|
445 |
si->_used = size; |
|
446 |
si->_capacity = capacity; |
|
447 |
si->_read_only = read_only; |
|
448 |
si->_allow_exec = allow_exec; |
|
27025 | 449 |
si->_crc = ClassLoader::crc32(0, base, (jint)size); |
1 | 450 |
write_bytes_aligned(base, (int)size); |
451 |
} |
|
452 |
||
453 |
||
454 |
// Dump bytes to file -- at the current file position. |
|
455 |
||
456 |
void FileMapInfo::write_bytes(const void* buffer, int nbytes) { |
|
457 |
if (_file_open) { |
|
458 |
int n = ::write(_fd, buffer, nbytes); |
|
459 |
if (n != nbytes) { |
|
460 |
// It is dangerous to leave the corrupted shared archive file around, |
|
461 |
// close and remove the file. See bug 6372906. |
|
462 |
close(); |
|
463 |
remove(_full_path); |
|
26296 | 464 |
fail_stop("Unable to write to shared archive file."); |
1 | 465 |
} |
466 |
} |
|
467 |
_file_offset += nbytes; |
|
468 |
} |
|
469 |
||
470 |
||
471 |
// Align file position to an allocation unit boundary. |
|
472 |
||
473 |
void FileMapInfo::align_file_position() { |
|
27025 | 474 |
size_t new_file_offset = align_size_up(_file_offset, |
475 |
os::vm_allocation_granularity()); |
|
1 | 476 |
if (new_file_offset != _file_offset) { |
477 |
_file_offset = new_file_offset; |
|
478 |
if (_file_open) { |
|
479 |
// Seek one byte back from the target and write a byte to insure |
|
480 |
// that the written file is the correct length. |
|
481 |
_file_offset -= 1; |
|
27025 | 482 |
if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) { |
26296 | 483 |
fail_stop("Unable to seek."); |
1 | 484 |
} |
485 |
char zero = 0; |
|
486 |
write_bytes(&zero, 1); |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
||
492 |
// Dump bytes to file -- at the current file position. |
|
493 |
||
494 |
void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) { |
|
495 |
align_file_position(); |
|
496 |
write_bytes(buffer, nbytes); |
|
497 |
align_file_position(); |
|
498 |
} |
|
499 |
||
500 |
||
501 |
// Close the shared archive file. This does NOT unmap mapped regions. |
|
502 |
||
503 |
void FileMapInfo::close() { |
|
504 |
if (_file_open) { |
|
505 |
if (::close(_fd) < 0) { |
|
506 |
fail_stop("Unable to close the shared archive file."); |
|
507 |
} |
|
508 |
_file_open = false; |
|
509 |
_fd = -1; |
|
510 |
} |
|
511 |
} |
|
512 |
||
513 |
||
514 |
// JVM/TI RedefineClasses() support: |
|
515 |
// Remap the shared readonly space to shared readwrite, private. |
|
516 |
bool FileMapInfo::remap_shared_readonly_as_readwrite() { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
517 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0]; |
1 | 518 |
if (!si->_read_only) { |
519 |
// the space is already readwrite so we are done |
|
520 |
return true; |
|
521 |
} |
|
522 |
size_t used = si->_used; |
|
523 |
size_t size = align_size_up(used, os::vm_allocation_granularity()); |
|
524 |
if (!open_for_read()) { |
|
525 |
return false; |
|
526 |
} |
|
527 |
char *base = os::remap_memory(_fd, _full_path, si->_file_offset, |
|
528 |
si->_base, size, false /* !read_only */, |
|
529 |
si->_allow_exec); |
|
530 |
close(); |
|
531 |
if (base == NULL) { |
|
532 |
fail_continue("Unable to remap shared readonly space (errno=%d).", errno); |
|
533 |
return false; |
|
534 |
} |
|
535 |
if (base != si->_base) { |
|
536 |
fail_continue("Unable to remap shared readonly space at required address."); |
|
537 |
return false; |
|
538 |
} |
|
539 |
si->_read_only = false; |
|
540 |
return true; |
|
541 |
} |
|
542 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
543 |
// 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
|
544 |
ReservedSpace FileMapInfo::reserve_shared_memory() { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
545 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0]; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
546 |
char* requested_addr = si->_base; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
547 |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
548 |
size_t size = FileMapInfo::shared_spaces_size(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
549 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
550 |
// 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
|
551 |
// other reserved memory (like the code cache). |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
552 |
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
|
553 |
if (!rs.is_reserved()) { |
26296 | 554 |
fail_continue("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
|
555 |
return rs; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
556 |
} |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13728
diff
changeset
|
557 |
// 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
|
558 |
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
|
559 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
560 |
return rs; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
561 |
} |
1 | 562 |
|
563 |
// 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
|
564 |
static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"}; |
1 | 565 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
566 |
char* FileMapInfo::map_region(int i) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
567 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
1 | 568 |
size_t used = si->_used; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
569 |
size_t alignment = os::vm_allocation_granularity(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
570 |
size_t size = align_size_up(used, alignment); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
571 |
char *requested_addr = si->_base; |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
572 |
bool read_only; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
573 |
|
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
574 |
// If a tool agent is in use (debugging enabled), we must map the address space RW |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
575 |
if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) { |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
576 |
read_only = false; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
577 |
} else { |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
578 |
read_only = si->_read_only; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
579 |
} |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
580 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
581 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
582 |
// map the contents of the CDS archive in this memory |
1 | 583 |
char *base = os::map_memory(_fd, _full_path, si->_file_offset, |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
584 |
requested_addr, size, read_only, |
1 | 585 |
si->_allow_exec); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
586 |
if (base == NULL || base != si->_base) { |
26296 | 587 |
fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]); |
1 | 588 |
return NULL; |
589 |
} |
|
15100
0ae85ac7c8b0
8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents:
14577
diff
changeset
|
590 |
#ifdef _WINDOWS |
0ae85ac7c8b0
8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents:
14577
diff
changeset
|
591 |
// 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
|
592 |
// 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
|
593 |
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
|
594 |
#endif |
1 | 595 |
return base; |
596 |
} |
|
597 |
||
27025 | 598 |
bool FileMapInfo::verify_region_checksum(int i) { |
599 |
if (!VerifySharedSpaces) { |
|
600 |
return true; |
|
601 |
} |
|
602 |
const char* buf = _header->_space[i]._base; |
|
603 |
size_t sz = _header->_space[i]._used; |
|
604 |
int crc = ClassLoader::crc32(0, buf, (jint)sz); |
|
605 |
if (crc != _header->_space[i]._crc) { |
|
606 |
fail_continue("Checksum verification failed."); |
|
607 |
return false; |
|
608 |
} |
|
609 |
return true; |
|
610 |
} |
|
1 | 611 |
|
612 |
// Unmap a memory region in the address space. |
|
613 |
||
614 |
void FileMapInfo::unmap_region(int i) { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
615 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
1 | 616 |
size_t used = si->_used; |
617 |
size_t size = align_size_up(used, os::vm_allocation_granularity()); |
|
618 |
if (!os::unmap_memory(si->_base, size)) { |
|
619 |
fail_stop("Unable to unmap shared space."); |
|
620 |
} |
|
621 |
} |
|
622 |
||
623 |
||
624 |
void FileMapInfo::assert_mark(bool check) { |
|
625 |
if (!check) { |
|
26296 | 626 |
fail_stop("Mark mismatch while restoring from shared file."); |
1 | 627 |
} |
628 |
} |
|
629 |
||
630 |
||
631 |
FileMapInfo* FileMapInfo::_current_info = NULL; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
632 |
SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
633 |
int FileMapInfo::_classpath_entry_table_size = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
634 |
size_t FileMapInfo::_classpath_entry_size = 0x1234baad; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
635 |
bool FileMapInfo::_validating_classpath_entry_table = false; |
1 | 636 |
|
637 |
// Open the shared archive file, read and validate the header |
|
638 |
// information (version, boot classpath, etc.). If initialization |
|
639 |
// fails, shared spaces are disabled and the file is closed. [See |
|
640 |
// fail_continue.] |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
641 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
642 |
// Validation of the archive is done in two steps: |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
643 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
644 |
// [1] validate_header() - done here. This checks the header, including _paths_misc_info. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
645 |
// [2] validate_classpath_entry_table - this is done later, because the table is in the RW |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
646 |
// region of the archive, which is not mapped yet. |
1 | 647 |
bool FileMapInfo::initialize() { |
648 |
assert(UseSharedSpaces, "UseSharedSpaces expected."); |
|
649 |
||
650 |
if (!open_for_read()) { |
|
651 |
return false; |
|
652 |
} |
|
653 |
||
654 |
init_from_file(_fd); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
655 |
if (!validate_header()) { |
1 | 656 |
return false; |
657 |
} |
|
658 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
659 |
SharedReadOnlySize = _header->_space[0]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
660 |
SharedReadWriteSize = _header->_space[1]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
661 |
SharedMiscDataSize = _header->_space[2]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
662 |
SharedMiscCodeSize = _header->_space[3]._capacity; |
1 | 663 |
return true; |
664 |
} |
|
665 |
||
27025 | 666 |
int FileMapInfo::FileMapHeader::compute_crc() { |
667 |
char* header = data(); |
|
668 |
// start computing from the field after _crc |
|
669 |
char* buf = (char*)&_crc + sizeof(int); |
|
670 |
size_t sz = data_size() - (buf - header); |
|
671 |
int crc = ClassLoader::crc32(0, buf, (jint)sz); |
|
672 |
return crc; |
|
673 |
} |
|
674 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
675 |
bool FileMapInfo::FileMapHeader::validate() { |
27025 | 676 |
if (VerifySharedSpaces && compute_crc() != _crc) { |
677 |
fail_continue("Header checksum verification failed."); |
|
678 |
return false; |
|
679 |
} |
|
680 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
681 |
if (_version != current_version()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
682 |
FileMapInfo::fail_continue("The shared archive file is the wrong version."); |
1 | 683 |
return false; |
684 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
685 |
if (_magic != (int)0xf00baba2) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
686 |
FileMapInfo::fail_continue("The shared archive file has a bad magic number."); |
1 | 687 |
return false; |
688 |
} |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
689 |
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
|
690 |
get_header_version(header_version); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
691 |
if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
692 |
if (TraceClassPaths) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
693 |
tty->print_cr("Expected: %s", header_version); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
694 |
tty->print_cr("Actual: %s", _jvm_ident); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
695 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
696 |
FileMapInfo::fail_continue("The shared archive file was created by a different" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
697 |
" version or build of HotSpot"); |
1 | 698 |
return false; |
699 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
700 |
if (_obj_alignment != ObjectAlignmentInBytes) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
701 |
FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
702 |
" does not equal the current ObjectAlignmentInBytes of %d.", |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
703 |
_obj_alignment, ObjectAlignmentInBytes); |
1 | 704 |
return false; |
705 |
} |
|
706 |
||
707 |
return true; |
|
708 |
} |
|
709 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
710 |
bool FileMapInfo::validate_header() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
711 |
bool status = _header->validate(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
712 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
713 |
if (status) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
714 |
if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
715 |
if (!PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
716 |
fail_continue("shared class paths mismatch (hint: enable -XX:+TraceClassPaths to diagnose the failure)"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
717 |
status = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
718 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
719 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
720 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
721 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
722 |
if (_paths_misc_info != NULL) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27025
diff
changeset
|
723 |
FREE_C_HEAP_ARRAY(char, _paths_misc_info); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
724 |
_paths_misc_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
725 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
726 |
return status; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
727 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
728 |
|
1 | 729 |
// The following method is provided to see whether a given pointer |
730 |
// falls in the mapped shared space. |
|
731 |
// Param: |
|
732 |
// p, The given pointer |
|
733 |
// Return: |
|
734 |
// True if the p is within the mapped shared space, otherwise, false. |
|
735 |
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
|
736 |
for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
737 |
if (p >= _header->_space[i]._base && |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
738 |
p < _header->_space[i]._base + _header->_space[i]._used) { |
1 | 739 |
return true; |
740 |
} |
|
741 |
} |
|
742 |
||
743 |
return false; |
|
744 |
} |
|
18483
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
745 |
|
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
746 |
void FileMapInfo::print_shared_spaces() { |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
747 |
gclog_or_tty->print_cr("Shared Spaces:"); |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
748 |
for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
749 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
18483
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
750 |
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
|
751 |
shared_region_name[i], |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
752 |
si->_base, si->_base + si->_used); |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
753 |
} |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
754 |
} |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
755 |
|
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
756 |
// Unmap mapped regions of shared space. |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
757 |
void FileMapInfo::stop_sharing_and_unmap(const char* msg) { |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
758 |
FileMapInfo *map_info = FileMapInfo::current_info(); |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
759 |
if (map_info) { |
26296 | 760 |
map_info->fail_continue("%s", msg); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
761 |
for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
762 |
if (map_info->_header->_space[i]._base != NULL) { |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
763 |
map_info->unmap_region(i); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
764 |
map_info->_header->_space[i]._base = NULL; |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
765 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
766 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
767 |
} else if (DumpSharedSpaces) { |
26296 | 768 |
fail_stop("%s", msg); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
769 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
770 |
} |