src/hotspot/share/memory/filemap.cpp
author stefank
Thu, 09 May 2019 14:26:03 +0200
changeset 54780 f8d182aedc92
parent 54573 b73893f7fee3
child 54825 1b03400e5a8f
permissions -rw-r--r--
8223136: Move compressed oops functions to CompressedOops class Reviewed-by: coleenp, lkorinth
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
     2
 * Copyright (c) 2003, 2019, 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"
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
    27
#include "classfile/classFileStream.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48962
diff changeset
    28
#include "classfile/classLoader.inline.hpp"
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
    29
#include "classfile/classLoaderData.inline.hpp"
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
    30
#include "classfile/classLoaderExt.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"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
    38
#include "memory/heapShared.inline.hpp"
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
    39
#include "memory/iterator.inline.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    40
#include "memory/metadataFactory.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    41
#include "memory/metaspaceClosure.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    42
#include "memory/metaspaceShared.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    43
#include "memory/oopFactory.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    44
#include "oops/compressedOops.inline.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
    45
#include "oops/objArrayOop.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
    46
#include "oops/oop.inline.hpp"
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
    47
#include "prims/jvmtiExport.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    48
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    49
#include "runtime/java.hpp"
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
    50
#include "runtime/mutexLocker.hpp"
51480
2e928420389d 8209826: Undefined reference to os::write after JDK-8209657 (filemap.hpp cleanup)
iklam
parents: 51477
diff changeset
    51
#include "runtime/os.inline.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    52
#include "runtime/vm_version.hpp"
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
    53
#include "services/memTracker.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    54
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    55
#include "utilities/defaultStream.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49931
diff changeset
    56
#if INCLUDE_G1GC
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    57
#include "gc/g1/g1CollectedHeap.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
    58
