src/hotspot/share/memory/filemap.cpp
author stefank
Fri, 04 May 2018 11:41:35 +0200
changeset 49982 9042ffe5b7fe
parent 49931 840e26123940
child 50039 9fec54fe663d
permissions -rw-r--r--
8200729: Conditional compilation of GCs Reviewed-by: ehelin, coleenp, kvn, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
     2
 * Copyright (c) 2003, 2018, 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"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47599
diff changeset
    26
#include "jvm.h"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48962
diff changeset
    27
#include "classfile/classLoader.inline.hpp"
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents: 33628
diff changeset
    28
#include "classfile/compactHashtable.inline.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    29
#include "classfile/sharedClassUtil.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46701
diff changeset
    30
#include "classfile/stringTable.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "classfile/symbolTable.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    32
#include "classfile/systemDictionaryShared.hpp"
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
    33
#include "classfile/altHashing.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
    34
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
    35
#include "logging/logStream.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
    36
#include "logging/logMessage.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "memory/filemap.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    38
#include "memory/metadataFactory.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    39
#include "memory/metaspaceClosure.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    40
#include "memory/metaspaceShared.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    41
#include "memory/oopFactory.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    42
#include "oops/compressedOops.inline.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    43
#include "oops/objArrayOop.hpp"
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
    44
#include "prims/jvmtiExport.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    45
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    46
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    47
#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
    48
#include "runtime/vm_version.hpp"
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
    49
#include "services/memTracker.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    50
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    51
#include "utilities/defaultStream.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49931
diff changeset
    52
