src/hotspot/share/memory/metaspaceShared.cpp
author coleenp
Fri, 31 Aug 2018 07:03:46 -0400
changeset 51608 625a5bdde0c5
parent 51554 5b0d86499960
child 51674 d7dcaacb95dd
permissions -rw-r--r--
8210155: Lock ClassLoaderDataGraph Summary: In preparation for concurrent class unloading. Reviewed-by: hseigel, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47679
diff changeset
    26
#include "jvm.h"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    27
#include "classfile/classListParser.hpp"
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    28
#include "classfile/classLoaderExt.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "classfile/dictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "classfile/loaderConstraints.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "classfile/placeholders.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "classfile/symbolTable.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46625
diff changeset
    33
#include "classfile/stringTable.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "classfile/systemDictionary.hpp"
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
    35
#include "classfile/systemDictionaryShared.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "code/codeCache.hpp"
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
    37
#include "interpreter/bytecodeStream.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    38
#include "interpreter/bytecodes.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    39
#include "logging/log.hpp"
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    40
#include "logging/logMessage.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "memory/filemap.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
    42
#include "memory/heapShared.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
#include "memory/metaspace.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
    44
#include "memory/metaspaceClosure.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    45
#include "memory/metaspaceShared.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37179
diff changeset
    46
#include "memory/resourceArea.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    47
#include "oops/compressedOops.inline.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    48
#include "oops/instanceClassLoaderKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    49
#include "oops/instanceMirrorKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    50
#include "oops/instanceRefKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    51
#include "oops/objArrayKlass.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
#include "oops/objArrayOop.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
#include "oops/oop.inline.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    54
#include "oops/typeArrayKlass.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    55
#include "prims/jvmtiRedefineClasses.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
    56
#include "runtime/handles.inline.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    57
#include "runtime/os.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49592
diff changeset
    58
#include "runtime/safepointVerifiers.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    59
#include "runtime/signature.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
    60
#include "runtime/timerTrace.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    61
#include "runtime/vmThread.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
#include "runtime/vm_operations.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    63
#include "utilities/align.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
    64
#include "utilities/bitMap.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    65
#include "utilities/defaultStream.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    66
#include "utilities/hashtable.inline.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49931
diff changeset
    67
#if INCLUDE_G1GC
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    68
#include "gc/g1/g1Allocator.inline.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    69
#include "gc/g1/g1CollectedHeap.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    70
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    72
ReservedSpace MetaspaceShared::_shared_rs;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    73
VirtualSpace MetaspaceShared::_shared_vs;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    74
MetaspaceSharedStats MetaspaceShared::_stats;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    75
bool MetaspaceShared::_has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    76
bool MetaspaceShared::_archive_loading_failed = false;
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
    77
bool MetaspaceShared::_remapped_readwrite = false;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    78
bool MetaspaceShared::_open_archive_heap_region_mapped = false;
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
    79
address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
    80
