author | pliden |
Wed, 20 Nov 2019 10:37:46 +0100 | |
changeset 59152 | 59272e9e0635 |
parent 59128 | ac11b83e0f38 |
child 59235 | 0f41ac6bb9dd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, 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" |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47599
diff
changeset
|
26 |
#include "jvm.h" |
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
27 |
#include "classfile/classFileStream.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48962
diff
changeset
|
28 |
#include "classfile/classLoader.inline.hpp" |
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
29 |
#include "classfile/classLoaderData.inline.hpp" |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
30 |
#include "classfile/classLoaderExt.hpp" |
7397 | 31 |
#include "classfile/symbolTable.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
32 |
#include "classfile/systemDictionaryShared.hpp" |
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
33 |
#include "classfile/altHashing.hpp" |
46522
86b13b03a053
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents:
42876
diff
changeset
|
34 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46630
diff
changeset
|
35 |
#include "logging/logStream.hpp" |
46522
86b13b03a053
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents:
42876
diff
changeset
|
36 |
#include "logging/logMessage.hpp" |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
37 |
#include "memory/archiveUtils.inline.hpp" |
54927 | 38 |
#include "memory/dynamicArchive.hpp" |
7397 | 39 |
#include "memory/filemap.hpp" |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
40 |
#include "memory/heapShared.inline.hpp" |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
41 |
#include "memory/iterator.inline.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
42 |
#include "memory/metadataFactory.hpp" |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
43 |
#include "memory/metaspaceClosure.hpp" |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
44 |
#include "memory/metaspaceShared.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
45 |
#include "memory/oopFactory.hpp" |
54825 | 46 |
#include "memory/universe.hpp" |
54927 | 47 |
#include "oops/compressedOops.hpp" |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49340
diff
changeset
|
48 |
#include "oops/compressedOops.inline.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
49 |
#include "oops/objArrayOop.hpp" |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
50 |
#include "oops/oop.inline.hpp" |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
51 |
#include "prims/jvmtiExport.hpp" |
7397 | 52 |
#include "runtime/arguments.hpp" |
53 |
#include "runtime/java.hpp" |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
54 |
#include "runtime/mutexLocker.hpp" |
51480
2e928420389d
8209826: Undefined reference to os::write after JDK-8209657 (filemap.hpp cleanup)
iklam
parents:
51477
diff
changeset
|
55 |
#include "runtime/os.inline.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
24424
diff
changeset
|
56 |
#include "runtime/vm_version.hpp" |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13728
diff
changeset
|
57 |
#include "services/memTracker.hpp" |
46625 | 58 |
#include "utilities/align.hpp" |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
59 |
#include "utilities/bitMap.inline.hpp" |
57897
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
60 |
#include "utilities/classpathStream.hpp" |
7397 | 61 |
#include "utilities/defaultStream.hpp" |
49982 | 62 |
#if INCLUDE_G1GC |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49340
diff
changeset
|
63 |
#include "gc/g1/g1CollectedHeap.hpp" |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
64 |
#include "gc/g1/heapRegion.hpp" |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49340
diff
changeset
|
65 |
#endif |
7397 | 66 |
|
1 | 67 |
# include <sys/stat.h> |
68 |
# include <errno.h> |
|
69 |
||
70 |
#ifndef O_BINARY // if defined (Win32) use binary files. |
|
71 |
#define O_BINARY 0 // otherwise do nothing. |
|
72 |
#endif |
|
73 |
||
2131 | 74 |
// Complain and stop. All error conditions occurring during the writing of |
1 | 75 |
// an archive file should stop the process. Unrecoverable errors during |
76 |
// the reading of the archive file should stop the process. |
|
77 |
||
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
78 |
static void fail_exit(const char *msg, va_list ap) { |
1 | 79 |
// This occurs very early during initialization: tty is not initialized. |
80 |
jio_fprintf(defaultStream::error_stream(), |
|
2131 | 81 |
"An error has occurred while processing the" |
1 | 82 |
" shared archive file.\n"); |
83 |
jio_vfprintf(defaultStream::error_stream(), msg, ap); |
|
84 |
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
|
85 |
// Do not change the text of the below message because some tests check for it. |
1 | 86 |
vm_exit_during_initialization("Unable to use shared archive.", NULL); |
87 |
} |
|
88 |
||
89 |
||
90 |
void FileMapInfo::fail_stop(const char *msg, ...) { |
|
91 |
va_list ap; |
|
92 |
va_start(ap, msg); |
|
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
93 |
fail_exit(msg, ap); // Never returns. |
1 | 94 |
va_end(ap); // for completeness. |
95 |
} |
|
96 |
||
97 |
||
98 |
// Complain and continue. Recoverable errors during the reading of the |
|
99 |
// archive file may continue (with sharing disabled). |
|
100 |
// |
|
101 |
// If we continue, then disable shared spaces and close the file. |
|
102 |
||
103 |
void FileMapInfo::fail_continue(const char *msg, ...) { |
|
104 |
va_list ap; |
|
105 |
va_start(ap, msg); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
106 |
if (PrintSharedArchiveAndExit && _validating_shared_path_table) { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
107 |
// 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
|
108 |
// 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
|
109 |
// entries. No need to quit. |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
110 |
tty->print("["); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
111 |
tty->vprint(msg, ap); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
112 |
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
|
113 |
} else { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
114 |
if (RequireSharedSpaces) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
115 |
fail_exit(msg, ap); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
116 |
} else { |
46522
86b13b03a053
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents:
42876
diff
changeset
|
117 |
if (log_is_enabled(Info, cds)) { |
86b13b03a053
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents:
42876
diff
changeset
|
118 |
ResourceMark rm; |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46630
diff
changeset
|
119 |
LogStream ls(Log(cds)::info()); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46630
diff
changeset
|
120 |
ls.print("UseSharedSpaces: "); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46630
diff
changeset
|
121 |
ls.vprint_cr(msg, ap); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
122 |
} |
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
|
123 |
} |
1 | 124 |
} |
125 |
va_end(ap); |
|
126 |
} |
|
127 |
||
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
128 |
// Fill in the fileMapInfo structure with data about this VM instance. |
1 | 129 |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
130 |
// 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
|
131 |
// 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
|
132 |
// |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
133 |
// 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
|
134 |
// 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
|
135 |
// 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
|
136 |
// 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
|
137 |
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
|
138 |
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
|
139 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
143 |
memset(header_version, 0, JVM_IDENT_MAX); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
144 |
|
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
145 |
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
|
146 |
strcpy(header_version, vm_version); |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
147 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
148 |
} else { |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
149 |
// 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
|
150 |
// value over multiple jvm invocations. |
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
151 |
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
|
152 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
153 |
// 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
|
154 |
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
|
155 |
|
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
156 |
// 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
|
157 |
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
|
158 |
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
|
159 |
} |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
160 |
|
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
161 |
assert(header_version[JVM_IDENT_MAX-1] == 0, "must be"); |
14577
fd68d810d86b
6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents:
14120
diff
changeset
|
162 |
} |
1 | 163 |
|
54927 | 164 |
FileMapInfo::FileMapInfo(bool is_static) { |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46625
diff
changeset
|
165 |
memset((void*)this, 0, sizeof(FileMapInfo)); |
54927 | 166 |
_is_static = is_static; |
167 |
size_t header_size; |
|
168 |
if (is_static) { |
|
169 |
assert(_current_info == NULL, "must be singleton"); // not thread safe |
|
170 |
_current_info = this; |
|
171 |
header_size = sizeof(FileMapHeader); |
|
172 |
} else { |
|
173 |
assert(_dynamic_archive_info == NULL, "must be singleton"); // not thread safe |
|
174 |
_dynamic_archive_info = this; |
|
175 |
header_size = sizeof(DynamicArchiveHeader); |
|
176 |
} |
|
177 |
_header = (FileMapHeader*)os::malloc(header_size, mtInternal); |
|
178 |
memset((void*)_header, 0, header_size); |
|
58096 | 179 |
_header->set_header_size(header_size); |
180 |
_header->set_version(INVALID_CDS_ARCHIVE_VERSION); |
|
181 |
_header->set_has_platform_or_app_classes(true); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
182 |
_file_offset = 0; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
183 |
_file_open = false; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
184 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
185 |
|
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
186 |
FileMapInfo::~FileMapInfo() { |
54927 | 187 |
if (_is_static) { |
188 |
assert(_current_info == this, "must be singleton"); // not thread safe |
|
189 |
_current_info = NULL; |
|
190 |
} else { |
|
191 |
assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe |
|
192 |
_dynamic_archive_info = NULL; |
|
193 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
194 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
195 |
|
1 | 196 |
void FileMapInfo::populate_header(size_t alignment) { |
58096 | 197 |
header()->populate(this, alignment); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
198 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
199 |
|
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
200 |
void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) { |
54927 | 201 |
if (DynamicDumpSharedSpaces) { |
202 |
_magic = CDS_DYNAMIC_ARCHIVE_MAGIC; |
|
203 |
} else { |
|
204 |
_magic = CDS_ARCHIVE_MAGIC; |
|
205 |
} |
|
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
206 |
_version = CURRENT_CDS_ARCHIVE_VERSION; |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
207 |
_alignment = alignment; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
208 |
_obj_alignment = ObjectAlignmentInBytes; |
33628 | 209 |
_compact_strings = CompactStrings; |
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
210 |
_narrow_oop_mode = CompressedOops::mode(); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
211 |
_narrow_oop_base = CompressedOops::base(); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
212 |
_narrow_oop_shift = CompressedOops::shift(); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
213 |
_max_heap_size = MaxHeapSize; |
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
214 |
_narrow_klass_shift = CompressedKlassPointers::shift(); |
52062
8dbf1a13af49
8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents:
51823
diff
changeset
|
215 |
if (HeapShared::is_heap_object_archiving_allowed()) { |
58015
dd84de796f2c
8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents:
57898
diff
changeset
|
216 |
_heap_end = CompressedOops::end(); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
217 |
} |
1 | 218 |
|
219 |
// The following fields are for sanity checks for whether this archive |
|
220 |
// will function correctly with this JVM and the bootclasspath it's |
|
221 |
// invoked with. |
|
222 |
||
223 |
// JVM version string ... changes on each build. |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
224 |
get_header_version(_jvm_ident); |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
225 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
226 |
_app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index(); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
227 |
_app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index(); |
54927 | 228 |
_num_module_paths = ClassLoader::num_module_path_entries(); |
51439
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
229 |
_max_used_path_index = ClassLoaderExt::max_used_path_index(); |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
230 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
231 |
_verify_local = BytecodeVerificationLocal; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
232 |
_verify_remote = BytecodeVerificationRemote; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
233 |
_has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes(); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
234 |
_requested_base_address = (char*)SharedBaseAddress; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
235 |
_mapped_base_address = (char*)SharedBaseAddress; |
52596
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
236 |
_allow_archiving_with_java_agent = AllowArchivingWithJavaAgent; |
54927 | 237 |
// the following 2 fields will be set in write_header for dynamic archive header |
238 |
_base_archive_name_size = 0; |
|
239 |
_base_archive_is_default = false; |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
240 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
241 |
if (!DynamicDumpSharedSpaces) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
242 |
set_shared_path_table(mapinfo->_shared_path_table); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
243 |
} |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
244 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
245 |
|
57898 | 246 |
void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) { |
247 |
_type = non_existent_entry; |
|
248 |
set_name(path, THREAD); |
|
249 |
} |
|
250 |
||
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
251 |
void SharedClassPathEntry::init(bool is_modules_image, |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
252 |
ClassPathEntry* cpe, TRAPS) { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
253 |
Arguments::assert_is_dumping_archive(); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
254 |
_timestamp = 0; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
255 |
_filesize = 0; |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
256 |
_from_class_path_attr = false; |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
257 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
258 |
struct stat st; |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
259 |
if (os::stat(cpe->name(), &st) == 0) { |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
260 |
if ((st.st_mode & S_IFMT) == S_IFDIR) { |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
261 |
_type = dir_entry; |
40013 | 262 |
} else { |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
263 |
// The timestamp of the modules_image is not checked at runtime. |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
264 |
if (is_modules_image) { |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
265 |
_type = modules_image_entry; |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
266 |
} else { |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
267 |
_type = jar_entry; |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
268 |
_timestamp = st.st_mtime; |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
269 |
_from_class_path_attr = cpe->from_class_path_attr(); |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
270 |
} |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
271 |
_filesize = st.st_size; |
40013 | 272 |
} |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
273 |
} else { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
274 |
// The file/dir must exist, or it would not have been added |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
275 |
// into ClassLoader::classpath_entry(). |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
276 |
// |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
277 |
// If we can't access a jar file in the boot path, then we can't |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
278 |
// make assumptions about where classes get loaded from. |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
279 |
FileMapInfo::fail_stop("Unable to open file %s.", cpe->name()); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
280 |
} |
40013 | 281 |
|
57898 | 282 |
// No need to save the name of the module file, as it will be computed at run time |
283 |
// to allow relocation of the JDK directory. |
|
284 |
const char* name = is_modules_image ? "" : cpe->name(); |
|
285 |
set_name(name, THREAD); |
|
286 |
} |
|
287 |
||
288 |
void SharedClassPathEntry::set_name(const char* name, TRAPS) { |
|
289 |
size_t len = strlen(name) + 1; |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
290 |
_name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD); |
57898 | 291 |
strcpy(_name->data(), name); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
292 |
} |
1 | 293 |
|
57898 | 294 |
const char* SharedClassPathEntry::name() const { |
295 |
if (UseSharedSpaces && is_modules_image()) { |
|
296 |
// In order to validate the runtime modules image file size against the archived |
|
297 |
// size information, we need to obtain the runtime modules image path. The recorded |
|
298 |
// dump time modules image path in the archive may be different from the runtime path |
|
299 |
// if the JDK image has beed moved after generating the archive. |
|
300 |
return ClassLoader::get_jrt_entry()->name(); |
|
301 |
} else { |
|
302 |
return _name->data(); |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
bool SharedClassPathEntry::validate(bool is_class_path) const { |
|
49931 | 307 |
assert(UseSharedSpaces, "runtime only"); |
308 |
||
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
309 |
struct stat st; |
57898 | 310 |
const char* name = this->name(); |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
311 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
312 |
bool ok = true; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
313 |
log_info(class, path)("checking shared classpath entry: %s", name); |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
314 |
if (os::stat(name, &st) != 0 && is_class_path) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
315 |
// If the archived module path entry does not exist at runtime, it is not fatal |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
316 |
// (no need to invalid the shared archive) because the shared runtime visibility check |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
317 |
// filters out any archived module classes that do not have a matching runtime |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
318 |
// module path location. |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
319 |
FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
320 |
ok = false; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
321 |
} else if (is_dir()) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
322 |
if (!os::dir_is_empty(name)) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
323 |
FileMapInfo::fail_continue("directory is not empty: %s", name); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
324 |
ok = false; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
325 |
} |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
326 |
} else if ((has_timestamp() && _timestamp != st.st_mtime) || |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
327 |
_filesize != st.st_size) { |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
328 |
ok = false; |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
329 |
if (PrintSharedArchiveAndExit) { |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
330 |
FileMapInfo::fail_continue(_timestamp != st.st_mtime ? |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
331 |
"Timestamp mismatch" : |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
332 |
"File size mismatch"); |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
333 |
} else { |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
334 |
FileMapInfo::fail_continue("A jar file is not the one used while building" |
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
335 |
" the shared archive file: %s", name); |
1 | 336 |
} |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
337 |
} |
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
338 |
|
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
339 |
if (PrintSharedArchiveAndExit && !ok) { |
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
340 |
// If PrintSharedArchiveAndExit is enabled, don't report failure to the |
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
341 |
// caller. Please see above comments for more details. |
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
342 |
ok = true; |
54927 | 343 |
MetaspaceShared::set_archive_loading_failed(); |
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
344 |
} |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
345 |
return ok; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
346 |
} |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
347 |
|
57898 | 348 |
bool SharedClassPathEntry::check_non_existent() const { |
349 |
assert(_type == non_existent_entry, "must be"); |
|
350 |
log_info(class, path)("should be non-existent: %s", name()); |
|
351 |
struct stat st; |
|
352 |
if (os::stat(name(), &st) != 0) { |
|
353 |
log_info(class, path)("ok"); |
|
354 |
return true; // file doesn't exist |
|
355 |
} else { |
|
356 |
return false; |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
||
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
361 |
void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
362 |
it->push(&_name); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
363 |
it->push(&_manifest); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
364 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
365 |
|
54927 | 366 |
void SharedPathTable::metaspace_pointers_do(MetaspaceClosure* it) { |
367 |
it->push(&_table); |
|
368 |
for (int i=0; i<_size; i++) { |
|
369 |
path_at(i)->metaspace_pointers_do(it); |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
void SharedPathTable::dumptime_init(ClassLoaderData* loader_data, Thread* THREAD) { |
|
374 |
size_t entry_size = sizeof(SharedClassPathEntry); |
|
57898 | 375 |
int num_entries = 0; |
376 |
num_entries += ClassLoader::num_boot_classpath_entries(); |
|
377 |
num_entries += ClassLoader::num_app_classpath_entries(); |
|
378 |
num_entries += ClassLoader::num_module_path_entries(); |
|
379 |
num_entries += FileMapInfo::num_non_existent_class_paths(); |
|
54927 | 380 |
size_t bytes = entry_size * num_entries; |
381 |
||
382 |
_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD); |
|
383 |
_size = num_entries; |
|
384 |
} |
|
385 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
386 |
void FileMapInfo::allocate_shared_path_table() { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
387 |
Arguments::assert_is_dumping_archive(); |
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
388 |
|
57898 | 389 |
EXCEPTION_MARK; // The following calls should never throw, but would exit VM on error. |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
390 |
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
391 |
ClassPathEntry* jrt = ClassLoader::get_jrt_entry(); |
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
392 |
|
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
393 |
assert(jrt != NULL, |
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
394 |
"No modular java runtime image present when allocating the CDS classpath entry table"); |
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
395 |
|
54927 | 396 |
_shared_path_table.dumptime_init(loader_data, THREAD); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
397 |
|
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
398 |
// 1. boot class path |
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
399 |
int i = 0; |
57898 | 400 |
i = add_shared_classpaths(i, "boot", jrt, THREAD); |
401 |
i = add_shared_classpaths(i, "app", ClassLoader::app_classpath_entries(), THREAD); |
|
402 |
i = add_shared_classpaths(i, "module", ClassLoader::module_path_entries(), THREAD); |
|
403 |
||
404 |
for (int x = 0; x < num_non_existent_class_paths(); x++, i++) { |
|
405 |
const char* path = _non_existent_class_paths->at(x); |
|
406 |
shared_path(i)->init_as_non_existent(path, THREAD); |
|
407 |
} |
|
408 |
||
409 |
assert(i == _shared_path_table.size(), "number of shared path entry mismatch"); |
|
410 |
} |
|
411 |
||
412 |
int FileMapInfo::add_shared_classpaths(int i, const char* which, ClassPathEntry *cpe, TRAPS) { |
|
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
413 |
while (cpe != NULL) { |
57898 | 414 |
bool is_jrt = (cpe == ClassLoader::get_jrt_entry()); |
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
50039
diff
changeset
|
415 |
const char* type = (is_jrt ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir")); |
57898 | 416 |
log_info(class, path)("add %s shared path (%s) %s", which, type, cpe->name()); |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
417 |
SharedClassPathEntry* ent = shared_path(i); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
418 |
ent->init(is_jrt, cpe, THREAD); |
57898 | 419 |
if (cpe->is_jar_file()) { |
420 |
update_jar_manifest(cpe, ent, THREAD); |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
421 |
} |
57898 | 422 |
if (is_jrt) { |
423 |
cpe = ClassLoader::get_next_boot_classpath_entry(cpe); |
|
424 |
} else { |
|
425 |
cpe = cpe->next(); |
|
426 |
} |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
427 |
i++; |
47991
a474466c4fdb
8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents:
47765
diff
changeset
|
428 |
} |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
429 |
|
57898 | 430 |
return i; |
1 | 431 |
} |
432 |
||
49931 | 433 |
void FileMapInfo::check_nonempty_dir_in_shared_path_table() { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
434 |
Arguments::assert_is_dumping_archive(); |
49931 | 435 |
|
436 |
bool has_nonempty_dir = false; |
|
437 |
||
54927 | 438 |
int last = _shared_path_table.size() - 1; |
51439
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
439 |
if (last > ClassLoaderExt::max_used_path_index()) { |
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
440 |
// no need to check any path beyond max_used_path_index |
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
441 |
last = ClassLoaderExt::max_used_path_index(); |
49931 | 442 |
} |
443 |
||
51439
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
444 |
for (int i = 0; i <= last; i++) { |
49931 | 445 |
SharedClassPathEntry *e = shared_path(i); |
446 |
if (e->is_dir()) { |
|
447 |
const char* path = e->name(); |
|
448 |
if (!os::dir_is_empty(path)) { |
|
58110
85e1de070bef
8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents:
58096
diff
changeset
|
449 |
log_error(cds)("Error: non-empty directory '%s'", path); |
49931 | 450 |
has_nonempty_dir = true; |
451 |
} |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
if (has_nonempty_dir) { |
|
456 |
ClassLoader::exit_with_path_failure("Cannot have non-empty directory in paths", NULL); |
|
457 |
} |
|
458 |
} |
|
459 |
||
57898 | 460 |
void FileMapInfo::record_non_existent_class_path_entry(const char* path) { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
461 |
Arguments::assert_is_dumping_archive(); |
57898 | 462 |
log_info(class, path)("non-existent Class-Path entry %s", path); |
463 |
if (_non_existent_class_paths == NULL) { |
|
464 |
_non_existent_class_paths = new (ResourceObj::C_HEAP, mtInternal)GrowableArray<const char*>(10, true); |
|
465 |
} |
|
466 |
_non_existent_class_paths->append(os::strdup(path)); |
|
467 |
} |
|
468 |
||
469 |
int FileMapInfo::num_non_existent_class_paths() { |
|
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
470 |
Arguments::assert_is_dumping_archive(); |
57898 | 471 |
if (_non_existent_class_paths != NULL) { |
472 |
return _non_existent_class_paths->length(); |
|
473 |
} else { |
|
474 |
return 0; |
|
475 |
} |
|
476 |
} |
|
477 |
||
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
478 |
class ManifestStream: public ResourceObj { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
479 |
private: |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
480 |
u1* _buffer_start; // Buffer bottom |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
481 |
u1* _buffer_end; // Buffer top (one past last element) |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
482 |
u1* _current; // Current buffer position |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
483 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
484 |
public: |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
485 |
// Constructor |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
486 |
ManifestStream(u1* buffer, int length) : _buffer_start(buffer), |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
487 |
_current(buffer) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
488 |
_buffer_end = buffer + length; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
489 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
490 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
491 |
static bool is_attr(u1* attr, const char* name) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
492 |
return strncmp((const char*)attr, name, strlen(name)) == 0; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
493 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
494 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
495 |
static char* copy_attr(u1* value, size_t len) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
496 |
char* buf = NEW_RESOURCE_ARRAY(char, len + 1); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
497 |
strncpy(buf, (char*)value, len); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
498 |
buf[len] = 0; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
499 |
return buf; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
500 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
501 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
502 |
// The return value indicates if the JAR is signed or not |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
503 |
bool check_is_signed() { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
504 |
u1* attr = _current; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
505 |
bool isSigned = false; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
506 |
while (_current < _buffer_end) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
507 |
if (*_current == '\n') { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
508 |
*_current = '\0'; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
509 |
u1* value = (u1*)strchr((char*)attr, ':'); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
510 |
if (value != NULL) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
511 |
assert(*(value+1) == ' ', "Unrecognized format" ); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
512 |
if (strstr((char*)attr, "-Digest") != NULL) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
513 |
isSigned = true; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
514 |
break; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
515 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
516 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
517 |
*_current = '\n'; // restore |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
518 |
attr = _current + 1; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
519 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
520 |
_current ++; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
521 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
522 |
return isSigned; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
523 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
524 |
}; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
525 |
|
57898 | 526 |
void FileMapInfo::update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) { |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
527 |
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
528 |
ResourceMark rm(THREAD); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
529 |
jint manifest_size; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
530 |
|
57898 | 531 |
assert(cpe->is_jar_file() && ent->is_jar(), "the shared class path entry is not a JAR file"); |
532 |
char* manifest = ClassLoaderExt::read_manifest(cpe, &manifest_size, CHECK); |
|
533 |
if (manifest != NULL) { |
|
534 |
ManifestStream* stream = new ManifestStream((u1*)manifest, |
|
535 |
manifest_size); |
|
536 |
if (stream->check_is_signed()) { |
|
537 |
ent->set_is_signed(); |
|
538 |
} else { |
|
539 |
// Copy the manifest into the shared archive |
|
540 |
manifest = ClassLoaderExt::read_raw_manifest(cpe, &manifest_size, CHECK); |
|
541 |
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data, |
|
542 |
manifest_size, |
|
543 |
THREAD); |
|
544 |
char* p = (char*)(buf->data()); |
|
545 |
memcpy(p, manifest, manifest_size); |
|
546 |
ent->set_manifest(buf); |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
547 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
548 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
549 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
550 |
|
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
551 |
char* FileMapInfo::skip_first_path_entry(const char* path) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
552 |
size_t path_sep_len = strlen(os::path_separator()); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
553 |
char* p = strstr((char*)path, os::path_separator()); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
554 |
if (p != NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
555 |
debug_only( { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
556 |
size_t image_name_len = strlen(MODULES_IMAGE_NAME); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
557 |
assert(strncmp(p - image_name_len, MODULES_IMAGE_NAME, image_name_len) == 0, |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
558 |
"first entry must be the modules image"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
559 |
} ); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
560 |
p += path_sep_len; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
561 |
} else { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
562 |
debug_only( { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
563 |
assert(ClassLoader::string_ends_with(path, MODULES_IMAGE_NAME), |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
564 |
"first entry must be the modules image"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
565 |
} ); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
566 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
567 |
return p; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
568 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
569 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
570 |
int FileMapInfo::num_paths(const char* path) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
571 |
if (path == NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
572 |
return 0; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
573 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
574 |
int npaths = 1; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
575 |
char* p = (char*)path; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
576 |
while (p != NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
577 |
char* prev = p; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
578 |
p = strstr((char*)p, os::path_separator()); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
579 |
if (p != NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
580 |
p++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
581 |
// don't count empty path |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
582 |
if ((p - prev) > 1) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
583 |
npaths++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
584 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
585 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
586 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
587 |
return npaths; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
588 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
589 |
|
57897
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
590 |
GrowableArray<const char*>* FileMapInfo::create_path_array(const char* paths) { |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
591 |
GrowableArray<const char*>* path_array = new(ResourceObj::RESOURCE_AREA, mtInternal) |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
592 |
GrowableArray<const char*>(10); |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
593 |
|
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
594 |
ClasspathStream cp_stream(paths); |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
595 |
while (cp_stream.has_next()) { |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
596 |
const char* path = cp_stream.get_next(); |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
597 |
struct stat st; |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
598 |
if (os::stat(path, &st) == 0) { |
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
599 |
path_array->append(path); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
600 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
601 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
602 |
return path_array; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
603 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
604 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
605 |
bool FileMapInfo::classpath_failure(const char* msg, const char* name) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
606 |
ClassLoader::trace_class_path(msg, name); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
607 |
if (PrintSharedArchiveAndExit) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
608 |
MetaspaceShared::set_archive_loading_failed(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
609 |
} |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
610 |
return false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
611 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
612 |
|
57897
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
613 |
bool FileMapInfo::check_paths(int shared_path_start_idx, int num_paths, GrowableArray<const char*>* rp_array) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
614 |
int i = 0; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
615 |
int j = shared_path_start_idx; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
616 |
bool mismatch = false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
617 |
while (i < num_paths && !mismatch) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
618 |
while (shared_path(j)->from_class_path_attr()) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
619 |
// shared_path(j) was expanded from the JAR file attribute "Class-Path:" |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
620 |
// during dump time. It's not included in the -classpath VM argument. |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
621 |
j++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
622 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
623 |
if (!os::same_files(shared_path(j)->name(), rp_array->at(i))) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
624 |
mismatch = true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
625 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
626 |
i++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
627 |
j++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
628 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
629 |
return mismatch; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
630 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
631 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
632 |
bool FileMapInfo::validate_boot_class_paths() { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
633 |
// |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
634 |
// - Archive contains boot classes only - relaxed boot path check: |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
635 |
// Extra path elements appended to the boot path at runtime are allowed. |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
636 |
// |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
637 |
// - Archive contains application or platform classes - strict boot path check: |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
638 |
// Validate the entire runtime boot path, which must be compatible |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
639 |
// with the dump time boot path. Appending boot path at runtime is not |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
640 |
// allowed. |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
641 |
// |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
642 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
643 |
// The first entry in boot path is the modules_image (guaranteed by |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
644 |
// ClassLoader::setup_boot_search_path()). Skip the first entry. The |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
645 |
// path of the runtime modules_image may be different from the dump |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
646 |
// time path (e.g. the JDK image is copied to a different location |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
647 |
// after generating the shared archive), which is acceptable. For most |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
648 |
// common cases, the dump time boot path might contain modules_image only. |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
649 |
char* runtime_boot_path = Arguments::get_sysclasspath(); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
650 |
char* rp = skip_first_path_entry(runtime_boot_path); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
651 |
assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); |
58096 | 652 |
int dp_len = header()->app_class_paths_start_index() - 1; // ignore the first path to the module image |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
653 |
bool mismatch = false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
654 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
655 |
bool relaxed_check = !header()->has_platform_or_app_classes(); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
656 |
if (dp_len == 0 && rp == NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
657 |
return true; // ok, both runtime and dump time boot paths have modules_images only |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
658 |
} else if (dp_len == 0 && rp != NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
659 |
if (relaxed_check) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
660 |
return true; // ok, relaxed check, runtime has extra boot append path entries |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
661 |
} else { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
662 |
mismatch = true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
663 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
664 |
} else if (dp_len > 0 && rp != NULL) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
665 |
int num; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
666 |
ResourceMark rm; |
57897
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
667 |
GrowableArray<const char*>* rp_array = create_path_array(rp); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
668 |
int rp_len = rp_array->length(); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
669 |
if (rp_len >= dp_len) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
670 |
if (relaxed_check) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
671 |
// only check the leading entries in the runtime boot path, up to |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
672 |
// the length of the dump time boot path |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
673 |
num = dp_len; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
674 |
} else { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
675 |
// check the full runtime boot path, must match with dump time |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
676 |
num = rp_len; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
677 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
678 |
mismatch = check_paths(1, num, rp_array); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
679 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
680 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
681 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
682 |
if (mismatch) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
683 |
// The paths are different |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
684 |
return classpath_failure("[BOOT classpath mismatch, actual =", runtime_boot_path); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
685 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
686 |
return true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
687 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
688 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
689 |
bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
690 |
const char *appcp = Arguments::get_appclasspath(); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
691 |
assert(appcp != NULL, "NULL app classpath"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
692 |
int rp_len = num_paths(appcp); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
693 |
bool mismatch = false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
694 |
if (rp_len < shared_app_paths_len) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
695 |
return classpath_failure("Run time APP classpath is shorter than the one at dump time: ", appcp); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
696 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
697 |
if (shared_app_paths_len != 0 && rp_len != 0) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
698 |
// Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar. |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
699 |
ResourceMark rm; |
57897
e2e315f1aa63
8230168: Use ClasspathStream for FileMapInfo::create_path_array
iklam
parents:
57584
diff
changeset
|
700 |
GrowableArray<const char*>* rp_array = create_path_array(appcp); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
701 |
if (rp_array->length() == 0) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
702 |
// None of the jar file specified in the runtime -cp exists. |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
703 |
return classpath_failure("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
704 |
} |
57898 | 705 |
|
706 |
// Handling of non-existent entries in the classpath: we eliminate all the non-existent |
|
707 |
// entries from both the dump time classpath (ClassLoader::update_class_path_entry_list) |
|
708 |
// and the runtime classpath (FileMapInfo::create_path_array), and check the remaining |
|
709 |
// entries. E.g.: |
|
710 |
// |
|
711 |
// dump : -cp a.jar:NE1:NE2:b.jar -> a.jar:b.jar -> recorded in archive. |
|
712 |
// run 1: -cp NE3:a.jar:NE4:b.jar -> a.jar:b.jar -> matched |
|
713 |
// run 2: -cp x.jar:NE4:b.jar -> x.jar:b.jar -> mismatched |
|
714 |
||
58096 | 715 |
int j = header()->app_class_paths_start_index(); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
716 |
mismatch = check_paths(j, shared_app_paths_len, rp_array); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
717 |
if (mismatch) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
718 |
return classpath_failure("[APP classpath mismatch, actual: -Djava.class.path=", appcp); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
719 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
720 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
721 |
return true; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
722 |
} |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
723 |
|
57898 | 724 |
void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) { |
725 |
LogTarget(Info, class, path) lt; |
|
726 |
if (lt.is_enabled()) { |
|
727 |
LogStream ls(lt); |
|
728 |
ls.print("%s", msg); |
|
729 |
const char* prefix = ""; |
|
730 |
for (int i = start_idx; i < end_idx; i++) { |
|
731 |
ls.print("%s%s", prefix, shared_path(i)->name()); |
|
732 |
prefix = os::path_separator(); |
|
733 |
} |
|
734 |
ls.cr(); |
|
735 |
} |
|
736 |
} |
|
737 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
738 |
bool FileMapInfo::validate_shared_path_table() { |
49931 | 739 |
assert(UseSharedSpaces, "runtime only"); |
740 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
741 |
_validating_shared_path_table = true; |
54927 | 742 |
|
743 |
// Load the shared path table info from the archive header |
|
58096 | 744 |
_shared_path_table = header()->shared_path_table(); |
54927 | 745 |
if (DynamicDumpSharedSpaces) { |
746 |
// Only support dynamic dumping with the usage of the default CDS archive |
|
747 |
// or a simple base archive. |
|
748 |
// If the base layer archive contains additional path component besides |
|
749 |
// the runtime image and the -cp, dynamic dumping is disabled. |
|
750 |
// |
|
751 |
// When dynamic archiving is enabled, the _shared_path_table is overwritten |
|
752 |
// to include the application path and stored in the top layer archive. |
|
753 |
assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); |
|
58096 | 754 |
if (header()->app_class_paths_start_index() > 1) { |
54927 | 755 |
DynamicDumpSharedSpaces = false; |
756 |
warning( |
|
757 |
"Dynamic archiving is disabled because base layer archive has appended boot classpath"); |
|
758 |
} |
|
58096 | 759 |
if (header()->num_module_paths() > 0) { |
54927 | 760 |
DynamicDumpSharedSpaces = false; |
761 |
warning( |
|
762 |
"Dynamic archiving is disabled because base layer archive has module path"); |
|
763 |
} |
|
764 |
} |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
765 |
|
58096 | 766 |
log_paths("Expecting BOOT path=", 0, header()->app_class_paths_start_index()); |
767 |
log_paths("Expecting -Djava.class.path=", header()->app_class_paths_start_index(), header()->app_module_paths_start_index()); |
|
57898 | 768 |
|
58096 | 769 |
int module_paths_start_index = header()->app_module_paths_start_index(); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
770 |
int shared_app_paths_len = 0; |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
771 |
|
51439
0517bd2a0eda
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents:
51070
diff
changeset
|
772 |
// validate the path entries up to the _max_used_path_index |
58096 | 773 |
for (int i=0; i < header()->max_used_path_index() + 1; i++) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
774 |
if (i < module_paths_start_index) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
775 |
if (shared_path(i)->validate()) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
776 |
// Only count the app class paths not from the "Class-path" attribute of a jar manifest. |
58096 | 777 |
if (!shared_path(i)->from_class_path_attr() && i >= header()->app_class_paths_start_index()) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
778 |
shared_app_paths_len++; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
779 |
} |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
780 |
log_info(class, path)("ok"); |
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
781 |
} else { |
54927 | 782 |
if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) { |
783 |
assert(!UseSharedSpaces, "UseSharedSpaces should be disabled"); |
|
784 |
} |
|
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
785 |
return false; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
786 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
787 |
} else if (i >= module_paths_start_index) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
788 |
if (shared_path(i)->validate(false /* not a class path entry */)) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
789 |
log_info(class, path)("ok"); |
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
790 |
} else { |
54927 | 791 |
if (_dynamic_archive_info != NULL && _dynamic_archive_info->_is_static) { |
792 |
assert(!UseSharedSpaces, "UseSharedSpaces should be disabled"); |
|
793 |
} |
|
52562
3a9384c12260
8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents:
52514
diff
changeset
|
794 |
return false; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
795 |
} |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
796 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
797 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
798 |
|
58096 | 799 |
if (header()->max_used_path_index() == 0) { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
800 |
// default archive only contains the module image in the bootclasspath |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
801 |
assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
802 |
} else { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
803 |
if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
804 |
fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
805 |
return false; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
806 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
807 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
808 |
|
57898 | 809 |
validate_non_existent_class_paths(); |
810 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
811 |
_validating_shared_path_table = false; |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
812 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
813 |
#if INCLUDE_JVMTI |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
814 |
if (_classpath_entries_for_jvmti != NULL) { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
815 |
os::free(_classpath_entries_for_jvmti); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
816 |
} |
54927 | 817 |
size_t sz = sizeof(ClassPathEntry*) * get_number_of_shared_paths(); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
818 |
_classpath_entries_for_jvmti = (ClassPathEntry**)os::malloc(sz, mtClass); |
54927 | 819 |
memset((void*)_classpath_entries_for_jvmti, 0, sz); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
820 |
#endif |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
821 |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
822 |
return true; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
823 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
824 |
|
57898 | 825 |
void FileMapInfo::validate_non_existent_class_paths() { |
826 |
// All of the recorded non-existent paths came from the Class-Path: attribute from the JAR |
|
827 |
// files on the app classpath. If any of these are found to exist during runtime, |
|
828 |
// it will change how classes are loading for the app loader. For safety, disable |
|
829 |
// loading of archived platform/app classes (currently there's no way to disable just the |
|
830 |
// app classes). |
|
831 |
||
832 |
assert(UseSharedSpaces, "runtime only"); |
|
58096 | 833 |
for (int i = header()->app_module_paths_start_index() + header()->num_module_paths(); |
57898 | 834 |
i < get_number_of_shared_paths(); |
835 |
i++) { |
|
836 |
SharedClassPathEntry* ent = shared_path(i); |
|
837 |
if (!ent->check_non_existent()) { |
|
838 |
warning("Archived non-system classes are disabled because the " |
|
839 |
"file %s exists", ent->name()); |
|
58096 | 840 |
header()->set_has_platform_or_app_classes(false); |
57898 | 841 |
} |
842 |
} |
|
843 |
} |
|
844 |
||
54927 | 845 |
bool FileMapInfo::check_archive(const char* archive_name, bool is_static) { |
846 |
int fd = os::open(archive_name, O_RDONLY | O_BINARY, 0); |
|
847 |
if (fd < 0) { |
|
848 |
// do not vm_exit_during_initialization here because Arguments::init_shared_archive_paths() |
|
849 |
// requires a shared archive name. The open_for_read() function will log a message regarding |
|
850 |
// failure in opening a shared archive. |
|
851 |
return false; |
|
852 |
} |
|
853 |
||
854 |
size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader); |
|
855 |
void* header = os::malloc(sz, mtInternal); |
|
856 |
memset(header, 0, sz); |
|
857 |
size_t n = os::read(fd, header, (unsigned int)sz); |
|
858 |
if (n != sz) { |
|
859 |
os::free(header); |
|
860 |
os::close(fd); |
|
861 |
vm_exit_during_initialization("Unable to read header from shared archive", archive_name); |
|
862 |
return false; |
|
863 |
} |
|
864 |
if (is_static) { |
|
865 |
FileMapHeader* static_header = (FileMapHeader*)header; |
|
58096 | 866 |
if (static_header->magic() != CDS_ARCHIVE_MAGIC) { |
54927 | 867 |
os::free(header); |
868 |
os::close(fd); |
|
869 |
vm_exit_during_initialization("Not a base shared archive", archive_name); |
|
870 |
return false; |
|
871 |
} |
|
872 |
} else { |
|
873 |
DynamicArchiveHeader* dynamic_header = (DynamicArchiveHeader*)header; |
|
58096 | 874 |
if (dynamic_header->magic() != CDS_DYNAMIC_ARCHIVE_MAGIC) { |
54927 | 875 |
os::free(header); |
876 |
os::close(fd); |
|
877 |
vm_exit_during_initialization("Not a top shared archive", archive_name); |
|
878 |
return false; |
|
879 |
} |
|
880 |
} |
|
881 |
os::free(header); |
|
882 |
os::close(fd); |
|
883 |
return true; |
|
884 |
} |
|
885 |
||
886 |
bool FileMapInfo::get_base_archive_name_from_header(const char* archive_name, |
|
887 |
int* size, char** base_archive_name) { |
|
888 |
int fd = os::open(archive_name, O_RDONLY | O_BINARY, 0); |
|
889 |
if (fd < 0) { |
|
890 |
*size = 0; |
|
891 |
return false; |
|
892 |
} |
|
893 |
||
894 |
// read the header as a dynamic archive header |
|
895 |
size_t sz = sizeof(DynamicArchiveHeader); |
|
896 |
DynamicArchiveHeader* dynamic_header = (DynamicArchiveHeader*)os::malloc(sz, mtInternal); |
|
897 |
size_t n = os::read(fd, dynamic_header, (unsigned int)sz); |
|
898 |
if (n != sz) { |
|
899 |
fail_continue("Unable to read the file header."); |
|
900 |
os::free(dynamic_header); |
|
901 |
os::close(fd); |
|
902 |
return false; |
|
903 |
} |
|
58096 | 904 |
if (dynamic_header->magic() != CDS_DYNAMIC_ARCHIVE_MAGIC) { |
54927 | 905 |
// Not a dynamic header, no need to proceed further. |
906 |
*size = 0; |
|
907 |
os::free(dynamic_header); |
|
908 |
os::close(fd); |
|
909 |
return false; |
|
910 |
} |
|
58096 | 911 |
if (dynamic_header->base_archive_is_default()) { |
54927 | 912 |
*base_archive_name = Arguments::get_default_shared_archive_path(); |
913 |
} else { |
|
914 |
// read the base archive name |
|
58096 | 915 |
size_t name_size = dynamic_header->base_archive_name_size(); |
54927 | 916 |
if (name_size == 0) { |
917 |
os::free(dynamic_header); |
|
918 |
os::close(fd); |
|
919 |
return false; |
|
920 |
} |
|
921 |
*base_archive_name = NEW_C_HEAP_ARRAY(char, name_size, mtInternal); |
|
922 |
n = os::read(fd, *base_archive_name, (unsigned int)name_size); |
|
923 |
if (n != name_size) { |
|
924 |
fail_continue("Unable to read the base archive name from the header."); |
|
925 |
FREE_C_HEAP_ARRAY(char, *base_archive_name); |
|
926 |
*base_archive_name = NULL; |
|
927 |
os::free(dynamic_header); |
|
928 |
os::close(fd); |
|
929 |
return false; |
|
930 |
} |
|
931 |
} |
|
932 |
||
933 |
os::free(dynamic_header); |
|
934 |
os::close(fd); |
|
935 |
return true; |
|
936 |
} |
|
937 |
||
938 |
void FileMapInfo::restore_shared_path_table() { |
|
58096 | 939 |
_shared_path_table = _current_info->header()->shared_path_table(); |
54927 | 940 |
} |
941 |
||
1 | 942 |
// Read the FileMapInfo information from the file. |
943 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
944 |
bool FileMapInfo::init_from_file(int fd) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
945 |
size_t sz = is_static() ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader); |
58096 | 946 |
size_t n = os::read(fd, header(), (unsigned int)sz); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
947 |
if (n != sz) { |
1 | 948 |
fail_continue("Unable to read the file header."); |
949 |
return false; |
|
950 |
} |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
951 |
|
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
952 |
if (!Arguments::has_jimage()) { |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
953 |
FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build."); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
954 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
955 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
956 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
957 |
unsigned int expected_magic = is_static() ? CDS_ARCHIVE_MAGIC : CDS_DYNAMIC_ARCHIVE_MAGIC; |
58096 | 958 |
if (header()->magic() != expected_magic) { |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
959 |
log_info(cds)("_magic expected: 0x%08x", expected_magic); |
58096 | 960 |
log_info(cds)(" actual: 0x%08x", header()->magic()); |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
961 |
FileMapInfo::fail_continue("The shared archive file has a bad magic number."); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
962 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
963 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
964 |
|
58096 | 965 |
if (header()->version() != CURRENT_CDS_ARCHIVE_VERSION) { |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
966 |
log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION); |
58096 | 967 |
log_info(cds)(" actual: %d", header()->version()); |
1 | 968 |
fail_continue("The shared archive file has the wrong version."); |
969 |
return false; |
|
970 |
} |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
971 |
|
58096 | 972 |
if (header()->header_size() != sz) { |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
973 |
log_info(cds)("_header_size expected: " SIZE_FORMAT, sz); |
58096 | 974 |
log_info(cds)(" actual: " SIZE_FORMAT, header()->header_size()); |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
975 |
FileMapInfo::fail_continue("The shared archive file has an incorrect header size."); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
976 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
977 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
978 |
|
58096 | 979 |
const char* actual_ident = header()->jvm_ident(); |
980 |
||
981 |
if (actual_ident[JVM_IDENT_MAX-1] != 0) { |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
982 |
FileMapInfo::fail_continue("JVM version identifier is corrupted."); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
983 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
984 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
985 |
|
58096 | 986 |
char expected_ident[JVM_IDENT_MAX]; |
987 |
get_header_version(expected_ident); |
|
988 |
if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) { |
|
989 |
log_info(cds)("_jvm_ident expected: %s", expected_ident); |
|
990 |
log_info(cds)(" actual: %s", actual_ident); |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
991 |
FileMapInfo::fail_continue("The shared archive file was created by a different" |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
992 |
" version or build of HotSpot"); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
993 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
994 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
995 |
|
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
996 |
if (VerifySharedSpaces) { |
58096 | 997 |
int expected_crc = header()->compute_crc(); |
998 |
if (expected_crc != header()->crc()) { |
|
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
999 |
log_info(cds)("_crc expected: %d", expected_crc); |
58096 | 1000 |
log_info(cds)(" actual: %d", header()->crc()); |
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
1001 |
FileMapInfo::fail_continue("Header checksum verification failed."); |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
1002 |
return false; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
1003 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
1004 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
55296
diff
changeset
|
1005 |
|
58096 | 1006 |
_file_offset = n + header()->base_archive_name_size(); // accounts for the size of _base_archive_name |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
1007 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1008 |
if (is_static()) { |
54927 | 1009 |
// just checking the last region is sufficient since the archive is written |
1010 |
// in sequential order |
|
1011 |
size_t len = lseek(fd, 0, SEEK_END); |
|
58096 | 1012 |
FileMapRegion* si = space_at(MetaspaceShared::last_valid_region); |
54927 | 1013 |
// The last space might be empty |
58096 | 1014 |
if (si->file_offset() > len || len - si->file_offset() < si->used()) { |
54927 | 1015 |
fail_continue("The shared archive file has been truncated."); |
1016 |
return false; |
|
1017 |
} |
|
27025 | 1018 |
} |
1019 |
||
1 | 1020 |
return true; |
1021 |
} |
|
1022 |
||
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1023 |
void FileMapInfo::seek_to_position(size_t pos) { |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1024 |
if (lseek(_fd, (long)pos, SEEK_SET) < 0) { |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1025 |
fail_stop("Unable to seek to position " SIZE_FORMAT, pos); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1026 |
} |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1027 |
} |
1 | 1028 |
|
1029 |
// Read the FileMapInfo information from the file. |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1030 |
bool FileMapInfo::open_for_read() { |
54927 | 1031 |
if (_file_open) { |
1032 |
return true; |
|
1033 |
} |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1034 |
if (is_static()) { |
54927 | 1035 |
_full_path = Arguments::GetSharedArchivePath(); |
1036 |
} else { |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1037 |
_full_path = Arguments::GetSharedDynamicArchivePath(); |
54927 | 1038 |
} |
53911
65f2a401e0eb
8218811: replace open by os::open in hotspot coding
mbaesken
parents:
53884
diff
changeset
|
1039 |
int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0); |
1 | 1040 |
if (fd < 0) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1041 |
if (is_static()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1042 |
if (errno == ENOENT) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1043 |
// Not locating the shared archive is ok. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1044 |
fail_continue("Specified shared archive not found (%s).", _full_path); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1045 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1046 |
fail_continue("Failed to open shared archive file (%s).", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1047 |
os::strerror(errno)); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1048 |
} |
1 | 1049 |
} else { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1050 |
log_warning(cds, dynamic)("specified dynamic archive doesn't exist: %s", _full_path); |
1 | 1051 |
} |
1052 |
return false; |
|
1053 |
} |
|
1054 |
||
1055 |
_fd = fd; |
|
1056 |
_file_open = true; |
|
1057 |
return true; |
|
1058 |
} |
|
1059 |
||
1060 |
// Write the FileMapInfo information to the file. |
|
1061 |
||
54927 | 1062 |
void FileMapInfo::open_for_write(const char* path) { |
1063 |
if (path == NULL) { |
|
1064 |
_full_path = Arguments::GetSharedArchivePath(); |
|
1065 |
} else { |
|
1066 |
_full_path = path; |
|
1067 |
} |
|
48962
88ad6c676c87
8194994: Remove redundant string streams used for logging
mlarsson
parents:
48794
diff
changeset
|
1068 |
LogMessage(cds) msg; |
88ad6c676c87
8194994: Remove redundant string streams used for logging
mlarsson
parents:
48794
diff
changeset
|
1069 |
if (msg.is_info()) { |
88ad6c676c87
8194994: Remove redundant string streams used for logging
mlarsson
parents:
48794
diff
changeset
|
1070 |
msg.info("Dumping shared data to file: "); |
88ad6c676c87
8194994: Remove redundant string streams used for logging
mlarsson
parents:
48794
diff
changeset
|
1071 |
msg.info(" %s", _full_path); |
1 | 1072 |
} |
1073 |
||
15461
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
1074 |
#ifdef _WINDOWS // On Windows, need WRITE permission to remove the file. |
54927 | 1075 |
chmod(_full_path, _S_IREAD | _S_IWRITE); |
15461
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
1076 |
#endif |
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
1077 |
|
e3acbfdabafa
7197672: There are issues with shared data on windows
hseigel
parents:
15101
diff
changeset
|
1078 |
// 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
|
1079 |
// allow processes that have it open continued access to the file. |
1 | 1080 |
remove(_full_path); |
53911
65f2a401e0eb
8218811: replace open by os::open in hotspot coding
mbaesken
parents:
53884
diff
changeset
|
1081 |
int fd = os::open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444); |
1 | 1082 |
if (fd < 0) { |
28950
693ae3d5e1ff
8072694: Need errno info when CDS archive creation fails
hseigel
parents:
28023
diff
changeset
|
1083 |
fail_stop("Unable to create shared archive file %s: (%s).", _full_path, |
37113 | 1084 |
os::strerror(errno)); |
1 | 1085 |
} |
1086 |
_fd = fd; |
|
1087 |
_file_open = true; |
|
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1088 |
|
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1089 |
// Seek past the header. We will write the header after all regions are written |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1090 |
// and their CRCs computed. |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1091 |
size_t header_bytes = header()->header_size(); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1092 |
if (header()->magic() == CDS_DYNAMIC_ARCHIVE_MAGIC) { |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1093 |
header_bytes += strlen(Arguments::GetSharedArchivePath()) + 1; |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1094 |
} |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1095 |
|
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1096 |
header_bytes = align_up(header_bytes, os::vm_allocation_granularity()); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1097 |
_file_offset = header_bytes; |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1098 |
seek_to_position(_file_offset); |
1 | 1099 |
} |
1100 |
||
1101 |
||
1102 |
// Write the header to the file, seek to the next allocation boundary. |
|
1103 |
||
1104 |
void FileMapInfo::write_header() { |
|
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1105 |
_file_offset = 0; |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1106 |
seek_to_position(_file_offset); |
54927 | 1107 |
char* base_archive_name = NULL; |
58096 | 1108 |
if (header()->magic() == CDS_DYNAMIC_ARCHIVE_MAGIC) { |
54927 | 1109 |
base_archive_name = (char*)Arguments::GetSharedArchivePath(); |
58096 | 1110 |
header()->set_base_archive_name_size(strlen(base_archive_name) + 1); |
1111 |
header()->set_base_archive_is_default(FLAG_IS_DEFAULT(SharedArchiveFile)); |
|
54927 | 1112 |
} |
1113 |
||
1114 |
assert(is_file_position_aligned(), "must be"); |
|
58096 | 1115 |
write_bytes(header(), header()->header_size()); |
54927 | 1116 |
if (base_archive_name != NULL) { |
58096 | 1117 |
write_bytes(base_archive_name, header()->base_archive_name_size()); |
54927 | 1118 |
} |
1 | 1119 |
} |
1120 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1121 |
size_t FileMapRegion::used_aligned() const { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1122 |
return align_up(used(), os::vm_allocation_granularity()); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1123 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1124 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1125 |
void FileMapRegion::init(int region_index, char* base, size_t size, bool read_only, |
58096 | 1126 |
bool allow_exec, int crc) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1127 |
_is_heap_region = HeapShared::is_heap_region(region_index); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1128 |
_is_bitmap_region = (region_index == MetaspaceShared::bm); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1129 |
_mapping_offset = 0; |
58096 | 1130 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1131 |
if (_is_heap_region) { |
58096 | 1132 |
assert(!DynamicDumpSharedSpaces, "must be"); |
1133 |
assert((base - (char*)CompressedKlassPointers::base()) % HeapWordSize == 0, "Sanity"); |
|
1134 |
if (base != NULL) { |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1135 |
_mapping_offset = (size_t)CompressedOops::encode_not_null((oop)base); |
59128 | 1136 |
assert(_mapping_offset == (size_t)(uint32_t)_mapping_offset, "must be 32-bit only"); |
58096 | 1137 |
} |
1138 |
} else { |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1139 |
if (base != NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1140 |
assert(base >= (char*)SharedBaseAddress, "must be"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1141 |
_mapping_offset = base - (char*)SharedBaseAddress; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1142 |
} |
58096 | 1143 |
} |
1144 |
_used = size; |
|
1145 |
_read_only = read_only; |
|
1146 |
_allow_exec = allow_exec; |
|
1147 |
_crc = crc; |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1148 |
_mapped_from_file = false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1149 |
_mapped_base = NULL; |
58096 | 1150 |
} |
1151 |
||
1 | 1152 |
void FileMapInfo::write_region(int region, char* base, size_t size, |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1153 |
bool read_only, bool allow_exec) { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58277
diff
changeset
|
1154 |
Arguments::assert_is_dumping_archive(); |
54927 | 1155 |
|
58096 | 1156 |
FileMapRegion* si = space_at(region); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1157 |
char* target_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1158 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1159 |
if (region == MetaspaceShared::bm) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1160 |
target_base = NULL; // always NULL for bm region. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1161 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1162 |
if (DynamicDumpSharedSpaces) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1163 |
assert(!HeapShared::is_heap_region(region), "dynamic archive doesn't support heap regions"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1164 |
target_base = DynamicArchive::buffer_to_target(base); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1165 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1166 |
target_base = base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1167 |
} |
54927 | 1168 |
} |
1 | 1169 |
|
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1170 |
si->set_file_offset(_file_offset); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1171 |
char* requested_base = (target_base == NULL) ? NULL : target_base + MetaspaceShared::final_delta(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1172 |
log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08) |
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1173 |
" bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08), |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1174 |
region, size, p2i(requested_base), _file_offset); |
54927 | 1175 |
|
58096 | 1176 |
int crc = ClassLoader::crc32(0, base, (jint)size); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1177 |
si->init(region, target_base, size, read_only, allow_exec, crc); |
54927 | 1178 |
|
51070 | 1179 |
if (base != NULL) { |
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1180 |
write_bytes_aligned(base, size); |
51070 | 1181 |
} |
1 | 1182 |
} |
1183 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1184 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1185 |
void FileMapInfo::write_bitmap_region(const CHeapBitMap* ptrmap) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1186 |
ResourceMark rm; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1187 |
size_t size_in_bits = ptrmap->size(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1188 |
size_t size_in_bytes = ptrmap->size_in_bytes(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1189 |
uintptr_t* buffer = (uintptr_t*)NEW_RESOURCE_ARRAY(char, size_in_bytes); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1190 |
ptrmap->write_to(buffer, size_in_bytes); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1191 |
header()->set_ptrmap_size_in_bits(size_in_bits); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1192 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1193 |
log_info(cds)("ptrmap = " INTPTR_FORMAT " (" SIZE_FORMAT " bytes)", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1194 |
p2i(buffer), size_in_bytes); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1195 |
write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1196 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1197 |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1198 |
// Write out the given archive heap memory regions. GC code combines multiple |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1199 |
// consecutive archive GC regions into one MemRegion whenever possible and |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1200 |
// produces the 'heap_mem' array. |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1201 |
// |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1202 |
// If the archive heap memory size is smaller than a single dump time GC region |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1203 |
// size, there is only one MemRegion in the array. |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1204 |
// |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1205 |
// If the archive heap memory size is bigger than one dump time GC region size, |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1206 |
// the 'heap_mem' array may contain more than one consolidated MemRegions. When |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1207 |
// the first/bottom archive GC region is a partial GC region (with the empty |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1208 |
// portion at the higher address within the region), one MemRegion is used for |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1209 |
// the bottom partial archive GC region. The rest of the consecutive archive |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1210 |
// GC regions are combined into another MemRegion. |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1211 |
// |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1212 |
// Here's the mapping from (archive heap GC regions) -> (GrowableArray<MemRegion> *regions). |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1213 |
// + We have 1 or more archive heap regions: ah0, ah1, ah2 ..... ahn |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1214 |
// + We have 1 or 2 consolidated heap memory regions: r0 and r1 |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1215 |
// |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1216 |
// If there's a single archive GC region (ah0), then r0 == ah0, and r1 is empty. |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1217 |
// Otherwise: |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1218 |
// |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1219 |
// "X" represented space that's occupied by heap objects. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1220 |
// "_" represented unused spaced in the heap region. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1221 |
// |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1222 |
// |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1223 |
// |ah0 | ah1 | ah2| ...... | ahn| |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1224 |
// |XXXXXX|__ |XXXXX|XXXX|XXXXXXXX|XXXX| |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1225 |
// |<-r0->| |<- r1 ----------------->| |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1226 |
// ^^^ |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1227 |
// | |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1228 |
// +-- gap |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1229 |
size_t FileMapInfo::write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem, |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1230 |
GrowableArray<ArchiveHeapOopmapInfo> *oopmaps, |
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1231 |
int first_region_id, int max_num_regions) { |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1232 |
assert(max_num_regions <= 2, "Only support maximum 2 memory regions"); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1233 |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1234 |
int arr_len = heap_mem == NULL ? 0 : heap_mem->length(); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1235 |
if(arr_len > max_num_regions) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1236 |
fail_stop("Unable to write archive heap memory regions: " |
52811
ff04b71bf6f1
8214388: CDS dumping fails with java heap fragmentation
iklam
parents:
52702
diff
changeset
|
1237 |
"number of memory regions exceeds maximum due to fragmentation. " |
52702
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52674
diff
changeset
|
1238 |
"Please increase java heap size " |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52674
diff
changeset
|
1239 |
"(current MaxHeapSize is " SIZE_FORMAT ", InitialHeapSize is " SIZE_FORMAT ").", |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52674
diff
changeset
|
1240 |
MaxHeapSize, InitialHeapSize); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1241 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1242 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1243 |
size_t total_size = 0; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1244 |
for (int i = first_region_id, arr_idx = 0; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1245 |
i < first_region_id + max_num_regions; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1246 |
i++, arr_idx++) { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1247 |
char* start = NULL; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1248 |
size_t size = 0; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1249 |
if (arr_idx < arr_len) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1250 |
start = (char*)heap_mem->at(arr_idx).start(); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1251 |
size = heap_mem->at(arr_idx).byte_size(); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1252 |
total_size += size; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1253 |
} |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1254 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1255 |
log_info(cds)("Archive heap region %d: " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes", |
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1256 |
i, p2i(start), p2i(start + size), size); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1257 |
write_region(i, start, size, false, false); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1258 |
if (size > 0) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1259 |
address oopmap = oopmaps->at(arr_idx)._oopmap; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1260 |
assert(oopmap >= (address)SharedBaseAddress, "must be"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1261 |
space_at(i)->init_oopmap(oopmap - (address)SharedBaseAddress, |
58096 | 1262 |
oopmaps->at(arr_idx)._oopmap_size_in_bits); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1263 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1264 |
} |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1265 |
return total_size; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1266 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1267 |
|
1 | 1268 |
// Dump bytes to file -- at the current file position. |
1269 |
||
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1270 |
void FileMapInfo::write_bytes(const void* buffer, size_t nbytes) { |
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1271 |
assert(_file_open, "must be"); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1272 |
size_t n = os::write(_fd, buffer, (unsigned int)nbytes); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1273 |
if (n != nbytes) { |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1274 |
// If the shared archive is corrupted, close it and remove it. |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1275 |
close(); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1276 |
remove(_full_path); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1277 |
fail_stop("Unable to write to shared archive file."); |
1 | 1278 |
} |
1279 |
_file_offset += nbytes; |
|
1280 |
} |
|
1281 |
||
54927 | 1282 |
bool FileMapInfo::is_file_position_aligned() const { |
1283 |
return _file_offset == align_up(_file_offset, |
|
1284 |
os::vm_allocation_granularity()); |
|
1285 |
} |
|
1 | 1286 |
|
1287 |
// Align file position to an allocation unit boundary. |
|
1288 |
||
1289 |
void FileMapInfo::align_file_position() { |
|
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1290 |
assert(_file_open, "must be"); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46560
diff
changeset
|
1291 |
size_t new_file_offset = align_up(_file_offset, |
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1292 |
os::vm_allocation_granularity()); |
1 | 1293 |
if (new_file_offset != _file_offset) { |
1294 |
_file_offset = new_file_offset; |
|
58277
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1295 |
// Seek one byte back from the target and write a byte to insure |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1296 |
// that the written file is the correct length. |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1297 |
_file_offset -= 1; |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1298 |
seek_to_position(_file_offset); |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1299 |
char zero = 0; |
00a98f0aa1b3
8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents:
58110
diff
changeset
|
1300 |
write_bytes(&zero, 1); |
1 | 1301 |
} |
1302 |
} |
|
1303 |
||
1304 |
||
1305 |
// Dump bytes to file -- at the current file position. |
|
1306 |
||
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1307 |
void FileMapInfo::write_bytes_aligned(const void* buffer, size_t nbytes) { |
1 | 1308 |
align_file_position(); |
1309 |
write_bytes(buffer, nbytes); |
|
1310 |
align_file_position(); |
|
1311 |
} |
|
1312 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1313 |
void FileMapInfo::set_final_requested_base(char* b) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1314 |
header()->set_final_requested_base(b); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1315 |
} |
1 | 1316 |
|
1317 |
// Close the shared archive file. This does NOT unmap mapped regions. |
|
1318 |
||
1319 |
void FileMapInfo::close() { |
|
1320 |
if (_file_open) { |
|
1321 |
if (::close(_fd) < 0) { |
|
1322 |
fail_stop("Unable to close the shared archive file."); |
|
1323 |
} |
|
1324 |
_file_open = false; |
|
1325 |
_fd = -1; |
|
1326 |
} |
|
1327 |
} |
|
1328 |
||
1329 |
||
1330 |
// JVM/TI RedefineClasses() support: |
|
1331 |
// Remap the shared readonly space to shared readwrite, private. |
|
1332 |
bool FileMapInfo::remap_shared_readonly_as_readwrite() { |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1333 |
int idx = MetaspaceShared::ro; |
58096 | 1334 |
FileMapRegion* si = space_at(idx); |
1335 |
if (!si->read_only()) { |
|
1 | 1336 |
// the space is already readwrite so we are done |
1337 |
return true; |
|
1338 |
} |
|
58096 | 1339 |
size_t used = si->used(); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46560
diff
changeset
|
1340 |
size_t size = align_up(used, os::vm_allocation_granularity()); |
1 | 1341 |
if (!open_for_read()) { |
1342 |
return false; |
|
1343 |
} |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1344 |
char *addr = region_addr(idx); |
58096 | 1345 |
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
|
1346 |
addr, size, false /* !read_only */, |
58096 | 1347 |
si->allow_exec()); |
1 | 1348 |
close(); |
54573
b73893f7fee3
8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents:
54340
diff
changeset
|
1349 |
// These have to be errors because the shared region is now unmapped. |
1 | 1350 |
if (base == NULL) { |
54573
b73893f7fee3
8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents:
54340
diff
changeset
|
1351 |
log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno); |
b73893f7fee3
8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents:
54340
diff
changeset
|
1352 |
vm_exit(1); |
1 | 1353 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1354 |
if (base != addr) { |
54573
b73893f7fee3
8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents:
54340
diff
changeset
|
1355 |
log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno); |
b73893f7fee3
8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents:
54340
diff
changeset
|
1356 |
vm_exit(1); |
1 | 1357 |
} |
58096 | 1358 |
si->set_read_only(false); |
1 | 1359 |
return true; |
1360 |
} |
|
1361 |
||
1362 |
// Memory map a region in the address space. |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1363 |
static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "Bitmap", |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1364 |
"String1", "String2", "OpenArchive1", "OpenArchive2" }; |
1 | 1365 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1366 |
MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1367 |
DEBUG_ONLY(FileMapRegion* last_region = NULL); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1368 |
intx addr_delta = mapped_base_address - header()->requested_base_address(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1369 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1370 |
// Make sure we don't attempt to use header()->mapped_base_address() unless |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1371 |
// it's been successfully mapped. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1372 |
DEBUG_ONLY(header()->set_mapped_base_address((char*)(uintptr_t)0xdeadbeef);) |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1373 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1374 |
for (int r = 0; r < num_regions; r++) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1375 |
int idx = regions[r]; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1376 |
MapArchiveResult result = map_region(idx, addr_delta, mapped_base_address, rs); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1377 |
if (result != MAP_ARCHIVE_SUCCESS) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1378 |
return result; |
54927 | 1379 |
} |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1380 |
FileMapRegion* si = space_at(idx); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1381 |
DEBUG_ONLY(if (last_region != NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1382 |
// Ensure that the OS won't be able to allocate new memory spaces between any mapped |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1383 |
// regions, or else it would mess up the simple comparision in MetaspaceObj::is_shared(). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1384 |
assert(si->mapped_base() == last_region->mapped_end(), "must have no gaps"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1385 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1386 |
last_region = si;) |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1387 |
log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)", is_static() ? "static " : "dynamic", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1388 |
idx, p2i(si->mapped_base()), p2i(si->mapped_end()), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1389 |
shared_region_name[idx]); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1390 |
|
54927 | 1391 |
} |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1392 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1393 |
DEBUG_ONLY(if (addr_delta == 0 && ArchiveRelocationMode == 1) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1394 |
// This is for simulating mmap failures at the requested address. We do it here (instead |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1395 |
// of MetaspaceShared::map_archives) so we can thoroughly test the code for failure handling |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1396 |
// (releasing all allocated resource, etc). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1397 |
log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1398 |
return MAP_ARCHIVE_MMAP_FAILURE; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1399 |
}); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1400 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1401 |
header()->set_mapped_base_address(header()->requested_base_address() + addr_delta); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1402 |
if (addr_delta != 0 && !relocate_pointers(addr_delta)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1403 |
return MAP_ARCHIVE_OTHER_FAILURE; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1404 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1405 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1406 |
return MAP_ARCHIVE_SUCCESS; |
54927 | 1407 |
} |
1408 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1409 |
bool FileMapInfo::read_region(int i, char* base, size_t size) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1410 |
assert(MetaspaceShared::use_windows_memory_mapping(), "used by windows only"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1411 |
FileMapRegion* si = space_at(i); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1412 |
log_info(cds)("Commit %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)%s", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1413 |
is_static() ? "static " : "dynamic", i, p2i(base), p2i(base + size), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1414 |
shared_region_name[i], si->allow_exec() ? " exec" : ""); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1415 |
if (!os::commit_memory(base, size, si->allow_exec())) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1416 |
log_error(cds)("Failed to commit %s region #%d (%s)", is_static() ? "static " : "dynamic", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1417 |
i, shared_region_name[i]); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1418 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1419 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1420 |
if (lseek(_fd, (long)si->file_offset(), SEEK_SET) != (int)si->file_offset() || |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1421 |
read_bytes(base, size) != size) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1422 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1423 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1424 |
return true; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1425 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1426 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1427 |
MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_base_address, ReservedSpace rs) { |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1428 |
assert(!HeapShared::is_heap_region(i), "sanity"); |
58096 | 1429 |
FileMapRegion* si = space_at(i); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1430 |
size_t size = si->used_aligned(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1431 |
char *requested_addr = mapped_base_address + si->mapping_offset(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1432 |
assert(si->mapped_base() == NULL, "must be not mapped yet"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1433 |
assert(requested_addr != NULL, "must be specified"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1434 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1435 |
si->set_mapped_from_file(false); |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
1436 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1437 |
if (MetaspaceShared::use_windows_memory_mapping()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1438 |
// Windows cannot remap read-only shared memory to read-write when required for |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1439 |
// RedefineClasses, which is also used by JFR. Always map windows regions as RW. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1440 |
si->set_read_only(false); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1441 |
} else if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space() || |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1442 |
Arguments::has_jfr_option()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1443 |
// If a tool agent is in use (debugging enabled), or JFR, we must map the address space RW |
58096 | 1444 |
si->set_read_only(false); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1445 |
} else if (addr_delta != 0) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1446 |
si->set_read_only(false); // Need to patch the pointers |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1447 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1448 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1449 |
if (rs.is_reserved()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1450 |
assert(rs.contains(requested_addr) && rs.contains(requested_addr + size - 1), "must be"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1451 |
MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
31332
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
1452 |
} |
dc17890f352d
8054386: Allow Java debugging when CDS is enabled
cjplummer
parents:
28950
diff
changeset
|
1453 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1454 |
if (MetaspaceShared::use_windows_memory_mapping() && addr_delta != 0) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1455 |
// This is the second time we try to map the archive(s). We have already created a ReservedSpace |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1456 |
// that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1457 |
// can't mmap into a ReservedSpace, so we just os::read() the data. We're going to patch all the |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1458 |
// regions anyway, so there's no benefit for mmap anyway. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1459 |
if (!read_region(i, requested_addr, size)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1460 |
return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1461 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1462 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1463 |
char* base = os::map_memory(_fd, _full_path, si->file_offset(), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1464 |
requested_addr, size, si->read_only(), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1465 |
si->allow_exec()); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1466 |
if (base != requested_addr) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1467 |
log_info(cds)("Unable to map %s shared space at required address.", shared_region_name[i]); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1468 |
_memory_mapping_failed = true; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1469 |
return MAP_ARCHIVE_MMAP_FAILURE; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1470 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1471 |
si->set_mapped_from_file(true); |
1 | 1472 |
} |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1473 |
si->set_mapped_base(requested_addr); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1474 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1475 |
if (!rs.is_reserved()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1476 |
// When mapping on Windows with (addr_delta == 0), we don't reserve the address space for the regions |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1477 |
// (Windows can't mmap into a ReservedSpace). In this case, NMT requires we call it after |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1478 |
// os::map_memory has succeeded. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1479 |
assert(MetaspaceShared::use_windows_memory_mapping(), "Windows memory mapping only"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1480 |
MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1481 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1482 |
|
54838 | 1483 |
if (VerifySharedSpaces && !verify_region_checksum(i)) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1484 |
return MAP_ARCHIVE_OTHER_FAILURE; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1485 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1486 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1487 |
return MAP_ARCHIVE_SUCCESS; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1488 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1489 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1490 |
char* FileMapInfo::map_relocation_bitmap(size_t& bitmap_size) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1491 |
FileMapRegion* si = space_at(MetaspaceShared::bm); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1492 |
bitmap_size = si->used_aligned(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1493 |
bool read_only = true, allow_exec = false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1494 |
char* requested_addr = NULL; // allow OS to pick any location |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1495 |
char* bitmap_base = os::map_memory(_fd, _full_path, si->file_offset(), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1496 |
requested_addr, bitmap_size, read_only, allow_exec); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1497 |
if (bitmap_base == NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1498 |
log_error(cds)("failed to map relocation bitmap"); |
48794
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47991
diff
changeset
|
1499 |
return NULL; |
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47991
diff
changeset
|
1500 |
} |
ea0d0781c63c
8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents:
47991
diff
changeset
|
1501 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1502 |
if (VerifySharedSpaces && !region_crc_check(bitmap_base, bitmap_size, si->crc())) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1503 |
log_error(cds)("relocation bitmap CRC error"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1504 |
if (!os::unmap_memory(bitmap_base, bitmap_size)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1505 |
fatal("os::unmap_memory of relocation bitmap failed"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1506 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1507 |
return NULL; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1508 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1509 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1510 |
return bitmap_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1511 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1512 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1513 |
bool FileMapInfo::relocate_pointers(intx addr_delta) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1514 |
log_debug(cds, reloc)("runtime archive relocation start"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1515 |
size_t bitmap_size; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1516 |
char* bitmap_base = map_relocation_bitmap(bitmap_size); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1517 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1518 |
if (bitmap_base == NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1519 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1520 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1521 |
size_t ptrmap_size_in_bits = header()->ptrmap_size_in_bits(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1522 |
log_debug(cds, reloc)("mapped relocation bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1523 |
" bytes = " SIZE_FORMAT " bits)", |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1524 |
p2i(bitmap_base), bitmap_size, ptrmap_size_in_bits); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1525 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1526 |
BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1527 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1528 |
// Patch all pointers in the the mapped region that are marked by ptrmap. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1529 |
address patch_base = (address)mapped_base(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1530 |
address patch_end = (address)mapped_end(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1531 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1532 |
// the current value of the pointers to be patched must be within this |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1533 |
// range (i.e., must be between the requesed base address, and the of the current archive). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1534 |
// Note: top archive may point to objects in the base archive, but not the other way around. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1535 |
address valid_old_base = (address)header()->requested_base_address(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1536 |
address valid_old_end = valid_old_base + mapping_end_offset(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1537 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1538 |
// after patching, the pointers must point inside this range |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1539 |
// (the requested location of the archive, as mapped at runtime). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1540 |
address valid_new_base = (address)header()->mapped_base_address(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1541 |
address valid_new_end = (address)mapped_end(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1542 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1543 |
SharedDataRelocator<false> patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end, |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1544 |
valid_new_base, valid_new_end, addr_delta); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1545 |
ptrmap.iterate(&patcher); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1546 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1547 |
if (!os::unmap_memory(bitmap_base, bitmap_size)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1548 |
fatal("os::unmap_memory of relocation bitmap failed"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1549 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1550 |
log_debug(cds, reloc)("runtime archive relocation done"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1551 |
return true; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1552 |
} |
1 | 1553 |
} |
1554 |
||
54927 | 1555 |
size_t FileMapInfo::read_bytes(void* buffer, size_t count) { |
1556 |
assert(_file_open, "Archive file is not open"); |
|
1557 |
size_t n = os::read(_fd, buffer, (unsigned int)count); |
|
1558 |
if (n != count) { |
|
1559 |
// Close the file if there's a problem reading it. |
|
1560 |
close(); |
|
1561 |
return 0; |
|
1562 |
} |
|
1563 |
_file_offset += count; |
|
1564 |
return count; |
|
1565 |
} |
|
1566 |
||
58096 | 1567 |
address FileMapInfo::decode_start_address(FileMapRegion* spc, bool with_current_oop_encoding_mode) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1568 |
size_t offset = spc->mapping_offset(); |
59128 | 1569 |
assert(offset == (size_t)(uint32_t)offset, "must be 32-bit only"); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1570 |
uint n = (uint)offset; |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1571 |
if (with_current_oop_encoding_mode) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1572 |
return (address)CompressedOops::decode_not_null(n); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1573 |
} else { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1574 |
return (address)HeapShared::decode_from_archive(n); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1575 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1576 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1577 |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1578 |
static MemRegion *closed_archive_heap_ranges = NULL; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1579 |
static MemRegion *open_archive_heap_ranges = NULL; |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1580 |
static int num_closed_archive_heap_ranges = 0; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1581 |
static int num_open_archive_heap_ranges = 0; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1582 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1583 |
#if INCLUDE_CDS_JAVA_HEAP |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1584 |
bool FileMapInfo::has_heap_regions() { |
58096 | 1585 |
return (space_at(MetaspaceShared::first_closed_archive_heap_region)->used() > 0); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1586 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1587 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1588 |
// Returns the address range of the archived heap regions computed using the |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1589 |
// current oop encoding mode. This range may be different than the one seen at |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1590 |
// dump time due to encoding mode differences. The result is used in determining |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1591 |
// if/how these regions should be relocated at run time. |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1592 |
MemRegion FileMapInfo::get_heap_regions_range_with_current_oop_encoding_mode() { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1593 |
address start = (address) max_uintx; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1594 |
address end = NULL; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1595 |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1596 |
for (int i = MetaspaceShared::first_closed_archive_heap_region; |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1597 |
i <= MetaspaceShared::last_valid_region; |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1598 |
i++) { |
58096 | 1599 |
FileMapRegion* si = space_at(i); |
1600 |
size_t size = si->used(); |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1601 |
if (size > 0) { |
51720
b7bfd64e43a6
8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents:
51491
diff
changeset
|
1602 |
address s = start_address_as_decoded_with_current_oop_encoding_mode(si); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1603 |
address e = s + size; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1604 |
if (start > s) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1605 |
start = s; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1606 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1607 |
if (end < e) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1608 |
end = e; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1609 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1610 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1611 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1612 |
assert(end != NULL, "must have at least one used heap region"); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1613 |
return MemRegion((HeapWord*)start, (HeapWord*)end); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1614 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1615 |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1616 |
// |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1617 |
// Map the closed and open archive heap objects to the runtime java heap. |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1618 |
// |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1619 |
// The shared objects are mapped at (or close to ) the java heap top in |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1620 |
// closed archive regions. The mapped objects contain no out-going |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1621 |
// references to any other java heap regions. GC does not write into the |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1622 |
// mapped closed archive heap region. |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1623 |
// |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1624 |
// The open archive heap objects are mapped below the shared objects in |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1625 |
// the runtime java heap. The mapped open archive heap data only contains |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1626 |
// references to the shared objects and open archive objects initially. |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1627 |
// During runtime execution, out-going references to any other java heap |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1628 |
// regions may be added. GC may mark and update references in the mapped |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1629 |
// open archive objects. |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1630 |
void FileMapInfo::map_heap_regions_impl() { |
52062
8dbf1a13af49
8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents:
51823
diff
changeset
|
1631 |
if (!HeapShared::is_heap_object_archiving_allowed()) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1632 |
log_info(cds)("CDS heap data is being ignored. UseG1GC, " |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1633 |
"UseCompressedOops and UseCompressedClassPointers are required."); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1634 |
return; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1635 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1636 |
|
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1637 |
if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) { |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1638 |
ShouldNotReachHere(); // CDS should have been disabled. |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1639 |
// The archived objects are mapped at JVM start-up, but we don't know if |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1640 |
// j.l.String or j.l.Class might be replaced by the ClassFileLoadHook, |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1641 |
// which would make the archived String or mirror objects invalid. Let's be safe and not |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1642 |
// use the archived objects. These 2 classes are loaded during the JVMTI "early" stage. |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1643 |
// |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1644 |
// If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1645 |
// in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1646 |
// because we won't install an archived object subgraph if the klass of any of the |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1647 |
// referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph(). |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1648 |
} |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1649 |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1650 |
log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:", |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1651 |
max_heap_size()/M); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1652 |
log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1653 |
p2i(narrow_klass_base()), narrow_klass_shift()); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1654 |
log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1655 |
narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift()); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1656 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1657 |
log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT, |
58015
dd84de796f2c
8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents:
57898
diff
changeset
|
1658 |
MaxHeapSize/M, HeapRegion::GrainBytes); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1659 |
log_info(cds)(" narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d", |
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1660 |
p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift()); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1661 |
log_info(cds)(" narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d", |
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1662 |
CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift()); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1663 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1664 |
if (narrow_klass_base() != CompressedKlassPointers::base() || |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1665 |
narrow_klass_shift() != CompressedKlassPointers::shift()) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1666 |
log_info(cds)("CDS heap data cannot be used because the archive was created with an incompatible narrow klass encoding mode."); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1667 |
return; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1668 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1669 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1670 |
if (narrow_oop_mode() != CompressedOops::mode() || |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1671 |
narrow_oop_base() != CompressedOops::base() || |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
54573
diff
changeset
|
1672 |
narrow_oop_shift() != CompressedOops::shift()) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1673 |
log_info(cds)("CDS heap data need to be relocated because the archive was created with an incompatible oop encoding mode."); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1674 |
_heap_pointers_need_patching = true; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1675 |
} else { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1676 |
MemRegion range = get_heap_regions_range_with_current_oop_encoding_mode(); |
58015
dd84de796f2c
8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents:
57898
diff
changeset
|
1677 |
if (!CompressedOops::is_in(range)) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1678 |
log_info(cds)("CDS heap data need to be relocated because"); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1679 |
log_info(cds)("the desired range " PTR_FORMAT " - " PTR_FORMAT, p2i(range.start()), p2i(range.end())); |
58015
dd84de796f2c
8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents:
57898
diff
changeset
|
1680 |
log_info(cds)("is outside of the heap " PTR_FORMAT " - " PTR_FORMAT, p2i(CompressedOops::begin()), p2i(CompressedOops::end())); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1681 |
_heap_pointers_need_patching = true; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1682 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1683 |
} |
47599
0fb1d501c408
8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents:
47216
diff
changeset
|
1684 |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1685 |
ptrdiff_t delta = 0; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1686 |
if (_heap_pointers_need_patching) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1687 |
// dumptime heap end ------------v |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1688 |
// [ |archived heap regions| ] runtime heap end ------v |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1689 |
// [ |archived heap regions| ] |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1690 |
// |<-----delta-------------------->| |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1691 |
// |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1692 |
// At dump time, the archived heap regions were near the top of the heap. |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1693 |
// At run time, they may not be inside the heap, so we move them so |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1694 |
// that they are now near the top of the runtime time. This can be done by |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1695 |
// the simple math of adding the delta as shown above. |
58096 | 1696 |
address dumptime_heap_end = header()->heap_end(); |
58015
dd84de796f2c
8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents:
57898
diff
changeset
|
1697 |
address runtime_heap_end = (address)CompressedOops::end(); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1698 |
delta = runtime_heap_end - dumptime_heap_end; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1699 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1700 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1701 |
log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1702 |
HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift()); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1703 |
|
58096 | 1704 |
FileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region); |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1705 |
address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si); |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1706 |
if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) { |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1707 |
// Align the bottom of the closed archive heap regions at G1 region boundary. |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1708 |
// This will avoid the situation where the highest open region and the lowest |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1709 |
// closed region sharing the same G1 region. Otherwise we will fail to map the |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1710 |
// open regions. |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1711 |
size_t align = size_t(relocated_closed_heap_region_bottom) % HeapRegion::GrainBytes; |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1712 |
delta -= align; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1713 |
log_info(cds)("CDS heap data need to be relocated lower by a further " SIZE_FORMAT |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1714 |
" bytes to " INTX_FORMAT " to be aligned with HeapRegion::GrainBytes", |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1715 |
align, delta); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1716 |
HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift()); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1717 |
_heap_pointers_need_patching = true; |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1718 |
relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1719 |
} |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1720 |
assert(is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes), |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1721 |
"must be"); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1722 |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1723 |
// Map the closed_archive_heap regions, GC does not write into the regions. |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1724 |
if (map_heap_data(&closed_archive_heap_ranges, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1725 |
MetaspaceShared::first_closed_archive_heap_region, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1726 |
MetaspaceShared::max_closed_archive_heap_region, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1727 |
&num_closed_archive_heap_ranges)) { |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1728 |
HeapShared::set_closed_archive_heap_region_mapped(); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1729 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1730 |
// Now, map open_archive heap regions, GC can write into the regions. |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1731 |
if (map_heap_data(&open_archive_heap_ranges, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1732 |
MetaspaceShared::first_open_archive_heap_region, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1733 |
MetaspaceShared::max_open_archive_heap_region, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1734 |
&num_open_archive_heap_ranges, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1735 |
true /* open */)) { |
52062
8dbf1a13af49
8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents:
51823
diff
changeset
|
1736 |
HeapShared::set_open_archive_heap_region_mapped(); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1737 |
} |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1738 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1739 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1740 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1741 |
void FileMapInfo::map_heap_regions() { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1742 |
if (has_heap_regions()) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1743 |
map_heap_regions_impl(); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1744 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1745 |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1746 |
if (!HeapShared::closed_archive_heap_region_mapped()) { |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1747 |
assert(closed_archive_heap_ranges == NULL && |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1748 |
num_closed_archive_heap_ranges == 0, "sanity"); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1749 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1750 |
|
52062
8dbf1a13af49
8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents:
51823
diff
changeset
|
1751 |
if (!HeapShared::open_archive_heap_region_mapped()) { |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1752 |
assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity"); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1753 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1754 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1755 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1756 |
bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first, |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1757 |
int max, int* num, bool is_open_archive) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1758 |
MemRegion * regions = new MemRegion[max]; |
58096 | 1759 |
FileMapRegion* si; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1760 |
int region_num = 0; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1761 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1762 |
for (int i = first; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1763 |
i < first + max; i++) { |
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1764 |
si = space_at(i); |
58096 | 1765 |
size_t size = si->used(); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1766 |
if (size > 0) { |
51720
b7bfd64e43a6
8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents:
51491
diff
changeset
|
1767 |
HeapWord* start = (HeapWord*)start_address_as_decoded_from_archive(si); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1768 |
regions[region_num] = MemRegion(start, size / HeapWordSize); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1769 |
region_num ++; |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1770 |
log_info(cds)("Trying to map heap data: region[%d] at " INTPTR_FORMAT ", size = " SIZE_FORMAT_W(8) " bytes", |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1771 |
i, p2i(start), size); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1772 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1773 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1774 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1775 |
if (region_num == 0) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1776 |
return false; // no archived java heap data |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1777 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1778 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1779 |
// Check that ranges are within the java heap |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1780 |
if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1781 |
log_info(cds)("UseSharedSpaces: Unable to allocate region, range is not within java heap."); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1782 |
return false; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1783 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1784 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1785 |
// allocate from java heap |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1786 |
if (!G1CollectedHeap::heap()->alloc_archive_regions( |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1787 |
regions, region_num, is_open_archive)) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1788 |
log_info(cds)("UseSharedSpaces: Unable to allocate region, java heap range is already in use."); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1789 |
return false; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1790 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1791 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1792 |
// Map the archived heap data. No need to call MemTracker::record_virtual_memory_type() |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1793 |
// for mapped regions as they are part of the reserved java heap, which is |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1794 |
// already recorded. |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1795 |
for (int i = 0; i < region_num; i++) { |
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1796 |
si = space_at(first + i); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1797 |
char* addr = (char*)regions[i].start(); |
58096 | 1798 |
char* base = os::map_memory(_fd, _full_path, si->file_offset(), |
1799 |
addr, regions[i].byte_size(), si->read_only(), |
|
1800 |
si->allow_exec()); |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1801 |
if (base == NULL || base != addr) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1802 |
// dealloc the regions from java heap |
52674
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
1803 |
dealloc_archive_heap_regions(regions, region_num, is_open_archive); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1804 |
log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. " |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1805 |
INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes", |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1806 |
p2i(addr), regions[i].byte_size()); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1807 |
return false; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1808 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1809 |
|
58096 | 1810 |
if (VerifySharedSpaces && !region_crc_check(addr, regions[i].byte_size(), si->crc())) { |
54927 | 1811 |
// dealloc the regions from java heap |
1812 |
dealloc_archive_heap_regions(regions, region_num, is_open_archive); |
|
1813 |
log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt"); |
|
1814 |
return false; |
|
1815 |
} |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1816 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1817 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1818 |
// the shared heap data is mapped successfully |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1819 |
*heap_mem = regions; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1820 |
*num = region_num; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1821 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1822 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1823 |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1824 |
void FileMapInfo::patch_archived_heap_embedded_pointers() { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1825 |
if (!_heap_pointers_need_patching) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1826 |
return; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1827 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1828 |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1829 |
patch_archived_heap_embedded_pointers(closed_archive_heap_ranges, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1830 |
num_closed_archive_heap_ranges, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1831 |
MetaspaceShared::first_closed_archive_heap_region); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1832 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1833 |
patch_archived_heap_embedded_pointers(open_archive_heap_ranges, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1834 |
num_open_archive_heap_ranges, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1835 |
MetaspaceShared::first_open_archive_heap_region); |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1836 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1837 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1838 |
void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges, |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1839 |
int first_region_idx) { |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1840 |
for (int i=0; i<num_ranges; i++) { |
58096 | 1841 |
FileMapRegion* si = space_at(i + first_region_idx); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1842 |
HeapShared::patch_archived_heap_embedded_pointers(ranges[i], (address)(SharedBaseAddress + si->oopmap_offset()), |
58096 | 1843 |
si->oopmap_size_in_bits()); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1844 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1845 |
} |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1846 |
|
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1847 |
// This internally allocates objects using SystemDictionary::Object_klass(), so it |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1848 |
// must be called after the well-known classes are resolved. |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1849 |
void FileMapInfo::fixup_mapped_heap_regions() { |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1850 |
// If any closed regions were found, call the fill routine to make them parseable. |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1851 |
// Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found. |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1852 |
if (num_closed_archive_heap_ranges != 0) { |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1853 |
assert(closed_archive_heap_ranges != NULL, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1854 |
"Null closed_archive_heap_ranges array with non-zero count"); |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1855 |
G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges, |
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1856 |
num_closed_archive_heap_ranges); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1857 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1858 |
|
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1859 |
// do the same for mapped open archive heap regions |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1860 |
if (num_open_archive_heap_ranges != 0) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1861 |
assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count"); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1862 |
G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges, |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1863 |
num_open_archive_heap_ranges); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1864 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1865 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1866 |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1867 |
// dealloc the archive regions from java heap |
52674
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
1868 |
void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) { |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1869 |
if (num > 0) { |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1870 |
assert(regions != NULL, "Null archive ranges array with non-zero count"); |
52674
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
1871 |
G1CollectedHeap::heap()->dealloc_archive_regions(regions, num, is_open); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1872 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1873 |
} |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1874 |
#endif // INCLUDE_CDS_JAVA_HEAP |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
1875 |
|
54927 | 1876 |
bool FileMapInfo::region_crc_check(char* buf, size_t size, int expected_crc) { |
1877 |
int crc = ClassLoader::crc32(0, buf, (jint)size); |
|
1878 |
if (crc != expected_crc) { |
|
1879 |
fail_continue("Checksum verification failed."); |
|
1880 |
return false; |
|
1881 |
} |
|
1882 |
return true; |
|
1883 |
} |
|
1884 |
||
27025 | 1885 |
bool FileMapInfo::verify_region_checksum(int i) { |
54838 | 1886 |
assert(VerifySharedSpaces, "sanity"); |
58096 | 1887 |
size_t sz = space_at(i)->used(); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1888 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1889 |
if (sz == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1890 |
return true; // no data |
58096 | 1891 |
} else { |
1892 |
return region_crc_check(region_addr(i), sz, space_at(i)->crc()); |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1893 |
} |
54927 | 1894 |
} |
1895 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1896 |
void FileMapInfo::unmap_regions(int regions[], int num_regions) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1897 |
for (int r = 0; r < num_regions; r++) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1898 |
int idx = regions[r]; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1899 |
unmap_region(idx); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1900 |
} |
27025 | 1901 |
} |
1 | 1902 |
|
1903 |
// Unmap a memory region in the address space. |
|
1904 |
||
1905 |
void FileMapInfo::unmap_region(int i) { |
|
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1906 |
assert(!HeapShared::is_heap_region(i), "sanity"); |
58096 | 1907 |
FileMapRegion* si = space_at(i); |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1908 |
char* mapped_base = si->mapped_base(); |
58096 | 1909 |
size_t used = si->used(); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46560
diff
changeset
|
1910 |
size_t size = align_up(used, os::vm_allocation_granularity()); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1911 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1912 |
if (mapped_base != NULL && size > 0 && si->mapped_from_file()) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1913 |
log_info(cds)("Unmapping region #%d at base " INTPTR_FORMAT " (%s)", i, p2i(mapped_base), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1914 |
shared_region_name[i]); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1915 |
if (!os::unmap_memory(mapped_base, size)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1916 |
fatal("os::unmap_memory failed"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1917 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1918 |
si->set_mapped_base(NULL); |
1 | 1919 |
} |
1920 |
} |
|
1921 |
||
1922 |
void FileMapInfo::assert_mark(bool check) { |
|
1923 |
if (!check) { |
|
26296 | 1924 |
fail_stop("Mark mismatch while restoring from shared file."); |
1 | 1925 |
} |
1926 |
} |
|
1927 |
||
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1928 |
void FileMapInfo::metaspace_pointers_do(MetaspaceClosure* it) { |
54927 | 1929 |
_shared_path_table.metaspace_pointers_do(it); |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1930 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
1931 |
|
1 | 1932 |
FileMapInfo* FileMapInfo::_current_info = NULL; |
54927 | 1933 |
FileMapInfo* FileMapInfo::_dynamic_archive_info = NULL; |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1934 |
bool FileMapInfo::_heap_pointers_need_patching = false; |
54927 | 1935 |
SharedPathTable FileMapInfo::_shared_path_table; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
1936 |
bool FileMapInfo::_validating_shared_path_table = false; |
54927 | 1937 |
bool FileMapInfo::_memory_mapping_failed = false; |
57898 | 1938 |
GrowableArray<const char*>* FileMapInfo::_non_existent_class_paths = NULL; |
1 | 1939 |
|
1940 |
// Open the shared archive file, read and validate the header |
|
1941 |
// information (version, boot classpath, etc.). If initialization |
|
1942 |
// fails, shared spaces are disabled and the file is closed. [See |
|
1943 |
// fail_continue.] |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
1944 |
// |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
1945 |
// Validation of the archive is done in two steps: |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
1946 |
// |
57898 | 1947 |
// [1] validate_header() - done here. |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
1948 |
// [2] validate_shared_path_table - this is done later, because the table is in the RW |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
1949 |
// region of the archive, which is not mapped yet. |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1950 |
bool FileMapInfo::initialize() { |
1 | 1951 |
assert(UseSharedSpaces, "UseSharedSpaces expected."); |
1952 |
||
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1953 |
if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) { |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1954 |
// CDS assumes that no classes resolved in SystemDictionary::resolve_well_known_classes |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1955 |
// are replaced at runtime by JVMTI ClassFileLoadHook. All of those classes are resolved |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1956 |
// during the JVMTI "early" stage, so we can still use CDS if |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1957 |
// JvmtiExport::has_early_class_hook_env() is false. |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1958 |
FileMapInfo::fail_continue("CDS is disabled because early JVMTI ClassFileLoadHook is in use."); |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1959 |
return false; |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1960 |
} |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
52314
diff
changeset
|
1961 |
|
1 | 1962 |
if (!open_for_read()) { |
1963 |
return false; |
|
1964 |
} |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1965 |
if (!init_from_file(_fd)) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1966 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1967 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1968 |
if (!validate_header()) { |
1 | 1969 |
return false; |
1970 |
} |
|
1971 |
return true; |
|
1972 |
} |
|
1973 |
||
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1974 |
char* FileMapInfo::region_addr(int idx) { |
58096 | 1975 |
FileMapRegion* si = space_at(idx); |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
1976 |
if (HeapShared::is_heap_region(idx)) { |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
1977 |
assert(DumpSharedSpaces, "The following doesn't work at runtime"); |
58096 | 1978 |
return si->used() > 0 ? |
51720
b7bfd64e43a6
8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents:
51491
diff
changeset
|
1979 |
(char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1980 |
} else { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1981 |
return si->mapped_base(); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1982 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1983 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
31332
diff
changeset
|
1984 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1985 |
FileMapRegion* FileMapInfo::first_core_space() const { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1986 |
return is_static() ? space_at(MetaspaceShared::mc) : space_at(MetaspaceShared::rw); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1987 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1988 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1989 |
FileMapRegion* FileMapInfo::last_core_space() const { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1990 |
return is_static() ? space_at(MetaspaceShared::md) : space_at(MetaspaceShared::mc); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1991 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
1992 |
|
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1993 |
int FileMapHeader::compute_crc() { |
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1994 |
char* start = (char*)this; |
27025 | 1995 |
// start computing from the field after _crc |
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
1996 |
char* buf = (char*)&_crc + sizeof(_crc); |
54927 | 1997 |
size_t sz = _header_size - (buf - start); |
27025 | 1998 |
int crc = ClassLoader::crc32(0, buf, (jint)sz); |
1999 |
return crc; |
|
2000 |
} |
|
2001 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49592
diff
changeset
|
2002 |
// This function should only be called during run time with UseSharedSpaces enabled. |
51477
e77d7687c831
8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents:
51439
diff
changeset
|
2003 |
bool FileMapHeader::validate() { |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
2004 |
if (_obj_alignment != ObjectAlignmentInBytes) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
2005 |
FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d" |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
32589
diff
changeset
|
2006 |
" does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".", |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
2007 |
_obj_alignment, ObjectAlignmentInBytes); |
1 | 2008 |
return false; |
2009 |
} |
|
33628 | 2010 |
if (_compact_strings != CompactStrings) { |
2011 |
FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)" |
|
2012 |
" does not equal the current CompactStrings setting (%s).", |
|
2013 |
_compact_strings ? "enabled" : "disabled", |
|
2014 |
CompactStrings ? "enabled" : "disabled"); |
|
2015 |
return false; |
|
2016 |
} |
|
1 | 2017 |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2018 |
// This must be done after header validation because it might change the |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2019 |
// header data |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2020 |
const char* prop = Arguments::get_property("java.system.class.loader"); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2021 |
if (prop != NULL) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2022 |
warning("Archived non-system classes are disabled because the " |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2023 |
"java.system.class.loader property is specified (value = \"%s\"). " |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
2024 |
"To use archived non-system classes, this property must not be set", prop); |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2025 |
_has_platform_or_app_classes = false; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2026 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2027 |
|
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2028 |
// For backwards compatibility, we don't check the verification setting |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2029 |
// if the archive only contains system classes. |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2030 |
if (_has_platform_or_app_classes && |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2031 |
((!_verify_local && BytecodeVerificationLocal) || |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2032 |
(!_verify_remote && BytecodeVerificationRemote))) { |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2033 |
FileMapInfo::fail_continue("The shared archive file was created with less restrictive " |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2034 |
"verification setting than the current setting."); |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2035 |
return false; |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2036 |
} |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49982
diff
changeset
|
2037 |
|
52596
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2038 |
// Java agents are allowed during run time. Therefore, the following condition is not |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2039 |
// checked: (!_allow_archiving_with_java_agent && AllowArchivingWithJavaAgent) |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2040 |
// Note: _allow_archiving_with_java_agent is set in the shared archive during dump time |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2041 |
// while AllowArchivingWithJavaAgent is set during the current run. |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2042 |
if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) { |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2043 |
FileMapInfo::fail_continue("The setting of the AllowArchivingWithJavaAgent is different " |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2044 |
"from the setting in the shared archive."); |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2045 |
return false; |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2046 |
} |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2047 |
|
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2048 |
if (_allow_archiving_with_java_agent) { |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2049 |
warning("This archive was created with AllowArchivingWithJavaAgent. It should be used " |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2050 |
"for testing purposes only and should not be used in a production environment"); |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2051 |
} |
dfa02b3f728c
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
52562
diff
changeset
|
2052 |
|
1 | 2053 |
return true; |
2054 |
} |
|
2055 |
||
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
2056 |
bool FileMapInfo::validate_header() { |
58096 | 2057 |
return header()->validate(); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
2058 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
2059 |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
2060 |
// Check if a given address is within one of the shared regions |
37439
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2061 |
bool FileMapInfo::is_in_shared_region(const void* p, int idx) { |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
2062 |
assert(idx == MetaspaceShared::ro || |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
2063 |
idx == MetaspaceShared::rw || |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
2064 |
idx == MetaspaceShared::mc || |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
2065 |
idx == MetaspaceShared::md, "invalid region index"); |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51480
diff
changeset
|
2066 |
char* base = region_addr(idx); |
58096 | 2067 |
if (p >= base && p < base + space_at(idx)->used()) { |
37439
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2068 |
return true; |
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2069 |
} |
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2070 |
return false; |
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2071 |
} |
e8970711113b
8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents:
37179
diff
changeset
|
2072 |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2073 |
// Unmap mapped regions of shared space. |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2074 |
void FileMapInfo::stop_sharing_and_unmap(const char* msg) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
2075 |
MetaspaceShared::set_shared_metaspace_range(NULL, NULL, NULL); |
52314
e53af5fa0dae
8212205: VM asserts after CDS archive has been unmapped
iklam
parents:
52126
diff
changeset
|
2076 |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2077 |
FileMapInfo *map_info = FileMapInfo::current_info(); |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2078 |
if (map_info) { |
26296 | 2079 |
map_info->fail_continue("%s", msg); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
2080 |
for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) { |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
2081 |
if (!HeapShared::is_heap_region(i)) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58447
diff
changeset
|
2082 |
map_info->unmap_region(i); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2083 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2084 |
} |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
2085 |
// Dealloc the archive heap regions only without unmapping. The regions are part |
32589
f86fb16fcab0
8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents:
31375
diff
changeset
|
2086 |
// of the java heap. Unmapping of the heap regions are managed by GC. |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
2087 |
map_info->dealloc_archive_heap_regions(open_archive_heap_ranges, |
52674
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
2088 |
num_open_archive_heap_ranges, |
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
2089 |
true); |
52402
72d4e10305b9
8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents:
52319
diff
changeset
|
2090 |
map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges, |
52674
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
2091 |
num_closed_archive_heap_ranges, |
c9325aa887da
8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents:
52596
diff
changeset
|
2092 |
false); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2093 |
} else if (DumpSharedSpaces) { |
26296 | 2094 |
fail_stop("%s", msg); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2095 |
} |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
18483
diff
changeset
|
2096 |
} |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2097 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2098 |
#if INCLUDE_JVMTI |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2099 |
ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = NULL; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2100 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2101 |
ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2102 |
ClassPathEntry* ent = _classpath_entries_for_jvmti[i]; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2103 |
if (ent == NULL) { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2104 |
if (i == 0) { |
57898 | 2105 |
ent = ClassLoader::get_jrt_entry(); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2106 |
assert(ent != NULL, "must be"); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2107 |
} else { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2108 |
SharedClassPathEntry* scpe = shared_path(i); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2109 |
assert(scpe->is_jar(), "must be"); // other types of scpe will not produce archived classes |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2110 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2111 |
const char* path = scpe->name(); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2112 |
struct stat st; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2113 |
if (os::stat(path, &st) != 0) { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2114 |
char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); ; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2115 |
jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2116 |
THROW_MSG_(vmSymbols::java_io_IOException(), msg, NULL); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2117 |
} else { |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
55296
diff
changeset
|
2118 |
ent = ClassLoader::create_class_path_entry(path, &st, /*throw_exception=*/true, false, false, CHECK_NULL); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2119 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2120 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2121 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2122 |
MutexLocker mu(CDSClassFileStream_lock, THREAD); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2123 |
if (_classpath_entries_for_jvmti[i] == NULL) { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2124 |
_classpath_entries_for_jvmti[i] = ent; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2125 |
} else { |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2126 |
// Another thread has beat me to creating this entry |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2127 |
delete ent; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2128 |
ent = _classpath_entries_for_jvmti[i]; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2129 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2130 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2131 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2132 |
return ent; |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2133 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2134 |
|
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2135 |
ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS) { |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2136 |
int path_index = ik->shared_classpath_index(); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2137 |
assert(path_index >= 0, "should be called for shared built-in classes only"); |
54927 | 2138 |
assert(path_index < (int)get_number_of_shared_paths(), "sanity"); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2139 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2140 |
ClassPathEntry* cpe = get_classpath_entry_for_jvmti(path_index, CHECK_NULL); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2141 |
assert(cpe != NULL, "must be"); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2142 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2143 |
Symbol* name = ik->name(); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2144 |
const char* const class_name = name->as_C_string(); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2145 |
const char* const file_name = ClassLoader::file_name_for_class_name(class_name, |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2146 |
name->utf8_length()); |
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2147 |
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2148 |
ClassFileStream* cfs = cpe->open_stream_for_loader(file_name, loader_data, THREAD); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2149 |
assert(cfs != NULL, "must be able to read the classfile data of shared classes for built-in loaders."); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2150 |
log_debug(cds, jvmti)("classfile data for %s [%d: %s] = %d bytes", class_name, path_index, |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2151 |
cfs->source(), cfs->length()); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53911
diff
changeset
|
2152 |
return cfs; |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2153 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2154 |
|
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52811
diff
changeset
|
2155 |
#endif |