src/share/vm/memory/filemap.cpp

Wed, 11 Sep 2013 00:38:18 -0400

author
dholmes
date
Wed, 11 Sep 2013 00:38:18 -0400
changeset 5689
de88570fabfc
parent 5625
35b99e7e0af2
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8024256: Minimal VM build is broken with PCH disabled
Reviewed-by: coleenp, twisti

duke@435 1 /*
hseigel@4521 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/classLoader.hpp"
stefank@2314 27 #include "classfile/symbolTable.hpp"
hseigel@4293 28 #include "classfile/altHashing.hpp"
stefank@2314 29 #include "memory/filemap.hpp"
stefank@2314 30 #include "runtime/arguments.hpp"
stefank@2314 31 #include "runtime/java.hpp"
stefank@2314 32 #include "runtime/os.hpp"
zgu@4193 33 #include "services/memTracker.hpp"
stefank@2314 34 #include "utilities/defaultStream.hpp"
stefank@2314 35
duke@435 36 # include <sys/stat.h>
duke@435 37 # include <errno.h>
duke@435 38
duke@435 39 #ifndef O_BINARY // if defined (Win32) use binary files.
duke@435 40 #define O_BINARY 0 // otherwise do nothing.
duke@435 41 #endif
duke@435 42
duke@435 43
duke@435 44 extern address JVM_FunctionAtStart();
duke@435 45 extern address JVM_FunctionAtEnd();
duke@435 46
twisti@1040 47 // Complain and stop. All error conditions occurring during the writing of
duke@435 48 // an archive file should stop the process. Unrecoverable errors during
duke@435 49 // the reading of the archive file should stop the process.
duke@435 50
duke@435 51 static void fail(const char *msg, va_list ap) {
duke@435 52 // This occurs very early during initialization: tty is not initialized.
duke@435 53 jio_fprintf(defaultStream::error_stream(),
twisti@1040 54 "An error has occurred while processing the"
duke@435 55 " shared archive file.\n");
duke@435 56 jio_vfprintf(defaultStream::error_stream(), msg, ap);
duke@435 57 jio_fprintf(defaultStream::error_stream(), "\n");
hseigel@5625 58 // Do not change the text of the below message because some tests check for it.
duke@435 59 vm_exit_during_initialization("Unable to use shared archive.", NULL);
duke@435 60 }
duke@435 61
duke@435 62
duke@435 63 void FileMapInfo::fail_stop(const char *msg, ...) {
duke@435 64 va_list ap;
duke@435 65 va_start(ap, msg);
duke@435 66 fail(msg, ap); // Never returns.
duke@435 67 va_end(ap); // for completeness.
duke@435 68 }
duke@435 69
duke@435 70
duke@435 71 // Complain and continue. Recoverable errors during the reading of the
duke@435 72 // archive file may continue (with sharing disabled).
duke@435 73 //
duke@435 74 // If we continue, then disable shared spaces and close the file.
duke@435 75
duke@435 76 void FileMapInfo::fail_continue(const char *msg, ...) {
duke@435 77 va_list ap;
duke@435 78 va_start(ap, msg);
duke@435 79 if (RequireSharedSpaces) {
duke@435 80 fail(msg, ap);
duke@435 81 }
duke@435 82 va_end(ap);
duke@435 83 UseSharedSpaces = false;
duke@435 84 close();
duke@435 85 }
duke@435 86
hseigel@4293 87 // Fill in the fileMapInfo structure with data about this VM instance.
duke@435 88
hseigel@4293 89 // This method copies the vm version info into header_version. If the version is too
hseigel@4293 90 // long then a truncated version, which has a hash code appended to it, is copied.
hseigel@4293 91 //
hseigel@4293 92 // Using a template enables this method to verify that header_version is an array of
hseigel@4293 93 // length JVM_IDENT_MAX. This ensures that the code that writes to the CDS file and
hseigel@4293 94 // the code that reads the CDS file will both use the same size buffer. Hence, will
hseigel@4293 95 // use identical truncation. This is necessary for matching of truncated versions.
hseigel@4293 96 template <int N> static void get_header_version(char (&header_version) [N]) {
hseigel@4293 97 assert(N == JVM_IDENT_MAX, "Bad header_version size");
hseigel@4293 98
hseigel@4293 99 const char *vm_version = VM_Version::internal_vm_info_string();
hseigel@4293 100 const int version_len = (int)strlen(vm_version);
hseigel@4293 101
hseigel@4293 102 if (version_len < (JVM_IDENT_MAX-1)) {
hseigel@4293 103 strcpy(header_version, vm_version);
hseigel@4293 104
hseigel@4293 105 } else {
hseigel@4293 106 // Get the hash value. Use a static seed because the hash needs to return the same
hseigel@4293 107 // value over multiple jvm invocations.
hseigel@4293 108 unsigned int hash = AltHashing::murmur3_32(8191, (const jbyte*)vm_version, version_len);
hseigel@4293 109
hseigel@4293 110 // Truncate the ident, saving room for the 8 hex character hash value.
hseigel@4293 111 strncpy(header_version, vm_version, JVM_IDENT_MAX-9);
hseigel@4293 112
hseigel@4293 113 // Append the hash code as eight hex digits.
hseigel@4293 114 sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
hseigel@4293 115 header_version[JVM_IDENT_MAX-1] = 0; // Null terminate.
hseigel@4293 116 }
hseigel@4293 117 }
duke@435 118
duke@435 119 void FileMapInfo::populate_header(size_t alignment) {
duke@435 120 _header._magic = 0xf00baba2;
duke@435 121 _header._version = _current_version;
duke@435 122 _header._alignment = alignment;
hseigel@4397 123 _header._obj_alignment = ObjectAlignmentInBytes;
duke@435 124
duke@435 125 // The following fields are for sanity checks for whether this archive
duke@435 126 // will function correctly with this JVM and the bootclasspath it's
duke@435 127 // invoked with.
duke@435 128
duke@435 129 // JVM version string ... changes on each build.
hseigel@4293 130 get_header_version(_header._jvm_ident);
duke@435 131
duke@435 132 // Build checks on classpath and jar files
duke@435 133 _header._num_jars = 0;
duke@435 134 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
duke@435 135 for ( ; cpe != NULL; cpe = cpe->next()) {
duke@435 136
duke@435 137 if (cpe->is_jar_file()) {
duke@435 138 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
duke@435 139 fail_stop("Too many jar files to share.", NULL);
duke@435 140 }
duke@435 141
duke@435 142 // Jar file - record timestamp and file size.
duke@435 143 struct stat st;
duke@435 144 const char *path = cpe->name();
duke@435 145 if (os::stat(path, &st) != 0) {
duke@435 146 // If we can't access a jar file in the boot path, then we can't
duke@435 147 // make assumptions about where classes get loaded from.
duke@435 148 fail_stop("Unable to open jar file %s.", path);
duke@435 149 }
duke@435 150 _header._jar[_header._num_jars]._timestamp = st.st_mtime;
duke@435 151 _header._jar[_header._num_jars]._filesize = st.st_size;
duke@435 152 _header._num_jars++;
duke@435 153 } else {
duke@435 154
duke@435 155 // If directories appear in boot classpath, they must be empty to
duke@435 156 // avoid having to verify each individual class file.
duke@435 157 const char* name = ((ClassPathDirEntry*)cpe)->name();
duke@435 158 if (!os::dir_is_empty(name)) {
duke@435 159 fail_stop("Boot classpath directory %s is not empty.", name);
duke@435 160 }
duke@435 161 }
duke@435 162 }
duke@435 163 }
duke@435 164
duke@435 165
duke@435 166 // Read the FileMapInfo information from the file.
duke@435 167
duke@435 168 bool FileMapInfo::init_from_file(int fd) {
duke@435 169
duke@435 170 size_t n = read(fd, &_header, sizeof(struct FileMapHeader));
duke@435 171 if (n != sizeof(struct FileMapHeader)) {
duke@435 172 fail_continue("Unable to read the file header.");
duke@435 173 return false;
duke@435 174 }
duke@435 175 if (_header._version != current_version()) {
duke@435 176 fail_continue("The shared archive file has the wrong version.");
duke@435 177 return false;
duke@435 178 }
duke@435 179 _file_offset = (long)n;
duke@435 180 return true;
duke@435 181 }
duke@435 182
duke@435 183
duke@435 184 // Read the FileMapInfo information from the file.
duke@435 185 bool FileMapInfo::open_for_read() {
duke@435 186 _full_path = Arguments::GetSharedArchivePath();
duke@435 187 int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
duke@435 188 if (fd < 0) {
duke@435 189 if (errno == ENOENT) {
duke@435 190 // Not locating the shared archive is ok.
duke@435 191 fail_continue("Specified shared archive not found.");
duke@435 192 } else {
duke@435 193 fail_continue("Failed to open shared archive file (%s).",
duke@435 194 strerror(errno));
duke@435 195 }
duke@435 196 return false;
duke@435 197 }
duke@435 198
duke@435 199 _fd = fd;
duke@435 200 _file_open = true;
duke@435 201 return true;
duke@435 202 }
duke@435 203
duke@435 204
duke@435 205 // Write the FileMapInfo information to the file.
duke@435 206
duke@435 207 void FileMapInfo::open_for_write() {
duke@435 208 _full_path = Arguments::GetSharedArchivePath();
duke@435 209 if (PrintSharedSpaces) {
duke@435 210 tty->print_cr("Dumping shared data to file: ");
duke@435 211 tty->print_cr(" %s", _full_path);
duke@435 212 }
duke@435 213
hseigel@4521 214 #ifdef _WINDOWS // On Windows, need WRITE permission to remove the file.
hseigel@4521 215 chmod(_full_path, _S_IREAD | _S_IWRITE);
hseigel@4521 216 #endif
hseigel@4521 217
hseigel@4521 218 // Use remove() to delete the existing file because, on Unix, this will
hseigel@4521 219 // allow processes that have it open continued access to the file.
duke@435 220 remove(_full_path);
duke@435 221 int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
duke@435 222 if (fd < 0) {
duke@435 223 fail_stop("Unable to create shared archive file %s.", _full_path);
duke@435 224 }
duke@435 225 _fd = fd;
duke@435 226 _file_offset = 0;
duke@435 227 _file_open = true;
duke@435 228 }
duke@435 229
duke@435 230
duke@435 231 // Write the header to the file, seek to the next allocation boundary.
duke@435 232
duke@435 233 void FileMapInfo::write_header() {
duke@435 234 write_bytes_aligned(&_header, sizeof(FileMapHeader));
duke@435 235 }
duke@435 236
duke@435 237
duke@435 238 // Dump shared spaces to file.
duke@435 239
coleenp@4037 240 void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) {
duke@435 241 align_file_position();
jmasa@5015 242 size_t used = space->used_bytes_slow(Metaspace::NonClassType);
jmasa@5015 243 size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType);
duke@435 244 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
coleenp@4037 245 write_region(i, (char*)space->bottom(), used, capacity, read_only, false);
duke@435 246 }
duke@435 247
duke@435 248
duke@435 249 // Dump region to file.
duke@435 250
duke@435 251 void FileMapInfo::write_region(int region, char* base, size_t size,
duke@435 252 size_t capacity, bool read_only,
duke@435 253 bool allow_exec) {
duke@435 254 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[region];
duke@435 255
duke@435 256 if (_file_open) {
duke@435 257 guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
duke@435 258 if (PrintSharedSpaces) {
coleenp@4037 259 tty->print_cr("Shared file region %d: 0x%6x bytes, addr " INTPTR_FORMAT
coleenp@4037 260 " file offset 0x%6x", region, size, base, _file_offset);
duke@435 261 }
duke@435 262 } else {
duke@435 263 si->_file_offset = _file_offset;
duke@435 264 }
duke@435 265 si->_base = base;
duke@435 266 si->_used = size;
duke@435 267 si->_capacity = capacity;
duke@435 268 si->_read_only = read_only;
duke@435 269 si->_allow_exec = allow_exec;
duke@435 270 write_bytes_aligned(base, (int)size);
duke@435 271 }
duke@435 272
duke@435 273
duke@435 274 // Dump bytes to file -- at the current file position.
duke@435 275
duke@435 276 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
duke@435 277 if (_file_open) {
duke@435 278 int n = ::write(_fd, buffer, nbytes);
duke@435 279 if (n != nbytes) {
duke@435 280 // It is dangerous to leave the corrupted shared archive file around,
duke@435 281 // close and remove the file. See bug 6372906.
duke@435 282 close();
duke@435 283 remove(_full_path);
duke@435 284 fail_stop("Unable to write to shared archive file.", NULL);
duke@435 285 }
duke@435 286 }
duke@435 287 _file_offset += nbytes;
duke@435 288 }
duke@435 289
duke@435 290
duke@435 291 // Align file position to an allocation unit boundary.
duke@435 292
duke@435 293 void FileMapInfo::align_file_position() {
duke@435 294 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity());
duke@435 295 if (new_file_offset != _file_offset) {
duke@435 296 _file_offset = new_file_offset;
duke@435 297 if (_file_open) {
duke@435 298 // Seek one byte back from the target and write a byte to insure
duke@435 299 // that the written file is the correct length.
duke@435 300 _file_offset -= 1;
duke@435 301 if (lseek(_fd, _file_offset, SEEK_SET) < 0) {
duke@435 302 fail_stop("Unable to seek.", NULL);
duke@435 303 }
duke@435 304 char zero = 0;
duke@435 305 write_bytes(&zero, 1);
duke@435 306 }
duke@435 307 }
duke@435 308 }
duke@435 309
duke@435 310
duke@435 311 // Dump bytes to file -- at the current file position.
duke@435 312
duke@435 313 void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
duke@435 314 align_file_position();
duke@435 315 write_bytes(buffer, nbytes);
duke@435 316 align_file_position();
duke@435 317 }
duke@435 318
duke@435 319
duke@435 320 // Close the shared archive file. This does NOT unmap mapped regions.
duke@435 321
duke@435 322 void FileMapInfo::close() {
duke@435 323 if (_file_open) {
duke@435 324 if (::close(_fd) < 0) {
duke@435 325 fail_stop("Unable to close the shared archive file.");
duke@435 326 }
duke@435 327 _file_open = false;
duke@435 328 _fd = -1;
duke@435 329 }
duke@435 330 }
duke@435 331
duke@435 332
duke@435 333 // JVM/TI RedefineClasses() support:
duke@435 334 // Remap the shared readonly space to shared readwrite, private.
duke@435 335 bool FileMapInfo::remap_shared_readonly_as_readwrite() {
duke@435 336 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0];
duke@435 337 if (!si->_read_only) {
duke@435 338 // the space is already readwrite so we are done
duke@435 339 return true;
duke@435 340 }
duke@435 341 size_t used = si->_used;
duke@435 342 size_t size = align_size_up(used, os::vm_allocation_granularity());
duke@435 343 if (!open_for_read()) {
duke@435 344 return false;
duke@435 345 }
duke@435 346 char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
duke@435 347 si->_base, size, false /* !read_only */,
duke@435 348 si->_allow_exec);
duke@435 349 close();
duke@435 350 if (base == NULL) {
duke@435 351 fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
duke@435 352 return false;
duke@435 353 }
duke@435 354 if (base != si->_base) {
duke@435 355 fail_continue("Unable to remap shared readonly space at required address.");
duke@435 356 return false;
duke@435 357 }
duke@435 358 si->_read_only = false;
duke@435 359 return true;
duke@435 360 }
duke@435 361
coleenp@4037 362 // Map the whole region at once, assumed to be allocated contiguously.
coleenp@4037 363 ReservedSpace FileMapInfo::reserve_shared_memory() {
coleenp@4037 364 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[0];
coleenp@4037 365 char* requested_addr = si->_base;
coleenp@4037 366
hseigel@5528 367 size_t size = FileMapInfo::shared_spaces_size();
coleenp@4037 368
coleenp@4037 369 // Reserve the space first, then map otherwise map will go right over some
coleenp@4037 370 // other reserved memory (like the code cache).
hseigel@5528 371 ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
coleenp@4037 372 if (!rs.is_reserved()) {
coleenp@4804 373 fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr));
coleenp@4037 374 return rs;
coleenp@4037 375 }
zgu@4193 376 // the reserved virtual memory is for mapping class data sharing archive
hseigel@4396 377 MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
hseigel@4396 378
coleenp@4037 379 return rs;
coleenp@4037 380 }
duke@435 381
duke@435 382 // Memory map a region in the address space.
coleenp@4037 383 static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode"};
duke@435 384
coleenp@4037 385 char* FileMapInfo::map_region(int i) {
duke@435 386 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
duke@435 387 size_t used = si->_used;
coleenp@4037 388 size_t alignment = os::vm_allocation_granularity();
coleenp@4037 389 size_t size = align_size_up(used, alignment);
coleenp@4037 390 char *requested_addr = si->_base;
coleenp@4037 391
coleenp@4037 392 // map the contents of the CDS archive in this memory
duke@435 393 char *base = os::map_memory(_fd, _full_path, si->_file_offset,
duke@435 394 requested_addr, size, si->_read_only,
duke@435 395 si->_allow_exec);
coleenp@4037 396 if (base == NULL || base != si->_base) {
coleenp@4037 397 fail_continue(err_msg("Unable to map %s shared space at required address.", shared_region_name[i]));
duke@435 398 return NULL;
duke@435 399 }
hseigel@4396 400 #ifdef _WINDOWS
hseigel@4396 401 // This call is Windows-only because the memory_type gets recorded for the other platforms
hseigel@4396 402 // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
hseigel@4396 403 MemTracker::record_virtual_memory_type((address)base, mtClassShared);
hseigel@4396 404 #endif
duke@435 405 return base;
duke@435 406 }
duke@435 407
duke@435 408
duke@435 409 // Unmap a memory region in the address space.
duke@435 410
duke@435 411 void FileMapInfo::unmap_region(int i) {
duke@435 412 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
duke@435 413 size_t used = si->_used;
duke@435 414 size_t size = align_size_up(used, os::vm_allocation_granularity());
duke@435 415 if (!os::unmap_memory(si->_base, size)) {
duke@435 416 fail_stop("Unable to unmap shared space.");
duke@435 417 }
duke@435 418 }
duke@435 419
duke@435 420
duke@435 421 void FileMapInfo::assert_mark(bool check) {
duke@435 422 if (!check) {
duke@435 423 fail_stop("Mark mismatch while restoring from shared file.", NULL);
duke@435 424 }
duke@435 425 }
duke@435 426
duke@435 427
duke@435 428 FileMapInfo* FileMapInfo::_current_info = NULL;
duke@435 429
duke@435 430
duke@435 431 // Open the shared archive file, read and validate the header
duke@435 432 // information (version, boot classpath, etc.). If initialization
duke@435 433 // fails, shared spaces are disabled and the file is closed. [See
duke@435 434 // fail_continue.]
duke@435 435 bool FileMapInfo::initialize() {
duke@435 436 assert(UseSharedSpaces, "UseSharedSpaces expected.");
duke@435 437
duke@435 438 if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
duke@435 439 fail_continue("Tool agent requires sharing to be disabled.");
duke@435 440 return false;
duke@435 441 }
duke@435 442
duke@435 443 if (!open_for_read()) {
duke@435 444 return false;
duke@435 445 }
duke@435 446
duke@435 447 init_from_file(_fd);
duke@435 448 if (!validate()) {
duke@435 449 return false;
duke@435 450 }
duke@435 451
duke@435 452 SharedReadOnlySize = _header._space[0]._capacity;
duke@435 453 SharedReadWriteSize = _header._space[1]._capacity;
duke@435 454 SharedMiscDataSize = _header._space[2]._capacity;
duke@435 455 SharedMiscCodeSize = _header._space[3]._capacity;
duke@435 456 return true;
duke@435 457 }
duke@435 458
duke@435 459
duke@435 460 bool FileMapInfo::validate() {
duke@435 461 if (_header._version != current_version()) {
duke@435 462 fail_continue("The shared archive file is the wrong version.");
duke@435 463 return false;
duke@435 464 }
duke@435 465 if (_header._magic != (int)0xf00baba2) {
duke@435 466 fail_continue("The shared archive file has a bad magic number.");
duke@435 467 return false;
duke@435 468 }
hseigel@4293 469 char header_version[JVM_IDENT_MAX];
hseigel@4293 470 get_header_version(header_version);
hseigel@4293 471 if (strncmp(_header._jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
duke@435 472 fail_continue("The shared archive file was created by a different"
duke@435 473 " version or build of HotSpot.");
duke@435 474 return false;
duke@435 475 }
hseigel@4397 476 if (_header._obj_alignment != ObjectAlignmentInBytes) {
hseigel@4397 477 fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
hseigel@4397 478 " does not equal the current ObjectAlignmentInBytes of %d.",
hseigel@4397 479 _header._obj_alignment, ObjectAlignmentInBytes);
hseigel@4397 480 return false;
hseigel@4397 481 }
duke@435 482
duke@435 483 // Cannot verify interpreter yet, as it can only be created after the GC
duke@435 484 // heap has been initialized.
duke@435 485
duke@435 486 if (_header._num_jars >= JVM_SHARED_JARS_MAX) {
duke@435 487 fail_continue("Too many jar files to share.");
duke@435 488 return false;
duke@435 489 }
duke@435 490
duke@435 491 // Build checks on classpath and jar files
duke@435 492 int num_jars_now = 0;
duke@435 493 ClassPathEntry *cpe = ClassLoader::classpath_entry(0);
duke@435 494 for ( ; cpe != NULL; cpe = cpe->next()) {
duke@435 495
duke@435 496 if (cpe->is_jar_file()) {
duke@435 497 if (num_jars_now < _header._num_jars) {
duke@435 498
duke@435 499 // Jar file - verify timestamp and file size.
duke@435 500 struct stat st;
duke@435 501 const char *path = cpe->name();
duke@435 502 if (os::stat(path, &st) != 0) {
duke@435 503 fail_continue("Unable to open jar file %s.", path);
duke@435 504 return false;
duke@435 505 }
duke@435 506 if (_header._jar[num_jars_now]._timestamp != st.st_mtime ||
duke@435 507 _header._jar[num_jars_now]._filesize != st.st_size) {
duke@435 508 fail_continue("A jar file is not the one used while building"
duke@435 509 " the shared archive file.");
duke@435 510 return false;
duke@435 511 }
duke@435 512 }
duke@435 513 ++num_jars_now;
duke@435 514 } else {
duke@435 515
duke@435 516 // If directories appear in boot classpath, they must be empty to
duke@435 517 // avoid having to verify each individual class file.
duke@435 518 const char* name = ((ClassPathDirEntry*)cpe)->name();
duke@435 519 if (!os::dir_is_empty(name)) {
duke@435 520 fail_continue("Boot classpath directory %s is not empty.", name);
duke@435 521 return false;
duke@435 522 }
duke@435 523 }
duke@435 524 }
duke@435 525 if (num_jars_now < _header._num_jars) {
duke@435 526 fail_continue("The number of jar files in the boot classpath is"
duke@435 527 " less than the number the shared archive was created with.");
duke@435 528 return false;
duke@435 529 }
duke@435 530
duke@435 531 return true;
duke@435 532 }
duke@435 533
duke@435 534 // The following method is provided to see whether a given pointer
duke@435 535 // falls in the mapped shared space.
duke@435 536 // Param:
duke@435 537 // p, The given pointer
duke@435 538 // Return:
duke@435 539 // True if the p is within the mapped shared space, otherwise, false.
duke@435 540 bool FileMapInfo::is_in_shared_space(const void* p) {
coleenp@4037 541 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
duke@435 542 if (p >= _header._space[i]._base &&
duke@435 543 p < _header._space[i]._base + _header._space[i]._used) {
duke@435 544 return true;
duke@435 545 }
duke@435 546 }
duke@435 547
duke@435 548 return false;
duke@435 549 }
iklam@5329 550
iklam@5329 551 void FileMapInfo::print_shared_spaces() {
iklam@5329 552 gclog_or_tty->print_cr("Shared Spaces:");
iklam@5329 553 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
iklam@5329 554 struct FileMapInfo::FileMapHeader::space_info* si = &_header._space[i];
iklam@5329 555 gclog_or_tty->print(" %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
iklam@5329 556 shared_region_name[i],
iklam@5329 557 si->_base, si->_base + si->_used);
iklam@5329 558 }
iklam@5329 559 }
hseigel@5528 560
hseigel@5528 561 // Unmap mapped regions of shared space.
hseigel@5528 562 void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
hseigel@5528 563 FileMapInfo *map_info = FileMapInfo::current_info();
hseigel@5528 564 if (map_info) {
hseigel@5528 565 map_info->fail_continue(msg);
hseigel@5528 566 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
hseigel@5528 567 if (map_info->_header._space[i]._base != NULL) {
hseigel@5528 568 map_info->unmap_region(i);
hseigel@5528 569 map_info->_header._space[i]._base = NULL;
hseigel@5528 570 }
hseigel@5528 571 }
hseigel@5528 572 } else if (DumpSharedSpaces) {
hseigel@5528 573 fail_stop(msg, NULL);
hseigel@5528 574 }
hseigel@5528 575 }

mercurial