hotspot/src/share/vm/memory/filemap.cpp
author ccheung
Tue, 20 Sep 2016 10:37:19 -0700
changeset 41281 e1dc38ba642f
parent 41182 dbd59c1da636
child 41667 4a349512fde1
permissions -rw-r--r--
8164011: --patch-module support for CDS Summary: allows the use of the --patch-module vm option with CDS. However, classes found in --patch-module during dump time will not be archived. Reviewed-by: iklam, dcubed, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
35917
463d67f86eaa 8079408: Reimplement TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData with Unified Logging.
mockner
parents: 35061
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/classLoader.hpp"
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents: 33628
diff changeset
    27
#include "classfile/compactHashtable.inline.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    28
#include "classfile/sharedClassUtil.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/symbolTable.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    30
#include "classfile/systemDictionaryShared.hpp"
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
    31
#include "classfile/altHashing.hpp"
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
    32
#if INCLUDE_ALL_GCS
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
    33
#include "gc/g1/g1CollectedHeap.hpp"
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
    34
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "memory/filemap.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    36
#include "memory/metadataFactory.hpp"
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    37
#include "memory/oopFactory.hpp"
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    38
#include "oops/objArrayOop.hpp"
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
    39
#include "prims/jvmtiExport.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    42
#include "runtime/os.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    43
#include "runtime/vm_version.hpp"
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
    44
