author | coleenp |
Thu, 18 Jun 2015 00:40:51 +0000 | |
changeset 31364 | 782625e8fb3c |
parent 31360 | 87d3a62c7e35 |
parent 31362 | 8957ccbb5821 |
child 31375 | aa5ecd9a5716 |
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" |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
31 |
#if INCLUDE_ALL_GCS |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
32 |
#include "gc/g1/g1CollectedHeap.hpp" |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
33 |
#endif |
7397 | 34 |
#include "memory/filemap.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
35 |
#include "memory/metadataFactory.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
36 |
#include "memory/oopFactory.hpp" |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
37 |
#include "oops/objArrayOop.hpp" |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
38 |
#include "prims/jvmtiExport.hpp" |
7397 | 39 |
#include "runtime/arguments.hpp" |
40 |
#include "runtime/java.hpp" |
|
41 |
#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
|
42 |
#include "runtime/vm_version.hpp" |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13728
diff
changeset
|
43 |
#include "services/memTracker.hpp" |
7397 | 44 |
#include "utilities/defaultStream.hpp" |
45 |
||
1 | 46 |
# include <sys/stat.h> |
47 |
# include <errno.h> |
|
48 |
||
49 |
#ifndef O_BINARY // if defined (Win32) use binary files. |
|
50 |
#define O_BINARY 0 // otherwise do nothing. |
|
51 |
#endif |
|
52 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23186
diff
changeset
|
53 |
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
1 | 54 |
extern address JVM_FunctionAtStart(); |
55 |
extern address JVM_FunctionAtEnd(); |
|
56 |
||
2131 | 57 |
// Complain and stop. All error conditions occurring during the writing of |
1 | 58 |
// an archive file should stop the process. Unrecoverable errors during |
59 |
// the reading of the archive file should stop the process. |
|
60 |
||
61 |
static void fail(const char *msg, va_list ap) { |
|
62 |
// This occurs very early during initialization: tty is not initialized. |
|
63 |
jio_fprintf(defaultStream::error_stream(), |
|
2131 | 64 |
"An error has occurred while processing the" |
1 | 65 |
" shared archive file.\n"); |
66 |
jio_vfprintf(defaultStream::error_stream(), msg, ap); |
|
67 |
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
|
68 |
// Do not change the text of the below message because some tests check for it. |
1 | 69 |
vm_exit_during_initialization("Unable to use shared archive.", NULL); |
70 |
} |
|
71 |
||
72 |
||
73 |
void FileMapInfo::fail_stop(const char *msg, ...) { |
|
74 |
va_list ap; |
|
75 |
va_start(ap, msg); |
|
76 |
fail(msg, ap); // Never returns. |
|
77 |
va_end(ap); // for completeness. |
|
78 |
} |
|
79 |
||
80 |
||
81 |
// Complain and continue. Recoverable errors during the reading of the |
|
82 |
// archive file may continue (with sharing disabled). |
|
83 |
// |
|
84 |
// If we continue, then disable shared spaces and close the file. |
|
85 |
||
86 |
void FileMapInfo::fail_continue(const char *msg, ...) { |
|
87 |
va_list ap; |
|
88 |
va_start(ap, msg); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
89 |
MetaspaceShared::set_archive_loading_failed(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
90 |
if (PrintSharedArchiveAndExit && _validating_classpath_entry_table) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
91 |
// 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
|
92 |
// 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
|
93 |
// entries. No need to quit. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
94 |
tty->print("["); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
95 |
tty->vprint(msg, ap); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
96 |
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
|
97 |
} else { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
98 |
if (RequireSharedSpaces) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
99 |
fail(msg, ap); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
100 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
101 |
if (PrintSharedSpaces) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
102 |
tty->print_cr("UseSharedSpaces: %s", msg); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
103 |
} |
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
|
104 |
} |
28017
84009002b566
8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
27880
diff
changeset
|
105 |
UseSharedSpaces = false; |
84009002b566
8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
27880
diff
changeset
|
106 |
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
|
107 |
current_info()->close(); |
1 | 108 |
} |
109 |
va_end(ap); |
|
110 |
} |
|
111 |
||
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
112 |
// Fill in the fileMapInfo structure with data about this VM instance. |
1 | 113 |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
114 |
// 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
|
115 |
// 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
|
116 |
// |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
117 |
// 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
|
118 |
// 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
|
119 |
// 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
|
120 |
// 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
|
121 |
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
|
122 |
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
|
123 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
127 |
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
|
128 |
strcpy(header_version, vm_version); |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
129 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
130 |
} else { |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
131 |
// 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
|
132 |
// value over multiple jvm invocations. |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
133 |
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
|
134 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
135 |
// 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
|
136 |
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
|
137 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
138 |
// 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
|
139 |
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
|
140 |
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
|
141 |
} |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
142 |
} |
1 | 143 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
144 |
FileMapInfo::FileMapInfo() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
145 |
assert(_current_info == NULL, "must be singleton"); // not thread safe |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
146 |
_current_info = this; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
147 |
memset(this, 0, sizeof(FileMapInfo)); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
148 |
_file_offset = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
149 |
_file_open = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
150 |
_header = SharedClassUtil::allocate_file_map_header(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
151 |
_header->_version = _invalid_version; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
152 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
153 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
154 |
FileMapInfo::~FileMapInfo() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
155 |
assert(_current_info == this, "must be singleton"); // not thread safe |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
156 |
_current_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
157 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
158 |
|
1 | 159 |
void FileMapInfo::populate_header(size_t alignment) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
160 |
_header->populate(this, alignment); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
161 |
} |
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 |
size_t FileMapInfo::FileMapHeader::data_size() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
164 |
return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
165 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
166 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
167 |
void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
168 |
_magic = 0xf00baba2; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
169 |
_version = _current_version; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
170 |
_alignment = alignment; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
171 |
_obj_alignment = ObjectAlignmentInBytes; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
172 |
_narrow_oop_mode = Universe::narrow_oop_mode(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
173 |
_narrow_oop_shift = Universe::narrow_oop_shift(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
174 |
_max_heap_size = MaxHeapSize; |
31362
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
175 |
_narrow_klass_base = Universe::narrow_klass_base(); |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
176 |
_narrow_klass_shift = Universe::narrow_klass_shift(); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
177 |
_classpath_entry_table_size = mapinfo->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
178 |
_classpath_entry_table = mapinfo->_classpath_entry_table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
179 |
_classpath_entry_size = mapinfo->_classpath_entry_size; |
1 | 180 |
|
181 |
// The following fields are for sanity checks for whether this archive |
|
182 |
// will function correctly with this JVM and the bootclasspath it's |
|
183 |
// invoked with. |
|
184 |
||
185 |
// JVM version string ... changes on each build. |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
186 |
get_header_version(_jvm_ident); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
187 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
188 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
189 |
void FileMapInfo::allocate_classpath_entry_table() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
190 |
int bytes = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
191 |
int count = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
192 |
char* strptr = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
193 |
char* strptr_max = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
194 |
Thread* THREAD = Thread::current(); |
1 | 195 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
196 |
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
197 |
size_t entry_size = SharedClassUtil::shared_class_path_entry_size(); |
1 | 198 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
199 |
for (int pass=0; pass<2; pass++) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
200 |
ClassPathEntry *cpe = ClassLoader::classpath_entry(0); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
201 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
202 |
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
|
203 |
const char *name = cpe->name(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
204 |
int name_bytes = (int)(strlen(name) + 1); |
1 | 205 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
206 |
if (pass == 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
207 |
count ++; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
208 |
bytes += (int)entry_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
209 |
bytes += name_bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
210 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
211 |
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
|
212 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
213 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
214 |
SharedClassPathEntry* ent = shared_classpath(cur_entry); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
215 |
if (cpe->is_jar_file()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
216 |
struct stat st; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
217 |
if (os::stat(name, &st) != 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
218 |
// 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
|
219 |
// into ClassLoader::classpath_entry(). |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
220 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
221 |
// 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
|
222 |
// make assumptions about where classes get loaded from. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
223 |
FileMapInfo::fail_stop("Unable to open jar file %s.", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
224 |
} |
1 | 225 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
226 |
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
|
227 |
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
|
228 |
} else { |
27562 | 229 |
struct stat st; |
230 |
if ((os::stat(name, &st) == 0) && ((st.st_mode & S_IFDIR) == S_IFDIR)) { |
|
231 |
if (!os::dir_is_empty(name)) { |
|
232 |
ClassLoader::exit_with_path_failure("Cannot have non-empty directory in archived classpaths", name); |
|
233 |
} |
|
234 |
ent->_filesize = -1; |
|
235 |
} else { |
|
236 |
ent->_filesize = -2; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
237 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
238 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
239 |
ent->_name = strptr; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
240 |
if (strptr + name_bytes <= strptr_max) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
241 |
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
|
242 |
strptr += name_bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
243 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
244 |
assert(0, "miscalculated buffer size"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
245 |
} |
1 | 246 |
} |
247 |
} |
|
26135
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 |
if (pass == 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
strptr = (char*)(arr->data()); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
253 |
strptr_max = strptr + bytes; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
254 |
SharedClassPathEntry* table = (SharedClassPathEntry*)strptr; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
255 |
strptr += entry_size * count; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
256 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
257 |
_classpath_entry_table_size = count; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
258 |
_classpath_entry_table = table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
259 |
_classpath_entry_size = entry_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
260 |
} |
1 | 261 |
} |
262 |
} |
|
263 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
264 |
bool FileMapInfo::validate_classpath_entry_table() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
265 |
_validating_classpath_entry_table = true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
266 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
267 |
int count = _header->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
268 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
269 |
_classpath_entry_table = _header->_classpath_entry_table; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
270 |
_classpath_entry_size = _header->_classpath_entry_size; |
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 |
for (int i=0; i<count; i++) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
273 |
SharedClassPathEntry* ent = shared_classpath(i); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
274 |
struct stat st; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
275 |
const char* name = ent->_name; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
276 |
bool ok = true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
277 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
278 |
tty->print_cr("[Checking shared classpath entry: %s]", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
279 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
280 |
if (os::stat(name, &st) != 0) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
281 |
fail_continue("Required classpath entry does not exist: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
282 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
283 |
} else if (ent->is_dir()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
284 |
if (!os::dir_is_empty(name)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
285 |
fail_continue("directory is not empty: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
286 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
287 |
} |
27562 | 288 |
} else if (ent->is_jar()) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
289 |
if (ent->_timestamp != st.st_mtime || |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
290 |
ent->_filesize != st.st_size) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
291 |
ok = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
292 |
if (PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
293 |
fail_continue(ent->_timestamp != st.st_mtime ? |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
294 |
"Timestamp mismatch" : |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
295 |
"File size mismatch"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
296 |
} else { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
297 |
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
|
298 |
" the shared archive file: %s", name); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
299 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
300 |
} |
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 |
if (ok) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
303 |
if (TraceClassPaths || (TraceClassLoading && Verbose)) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
304 |
tty->print_cr("[ok]"); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
305 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
306 |
} else if (!PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
307 |
_validating_classpath_entry_table = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
308 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
309 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
310 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
311 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
312 |
_classpath_entry_table_size = _header->_classpath_entry_table_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
313 |
_validating_classpath_entry_table = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
314 |
return true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
315 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
316 |
|
1 | 317 |
|
318 |
// Read the FileMapInfo information from the file. |
|
319 |
||
320 |
bool FileMapInfo::init_from_file(int fd) { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
321 |
size_t sz = _header->data_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
322 |
char* addr = _header->data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
323 |
size_t n = os::read(fd, addr, (unsigned int)sz); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
324 |
if (n != sz) { |
1 | 325 |
fail_continue("Unable to read the file header."); |
326 |
return false; |
|
327 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
328 |
if (_header->_version != current_version()) { |
1 | 329 |
fail_continue("The shared archive file has the wrong version."); |
330 |
return false; |
|
331 |
} |
|
332 |
_file_offset = (long)n; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
333 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
334 |
size_t info_size = _header->_paths_misc_info_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
335 |
_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
|
336 |
if (_paths_misc_info == NULL) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
337 |
fail_continue("Unable to read the file header."); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
338 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
339 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
340 |
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
|
341 |
if (n != info_size) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
342 |
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
|
343 |
FREE_C_HEAP_ARRAY(char, _paths_misc_info); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
344 |
_paths_misc_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
345 |
return false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
346 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
347 |
|
27025 | 348 |
size_t len = lseek(fd, 0, SEEK_END); |
349 |
struct FileMapInfo::FileMapHeader::space_info* si = |
|
350 |
&_header->_space[MetaspaceShared::mc]; |
|
351 |
if (si->_file_offset >= len || len - si->_file_offset < si->_used) { |
|
352 |
fail_continue("The shared archive file has been truncated."); |
|
353 |
return false; |
|
354 |
} |
|
355 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
356 |
_file_offset += (long)n; |
1 | 357 |
return true; |
358 |
} |
|
359 |
||
360 |
||
361 |
// Read the FileMapInfo information from the file. |
|
362 |
bool FileMapInfo::open_for_read() { |
|
363 |
_full_path = Arguments::GetSharedArchivePath(); |
|
364 |
int fd = open(_full_path, O_RDONLY | O_BINARY, 0); |
|
365 |
if (fd < 0) { |
|
366 |
if (errno == ENOENT) { |
|
367 |
// Not locating the shared archive is ok. |
|
368 |
fail_continue("Specified shared archive not found."); |
|
369 |
} else { |
|
370 |
fail_continue("Failed to open shared archive file (%s).", |
|
371 |
strerror(errno)); |
|
372 |
} |
|
373 |
return false; |
|
374 |
} |
|
375 |
||
376 |
_fd = fd; |
|
377 |
_file_open = true; |
|
378 |
return true; |
|
379 |
} |
|
380 |
||
381 |
||
382 |
// Write the FileMapInfo information to the file. |
|
383 |
||
384 |
void FileMapInfo::open_for_write() { |
|
385 |
_full_path = Arguments::GetSharedArchivePath(); |
|
386 |
if (PrintSharedSpaces) { |
|
387 |
tty->print_cr("Dumping shared data to file: "); |
|
388 |
tty->print_cr(" %s", _full_path); |
|
389 |
} |
|
390 |
||
15461
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
391 |
#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
|
392 |
chmod(_full_path, _S_IREAD | _S_IWRITE); |
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
393 |
#endif |
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
394 |
|
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
395 |
// 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
|
396 |
// allow processes that have it open continued access to the file. |
1 | 397 |
remove(_full_path); |
398 |
int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444); |
|
399 |
if (fd < 0) { |
|
28950
693ae3d5e1ff
8072694: Need errno info when CDS archive creation fails
hseigel
parents:
28023
diff
changeset
|
400 |
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
|
401 |
strerror(errno)); |
1 | 402 |
} |
403 |
_fd = fd; |
|
404 |
_file_offset = 0; |
|
405 |
_file_open = true; |
|
406 |
} |
|
407 |
||
408 |
||
409 |
// Write the header to the file, seek to the next allocation boundary. |
|
410 |
||
411 |
void FileMapInfo::write_header() { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
412 |
int info_size = ClassLoader::get_shared_paths_misc_info_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
413 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
414 |
_header->_paths_misc_info_size = info_size; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
415 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
416 |
align_file_position(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
417 |
size_t sz = _header->data_size(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
418 |
char* addr = _header->data(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
419 |
write_bytes(addr, (int)sz); // skip the C++ vtable |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
420 |
write_bytes(ClassLoader::get_shared_paths_misc_info(), info_size); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
421 |
align_file_position(); |
1 | 422 |
} |
423 |
||
424 |
||
425 |
// Dump shared spaces to file. |
|
426 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
427 |
void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) { |
1 | 428 |
align_file_position(); |
17109
90e6c31bbbe4
8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents:
16430
diff
changeset
|
429 |
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
|
430 |
size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
431 |
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
|
432 |
write_region(i, (char*)space->bottom(), used, capacity, read_only, false); |
1 | 433 |
} |
434 |
||
435 |
||
436 |
// Dump region to file. |
|
437 |
||
438 |
void FileMapInfo::write_region(int region, char* base, size_t size, |
|
439 |
size_t capacity, bool read_only, |
|
440 |
bool allow_exec) { |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
441 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region]; |
1 | 442 |
|
443 |
if (_file_open) { |
|
444 |
guarantee(si->_file_offset == _file_offset, "file offset mismatch."); |
|
445 |
if (PrintSharedSpaces) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
446 |
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
|
447 |
" file offset 0x%6x", region, size, base, _file_offset); |
1 | 448 |
} |
449 |
} else { |
|
450 |
si->_file_offset = _file_offset; |
|
451 |
} |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
452 |
if (MetaspaceShared::is_string_region(region)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
453 |
assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
454 |
if (base != NULL) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
455 |
si->_addr._offset = (intx)oopDesc::encode_heap_oop_not_null((oop)base); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
456 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
457 |
si->_addr._offset = 0; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
458 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
459 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
460 |
si->_addr._base = base; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
461 |
} |
1 | 462 |
si->_used = size; |
463 |
si->_capacity = capacity; |
|
464 |
si->_read_only = read_only; |
|
465 |
si->_allow_exec = allow_exec; |
|
27025 | 466 |
si->_crc = ClassLoader::crc32(0, base, (jint)size); |
1 | 467 |
write_bytes_aligned(base, (int)size); |
468 |
} |
|
469 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
470 |
// Write the string space. The string space contains one or multiple GC(G1) regions. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
471 |
// When the total string space size is smaller than one GC region of the dump time, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
472 |
// only one string region is used for shared strings. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
473 |
// |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
474 |
// If the total string space size is bigger than one GC region, there would be more |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
475 |
// than one GC regions allocated for shared strings. The first/bottom GC region might |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
476 |
// be a partial GC region with the empty portion at the higher address within that region. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
477 |
// The non-empty portion of the first region is written into the archive as one string |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
478 |
// region. The rest are consecutive full GC regions if they exist, which can be written |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
479 |
// out in one chunk as another string region. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
480 |
void FileMapInfo::write_string_regions(GrowableArray<MemRegion> *regions) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
481 |
for (int i = MetaspaceShared::first_string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
482 |
i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
483 |
char* start = NULL; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
484 |
size_t size = 0; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
485 |
if (regions->is_nonempty()) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
486 |
if (i == MetaspaceShared::first_string) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
487 |
MemRegion first = regions->first(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
488 |
start = (char*)first.start(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
489 |
size = first.byte_size(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
490 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
491 |
int len = regions->length(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
492 |
if (len > 1) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
493 |
start = (char*)regions->at(1).start(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
494 |
size = (char*)regions->at(len - 1).end() - start; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
495 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
496 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
497 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
498 |
write_region(i, start, size, size, false, false); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
499 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
500 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
501 |
|
1 | 502 |
|
503 |
// Dump bytes to file -- at the current file position. |
|
504 |
||
505 |
void FileMapInfo::write_bytes(const void* buffer, int nbytes) { |
|
506 |
if (_file_open) { |
|
507 |
int n = ::write(_fd, buffer, nbytes); |
|
508 |
if (n != nbytes) { |
|
509 |
// It is dangerous to leave the corrupted shared archive file around, |
|
510 |
// close and remove the file. See bug 6372906. |
|
511 |
close(); |
|
512 |
remove(_full_path); |
|
26296 | 513 |
fail_stop("Unable to write to shared archive file."); |
1 | 514 |
} |
515 |
} |
|
516 |
_file_offset += nbytes; |
|
517 |
} |
|
518 |
||
519 |
||
520 |
// Align file position to an allocation unit boundary. |
|
521 |
||
522 |
void FileMapInfo::align_file_position() { |
|
27025 | 523 |
size_t new_file_offset = align_size_up(_file_offset, |
524 |
os::vm_allocation_granularity()); |
|
1 | 525 |
if (new_file_offset != _file_offset) { |
526 |
_file_offset = new_file_offset; |
|
527 |
if (_file_open) { |
|
528 |
// Seek one byte back from the target and write a byte to insure |
|
529 |
// that the written file is the correct length. |
|
530 |
_file_offset -= 1; |
|
27025 | 531 |
if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) { |
26296 | 532 |
fail_stop("Unable to seek."); |
1 | 533 |
} |
534 |
char zero = 0; |
|
535 |
write_bytes(&zero, 1); |
|
536 |
} |
|
537 |
} |
|
538 |
} |
|
539 |
||
540 |
||
541 |
// Dump bytes to file -- at the current file position. |
|
542 |
||
543 |
void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) { |
|
544 |
align_file_position(); |
|
545 |
write_bytes(buffer, nbytes); |
|
546 |
align_file_position(); |
|
547 |
} |
|
548 |
||
549 |
||
550 |
// Close the shared archive file. This does NOT unmap mapped regions. |
|
551 |
||
552 |
void FileMapInfo::close() { |
|
553 |
if (_file_open) { |
|
554 |
if (::close(_fd) < 0) { |
|
555 |
fail_stop("Unable to close the shared archive file."); |
|
556 |
} |
|
557 |
_file_open = false; |
|
558 |
_fd = -1; |
|
559 |
} |
|
560 |
} |
|
561 |
||
562 |
||
563 |
// JVM/TI RedefineClasses() support: |
|
564 |
// Remap the shared readonly space to shared readwrite, private. |
|
565 |
bool FileMapInfo::remap_shared_readonly_as_readwrite() { |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
566 |
int idx = 0; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
567 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[idx]; |
1 | 568 |
if (!si->_read_only) { |
569 |
// the space is already readwrite so we are done |
|
570 |
return true; |
|
571 |
} |
|
572 |
size_t used = si->_used; |
|
573 |
size_t size = align_size_up(used, os::vm_allocation_granularity()); |
|
574 |
if (!open_for_read()) { |
|
575 |
return false; |
|
576 |
} |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
577 |
char *addr = _header->region_addr(idx); |
1 | 578 |
char *base = os::remap_memory(_fd, _full_path, si->_file_offset, |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
579 |
addr, size, false /* !read_only */, |
1 | 580 |
si->_allow_exec); |
581 |
close(); |
|
582 |
if (base == NULL) { |
|
583 |
fail_continue("Unable to remap shared readonly space (errno=%d).", errno); |
|
584 |
return false; |
|
585 |
} |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
586 |
if (base != addr) { |
1 | 587 |
fail_continue("Unable to remap shared readonly space at required address."); |
588 |
return false; |
|
589 |
} |
|
590 |
si->_read_only = false; |
|
591 |
return true; |
|
592 |
} |
|
593 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
594 |
// 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
|
595 |
ReservedSpace FileMapInfo::reserve_shared_memory() { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
596 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0]; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
597 |
char* requested_addr = _header->region_addr(0); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
598 |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
599 |
size_t size = FileMapInfo::shared_spaces_size(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
600 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
601 |
// 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
|
602 |
// other reserved memory (like the code cache). |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
603 |
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
|
604 |
if (!rs.is_reserved()) { |
26296 | 605 |
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
|
606 |
return rs; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
607 |
} |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13728
diff
changeset
|
608 |
// 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
|
609 |
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
|
610 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
611 |
return rs; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
612 |
} |
1 | 613 |
|
614 |
// Memory map a region in the address space. |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
615 |
static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode", |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
616 |
"String1", "String2" }; |
1 | 617 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
618 |
char* FileMapInfo::map_region(int i) { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
619 |
assert(!MetaspaceShared::is_string_region(i), "sanity"); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
620 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
1 | 621 |
size_t used = si->_used; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
622 |
size_t alignment = os::vm_allocation_granularity(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
623 |
size_t size = align_size_up(used, alignment); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
624 |
char *requested_addr = _header->region_addr(i); |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
625 |
bool read_only; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
626 |
|
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
627 |
// 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
|
628 |
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
|
629 |
read_only = false; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
630 |
} else { |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
631 |
read_only = si->_read_only; |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
632 |
} |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
633 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
634 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7405
diff
changeset
|
635 |
// map the contents of the CDS archive in this memory |
1 | 636 |
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
|
637 |
requested_addr, size, read_only, |
1 | 638 |
si->_allow_exec); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
639 |
if (base == NULL || base != requested_addr) { |
26296 | 640 |
fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]); |
1 | 641 |
return NULL; |
642 |
} |
|
15100
0ae85ac7c8b0
8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents:
14577
diff
changeset
|
643 |
#ifdef _WINDOWS |
0ae85ac7c8b0
8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents:
14577
diff
changeset
|
644 |
// 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
|
645 |
// 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
|
646 |
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
|
647 |
#endif |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
648 |
|
1 | 649 |
return base; |
650 |
} |
|
651 |
||
31360
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
652 |
static MemRegion *string_ranges = NULL; |
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
653 |
static int num_ranges = 0; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
654 |
bool FileMapInfo::map_string_regions() { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
655 |
#if INCLUDE_ALL_GCS |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
656 |
if (UseG1GC && UseCompressedOops && UseCompressedClassPointers) { |
31362
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
657 |
// Check that all the narrow oop and klass encodings match the archive |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
658 |
if (narrow_oop_mode() != Universe::narrow_oop_mode() || |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
659 |
narrow_oop_shift() != Universe::narrow_oop_shift() || |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
660 |
narrow_klass_base() != Universe::narrow_klass_base() || |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
661 |
narrow_klass_shift() != Universe::narrow_klass_shift()) { |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
662 |
if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) { |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
663 |
tty->print_cr("Shared string data from the CDS archive is being ignored. " |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
664 |
"The current CompressedOops/CompressedClassPointers encoding differs from " |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
665 |
"that archived due to heap size change. The archive was dumped using max heap " |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
666 |
"size %dM.", max_heap_size()/M); |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
667 |
} |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
668 |
} else { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
669 |
string_ranges = new MemRegion[MetaspaceShared::max_strings]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
670 |
struct FileMapInfo::FileMapHeader::space_info* si; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
671 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
672 |
for (int i = MetaspaceShared::first_string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
673 |
i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
674 |
si = &_header->_space[i]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
675 |
size_t used = si->_used; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
676 |
if (used > 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
677 |
size_t size = used; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
678 |
char* requested_addr = (char*)((void*)oopDesc::decode_heap_oop_not_null( |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
679 |
(narrowOop)si->_addr._offset)); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
680 |
string_ranges[num_ranges] = MemRegion((HeapWord*)requested_addr, size / HeapWordSize); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
681 |
num_ranges ++; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
682 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
683 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
684 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
685 |
if (num_ranges == 0) { |
31362
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
686 |
StringTable::ignore_shared_strings(true); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
687 |
return true; // no shared string data |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
688 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
689 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
690 |
// Check that ranges are within the java heap |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
691 |
if (!G1CollectedHeap::heap()->check_archive_addresses(string_ranges, num_ranges)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
692 |
fail_continue("Unable to allocate shared string space: range is not " |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
693 |
"within java heap."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
694 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
695 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
696 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
697 |
// allocate from java heap |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
698 |
if (!G1CollectedHeap::heap()->alloc_archive_regions(string_ranges, num_ranges)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
699 |
fail_continue("Unable to allocate shared string space: range is " |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
700 |
"already in use."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
701 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
702 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
703 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
704 |
// Map the string data. No need to call MemTracker::record_virtual_memory_type() |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
705 |
// for mapped string regions as they are part of the reserved java heap, which |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
706 |
// is already recorded. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
707 |
for (int i = 0; i < num_ranges; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
708 |
si = &_header->_space[MetaspaceShared::first_string + i]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
709 |
char* addr = (char*)string_ranges[i].start(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
710 |
char* base = os::map_memory(_fd, _full_path, si->_file_offset, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
711 |
addr, string_ranges[i].byte_size(), si->_read_only, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
712 |
si->_allow_exec); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
713 |
if (base == NULL || base != addr) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
714 |
fail_continue("Unable to map shared string space at required address."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
715 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
716 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
717 |
} |
31362
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
718 |
|
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
719 |
if (!verify_string_regions()) { |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
720 |
fail_continue("Shared string regions are corrupt"); |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
721 |
return false; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
722 |
} |
31362
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
723 |
|
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
724 |
// the shared string data is mapped successfully |
8957ccbb5821
8098821: Crash in system dictionary initialization with shared strings
coleenp
parents:
31345
diff
changeset
|
725 |
return true; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
726 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
727 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
728 |
if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
729 |
tty->print_cr("Shared string data from the CDS archive is being ignored. UseG1GC, " |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
730 |
"UseCompressedOops and UseCompressedClassPointers are required."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
731 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
732 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
733 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
734 |
// if we get here, the shared string data is not mapped |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
735 |
assert(string_ranges == NULL && num_ranges == 0, "sanity"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
736 |
StringTable::ignore_shared_strings(true); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
737 |
#endif |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
738 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
739 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
740 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
741 |
bool FileMapInfo::verify_string_regions() { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
742 |
for (int i = MetaspaceShared::first_string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
743 |
i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
744 |
if (!verify_region_checksum(i)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
745 |
return false; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
746 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
747 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
748 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
749 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
750 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
751 |
void FileMapInfo::fixup_string_regions() { |
31360
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
752 |
// If any string regions were found, call the fill routine to make them parseable. |
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
753 |
// Note that string_ranges may be non-NULL even if no ranges were found. |
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
754 |
if (num_ranges != 0) { |
87d3a62c7e35
8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents:
31345
diff
changeset
|
755 |
assert(string_ranges != NULL, "Null string_ranges array with non-zero count"); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
756 |
G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_ranges); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
757 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
758 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
759 |
|
27025 | 760 |
bool FileMapInfo::verify_region_checksum(int i) { |
761 |
if (!VerifySharedSpaces) { |
|
762 |
return true; |
|
763 |
} |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
764 |
|
27025 | 765 |
size_t sz = _header->_space[i]._used; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
766 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
767 |
if (sz == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
768 |
return true; // no data |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
769 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
770 |
if (MetaspaceShared::is_string_region(i) && StringTable::shared_string_ignored()) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
771 |
return true; // shared string data are not mapped |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
772 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
773 |
const char* buf = _header->region_addr(i); |
27025 | 774 |
int crc = ClassLoader::crc32(0, buf, (jint)sz); |
775 |
if (crc != _header->_space[i]._crc) { |
|
776 |
fail_continue("Checksum verification failed."); |
|
777 |
return false; |
|
778 |
} |
|
779 |
return true; |
|
780 |
} |
|
1 | 781 |
|
782 |
// Unmap a memory region in the address space. |
|
783 |
||
784 |
void FileMapInfo::unmap_region(int i) { |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
785 |
assert(!MetaspaceShared::is_string_region(i), "sanity"); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
786 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
1 | 787 |
size_t used = si->_used; |
788 |
size_t size = align_size_up(used, os::vm_allocation_granularity()); |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
789 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
790 |
if (used == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
791 |
return; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
792 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
793 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
794 |
char* addr = _header->region_addr(i); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
795 |
if (!os::unmap_memory(addr, size)) { |
1 | 796 |
fail_stop("Unable to unmap shared space."); |
797 |
} |
|
798 |
} |
|
799 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
800 |
void FileMapInfo::unmap_string_regions() { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
801 |
for (int i = MetaspaceShared::first_string; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
802 |
i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
803 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
804 |
size_t used = si->_used; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
805 |
if (used > 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
806 |
size_t size = align_size_up(used, os::vm_allocation_granularity()); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
807 |
char* addr = (char*)((void*)oopDesc::decode_heap_oop_not_null( |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
808 |
(narrowOop)si->_addr._offset)); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
809 |
if (!os::unmap_memory(addr, size)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
810 |
fail_stop("Unable to unmap shared space."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
811 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
812 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
813 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
814 |
} |
1 | 815 |
|
816 |
void FileMapInfo::assert_mark(bool check) { |
|
817 |
if (!check) { |
|
26296 | 818 |
fail_stop("Mark mismatch while restoring from shared file."); |
1 | 819 |
} |
820 |
} |
|
821 |
||
822 |
||
823 |
FileMapInfo* FileMapInfo::_current_info = NULL; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
824 |
SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
825 |
int FileMapInfo::_classpath_entry_table_size = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
826 |
size_t FileMapInfo::_classpath_entry_size = 0x1234baad; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
827 |
bool FileMapInfo::_validating_classpath_entry_table = false; |
1 | 828 |
|
829 |
// Open the shared archive file, read and validate the header |
|
830 |
// information (version, boot classpath, etc.). If initialization |
|
831 |
// fails, shared spaces are disabled and the file is closed. [See |
|
832 |
// fail_continue.] |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
833 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
834 |
// Validation of the archive is done in two steps: |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
835 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
836 |
// [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
|
837 |
// [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
|
838 |
// region of the archive, which is not mapped yet. |
1 | 839 |
bool FileMapInfo::initialize() { |
840 |
assert(UseSharedSpaces, "UseSharedSpaces expected."); |
|
841 |
||
842 |
if (!open_for_read()) { |
|
843 |
return false; |
|
844 |
} |
|
845 |
||
846 |
init_from_file(_fd); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
847 |
if (!validate_header()) { |
1 | 848 |
return false; |
849 |
} |
|
850 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
851 |
SharedReadOnlySize = _header->_space[0]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
852 |
SharedReadWriteSize = _header->_space[1]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
853 |
SharedMiscDataSize = _header->_space[2]._capacity; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
854 |
SharedMiscCodeSize = _header->_space[3]._capacity; |
1 | 855 |
return true; |
856 |
} |
|
857 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
858 |
char* FileMapInfo::FileMapHeader::region_addr(int idx) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
859 |
if (MetaspaceShared::is_string_region(idx)) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
860 |
return (char*)((void*)oopDesc::decode_heap_oop_not_null( |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
861 |
(narrowOop)_space[idx]._addr._offset)); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
862 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
863 |
return _space[idx]._addr._base; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
864 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
865 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
866 |
|
27025 | 867 |
int FileMapInfo::FileMapHeader::compute_crc() { |
868 |
char* header = data(); |
|
869 |
// start computing from the field after _crc |
|
870 |
char* buf = (char*)&_crc + sizeof(int); |
|
871 |
size_t sz = data_size() - (buf - header); |
|
872 |
int crc = ClassLoader::crc32(0, buf, (jint)sz); |
|
873 |
return crc; |
|
874 |
} |
|
875 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
876 |
bool FileMapInfo::FileMapHeader::validate() { |
27025 | 877 |
if (VerifySharedSpaces && compute_crc() != _crc) { |
878 |
fail_continue("Header checksum verification failed."); |
|
879 |
return false; |
|
880 |
} |
|
881 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
882 |
if (_version != current_version()) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
883 |
FileMapInfo::fail_continue("The shared archive file is the wrong version."); |
1 | 884 |
return false; |
885 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
886 |
if (_magic != (int)0xf00baba2) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
887 |
FileMapInfo::fail_continue("The shared archive file has a bad magic number."); |
1 | 888 |
return false; |
889 |
} |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
890 |
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
|
891 |
get_header_version(header_version); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
892 |
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
|
893 |
if (TraceClassPaths) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
894 |
tty->print_cr("Expected: %s", header_version); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
895 |
tty->print_cr("Actual: %s", _jvm_ident); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
896 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
897 |
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
|
898 |
" version or build of HotSpot"); |
1 | 899 |
return false; |
900 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
901 |
if (_obj_alignment != ObjectAlignmentInBytes) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
902 |
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
|
903 |
" does not equal the current ObjectAlignmentInBytes of %d.", |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
904 |
_obj_alignment, ObjectAlignmentInBytes); |
1 | 905 |
return false; |
906 |
} |
|
907 |
||
908 |
return true; |
|
909 |
} |
|
910 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
911 |
bool FileMapInfo::validate_header() { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
912 |
bool status = _header->validate(); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
913 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
914 |
if (status) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
915 |
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
|
916 |
if (!PrintSharedArchiveAndExit) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
917 |
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
|
918 |
status = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
919 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
920 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
921 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
922 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
923 |
if (_paths_misc_info != NULL) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27025
diff
changeset
|
924 |
FREE_C_HEAP_ARRAY(char, _paths_misc_info); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
925 |
_paths_misc_info = NULL; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
926 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
927 |
return status; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
928 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
929 |
|
1 | 930 |
// The following method is provided to see whether a given pointer |
931 |
// falls in the mapped shared space. |
|
932 |
// Param: |
|
933 |
// p, The given pointer |
|
934 |
// Return: |
|
935 |
// True if the p is within the mapped shared space, otherwise, false. |
|
936 |
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
|
937 |
for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
938 |
char *base; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
939 |
if (MetaspaceShared::is_string_region(i) && _header->_space[i]._used == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
940 |
continue; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
941 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
942 |
base = _header->region_addr(i); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
943 |
if (p >= base && p < base + _header->_space[i]._used) { |
1 | 944 |
return true; |
945 |
} |
|
946 |
} |
|
947 |
||
948 |
return false; |
|
949 |
} |
|
18483
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
950 |
|
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
951 |
void FileMapInfo::print_shared_spaces() { |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
952 |
gclog_or_tty->print_cr("Shared Spaces:"); |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
953 |
for (int i = 0; i < MetaspaceShared::n_regions; i++) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
954 |
struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
955 |
char *base = _header->region_addr(i); |
18483
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
956 |
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
|
957 |
shared_region_name[i], |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
958 |
base, base + si->_used); |
18483
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
959 |
} |
c021907fa0a7
8016075: Win32 crash with CDS enabled and small heap size
iklam
parents:
17109
diff
changeset
|
960 |
} |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
961 |
|
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
962 |
// Unmap mapped regions of shared space. |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
963 |
void FileMapInfo::stop_sharing_and_unmap(const char* msg) { |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
964 |
FileMapInfo *map_info = FileMapInfo::current_info(); |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
965 |
if (map_info) { |
26296 | 966 |
map_info->fail_continue("%s", msg); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
967 |
for (int i = 0; i < MetaspaceShared::num_non_strings; i++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
968 |
char *addr = map_info->_header->region_addr(i); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
969 |
if (addr != NULL && !MetaspaceShared::is_string_region(i)) { |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
970 |
map_info->unmap_region(i); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
971 |
map_info->_header->_space[i]._addr._base = NULL; |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
972 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
973 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
974 |
map_info->unmap_string_regions(); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
975 |
} else if (DumpSharedSpaces) { |
26296 | 976 |
fail_stop("%s", msg); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
977 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
978 |
} |