size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    81
size_t MetaspaceShared::_core_spaces_size = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    82
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    83
// The CDS archive is divided into the following regions:
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    84
//     mc  - misc code (the method entry trampolines)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    85
//     rw  - read-write metadata
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    86
//     ro  - read-only metadata and read-only tables
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    87
//     md  - misc data (the c++ vtables)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    88
//     od  - optional data (original class files)
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    89
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    90
//     s0  - shared strings(closed archive heap space) #0
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    91
//     s1  - shared strings(closed archive heap space) #1 (may be empty)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    92
//     oa0 - open archive heap space #0
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    93
//     oa1 - open archive heap space #1 (may be empty)
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    94
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    95
// The mc, rw, ro, md and od regions are linearly allocated, starting from
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    96
// SharedBaseAddress, in the order of mc->rw->ro->md->od. The size of these 5 regions
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    97
// are page-aligned, and there's no gap between any consecutive regions.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    98
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    99
// These 5 regions are populated in the following steps:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   100
// [1] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   101
//     temporarily allocated outside of the shared regions. Only the method entry
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   102
//     trampolines are written into the mc region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   103
// [2] ArchiveCompactor copies RW metadata into the rw region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   104
// [3] ArchiveCompactor copies RO metadata into the ro region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   105
// [4] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   106
//     are copied into the ro region as read-only tables.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   107
// [5] C++ vtables are copied into the md region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   108
// [6] Original class files are copied into the od region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   109
//
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   110
// The s0/s1 and oa0/oa1 regions are populated inside MetaspaceShared::dump_java_heap_objects.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   111
// Their layout is independent of the other 5 regions.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   112
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   113
class DumpRegion {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   114
private:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   115
  const char* _name;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   116
  char* _base;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   117
  char* _top;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   118
  char* _end;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   119
  bool _is_packed;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   120
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   121
  char* expand_top_to(char* newtop) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   122
    assert(is_allocatable(), "must be initialized and not packed");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   123
    assert(newtop >= _top, "must not grow backwards");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   124
    if (newtop > _end) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   125
      MetaspaceShared::report_out_of_space(_name, newtop - _top);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   126
      ShouldNotReachHere();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   127
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   128
    MetaspaceShared::commit_shared_space_to(newtop);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   129
    _top = newtop;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   130
    return _top;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   131
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   132
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   133
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   134
  DumpRegion(const char* name) : _name(name), _base(NULL), _top(NULL), _end(NULL), _is_packed(false) {}
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   135
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   136
  char* allocate(size_t num_bytes, size_t alignment=BytesPerWord) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   137
    char* p = (char*)align_up(_top, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   138
    char* newtop = p + align_up(num_bytes, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   139
    expand_top_to(newtop);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   140
    memset(p, 0, newtop - p);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   141
    return p;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   142
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   143
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   144
  void append_intptr_t(intptr_t n) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   145
    assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   146
    intptr_t *p = (intptr_t*)_top;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   147
    char* newtop = _top + sizeof(intptr_t);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   148
    expand_top_to(newtop);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   149
    *p = n;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   150
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   151
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   152
  char* base()      const { return _base;        }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   153
  char* top()       const { return _top;         }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   154
  char* end()       const { return _end;         }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   155
  size_t reserved() const { return _end - _base; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   156
  size_t used()     const { return _top - _base; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   157
  bool is_packed()  const { return _is_packed;   }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   158
  bool is_allocatable() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   159
    return !is_packed() && _base != NULL;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   160
  }
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   161
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   162
  void print(size_t total_bytes) const {
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
   163
    tty->print_cr("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT,
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
   164
                  _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()), p2i(_base));
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   165
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   166
  void print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   167
    tty->print("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   168
               _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   169
    if (strcmp(_name, failing_region) == 0) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   170
      tty->print_cr(" required = %d", int(needed_bytes));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   171
    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   172
      tty->cr();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   173
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   174
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   175
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   176
  void init(const ReservedSpace* rs) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   177
    _base = _top = rs->base();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   178
    _end = rs->end();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   179
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   180
  void init(char* b, char* t, char* e) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   181
    _base = b;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   182
    _top = t;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   183
    _end = e;
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   184
  }
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   185
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   186
  void pack(DumpRegion* next = NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   187
    assert(!is_packed(), "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   188
    _end = (char*)align_up(_top, Metaspace::reserve_alignment());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   189
    _is_packed = true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   190
    if (next != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   191
      next->_base = next->_top = this->_end;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   192
      next->_end = MetaspaceShared::shared_rs()->end();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   193
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   194
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   195
  bool contains(char* p) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   196
    return base() <= p && p < top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   197
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   198
};
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   199
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   200
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   201
DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"), _od_region("od");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   202
size_t _total_string_region_size = 0, _total_open_archive_region_size = 0;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   203
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   204
char* MetaspaceShared::misc_code_space_alloc(size_t num_bytes) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   205
  return _mc_region.allocate(num_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   206
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   207
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   208
char* MetaspaceShared::read_only_space_alloc(size_t num_bytes) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   209
  return _ro_region.allocate(num_bytes);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   210
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   211
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
   212
char* MetaspaceShared::read_only_space_top() {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
   213
  return _ro_region.top();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
   214
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
   215
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   216
void MetaspaceShared::initialize_runtime_shared_and_meta_spaces() {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   217
  assert(UseSharedSpaces, "Must be called when UseSharedSpaces is enabled");
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   218
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   219
  // If using shared space, open the file that contains the shared space
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   220
  // and map in the memory before initializing the rest of metaspace (so
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   221
  // the addresses don't conflict)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   222
  address cds_address = NULL;
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   223
  FileMapInfo* mapinfo = new FileMapInfo();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   224
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   225
  // Open the shared archive file, read and validate the header. If
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   226
  // initialization fails, shared spaces [UseSharedSpaces] are
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   227
  // disabled and the file is closed.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   228
  // Map in spaces now also
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   229
  if (mapinfo->initialize() && map_shared_spaces(mapinfo)) {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   230
    size_t cds_total = core_spaces_size();
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
   231
    cds_address = (address)mapinfo->region_addr(0);
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   232
#ifdef _LP64
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   233
    if (Metaspace::using_class_space()) {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   234
      char* cds_end = (char*)(cds_address + cds_total);
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   235
      cds_end = (char *)align_up(cds_end, Metaspace::reserve_alignment());
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   236
      // If UseCompressedClassPointers is set then allocate the metaspace area
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   237
      // above the heap and above the CDS area (if it exists).
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   238
      Metaspace::allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   239
      // map_heap_regions() compares the current narrow oop and klass encodings
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   240
      // with the archived ones, so it must be done after all encodings are determined.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   241
      mapinfo->map_heap_regions();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   242
    }
49481
8d02d496e785 8193266: AArch64: TestOptionsWithRanges.java SIGSEGV
smonteith
parents: 49480
diff changeset
   243
    Universe::set_narrow_klass_range(CompressedClassSpaceSize);
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   244
#endif // _LP64
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   245
  } else {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   246
    assert(!mapinfo->is_open() && !UseSharedSpaces,
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   247
           "archive file not closed or shared spaces not disabled.");
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   248
  }
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   249
}
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   250
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   251
void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   252
  assert(DumpSharedSpaces, "should be called for dump time only");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   253
  const size_t reserve_alignment = Metaspace::reserve_alignment();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   254
  bool large_pages = false; // No large pages when dumping the CDS archive.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   255
  char* shared_base = (char*)align_up((char*)SharedBaseAddress, reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   256
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   257
#ifdef _LP64
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   258
  // On 64-bit VM, the heap and class space layout will be the same as if
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   259
  // you're running in -Xshare:on mode:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   260
  //
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   261
  //                              +-- SharedBaseAddress (default = 0x800000000)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   262
  //                              v
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   263
  // +-..---------+---------+ ... +----+----+----+----+----+---------------+
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   264
  // |    Heap    | Archive |     | MC | RW | RO | MD | OD | class space   |
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   265
  // +-..---------+---------+ ... +----+----+----+----+----+---------------+
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   266
  // |<--   MaxHeapSize  -->|     |<-- UnscaledClassSpaceMax = 4GB ------->|
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   267
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   268
  const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   269
  const size_t cds_total = align_down(UnscaledClassSpaceMax, reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   270
#else
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   271
  // We don't support archives larger than 256MB on 32-bit due to limited virtual address space.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   272
  size_t cds_total = align_down(256*M, reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   273
#endif
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   274
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   275
  // First try to reserve the space at the specified SharedBaseAddress.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   276
  _shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages, shared_base);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   277
  if (_shared_rs.is_reserved()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   278
    assert(shared_base == 0 || _shared_rs.base() == shared_base, "should match");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   279
  } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   280
    // Get a mmap region anywhere if the SharedBaseAddress fails.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   281
    _shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   282
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   283
  if (!_shared_rs.is_reserved()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   284
    vm_exit_during_initialization("Unable to reserve memory for shared space",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   285
                                  err_msg(SIZE_FORMAT " bytes.", cds_total));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   286
  }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   287
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   288
#ifdef _LP64
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   289
  // During dump time, we allocate 4GB (UnscaledClassSpaceMax) of space and split it up:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   290
  // + The upper 1 GB is used as the "temporary compressed class space" -- preload_classes()
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   291
  //   will store Klasses into this space.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   292
  // + The lower 3 GB is used for the archive -- when preload_classes() is done,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   293
  //   ArchiveCompactor will copy the class metadata into this space, first the RW parts,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   294
  //   then the RO parts.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   295
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   296
  assert(UseCompressedOops && UseCompressedClassPointers,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   297
      "UseCompressedOops and UseCompressedClassPointers must be set");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   298
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   299
  size_t max_archive_size = align_down(cds_total * 3 / 4, reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   300
  ReservedSpace tmp_class_space = _shared_rs.last_part(max_archive_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   301
  CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   302
  _shared_rs = _shared_rs.first_part(max_archive_size);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   303
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   304
  // Set up compress class pointers.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   305
  Universe::set_narrow_klass_base((address)_shared_rs.base());
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   306
  // Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   307
  // with AOT.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   308
  Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
49481
8d02d496e785 8193266: AArch64: TestOptionsWithRanges.java SIGSEGV
smonteith
parents: 49480
diff changeset
   309
  // Set the range of klass addresses to 4GB.
8d02d496e785 8193266: AArch64: TestOptionsWithRanges.java SIGSEGV
smonteith
parents: 49480
diff changeset
   310
  Universe::set_narrow_klass_range(cds_total);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   311
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   312
  Metaspace::initialize_class_space(tmp_class_space);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
   313
  log_info(cds)("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   314
                p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   315
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
   316
  log_info(cds)("Allocated temporary class space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   317
                CompressedClassSpaceSize, p2i(tmp_class_space.base()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   318
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   319
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   320
  // Start with 0 committed bytes. The memory will be committed as needed by
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   321
  // MetaspaceShared::commit_shared_space_to().
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   322
  if (!_shared_vs.initialize(_shared_rs, 0)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   323
    vm_exit_during_initialization("Unable to allocate memory for shared space");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   324
  }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   325
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   326
  _mc_region.init(&_shared_rs);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   327
  tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   328
                _shared_rs.size(), p2i(_shared_rs.base()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   329
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   330
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   331
// Called by universe_post_init()
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   332
void MetaspaceShared::post_initialize(TRAPS) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   333
  if (UseSharedSpaces) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   334
    int size = FileMapInfo::get_number_of_shared_paths();
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   335
    if (size > 0) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   336
      SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);
51477
e77d7687c831 8209657: Refactor filemap.hpp to simplify integration with Serviceability Agent
iklam
parents: 51444
diff changeset
   337
      FileMapHeader* header = FileMapInfo::current_info()->header();
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   338
      ClassLoaderExt::init_paths_start_index(header->_app_class_paths_start_index);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   339
      ClassLoaderExt::init_app_module_paths_start_index(header->_app_module_paths_start_index);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   340
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   341
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   342
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   343
  if (DumpSharedSpaces) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   344
    if (SharedArchiveConfigFile) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   345
      read_extra_data(SharedArchiveConfigFile, THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   346
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   347
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   348
}
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   349
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   350
void MetaspaceShared::read_extra_data(const char* filename, TRAPS) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   351
  HashtableTextDump reader(filename);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   352
  reader.check_version("VERSION: 1.0");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   353
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   354
  while (reader.remain() > 0) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   355
    int utf8_length;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   356
    int prefix_type = reader.scan_prefix(&utf8_length);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   357
    ResourceMark rm(THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   358
    char* utf8_buffer = NEW_RESOURCE_ARRAY(char, utf8_length);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   359
    reader.get_utf8(utf8_buffer, utf8_length);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   360
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   361
    if (prefix_type == HashtableTextDump::SymbolPrefix) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   362
      SymbolTable::new_symbol(utf8_buffer, utf8_length, THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   363
    } else{
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   364
      assert(prefix_type == HashtableTextDump::StringPrefix, "Sanity");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   365
      utf8_buffer[utf8_length] = '\0';
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   366
      oop s = StringTable::intern(utf8_buffer, THREAD);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   367
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   368
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   369
}
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   370
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   371
void MetaspaceShared::commit_shared_space_to(char* newtop) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   372
  assert(DumpSharedSpaces, "dump-time only");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   373
  char* base = _shared_rs.base();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   374
  size_t need_committed_size = newtop - base;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   375
  size_t has_committed_size = _shared_vs.committed_size();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   376
  if (need_committed_size < has_committed_size) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   377
    return;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   378
  }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   379
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   380
  size_t min_bytes = need_committed_size - has_committed_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   381
  size_t preferred_bytes = 1 * M;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   382
  size_t uncommitted = _shared_vs.reserved_size() - has_committed_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   383
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   384
  size_t commit = MAX2(min_bytes, preferred_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   385
  assert(commit <= uncommitted, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   386
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   387
  bool result = _shared_vs.expand_by(commit, false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   388
  if (!result) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   389
    vm_exit_during_initialization(err_msg("Failed to expand shared space to " SIZE_FORMAT " bytes",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   390
                                          need_committed_size));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   391
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   392
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   393
  log_info(cds)("Expanding shared spaces by " SIZE_FORMAT_W(7) " bytes [total " SIZE_FORMAT_W(9)  " bytes ending at %p]",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   394
                commit, _shared_vs.actual_committed_size(), _shared_vs.high());
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   395
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   396
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   397
// Read/write a data stream for restoring/preserving metadata pointers and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   398
// miscellaneous data from/to the shared archive file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   399
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   400
void MetaspaceShared::serialize(SerializeClosure* soc) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   401
  int tag = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   402
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   403
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   404
  // Verify the sizes of various metadata in the system.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   405
  soc->do_tag(sizeof(Method));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   406
  soc->do_tag(sizeof(ConstMethod));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   407
  soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   408
  soc->do_tag(sizeof(ConstantPool));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   409
  soc->do_tag(sizeof(ConstantPoolCache));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   410
  soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   411
  soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   412
  soc->do_tag(sizeof(Symbol));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   413
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   414
  // Dump/restore miscellaneous metadata.
51554
5b0d86499960 8209958: Clean up duplicate basic array type statics in Universe
coleenp
parents: 51491
diff changeset
   415
  Universe::serialize(soc);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   416
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   417
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   418
  // Dump/restore references to commonly used names and signatures.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   419
  vmSymbols::serialize(soc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   420
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   421
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   422
  // Dump/restore the symbol and string tables
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   423
  SymbolTable::serialize(soc);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   424
  StringTable::serialize(soc);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   425
  soc->do_tag(--tag);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   426
51417
b08c2a94cce1 8206115: Use shared macros for JavaClasses::compute_offsets and MetaspaceShared::serialize_well_known_classes
iklam
parents: 51371
diff changeset
   427
  JavaClasses::serialize_offsets(soc);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
   428
  InstanceMirrorKlass::serialize_offsets(soc);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   429
  soc->do_tag(--tag);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   430
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   431
  soc->do_tag(666);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   432
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   433
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   434
address MetaspaceShared::cds_i2i_entry_code_buffers(size_t total_size) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   435
  if (DumpSharedSpaces) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   436
    if (_cds_i2i_entry_code_buffers == NULL) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   437
      _cds_i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   438
      _cds_i2i_entry_code_buffers_size = total_size;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   439
    }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   440
  } else if (UseSharedSpaces) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   441
    assert(_cds_i2i_entry_code_buffers != NULL, "must already been initialized");
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   442
  } else {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   443
    return NULL;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   444
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   445
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   446
  assert(_cds_i2i_entry_code_buffers_size == total_size, "must not change");
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   447
  return _cds_i2i_entry_code_buffers;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   448
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   449
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   450
// CDS code for dumping shared archive.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   451
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   452
// Global object for holding classes that have been loaded.  Since this
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   453
// is run at a safepoint just before exit, this is the entire set of classes.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   454
static GrowableArray<Klass*>* _global_klass_objects;
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   455
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   456
static void collect_array_classes(Klass* k) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   457
  _global_klass_objects->append_if_missing(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   458
  if (k->is_array_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   459
    // Add in the array classes too
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   460
    ArrayKlass* ak = ArrayKlass::cast(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   461
    Klass* h = ak->higher_dimension();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   462
    if (h != NULL) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   463
      h->array_klasses_do(collect_array_classes);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   464
    }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   465
  }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   466
}
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   467
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   468
class CollectClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   469
  void do_klass(Klass* k) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   470
    if (!(k->is_instance_klass() && InstanceKlass::cast(k)->is_in_error_state())) {
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   471
      if (k->is_instance_klass() && InstanceKlass::cast(k)->signers() != NULL) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   472
        // Mark any class with signers and don't add to the _global_klass_objects
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   473
        k->set_has_signer_and_not_archived();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   474
      } else {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   475
        _global_klass_objects->append_if_missing(k);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   476
      }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   477
    }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   478
    if (k->is_array_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   479
      // Add in the array classes too
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   480
      ArrayKlass* ak = ArrayKlass::cast(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   481
      Klass* h = ak->higher_dimension();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   482
      if (h != NULL) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   483
        h->array_klasses_do(collect_array_classes);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   484
      }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   485
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   486
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   487
};
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   488
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   489
static void remove_unshareable_in_classes() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   490
  for (int i = 0; i < _global_klass_objects->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   491
    Klass* k = _global_klass_objects->at(i);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   492
    if (!k->is_objArray_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   493
      // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   494
      // on their array classes.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   495
      assert(k->is_instance_klass() || k->is_typeArray_klass(), "must be");
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   496
      k->remove_unshareable_info();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   497
    }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   498
  }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   499
}
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   500
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   501
static void remove_java_mirror_in_classes() {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   502
  for (int i = 0; i < _global_klass_objects->length(); i++) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   503
    Klass* k = _global_klass_objects->at(i);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   504
    if (!k->is_objArray_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   505
      // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   506
      // on their array classes.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   507
      assert(k->is_instance_klass() || k->is_typeArray_klass(), "must be");
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   508
      k->remove_java_mirror();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   509
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   511
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   512
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   513
static void clear_basic_type_mirrors() {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   514
  assert(!MetaspaceShared::is_heap_object_archiving_allowed(), "Sanity");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   515
  Universe::set_int_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   516
  Universe::set_float_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   517
  Universe::set_double_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   518
  Universe::set_byte_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   519
  Universe::set_bool_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   520
  Universe::set_char_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   521
  Universe::set_long_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   522
  Universe::set_short_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   523
  Universe::set_void_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   524
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   525
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   526
static void rewrite_nofast_bytecode(Method* method) {
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   527
  BytecodeStream bcs(method);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   528
  while (!bcs.is_last_bytecode()) {
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   529
    Bytecodes::Code opcode = bcs.next();
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   530
    switch (opcode) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   531
    case Bytecodes::_getfield:      *bcs.bcp() = Bytecodes::_nofast_getfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   532
    case Bytecodes::_putfield:      *bcs.bcp() = Bytecodes::_nofast_putfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   533
    case Bytecodes::_aload_0:       *bcs.bcp() = Bytecodes::_nofast_aload_0;       break;
38943
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   534
    case Bytecodes::_iload: {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   535
      if (!bcs.is_wide()) {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   536
        *bcs.bcp() = Bytecodes::_nofast_iload;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   537
      }
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   538
      break;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   539
    }
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   540
    default: break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   541
    }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   542
  }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   543
}
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   544
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   545
// Walk all methods in the class list to ensure that they won't be modified at
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   546
// run time. This includes:
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   547
// [1] Rewrite all bytecodes as needed, so that the ConstMethod* will not be modified
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   548
//     at run time by RewriteBytecodes/RewriteFrequentPairs
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   549
// [2] Assign a fingerprint, so one doesn't need to be assigned at run-time.
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   550
static void rewrite_nofast_bytecodes_and_calculate_fingerprints() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   551
  for (int i = 0; i < _global_klass_objects->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   552
    Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   553
    if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   554
      InstanceKlass* ik = InstanceKlass::cast(k);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   555
      for (int i = 0; i < ik->methods()->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   556
        Method* m = ik->methods()->at(i);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   557
        rewrite_nofast_bytecode(m);
20059
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   558
        Fingerprinter fp(m);
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   559
        // The side effect of this call sets method's fingerprint field.
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   560
        fp.fingerprint();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   561
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   562
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   563
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   564
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   565
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   566
static void relocate_cached_class_file() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   567
  for (int i = 0; i < _global_klass_objects->length(); i++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   568
    Klass* k = _global_klass_objects->at(i);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   569
    if (k->is_instance_klass()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   570
      InstanceKlass* ik = InstanceKlass::cast(k);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   571
      JvmtiCachedClassFileData* p = ik->get_archived_class_data();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   572
      if (p != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   573
        int size = offset_of(JvmtiCachedClassFileData, data) + p->length;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   574
        JvmtiCachedClassFileData* q = (JvmtiCachedClassFileData*)_od_region.allocate(size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   575
        q->length = p->length;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   576
        memcpy(q->data, p->data, p->length);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   577
        ik->set_archived_class_data(q);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   578
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   579
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   580
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   581
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   582
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   583
NOT_PRODUCT(
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
   584
static void assert_not_unsafe_anonymous_class(InstanceKlass* k) {
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
   585
  assert(!(k->is_unsafe_anonymous()), "cannot archive unsafe anonymous classes");
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   586
}
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   587
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
   588
// Unsafe anonymous classes are not stored inside any dictionaries.
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
   589
static void assert_no_unsafe_anonymous_classes_in_dictionaries() {
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
   590
  ClassLoaderDataGraph::dictionary_classes_do(assert_not_unsafe_anonymous_class);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   591
})
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   592
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   593
// Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   594
// (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   595
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   596
// Addresses of the vtables and the methods may be different across JVM runs,
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   597
// if libjvm.so is dynamically loaded at a different base address.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   598
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   599
// To ensure that the Metadata objects in the CDS archive always have the correct vtable:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   600
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   601
// + at dump time:  we redirect the _vptr to point to our own vtables inside
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   602
//                  the CDS image
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   603
// + at run time:   we clone the actual contents of the vtables from libjvm.so
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   604
//                  into our own tables.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   605
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   606
// Currently, the archive contain ONLY the following types of objects that have C++ vtables.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   607
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   608
  f(ConstantPool) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   609
  f(InstanceKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   610
  f(InstanceClassLoaderKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   611
  f(InstanceMirrorKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   612
  f(InstanceRefKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   613
  f(Method) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   614
  f(ObjArrayKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   615
  f(TypeArrayKlass)
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   616
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   617
class CppVtableInfo {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   618
  intptr_t _vtable_size;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   619
  intptr_t _cloned_vtable[1];
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   620
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   621
  static int num_slots(int vtable_size) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   622
    return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   623
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   624
  int vtable_size()           { return int(uintx(_vtable_size)); }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   625
  void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   626
  intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   627
  void zero()                 { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   628
  // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   629
  static size_t byte_size(int vtable_size) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   630
    CppVtableInfo i;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   631
    return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   632
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   633
};
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   634
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   635
template <class T> class CppVtableCloner : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   636
  static intptr_t* vtable_of(Metadata& m) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   637
    return *((intptr_t**)&m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   638
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   639
  static CppVtableInfo* _info;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   640
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   641
  static int get_vtable_length(const char* name);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   642
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   643
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   644
  // Allocate and initialize the C++ vtable, starting from top, but do not go past end.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   645
  static intptr_t* allocate(const char* name);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   646
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   647
  // Clone the vtable to ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   648
  static intptr_t* clone_vtable(const char* name, CppVtableInfo* info);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   649
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   650
  static void zero_vtable_clone() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   651
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   652
    _info->zero();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   653
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   654
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   655
  // Switch the vtable pointer to point to the cloned vtable.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   656
  static void patch(Metadata* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   657
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   658
    *(void**)obj = (void*)(_info->cloned_vtable());
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   659
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   660
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   661
  static bool is_valid_shared_object(const T* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   662
    intptr_t* vptr = *(intptr_t**)obj;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   663
    return vptr == _info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   664
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   665
};
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   666
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   667
template <class T> CppVtableInfo* CppVtableCloner<T>::_info = NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   668
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   669
template <class T>
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   670
intptr_t* CppVtableCloner<T>::allocate(const char* name) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   671
  assert(is_aligned(_md_region.top(), sizeof(intptr_t)), "bad alignment");
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   672
  int n = get_vtable_length(name);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   673
  _info = (CppVtableInfo*)_md_region.allocate(CppVtableInfo::byte_size(n), sizeof(intptr_t));
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   674
  _info->set_vtable_size(n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   675
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   676
  intptr_t* p = clone_vtable(name, _info);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   677
  assert((char*)p == _md_region.top(), "must be");
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   678
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   679
  return p;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   680
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   681
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   682
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   683
intptr_t* CppVtableCloner<T>::clone_vtable(const char* name, CppVtableInfo* info) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   684
  if (!DumpSharedSpaces) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   685
    assert(_info == 0, "_info is initialized only at dump time");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   686
    _info = info; // Remember it -- it will be used by MetaspaceShared::is_valid_shared_method()
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   687
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   688
  T tmp; // Allocate temporary dummy metadata object to get to the original vtable.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   689
  int n = info->vtable_size();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   690
  intptr_t* srcvtable = vtable_of(tmp);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   691
  intptr_t* dstvtable = info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   692
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   693
  // We already checked (and, if necessary, adjusted n) when the vtables were allocated, so we are
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   694
  // safe to do memcpy.
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   695
  log_debug(cds, vtables)("Copying %3d vtable entries for %s", n, name);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   696
  memcpy(dstvtable, srcvtable, sizeof(intptr_t) * n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   697
  return dstvtable + n;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   698
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   699
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   700
// To determine the size of the vtable for each type, we use the following
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   701
// trick by declaring 2 subclasses:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   702
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   703
//   class CppVtableTesterA: public InstanceKlass {virtual int   last_virtual_method() {return 1;}    };
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   704
//   class CppVtableTesterB: public InstanceKlass {virtual void* last_virtual_method() {return NULL}; };
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   705
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   706
// CppVtableTesterA and CppVtableTesterB's vtables have the following properties:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   707
// - Their size (N+1) is exactly one more than the size of InstanceKlass's vtable (N)
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   708
// - The first N entries have are exactly the same as in InstanceKlass's vtable.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   709
// - Their last entry is different.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   710
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   711
// So to determine the value of N, we just walk CppVtableTesterA and CppVtableTesterB's tables
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   712
// and find the first entry that's different.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   713
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   714
// This works on all C++ compilers supported by Oracle, but you may need to tweak it for more
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   715
// esoteric compilers.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   716
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   717
template <class T> class CppVtableTesterB: public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   718
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   719
  virtual int last_virtual_method() {return 1;}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   720
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   721
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   722
template <class T> class CppVtableTesterA : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   723
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   724
  virtual void* last_virtual_method() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   725
    // Make this different than CppVtableTesterB::last_virtual_method so the C++
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   726
    // compiler/linker won't alias the two functions.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   727
    return NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   728
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   729
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   730
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   731
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   732
int CppVtableCloner<T>::get_vtable_length(const char* name) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   733
  CppVtableTesterA<T> a;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   734
  CppVtableTesterB<T> b;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   735
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   736
  intptr_t* avtable = vtable_of(a);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   737
  intptr_t* bvtable = vtable_of(b);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   738
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   739
  // Start at slot 1, because slot 0 may be RTTI (on Solaris/Sparc)
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   740
  int vtable_len = 1;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   741
  for (; ; vtable_len++) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   742
    if (avtable[vtable_len] != bvtable[vtable_len]) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   743
      break;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   744
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   745
  }
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   746
  log_debug(cds, vtables)("Found   %3d vtable entries for %s", vtable_len, name);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   747
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   748
  return vtable_len;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   749
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   750
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   751
#define ALLOC_CPP_VTABLE_CLONE(c) \
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   752
  CppVtableCloner<c>::allocate(#c);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   753
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   754
#define CLONE_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   755
  p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   756
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   757
#define ZERO_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   758
 CppVtableCloner<c>::zero_vtable_clone();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   759
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   760
// This can be called at both dump time and run time.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   761
intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   762
  assert(DumpSharedSpaces || UseSharedSpaces, "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   763
  CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   764
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   765
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   766
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   767
void MetaspaceShared::zero_cpp_vtable_clones_for_writing() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   768
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   769
  CPP_VTABLE_PATCH_TYPES_DO(ZERO_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   770
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   771
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   772
// Allocate and initialize the C++ vtables, starting from top, but do not go past end.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   773
void MetaspaceShared::allocate_cpp_vtable_clones() {
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   774
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   775
  // Layout (each slot is a intptr_t):
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   776
  //   [number of slots in the first vtable = n1]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   777
  //   [ <n1> slots for the first vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   778
  //   [number of slots in the first second = n2]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   779
  //   [ <n2> slots for the second vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   780
  //   ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   781
  // The order of the vtables is the same as the CPP_VTAB_PATCH_TYPES_DO macro.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   782
  CPP_VTABLE_PATCH_TYPES_DO(ALLOC_CPP_VTABLE_CLONE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   783
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   784
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   785
// Switch the vtable pointer to point to the cloned vtable. We assume the
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   786
// vtable pointer is in first slot in object.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   787
void MetaspaceShared::patch_cpp_vtable_pointers() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   788
  int n = _global_klass_objects->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   789
  for (int i = 0; i < n; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   790
    Klass* obj = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   791
    if (obj->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   792
      InstanceKlass* ik = InstanceKlass::cast(obj);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   793
      if (ik->is_class_loader_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   794
        CppVtableCloner<InstanceClassLoaderKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   795
      } else if (ik->is_reference_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   796
        CppVtableCloner<InstanceRefKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   797
      } else if (ik->is_mirror_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   798
        CppVtableCloner<InstanceMirrorKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   799
      } else {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   800
        CppVtableCloner<InstanceKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   801
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   802
      ConstantPool* cp = ik->constants();
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   803
      CppVtableCloner<ConstantPool>::patch(cp);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   804
      for (int j = 0; j < ik->methods()->length(); j++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   805
        Method* m = ik->methods()->at(j);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   806
        CppVtableCloner<Method>::patch(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   807
        assert(CppVtableCloner<Method>::is_valid_shared_object(m), "must be");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   808
      }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   809
    } else if (obj->is_objArray_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   810
      CppVtableCloner<ObjArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   811
    } else {
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   812
      assert(obj->is_typeArray_klass(), "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   813
      CppVtableCloner<TypeArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   814
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   815
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   816
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   817
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   818
bool MetaspaceShared::is_valid_shared_method(const Method* m) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
   819
  assert(is_in_shared_metaspace(m), "must be");
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   820
  return CppVtableCloner<Method>::is_valid_shared_object(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   821
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   822
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   823
// Closure for serializing initialization data out to a data area to be
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   824
// written to the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   825
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   826
class WriteClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   827
private:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   828
  DumpRegion* _dump_region;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   829
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   830
public:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   831
  WriteClosure(DumpRegion* r) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   832
    _dump_region = r;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   833
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   834
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   835
  void do_ptr(void** p) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   836
    _dump_region->append_intptr_t((intptr_t)*p);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   837
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   838
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   839
  void do_u4(u4* p) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   840
    void* ptr = (void*)(uintx(*p));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   841
    do_ptr(&ptr);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   842
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   843
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   844
  void do_tag(int tag) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   845
    _dump_region->append_intptr_t((intptr_t)tag);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   846
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   847
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   848
  void do_oop(oop* o) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   849
    if (*o == NULL) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   850
      _dump_region->append_intptr_t(0);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   851
    } else {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   852
      assert(MetaspaceShared::is_heap_object_archiving_allowed(),
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   853
             "Archiving heap object is not allowed");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   854
      _dump_region->append_intptr_t(
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
   855
        (intptr_t)CompressedOops::encode_not_null(*o));
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   856
    }
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   857
  }
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   858
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   859
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   860
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   861
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   862
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   863
    while (size > 0) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   864
      _dump_region->append_intptr_t(*(intptr_t*)start);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   865
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   866
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   867
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   868
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   869
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   870
  bool reading() const { return false; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   871
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   872
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   873
// This is for dumping detailed statistics for the allocations
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   874
// in the shared spaces.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   875
class DumpAllocStats : public ResourceObj {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   876
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   877
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   878
  // Here's poor man's enum inheritance
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   879
#define SHAREDSPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   880
  METASPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   881
  f(SymbolHashentry) \
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   882
  f(SymbolBucket) \
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   883
  f(StringHashentry) \
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   884
  f(StringBucket) \
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   885
  f(Other)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   886
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   887
  enum Type {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   888
    // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   889
    SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE)
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   890
    _number_of_types
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   891
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   892
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   893
  static const char * type_name(Type type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   894
    switch(type) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   895
    SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE)
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   896
    default:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   897
      ShouldNotReachHere();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   898
      return NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   899
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   900
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   901
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   902
public:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   903
  enum { RO = 0, RW = 1 };
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   904
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   905
  int _counts[2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   906
  int _bytes [2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   907
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   908
  DumpAllocStats() {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   909
    memset(_counts, 0, sizeof(_counts));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   910
    memset(_bytes,  0, sizeof(_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   911
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   912
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   913
  void record(MetaspaceObj::Type type, int byte_size, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   914
    assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   915
    int which = (read_only) ? RO : RW;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   916
    _counts[which][type] ++;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   917
    _bytes [which][type] += byte_size;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   918
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   919
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   920
  void record_other_type(int byte_size, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   921
    int which = (read_only) ? RO : RW;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   922
    _bytes [which][OtherType] += byte_size;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   923
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   924
  void print_stats(int ro_all, int rw_all, int mc_all, int md_all);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   925
};
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   926
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   927
void DumpAllocStats::print_stats(int ro_all, int rw_all, int mc_all, int md_all) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   928
  // Calculate size of data that was not allocated by Metaspace::allocate()
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   929
  MetaspaceSharedStats *stats = MetaspaceShared::stats();
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   930
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   931
  // symbols
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   932
  _counts[RO][SymbolHashentryType] = stats->symbol.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   933
  _bytes [RO][SymbolHashentryType] = stats->symbol.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   934
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   935
  _counts[RO][SymbolBucketType] = stats->symbol.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   936
  _bytes [RO][SymbolBucketType] = stats->symbol.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   937
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   938
  // strings
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   939
  _counts[RO][StringHashentryType] = stats->string.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   940
  _bytes [RO][StringHashentryType] = stats->string.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   941
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   942
  _counts[RO][StringBucketType] = stats->string.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   943
  _bytes [RO][StringBucketType] = stats->string.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   944
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   945
  // TODO: count things like dictionary, vtable, etc
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   946
  _bytes[RW][OtherType] += mc_all + md_all;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   947
  rw_all += mc_all + md_all; // mc/md are mapped Read/Write
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   948
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   949
  // prevent divide-by-zero
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   950
  if (ro_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   951
    ro_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   952
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   953
  if (rw_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   954
    rw_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   955
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   956
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   957
  int all_ro_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   958
  int all_ro_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   959
  int all_rw_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   960
  int all_rw_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   961
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   962
// To make fmt_stats be a syntactic constant (for format warnings), use #define.
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   963
#define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   964
  const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   965
  const char *hdr = "                        ro_cnt   ro_bytes     % |   rw_cnt   rw_bytes     % |  all_cnt  all_bytes     %";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   966
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   967
  LogMessage(cds) msg;
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   968
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   969
  msg.info("Detailed metadata info (excluding od/st regions; rw stats include md/mc regions):");
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   970
  msg.info("%s", hdr);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   971
  msg.info("%s", sep);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   972
  for (int type = 0; type < int(_number_of_types); type ++) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   973
    const char *name = type_name((Type)type);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   974
    int ro_count = _counts[RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   975
    int ro_bytes = _bytes [RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   976
    int rw_count = _counts[RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   977
    int rw_bytes = _bytes [RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   978
    int count = ro_count + rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   979
    int bytes = ro_bytes + rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   980
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
   981
    double ro_perc = percent_of(ro_bytes, ro_all);
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
   982
    double rw_perc = percent_of(rw_bytes, rw_all);
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
   983
    double perc    = percent_of(bytes, ro_all + rw_all);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   984
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
   985
    msg.info(fmt_stats, name,
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   986
                         ro_count, ro_bytes, ro_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   987
                         rw_count, rw_bytes, rw_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   988
                         count, bytes, perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   989
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   990
    all_ro_count += ro_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   991
    all_ro_bytes += ro_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   992
    all_rw_count += rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   993
    all_rw_bytes += rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   994
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   995
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   996
  int all_count = all_ro_count + all_rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   997
  int all_bytes = all_ro_bytes + all_rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   998
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
   999
  double all_ro_perc = percent_of(all_ro_bytes, ro_all);
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1000
  double all_rw_perc = percent_of(all_rw_bytes, rw_all);
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1001
  double all_perc    = percent_of(all_bytes, ro_all + rw_all);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1002
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1003
  msg.info("%s", sep);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1004
  msg.info(fmt_stats, "Total",
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1005
                       all_ro_count, all_ro_bytes, all_ro_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1006
                       all_rw_count, all_rw_bytes, all_rw_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1007
                       all_count, all_bytes, all_perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1008
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1009
  assert(all_ro_bytes == ro_all, "everything should have been counted");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1010
  assert(all_rw_bytes == rw_all, "everything should have been counted");
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1011
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
  1012
#undef fmt_stats
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1013
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1014
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1015
// Populate the shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1016
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1017
class VM_PopulateDumpSharedSpace: public VM_Operation {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1018
private:
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1019
  GrowableArray<MemRegion> *_closed_archive_heap_regions;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1020
  GrowableArray<MemRegion> *_open_archive_heap_regions;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1021
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1022
  GrowableArray<ArchiveHeapOopmapInfo> *_closed_archive_heap_oopmaps;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1023
  GrowableArray<ArchiveHeapOopmapInfo> *_open_archive_heap_oopmaps;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1024
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1025
  void dump_java_heap_objects() NOT_CDS_JAVA_HEAP_RETURN;
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1026
  void dump_archive_heap_oopmaps() NOT_CDS_JAVA_HEAP_RETURN;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1027
  void dump_archive_heap_oopmaps(GrowableArray<MemRegion>* regions,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1028
                                 GrowableArray<ArchiveHeapOopmapInfo>* oopmaps);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1029
  void dump_symbols();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1030
  char* dump_read_only_tables();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1031
  void print_region_stats();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1032
  void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1033
                               const char *name, const size_t total_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1034
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1035
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1036
  VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1037
  void doit();   // outline because gdb sucks
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1038
  static void write_region(FileMapInfo* mapinfo, int region, DumpRegion* space, bool read_only,  bool allow_exec);
49372
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 49347
diff changeset
  1039
  bool allow_nested_vm_operations() const { return true; }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1040
}; // class VM_PopulateDumpSharedSpace
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1041
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1042
class SortedSymbolClosure: public SymbolClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1043
  GrowableArray<Symbol*> _symbols;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1044
  virtual void do_symbol(Symbol** sym) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1045
    assert((*sym)->is_permanent(), "archived symbols must be permanent");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1046
    _symbols.append(*sym);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1047
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1048
  static int compare_symbols_by_address(Symbol** a, Symbol** b) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1049
    if (a[0] < b[0]) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1050
      return -1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1051
    } else if (a[0] == b[0]) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1052
      return 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1053
    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1054
      return 1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1055
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1056
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1057
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1058
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1059
  SortedSymbolClosure() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1060
    SymbolTable::symbols_do(this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1061
    _symbols.sort(compare_symbols_by_address);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1062
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1063
  GrowableArray<Symbol*>* get_sorted_symbols() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1064
    return &_symbols;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1065
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1066
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1067
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1068
// ArchiveCompactor --
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1069
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1070
// This class is the central piece of shared archive compaction -- all metaspace data are
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1071
// initially allocated outside of the shared regions. ArchiveCompactor copies the
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1072
// metaspace data into their final location in the shared regions.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1073
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1074
class ArchiveCompactor : AllStatic {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1075
  static DumpAllocStats* _alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1076
  static SortedSymbolClosure* _ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1077
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1078
  static unsigned my_hash(const address& a) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1079
    return primitive_hash<address>(a);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1080
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1081
  static bool my_equals(const address& a0, const address& a1) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1082
    return primitive_equals<address>(a0, a1);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1083
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1084
  typedef ResourceHashtable<
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1085
      address, address,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1086
      ArchiveCompactor::my_hash,   // solaris compiler doesn't like: primitive_hash<address>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1087
      ArchiveCompactor::my_equals, // solaris compiler doesn't like: primitive_equals<address>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1088
      16384, ResourceObj::C_HEAP> RelocationTable;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1089
  static RelocationTable* _new_loc_table;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1090
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1091
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1092
  static void initialize() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1093
    _alloc_stats = new(ResourceObj::C_HEAP, mtInternal)DumpAllocStats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1094
    _new_loc_table = new(ResourceObj::C_HEAP, mtInternal)RelocationTable;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1095
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1096
  static DumpAllocStats* alloc_stats() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1097
    return _alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1098
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1099
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1100
  static void allocate(MetaspaceClosure::Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1101
    address obj = ref->obj();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1102
    int bytes = ref->size() * BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1103
    char* p;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1104
    size_t alignment = BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1105
    char* oldtop;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1106
    char* newtop;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1107
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1108
    if (read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1109
      oldtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1110
      p = _ro_region.allocate(bytes, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1111
      newtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1112
    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1113
      oldtop = _rw_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1114
      p = _rw_region.allocate(bytes, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1115
      newtop = _rw_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1116
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1117
    memcpy(p, obj, bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1118
    bool isnew = _new_loc_table->put(obj, (address)p);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1119
    log_trace(cds)("Copy: " PTR_FORMAT " ==> " PTR_FORMAT " %d", p2i(obj), p2i(p), bytes);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1120
    assert(isnew, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1121
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1122
    _alloc_stats->record(ref->msotype(), int(newtop - oldtop), read_only);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1123
    if (ref->msotype() == MetaspaceObj::SymbolType) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1124
      uintx delta = MetaspaceShared::object_delta(p);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1125
      if (delta > MAX_SHARED_DELTA) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1126
        // This is just a sanity check and should not appear in any real world usage. This
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1127
        // happens only if you allocate more than 2GB of Symbols and would require
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1128
        // millions of shared classes.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1129
        vm_exit_during_initialization("Too many Symbols in the CDS archive",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1130
                                      "Please reduce the number of shared classes.");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1131
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1132
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1133
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1134
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1135
  static address get_new_loc(MetaspaceClosure::Ref* ref) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1136
    address* pp = _new_loc_table->get(ref->obj());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1137
    assert(pp != NULL, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1138
    return *pp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1139
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1140
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1141
private:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1142
  // Makes a shallow copy of visited MetaspaceObj's
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1143
  class ShallowCopier: public UniqueMetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1144
    bool _read_only;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1145
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1146
    ShallowCopier(bool read_only) : _read_only(read_only) {}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1147
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1148
    virtual void do_unique_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1149
      if (read_only == _read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1150
        allocate(ref, read_only);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1151
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1152
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1153
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1154
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1155
  // Relocate embedded pointers within a MetaspaceObj's shallow copy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1156
  class ShallowCopyEmbeddedRefRelocator: public UniqueMetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1157
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1158
    virtual void do_unique_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1159
      address new_loc = get_new_loc(ref);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1160
      RefRelocator refer;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1161
      ref->metaspace_pointers_do_at(&refer, new_loc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1162
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1163
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1164
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1165
  // Relocate a reference to point to its shallow copy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1166
  class RefRelocator: public MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1167
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1168
    virtual bool do_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1169
      if (ref->not_null()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1170
        ref->update(get_new_loc(ref));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1171
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1172
      return false; // Do not recurse.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1173
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1174
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1175
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1176
#ifdef ASSERT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1177
  class IsRefInArchiveChecker: public MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1178
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1179
    virtual bool do_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1180
      if (ref->not_null()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1181
        char* obj = (char*)ref->obj();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1182
        assert(_ro_region.contains(obj) || _rw_region.contains(obj),
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1183
               "must be relocated to point to CDS archive");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1184
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1185
      return false; // Do not recurse.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1186
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1187
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1188
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1189
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1190
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1191
  static void copy_and_compact() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1192
    // We should no longer allocate anything from the metaspace, so that
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1193
    // we can have a stable set of MetaspaceObjs to work with.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1194
    Metaspace::freeze();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1195
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1196
    ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1197
    SortedSymbolClosure the_ssc; // StackObj
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1198
    _ssc = &the_ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1199
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1200
    tty->print_cr("Scanning all metaspace objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1201
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1202
      // allocate and shallow-copy RW objects, immediately following the MC region
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1203
      tty->print_cr("Allocating RW objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1204
      _mc_region.pack(&_rw_region);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1205
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1206
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1207
      ShallowCopier rw_copier(false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1208
      iterate_roots(&rw_copier);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1209
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1210
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1211
      // allocate and shallow-copy of RO object, immediately following the RW region
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1212
      tty->print_cr("Allocating RO objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1213
      _rw_region.pack(&_ro_region);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1214
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1215
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1216
      ShallowCopier ro_copier(true);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1217
      iterate_roots(&ro_copier);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1218
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1219
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1220
      tty->print_cr("Relocating embedded pointers ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1221
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1222
      ShallowCopyEmbeddedRefRelocator emb_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1223
      iterate_roots(&emb_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1224
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1225
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1226
      tty->print_cr("Relocating external roots ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1227
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1228
      RefRelocator ext_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1229
      iterate_roots(&ext_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1230
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1231
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1232
#ifdef ASSERT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1233
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1234
      tty->print_cr("Verifying external roots ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1235
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1236
      IsRefInArchiveChecker checker;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1237
      iterate_roots(&checker);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1238
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1239
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1240
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1241
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1242
    // cleanup
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1243
    _ssc = NULL;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1244
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1245
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1246
  // We must relocate the System::_well_known_klasses only after we have copied the
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1247
  // java objects in during dump_java_heap_objects(): during the object copy, we operate on
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1248
  // old objects which assert that their klass is the original klass.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1249
  static void relocate_well_known_klasses() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1250
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1251
      tty->print_cr("Relocating SystemDictionary::_well_known_klasses[] ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1252
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1253
      RefRelocator ext_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1254
      SystemDictionary::well_known_klasses_do(&ext_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1255
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1256
    // NOTE: after this point, we shouldn't have any globals that can reach the old
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1257
    // objects.
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
    // We cannot use any of the objects in the heap anymore (except for the objects
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1260
    // in the CDS shared string regions) because their headers no longer point to
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1261
    // valid Klasses.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1262
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1263
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1264
  static void iterate_roots(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1265
    GrowableArray<Symbol*>* symbols = _ssc->get_sorted_symbols();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1266
    for (int i=0; i<symbols->length(); i++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1267
      it->push(symbols->adr_at(i));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1268
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1269
    if (_global_klass_objects != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1270
      // Need to fix up the pointers
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1271
      for (int i = 0; i < _global_klass_objects->length(); i++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1272
        // NOTE -- this requires that the vtable is NOT yet patched, or else we are hosed.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1273
        it->push(_global_klass_objects->adr_at(i));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1274
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1275
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1276
    FileMapInfo::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1277
    SystemDictionary::classes_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1278
    Universe::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1279
    SymbolTable::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1280
    vmSymbols::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1281
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1282
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1283
  static Klass* get_relocated_klass(Klass* orig_klass) {
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1284
    assert(DumpSharedSpaces, "dump time only");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1285
    address* pp = _new_loc_table->get((address)orig_klass);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1286
    assert(pp != NULL, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1287
    Klass* klass = (Klass*)(*pp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1288
    assert(klass->is_klass(), "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1289
    return klass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1290
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1291
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1292
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1293
DumpAllocStats* ArchiveCompactor::_alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1294
SortedSymbolClosure* ArchiveCompactor::_ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1295
ArchiveCompactor::RelocationTable* ArchiveCompactor::_new_loc_table;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1296
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1297
void VM_PopulateDumpSharedSpace::write_region(FileMapInfo* mapinfo, int region_idx,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1298
                                              DumpRegion* dump_region, bool read_only,  bool allow_exec) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1299
  mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1300
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1301
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1302
void VM_PopulateDumpSharedSpace::dump_symbols() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1303
  tty->print_cr("Dumping symbol table ...");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1304
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1305
  NOT_PRODUCT(SymbolTable::verify());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1306
  SymbolTable::write_to_archive();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1307
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1308
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1309
char* VM_PopulateDumpSharedSpace::dump_read_only_tables() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1310
  char* oldtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1311
  // Reorder the system dictionary. Moving the symbols affects
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1312
  // how the hash table indices are calculated.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1313
  SystemDictionary::reorder_dictionary_for_sharing();
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1314
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1315
  tty->print("Removing java_mirror ... ");
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1316
  if (!MetaspaceShared::is_heap_object_archiving_allowed()) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1317
    clear_basic_type_mirrors();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1318
  }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1319
  remove_java_mirror_in_classes();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1320
  tty->print_cr("done. ");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1321
  NOT_PRODUCT(SystemDictionary::verify();)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1322
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1323
  size_t buckets_bytes = SystemDictionary::count_bytes_for_buckets();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1324
  char* buckets_top = _ro_region.allocate(buckets_bytes, sizeof(intptr_t));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1325
  SystemDictionary::copy_buckets(buckets_top, _ro_region.top());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1326
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1327
  size_t table_bytes = SystemDictionary::count_bytes_for_table();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1328
  char* table_top = _ro_region.allocate(table_bytes, sizeof(intptr_t));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1329
  SystemDictionary::copy_table(table_top, _ro_region.top());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1330
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1331
  // Write the archived object sub-graph infos. For each klass with sub-graphs,
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1332
  // the info includes the static fields (sub-graph entry points) and Klasses
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1333
  // of objects included in the sub-graph.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1334
  HeapShared::write_archived_subgraph_infos();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1335
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1336
  // Write the other data to the output array.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1337
  WriteClosure wc(&_ro_region);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1338
  MetaspaceShared::serialize(&wc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1339
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1340
  // Write the bitmaps for patching the archive heap regions
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1341
  dump_archive_heap_oopmaps();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1342
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1343
  char* newtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1344
  ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - oldtop), true);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1345
  return buckets_top;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1346
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1347
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1348
void VM_PopulateDumpSharedSpace::doit() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1349
  Thread* THREAD = VMThread::vm_thread();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1350
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49769
diff changeset
  1351
  FileMapInfo::check_nonempty_dir_in_shared_path_table();
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49769
diff changeset
  1352
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1353
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1354
  // The following guarantee is meant to ensure that no loader constraints
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1355
  // exist yet, since the constraints table is not shared.  This becomes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1356
  // more important now that we don't re-initialize vtables/itables for
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1357
  // shared classes at runtime, where constraints were previously created.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1358
  guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1359
            "loader constraints are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
  guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1361
          "placeholders are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
  // Revisit and implement this if we prelink method handle call sites:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
  guarantee(SystemDictionary::invoke_method_table() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1364
            SystemDictionary::invoke_method_table()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1365
            "invoke method table is not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1366
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1367
  // At this point, many classes have been loaded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1368
  // Gather systemDictionary classes in a global array and do everything to
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1369
  // that so we don't have to walk the SystemDictionary again.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1370
  _global_klass_objects = new GrowableArray<Klass*>(1000);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1371
  CollectClassesClosure collect_classes;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1372
  ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1373
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1374
  tty->print_cr("Number of classes %d", _global_klass_objects->length());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1375
  {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1376
    int num_type_array = 0, num_obj_array = 0, num_inst = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1377
    for (int i = 0; i < _global_klass_objects->length(); i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1378
      Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1379
      if (k->is_instance_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1380
        num_inst ++;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1381
      } else if (k->is_objArray_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1382
        num_obj_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1383
      } else {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1384
        assert(k->is_typeArray_klass(), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1385
        num_type_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1386
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1387
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1388
    tty->print_cr("    instance classes   = %5d", num_inst);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1389
    tty->print_cr("    obj array classes  = %5d", num_obj_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1390
    tty->print_cr("    type array classes = %5d", num_type_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1391
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1392
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
  1393
  // Ensure the ConstMethods won't be modified at run-time
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
  1394
  tty->print("Updating ConstMethods ... ");
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
  1395
  rewrite_nofast_bytecodes_and_calculate_fingerprints();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1396
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1397
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1398
  // Move classes from platform/system dictionaries into the boot dictionary
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1399
  SystemDictionary::combine_shared_dictionaries();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1400
50206
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1401
  // Make sure all classes have a correct loader type.
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1402
  ClassLoaderData::the_null_class_loader_data()->dictionary()->classes_do(MetaspaceShared::check_shared_class_loader_type);
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1403
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1404
  // Remove all references outside the metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1405
  tty->print("Removing unshareable information ... ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1406
  remove_unshareable_in_classes();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1407
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1408
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
  1409
  // We don't support archiving unsafe anonymous classes. Verify that they are not stored in
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
  1410
  // any dictionaries.
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51429
diff changeset
  1411
  NOT_PRODUCT(assert_no_unsafe_anonymous_classes_in_dictionaries());
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1412
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1413
  SystemDictionaryShared::finalize_verification_constraints();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1414
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1415
  ArchiveCompactor::initialize();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1416
  ArchiveCompactor::copy_and_compact();
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1417
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1418
  dump_symbols();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1419
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1420
  // Dump supported java heap objects
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1421
  _closed_archive_heap_regions = NULL;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1422
  _open_archive_heap_regions = NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1423
  dump_java_heap_objects();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1424
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1425
  ArchiveCompactor::relocate_well_known_klasses();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1426
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1427
  char* read_only_tables_start = dump_read_only_tables();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1428
  _ro_region.pack(&_md_region);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1429
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1430
  char* vtbl_list = _md_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1431
  MetaspaceShared::allocate_cpp_vtable_clones();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1432
  _md_region.pack(&_od_region);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
  1433
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1434
  // Relocate the archived class file data into the od region
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1435
  relocate_cached_class_file();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1436
  _od_region.pack();
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
  1437
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1438
  // The 5 core spaces are allocated consecutively mc->rw->ro->md->od, so there total size
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1439
  // is just the spaces between the two ends.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1440
  size_t core_spaces_size = _od_region.end() - _mc_region.base();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1441
  assert(core_spaces_size == (size_t)align_up(core_spaces_size, Metaspace::reserve_alignment()),
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1442
         "should already be aligned");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1443
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1444
  // During patching, some virtual methods may be called, so at this point
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1445
  // the vtables must contain valid methods (as filled in by CppVtableCloner::allocate).
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1446
  MetaspaceShared::patch_cpp_vtable_pointers();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1447
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1448
  // The vtable clones contain addresses of the current process.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1449
  // We don't want to write these addresses into the archive.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1450
  MetaspaceShared::zero_cpp_vtable_clones_for_writing();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1451
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1452
  // Create and write the archive file that maps the shared spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1453
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1454
  FileMapInfo* mapinfo = new FileMapInfo();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1455
  mapinfo->populate_header(os::vm_allocation_granularity());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1456
  mapinfo->set_read_only_tables_start(read_only_tables_start);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1457
  mapinfo->set_misc_data_patching_start(vtbl_list);
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1458
  mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1459
  mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1460
  mapinfo->set_core_spaces_size(core_spaces_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1461
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1462
  for (int pass=1; pass<=2; pass++) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1463
    if (pass == 1) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1464
      // The first pass doesn't actually write the data to disk. All it
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1465
      // does is to update the fields in the mapinfo->_header.
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1466
    } else {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1467
      // After the first pass, the contents of mapinfo->_header are finalized,
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1468
      // so we can compute the header's CRC, and write the contents of the header
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1469
      // and the regions into disk.
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1470
      mapinfo->open_for_write();
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1471
      mapinfo->set_header_crc(mapinfo->compute_header_crc());
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1472
    }
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1473
    mapinfo->write_header();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1474
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1475
    // NOTE: md contains the trampoline code for method entries, which are patched at run time,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1476
    // so it needs to be read/write.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1477
    write_region(mapinfo, MetaspaceShared::mc, &_mc_region, /*read_only=*/false,/*allow_exec=*/true);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1478
    write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1479
    write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1480
    write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1481
    write_region(mapinfo, MetaspaceShared::od, &_od_region, /*read_only=*/true, /*allow_exec=*/false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1482
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1483
    _total_string_region_size = mapinfo->write_archive_heap_regions(
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1484
                                        _closed_archive_heap_regions,
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1485
                                        _closed_archive_heap_oopmaps,
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1486
                                        MetaspaceShared::first_string,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1487
                                        MetaspaceShared::max_strings);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1488
    _total_open_archive_region_size = mapinfo->write_archive_heap_regions(
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1489
                                        _open_archive_heap_regions,
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1490
                                        _open_archive_heap_oopmaps,
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1491
                                        MetaspaceShared::first_open_archive_heap_region,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1492
                                        MetaspaceShared::max_open_archive_heap_region);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1493
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1494
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1495
  mapinfo->close();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1496
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1497
  // Restore the vtable in case we invoke any virtual methods.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1498
  MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1499
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1500
  print_region_stats();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1501
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1502
  if (log_is_enabled(Info, cds)) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1503
    ArchiveCompactor::alloc_stats()->print_stats(int(_ro_region.used()), int(_rw_region.used()),
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1504
                                                 int(_mc_region.used()), int(_md_region.used()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1505
  }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1506
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1507
  if (PrintSystemDictionaryAtExit) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1508
    SystemDictionary::print();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1509
  }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1510
  // There may be other pending VM operations that operate on the InstanceKlasses,
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1511
  // which will fail because InstanceKlasses::remove_unshareable_info()
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1512
  // has been called. Forget these operations and exit the VM directly.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1513
  vm_direct_exit(0);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1514
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1515
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1516
void VM_PopulateDumpSharedSpace::print_region_stats() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1517
  // Print statistics of all the regions
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1518
  const size_t total_reserved = _ro_region.reserved()  + _rw_region.reserved() +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1519
                                _mc_region.reserved()  + _md_region.reserved() +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1520
                                _od_region.reserved()  +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1521
                                _total_string_region_size +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1522
                                _total_open_archive_region_size;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1523
  const size_t total_bytes = _ro_region.used()  + _rw_region.used() +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1524
                             _mc_region.used()  + _md_region.used() +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1525
                             _od_region.used()  +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1526
                             _total_string_region_size +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1527
                             _total_open_archive_region_size;
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1528
  const double total_u_perc = percent_of(total_bytes, total_reserved);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1529
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1530
  _mc_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1531
  _rw_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1532
  _ro_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1533
  _md_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1534
  _od_region.print(total_reserved);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1535
  print_heap_region_stats(_closed_archive_heap_regions, "st", total_reserved);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1536
  print_heap_region_stats(_open_archive_heap_regions, "oa", total_reserved);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1537
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
  1538
  tty->print_cr("total    : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]",
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1539
                 total_bytes, total_reserved, total_u_perc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1540
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1541
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1542
void VM_PopulateDumpSharedSpace::print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1543
                                                         const char *name, const size_t total_size) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1544
  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
  1545
  for (int i = 0; i < arr_len; i++) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1546
      char* start = (char*)heap_mem->at(i).start();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1547
      size_t size = heap_mem->at(i).byte_size();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1548
      char* top = start + size;
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
  1549
      tty->print_cr("%s%d space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [100.0%% used] at " INTPTR_FORMAT,
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1550
                    name, i, size, size/double(total_size)*100.0, size, p2i(start));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1551
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1552
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1553
}
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1554
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1555
// Update a Java object to point its Klass* to the new location after
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1556
// shared archive has been compacted.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1557
void MetaspaceShared::relocate_klass_ptr(oop o) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1558
  assert(DumpSharedSpaces, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1559
  Klass* k = ArchiveCompactor::get_relocated_klass(o->klass());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1560
  o->set_klass(k);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1561
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1562
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1563
Klass* MetaspaceShared::get_relocated_klass(Klass *k) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1564
  assert(DumpSharedSpaces, "sanity");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1565
  return ArchiveCompactor::get_relocated_klass(k);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1566
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1567
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1568
class LinkSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1569
  Thread* THREAD;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1570
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1571
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1572
  LinkSharedClassesClosure(Thread* thread) : THREAD(thread), _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1573
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1574
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1575
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1576
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1577
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1578
    if (k->is_instance_klass()) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1579
      InstanceKlass* ik = InstanceKlass::cast(k);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1580
      // Link the class to cause the bytecodes to be rewritten and the
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1581
      // cpcache to be created. Class verification is done according
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1582
      // to -Xverify setting.
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1583
      _made_progress |= MetaspaceShared::try_link_class(ik, THREAD);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1584
      guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1585
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1586
      ik->constants()->resolve_class_constants(THREAD);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1587
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1588
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1589
};
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1590
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1591
class CheckSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1592
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1593
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1594
  CheckSharedClassesClosure() : _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1595
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1596
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1597
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1598
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1599
    if (k->is_instance_klass() && InstanceKlass::cast(k)->check_sharing_error_state()) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1600
      _made_progress = true;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1601
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1602
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1603
};
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1604
50206
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1605
void MetaspaceShared::check_shared_class_loader_type(InstanceKlass* ik) {
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1606
  ResourceMark rm;
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1607
  if (ik->shared_classpath_index() == UNREGISTERED_INDEX) {
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1608
    guarantee(ik->loader_type() == 0,
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1609
            "Class loader type must not be set for this class %s", ik->name()->as_C_string());
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1610
  } else {
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1611
    guarantee(ik->loader_type() != 0,
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
  1612
            "Class loader type must be set for this class %s", ik->name()->as_C_string());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1613
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1614
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1615
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1616
void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1617
  // We need to iterate because verification may cause additional classes
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1618
  // to be loaded.
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1619
  LinkSharedClassesClosure link_closure(THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1620
  do {
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1621
    link_closure.reset();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 51554
diff changeset
  1622
    ClassLoaderDataGraph::unlocked_loaded_classes_do(&link_closure);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1623
    guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1624
  } while (link_closure.made_progress());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1625
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1626
  if (_has_error_classes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1627
    // Mark all classes whose super class or interfaces failed verification.
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1628
    CheckSharedClassesClosure check_closure;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1629
    do {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1630
      // Not completely sure if we need to do this iteratively. Anyway,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1631
      // we should come here only if there are unverifiable classes, which
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1632
      // shouldn't happen in normal cases. So better safe than sorry.
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1633
      check_closure.reset();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 51554
diff changeset
  1634
      ClassLoaderDataGraph::unlocked_loaded_classes_do(&check_closure);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1635
    } while (check_closure.made_progress());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1636
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1637
    if (IgnoreUnverifiableClassesDuringDump) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1638
      // This is useful when running JCK or SQE tests. You should not
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1639
      // enable this when running real apps.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1640
      SystemDictionary::remove_classes_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1641
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1642
      tty->print_cr("Please remove the unverifiable classes from your class list and try again");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1643
      exit(1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1644
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1645
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1646
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1647
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1648
void MetaspaceShared::prepare_for_dumping() {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1649
  Arguments::check_unsupported_dumping_properties();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1650
  ClassLoader::initialize_shared_path();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1651
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1652
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1653
// Preload classes from a list, populate the shared spaces and dump to a
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1654
// file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1655
void MetaspaceShared::preload_and_dump(TRAPS) {
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 37094
diff changeset
  1656
  { TraceTime timer("Dump Shared Spaces", TRACETIME_LOG(Info, startuptime));
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1657
    ResourceMark rm;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1658
    char class_list_path_str[JVM_MAXPATHLEN];
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1659
    // Preload classes to be shared.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1660
    // Should use some os:: method rather than fopen() here. aB.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1661
    const char* class_list_path;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1662
    if (SharedClassListFile == NULL) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1663
      // Construct the path to the class list (in jre/lib)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1664
      // Walk up two directories from the location of the VM and
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1665
      // optionally tack on "lib" (depending on platform)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1666
      os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1667
      for (int i = 0; i < 3; i++) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1668
        char *end = strrchr(class_list_path_str, *os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1669
        if (end != NULL) *end = '\0';
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1670
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1671
      int class_list_path_len = (int)strlen(class_list_path_str);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1672
      if (class_list_path_len >= 3) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1673
        if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1674
          if (class_list_path_len < JVM_MAXPATHLEN - 4) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1675
            jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1676
                         sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1677
                         "%slib", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1678
            class_list_path_len += 4;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1679
          }
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
  1680
        }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1681
      }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1682
      if (class_list_path_len < JVM_MAXPATHLEN - 10) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1683
        jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1684
                     sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1685
                     "%sclasslist", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1686
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1687
      class_list_path = class_list_path_str;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1688
    } else {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1689
      class_list_path = SharedClassListFile;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1690
    }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1691
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1692
    tty->print_cr("Loading classes to share ...");
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1693
    _has_error_classes = false;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1694
    int class_count = preload_classes(class_list_path, THREAD);
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1695
    if (ExtraSharedClassListFile) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1696
      class_count += preload_classes(ExtraSharedClassListFile, THREAD);
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1697
    }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1698
    tty->print_cr("Loading classes to share: done.");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1699
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1700
    log_info(cds)("Shared spaces: preloaded %d classes", class_count);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1701
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1702
    // Rewrite and link classes
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1703
    tty->print_cr("Rewriting and linking classes ...");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1704
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1705
    // Link any classes which got missed. This would happen if we have loaded classes that
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1706
    // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1707
    // fails verification, all other interfaces that were not specified in the classlist but
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1708
    // are implemented by K are not verified.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1709
    link_and_cleanup_shared_classes(CATCH);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1710
    tty->print_cr("Rewriting and linking classes: done");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1711
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1712
    SystemDictionary::clear_invoke_method_table();
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
  1713
    HeapShared::init_archivable_static_fields(THREAD);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1714
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1715
    VM_PopulateDumpSharedSpace op;
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1716
    VMThread::execute(&op);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1717
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1718
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1719
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1720
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1721
int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1722
  ClassListParser parser(class_list_path);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1723
  int class_count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1724
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1725
    while (parser.parse_one_line()) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1726
      Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1727
      if (HAS_PENDING_EXCEPTION) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1728
        if (klass == NULL &&
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1729
             (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1730
          // print a warning only when the pending exception is class not found
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1731
          tty->print_cr("Preload Warning: Cannot find %s", parser.current_class_name());
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1732
        }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1733
        CLEAR_PENDING_EXCEPTION;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1734
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1735
      if (klass != NULL) {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1736
        if (log_is_enabled(Trace, cds)) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1737
          ResourceMark rm;
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1738
          log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1739
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1740
48383
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1741
        if (klass->is_instance_klass()) {
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1742
          InstanceKlass* ik = InstanceKlass::cast(klass);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1743
48383
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1744
          // Link the class to cause the bytecodes to be rewritten and the
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1745
          // cpcache to be created. The linking is done as soon as classes
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1746
          // are loaded in order that the related data structures (klass and
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1747
          // cpCache) are located together.
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1748
          try_link_class(ik, THREAD);
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1749
          guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 47765
diff changeset
  1750
        }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1751
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1752
        class_count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1753
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1754
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1755
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1756
  return class_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1757
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1758
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1759
// Returns true if the class's status has changed
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1760
bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1761
  assert(DumpSharedSpaces, "should only be called during dumping");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1762
  if (ik->init_state() < InstanceKlass::linked) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1763
    bool saved = BytecodeVerificationLocal;
49769
b8c9bec06921 8197972: Always verify non-system classes during CDS dump time
ccheung
parents: 49739
diff changeset
  1764
    if (ik->loader_type() == 0 && ik->class_loader() == NULL) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1765
      // The verification decision is based on BytecodeVerificationRemote
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1766
      // for non-system classes. Since we are using the NULL classloader
49769
b8c9bec06921 8197972: Always verify non-system classes during CDS dump time
ccheung
parents: 49739
diff changeset
  1767
      // to load non-system classes for customized class loaders during dumping,
b8c9bec06921 8197972: Always verify non-system classes during CDS dump time
ccheung
parents: 49739
diff changeset
  1768
      // we need to temporarily change BytecodeVerificationLocal to be the same as
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1769
      // BytecodeVerificationRemote. Note this can cause the parent system
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1770
      // classes also being verified. The extra overhead is acceptable during
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1771
      // dumping.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1772
      BytecodeVerificationLocal = BytecodeVerificationRemote;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1773
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1774
    ik->link_class(THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1775
    if (HAS_PENDING_EXCEPTION) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1776
      ResourceMark rm;
27618
790a8bf5488b 8064375: Change certain errors to warnings in CDS output.
jiangli
parents: 27025
diff changeset
  1777
      tty->print_cr("Preload Warning: Verification failed for %s",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1778
                    ik->external_name());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1779
      CLEAR_PENDING_EXCEPTION;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1780
      ik->set_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1781
      _has_error_classes = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1782
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1783
    BytecodeVerificationLocal = saved;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1784
    return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1785
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1786
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1787
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1788
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1789
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1790
#if INCLUDE_CDS_JAVA_HEAP
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1791
void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1792
  if (!MetaspaceShared::is_heap_object_archiving_allowed()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1793
    if (log_is_enabled(Info, cds)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1794
      log_info(cds)(
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1795
        "Archived java heap is not supported as UseG1GC, "
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1796
        "UseCompressedOops and UseCompressedClassPointers are required."
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1797
        "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.",
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1798
        BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops),
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1799
        BOOL_TO_STR(UseCompressedClassPointers));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1800
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1801
    return;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1802
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1803
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1804
  {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1805
    NoSafepointVerifier nsv;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1806
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1807
    // Cache for recording where the archived objects are copied to
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1808
    MetaspaceShared::create_archive_object_cache();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1809
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1810
    tty->print_cr("Dumping objects to 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
  1811
    NOT_PRODUCT(StringTable::verify());
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1812
    // The closed space has maximum two regions. See FileMapInfo::write_archive_heap_regions() for details.
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1813
    _closed_archive_heap_regions = new GrowableArray<MemRegion>(2);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1814
    MetaspaceShared::dump_closed_archive_heap_objects(_closed_archive_heap_regions);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1815
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1816
    tty->print_cr("Dumping objects to open archive heap region ...");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1817
    _open_archive_heap_regions = new GrowableArray<MemRegion>(2);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1818
    MetaspaceShared::dump_open_archive_heap_objects(_open_archive_heap_regions);
46989
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
  1819
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
  1820
    MetaspaceShared::destroy_archive_object_cache();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1821
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1822
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1823
  G1HeapVerifier::verify_archive_regions();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1824
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1825
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1826
void VM_PopulateDumpSharedSpace::dump_archive_heap_oopmaps() {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1827
  if (MetaspaceShared::is_heap_object_archiving_allowed()) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1828
    _closed_archive_heap_oopmaps = new GrowableArray<ArchiveHeapOopmapInfo>(2);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1829
    dump_archive_heap_oopmaps(_closed_archive_heap_regions, _closed_archive_heap_oopmaps);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1830
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1831
    _open_archive_heap_oopmaps = new GrowableArray<ArchiveHeapOopmapInfo>(2);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1832
    dump_archive_heap_oopmaps(_open_archive_heap_regions, _open_archive_heap_oopmaps);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1833
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1834
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1835
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1836
void VM_PopulateDumpSharedSpace::dump_archive_heap_oopmaps(GrowableArray<MemRegion>* regions,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1837
                                                           GrowableArray<ArchiveHeapOopmapInfo>* oopmaps) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1838
  for (int i=0; i<regions->length(); i++) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1839
    ResourceBitMap oopmap = HeapShared::calculate_oopmap(regions->at(i));
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1840
    size_t size_in_bits = oopmap.size();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1841
    size_t size_in_bytes = oopmap.size_in_bytes();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1842
    uintptr_t* buffer = (uintptr_t*)_ro_region.allocate(size_in_bytes, sizeof(intptr_t));
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1843
    oopmap.write_to(buffer, size_in_bytes);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1844
    log_info(cds)("Oopmap = " INTPTR_FORMAT " (" SIZE_FORMAT_W(6) " bytes) for heap region "
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1845
                  INTPTR_FORMAT " (" SIZE_FORMAT_W(8) " bytes)",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1846
                  p2i(buffer), size_in_bytes,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1847
                  p2i(regions->at(i).start()), regions->at(i).byte_size());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1848
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1849
    ArchiveHeapOopmapInfo info;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1850
    info._oopmap = (address)buffer;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1851
    info._oopmap_size_in_bits = size_in_bits;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1852
    oopmaps->append(info);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1853
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1854
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1855
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1856
void MetaspaceShared::dump_closed_archive_heap_objects(
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1857
                                    GrowableArray<MemRegion> * closed_archive) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1858
  assert(is_heap_object_archiving_allowed(), "Cannot dump java heap objects");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1859
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1860
  Thread* THREAD = Thread::current();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1861
  G1CollectedHeap::heap()->begin_archive_alloc_range();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1862
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1863
  // Archive interned string objects
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50206
diff changeset
  1864
  StringTable::write_to_archive();
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1865
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1866
  G1CollectedHeap::heap()->end_archive_alloc_range(closed_archive,
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1867
                                                   os::vm_allocation_granularity());
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1868
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1869
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1870
void MetaspaceShared::dump_open_archive_heap_objects(
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1871
                                    GrowableArray<MemRegion> * open_archive) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1872
  assert(UseG1GC, "Only support G1 GC");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1873
  assert(UseCompressedOops && UseCompressedClassPointers,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1874
         "Only support UseCompressedOops and UseCompressedClassPointers enabled");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1875
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1876
  Thread* THREAD = Thread::current();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1877
  G1CollectedHeap::heap()->begin_archive_alloc_range(true /* open */);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1878
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1879
  java_lang_Class::archive_basic_type_mirrors(THREAD);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1880
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1881
  MetaspaceShared::archive_klass_objects(THREAD);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1882
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1883
  HeapShared::archive_module_graph_objects(THREAD);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1884
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1885
  G1CollectedHeap::heap()->end_archive_alloc_range(open_archive,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1886
                                                   os::vm_allocation_granularity());
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1887
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1888
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1889
unsigned MetaspaceShared::obj_hash(oop const& p) {
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1890
  assert(!p->mark()->has_bias_pattern(),
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1891
         "this object should never have been locked");  // so identity_hash won't safepoin
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1892
  unsigned hash = (unsigned)p->identity_hash();
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1893
  return hash;
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1894
}
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
  1895
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1896
MetaspaceShared::ArchivedObjectCache* MetaspaceShared::_archive_object_cache = NULL;
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1897
oop MetaspaceShared::find_archived_heap_object(oop obj) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1898
  assert(DumpSharedSpaces, "dump-time only");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1899
  ArchivedObjectCache* cache = MetaspaceShared::archive_object_cache();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1900
  oop* p = cache->get(obj);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1901
  if (p != NULL) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1902
    return *p;
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1903
  } else {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1904
    return NULL;
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1905
  }
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1906
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1907
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1908
oop MetaspaceShared::archive_heap_object(oop obj, Thread* THREAD) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1909
  assert(DumpSharedSpaces, "dump-time only");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1910
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1911
  oop ao = find_archived_heap_object(obj);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1912
  if (ao != NULL) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1913
    // already archived
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1914
    return ao;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1915
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1916
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1917
  int len = obj->size();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1918
  if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
51425
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1919
    log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1920
                         p2i(obj), (size_t)obj->size());
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1921
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1922
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1923
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1924
  int hash = obj->identity_hash();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1925
  oop archived_oop = (oop)G1CollectedHeap::heap()->archive_mem_allocate(len);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1926
  if (archived_oop != NULL) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1927
    Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)archived_oop, len);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1928
    relocate_klass_ptr(archived_oop);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1929
    ArchivedObjectCache* cache = MetaspaceShared::archive_object_cache();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1930
    cache->put(obj, archived_oop);
51425
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1931
    log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT,
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1932
                         p2i(obj), p2i(archived_oop));
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1933
  } else {
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1934
    log_error(cds, heap)(
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1935
      "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1936
      p2i(obj));
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51417
diff changeset
  1937
    vm_exit(1);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1938
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1939
  return archived_oop;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1940
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1941
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1942
oop MetaspaceShared::materialize_archived_object(narrowOop v) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1943
  if (!CompressedOops::is_null(v)) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1944
    oop obj = HeapShared::decode_with_archived_oop_encoding_mode(v);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1945
    return G1CollectedHeap::heap()->materialize_archived_object(obj);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1946
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  1947
  return NULL;
50532
a18c60527166 8204585: Remove IN_ARCHIVE_ROOT from Access API
kbarrett
parents: 50445
diff changeset
  1948
}
a18c60527166 8204585: Remove IN_ARCHIVE_ROOT from Access API
kbarrett
parents: 50445
diff changeset
  1949
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1950
void MetaspaceShared::archive_klass_objects(Thread* THREAD) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1951
  int i;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1952
  for (i = 0; i < _global_klass_objects->length(); i++) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1953
    Klass* k = _global_klass_objects->at(i);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1954
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1955
    // archive mirror object
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1956
    java_lang_Class::archive_mirror(k, CHECK);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1957
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1958
    // archive the resolved_referenes array
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1959
    if (k->is_instance_klass()) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1960
      InstanceKlass* ik = InstanceKlass::cast(k);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1961
      ik->constants()->archive_resolved_references(THREAD);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1962
    }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1963
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1964
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1965
50056
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
  1966
bool MetaspaceShared::is_archive_object(oop p) {
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
  1967
  return (p == NULL) ? false : G1ArchiveAllocator::is_archive_object(p);
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
  1968
}
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
  1969
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1970
void MetaspaceShared::fixup_mapped_heap_regions() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1971
  FileMapInfo *mapinfo = FileMapInfo::current_info();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1972
  mapinfo->fixup_mapped_heap_regions();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1973
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1974
#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
  1975
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1976
// Closure for serializing initialization data in from a data area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1977
// (ptr_array) read from the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1978
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1979
class ReadClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1980
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1981
  intptr_t** _ptr_array;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1982
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1983
  inline intptr_t nextPtr() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1984
    return *(*_ptr_array)++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1985
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1986
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1987
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1988
  ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1989
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1990
  void do_ptr(void** p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1991
    assert(*p == NULL, "initializing previous initialized pointer.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1992
    intptr_t obj = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1993
    assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1994
           "hit tag while initializing ptrs.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1995
    *p = (void*)obj;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1996
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1997
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1998
  void do_u4(u4* p) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1999
    intptr_t obj = nextPtr();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2000
    *p = (u4)(uintx(obj));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2001
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2002
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2003
  void do_tag(int tag) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2004
    int old_tag;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2005
    old_tag = (int)(intptr_t)nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2006
    // do_int(&old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2007
    assert(tag == old_tag, "old tag doesn't match");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2008
    FileMapInfo::assert_mark(tag == old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2009
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2010
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2011
  void do_oop(oop *p) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2012
    narrowOop o = (narrowOop)nextPtr();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2013
    if (o == 0 || !MetaspaceShared::open_archive_heap_region_mapped()) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2014
      p = NULL;
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2015
    } else {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2016
      assert(MetaspaceShared::is_heap_object_archiving_allowed(),
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2017
             "Archived heap object is not allowed");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2018
      assert(MetaspaceShared::open_archive_heap_region_mapped(),
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2019
             "Open archive heap region is not mapped");
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  2020
      *p = HeapShared::decode_with_archived_oop_encoding_mode(o);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2021
    }
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2022
  }
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  2023
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2024
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2025
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2026
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2027
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2028
    while (size > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2029
      *(intptr_t*)start = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2030
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2031
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2032
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2033
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2034
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2035
  bool reading() const { return true; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2036
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2037
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2038
// Return true if given address is in the misc data region
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2039
bool MetaspaceShared::is_in_shared_region(const void* p, int idx) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2040
  return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx);
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2041
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2042
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2043
bool MetaspaceShared::is_in_trampoline_frame(address addr) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2044
  if (UseSharedSpaces && is_in_shared_region(addr, MetaspaceShared::mc)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2045
    return true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2046
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2047
  return false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2048
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2049
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2050
// Map shared spaces at requested addresses and return if succeeded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2051
bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2052
  size_t image_alignment = mapinfo->alignment();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2053
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2054
#ifndef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2055
  // Map in the shared memory and then map the regions on top of it.
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2056
  // On Windows, don't map the memory here because it will cause the
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2057
  // mappings of the regions to fail.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2058
  ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2059
  if (!shared_rs.is_reserved()) return false;
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2060
#endif
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2061
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2062
  assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2063
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2064
  char* ro_base = NULL; char* ro_top;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2065
  char* rw_base = NULL; char* rw_top;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2066
  char* mc_base = NULL; char* mc_top;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2067
  char* md_base = NULL; char* md_top;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2068
  char* od_base = NULL; char* od_top;
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  2069
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2070
  // Map each shared region
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2071
  if ((mc_base = mapinfo->map_region(mc, &mc_top)) != NULL &&
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2072
      (rw_base = mapinfo->map_region(rw, &rw_top)) != NULL &&
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2073
      (ro_base = mapinfo->map_region(ro, &ro_top)) != NULL &&
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2074
      (md_base = mapinfo->map_region(md, &md_top)) != NULL &&
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2075
      (od_base = mapinfo->map_region(od, &od_top)) != NULL &&
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2076
      (image_alignment == (size_t)os::vm_allocation_granularity()) &&
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 49594
diff changeset
  2077
      mapinfo->validate_shared_path_table()) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2078
    // Success -- set up MetaspaceObj::_shared_metaspace_{base,top} for
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2079
    // fast checking in MetaspaceShared::is_in_shared_metaspace() and
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2080
    // MetaspaceObj::is_shared().
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2081
    //
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2082
    // We require that mc->rw->ro->md->od to be laid out consecutively, with no
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2083
    // gaps between them. That way, we can ensure that the OS won't be able to
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2084
    // allocate any new memory spaces inside _shared_metaspace_{base,top}, which
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2085
    // would mess up the simple comparision in MetaspaceShared::is_in_shared_metaspace().
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2086
    assert(mc_base < ro_base && mc_base < rw_base && mc_base < md_base && mc_base < od_base, "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2087
    assert(od_top  > ro_top  && od_top  > rw_top  && od_top  > md_top  && od_top  > mc_top , "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2088
    assert(mc_top == rw_base, "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2089
    assert(rw_top == ro_base, "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2090
    assert(ro_top == md_base, "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2091
    assert(md_top == od_base, "must be");
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2092
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2093
    MetaspaceObj::_shared_metaspace_base = (void*)mc_base;
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2094
    MetaspaceObj::_shared_metaspace_top  = (void*)od_top;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2095
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2096
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2097
    // If there was a failure in mapping any of the spaces, unmap the ones
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2098
    // that succeeded
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2099
    if (ro_base != NULL) mapinfo->unmap_region(ro);
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2100
    if (rw_base != NULL) mapinfo->unmap_region(rw);
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2101
    if (mc_base != NULL) mapinfo->unmap_region(mc);
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2102
    if (md_base != NULL) mapinfo->unmap_region(md);
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  2103
    if (od_base != NULL) mapinfo->unmap_region(od);
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2104
#ifndef _WINDOWS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2105
    // Release the entire mapped region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2106
    shared_rs.release();
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2107
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2108
    // If -Xshare:on is specified, print out the error message and exit VM,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2109
    // otherwise, set UseSharedSpaces to false and continue.
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27619
diff changeset
  2110
    if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2111
      vm_exit_during_initialization("Unable to use shared archive.", "Failed map_region for using -Xshare:on.");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2112
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2113
      FLAG_SET_DEFAULT(UseSharedSpaces, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2114
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2115
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2116
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2117
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2118
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2119
// Read the miscellaneous data from the shared file, and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2120
// serialize it out to its various destinations.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2121
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2122
void MetaspaceShared::initialize_shared_spaces() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2123
  FileMapInfo *mapinfo = FileMapInfo::current_info();
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2124
  _cds_i2i_entry_code_buffers = mapinfo->cds_i2i_entry_code_buffers();
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  2125
  _cds_i2i_entry_code_buffers_size = mapinfo->cds_i2i_entry_code_buffers_size();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2126
  _core_spaces_size = mapinfo->core_spaces_size();
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  2127
  char* buffer = mapinfo->misc_data_patching_start();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2128
  clone_cpp_vtables((intptr_t*)buffer);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  2129
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2130
  // The rest of the data is now stored in the RW region
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2131
  buffer = mapinfo->read_only_tables_start();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2132
  int sharedDictionaryLen = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2133
  buffer += sizeof(intptr_t);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  2134
  int number_of_entries = *(intptr_t*)buffer;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2135
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2136
  SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2137
                                          sharedDictionaryLen,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2138
                                          number_of_entries);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2139
  buffer += sharedDictionaryLen;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2140
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2141
  // The following data are the linked list elements
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2142
  // (HashtableEntry objects) for the shared dictionary table.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2143
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  2144
  int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2145
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2146
  buffer += len;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2147
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  2148
  // The table of archived java heap object sub-graph infos
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  2149
  buffer = HeapShared::read_archived_subgraph_infos(buffer);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50819
diff changeset
  2150
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2151
  // Verify various attributes of the archive, plus initialize the
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2152
  // shared string/symbol tables
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2153
  intptr_t* array = (intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2154
  ReadClosure rc(&array);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2155
  serialize(&rc);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2156
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2157
  // Initialize the run-time symbol table.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2158
  SymbolTable::create_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2159
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  2160
  mapinfo->patch_archived_heap_embedded_pointers();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  2161
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2162
  // Close the mapinfo file
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2163
  mapinfo->close();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2164
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2165
  if (PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2166
    if (PrintSharedDictionary) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2167
      tty->print_cr("\nShared classes:\n");
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46625
diff changeset
  2168
      SystemDictionary::print_shared(tty);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2169
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2170
    if (_archive_loading_failed) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2171
      tty->print_cr("archive is invalid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2172
      vm_exit(1);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2173
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2174
      tty->print_cr("archive is valid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2175
      vm_exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2176
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2177
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2178
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2179
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2180
// JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2181
bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2182
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2183
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2184
  if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2185
    // remap the shared readonly space to shared readwrite, private
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2186
    FileMapInfo* mapinfo = FileMapInfo::current_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2187
    if (!mapinfo->remap_shared_readonly_as_readwrite()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2188
      return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2189
    }
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
  2190
    _remapped_readwrite = true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2191
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2192
  return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2193
}
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2194
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2195
void MetaspaceShared::report_out_of_space(const char* name, size_t needed_bytes) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2196
  // This is highly unlikely to happen on 64-bits because we have reserved a 4GB space.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2197
  // On 32-bit we reserve only 256MB so you could run out of space with 100,000 classes
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2198
  // or so.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2199
  _mc_region.print_out_of_space_msg(name, needed_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2200
  _rw_region.print_out_of_space_msg(name, needed_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2201
  _ro_region.print_out_of_space_msg(name, needed_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2202
  _md_region.print_out_of_space_msg(name, needed_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2203
  _od_region.print_out_of_space_msg(name, needed_bytes);
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2204
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2205
  vm_exit_during_initialization(err_msg("Unable to allocate from '%s' region", name),
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2206
                                "Please reduce the number of shared classes.");
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2207
}