#include "services/memTracker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    45
#include "utilities/defaultStream.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    46
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
# include <sys/stat.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
# include <errno.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
#ifndef O_BINARY       // if defined (Win32) use binary files.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
#define O_BINARY 0     // otherwise do nothing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
extern address JVM_FunctionAtStart();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
extern address JVM_FunctionAtEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    57
// Complain and stop. All error conditions occurring during the writing of
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// an archive file should stop the process.  Unrecoverable errors during
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// the reading of the archive file should stop the process.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
static void fail(const char *msg, va_list ap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // This occurs very early during initialization: tty is not initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  jio_fprintf(defaultStream::error_stream(),
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    64
              "An error has occurred while processing the"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
              " shared archive file.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  jio_vfprintf(defaultStream::error_stream(), msg, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  jio_fprintf(defaultStream::error_stream(), "\n");
19707
fecaabc8e462 8023381: VM fails to initialize in runtime/CDSCompressedKPtrs/XShareAuto.java runtime/SharedArchiveFile/CdsSameObjectAlignment.java
hseigel
parents: 19319
diff changeset
    68
  // Do not change the text of the below message because some tests check for it.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  vm_exit_during_initialization("Unable to use shared archive.", NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void FileMapInfo::fail_stop(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  va_start(ap, msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  fail(msg, ap);        // Never returns.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  va_end(ap);           // for completeness.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// Complain and continue.  Recoverable errors during the reading of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// archive file may continue (with sharing disabled).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// If we continue, then disable shared spaces and close the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void FileMapInfo::fail_continue(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  va_start(ap, msg);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    89
  MetaspaceShared::set_archive_loading_failed();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    90
  if (PrintSharedArchiveAndExit && _validating_classpath_entry_table) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    91
    // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    92
    // do not validate, we can still continue "limping" to validate the remaining
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    93
    // entries. No need to quit.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    94
    tty->print("[");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    95
    tty->vprint(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    96
    tty->print_cr("]");
23186
9396c6fb571b 8033990: Add message to verbose output to indicate when JVM was unable to use shared archive (with -Xshare:auto)
mseledtsov
parents: 19707
diff changeset
    97
  } else {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    98
    if (RequireSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    99
      fail(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   100
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   101
      if (PrintSharedSpaces) {
38108
95c7e9d6747c 8154976: UseSharedSpaces error message is incomplete
ccheung
parents: 37439
diff changeset
   102
        tty->print("UseSharedSpaces: ");
95c7e9d6747c 8154976: UseSharedSpaces error message is incomplete
ccheung
parents: 37439
diff changeset
   103
        tty->vprint_cr(msg, ap);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   104
      }
23186
9396c6fb571b 8033990: Add message to verbose output to indicate when JVM was unable to use shared archive (with -Xshare:auto)
mseledtsov
parents: 19707
diff changeset
   105
    }
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   106
    UseSharedSpaces = false;
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   107
    assert(current_info() != NULL, "singleton must be registered");
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   108
    current_info()->close();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   113
// Fill in the fileMapInfo structure with data about this VM instance.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   115
// This method copies the vm version info into header_version.  If the version is too
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   116
// long then a truncated version, which has a hash code appended to it, is copied.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   117
//
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   118
// Using a template enables this method to verify that header_version is an array of
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   119
// length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   120
// the code that reads the CDS file will both use the same size buffer.  Hence, will
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   121
// use identical truncation.  This is necessary for matching of truncated versions.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   122
template <int N> static void get_header_version(char (&header_version) [N]) {
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   123
  assert(N == JVM_IDENT_MAX, "Bad header_version size");
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   124
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   125
  const char *vm_version = VM_Version::internal_vm_info_string();
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   126
  const int version_len = (int)strlen(vm_version);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   127
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   128
  if (version_len < (JVM_IDENT_MAX-1)) {
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   129
    strcpy(header_version, vm_version);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   130
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   131
  } else {
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   132
    // Get the hash value.  Use a static seed because the hash needs to return the same
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   133
    // value over multiple jvm invocations.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   134
    unsigned int hash = AltHashing::murmur3_32(8191, (const jbyte*)vm_version, version_len);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   135
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   136
    // Truncate the ident, saving room for the 8 hex character hash value.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   137
    strncpy(header_version, vm_version, JVM_IDENT_MAX-9);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   138
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   139
    // Append the hash code as eight hex digits.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   140
    sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   141
    header_version[JVM_IDENT_MAX-1] = 0;  // Null terminate.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   142
  }
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   143
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   145
FileMapInfo::FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   146
  assert(_current_info == NULL, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   147
  _current_info = this;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   148
  memset(this, 0, sizeof(FileMapInfo));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   149
  _file_offset = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   150
  _file_open = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   151
  _header = SharedClassUtil::allocate_file_map_header();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   152
  _header->_version = _invalid_version;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   153
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   154
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   155
FileMapInfo::~FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   156
  assert(_current_info == this, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   157
  _current_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   158
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   159
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
void FileMapInfo::populate_header(size_t alignment) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   161
  _header->populate(this, alignment);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   162
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   163
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   164
size_t FileMapInfo::FileMapHeader::data_size() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   165
  return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   166
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   167
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   168
void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   169
  _magic = 0xf00baba2;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   170
  _version = _current_version;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   171
  _alignment = alignment;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   172
  _obj_alignment = ObjectAlignmentInBytes;
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   173
  _compact_strings = CompactStrings;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   174
  _narrow_oop_mode = Universe::narrow_oop_mode();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   175
  _narrow_oop_shift = Universe::narrow_oop_shift();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   176
  _max_heap_size = MaxHeapSize;
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   177
  _narrow_klass_base = Universe::narrow_klass_base();
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   178
  _narrow_klass_shift = Universe::narrow_klass_shift();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   179
  _classpath_entry_table_size = mapinfo->_classpath_entry_table_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   180
  _classpath_entry_table = mapinfo->_classpath_entry_table;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   181
  _classpath_entry_size = mapinfo->_classpath_entry_size;
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   182
  _num_patch_mod_prefixes = ClassLoader::num_patch_mod_prefixes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // The following fields are for sanity checks for whether this archive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // will function correctly with this JVM and the bootclasspath it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // invoked with.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // JVM version string ... changes on each build.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   189
  get_header_version(_jvm_ident);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   190
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   191
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   192
void FileMapInfo::allocate_classpath_entry_table() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   193
  int bytes = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   194
  int count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   195
  char* strptr = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   196
  char* strptr_max = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   197
  Thread* THREAD = Thread::current();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   199
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   200
  size_t entry_size = SharedClassUtil::shared_class_path_entry_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   202
  for (int pass=0; pass<2; pass++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   203
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   204
    // Process the modular java runtime image first
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   205
    ClassPathEntry* jrt_entry = ClassLoader::get_jrt_entry();
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   206
    assert(jrt_entry != NULL,
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   207
           "No modular java runtime image present when allocating the CDS classpath entry table");
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   208
    const char *name = jrt_entry->name();
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   209
    int name_bytes = (int)(strlen(name) + 1);
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   210
    if (pass == 0) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   211
      count++;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   212
      bytes += (int)entry_size;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   213
      bytes += name_bytes;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   214
      log_info(class, path)("add main shared path for modular java runtime image %s", name);
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   215
    } else {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   216
      // The java runtime image is always in slot 0 on the shared class path.
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   217
      SharedClassPathEntry* ent = shared_classpath(0);
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   218
      struct stat st;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   219
      if (os::stat(name, &st) == 0) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   220
        ent->_timestamp = st.st_mtime;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   221
        ent->_filesize = st.st_size;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   222
      }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   223
      if (ent->_filesize == 0) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   224
        // unknown
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   225
        ent->_filesize = -2;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   226
      }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   227
      ent->_name = strptr;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   228
      assert(strptr + name_bytes <= strptr_max, "miscalculated buffer size");
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   229
      strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0.
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   230
      strptr += name_bytes;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   231
    }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   232
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   233
    // Walk the appended entries, which includes the entries added for the classpath.
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   234
    ClassPathEntry *cpe = ClassLoader::classpath_entry(1);
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   235
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   236
    // Since the java runtime image is always in slot 0 on the shared class path, the
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   237
    // appended entries are started at slot 1 immediately after.
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   238
    for (int cur_entry = 1 ; cpe != NULL; cpe = cpe->next(), cur_entry++) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   239
      const char *name = cpe->name();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   240
      int name_bytes = (int)(strlen(name) + 1);
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   241
      assert(!cpe->is_jrt(), "A modular java runtime image is present on the list of appended entries");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   243
      if (pass == 0) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   244
        count ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   245
        bytes += (int)entry_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   246
        bytes += name_bytes;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   247
        log_info(class, path)("add main shared path (%s) %s", (cpe->is_jar_file() ? "jar" : "dir"), name);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   248
      } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   249
        SharedClassPathEntry* ent = shared_classpath(cur_entry);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   250
        if (cpe->is_jar_file()) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   251
          struct stat st;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   252
          if (os::stat(name, &st) != 0) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   253
            // The file/dir must exist, or it would not have been added
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   254
            // into ClassLoader::classpath_entry().
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   255
            //
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   256
            // If we can't access a jar file in the boot path, then we can't
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   257
            // make assumptions about where classes get loaded from.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   258
            FileMapInfo::fail_stop("Unable to open jar file %s.", name);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   259
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   261
          EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   262
          SharedClassUtil::update_shared_classpath(cpe, ent, st.st_mtime, st.st_size, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   263
        } else {
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents: 27025
diff changeset
   264
          struct stat st;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   265
          if (os::stat(name, &st) == 0) {
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   266
            if ((st.st_mode & S_IFDIR) == S_IFDIR) {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   267
              if (!os::dir_is_empty(name)) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   268
                ClassLoader::exit_with_path_failure(
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   269
                  "Cannot have non-empty directory in archived classpaths", name);
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   270
              }
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   271
              ent->_filesize = -1;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents: 27025
diff changeset
   272
            }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   273
          }
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   274
          if (ent->_filesize == 0) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   275
            // unknown
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents: 27025
diff changeset
   276
            ent->_filesize = -2;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   277
          }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   278
        }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   279
        ent->_name = strptr;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   280
        if (strptr + name_bytes <= strptr_max) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   281
          strncpy(strptr, name, (size_t)name_bytes); // name_bytes includes trailing 0.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   282
          strptr += name_bytes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   283
        } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   284
          assert(0, "miscalculated buffer size");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   285
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   288
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   289
    if (pass == 0) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   290
      EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   291
      Array<u8>* arr = MetadataFactory::new_array<u8>(loader_data, (bytes + 7)/8, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   292
      strptr = (char*)(arr->data());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   293
      strptr_max = strptr + bytes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   294
      SharedClassPathEntry* table = (SharedClassPathEntry*)strptr;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   295
      strptr += entry_size * count;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   296
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   297
      _classpath_entry_table_size = count;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   298
      _classpath_entry_table = table;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   299
      _classpath_entry_size = entry_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   300
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   304
bool FileMapInfo::validate_classpath_entry_table() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   305
  _validating_classpath_entry_table = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   306
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   307
  int count = _header->_classpath_entry_table_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   308
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   309
  _classpath_entry_table = _header->_classpath_entry_table;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   310
  _classpath_entry_size = _header->_classpath_entry_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   311
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   312
  for (int i=0; i<count; i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   313
    SharedClassPathEntry* ent = shared_classpath(i);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   314
    struct stat st;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   315
    const char* name = ent->_name;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   316
    bool ok = true;
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   317
    log_info(class, path)("checking shared classpath entry: %s", name);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   318
    if (os::stat(name, &st) != 0) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   319
      fail_continue("Required classpath entry does not exist: %s", name);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   320
      ok = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   321
    } else if (ent->is_dir()) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   322
      if (!os::dir_is_empty(name)) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   323
        fail_continue("directory is not empty: %s", name);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   324
        ok = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   325
      }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   326
    } else if (ent->is_jar_or_bootimage()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   327
      if (ent->_timestamp != st.st_mtime ||
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   328
          ent->_filesize != st.st_size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   329
        ok = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   330
        if (PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   331
          fail_continue(ent->_timestamp != st.st_mtime ?
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   332
                        "Timestamp mismatch" :
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   333
                        "File size mismatch");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   334
        } else {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36364
diff changeset
   335
          fail_continue("A jar/jimage file is not the one used while building"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   336
                        " the shared archive file: %s", name);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   337
        }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   338
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   339
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   340
    if (ok) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   341
      log_info(class, path)("ok");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   342
    } else if (!PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   343
      _validating_classpath_entry_table = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   344
      return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   345
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   346
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   347
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   348
  _classpath_entry_table_size = _header->_classpath_entry_table_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   349
  _validating_classpath_entry_table = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   350
  return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   351
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   352
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
bool FileMapInfo::init_from_file(int fd) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   357
  size_t sz = _header->data_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   358
  char* addr = _header->data();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   359
  size_t n = os::read(fd, addr, (unsigned int)sz);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   360
  if (n != sz) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    fail_continue("Unable to read the file header.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   364
  if (_header->_version != current_version()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    fail_continue("The shared archive file has the wrong version.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  _file_offset = (long)n;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   369
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   370
  size_t info_size = _header->_paths_misc_info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   371
  _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   372
  if (_paths_misc_info == NULL) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   373
    fail_continue("Unable to read the file header.");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   374
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   375
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   376
  n = os::read(fd, _paths_misc_info, (unsigned int)info_size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   377
  if (n != info_size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   378
    fail_continue("Unable to read the shared path info header.");
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27025
diff changeset
   379
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   380
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   381
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   382
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   383
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   384
  size_t len = lseek(fd, 0, SEEK_END);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   385
  struct FileMapInfo::FileMapHeader::space_info* si =
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   386
    &_header->_space[MetaspaceShared::mc];
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   387
  if (si->_file_offset >= len || len - si->_file_offset < si->_used) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   388
    fail_continue("The shared archive file has been truncated.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   389
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   390
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   391
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   392
  _file_offset += (long)n;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
bool FileMapInfo::open_for_read() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  _full_path = Arguments::GetSharedArchivePath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  if (fd < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    if (errno == ENOENT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      // Not locating the shared archive is ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      fail_continue("Specified shared archive not found.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      fail_continue("Failed to open shared archive file (%s).",
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36364
diff changeset
   407
                    os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
// Write the FileMapInfo information to the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
void FileMapInfo::open_for_write() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
 _full_path = Arguments::GetSharedArchivePath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    tty->print_cr("Dumping shared data to file: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    tty->print_cr("   %s", _full_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
15461
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   427
#ifdef _WINDOWS  // On Windows, need WRITE permission to remove the file.
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   428
  chmod(_full_path, _S_IREAD | _S_IWRITE);
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   429
#endif
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   430
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   431
  // Use remove() to delete the existing file because, on Unix, this will
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   432
  // allow processes that have it open continued access to the file.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  remove(_full_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  if (fd < 0) {
28950
693ae3d5e1ff 8072694: Need errno info when CDS archive creation fails
hseigel
parents: 28023
diff changeset
   436
    fail_stop("Unable to create shared archive file %s: (%s).", _full_path,
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36364
diff changeset
   437
              os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  _file_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
// Write the header to the file, seek to the next allocation boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
void FileMapInfo::write_header() {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   448
  int info_size = ClassLoader::get_shared_paths_misc_info_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   449
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   450
  _header->_paths_misc_info_size = info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   451
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   452
  align_file_position();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   453
  size_t sz = _header->data_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   454
  char* addr = _header->data();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   455
  write_bytes(addr, (int)sz); // skip the C++ vtable
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   456
  write_bytes(ClassLoader::get_shared_paths_misc_info(), info_size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   457
  align_file_position();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// Dump shared spaces to file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   463
void FileMapInfo::write_space(int i, Metaspace* space, bool read_only) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  align_file_position();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 16430
diff changeset
   465
  size_t used = space->used_bytes_slow(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 16430
diff changeset
   466
  size_t capacity = space->capacity_bytes_slow(Metaspace::NonClassType);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   467
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   468
  write_region(i, (char*)space->bottom(), used, capacity, read_only, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
// Dump region to file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
void FileMapInfo::write_region(int region, char* base, size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
                               size_t capacity, bool read_only,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
                               bool allow_exec) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   477
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    if (PrintSharedSpaces) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   482
      tty->print_cr("Shared file region %d: " SIZE_FORMAT_HEX_W(6) " bytes, addr " INTPTR_FORMAT
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   483
                    " file offset " SIZE_FORMAT_HEX_W(6), region, size, p2i(base), _file_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    si->_file_offset = _file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   488
  if (MetaspaceShared::is_string_region(region)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   489
    assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   490
    if (base != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   491
      si->_addr._offset = (intx)oopDesc::encode_heap_oop_not_null((oop)base);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   492
    } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   493
      si->_addr._offset = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   494
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   495
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   496
    si->_addr._base = base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   497
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  si->_used = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  si->_capacity = capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  si->_read_only = read_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  si->_allow_exec = allow_exec;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   502
  si->_crc = ClassLoader::crc32(0, base, (jint)size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  write_bytes_aligned(base, (int)size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   506
// Write the string space. The string space contains one or multiple GC(G1) regions.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   507
// When the total string space size is smaller than one GC region of the dump time,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   508
// only one string region is used for shared strings.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   509
//
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   510
// If the total string space size is bigger than one GC region, there would be more
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   511
// than one GC regions allocated for shared strings. The first/bottom GC region might
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   512
// be a partial GC region with the empty portion at the higher address within that region.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   513
// The non-empty portion of the first region is written into the archive as one string
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   514
// region. The rest are consecutive full GC regions if they exist, which can be written
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   515
// out in one chunk as another string region.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   516
void FileMapInfo::write_string_regions(GrowableArray<MemRegion> *regions) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   517
  for (int i = MetaspaceShared::first_string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   518
           i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   519
    char* start = NULL;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   520
    size_t size = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   521
    if (regions->is_nonempty()) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   522
      if (i == MetaspaceShared::first_string) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   523
        MemRegion first = regions->first();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   524
        start = (char*)first.start();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   525
        size = first.byte_size();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   526
      } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   527
        int len = regions->length();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   528
        if (len > 1) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   529
          start = (char*)regions->at(1).start();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   530
          size = (char*)regions->at(len - 1).end() - start;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   531
        }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   532
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   533
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   534
    write_region(i, start, size, size, false, false);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   535
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   536
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   537
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    int n = ::write(_fd, buffer, nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    if (n != nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      // It is dangerous to leave the corrupted shared archive file around,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      // close and remove the file. See bug 6372906.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      remove(_full_path);
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   549
      fail_stop("Unable to write to shared archive file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  _file_offset += nbytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
// Align file position to an allocation unit boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
void FileMapInfo::align_file_position() {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   559
  size_t new_file_offset = align_size_up(_file_offset,
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   560
                                         os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  if (new_file_offset != _file_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    _file_offset = new_file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      // Seek one byte back from the target and write a byte to insure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      // that the written file is the correct length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      _file_offset -= 1;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   567
      if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   568
        fail_stop("Unable to seek.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      char zero = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      write_bytes(&zero, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  write_bytes(buffer, nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
// Close the shared archive file.  This does NOT unmap mapped regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
void FileMapInfo::close() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    if (::close(_fd) < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      fail_stop("Unable to close the shared archive file.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    _file_open = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    _fd = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
// JVM/TI RedefineClasses() support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
// Remap the shared readonly space to shared readwrite, private.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
bool FileMapInfo::remap_shared_readonly_as_readwrite() {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   602
  int idx = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   603
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[idx];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  if (!si->_read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    // the space is already readwrite so we are done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  size_t used = si->_used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  size_t size = align_size_up(used, os::vm_allocation_granularity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   613
  char *addr = _header->region_addr(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  char *base = os::remap_memory(_fd, _full_path, si->_file_offset,
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   615
                                addr, size, false /* !read_only */,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
                                si->_allow_exec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  if (base == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   622
  if (base != addr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    fail_continue("Unable to remap shared readonly space at required address.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  si->_read_only = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   630
// Map the whole region at once, assumed to be allocated contiguously.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   631
ReservedSpace FileMapInfo::reserve_shared_memory() {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   632
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[0];
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   633
  char* requested_addr = _header->region_addr(0);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   634
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
   635
  size_t size = FileMapInfo::shared_spaces_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   636
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   637
  // Reserve the space first, then map otherwise map will go right over some
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   638
  // other reserved memory (like the code cache).
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
   639
  ReservedSpace rs(size, os::vm_allocation_granularity(), false, requested_addr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   640
  if (!rs.is_reserved()) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   641
    fail_continue("Unable to reserve shared space at required address "
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   642
                  INTPTR_FORMAT, p2i(requested_addr));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   643
    return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   644
  }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
   645
  // the reserved virtual memory is for mapping class data sharing archive
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   646
  MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   647
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   648
  return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   649
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
// Memory map a region in the address space.
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   652
static const char* shared_region_name[] = { "ReadOnly", "ReadWrite", "MiscData", "MiscCode",
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 40244
diff changeset
   653
                                            "String1", "String2", "OptionalData" };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   655
char* FileMapInfo::map_region(int i) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   656
  assert(!MetaspaceShared::is_string_region(i), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   657
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  size_t used = si->_used;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   659
  size_t alignment = os::vm_allocation_granularity();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   660
  size_t size = align_size_up(used, alignment);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   661
  char *requested_addr = _header->region_addr(i);
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   662
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   663
  // If a tool agent is in use (debugging enabled), we must map the address space RW
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   664
  if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space()) {
31375
aa5ecd9a5716 8087153: EXCEPTION_ACCESS_VIOLATION when CDS RO section vanished on win32
cjplummer
parents: 31364
diff changeset
   665
    si->_read_only = false;
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   666
  }
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   667
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   668
  // map the contents of the CDS archive in this memory
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  char *base = os::map_memory(_fd, _full_path, si->_file_offset,
31375
aa5ecd9a5716 8087153: EXCEPTION_ACCESS_VIOLATION when CDS RO section vanished on win32
cjplummer
parents: 31364
diff changeset
   670
                              requested_addr, size, si->_read_only,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
                              si->_allow_exec);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   672
  if (base == NULL || base != requested_addr) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   673
    fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  }
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   676
#ifdef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   677
  // This call is Windows-only because the memory_type gets recorded for the other platforms
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   678
  // in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   679
  MemTracker::record_virtual_memory_type((address)base, mtClassShared);
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   680
#endif
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   681
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  return base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
31360
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   685
static MemRegion *string_ranges = NULL;
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   686
static int num_ranges = 0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   687
bool FileMapInfo::map_string_regions() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   688
#if INCLUDE_ALL_GCS
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   689
  if (UseG1GC && UseCompressedOops && UseCompressedClassPointers) {
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   690
    // Check that all the narrow oop and klass encodings match the archive
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   691
    if (narrow_oop_mode() != Universe::narrow_oop_mode() ||
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   692
        narrow_oop_shift() != Universe::narrow_oop_shift() ||
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   693
        narrow_klass_base() != Universe::narrow_klass_base() ||
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   694
        narrow_klass_shift() != Universe::narrow_klass_shift()) {
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   695
      if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) {
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   696
        tty->print_cr("Shared string data from the CDS archive is being ignored. "
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   697
                     "The current CompressedOops/CompressedClassPointers encoding differs from "
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   698
                     "that archived due to heap size change. The archive was dumped using max heap "
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   699
                     "size " UINTX_FORMAT "M.", max_heap_size()/M);
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   700
      }
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   701
    } else {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   702
      string_ranges = new MemRegion[MetaspaceShared::max_strings];
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   703
      struct FileMapInfo::FileMapHeader::space_info* si;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   704
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   705
      for (int i = MetaspaceShared::first_string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   706
               i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   707
        si = &_header->_space[i];
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   708
        size_t used = si->_used;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   709
        if (used > 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   710
          size_t size = used;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   711
          char* requested_addr = (char*)((void*)oopDesc::decode_heap_oop_not_null(
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   712
                                                 (narrowOop)si->_addr._offset));
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   713
          string_ranges[num_ranges] = MemRegion((HeapWord*)requested_addr, size / HeapWordSize);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   714
          num_ranges ++;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   715
        }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   716
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   717
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   718
      if (num_ranges == 0) {
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   719
        StringTable::ignore_shared_strings(true);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   720
        return true; // no shared string data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   721
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   722
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   723
      // Check that ranges are within the java heap
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   724
      if (!G1CollectedHeap::heap()->check_archive_addresses(string_ranges, num_ranges)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   725
        fail_continue("Unable to allocate shared string space: range is not "
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   726
                      "within java heap.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   727
        return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   728
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   729
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   730
      // allocate from java heap
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   731
      if (!G1CollectedHeap::heap()->alloc_archive_regions(string_ranges, num_ranges)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   732
        fail_continue("Unable to allocate shared string space: range is "
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   733
                      "already in use.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   734
        return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   735
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   736
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   737
      // Map the string data. No need to call MemTracker::record_virtual_memory_type()
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   738
      // for mapped string regions as they are part of the reserved java heap, which
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   739
      // is already recorded.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   740
      for (int i = 0; i < num_ranges; i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   741
        si = &_header->_space[MetaspaceShared::first_string + i];
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   742
        char* addr = (char*)string_ranges[i].start();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   743
        char* base = os::map_memory(_fd, _full_path, si->_file_offset,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   744
                                    addr, string_ranges[i].byte_size(), si->_read_only,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   745
                                    si->_allow_exec);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   746
        if (base == NULL || base != addr) {
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   747
          // dealloc the string regions from java heap
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   748
          dealloc_string_regions();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   749
          fail_continue("Unable to map shared string space at required address.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   750
          return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   751
        }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   752
      }
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   753
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   754
      if (!verify_string_regions()) {
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   755
        // dealloc the string regions from java heap
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   756
        dealloc_string_regions();
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   757
        fail_continue("Shared string regions are corrupt");
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   758
        return false;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   759
      }
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   760
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   761
      // the shared string data is mapped successfully
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   762
      return true;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   763
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   764
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   765
    if (PrintSharedSpaces && _header->_space[MetaspaceShared::first_string]._used > 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   766
      tty->print_cr("Shared string data from the CDS archive is being ignored. UseG1GC, "
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   767
                    "UseCompressedOops and UseCompressedClassPointers are required.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   768
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   769
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   770
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   771
  // if we get here, the shared string data is not mapped
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   772
  assert(string_ranges == NULL && num_ranges == 0, "sanity");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   773
  StringTable::ignore_shared_strings(true);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   774
#endif
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   775
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   776
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   777
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   778
bool FileMapInfo::verify_string_regions() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   779
  for (int i = MetaspaceShared::first_string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   780
           i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   781
    if (!verify_region_checksum(i)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   782
      return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   783
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   784
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   785
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   786
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   787
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   788
void FileMapInfo::fixup_string_regions() {
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   789
#if INCLUDE_ALL_GCS
31360
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   790
  // If any string regions were found, call the fill routine to make them parseable.
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   791
  // Note that string_ranges may be non-NULL even if no ranges were found.
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   792
  if (num_ranges != 0) {
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   793
    assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   794
    G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_ranges);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   795
  }
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   796
#endif
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   797
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   798
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   799
bool FileMapInfo::verify_region_checksum(int i) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   800
  if (!VerifySharedSpaces) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   801
    return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   802
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   803
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   804
  size_t sz = _header->_space[i]._used;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   805
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   806
  if (sz == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   807
    return true; // no data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   808
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   809
  if (MetaspaceShared::is_string_region(i) && StringTable::shared_string_ignored()) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   810
    return true; // shared string data are not mapped
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   811
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   812
  const char* buf = _header->region_addr(i);
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   813
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   814
  if (crc != _header->_space[i]._crc) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   815
    fail_continue("Checksum verification failed.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   816
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   817
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   818
  return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   819
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
// Unmap a memory region in the address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
void FileMapInfo::unmap_region(int i) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   824
  assert(!MetaspaceShared::is_string_region(i), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   825
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  size_t used = si->_used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  size_t size = align_size_up(used, os::vm_allocation_granularity());
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   828
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   829
  if (used == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   830
    return;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   831
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   832
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   833
  char* addr = _header->region_addr(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   834
  if (!os::unmap_memory(addr, size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    fail_stop("Unable to unmap shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   839
// dealloc the archived string region from java heap
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   840
void FileMapInfo::dealloc_string_regions() {
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   841
#if INCLUDE_ALL_GCS
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   842
  if (num_ranges > 0) {
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   843
    assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   844
    G1CollectedHeap::heap()->dealloc_archive_regions(string_ranges, num_ranges);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   845
  }
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
   846
#endif
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   847
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
void FileMapInfo::assert_mark(bool check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  if (!check) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   851
    fail_stop("Mark mismatch while restoring from shared file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
FileMapInfo* FileMapInfo::_current_info = NULL;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   857
SharedClassPathEntry* FileMapInfo::_classpath_entry_table = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   858
int FileMapInfo::_classpath_entry_table_size = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   859
size_t FileMapInfo::_classpath_entry_size = 0x1234baad;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   860
bool FileMapInfo::_validating_classpath_entry_table = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
// Open the shared archive file, read and validate the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
// information (version, boot classpath, etc.).  If initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
// fails, shared spaces are disabled and the file is closed. [See
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
// fail_continue.]
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   866
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   867
// Validation of the archive is done in two steps:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   868
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   869
// [1] validate_header() - done here. This checks the header, including _paths_misc_info.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   870
// [2] validate_classpath_entry_table - this is done later, because the table is in the RW
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   871
//     region of the archive, which is not mapped yet.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
bool FileMapInfo::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  assert(UseSharedSpaces, "UseSharedSpaces expected.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  init_from_file(_fd);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   880
  if (!validate_header()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   884
  SharedReadOnlySize =  _header->_space[0]._capacity;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   885
  SharedReadWriteSize = _header->_space[1]._capacity;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   886
  SharedMiscDataSize =  _header->_space[2]._capacity;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   887
  SharedMiscCodeSize =  _header->_space[3]._capacity;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   891
char* FileMapInfo::FileMapHeader::region_addr(int idx) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   892
  if (MetaspaceShared::is_string_region(idx)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   893
    return (char*)((void*)oopDesc::decode_heap_oop_not_null(
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   894
              (narrowOop)_space[idx]._addr._offset));
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   895
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   896
    return _space[idx]._addr._base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   897
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   898
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   899
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   900
int FileMapInfo::FileMapHeader::compute_crc() {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   901
  char* header = data();
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   902
  // start computing from the field after _crc
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   903
  char* buf = (char*)&_crc + sizeof(int);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   904
  size_t sz = data_size() - (buf - header);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   905
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   906
  return crc;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   907
}
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   908
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   909
bool FileMapInfo::FileMapHeader::validate() {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   910
  if (VerifySharedSpaces && compute_crc() != _crc) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   911
    fail_continue("Header checksum verification failed.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   912
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   913
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   914
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   915
  if (!Arguments::has_jimage()) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   916
    FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   917
    return false;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   918
  }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   919
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   920
  if (_version != current_version()) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   921
    FileMapInfo::fail_continue("The shared archive file is the wrong version.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   924
  if (_magic != (int)0xf00baba2) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   925
    FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  }
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   928
  char header_version[JVM_IDENT_MAX];
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   929
  get_header_version(header_version);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   930
  if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   931
    log_info(class, path)("expected: %s", header_version);
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   932
    log_info(class, path)("actual:   %s", _jvm_ident);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   933
    FileMapInfo::fail_continue("The shared archive file was created by a different"
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   934
                  " version or build of HotSpot");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   937
  if (_obj_alignment != ObjectAlignmentInBytes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   938
    FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
   939
                  " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   940
                  _obj_alignment, ObjectAlignmentInBytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  }
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   943
  if (_compact_strings != CompactStrings) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   944
    FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   945
                  " does not equal the current CompactStrings setting (%s).",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   946
                  _compact_strings ? "enabled" : "disabled",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   947
                  CompactStrings   ? "enabled" : "disabled");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   948
    return false;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   949
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   951
  // Check if there is a mismatch in --patch-module entry counts between dump time and run time.
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   952
  // More checks will be performed on individual --patch-module entry in the
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   953
  // SharedPathsMiscInfo::check() function.
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   954
  GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   955
  if (patch_mod_args != NULL) {
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   956
    if (_num_patch_mod_prefixes == 0) {
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   957
      FileMapInfo::fail_stop("--patch-module found in run time but none was specified in dump time");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   958
    }
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   959
    if (patch_mod_args->length() != _num_patch_mod_prefixes) {
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   960
      FileMapInfo::fail_stop("mismatched --patch-module entry counts between dump time and run time");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   961
    }
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   962
  } else {
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   963
    if (_num_patch_mod_prefixes > 0) {
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   964
      FileMapInfo::fail_stop("--patch-module specified in dump time but none was specified in run time");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   965
    }
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   966
  }
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 41182
diff changeset
   967
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   971
bool FileMapInfo::validate_header() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   972
  bool status = _header->validate();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   973
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   974
  if (status) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   975
    if (!ClassLoader::check_shared_paths_misc_info(_paths_misc_info, _header->_paths_misc_info_size)) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   976
      if (!PrintSharedArchiveAndExit) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
   977
        fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   978
        status = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   979
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   980
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   981
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   982
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   983
  if (_paths_misc_info != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27025
diff changeset
   984
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   985
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   986
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   987
  return status;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   988
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   989
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
// The following method is provided to see whether a given pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
// falls in the mapped shared space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
// Param:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
// p, The given pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
// Return:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
// True if the p is within the mapped shared space, otherwise, false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
bool FileMapInfo::is_in_shared_space(const void* p) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   997
  for (int i = 0; i < MetaspaceShared::n_regions; i++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   998
    char *base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   999
    if (MetaspaceShared::is_string_region(i) && _header->_space[i]._used == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1000
      continue;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1001
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1002
    base = _header->region_addr(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1003
    if (p >= base && p < base + _header->_space[i]._used) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
}
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1010
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1011
// Check if a given address is within one of the shared regions (ro, rw, md, mc)
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1012
bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1013
  assert((idx >= MetaspaceShared::ro) && (idx <= MetaspaceShared::mc), "invalid region index");
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1014
  char* base = _header->region_addr(idx);
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1015
  if (p >= base && p < base + _header->_space[idx]._used) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1016
    return true;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1017
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1018
  return false;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1019
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1020
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1021
void FileMapInfo::print_shared_spaces() {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34659
diff changeset
  1022
  tty->print_cr("Shared Spaces:");
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1023
  for (int i = 0; i < MetaspaceShared::n_regions; i++) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1024
    struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1025
    char *base = _header->region_addr(i);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34659
diff changeset
  1026
    tty->print("  %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1027
                        shared_region_name[i],
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32589
diff changeset
  1028
                        p2i(base), p2i(base + si->_used));
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1029
  }
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1030
}
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1031
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1032
// Unmap mapped regions of shared space.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1033
void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1034
  FileMapInfo *map_info = FileMapInfo::current_info();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1035
  if (map_info) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1036
    map_info->fail_continue("%s", msg);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1037
    for (int i = 0; i < MetaspaceShared::num_non_strings; i++) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1038
      char *addr = map_info->_header->region_addr(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1039
      if (addr != NULL && !MetaspaceShared::is_string_region(i)) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1040
        map_info->unmap_region(i);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1041
        map_info->_header->_space[i]._addr._base = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1042
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1043
    }
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
  1044
    // Dealloc the string regions only without unmapping. The string regions are part
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
  1045
    // of the java heap. Unmapping of the heap regions are managed by GC.
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
  1046
    map_info->dealloc_string_regions();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1047
  } else if (DumpSharedSpaces) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1048
    fail_stop("%s", msg);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1049
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1050
}