annotate src/share/vm/memory/filemap.cpp @ 1716:be3f9c242c9d

6948538: CMS: BOT walkers can fall into object allocation and initialization cracks Summary: GC workers now recognize an intermediate transient state of blocks which are allocated but have not yet completed initialization. blk_start() calls do not attempt to determine the size of a block in the transient state, rather waiting for the block to become initialized so that it is safe to query its size. Audited and ensured the order of initialization of object fields (klass, free bit and size) to respect block state transition protocol. Also included some new assertion checking code enabled in debug mode. Reviewed-by: chrisphi, johnc, poonam
author ysr
date Mon, 16 Aug 2010 15:58:42 -0700
parents c18cbe5936b8
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
2 * Copyright (c) 2003, 2006, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_filemap.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27 # include <sys/stat.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
28 # include <errno.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifndef O_BINARY // if defined (Win32) use binary files.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #define O_BINARY 0 // otherwise do nothing.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 extern address JVM_FunctionAtStart();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 extern address JVM_FunctionAtEnd();
a61af66fc99e Initial load
duke
parents:
diff changeset
37
605
98cb887364d3 6810672: Comment typos
twisti
parents: 0
diff changeset
38 // Complain and stop. All error conditions occurring during the writing of
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // an archive file should stop the process. Unrecoverable errors during
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // the reading of the archive file should stop the process.
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 static void fail(const char *msg, va_list ap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // This occurs very early during initialization: tty is not initialized.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 jio_fprintf(defaultStream::error_stream(),
605
98cb887364d3 6810672: Comment typos
twisti
parents: 0
diff changeset
45 "An error has occurred while processing the"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 " shared archive file.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
47 jio_vfprintf(defaultStream::error_stream(), msg, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 jio_fprintf(defaultStream::error_stream(), "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 vm_exit_during_initialization("Unable to use shared archive.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 void FileMapInfo::fail_stop(const char *msg, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 va_start(ap, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 fail(msg, ap); // Never returns.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 va_end(ap); // for completeness.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Complain and continue. Recoverable errors during the reading of the
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // archive file may continue (with sharing disabled).
a61af66fc99e Initial load
duke
parents:
diff changeset
63 //
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // If we continue, then disable shared spaces and close the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void FileMapInfo::fail_continue(const char *msg, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 va_start(ap, msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 if (RequireSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 fail(msg, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 va_end(ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 UseSharedSpaces = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Fill in the fileMapInfo structure with data about this VM instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void FileMapInfo::populate_header(size_t alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _header._magic = 0xf00baba2;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _header._version = _current_version;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 _header._alignment = alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // The following fields are for sanity checks for whether this archive
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // will function correctly with this JVM and the bootclasspath it's
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // invoked with.
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // JVM version string ... changes on each build.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 const char *vm_version = VM_Version::internal_vm_info_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (strlen(vm_version) < (JVM_IDENT_MAX-1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 strcpy(_header._jvm_ident, vm_version);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 fail_stop("JVM Ident field for shared archive is too long"
a61af66fc99e Initial load
duke
parents:
diff changeset
95 " - truncated to <%s>", _header._jvm_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Build checks on classpath and jar files
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _header._num_jars = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for ( ; cpe != NULL; cpe = cpe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (cpe->is_jar_file()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 fail_stop("Too many jar files to share.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Jar file - record timestamp and file size.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 struct stat st;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 const char *path = cpe->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (os::stat(path, &st) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // If we can't access a jar file in the boot path, then we can't
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // make assumptions about where classes get loaded from.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 fail_stop("Unable to open jar file %s.", path);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 _header._jar[_header._num_jars]._timestamp = st.st_mtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 _header._jar[_header._num_jars]._filesize = st.st_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 _header._num_jars++;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // If directories appear in boot classpath, they must be empty to
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // avoid having to verify each individual class file.
a61af66fc99e Initial load
duke
parents:
diff changeset
123 const char* name = ((ClassPathDirEntry*)cpe)->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (!os::dir_is_empty(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 fail_stop("Boot classpath directory %s is not empty.", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Read the FileMapInfo information from the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 bool FileMapInfo::init_from_file(int fd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 size_t n = read(fd, &_header, sizeof(struct FileMapHeader));
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (n != sizeof(struct FileMapHeader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 fail_continue("Unable to read the file header.");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (_header._version != current_version()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 fail_continue("The shared archive file has the wrong version.");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _file_offset = (long)n;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Read the FileMapInfo information from the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 bool FileMapInfo::open_for_read() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _full_path = Arguments::GetSharedArchivePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (fd < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (errno == ENOENT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Not locating the shared archive is ok.
a61af66fc99e Initial load
duke
parents:
diff changeset
157 fail_continue("Specified shared archive not found.");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 fail_continue("Failed to open shared archive file (%s).",
a61af66fc99e Initial load
duke
parents:
diff changeset
160 strerror(errno));
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _file_open = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // Write the FileMapInfo information to the file.
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void FileMapInfo::open_for_write() {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _full_path = Arguments::GetSharedArchivePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 tty->print_cr("Dumping shared data to file: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 tty->print_cr(" %s", _full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Remove the existing file in case another process has it open.
a61af66fc99e Initial load
duke
parents:
diff changeset
181 remove(_full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (fd < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 fail_stop("Unable to create shared archive file %s.", _full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _fd = fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _file_offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _file_open = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Write the header to the file, seek to the next allocation boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 void FileMapInfo::write_header() {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 write_bytes_aligned(&_header, sizeof(FileMapHeader));
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Dump shared spaces to file.
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 void FileMapInfo::write_space(int i, CompactibleSpace* space, bool read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 align_file_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
204 write_region(i, (char*)space->bottom(), space->used(),
a61af66fc99e Initial load
duke
parents:
diff changeset
205 space->capacity(), read_only, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Dump region to file.
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void FileMapInfo::write_region(int region, char* base, size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
212 size_t capacity, bool read_only,
a61af66fc99e Initial load
duke
parents:
diff changeset
213 bool allow_exec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[region];
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (PrintSharedSpaces) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 tty->print_cr("Shared file region %d: 0x%x bytes, addr 0x%x,"
a61af66fc99e Initial load
duke
parents:
diff changeset
220 " file offset 0x%x", region, size, base, _file_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 si->_file_offset = _file_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 si->_base = base;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 si->_used = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 si->_capacity = capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 si->_read_only = read_only;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 si->_allow_exec = allow_exec;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 write_bytes_aligned(base, (int)size);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // Dump bytes to file -- at the current file position.
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 int n = ::write(_fd, buffer, nbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (n != nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // It is dangerous to leave the corrupted shared archive file around,
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // close and remove the file. See bug 6372906.
a61af66fc99e Initial load
duke
parents:
diff changeset
242 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 remove(_full_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 fail_stop("Unable to write to shared archive file.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 _file_offset += nbytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // Align file position to an allocation unit boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void FileMapInfo::align_file_position() {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (new_file_offset != _file_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 _file_offset = new_file_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // Seek one byte back from the target and write a byte to insure
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // that the written file is the correct length.
a61af66fc99e Initial load
duke
parents:
diff changeset
260 _file_offset -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (lseek(_fd, _file_offset, SEEK_SET) < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 fail_stop("Unable to seek.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 char zero = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 write_bytes(&zero, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Dump bytes to file -- at the current file position.
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 align_file_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 write_bytes(buffer, nbytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 align_file_position();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Close the shared archive file. This does NOT unmap mapped regions.
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 void FileMapInfo::close() {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (_file_open) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 if (::close(_fd) < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 fail_stop("Unable to close the shared archive file.");
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 _file_open = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 _fd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Memory map a shared space from the archive file.
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 bool FileMapInfo::map_space(int i, ReservedSpace rs, ContiguousSpace* space) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (space != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (si->_base != (char*)space->bottom() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
299 si->_capacity != space->capacity()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 fail_continue("Shared space base address does not match.");
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 bool result = (map_region(i, rs) != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (space != NULL && result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 space->set_top((HeapWord*)(si->_base + si->_used));
a61af66fc99e Initial load
duke
parents:
diff changeset
307 space->set_saved_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
309 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // JVM/TI RedefineClasses() support:
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // Remap the shared readonly space to shared readwrite, private.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (!si->_read_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // the space is already readwrite so we are done
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (!open_for_read()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
327 si->_base, size, false /* !read_only */,
a61af66fc99e Initial load
duke
parents:
diff changeset
328 si->_allow_exec);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 close();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if (base == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (base != si->_base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 fail_continue("Unable to remap shared readonly space at required address.");
a61af66fc99e Initial load
duke
parents:
diff changeset
336 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338 si->_read_only = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Memory map a region in the address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 char* FileMapInfo::map_region(int i, ReservedSpace rs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
347 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 ReservedSpace mapped_rs = rs.first_part(size, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 ReservedSpace unmapped_rs = rs.last_part(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 mapped_rs.release();
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 return map_region(i, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // Memory map a region in the address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 char* FileMapInfo::map_region(int i, bool address_must_match) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
362 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
364 char *requested_addr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (address_must_match) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 requested_addr = si->_base;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368 char *base = os::map_memory(_fd, _full_path, si->_file_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
369 requested_addr, size, si->_read_only,
a61af66fc99e Initial load
duke
parents:
diff changeset
370 si->_allow_exec);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 if (base == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 fail_continue("Unable to map shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (address_must_match) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if (base != si->_base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 fail_continue("Unable to map shared space at required address.");
a61af66fc99e Initial load
duke
parents:
diff changeset
378 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 si->_base = base; // save mapped address for unmapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 return base;
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // Unmap a memory region in the address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 void FileMapInfo::unmap_region(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
391 size_t used = si->_used;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 size_t size = align_size_up(used, os::vm_allocation_granularity());
a61af66fc99e Initial load
duke
parents:
diff changeset
393 if (!os::unmap_memory(si->_base, size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 fail_stop("Unable to unmap shared space.");
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 void FileMapInfo::assert_mark(bool check) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 if (!check) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 fail_stop("Mark mismatch while restoring from shared file.", NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 FileMapInfo* FileMapInfo::_current_info = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // Open the shared archive file, read and validate the header
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // information (version, boot classpath, etc.). If initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // fails, shared spaces are disabled and the file is closed. [See
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // fail_continue.]
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 bool FileMapInfo::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 assert(UseSharedSpaces, "UseSharedSpaces expected.");
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 fail_continue("Tool agent requires sharing to be disabled.");
a61af66fc99e Initial load
duke
parents:
diff changeset
420 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 if (!open_for_read()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 init_from_file(_fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 if (!validate()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 SharedReadOnlySize = _header._space[0]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
433 SharedReadWriteSize = _header._space[1]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 SharedMiscDataSize = _header._space[2]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 SharedMiscCodeSize = _header._space[3]._capacity;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439
a61af66fc99e Initial load
duke
parents:
diff changeset
440 bool FileMapInfo::validate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (_header._version != current_version()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 fail_continue("The shared archive file is the wrong version.");
a61af66fc99e Initial load
duke
parents:
diff changeset
443 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 if (_header._magic != (int)0xf00baba2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
446 fail_continue("The shared archive file has a bad magic number.");
a61af66fc99e Initial load
duke
parents:
diff changeset
447 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (strncmp(_header._jvm_ident, VM_Version::internal_vm_info_string(),
a61af66fc99e Initial load
duke
parents:
diff changeset
450 JVM_IDENT_MAX-1) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 fail_continue("The shared archive file was created by a different"
a61af66fc99e Initial load
duke
parents:
diff changeset
452 " version or build of HotSpot.");
a61af66fc99e Initial load
duke
parents:
diff changeset
453 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // Cannot verify interpreter yet, as it can only be created after the GC
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // heap has been initialized.
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 fail_continue("Too many jar files to share.");
a61af66fc99e Initial load
duke
parents:
diff changeset
461 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // Build checks on classpath and jar files
a61af66fc99e Initial load
duke
parents:
diff changeset
465 int num_jars_now = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 for ( ; cpe != NULL; cpe = cpe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (cpe->is_jar_file()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (num_jars_now < _header._num_jars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // Jar file - verify timestamp and file size.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 struct stat st;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 const char *path = cpe->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (os::stat(path, &st) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 fail_continue("Unable to open jar file %s.", path);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 if (_header._jar[num_jars_now]._timestamp != st.st_mtime ||
a61af66fc99e Initial load
duke
parents:
diff changeset
480 _header._jar[num_jars_now]._filesize != st.st_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 fail_continue("A jar file is not the one used while building"
a61af66fc99e Initial load
duke
parents:
diff changeset
482 " the shared archive file.");
a61af66fc99e Initial load
duke
parents:
diff changeset
483 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
486 ++num_jars_now;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // If directories appear in boot classpath, they must be empty to
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // avoid having to verify each individual class file.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 const char* name = ((ClassPathDirEntry*)cpe)->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (!os::dir_is_empty(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 fail_continue("Boot classpath directory %s is not empty.", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 if (num_jars_now < _header._num_jars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
499 fail_continue("The number of jar files in the boot classpath is"
a61af66fc99e Initial load
duke
parents:
diff changeset
500 " less than the number the shared archive was created with.");
a61af66fc99e Initial load
duke
parents:
diff changeset
501 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
503
a61af66fc99e Initial load
duke
parents:
diff changeset
504 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // The following method is provided to see whether a given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // falls in the mapped shared space.
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // Param:
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // p, The given pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // Return:
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // True if the p is within the mapped shared space, otherwise, false.
a61af66fc99e Initial load
duke
parents:
diff changeset
513 bool FileMapInfo::is_in_shared_space(const void* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 for (int i = 0; i < CompactingPermGenGen::n_regions; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (p >= _header._space[i]._base &&
a61af66fc99e Initial load
duke
parents:
diff changeset
516 p < _header._space[i]._base + _header._space[i]._used) {
a61af66fc99e Initial load
duke
parents:
diff changeset
517 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
522 }