#include "gc/g1/heapRegion.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
    59
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    60
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
# include <sys/stat.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
# include <errno.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#ifndef O_BINARY       // if defined (Win32) use binary files.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
#define O_BINARY 0     // otherwise do nothing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
extern address JVM_FunctionAtStart();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
extern address JVM_FunctionAtEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    71
// Complain and stop. All error conditions occurring during the writing of
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// an archive file should stop the process.  Unrecoverable errors during
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// the reading of the archive file should stop the process.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
static void fail(const char *msg, va_list ap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // This occurs very early during initialization: tty is not initialized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  jio_fprintf(defaultStream::error_stream(),
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    78
              "An error has occurred while processing the"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
              " shared archive file.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  jio_vfprintf(defaultStream::error_stream(), msg, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  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
    82
  // Do not change the text of the below message because some tests check for it.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  vm_exit_during_initialization("Unable to use shared archive.", NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
void FileMapInfo::fail_stop(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  va_start(ap, msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  fail(msg, ap);        // Never returns.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  va_end(ap);           // for completeness.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// Complain and continue.  Recoverable errors during the reading of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// archive file may continue (with sharing disabled).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// If we continue, then disable shared spaces and close the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void FileMapInfo::fail_continue(const char *msg, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  va_start(ap, msg);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   103
  MetaspaceShared::set_archive_loading_failed();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   104
  if (PrintSharedArchiveAndExit && _validating_shared_path_table) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   105
    // 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
   106
    // 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
   107
    // entries. No need to quit.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   108
    tty->print("[");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   109
    tty->vprint(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   110
    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
   111
  } else {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   112
    if (RequireSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   113
      fail(msg, ap);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   114
    } else {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   115
      if (log_is_enabled(Info, cds)) {
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42876
diff changeset
   116
        ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   117
        LogStream ls(Log(cds)::info());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   118
        ls.print("UseSharedSpaces: ");
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   119
        ls.vprint_cr(msg, ap);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   120
      }
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
   121
    }
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   122
    UseSharedSpaces = false;
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27880
diff changeset
   123
    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
   124
    current_info()->close();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   129
// Fill in the fileMapInfo structure with data about this VM instance.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   131
// 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
   132
// 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
   133
//
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   134
// 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
   135
// 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
   136
// 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
   137
// 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
   138
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
   139
  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
   140
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   141
  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
   142
  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
   143
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   144
  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
   145
    strcpy(header_version, vm_version);
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
  } else {
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   148
    // 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
   149
    // value over multiple jvm invocations.
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   150
    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
   151
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   152
    // 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
   153
    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
   154
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   155
    // 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
   156
    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
   157
    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
   158
  }
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
   159
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   161
FileMapInfo::FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   162
  assert(_current_info == NULL, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   163
  _current_info = this;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   164
  memset((void*)this, 0, sizeof(FileMapInfo));
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   165
  _file_offset = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   166
  _file_open = false;
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   167
  _header = (FileMapHeader*)os::malloc(sizeof(FileMapHeader), mtInternal);
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   168
  _header->_version = INVALID_CDS_ARCHIVE_VERSION;
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   169
  _header->_has_platform_or_app_classes = true;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   170
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   171
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   172
FileMapInfo::~FileMapInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   173
  assert(_current_info == this, "must be singleton"); // not thread safe
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   174
  _current_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   175
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   176
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
void FileMapInfo::populate_header(size_t alignment) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   178
  _header->populate(this, alignment);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   179
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   180
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   181
void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   182
  _magic = CDS_ARCHIVE_MAGIC;
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   183
  _version = CURRENT_CDS_ARCHIVE_VERSION;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   184
  _alignment = alignment;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   185
  _obj_alignment = ObjectAlignmentInBytes;
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   186
  _compact_strings = CompactStrings;
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   187
  _narrow_oop_mode = CompressedOops::mode();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   188
  _narrow_oop_base = CompressedOops::base();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   189
  _narrow_oop_shift = CompressedOops::shift();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   190
  _max_heap_size = MaxHeapSize;
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   191
  _narrow_klass_base = CompressedKlassPointers::base();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   192
  _narrow_klass_shift = CompressedKlassPointers::shift();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   193
  _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
   194
  _shared_path_table = mapinfo->_shared_path_table;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   195
  _shared_path_entry_size = mapinfo->_shared_path_entry_size;
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 51823
diff changeset
   196
  if (HeapShared::is_heap_object_archiving_allowed()) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   197
    _heap_reserved = Universe::heap()->reserved_region();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   198
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // The following fields are for sanity checks for whether this archive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // will function correctly with this JVM and the bootclasspath it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // invoked with.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // JVM version string ... changes on each build.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   205
  get_header_version(_jvm_ident);
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   206
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   207
  ClassLoaderExt::finalize_shared_paths_misc_info();
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   208
  _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   209
  _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   210
  _max_used_path_index = ClassLoaderExt::max_used_path_index();
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   211
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   212
  _verify_local = BytecodeVerificationLocal;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   213
  _verify_remote = BytecodeVerificationRemote;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   214
  _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   215
  _shared_base_address = SharedBaseAddress;
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
   216
  _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   217
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   218
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   219
void SharedClassPathEntry::init(const char* name, bool is_modules_image, TRAPS) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   220
  assert(DumpSharedSpaces, "dump time only");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   221
  _timestamp = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   222
  _filesize  = 0;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   223
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   224
  struct stat st;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   225
  if (os::stat(name, &st) == 0) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   226
    if ((st.st_mode & S_IFMT) == S_IFDIR) {
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   227
      _type = dir_entry;
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   228
    } else {
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   229
      // The timestamp of the modules_image is not checked at runtime.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   230
      if (is_modules_image) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   231
        _type = modules_image_entry;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   232
      } else {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   233
        _type = jar_entry;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   234
        _timestamp = st.st_mtime;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   235
      }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   236
      _filesize = st.st_size;
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   237
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   238
  } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   239
    // 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
   240
    // into ClassLoader::classpath_entry().
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   241
    //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   242
    // 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
   243
    // make assumptions about where classes get loaded from.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   244
    FileMapInfo::fail_stop("Unable to open file %s.", name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   245
  }
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
   246
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   247
  size_t len = strlen(name) + 1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   248
  _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
   249
  strcpy(_name->data(), name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   250
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   252
bool SharedClassPathEntry::validate(bool is_class_path) {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   253
  assert(UseSharedSpaces, "runtime only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   254
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   255
  struct stat st;
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   256
  const char* name;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   257
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   258
  // In order to validate the runtime modules image file size against the archived
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   259
  // size information, we need to obtain the runtime modules image path. The recorded
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   260
  // dump time modules image path in the archive may be different from the runtime path
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   261
  // if the JDK image has beed moved after generating the archive.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   262
  if (is_modules_image()) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   263
    name = ClassLoader::get_jrt_entry()->name();
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   264
  } else {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   265
    name = this->name();
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   266
  }
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   267
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   268
  bool ok = true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   269
  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
   270
  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
   271
    // 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
   272
    // (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
   273
    // 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
   274
    // module path location.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   275
    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
   276
    ok = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   277
  } else if (is_dir()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   278
    if (!os::dir_is_empty(name)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   279
      FileMapInfo::fail_continue("directory is not empty: %s", name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   280
      ok = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   281
    }
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   282
  } else if ((has_timestamp() && _timestamp != st.st_mtime) ||
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   283
             _filesize != st.st_size) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   284
    ok = false;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   285
    if (PrintSharedArchiveAndExit) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   286
      FileMapInfo::fail_continue(_timestamp != st.st_mtime ?
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   287
                                 "Timestamp mismatch" :
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   288
                                 "File size mismatch");
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   289
    } else {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   290
      FileMapInfo::fail_continue("A jar file is not the one used while building"
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   291
                                 " the shared archive file: %s", name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   293
  }
52562
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   294
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   295
  if (PrintSharedArchiveAndExit && !ok) {
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   296
    // If PrintSharedArchiveAndExit is enabled, don't report failure to the
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   297
    // caller. Please see above comments for more details.
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   298
    ok = true;
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   299
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   300
  return ok;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   301
}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   302
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   303
void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   304
  it->push(&_name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   305
  it->push(&_manifest);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   306
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   307
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   308
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
   309
  assert(DumpSharedSpaces, "Sanity");
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   310
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   311
  Thread* THREAD = Thread::current();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   312
  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
   313
  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
   314
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   315
  assert(jrt != NULL,
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   316
         "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
   317
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   318
  size_t entry_size = sizeof(SharedClassPathEntry); // 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
   319
  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
   320
  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
   321
  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
   322
  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
   323
  size_t bytes = entry_size * num_entries;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   324
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   325
  _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
   326
  _shared_path_table_size = num_entries;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   327
  _shared_path_entry_size = entry_size;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   328
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   329
  // 1. boot class path
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   330
  int i = 0;
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   331
  ClassPathEntry* cpe = jrt;
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   332
  while (cpe != NULL) {
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   333
    bool is_jrt = (cpe == jrt);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   334
    const char* type = (is_jrt ? "jrt" : (cpe->is_jar_file() ? "jar" : "dir"));
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   335
    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
   336
    SharedClassPathEntry* ent = shared_path(i);
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   337
    ent->init(cpe->name(), is_jrt, THREAD);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   338
    if (!is_jrt) {    // No need to do the modules image.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   339
      EXCEPTION_MARK; // The following call should never throw, but would exit VM on error.
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   340
      update_shared_classpath(cpe, ent, THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   341
    }
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   342
    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
   343
    i++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  }
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   345
  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
   346
         "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
   347
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   348
  // 2. app class path
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   349
  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
   350
  while (acpe != NULL) {
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   351
    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
   352
    SharedClassPathEntry* ent = shared_path(i);
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   353
    ent->init(acpe->name(), false, THREAD);
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   354
    EXCEPTION_MARK;
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   355
    update_shared_classpath(acpe, ent, THREAD);
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   356
    acpe = acpe->next();
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   357
    i++;
47991
a474466c4fdb 8187118: Remove appending -cp path to the boot class path at AppCDS dump time
jiangli
parents: 47765
diff changeset
   358
  }
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   359
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   360
  // 3. module path
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   361
  ClassPathEntry *mpe = ClassLoader::module_path_entries();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   362
  while (mpe != NULL) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   363
    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
   364
    SharedClassPathEntry* ent = shared_path(i);
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   365
    ent->init(mpe->name(), false, THREAD);
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   366
    EXCEPTION_MARK;
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   367
    update_shared_classpath(mpe, ent, THREAD);
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   368
    mpe = mpe->next();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   369
    i++;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   370
  }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   371
  assert(i == num_entries, "number of shared path entry mismatch");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   374
void FileMapInfo::check_nonempty_dir_in_shared_path_table() {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   375
  assert(DumpSharedSpaces, "dump time only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   376
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   377
  bool has_nonempty_dir = false;
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   378
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   379
  int last = _shared_path_table_size - 1;
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   380
  if (last > ClassLoaderExt::max_used_path_index()) {
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   381
     // no need to check any path beyond max_used_path_index
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   382
     last = ClassLoaderExt::max_used_path_index();
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   383
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   384
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   385
  for (int i = 0; i <= last; i++) {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   386
    SharedClassPathEntry *e = shared_path(i);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   387
    if (e->is_dir()) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   388
      const char* path = e->name();
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   389
      if (!os::dir_is_empty(path)) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   390
        tty->print_cr("Error: non-empty directory '%s'", path);
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   391
        has_nonempty_dir = true;
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   392
      }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   393
    }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   394
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   395
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   396
  if (has_nonempty_dir) {
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   397
    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
   398
  }
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   399
}
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   400
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   401
class ManifestStream: public ResourceObj {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   402
  private:
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   403
  u1*   _buffer_start; // Buffer bottom
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   404
  u1*   _buffer_end;   // Buffer top (one past last element)
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   405
  u1*   _current;      // Current buffer position
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   406
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   407
 public:
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   408
  // Constructor
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   409
  ManifestStream(u1* buffer, int length) : _buffer_start(buffer),
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   410
                                           _current(buffer) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   411
    _buffer_end = buffer + length;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   412
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   413
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   414
  static bool is_attr(u1* attr, const char* name) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   415
    return strncmp((const char*)attr, name, strlen(name)) == 0;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   416
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   417
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   418
  static char* copy_attr(u1* value, size_t len) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   419
    char* buf = NEW_RESOURCE_ARRAY(char, len + 1);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   420
    strncpy(buf, (char*)value, len);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   421
    buf[len] = 0;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   422
    return buf;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   423
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   424
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   425
  // The return value indicates if the JAR is signed or not
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   426
  bool check_is_signed() {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   427
    u1* attr = _current;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   428
    bool isSigned = false;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   429
    while (_current < _buffer_end) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   430
      if (*_current == '\n') {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   431
        *_current = '\0';
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   432
        u1* value = (u1*)strchr((char*)attr, ':');
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   433
        if (value != NULL) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   434
          assert(*(value+1) == ' ', "Unrecognized format" );
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   435
          if (strstr((char*)attr, "-Digest") != NULL) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   436
            isSigned = true;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   437
            break;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   438
          }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   439
        }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   440
        *_current = '\n'; // restore
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   441
        attr = _current + 1;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   442
      }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   443
      _current ++;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   444
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   445
    return isSigned;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   446
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   447
};
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   448
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   449
void FileMapInfo::update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   450
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   451
  ResourceMark rm(THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   452
  jint manifest_size;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   453
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   454
  if (cpe->is_jar_file()) {
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   455
    assert(ent->is_jar(), "the shared class path entry is not a JAR file");
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   456
    char* manifest = ClassLoaderExt::read_manifest(cpe, &manifest_size, CHECK);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   457
    if (manifest != NULL) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   458
      ManifestStream* stream = new ManifestStream((u1*)manifest,
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   459
                                                  manifest_size);
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   460
      if (stream->check_is_signed()) {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 50039
diff changeset
   461
        ent->set_is_signed();
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   462
      } else {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   463
        // Copy the manifest into the shared archive
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   464
        manifest = ClassLoaderExt::read_raw_manifest(cpe, &manifest_size, CHECK);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   465
        Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   466
                                                        manifest_size,
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   467
                                                        THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   468
        char* p = (char*)(buf->data());
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   469
        memcpy(p, manifest, manifest_size);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   470
        ent->set_manifest(buf);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   471
      }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   472
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   473
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   474
}
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   475
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   476
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   477
bool FileMapInfo::validate_shared_path_table() {
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   478
  assert(UseSharedSpaces, "runtime only");
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49739
diff changeset
   479
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   480
  _validating_shared_path_table = true;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   481
  _shared_path_table = _header->_shared_path_table;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   482
  _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
   483
  _shared_path_table_size = _header->_shared_path_table_size;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   484
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   485
  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
   486
51439
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   487
  // validate the path entries up to the _max_used_path_index
0517bd2a0eda 8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived
ccheung
parents: 51070
diff changeset
   488
  for (int i=0; i < _header->_max_used_path_index + 1; i++) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   489
    if (i < module_paths_start_index) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   490
      if (shared_path(i)->validate()) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   491
        log_info(class, path)("ok");
52562
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   492
      } else {
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   493
        assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   494
        return false;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   495
      }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   496
    } else if (i >= module_paths_start_index) {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   497
      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
   498
        log_info(class, path)("ok");
52562
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   499
      } else {
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   500
        assert(!UseSharedSpaces, "UseSharedSpaces should be disabled");
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
   501
        return false;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   502
      }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   503
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   504
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   505
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
   506
  _validating_shared_path_table = false;
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   507
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   508
#if INCLUDE_JVMTI
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   509
  if (_classpath_entries_for_jvmti != NULL) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   510
    os::free(_classpath_entries_for_jvmti);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   511
  }
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   512
  size_t sz = sizeof(ClassPathEntry*) *  _shared_path_table_size;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   513
  _classpath_entries_for_jvmti = (ClassPathEntry**)os::malloc(sz, mtClass);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   514
  memset(_classpath_entries_for_jvmti, 0, sz);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   515
#endif
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
   516
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   517
  return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   518
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   519
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
bool FileMapInfo::init_from_file(int fd) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   523
  size_t sz = sizeof(FileMapHeader);
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   524
  size_t n = os::read(fd, _header, (unsigned int)sz);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   525
  if (n != sz) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    fail_continue("Unable to read the file header.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  }
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   529
  if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    fail_continue("The shared archive file has the wrong version.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  _file_offset = (long)n;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   534
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   535
  size_t info_size = _header->_paths_misc_info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   536
  _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
   537
  if (_paths_misc_info == NULL) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   538
    fail_continue("Unable to read the file header.");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   539
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   540
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   541
  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
   542
  if (n != info_size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   543
    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
   544
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   545
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   546
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   547
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   548
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   549
  size_t len = lseek(fd, 0, SEEK_END);
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   550
  CDSFileMapRegion* si = space_at(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
   551
  // 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
   552
  if (si->_file_offset > len || len - si->_file_offset < si->_used) {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   553
    fail_continue("The shared archive file has been truncated.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   554
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   555
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   556
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   557
  _file_offset += (long)n;
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   558
  SharedBaseAddress = _header->_shared_base_address;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
// Read the FileMapInfo information from the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
bool FileMapInfo::open_for_read() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  _full_path = Arguments::GetSharedArchivePath();
53911
65f2a401e0eb 8218811: replace open by os::open in hotspot coding
mbaesken
parents: 53884
diff changeset
   566
  int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  if (fd < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    if (errno == ENOENT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      // Not locating the shared archive is ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      fail_continue("Specified shared archive not found.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      fail_continue("Failed to open shared archive file (%s).",
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36364
diff changeset
   573
                    os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
// Write the FileMapInfo information to the file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
void FileMapInfo::open_for_write() {
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   587
  _full_path = Arguments::GetSharedArchivePath();
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   588
  LogMessage(cds) msg;
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   589
  if (msg.is_info()) {
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   590
    msg.info("Dumping shared data to file: ");
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   591
    msg.info("   %s", _full_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
15461
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   594
#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
   595
  chmod(_full_path, _S_IREAD | _S_IWRITE);
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   596
#endif
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   597
e3acbfdabafa 7197672: There are issues with shared data on windows
hseigel
parents: 15101
diff changeset
   598
  // 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
   599
  // allow processes that have it open continued access to the file.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  remove(_full_path);
53911
65f2a401e0eb 8218811: replace open by os::open in hotspot coding
mbaesken
parents: 53884
diff changeset
   601
  int fd = os::open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  if (fd < 0) {
28950
693ae3d5e1ff 8072694: Need errno info when CDS archive creation fails
hseigel
parents: 28023
diff changeset
   603
    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
   604
              os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  _fd = fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  _file_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  _file_open = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
// Write the header to the file, seek to the next allocation boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
void FileMapInfo::write_header() {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   615
  int info_size = ClassLoader::get_shared_paths_misc_info_size();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   616
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   617
  _header->_paths_misc_info_size = info_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   618
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   619
  align_file_position();
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   620
  write_bytes(_header, sizeof(FileMapHeader));
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   621
  write_bytes(ClassLoader::get_shared_paths_misc_info(), (size_t)info_size);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
   622
  align_file_position();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
// Dump region to file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
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
   629
                               bool read_only, bool allow_exec) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   630
  CDSFileMapRegion* si = space_at(region);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    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
   634
    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
   635
                  " 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
   636
                  region, size, p2i(base), _file_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    si->_file_offset = _file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  }
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   640
  if (HeapShared::is_heap_region(region)) {
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   641
    assert((base - (char*)CompressedOops::base()) % HeapWordSize == 0, "Sanity");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   642
    if (base != NULL) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49340
diff changeset
   643
      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
   644
    } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   645
      si->_addr._offset = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   646
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   647
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   648
    si->_addr._base = base;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   649
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  si->_used = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  si->_read_only = read_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  si->_allow_exec = allow_exec;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   653
  si->_crc = ClassLoader::crc32(0, base, (jint)size);
51070
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 50199
diff changeset
   654
  if (base != NULL) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   655
    write_bytes_aligned(base, size);
51070
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 50199
diff changeset
   656
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   659
// 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
   660
// 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
   661
// 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
   662
//
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   663
// 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
   664
// size, there is only one MemRegion in the array.
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   665
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   666
// 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
   667
// 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
   668
// 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
   669
// 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
   670
// 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
   671
// GC regions are combined into another MemRegion.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   672
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   673
// 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
   674
//   + 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
   675
//   + 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
   676
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   677
// 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
   678
// Otherwise:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   679
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   680
// "X" represented space that's occupied by heap objects.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   681
// "_" represented unused spaced in the heap region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   682
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   683
//
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   684
//    |ah0       | ah1 | ah2| ...... | ahn|
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   685
//    |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
   686
//    |<-r0->|   |<- r1 ----------------->|
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   687
//            ^^^
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   688
//             |
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   689
//             +-- gap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   690
size_t FileMapInfo::write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   691
                                               GrowableArray<ArchiveHeapOopmapInfo> *oopmaps,
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   692
                                               int first_region_id, int max_num_regions,
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   693
                                               bool print_log) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   694
  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
   695
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   696
  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
   697
  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
   698
    fail_stop("Unable to write archive heap memory regions: "
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52702
diff changeset
   699
              "number of memory regions exceeds maximum due to fragmentation. "
52702
10c6e9066819 8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents: 52674
diff changeset
   700
              "Please increase java heap size "
10c6e9066819 8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents: 52674
diff changeset
   701
              "(current MaxHeapSize is " SIZE_FORMAT ", InitialHeapSize is " SIZE_FORMAT ").",
10c6e9066819 8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents: 52674
diff changeset
   702
              MaxHeapSize, InitialHeapSize);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   703
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   704
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   705
  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
   706
  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
   707
           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
   708
           i++, arr_idx++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   709
    char* start = NULL;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   710
    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
   711
    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
   712
      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
   713
      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
   714
      total_size += size;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   715
    }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   716
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   717
    if (print_log) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   718
      log_info(cds)("Archive heap region %d " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes",
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   719
                    i, p2i(start), p2i(start + size), size);
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52402
diff changeset
   720
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   721
    write_region(i, start, size, false, false);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   722
    if (size > 0) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   723
      space_at(i)->_oopmap = oopmaps->at(arr_idx)._oopmap;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   724
      space_at(i)->_oopmap_size_in_bits = oopmaps->at(arr_idx)._oopmap_size_in_bits;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   725
    }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   726
  }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   727
  return total_size;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   728
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   729
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   732
void FileMapInfo::write_bytes(const void* buffer, size_t nbytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  if (_file_open) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   734
    size_t n = os::write(_fd, buffer, (unsigned int)nbytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    if (n != nbytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
      // It is dangerous to leave the corrupted shared archive file around,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      // close and remove the file. See bug 6372906.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      remove(_full_path);
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   740
      fail_stop("Unable to write to shared archive file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  _file_offset += nbytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
// Align file position to an allocation unit boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
void FileMapInfo::align_file_position() {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   750
  size_t new_file_offset = align_up(_file_offset,
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   751
                                         os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  if (new_file_offset != _file_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    _file_offset = new_file_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      // Seek one byte back from the target and write a byte to insure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      // that the written file is the correct length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
      _file_offset -= 1;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
   758
      if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   759
        fail_stop("Unable to seek.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      char zero = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      write_bytes(&zero, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
// Dump bytes to file -- at the current file position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   770
void FileMapInfo::write_bytes_aligned(const void* buffer, size_t nbytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  write_bytes(buffer, nbytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  align_file_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
// Close the shared archive file.  This does NOT unmap mapped regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
void FileMapInfo::close() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  if (_file_open) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    if (::close(_fd) < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      fail_stop("Unable to close the shared archive file.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    _file_open = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    _fd = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
// JVM/TI RedefineClasses() support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
// Remap the shared readonly space to shared readwrite, private.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
bool FileMapInfo::remap_shared_readonly_as_readwrite() {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   793
  int idx = MetaspaceShared::ro;
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   794
  CDSFileMapRegion* si = space_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  if (!si->_read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    // the space is already readwrite so we are done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  size_t used = si->_used;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   800
  size_t size = align_up(used, os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  }
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   804
  char *addr = region_addr(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  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
   806
                                addr, size, false /* !read_only */,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
                                si->_allow_exec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  close();
54573
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   809
  // These have to be errors because the shared region is now unmapped.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  if (base == NULL) {
54573
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   811
    log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   812
    vm_exit(1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   814
  if (base != addr) {
54573
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   815
    log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   816
    vm_exit(1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  si->_read_only = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   822
// 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
   823
ReservedSpace FileMapInfo::reserve_shared_memory() {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   824
  char* requested_addr = region_addr(0);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   825
  size_t size = FileMapInfo::core_spaces_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   826
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   827
  // 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
   828
  // other reserved memory (like the code cache).
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
   829
  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
   830
  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
   831
    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
   832
                  INTPTR_FORMAT, p2i(requested_addr));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   833
    return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   834
  }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13728
diff changeset
   835
  // 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
   836
  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
   837
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   838
  return rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   839
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
// 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
   842
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
   843
                                            "String1", "String2", "OpenArchive1", "OpenArchive2" };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   845
char* FileMapInfo::map_region(int i, char** top_ret) {
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   846
  assert(!HeapShared::is_heap_region(i), "sanity");
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
   847
  CDSFileMapRegion* si = space_at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  size_t used = si->_used;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   849
  size_t alignment = os::vm_allocation_granularity();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
   850
  size_t size = align_up(used, alignment);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   851
  char *requested_addr = region_addr(i);
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   852
54573
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   853
#ifdef _WINDOWS
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   854
  // Windows cannot remap read-only shared memory to read-write when required for
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   855
  // RedefineClasses, which is also used by JFR.  Always map windows regions as RW.
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   856
  si->_read_only = false;
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   857
#else
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   858
  // If a tool agent is in use (debugging enabled), or JFR, we must map the address space RW
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   859
  if (JvmtiExport::can_modify_any_class() || JvmtiExport::can_walk_any_space() ||
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   860
      Arguments::has_jfr_option()) {
31375
aa5ecd9a5716 8087153: EXCEPTION_ACCESS_VIOLATION when CDS RO section vanished on win32
cjplummer
parents: 31364
diff changeset
   861
    si->_read_only = false;
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   862
  }
54573
b73893f7fee3 8222379: JFR TestClassLoadEvent.java failed due to EXCEPTION_ACCESS_VIOLATION
coleenp
parents: 54340
diff changeset
   863
#endif // _WINDOWS
31332
dc17890f352d 8054386: Allow Java debugging when CDS is enabled
cjplummer
parents: 28950
diff changeset
   864
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7405
diff changeset
   865
  // map the contents of the CDS archive in this memory
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  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
   867
                              requested_addr, size, si->_read_only,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
                              si->_allow_exec);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   869
  if (base == NULL || base != requested_addr) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
   870
    fail_continue("Unable to map %s shared space at required address.", shared_region_name[i]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  }
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   873
#ifdef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14577
diff changeset
   874
  // 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
   875
  // 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
   876
  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
   877
#endif
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
   878
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   879
  if (!verify_region_checksum(i)) {
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   880
    return NULL;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   881
  }
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   882
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47991
diff changeset
   883
  *top_ret = base + size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  return base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   887
address FileMapInfo::decode_start_address(CDSFileMapRegion* spc, bool with_current_oop_encoding_mode) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   888
  if (with_current_oop_encoding_mode) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   889
    return (address)CompressedOops::decode_not_null(offset_of_space(spc));
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   890
  } else {
51720
b7bfd64e43a6 8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents: 51491
diff changeset
   891
    return (address)HeapShared::decode_from_archive(offset_of_space(spc));
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   892
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   893
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   894
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   895
static MemRegion *closed_archive_heap_ranges = NULL;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   896
static MemRegion *open_archive_heap_ranges = NULL;
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   897
static int num_closed_archive_heap_ranges = 0;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   898
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
   899
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   900
#if INCLUDE_CDS_JAVA_HEAP
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   901
bool FileMapInfo::has_heap_regions() {
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   902
  return (_header->_space[MetaspaceShared::first_closed_archive_heap_region]._used > 0);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   903
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   904
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   905
// Returns the address range of the archived heap regions computed using the
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   906
// current oop encoding mode. This range may be different than the one seen at
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   907
// dump time due to encoding mode differences. The result is used in determining
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   908
// if/how these regions should be relocated at run time.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   909
MemRegion FileMapInfo::get_heap_regions_range_with_current_oop_encoding_mode() {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   910
  address start = (address) max_uintx;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   911
  address end   = NULL;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   912
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   913
  for (int i = MetaspaceShared::first_closed_archive_heap_region;
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   914
           i <= MetaspaceShared::last_valid_region;
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   915
           i++) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   916
    CDSFileMapRegion* si = space_at(i);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   917
    size_t size = si->_used;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   918
    if (size > 0) {
51720
b7bfd64e43a6 8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents: 51491
diff changeset
   919
      address s = start_address_as_decoded_with_current_oop_encoding_mode(si);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   920
      address e = s + size;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   921
      if (start > s) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   922
        start = s;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   923
      }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   924
      if (end < e) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   925
        end = e;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   926
      }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   927
    }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   928
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   929
  assert(end != NULL, "must have at least one used heap region");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   930
  return MemRegion((HeapWord*)start, (HeapWord*)end);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   931
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   932
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   933
//
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   934
// Map the closed and open archive heap objects to the runtime java heap.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   935
//
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   936
// The shared objects are mapped at (or close to ) the java heap top in
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   937
// closed archive regions. The mapped objects contain no out-going
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   938
// references to any other java heap regions. GC does not write into the
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   939
// mapped closed archive heap region.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   940
//
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   941
// The open archive heap objects are mapped below the shared objects in
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   942
// the runtime java heap. The mapped open archive heap data only contains
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
   943
// references to the shared objects and open archive objects initially.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   944
// 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
   945
// 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
   946
// open archive objects.
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   947
void FileMapInfo::map_heap_regions_impl() {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 51823
diff changeset
   948
  if (!HeapShared::is_heap_object_archiving_allowed()) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   949
    log_info(cds)("CDS heap data is being ignored. UseG1GC, "
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   950
                  "UseCompressedOops and UseCompressedClassPointers are required.");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   951
    return;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   952
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   953
52319
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   954
  if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   955
    ShouldNotReachHere(); // CDS should have been disabled.
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   956
    // The archived objects are mapped at JVM start-up, but we don't know if
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   957
    // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   958
    // which would make the archived String or mirror objects invalid. Let's be safe and not
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   959
    // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   960
    //
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   961
    // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   962
    // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   963
    // because we won't install an archived object subgraph if the klass of any of the
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   964
    // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   965
  }
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
   966
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   967
  MemRegion heap_reserved = Universe::heap()->reserved_region();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   968
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   969
  log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   970
                max_heap_size()/M);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   971
  log_info(cds)("    narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   972
                p2i(narrow_klass_base()), narrow_klass_shift());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   973
  log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   974
                narrow_oop_mode(), p2i(narrow_oop_base()), narrow_oop_shift());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   975
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   976
  log_info(cds)("The current max heap size = " SIZE_FORMAT "M, HeapRegion::GrainBytes = " SIZE_FORMAT,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   977
                heap_reserved.byte_size()/M, HeapRegion::GrainBytes);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   978
  log_info(cds)("    narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   979
                p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift());
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   980
  log_info(cds)("    narrow_oop_mode = %d, narrow_oop_base = " PTR_FORMAT ", narrow_oop_shift = %d",
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   981
                CompressedOops::mode(), p2i(CompressedOops::base()), CompressedOops::shift());
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   982
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   983
  if (narrow_klass_base() != CompressedKlassPointers::base() ||
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   984
      narrow_klass_shift() != CompressedKlassPointers::shift()) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   985
    log_info(cds)("CDS heap data cannot be used because the archive was created with an incompatible narrow klass encoding mode.");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   986
    return;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   987
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   988
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   989
  if (narrow_oop_mode() != CompressedOops::mode() ||
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   990
      narrow_oop_base() != CompressedOops::base() ||
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54573
diff changeset
   991
      narrow_oop_shift() != CompressedOops::shift()) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   992
    log_info(cds)("CDS heap data need to be relocated because the archive was created with an incompatible oop encoding mode.");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   993
    _heap_pointers_need_patching = true;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   994
  } else {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   995
    MemRegion range = get_heap_regions_range_with_current_oop_encoding_mode();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   996
    if (!heap_reserved.contains(range)) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   997
      log_info(cds)("CDS heap data need to be relocated because");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   998
      log_info(cds)("the desired range " PTR_FORMAT " - "  PTR_FORMAT, p2i(range.start()), p2i(range.end()));
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
   999
      log_info(cds)("is outside of the heap " PTR_FORMAT " - "  PTR_FORMAT, p2i(heap_reserved.start()), p2i(heap_reserved.end()));
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1000
      _heap_pointers_need_patching = true;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1001
    }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1002
  }
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
  1003
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1004
  ptrdiff_t delta = 0;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1005
  if (_heap_pointers_need_patching) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1006
    //   dumptime heap end  ------------v
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1007
    //   [      |archived heap regions| ]         runtime heap end ------v
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1008
    //                                       [   |archived heap regions| ]
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1009
    //                                  |<-----delta-------------------->|
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1010
    //
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1011
    // At dump time, the archived heap regions were near the top of the heap.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1012
    // At run time, they may not be inside the heap, so we move them so
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1013
    // that they are now near the top of the runtime time. This can be done by
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1014
    // the simple math of adding the delta as shown above.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1015
    address dumptime_heap_end = (address)_header->_heap_reserved.end();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1016
    address runtime_heap_end = (address)heap_reserved.end();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1017
    delta = runtime_heap_end - dumptime_heap_end;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1018
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1019
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1020
  log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1021
  HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1022
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1023
  CDSFileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region);
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1024
  address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1025
  if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) {
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1026
    // Align the bottom of the closed archive heap regions at G1 region boundary.
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1027
    // This will avoid the situation where the highest open region and the lowest
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1028
    // closed region sharing the same G1 region. Otherwise we will fail to map the
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1029
    // open regions.
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1030
    size_t align = size_t(relocated_closed_heap_region_bottom) % HeapRegion::GrainBytes;
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1031
    delta -= align;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1032
    log_info(cds)("CDS heap data need to be relocated lower by a further " SIZE_FORMAT
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1033
                  " bytes to " INTX_FORMAT " to be aligned with HeapRegion::GrainBytes",
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1034
                  align, delta);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1035
    HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1036
    _heap_pointers_need_patching = true;
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1037
    relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1038
  }
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1039
  assert(is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes),
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1040
         "must be");
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1041
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1042
  // Map the closed_archive_heap regions, GC does not write into the regions.
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1043
  if (map_heap_data(&closed_archive_heap_ranges,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1044
                    MetaspaceShared::first_closed_archive_heap_region,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1045
                    MetaspaceShared::max_closed_archive_heap_region,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1046
                    &num_closed_archive_heap_ranges)) {
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1047
    HeapShared::set_closed_archive_heap_region_mapped();
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1048
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1049
    // Now, map open_archive heap regions, GC can write into the regions.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1050
    if (map_heap_data(&open_archive_heap_ranges,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1051
                      MetaspaceShared::first_open_archive_heap_region,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1052
                      MetaspaceShared::max_open_archive_heap_region,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1053
                      &num_open_archive_heap_ranges,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1054
                      true /* open */)) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 51823
diff changeset
  1055
      HeapShared::set_open_archive_heap_region_mapped();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1056
    }
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1057
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1058
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1059
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1060
void FileMapInfo::map_heap_regions() {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1061
  if (has_heap_regions()) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1062
    map_heap_regions_impl();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1063
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1064
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1065
  if (!HeapShared::closed_archive_heap_region_mapped()) {
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1066
    assert(closed_archive_heap_ranges == NULL &&
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1067
           num_closed_archive_heap_ranges == 0, "sanity");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1068
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1069
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 51823
diff changeset
  1070
  if (!HeapShared::open_archive_heap_region_mapped()) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1071
    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
  1072
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1073
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1074
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1075
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
  1076
                                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
  1077
  MemRegion * regions = new MemRegion[max];
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1078
  CDSFileMapRegion* si;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1079
  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
  1080
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1081
  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
  1082
           i < first + max; i++) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1083
    si = space_at(i);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1084
    size_t size = si->_used;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1085
    if (size > 0) {
51720
b7bfd64e43a6 8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents: 51491
diff changeset
  1086
      HeapWord* start = (HeapWord*)start_address_as_decoded_from_archive(si);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1087
      regions[region_num] = MemRegion(start, size / HeapWordSize);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1088
      region_num ++;
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1089
      log_info(cds)("Trying to map heap data: region[%d] at " INTPTR_FORMAT ", size = " SIZE_FORMAT_W(8) " bytes",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1090
                    i, p2i(start), size);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1091
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1092
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1093
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1094
  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
  1095
    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
  1096
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1097
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1098
  // 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
  1099
  if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1100
    log_info(cds)("UseSharedSpaces: Unable to allocate region, range is not within java heap.");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1101
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1102
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1103
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1104
  // 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
  1105
  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
  1106
             regions, region_num, is_open_archive)) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1107
    log_info(cds)("UseSharedSpaces: Unable to allocate region, java heap range is already in use.");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1108
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1109
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1110
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1111
  // 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
  1112
  // 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
  1113
  // already recorded.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1114
  for (int i = 0; i < region_num; i++) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1115
    si = space_at(first + i);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1116
    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
  1117
    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
  1118
                                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
  1119
                                si->_allow_exec);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1120
    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
  1121
      // dealloc the regions from java heap
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1122
      dealloc_archive_heap_regions(regions, region_num, is_open_archive);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1123
      log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1124
                    INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1125
                    p2i(addr), regions[i].byte_size());
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1126
      return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1127
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1128
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1129
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1130
  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
  1131
    // dealloc the regions from java heap
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1132
    dealloc_archive_heap_regions(regions, region_num, is_open_archive);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1133
    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
  1134
    return false;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1135
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1136
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1137
  // 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
  1138
  *heap_mem = regions;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1139
  *num = region_num;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1140
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1141
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1142
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1143
bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
52126
27df68106e57 8211956: AppCDS crashes for some uses with JRuby
jiangli
parents: 52062
diff changeset
  1144
  assert(num > 0, "sanity");
27df68106e57 8211956: AppCDS crashes for some uses with JRuby
jiangli
parents: 52062
diff changeset
  1145
  for (int i = first; i < first + num; i++) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1146
    if (!verify_region_checksum(i)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1147
      return false;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1148
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1149
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1150
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1151
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1152
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1153
void FileMapInfo::patch_archived_heap_embedded_pointers() {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1154
  if (!_heap_pointers_need_patching) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1155
    return;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1156
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1157
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1158
  patch_archived_heap_embedded_pointers(closed_archive_heap_ranges,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1159
                                        num_closed_archive_heap_ranges,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1160
                                        MetaspaceShared::first_closed_archive_heap_region);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1161
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1162
  patch_archived_heap_embedded_pointers(open_archive_heap_ranges,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1163
                                        num_open_archive_heap_ranges,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1164
                                        MetaspaceShared::first_open_archive_heap_region);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1165
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1166
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1167
void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1168
                                                        int first_region_idx) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1169
  for (int i=0; i<num_ranges; i++) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1170
    CDSFileMapRegion* si = space_at(i + first_region_idx);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1171
    HeapShared::patch_archived_heap_embedded_pointers(ranges[i], (address)si->_oopmap,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1172
                                                      si->_oopmap_size_in_bits);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1173
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1174
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1175
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1176
// This internally allocates objects using SystemDictionary::Object_klass(), so it
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1177
// must be called after the well-known classes are resolved.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1178
void FileMapInfo::fixup_mapped_heap_regions() {
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1179
  // If any closed regions were found, call the fill routine to make them parseable.
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1180
  // Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found.
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1181
  if (num_closed_archive_heap_ranges != 0) {
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1182
    assert(closed_archive_heap_ranges != NULL,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1183
           "Null closed_archive_heap_ranges array with non-zero count");
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1184
    G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges,
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1185
                                                  num_closed_archive_heap_ranges);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1186
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1187
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1188
  // 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
  1189
  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
  1190
    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
  1191
    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
  1192
                                                  num_open_archive_heap_ranges);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1193
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1194
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1195
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1196
// dealloc the archive regions from java heap
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1197
void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num, bool is_open) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1198
  if (num > 0) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1199
    assert(regions != NULL, "Null archive ranges array with non-zero count");
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1200
    G1CollectedHeap::heap()->dealloc_archive_regions(regions, num, is_open);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1201
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1202
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1203
#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
  1204
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1205
bool FileMapInfo::verify_region_checksum(int i) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1206
  if (!VerifySharedSpaces) {
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1207
    return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1208
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1209
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1210
  size_t sz = space_at(i)->_used;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1211
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1212
  if (sz == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1213
    return true; // no data
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1214
  }
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1215
  if ((HeapShared::is_closed_archive_heap_region(i) &&
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1216
       !HeapShared::closed_archive_heap_region_mapped()) ||
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1217
      (HeapShared::is_open_archive_heap_region(i) &&
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 51823
diff changeset
  1218
       !HeapShared::open_archive_heap_region_mapped())) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1219
    return true; // archived heap data is not mapped
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1220
  }
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1221
  const char* buf = region_addr(i);
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1222
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1223
  if (crc != space_at(i)->_crc) {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1224
    fail_continue("Checksum verification failed.");
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1225
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1226
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1227
  return true;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1228
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
// Unmap a memory region in the address space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
void FileMapInfo::unmap_region(int i) {
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1233
  assert(!HeapShared::is_heap_region(i), "sanity");
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1234
  CDSFileMapRegion* si = space_at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  size_t used = si->_used;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
  1236
  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
  1237
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1238
  if (used == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1239
    return;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1240
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1241
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1242
  char* addr = region_addr(i);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1243
  if (!os::unmap_memory(addr, size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    fail_stop("Unable to unmap shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
void FileMapInfo::assert_mark(bool check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  if (!check) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1250
    fail_stop("Mark mismatch while restoring from shared file.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1254
void FileMapInfo::metaspace_pointers_do(MetaspaceClosure* it) {
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1255
  it->push(&_shared_path_table);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1256
  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
  1257
    shared_path(i)->metaspace_pointers_do(it);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1258
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1259
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1260
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
FileMapInfo* FileMapInfo::_current_info = NULL;
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1263
bool FileMapInfo::_heap_pointers_need_patching = false;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1264
Array<u8>* FileMapInfo::_shared_path_table = NULL;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1265
int FileMapInfo::_shared_path_table_size = 0;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1266
size_t FileMapInfo::_shared_path_entry_size = 0x1234baad;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1267
bool FileMapInfo::_validating_shared_path_table = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
// Open the shared archive file, read and validate the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
// information (version, boot classpath, etc.).  If initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
// fails, shared spaces are disabled and the file is closed. [See
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
// fail_continue.]
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1273
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1274
// Validation of the archive is done in two steps:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1275
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1276
// [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
  1277
// [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
  1278
//     region of the archive, which is not mapped yet.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
bool FileMapInfo::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
  assert(UseSharedSpaces, "UseSharedSpaces expected.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
52319
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1282
  if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1283
    // CDS assumes that no classes resolved in SystemDictionary::resolve_well_known_classes
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1284
    // are replaced at runtime by JVMTI ClassFileLoadHook. All of those classes are resolved
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1285
    // during the JVMTI "early" stage, so we can still use CDS if
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1286
    // JvmtiExport::has_early_class_hook_env() is false.
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1287
    FileMapInfo::fail_continue("CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1288
    return false;
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1289
  }
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52314
diff changeset
  1290
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  if (!open_for_read()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  init_from_file(_fd);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1296
  if (!validate_header()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1302
char* FileMapInfo::region_addr(int idx) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1303
  CDSFileMapRegion* si = space_at(idx);
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1304
  if (HeapShared::is_heap_region(idx)) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1305
    assert(DumpSharedSpaces, "The following doesn't work at runtime");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1306
    return si->_used > 0 ?
51720
b7bfd64e43a6 8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents: 51491
diff changeset
  1307
          (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1308
  } else {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1309
    return si->_addr._base;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1310
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1311
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 31332
diff changeset
  1312
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1313
int FileMapHeader::compute_crc() {
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1314
  char* start = (char*)this;
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1315
  // start computing from the field after _crc
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1316
  char* buf = (char*)&_crc + sizeof(_crc);
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1317
  size_t sz = sizeof(FileMapHeader) - (buf - start);
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1318
  int crc = ClassLoader::crc32(0, buf, (jint)sz);
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1319
  return crc;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1320
}
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1321
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49592
diff changeset
  1322
// This function should only be called during run time with UseSharedSpaces enabled.
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1323
bool FileMapHeader::validate() {
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1324
  if (VerifySharedSpaces && compute_crc() != _crc) {
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1325
    FileMapInfo::fail_continue("Header checksum verification failed.");
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1326
    return false;
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1327
  }
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26296
diff changeset
  1328
40013
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1329
  if (!Arguments::has_jimage()) {
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1330
    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
  1331
    return false;
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1332
  }
943cf01a6b82 8154239: -Xbootclasspath/a breaks exploded build
lfoltan
parents: 38207
diff changeset
  1333
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1334
  if (_version != CURRENT_CDS_ARCHIVE_VERSION) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1335
    FileMapInfo::fail_continue("The shared archive file is the wrong version.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
  }
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1338
  if (_magic != CDS_ARCHIVE_MAGIC) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1339
    FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
  }
14577
fd68d810d86b 6924920: Class Data Sharing limit on the java version string can create failures
hseigel
parents: 14120
diff changeset
  1342
  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
  1343
  get_header_version(header_version);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1344
  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
  1345
    log_info(class, path)("expected: %s", header_version);
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
  1346
    log_info(class, path)("actual:   %s", _jvm_ident);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1347
    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
  1348
                  " version or build of HotSpot");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1351
  if (_obj_alignment != ObjectAlignmentInBytes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1352
    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
  1353
                  " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1354
                  _obj_alignment, ObjectAlignmentInBytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  }
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1357
  if (_compact_strings != CompactStrings) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1358
    FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1359
                  " does not equal the current CompactStrings setting (%s).",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1360
                  _compact_strings ? "enabled" : "disabled",
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1361
                  CompactStrings   ? "enabled" : "disabled");
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1362
    return false;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
  1363
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1365
  // This must be done after header validation because it might change the
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1366
  // header data
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1367
  const char* prop = Arguments::get_property("java.system.class.loader");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1368
  if (prop != NULL) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1369
    warning("Archived non-system classes are disabled because the "
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1370
            "java.system.class.loader property is specified (value = \"%s\"). "
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1371
            "To use archived non-system classes, this property must not be set", prop);
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1372
    _has_platform_or_app_classes = false;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1373
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1374
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1375
  // For backwards compatibility, we don't check the verification setting
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1376
  // if the archive only contains system classes.
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1377
  if (_has_platform_or_app_classes &&
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1378
      ((!_verify_local && BytecodeVerificationLocal) ||
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1379
       (!_verify_remote && BytecodeVerificationRemote))) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1380
    FileMapInfo::fail_continue("The shared archive file was created with less restrictive "
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1381
                  "verification setting than the current setting.");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1382
    return false;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1383
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
  1384
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1385
  // Java agents are allowed during run time. Therefore, the following condition is not
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1386
  // checked: (!_allow_archiving_with_java_agent && AllowArchivingWithJavaAgent)
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1387
  // Note: _allow_archiving_with_java_agent is set in the shared archive during dump time
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1388
  // while AllowArchivingWithJavaAgent is set during the current run.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1389
  if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1390
    FileMapInfo::fail_continue("The setting of the AllowArchivingWithJavaAgent is different "
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1391
                               "from the setting in the shared archive.");
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1392
    return false;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1393
  }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1394
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1395
  if (_allow_archiving_with_java_agent) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1396
    warning("This archive was created with AllowArchivingWithJavaAgent. It should be used "
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1397
            "for testing purposes only and should not be used in a production environment");
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1398
  }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1399
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1403
bool FileMapInfo::validate_header() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1404
  bool status = _header->validate();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1405
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1406
  if (status) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1407
    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
  1408
      if (!PrintSharedArchiveAndExit) {
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38108
diff changeset
  1409
        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
  1410
        status = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1411
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1412
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1413
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1414
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1415
  if (_paths_misc_info != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27025
diff changeset
  1416
    FREE_C_HEAP_ARRAY(char, _paths_misc_info);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1417
    _paths_misc_info = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1418
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1419
  return status;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1420
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25715
diff changeset
  1421
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1422
// 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
  1423
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
  1424
  assert(idx == MetaspaceShared::ro ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1425
         idx == MetaspaceShared::rw ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1426
         idx == MetaspaceShared::mc ||
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1427
         idx == MetaspaceShared::md, "invalid region index");
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1428
  char* base = region_addr(idx);
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51439
diff changeset
  1429
  if (p >= base && p < base + space_at(idx)->_used) {
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1430
    return true;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1431
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1432
  return false;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1433
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37179
diff changeset
  1434
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1435
// Unmap mapped regions of shared space.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1436
void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
52314
e53af5fa0dae 8212205: VM asserts after CDS archive has been unmapped
iklam
parents: 52126
diff changeset
  1437
  MetaspaceObj::set_shared_metaspace_range(NULL, NULL);
e53af5fa0dae 8212205: VM asserts after CDS archive has been unmapped
iklam
parents: 52126
diff changeset
  1438
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1439
  FileMapInfo *map_info = FileMapInfo::current_info();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1440
  if (map_info) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1441
    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
  1442
    for (int i = 0; i < MetaspaceShared::num_non_heap_spaces; i++) {
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1443
      if (!HeapShared::is_heap_region(i)) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1444
        char *addr = map_info->region_addr(i);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1445
        if (addr != NULL) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1446
          map_info->unmap_region(i);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1447
          map_info->space_at(i)->_addr._base = NULL;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51480
diff changeset
  1448
        }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1449
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1450
    }
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1451
    // 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
  1452
    // 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
  1453
    map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1454
                                           num_open_archive_heap_ranges,
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1455
                                           true);
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52319
diff changeset
  1456
    map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
52674
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1457
                                           num_closed_archive_heap_ranges,
c9325aa887da 8214118: HeapRegions marked as archive even if CDS mapping fails
sjohanss
parents: 52596
diff changeset
  1458
                                           false);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1459
  } else if (DumpSharedSpaces) {
26296
fd6180a0e0ab 8055754: filemap.cpp does not compile with clang
sla
parents: 26135
diff changeset
  1460
    fail_stop("%s", msg);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1461
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18483
diff changeset
  1462
}
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1463
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1464
#if INCLUDE_JVMTI
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1465
ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = NULL;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1466
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1467
ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1468
  ClassPathEntry* ent = _classpath_entries_for_jvmti[i];
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1469
  if (ent == NULL) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1470
    if (i == 0) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1471
      ent = ClassLoader:: get_jrt_entry();
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1472
      assert(ent != NULL, "must be");
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1473
    } else {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1474
      SharedClassPathEntry* scpe = shared_path(i);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1475
      assert(scpe->is_jar(), "must be"); // other types of scpe will not produce archived classes
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1476
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1477
      const char* path = scpe->name();
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1478
      struct stat st;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1479
      if (os::stat(path, &st) != 0) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1480
        char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); ;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1481
        jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1482
        THROW_MSG_(vmSymbols::java_io_IOException(), msg, NULL);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1483
      } else {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1484
        ent = ClassLoader::create_class_path_entry(path, &st, /*throw_exception=*/true, false, CHECK_NULL);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1485
      }
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1486
    }
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1487
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1488
    MutexLocker mu(CDSClassFileStream_lock, THREAD);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1489
    if (_classpath_entries_for_jvmti[i] == NULL) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1490
      _classpath_entries_for_jvmti[i] = ent;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1491
    } else {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1492
      // Another thread has beat me to creating this entry
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1493
      delete ent;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1494
      ent = _classpath_entries_for_jvmti[i];
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1495
    }
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1496
  }
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1497
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1498
  return ent;
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1499
}
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1500
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1501
ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, Handle class_loader, TRAPS) {
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1502
  int path_index = ik->shared_classpath_index();
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1503
  assert(path_index >= 0, "should be called for shared built-in classes only");
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1504
  assert(path_index < (int)_shared_path_table_size, "sanity");
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1505
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1506
  ClassPathEntry* cpe = get_classpath_entry_for_jvmti(path_index, CHECK_NULL);
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1507
  assert(cpe != NULL, "must be");
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1508
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1509
  Symbol* name = ik->name();
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1510
  const char* const class_name = name->as_C_string();
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1511
  const char* const file_name = ClassLoader::file_name_for_class_name(class_name,
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1512
                                                                      name->utf8_length());
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1513
  ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1514
  ClassFileStream* cfs = cpe->open_stream_for_loader(file_name, loader_data, THREAD);
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1515
  assert(cfs != NULL, "must be able to read the classfile data of shared classes for built-in loaders.");
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1516
  log_debug(cds, jvmti)("classfile data for %s [%d: %s] = %d bytes", class_name, path_index,
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1517
                        cfs->source(), cfs->length());
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53911
diff changeset
  1518
  return cfs;
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1519
}
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1520
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 52811
diff changeset
  1521
#endif