#if INCLUDE_G1GC
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    53
#include "gc/g1/g1CollectedHeap.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    54
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    55
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
# include <sys/stat.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
# include <errno.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
#ifndef O_BINARY       // if defined (Win32) use binary files.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#define O_BINARY 0     // otherwise do nothing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
extern address JVM_FunctionAtStart();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
extern address JVM_FunctionAtEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    66
// Complain and stop. All error conditions occurring during the writing of
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// an archive file should stop the process.  Unrecoverable errors during
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// the reading of the archive file should stop the process.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
static void fail(const char *msg, va_list ap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // This occurs very early during initialization: tty is not initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  jio_fprintf(defaultStream::error_stream(),
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    73
              "An error has occurred while processing the"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
              " shared archive file.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  jio_vfprintf(defaultStream::error_stream(), msg, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  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
    77
  // Do not change the text of the below message because some tests check for it.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  vm_exit_during_initialization("Unable to use shared archive.", NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
void FileMapInfo::fail_stop(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
        va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  va_start(ap, msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  fail(msg, ap);        // Never returns.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  va_end(ap);           // for completeness.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// Complain and continue.  Recoverable errors during the reading of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
// archive file may continue (with sharing disabled).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// If we continue, then disable shared spaces and close the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
void FileMapInfo::fail_continue(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  va_start(ap, msg);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    98
  MetaspaceShared::set_archive_loading_failed();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
    99
  if (PrintSharedArchiveAndExit && _validating_shared_path_table) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   100
    // 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
   101
    // 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
   102
    // entries. No need to quit.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   103
    tty->print("[");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   104
    tty->vprint(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   105
    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
   106
  } else {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   107
    if (RequireSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   108
      fail(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   109
    } else {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   110
      if (log_is_enabled(Info, cds)) {
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   111
        ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   112
        LogStream ls(Log(cds)::info());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   113
        ls.print("UseSharedSpaces: ");
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   114
        ls.vprint_cr(msg, ap);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   115
      }
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
   116
    }
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   117
    UseSharedSpaces = false;
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   118
    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
   119
    current_info()->close();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   124
// Fill in the fileMapInfo structure with data about this VM instance.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   126
// 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
   127
// 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
   128
//
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   129
// 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
   130
// 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
   131
// 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
   132
// 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
   133
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
   134
  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
   135
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   136
  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
   137
  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
   138
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   139
  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
   140
    strcpy(header_version, vm_version);
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   141
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   142
  } else {
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   143
    // 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
   144
    // value over multiple jvm invocations.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   145
    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
   146
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   147
    // 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
   148
    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
   149
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   150
    // 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
   151
    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
   152
    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
   153
  }
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   154
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   156
FileMapInfo::FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   157
  assert(_current_info == NULL, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   158
  _current_info = this;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   159
  memset((void*)this, 0, sizeof(FileMapInfo));
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   160
  _file_offset = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   161
  _file_open = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   162
  _header = SharedClassUtil::allocate_file_map_header();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   163
  _header->_version = _invalid_version;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   164
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   165
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   166
FileMapInfo::~FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   167
  assert(_current_info == this, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   168
  _current_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   169
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   170
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void FileMapInfo::populate_header(size_t alignment) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   172
  _header->populate(this, alignment);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   173
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   174
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   175
size_t FileMapInfo::FileMapHeader::data_size() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   176
  return SharedClassUtil::file_map_header_size() - sizeof(FileMapInfo::FileMapHeaderBase);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   177
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   178
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   179
void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   180
  _magic = 0xf00baba2;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   181
  _version = _current_version;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   182
  _alignment = alignment;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   183
  _obj_alignment = ObjectAlignmentInBytes;
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   184
  _compact_strings = CompactStrings;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   185
  _narrow_oop_mode = Universe::narrow_oop_mode();
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   186
  _narrow_oop_base = Universe::narrow_oop_base();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   187
  _narrow_oop_shift = Universe::narrow_oop_shift();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   188
  _max_heap_size = MaxHeapSize;
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   189
  _narrow_klass_base = Universe::narrow_klass_base();
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   190
  _narrow_klass_shift = Universe::narrow_klass_shift();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   191
  _shared_path_table_size = mapinfo->_shared_path_table_size;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   192
  _shared_path_table = mapinfo->_shared_path_table;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   193
  _shared_path_entry_size = mapinfo->_shared_path_entry_size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // The following fields are for sanity checks for whether this archive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // will function correctly with this JVM and the bootclasspath it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // invoked with.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // JVM version string ... changes on each build.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   200
  get_header_version(_jvm_ident);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   201
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   202
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   203
void SharedClassPathEntry::init(const char* name, TRAPS) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   204
  _timestamp = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   205
  _filesize  = 0;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   206
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   207
  struct stat st;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   208
  if (os::stat(name, &st) == 0) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   209
    if ((st.st_mode & S_IFMT) == S_IFDIR) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   210
      _is_dir = true;
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   211
    } else {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   212
      _is_dir = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   213
      _timestamp = st.st_mtime;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   214
      _filesize = st.st_size;
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   215
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   216
  } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   217
    // The file/dir must exist, or it would not have been added
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   218
    // into ClassLoader::classpath_entry().
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   219
    //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   220
    // If we can't access a jar file in the boot path, then we can't
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   221
    // make assumptions about where classes get loaded from.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   222
    FileMapInfo::fail_stop("Unable to open file %s.", name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   223
  }
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   224
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   225
  size_t len = strlen(name) + 1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   226
  _name = MetadataFactory::new_array<char>(ClassLoaderData::the_null_class_loader_data(), (int)len, THREAD);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   227
  strcpy(_name->data(), name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   228
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   230
bool SharedClassPathEntry::validate(bool is_class_path) {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   231
  assert(UseSharedSpaces, "runtime only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   232
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   233
  struct stat st;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   234
  const char* name = this->name();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   235
  bool ok = true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   236
  log_info(class, path)("checking shared classpath entry: %s", name);
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   237
  if (os::stat(name, &st) != 0 && is_class_path) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   238
    // If the archived module path entry does not exist at runtime, it is not fatal
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   239
    // (no need to invalid the shared archive) because the shared runtime visibility check
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   240
    // filters out any archived module classes that do not have a matching runtime
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   241
    // module path location.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   242
    FileMapInfo::fail_continue("Required classpath entry does not exist: %s", name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   243
    ok = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   244
  } else if (is_dir()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   245
    if (!os::dir_is_empty(name)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   246
      FileMapInfo::fail_continue("directory is not empty: %s", name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   247
      ok = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   248
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   249
  } else if (is_jar_or_bootimage()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   250
    if (_timestamp != st.st_mtime ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   251
        _filesize != st.st_size) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   252
      ok = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   253
      if (PrintSharedArchiveAndExit) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   254
        FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   255
                                   "Timestamp mismatch" :
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   256
                                   "File size mismatch");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   257
      } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   258
        FileMapInfo::fail_continue("A jar/jimage file is not the one used while building"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   259
                                   " the shared archive file: %s", name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   262
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   263
  return ok;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   264
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   265
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   266
void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   267
  it->push(&_name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   268
  it->push(&_manifest);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   269
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   270
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   271
void FileMapInfo::allocate_shared_path_table() {
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   272
  assert(DumpSharedSpaces, "Sanity");
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   273
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   274
  Thread* THREAD = Thread::current();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   275
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   276
  ClassPathEntry* jrt = ClassLoader::get_jrt_entry();
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   277
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   278
  assert(jrt != NULL,
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   279
         "No modular java runtime image present when allocating the CDS classpath entry table");
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   280
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   281
  size_t entry_size = SharedClassUtil::shared_class_path_entry_size(); // assert ( should be 8 byte aligned??)
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   282
  int num_boot_classpath_entries = ClassLoader::num_boot_classpath_entries();
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   283
  int num_app_classpath_entries = ClassLoader::num_app_classpath_entries();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   284
  int num_module_path_entries = ClassLoader::num_module_path_entries();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   285
  int num_entries = num_boot_classpath_entries + num_app_classpath_entries + num_module_path_entries;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   286
  size_t bytes = entry_size * num_entries;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   287
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   288
  _shared_path_table = MetadataFactory::new_array<u8>(loader_data, (int)(bytes + 7 / 8), THREAD);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   289
  _shared_path_table_size = num_entries;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   290
  _shared_path_entry_size = entry_size;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   291
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   292
  // 1. boot class path
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   293
  int i = 0;
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   294
  ClassPathEntry* cpe = jrt;
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   295
  while (cpe != NULL) {
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   296
    const char* type = ((cpe == jrt) ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   297
    log_info(class, path)("add main shared path (%s) %s", type, cpe->name());
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   298
    SharedClassPathEntry* ent = shared_path(i);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   299
    ent->init(cpe->name(), THREAD);
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   300
    if (cpe != jrt) { // No need to do jimage.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   301
      EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   302
      SharedClassUtil::update_shared_classpath(cpe, ent, THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   303
    }
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   304
    cpe = ClassLoader::get_next_boot_classpath_entry(cpe);
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   305
    i++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   307
  assert(i == num_boot_classpath_entries,
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   308
         "number of boot class path entry mismatch");
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   309
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   310
  // 2. app class path
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   311
  ClassPathEntry *acpe = ClassLoader::app_classpath_entries();
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   312
  while (acpe != NULL) {
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   313
    log_info(class, path)("add app shared path %s", acpe->name());
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   314
    SharedClassPathEntry* ent = shared_path(i);
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   315
    ent->init(acpe->name(), THREAD);
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   316
    EXCEPTION_MARK;
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   317
    SharedClassUtil::update_shared_classpath(acpe, ent, THREAD);
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   318
    acpe = acpe->next();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   319
    i++;
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   320
  }
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   321
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   322
  // 3. module path
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   323
  ClassPathEntry *mpe = ClassLoader::module_path_entries();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   324
  while (mpe != NULL) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   325
    log_info(class, path)("add module path %s",mpe->name());
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   326
    SharedClassPathEntry* ent = shared_path(i);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   327
    ent->init(mpe->name(), THREAD);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   328
    EXCEPTION_MARK;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   329
    SharedClassUtil::update_shared_classpath(mpe, ent, THREAD);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   330
    mpe = mpe->next();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   331
    i++;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   332
  }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   333
  assert(i == num_entries, "number of shared path entry mismatch");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   336
void FileMapInfo::check_nonempty_dir_in_shared_path_table() {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   337
  assert(DumpSharedSpaces, "dump time only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   338
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   339
  bool has_nonempty_dir = false;
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   340
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   341
  int end = _shared_path_table_size;
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   342
  if (!ClassLoaderExt::has_platform_or_app_classes()) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   343
    // only check the boot path if no app class is loaded
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   344
    end = ClassLoaderExt::app_class_paths_start_index();
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   345
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   346
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   347
  for (int i = 0; i < end; i++) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   348
    SharedClassPathEntry *e = shared_path(i);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   349
    if (e->is_dir()) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   350
      const char* path = e->name();
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   351
      if (!os::dir_is_empty(path)) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   352
        tty->print_cr("Error: non-empty directory '%s'", path);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   353
        has_nonempty_dir = true;
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   354
      }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   355
    }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   356
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   357
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   358
  if (has_nonempty_dir) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   359
    ClassLoader::exit_with_path_failure("Cannot have non-empty directory in paths", NULL);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   360
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   361
}
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   362
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   363
bool FileMapInfo::validate_shared_path_table() {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   364
  assert(UseSharedSpaces, "runtime only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   365
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   366
  _validating_shared_path_table = true;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   367
  _shared_path_table = _header->_shared_path_table;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   368
  _shared_path_entry_size = _header->_shared_path_entry_size;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   369
  _shared_path_table_size = _header->_shared_path_table_size;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   370
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   371
  FileMapHeaderExt* header = (FileMapHeaderExt*)FileMapInfo::current_info()->header();
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   372
  int module_paths_start_index = header->_app_module_paths_start_index;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   373
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   374
  // If the shared archive contain app or platform classes, validate all entries
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   375
  // in the shared path table. Otherwise, only validate the boot path entries (with
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   376
  // entry index < _app_class_paths_start_index).
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   377
  int count = header->has_platform_or_app_classes() ?
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   378
              _shared_path_table_size : header->_app_class_paths_start_index;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   379
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   380
  for (int i=0; i<count; i++) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   381
    if (i < module_paths_start_index) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   382
      if (shared_path(i)->validate()) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   383
        log_info(class, path)("ok");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   384
      }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   385
    } else if (i >= module_paths_start_index) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   386
      if (shared_path(i)->validate(false /* not a class path entry */)) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   387
        log_info(class, path)("ok");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   388
      }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   389
    } else if (!PrintSharedArchiveAndExit) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   390
      _validating_shared_path_table = false;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   391
      _shared_path_table = NULL;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   392
      _shared_path_table_size = 0;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   393
      return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   394
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   395
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   396
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   397
  _validating_shared_path_table = false;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   398
  return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   399
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   400
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
bool FileMapInfo::init_from_file(int fd) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   404
  size_t sz = _header->data_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   405
  char* addr = _header->data();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   406
  size_t n = os::read(fd, addr, (unsigned int)sz);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   407
  if (n != sz) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    fail_continue("Unable to read the file header.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   411
  if (_header->_version != current_version()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    fail_continue("The shared archive file has the wrong version.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  _file_offset = (long)n;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   416
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   417
  size_t info_size = _header->_paths_misc_info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   418
  _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
   419
  if (_paths_misc_info == NULL) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   420
    fail_continue("Unable to read the file header.");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   421
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   422
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   423
  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
   424
  if (n != info_size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   425
    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
   426
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   427
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   428
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   429
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   430
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   431
  size_t len = lseek(fd, 0, SEEK_END);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   432
  struct FileMapInfo::FileMapHeader::space_info* si =
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   433
    &_header->_space[MetaspaceShared::last_valid_region];
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   434
  // The last space might be empty
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   435
  if (si->_file_offset > len || len - si->_file_offset < si->_used) {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   436
    fail_continue("The shared archive file has been truncated.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   437
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   438
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   439
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   440
  _file_offset += (long)n;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  return 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
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
bool FileMapInfo::open_for_read() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  _full_path = Arguments::GetSharedArchivePath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  if (fd < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (errno == ENOENT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      // Not locating the shared archive is ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      fail_continue("Specified shared archive not found.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      fail_continue("Failed to open shared archive file (%s).",
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36364
diff changeset
   455
                    os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
// Write the FileMapInfo information to the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
void FileMapInfo::open_for_write() {
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   469
  _full_path = Arguments::GetSharedArchivePath();
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   470
  LogMessage(cds) msg;
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   471
  if (msg.is_info()) {
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   472
    msg.info("Dumping shared data to file: ");
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   473
    msg.info("   %s", _full_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
15461
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   476
#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
   477
  chmod(_full_path, _S_IREAD | _S_IWRITE);
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   478
#endif
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   479
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   480
  // 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
   481
  // allow processes that have it open continued access to the file.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  remove(_full_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  if (fd < 0) {
28950
693ae3d5e1ff 8072694: Need errno info when CDS archive creation fails
hseigel
parents: 28023
diff changeset
   485
    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
   486
              os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  _file_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
// Write the header to the file, seek to the next allocation boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
void FileMapInfo::write_header() {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   497
  int info_size = ClassLoader::get_shared_paths_misc_info_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   498
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   499
  _header->_paths_misc_info_size = info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   500
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   501
  align_file_position();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   502
  size_t sz = _header->data_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   503
  char* addr = _header->data();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   504
  write_bytes(addr, (int)sz); // skip the C++ vtable
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   505
  write_bytes(ClassLoader::get_shared_paths_misc_info(), info_size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   506
  align_file_position();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
// Dump region to file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
void FileMapInfo::write_region(int region, char* base, size_t size,
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   513
                               bool read_only, bool allow_exec) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   514
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[region];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    guarantee(si->_file_offset == _file_offset, "file offset mismatch.");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   518
    log_info(cds)("Shared file region %d: " SIZE_FORMAT_HEX_W(08)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   519
                  " bytes, addr " INTPTR_FORMAT " file offset " SIZE_FORMAT_HEX_W(08),
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   520
                  region, size, p2i(base), _file_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    si->_file_offset = _file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   524
  if (MetaspaceShared::is_heap_region(region)) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   525
    assert((base - (char*)Universe::narrow_oop_base()) % HeapWordSize == 0, "Sanity");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   526
    if (base != NULL) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
   527
      si->_addr._offset = (intx)CompressedOops::encode_not_null((oop)base);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   528
    } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   529
      si->_addr._offset = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   530
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   531
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   532
    si->_addr._base = base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   533
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  si->_used = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  si->_read_only = read_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  si->_allow_exec = allow_exec;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   537
  si->_crc = ClassLoader::crc32(0, base, (jint)size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  write_bytes_aligned(base, (int)size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   541
// Write out the given archive heap memory regions.  GC code combines multiple
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   542
// consecutive archive GC regions into one MemRegion whenever possible and
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   543
// produces the 'heap_mem' array.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   544
//
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   545
// If the archive heap memory size is smaller than a single dump time GC region
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   546
// size, there is only one MemRegion in the array.
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   547
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   548
// If the archive heap memory size is bigger than one dump time GC region size,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   549
// the 'heap_mem' array may contain more than one consolidated MemRegions. When
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   550
// the first/bottom archive GC region is a partial GC region (with the empty
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   551
// portion at the higher address within the region), one MemRegion is used for
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   552
// the bottom partial archive GC region. The rest of the consecutive archive
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   553
// GC regions are combined into another MemRegion.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   554
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   555
// Here's the mapping from (archive heap GC regions) -> (GrowableArray<MemRegion> *regions).
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   556
//   + We have 1 or more archive heap regions: ah0, ah1, ah2 ..... ahn
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   557
//   + We have 1 or 2 consolidated heap memory regions: r0 and r1
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   558
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   559
// If there's a single archive GC region (ah0), then r0 == ah0, and r1 is empty.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   560
// Otherwise:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   561
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   562
// "X" represented space that's occupied by heap objects.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   563
// "_" represented unused spaced in the heap region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   564
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   565
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   566
//    |ah0       | ah1 | ah2| ...... | ahn |
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   567
//    |XXXXXX|__ |XXXXX|XXXX|XXXXXXXX|XXXX|
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   568
//    |<-r0->|   |<- r1 ----------------->|
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   569
//            ^^^
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   570
//             |
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   571
//             +-- gap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   572
size_t FileMapInfo::write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   573
                                               int first_region_id, int max_num_regions) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   574
  assert(max_num_regions <= 2, "Only support maximum 2 memory regions");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   575
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   576
  int arr_len = heap_mem == NULL ? 0 : heap_mem->length();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   577
  if(arr_len > max_num_regions) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   578
    fail_stop("Unable to write archive heap memory regions: "
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   579
              "number of memory regions exceeds maximum due to fragmentation");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   580
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   581
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   582
  size_t total_size = 0;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   583
  for (int i = first_region_id, arr_idx = 0;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   584
           i < first_region_id + max_num_regions;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   585
           i++, arr_idx++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   586
    char* start = NULL;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   587
    size_t size = 0;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   588
    if (arr_idx < arr_len) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   589
      start = (char*)heap_mem->at(arr_idx).start();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   590
      size = heap_mem->at(arr_idx).byte_size();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   591
      total_size += size;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   592
    }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   593
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   594
    log_info(cds)("Archive heap region %d " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes",
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   595
                  i, p2i(start), p2i(start + size), size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   596
    write_region(i, start, size, false, false);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   597
  }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   598
  return total_size;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   599
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   600
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    int n = ::write(_fd, buffer, nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    if (n != nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      // It is dangerous to leave the corrupted shared archive file around,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
      // close and remove the file. See bug 6372906.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
      close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
      remove(_full_path);
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   611
      fail_stop("Unable to write to shared archive file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  _file_offset += nbytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
// Align file position to an allocation unit boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
void FileMapInfo::align_file_position() {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   621
  size_t new_file_offset = align_up(_file_offset,
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   622
                                         os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  if (new_file_offset != _file_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    _file_offset = new_file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      // Seek one byte back from the target and write a byte to insure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      // that the written file is the correct length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      _file_offset -= 1;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   629
      if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   630
        fail_stop("Unable to seek.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      char zero = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      write_bytes(&zero, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
void FileMapInfo::write_bytes_aligned(const void* buffer, int nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  write_bytes(buffer, nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
// Close the shared archive file.  This does NOT unmap mapped regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
void FileMapInfo::close() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    if (::close(_fd) < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      fail_stop("Unable to close the shared archive file.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    _file_open = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    _fd = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
// JVM/TI RedefineClasses() support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
// Remap the shared readonly space to shared readwrite, private.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
bool FileMapInfo::remap_shared_readonly_as_readwrite() {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   664
  int idx = MetaspaceShared::ro;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   665
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[idx];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  if (!si->_read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    // the space is already readwrite so we are done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  size_t used = si->_used;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   671
  size_t size = align_up(used, os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   675
  char *addr = _header->region_addr(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  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
   677
                                addr, size, false /* !read_only */,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
                                si->_allow_exec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  if (base == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    fail_continue("Unable to remap shared readonly space (errno=%d).", errno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   684
  if (base != addr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    fail_continue("Unable to remap shared readonly space at required address.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  si->_read_only = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   692
// 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
   693
ReservedSpace FileMapInfo::reserve_shared_memory() {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   694
  char* requested_addr = _header->region_addr(0);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   695
  size_t size = FileMapInfo::core_spaces_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   696
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   697
  // 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
   698
  // other reserved memory (like the code cache).
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
   699
  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
   700
  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
   701
    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
   702
                  INTPTR_FORMAT, p2i(requested_addr));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   703
    return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   704
  }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
   705
  // 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
   706
  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
   707
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   708
  return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   709
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
// Memory map a region in the address space.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   712
static const char* shared_region_name[] = { "MiscData", "ReadWrite", "ReadOnly", "MiscCode", "OptionalData",
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   713
                                            "String1", "String2", "OpenArchive1", "OpenArchive2" };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   715
char* FileMapInfo::map_region(int i, char** top_ret) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   716
  assert(!MetaspaceShared::is_heap_region(i), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   717
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  size_t used = si->_used;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   719
  size_t alignment = os::vm_allocation_granularity();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   720
  size_t size = align_up(used, alignment);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   721
  char *requested_addr = _header->region_addr(i);
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   722
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   723
  // 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
   724
  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
   725
    si->_read_only = false;
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   726
  }
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   727
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   728
  // map the contents of the CDS archive in this memory
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  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
   730
                              requested_addr, size, si->_read_only,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
                              si->_allow_exec);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   732
  if (base == NULL || base != requested_addr) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   733
    fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  }
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   736
#ifdef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   737
  // 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
   738
  // 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
   739
  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
   740
#endif
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   741
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   742
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   743
  if (!verify_region_checksum(i)) {
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   744
    return NULL;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   745
  }
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   746
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   747
  *top_ret = base + size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  return base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
31360
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   751
static MemRegion *string_ranges = NULL;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   752
static MemRegion *open_archive_heap_ranges = NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   753
static int num_string_ranges = 0;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   754
static int num_open_archive_heap_ranges = 0;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   755
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   756
#if INCLUDE_CDS_JAVA_HEAP
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   757
//
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   758
// Map the shared string objects and open archive heap objects to the runtime
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   759
// java heap.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   760
//
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   761
// The shared strings are mapped near the runtime java heap top. The
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   762
// mapped strings contain no out-going references to any other java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   763
// regions. GC does not write into the mapped shared strings.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   764
//
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   765
// The open archive heap objects are mapped below the shared strings in
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   766
// the runtime java heap. The mapped open archive heap data only contain
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   767
// references to the shared strings and open archive objects initially.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   768
// During runtime execution, out-going references to any other java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   769
// regions may be added. GC may mark and update references in the mapped
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   770
// open archive objects.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   771
void FileMapInfo::map_heap_regions() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   772
  if (MetaspaceShared::is_heap_object_archiving_allowed()) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   773
      log_info(cds)("Archived narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   774
                    narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   775
      log_info(cds)("Archived narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   776
                    p2i(narrow_klass_base()), narrow_klass_shift());
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   777
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   778
    // 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
   779
    if (narrow_oop_mode() != Universe::narrow_oop_mode() ||
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   780
        narrow_oop_base() != Universe::narrow_oop_base() ||
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   781
        narrow_oop_shift() != Universe::narrow_oop_shift() ||
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   782
        narrow_klass_base() != Universe::narrow_klass_base() ||
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   783
        narrow_klass_shift() != Universe::narrow_klass_shift()) {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   784
      if (log_is_enabled(Info, cds) && _header->_space[MetaspaceShared::first_string]._used > 0) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   785
        log_info(cds)("Cached heap data from the CDS archive is being ignored. "
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   786
                      "The current CompressedOops/CompressedClassPointers encoding differs from "
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   787
                      "that archived due to heap size change. The archive was dumped using max heap "
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   788
                      "size " UINTX_FORMAT "M.", max_heap_size()/M);
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   789
        log_info(cds)("Current narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   790
                      Universe::narrow_oop_mode(), p2i(Universe::narrow_oop_base()),
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   791
                      Universe::narrow_oop_shift());
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   792
        log_info(cds)("Current narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   793
                      p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
31362
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   794
      }
8957ccbb5821 8098821: Crash in system dictionary initialization with shared strings
coleenp
parents: 31345
diff changeset
   795
    } else {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   796
      // First, map string regions as closed archive heap regions.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   797
      // GC does not write into the regions.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   798
      if (map_heap_data(&string_ranges,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   799
                         MetaspaceShared::first_string,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   800
                         MetaspaceShared::max_strings,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   801
                         &num_string_ranges)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   802
        StringTable::set_shared_string_mapped();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   803
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   804
        // Now, map open_archive heap regions, GC can write into the regions.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   805
        if (map_heap_data(&open_archive_heap_ranges,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   806
                          MetaspaceShared::first_open_archive_heap_region,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   807
                          MetaspaceShared::max_open_archive_heap_region,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   808
                          &num_open_archive_heap_ranges,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   809
                          true /* open */)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   810
          MetaspaceShared::set_open_archive_heap_region_mapped();
31345
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
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   813
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   814
  } else {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   815
    if (log_is_enabled(Info, cds) && _header->_space[MetaspaceShared::first_string]._used > 0) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   816
      log_info(cds)("Cached heap data from the CDS archive is being ignored. UseG1GC, "
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   817
                    "UseCompressedOops and UseCompressedClassPointers are required.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   818
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   819
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   820
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   821
  if (!StringTable::shared_string_mapped()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   822
    assert(string_ranges == NULL && num_string_ranges == 0, "sanity");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   823
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   824
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   825
  if (!MetaspaceShared::open_archive_heap_region_mapped()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   826
    assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   827
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   828
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   829
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   830
bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   831
                                int max, int* num, bool is_open_archive) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   832
  MemRegion * regions = new MemRegion[max];
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   833
  struct FileMapInfo::FileMapHeader::space_info* si;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   834
  int region_num = 0;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   835
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   836
  for (int i = first;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   837
           i < first + max; i++) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   838
    si = &_header->_space[i];
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   839
    size_t used = si->_used;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   840
    if (used > 0) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   841
      size_t size = used;
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
   842
      char* requested_addr = (char*)((void*)CompressedOops::decode_not_null(
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   843
                                            (narrowOop)si->_addr._offset));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   844
      regions[region_num] = MemRegion((HeapWord*)requested_addr, size / HeapWordSize);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   845
      region_num ++;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   846
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   847
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   848
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   849
  if (region_num == 0) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   850
    return false; // no archived java heap data
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   851
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   852
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   853
  // Check that ranges are within the java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   854
  if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   855
    log_info(cds)("UseSharedSpaces: Unable to allocate region, "
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   856
                  "range is not within java heap.");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   857
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   858
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   859
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   860
  // allocate from java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   861
  if (!G1CollectedHeap::heap()->alloc_archive_regions(
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   862
             regions, region_num, is_open_archive)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   863
    log_info(cds)("UseSharedSpaces: Unable to allocate region, "
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   864
                  "java heap range is already in use.");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   865
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   866
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   867
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   868
  // Map the archived heap data. No need to call MemTracker::record_virtual_memory_type()
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   869
  // for mapped regions as they are part of the reserved java heap, which is
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   870
  // already recorded.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   871
  for (int i = 0; i < region_num; i++) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   872
    si = &_header->_space[first + i];
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   873
    char* addr = (char*)regions[i].start();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   874
    char* base = os::map_memory(_fd, _full_path, si->_file_offset,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   875
                                addr, regions[i].byte_size(), si->_read_only,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   876
                                si->_allow_exec);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   877
    if (base == NULL || base != addr) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   878
      // dealloc the regions from java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   879
      dealloc_archive_heap_regions(regions, region_num);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   880
      log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap.");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   881
      return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   882
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   883
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   884
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   885
  if (!verify_mapped_heap_regions(first, region_num)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   886
    // dealloc the regions from java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   887
    dealloc_archive_heap_regions(regions, region_num);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   888
    log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   889
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   890
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   891
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   892
  // the shared heap data is mapped successfully
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   893
  *heap_mem = regions;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   894
  *num = region_num;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   895
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   896
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   897
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   898
bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   899
  for (int i = first;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   900
           i <= first + num; i++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   901
    if (!verify_region_checksum(i)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   902
      return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   903
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   904
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   905
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   906
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   907
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   908
void FileMapInfo::fixup_mapped_heap_regions() {
31360
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   909
  // 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
   910
  // Note that string_ranges may be non-NULL even if no ranges were found.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   911
  if (num_string_ranges != 0) {
31360
87d3a62c7e35 8098815: Assertion failure in CDS shared string archive support on Windows
iklam
parents: 31345
diff changeset
   912
    assert(string_ranges != NULL, "Null string_ranges array with non-zero count");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   913
    G1CollectedHeap::heap()->fill_archive_regions(string_ranges, num_string_ranges);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   914
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   915
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   916
  // do the same for mapped open archive heap regions
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   917
  if (num_open_archive_heap_ranges != 0) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   918
    assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   919
    G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   920
                                                  num_open_archive_heap_ranges);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   921
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   922
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   923
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   924
// dealloc the archive regions from java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   925
void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   926
  if (num > 0) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   927
    assert(regions != NULL, "Null archive ranges array with non-zero count");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   928
    G1CollectedHeap::heap()->dealloc_archive_regions(regions, num);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   929
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   930
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   931
#endif // INCLUDE_CDS_JAVA_HEAP
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   932
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   933
bool FileMapInfo::verify_region_checksum(int i) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   934
  if (!VerifySharedSpaces) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   935
    return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   936
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   937
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   938
  size_t sz = _header->_space[i]._used;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   939
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   940
  if (sz == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   941
    return true; // no data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   942
  }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   943
  if ((MetaspaceShared::is_string_region(i) &&
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   944
       !StringTable::shared_string_mapped()) ||
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   945
      (MetaspaceShared::is_open_archive_heap_region(i) &&
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   946
       !MetaspaceShared::open_archive_heap_region_mapped())) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   947
    return true; // archived heap data is not mapped
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   948
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   949
  const char* buf = _header->region_addr(i);
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   950
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   951
  if (crc != _header->_space[i]._crc) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   952
    fail_continue("Checksum verification failed.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   953
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   954
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   955
  return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   956
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
// Unmap a memory region in the address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
void FileMapInfo::unmap_region(int i) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   961
  assert(!MetaspaceShared::is_heap_region(i), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   962
  struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  size_t used = si->_used;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   964
  size_t size = align_up(used, os::vm_allocation_granularity());
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   965
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   966
  if (used == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   967
    return;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   968
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   969
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   970
  char* addr = _header->region_addr(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   971
  if (!os::unmap_memory(addr, size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    fail_stop("Unable to unmap shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
void FileMapInfo::assert_mark(bool check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  if (!check) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   978
    fail_stop("Mark mismatch while restoring from shared file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   982
void FileMapInfo::metaspace_pointers_do(MetaspaceClosure* it) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   983
  it->push(&_shared_path_table);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   984
  for (int i=0; i<_shared_path_table_size; i++) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   985
    shared_path(i)->metaspace_pointers_do(it);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   986
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   987
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   988
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
FileMapInfo* FileMapInfo::_current_info = NULL;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   991
Array<u8>* FileMapInfo::_shared_path_table = NULL;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   992
int FileMapInfo::_shared_path_table_size = 0;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   993
size_t FileMapInfo::_shared_path_entry_size = 0x1234baad;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   994
bool FileMapInfo::_validating_shared_path_table = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
// Open the shared archive file, read and validate the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
// information (version, boot classpath, etc.).  If initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
// fails, shared spaces are disabled and the file is closed. [See
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
// fail_continue.]
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1000
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1001
// Validation of the archive is done in two steps:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1002
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1003
// [1] validate_header() - done here. This checks the header, including _paths_misc_info.
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1004
// [2] validate_shared_path_table - this is done later, because the table is in the RW
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1005
//     region of the archive, which is not mapped yet.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
bool FileMapInfo::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  assert(UseSharedSpaces, "UseSharedSpaces expected.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  init_from_file(_fd);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1014
  if (!validate_header()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1020
char* FileMapInfo::FileMapHeader::region_addr(int idx) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1021
  if (MetaspaceShared::is_heap_region(idx)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1022
    return _space[idx]._used > 0 ?
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
  1023
             (char*)((void*)CompressedOops::decode_not_null((narrowOop)_space[idx]._addr._offset)) : NULL;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1024
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1025
    return _space[idx]._addr._base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1026
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1027
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1028
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1029
int FileMapInfo::FileMapHeader::compute_crc() {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1030
  char* header = data();
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1031
  // start computing from the field after _crc
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1032
  char* buf = (char*)&_crc + sizeof(int);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1033
  size_t sz = data_size() - (buf - header);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1034
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1035
  return crc;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1036
}
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1037
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1038
// This function should only be called during run time with UseSharedSpaces enabled.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1039
bool FileMapInfo::FileMapHeader::validate() {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1040
  if (VerifySharedSpaces && compute_crc() != _crc) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1041
    fail_continue("Header checksum verification failed.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1042
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1043
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1044
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1045
  if (!Arguments::has_jimage()) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1046
    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
  1047
    return false;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1048
  }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1049
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1050
  if (_version != current_version()) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1051
    FileMapInfo::fail_continue("The shared archive file is the wrong version.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1054
  if (_magic != (int)0xf00baba2) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1055
    FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  }
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
  1058
  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
  1059
  get_header_version(header_version);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1060
  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
  1061
    log_info(class, path)("expected: %s", header_version);
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
  1062
    log_info(class, path)("actual:   %s", _jvm_ident);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1063
    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
  1064
                  " version or build of HotSpot");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1067
  if (_obj_alignment != ObjectAlignmentInBytes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1068
    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
  1069
                  " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1070
                  _obj_alignment, ObjectAlignmentInBytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  }
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1073
  if (_compact_strings != CompactStrings) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1074
    FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1075
                  " does not equal the current CompactStrings setting (%s).",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1076
                  _compact_strings ? "enabled" : "disabled",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1077
                  CompactStrings   ? "enabled" : "disabled");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1078
    return false;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1079
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1084
bool FileMapInfo::validate_header() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1085
  bool status = _header->validate();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1086
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1087
  if (status) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1088
    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
  1089
      if (!PrintSharedArchiveAndExit) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
  1090
        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
  1091
        status = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1092
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1093
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1094
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1095
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1096
  if (_paths_misc_info != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27025
diff changeset
  1097
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1098
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1099
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1100
  return status;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1101
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1102
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1103
// Check if a given address is within one of the shared regions
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1104
bool FileMapInfo::is_in_shared_region(const void* p, int idx) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1105
  assert(idx == MetaspaceShared::ro ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1106
         idx == MetaspaceShared::rw ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1107
         idx == MetaspaceShared::mc ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1108
         idx == MetaspaceShared::md, "invalid region index");
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1109
  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
  1110
  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
  1111
    return true;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1112
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1113
  return false;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1114
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1115
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1116
void FileMapInfo::print_shared_spaces() {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34659
diff changeset
  1117
  tty->print_cr("Shared Spaces:");
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1118
  for (int i = 0; i < MetaspaceShared::n_regions; i++) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1119
    struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i];
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1120
    char *base = _header->region_addr(i);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34659
diff changeset
  1121
    tty->print("  %s " INTPTR_FORMAT "-" INTPTR_FORMAT,
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1122
                        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
  1123
                        p2i(base), p2i(base + si->_used));
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1124
  }
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17109
diff changeset
  1125
}
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1126
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1127
// Unmap mapped regions of shared space.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1128
void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1129
  FileMapInfo *map_info = FileMapInfo::current_info();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1130
  if (map_info) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1131
    map_info->fail_continue("%s", msg);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1132
    for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1133
      char *addr = map_info->_header->region_addr(i);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1134
      if (addr != NULL && !MetaspaceShared::is_heap_region(i)) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1135
        map_info->unmap_region(i);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1136
        map_info->_header->_space[i]._addr._base = NULL;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1137
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1138
    }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1139
    // Dealloc the archive heap regions only without unmapping. The regions are part
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 31375
diff changeset
  1140
    // of the java heap. Unmapping of the heap regions are managed by GC.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1141
    map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1142
                                           num_open_archive_heap_ranges);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1143
    map_info->dealloc_archive_heap_regions(string_ranges, num_string_ranges);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1144
  } else if (DumpSharedSpaces) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1145
    fail_stop("%s", msg);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1146
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1147
}