annotate src/share/vm/memory/filemap.cpp @ 20375:6e0cb14ce59b

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