src/hotspot/share/memory/metaspaceShared.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58447 319173c62caa
child 59070 22ee476cc664
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
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
/*
53261
b7dca420fa0c 8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents: 52877
diff changeset
     2
 * Copyright (c) 2012, 2019, 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"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51796
diff changeset
    27
#include "classfile/classLoaderDataGraph.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    28
#include "classfile/classListParser.hpp"
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    29
#include "classfile/classLoaderExt.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "classfile/dictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "classfile/loaderConstraints.hpp"
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
    32
#include "classfile/javaClasses.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "classfile/placeholders.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "classfile/symbolTable.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46625
diff changeset
    35
#include "classfile/stringTable.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "classfile/systemDictionary.hpp"
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
    37
#include "classfile/systemDictionaryShared.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
#include "code/codeCache.hpp"
54371
72e44c1e7dc6 8221763: Build fails when using --with-jvm-features=-g1gc,-jfr,-shenandoahgc
aoqi
parents: 53884
diff changeset
    39
#include "gc/shared/softRefPolicy.hpp"
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
    40
#include "interpreter/bytecodeStream.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    41
#include "interpreter/bytecodes.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    42
#include "logging/log.hpp"
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    43
#include "logging/logMessage.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
#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
    45
#include "memory/heapShared.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
#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
    47
#include "memory/metaspaceClosure.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
#include "memory/metaspaceShared.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37179
diff changeset
    49
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54780
diff changeset
    50
#include "memory/universe.hpp"
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    51
#include "memory/dynamicArchive.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    52
#include "oops/compressedOops.inline.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    53
#include "oops/instanceClassLoaderKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    54
#include "oops/instanceMirrorKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    55
#include "oops/instanceRefKlass.hpp"
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    56
#include "oops/methodData.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    57
#include "oops/objArrayKlass.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    58
#include "oops/objArrayOop.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    59
#include "oops/oop.inline.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    60
#include "oops/typeArrayKlass.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    61
#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
    62
#include "runtime/handles.inline.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    63
#include "runtime/os.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49592
diff changeset
    64
#include "runtime/safepointVerifiers.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    65
#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
    66
#include "runtime/timerTrace.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    67
#include "runtime/vmThread.hpp"
52877
9e041366c764 8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents: 52811
diff changeset
    68
#include "runtime/vmOperations.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    69
#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
    70
#include "utilities/bitMap.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    71
#include "utilities/defaultStream.hpp"
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
    72
#include "utilities/hashtable.inline.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49931
diff changeset
    73
#if INCLUDE_G1GC
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    74
#include "gc/g1/g1CollectedHeap.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49481
diff changeset
    75
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    76
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    77
ReservedSpace MetaspaceShared::_shared_rs;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    78
VirtualSpace MetaspaceShared::_shared_vs;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    79
MetaspaceSharedStats MetaspaceShared::_stats;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    80
bool MetaspaceShared::_has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    81
bool MetaspaceShared::_archive_loading_failed = false;
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
    82
bool MetaspaceShared::_remapped_readwrite = false;
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
    83
address MetaspaceShared::_i2i_entry_code_buffers = NULL;
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
    84
size_t MetaspaceShared::_i2i_entry_code_buffers_size = 0;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    85
size_t MetaspaceShared::_core_spaces_size = 0;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    86
void* MetaspaceShared::_shared_metaspace_static_top = NULL;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    87
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    88
// 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
    89
//     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
    90
//     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
    91
//     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
    92
//     md  - misc data (the c++ vtables)
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    93
//
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
    94
//     ca0 - closed archive heap space #0
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
    95
//     ca1 - closed archive heap space #1 (may be empty)
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    96
//     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
    97
//     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
    98
//
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
    99
// The mc, rw, ro, and md regions are linearly allocated, starting from
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   100
// SharedBaseAddress, in the order of mc->rw->ro->md. The size of these 4 regions
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   101
// 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
   102
//
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   103
// These 4 regions are populated in the following steps:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   104
// [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
   105
//     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
   106
//     trampolines are written into the mc region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   107
// [2] ArchiveCompactor copies RW metadata into the rw region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   108
// [3] ArchiveCompactor copies RO metadata into the ro region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   109
// [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
   110
//     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
   111
// [5] C++ vtables are copied into the md region.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   112
//
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   113
// The s0/s1 and oa0/oa1 regions are populated inside HeapShared::archive_java_heap_objects.
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   114
// Their layout is independent of the other 4 regions.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   115
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   116
char* DumpRegion::expand_top_to(char* newtop) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   117
  assert(is_allocatable(), "must be initialized and not packed");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   118
  assert(newtop >= _top, "must not grow backwards");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   119
  if (newtop > _end) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   120
    MetaspaceShared::report_out_of_space(_name, newtop - _top);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   121
    ShouldNotReachHere();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   122
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   123
  uintx delta;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   124
  if (DynamicDumpSharedSpaces) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   125
    delta = DynamicArchive::object_delta_uintx(newtop);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   126
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   127
    delta = MetaspaceShared::object_delta_uintx(newtop);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   128
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   129
  if (delta > MAX_SHARED_DELTA) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   130
    // This is just a sanity check and should not appear in any real world usage. This
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   131
    // happens only if you allocate more than 2GB of shared objects and would require
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   132
    // millions of shared classes.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   133
    vm_exit_during_initialization("Out of memory in the CDS archive",
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   134
                                  "Please reduce the number of shared classes.");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   135
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   136
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   137
  MetaspaceShared::commit_shared_space_to(newtop);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   138
  _top = newtop;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   139
  return _top;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   140
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   141
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   142
char* DumpRegion::allocate(size_t num_bytes, size_t alignment) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   143
  char* p = (char*)align_up(_top, alignment);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   144
  char* newtop = p + align_up(num_bytes, alignment);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   145
  expand_top_to(newtop);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   146
  memset(p, 0, newtop - p);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   147
  return p;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   148
}
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   149
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   150
void DumpRegion::print(size_t total_bytes) const {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   151
  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,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   152
                _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()), p2i(_base));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   153
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   154
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   155
void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   156
  tty->print("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   157
             _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   158
  if (strcmp(_name, failing_region) == 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   159
    tty->print_cr(" required = %d", int(needed_bytes));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   160
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   161
    tty->cr();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   162
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   163
}
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   164
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   165
void DumpRegion::pack(DumpRegion* next) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   166
  assert(!is_packed(), "sanity");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   167
  _end = (char*)align_up(_top, Metaspace::reserve_alignment());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   168
  _is_packed = true;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   169
  if (next != NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   170
    next->_base = next->_top = this->_end;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   171
    next->_end = MetaspaceShared::shared_rs()->end();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   172
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   173
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   174
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   175
DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md");
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   176
size_t _total_closed_archive_region_size = 0, _total_open_archive_region_size = 0;
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   177
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   178
void MetaspaceShared::init_shared_dump_space(DumpRegion* first_space, address first_space_bottom) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   179
  // Start with 0 committed bytes. The memory will be committed as needed by
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   180
  // MetaspaceShared::commit_shared_space_to().
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   181
  if (!_shared_vs.initialize(_shared_rs, 0)) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   182
    vm_exit_during_initialization("Unable to allocate memory for shared space");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   183
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   184
  first_space->init(&_shared_rs, (char*)first_space_bottom);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   185
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   186
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   187
DumpRegion* MetaspaceShared::misc_code_dump_space() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   188
  return &_mc_region;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   189
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   190
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   191
DumpRegion* MetaspaceShared::read_write_dump_space() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   192
  return &_rw_region;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   193
}
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   194
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   195
DumpRegion* MetaspaceShared::read_only_dump_space() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   196
  return &_ro_region;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   197
}
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   198
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   199
void MetaspaceShared::pack_dump_space(DumpRegion* current, DumpRegion* next,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   200
                                      ReservedSpace* rs) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   201
  current->pack(next);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   202
}
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
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   212
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
   213
  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
   214
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   215
  // 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
   216
  // 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
   217
  // the addresses don't conflict)
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   218
  FileMapInfo* mapinfo = new FileMapInfo(true);
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   219
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   220
  // 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
   221
  // initialization fails, shared spaces [UseSharedSpaces] are
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   222
  // disabled and the file is closed.
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   223
  // Map in spaces now also
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   224
  if (mapinfo->initialize(true) && map_shared_spaces(mapinfo)) {
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   225
    size_t cds_total = core_spaces_size();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   226
    address cds_address = (address)mapinfo->region_addr(0);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   227
    char* cds_end = (char *)align_up(cds_address + cds_total,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   228
                                     Metaspace::reserve_alignment());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   229
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   230
    // Mapping the dynamic archive before allocating the class space
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   231
    cds_end = initialize_dynamic_runtime_shared_spaces((char*)cds_address, cds_end);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   232
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   233
#ifdef _LP64
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   234
    if (Metaspace::using_class_space()) {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   235
      // 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
   236
      // 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
   237
      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
   238
      // 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
   239
      // 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
   240
      mapinfo->map_heap_regions();
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   241
    }
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54371
diff changeset
   242
    CompressedKlassPointers::set_range(CompressedClassSpaceSize);
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   243
#endif // _LP64
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   244
  } else {
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   245
    assert(!mapinfo->is_open() && !UseSharedSpaces,
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   246
           "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
   247
  }
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
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   250
char* MetaspaceShared::initialize_dynamic_runtime_shared_spaces(
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   251
        char* static_start, char* static_end) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   252
  assert(UseSharedSpaces, "must be runtime");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   253
  char* cds_end = static_end;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   254
  if (!DynamicDumpSharedSpaces) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   255
    address dynamic_top = DynamicArchive::map();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   256
    if (dynamic_top != NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   257
      assert(dynamic_top > (address)static_start, "Unexpected layout");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   258
      MetaspaceObj::expand_shared_metaspace_range(dynamic_top);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   259
      cds_end = (char *)align_up(dynamic_top, Metaspace::reserve_alignment());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   260
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   261
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   262
  return cds_end;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   263
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   264
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   265
ReservedSpace* MetaspaceShared::reserve_shared_rs(size_t size, size_t alignment,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   266
                                                  bool large, char* requested_address) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   267
  if (requested_address != NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   268
    _shared_rs = ReservedSpace(size, alignment, large, requested_address);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   269
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   270
    _shared_rs = ReservedSpace(size, alignment, large);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   271
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   272
  return &_shared_rs;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   273
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   274
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   275
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
   276
  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
   277
  const size_t reserve_alignment = Metaspace::reserve_alignment();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   278
  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
   279
  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
   280
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   281
#ifdef _LP64
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   282
  // 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
   283
  // you're running in -Xshare:on mode:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   284
  //
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   285
  //                              +-- SharedBaseAddress (default = 0x800000000)
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   286
  //                              v
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   287
  // +-..---------+---------+ ... +----+----+----+----+---------------+
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   288
  // |    Heap    | Archive |     | MC | RW | RO | MD | class space   |
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   289
  // +-..---------+---------+ ... +----+----+----+----+---------------+
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
   290
  // |<--   MaxHeapSize  -->|     |<-- UnscaledClassSpaceMax = 4GB -->|
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   291
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   292
  const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   293
  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
   294
#else
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   295
  // 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
   296
  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
   297
#endif
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   298
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   299
  // First try to reserve the space at the specified SharedBaseAddress.
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   300
  //_shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages, shared_base);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   301
  reserve_shared_rs(cds_total, reserve_alignment, large_pages, shared_base);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   302
  if (_shared_rs.is_reserved()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   303
    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
   304
  } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   305
    // Get a mmap region anywhere if the SharedBaseAddress fails.
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   306
    //_shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   307
    reserve_shared_rs(cds_total, reserve_alignment, large_pages, NULL);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   308
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   309
  if (!_shared_rs.is_reserved()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   310
    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
   311
                                  err_msg(SIZE_FORMAT " bytes.", cds_total));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   312
  }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   313
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   314
#ifdef _LP64
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   315
  // 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
   316
  // + 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
   317
  //   will store Klasses into this space.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   318
  // + 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
   319
  //   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
   320
  //   then the RO parts.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   321
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   322
  assert(UseCompressedOops && UseCompressedClassPointers,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   323
      "UseCompressedOops and UseCompressedClassPointers must be set");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   324
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   325
  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
   326
  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
   327
  CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   328
  _shared_rs = _shared_rs.first_part(max_archive_size);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   329
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   330
  // Set up compress class pointers.
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54371
diff changeset
   331
  CompressedKlassPointers::set_base((address)_shared_rs.base());
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47574
diff changeset
   332
  // 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
   333
  // with AOT.
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54371
diff changeset
   334
  CompressedKlassPointers::set_shift(LogKlassAlignmentInBytes);
49481
8d02d496e785 8193266: AArch64: TestOptionsWithRanges.java SIGSEGV
smonteith
parents: 49480
diff changeset
   335
  // Set the range of klass addresses to 4GB.
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54371
diff changeset
   336
  CompressedKlassPointers::set_range(cds_total);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   337
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   338
  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
   339
  log_info(cds)("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54371
diff changeset
   340
                p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   341
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
   342
  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
   343
                CompressedClassSpaceSize, p2i(tmp_class_space.base()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   344
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   345
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   346
  init_shared_dump_space(&_mc_region);
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   347
  SharedBaseAddress = (size_t)_shared_rs.base();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   348
  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
   349
                _shared_rs.size(), p2i(_shared_rs.base()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   350
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   351
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   352
// Called by universe_post_init()
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   353
void MetaspaceShared::post_initialize(TRAPS) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   354
  if (UseSharedSpaces) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   355
    int size = FileMapInfo::get_number_of_shared_paths();
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   356
    if (size > 0) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   357
      SystemDictionaryShared::allocate_shared_data_arrays(size, THREAD);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   358
      if (!DynamicDumpSharedSpaces) {
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   359
        FileMapInfo* info;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   360
        if (FileMapInfo::dynamic_info() == NULL) {
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   361
          info = FileMapInfo::current_info();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   362
        } else {
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   363
          info = FileMapInfo::dynamic_info();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   364
        }
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   365
        ClassLoaderExt::init_paths_start_index(info->app_class_paths_start_index());
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   366
        ClassLoaderExt::init_app_module_paths_start_index(info->app_module_paths_start_index());
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   367
      }
50039
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
}
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   371
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   372
static GrowableArray<Handle>* _extra_interned_strings = NULL;
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   373
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   374
void MetaspaceShared::read_extra_data(const char* filename, TRAPS) {
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   375
  _extra_interned_strings = new (ResourceObj::C_HEAP, mtInternal)GrowableArray<Handle>(10000, true);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   376
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   377
  HashtableTextDump reader(filename);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   378
  reader.check_version("VERSION: 1.0");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   379
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   380
  while (reader.remain() > 0) {
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   381
    int utf8_length;
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   382
    int prefix_type = reader.scan_prefix(&utf8_length);
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   383
    ResourceMark rm(THREAD);
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   384
    if (utf8_length == 0x7fffffff) {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   385
      // buf_len will overflown 32-bit value.
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   386
      vm_exit_during_initialization(err_msg("string length too large: %d", utf8_length));
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   387
    }
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   388
    int buf_len = utf8_length+1;
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   389
    char* utf8_buffer = NEW_RESOURCE_ARRAY(char, buf_len);
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   390
    reader.get_utf8(utf8_buffer, utf8_length);
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   391
    utf8_buffer[utf8_length] = '\0';
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   392
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   393
    if (prefix_type == HashtableTextDump::SymbolPrefix) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   394
      SymbolTable::new_permanent_symbol(utf8_buffer);
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   395
    } else{
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   396
      assert(prefix_type == HashtableTextDump::StringPrefix, "Sanity");
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   397
      oop s = StringTable::intern(utf8_buffer, THREAD);
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   398
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   399
      if (HAS_PENDING_EXCEPTION) {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   400
        log_warning(cds, heap)("[line %d] extra interned string allocation failed; size too large: %d",
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   401
                               reader.last_line_no(), utf8_length);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   402
        CLEAR_PENDING_EXCEPTION;
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   403
      } else {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   404
#if INCLUDE_G1GC
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   405
        if (UseG1GC) {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   406
          typeArrayOop body = java_lang_String::value(s);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   407
          const HeapRegion* hr = G1CollectedHeap::heap()->heap_region_containing(body);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   408
          if (hr->is_humongous()) {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   409
            // Don't keep it alive, so it will be GC'ed before we dump the strings, in order
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   410
            // to maximize free heap space and minimize fragmentation.
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   411
            log_warning(cds, heap)("[line %d] extra interned string ignored; size too large: %d",
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   412
                                reader.last_line_no(), utf8_length);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   413
            continue;
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   414
          }
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   415
        }
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   416
#endif
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   417
        // Interned strings are GC'ed if there are no references to it, so let's
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   418
        // add a reference to keep this string alive.
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   419
        assert(s != NULL, "must succeed");
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   420
        Handle h(THREAD, s);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   421
        _extra_interned_strings->append(h);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
   422
      }
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   423
    }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   424
  }
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   425
}
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49982
diff changeset
   426
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   427
void MetaspaceShared::commit_shared_space_to(char* newtop) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 58278
diff changeset
   428
  Arguments::assert_is_dumping_archive();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   429
  char* base = _shared_rs.base();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   430
  size_t need_committed_size = newtop - base;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   431
  size_t has_committed_size = _shared_vs.committed_size();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   432
  if (need_committed_size < has_committed_size) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   433
    return;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   434
  }
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   435
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   436
  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
   437
  size_t preferred_bytes = 1 * M;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   438
  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
   439
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   440
  size_t commit =MAX2(min_bytes, preferred_bytes);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   441
  commit = MIN2(commit, uncommitted);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   442
  assert(commit <= uncommitted, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   443
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   444
  bool result = _shared_vs.expand_by(commit, false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   445
  if (!result) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   446
    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
   447
                                          need_committed_size));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   448
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   449
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   450
  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
   451
                commit, _shared_vs.actual_committed_size(), _shared_vs.high());
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   452
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   453
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   454
// 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
   455
// miscellaneous data from/to the shared archive file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   456
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   457
void MetaspaceShared::serialize(SerializeClosure* soc) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   458
  int tag = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   459
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   460
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   461
  // Verify the sizes of various metadata in the system.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   462
  soc->do_tag(sizeof(Method));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   463
  soc->do_tag(sizeof(ConstMethod));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   464
  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
   465
  soc->do_tag(sizeof(ConstantPool));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   466
  soc->do_tag(sizeof(ConstantPoolCache));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   467
  soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   468
  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
   469
  soc->do_tag(sizeof(Symbol));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   470
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   471
  // Dump/restore miscellaneous metadata.
51554
5b0d86499960 8209958: Clean up duplicate basic array type statics in Universe
coleenp
parents: 51491
diff changeset
   472
  Universe::serialize(soc);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   473
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   474
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   475
  // Dump/restore references to commonly used names and signatures.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   476
  vmSymbols::serialize(soc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   477
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   478
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
   479
  // Dump/restore the symbol/string/subgraph_info tables
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
   480
  SymbolTable::serialize_shared_table_header(soc);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
   481
  StringTable::serialize_shared_table_header(soc);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
   482
  HeapShared::serialize_subgraph_info_table_header(soc);
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   483
  SystemDictionaryShared::serialize_dictionary_headers(soc);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   484
51417
b08c2a94cce1 8206115: Use shared macros for JavaClasses::compute_offsets and MetaspaceShared::serialize_well_known_classes
iklam
parents: 51371
diff changeset
   485
  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
   486
  InstanceMirrorKlass::serialize_offsets(soc);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   487
  soc->do_tag(--tag);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   488
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   489
  serialize_cloned_cpp_vtptrs(soc);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   490
  soc->do_tag(--tag);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   491
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   492
  soc->do_tag(666);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   493
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   494
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   495
address MetaspaceShared::i2i_entry_code_buffers(size_t 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
   496
  if (DumpSharedSpaces) {
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   497
    if (_i2i_entry_code_buffers == NULL) {
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   498
      _i2i_entry_code_buffers = (address)misc_code_space_alloc(total_size);
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   499
      _i2i_entry_code_buffers_size = 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
   500
    }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   501
  } else if (UseSharedSpaces) {
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   502
    assert(_i2i_entry_code_buffers != NULL, "must already been initialized");
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   503
  } else {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   504
    return NULL;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   505
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   506
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   507
  assert(_i2i_entry_code_buffers_size == total_size, "must not change");
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
   508
  return _i2i_entry_code_buffers;
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   509
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   511
uintx MetaspaceShared::object_delta_uintx(void* obj) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 58278
diff changeset
   512
  Arguments::assert_is_dumping_archive();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   513
  if (DumpSharedSpaces) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   514
    assert(shared_rs()->contains(obj), "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   515
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   516
    assert(is_in_shared_metaspace(obj) || DynamicArchive::is_in_target_space(obj), "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   517
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   518
  address base_address = address(SharedBaseAddress);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   519
  uintx deltax = address(obj) - base_address;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   520
  return deltax;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   521
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   522
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   523
// 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
   524
// 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
   525
static GrowableArray<Klass*>* _global_klass_objects;
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   526
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   527
GrowableArray<Klass*>* MetaspaceShared::collected_klasses() {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   528
  return _global_klass_objects;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   529
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   530
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   531
static void collect_array_classes(Klass* k) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   532
  _global_klass_objects->append_if_missing(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   533
  if (k->is_array_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   534
    // Add in the array classes too
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   535
    ArrayKlass* ak = ArrayKlass::cast(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   536
    Klass* h = ak->higher_dimension();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   537
    if (h != NULL) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   538
      h->array_klasses_do(collect_array_classes);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   539
    }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   540
  }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   541
}
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   542
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   543
class CollectClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   544
  void do_klass(Klass* k) {
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   545
    if (k->is_instance_klass() &&
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   546
        SystemDictionaryShared::is_excluded_class(InstanceKlass::cast(k))) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   547
      // Don't add to the _global_klass_objects
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   548
    } else {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
   549
      _global_klass_objects->append_if_missing(k);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   550
    }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   551
    if (k->is_array_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   552
      // Add in the array classes too
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   553
      ArrayKlass* ak = ArrayKlass::cast(k);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   554
      Klass* h = ak->higher_dimension();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   555
      if (h != NULL) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   556
        h->array_klasses_do(collect_array_classes);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   557
      }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   558
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   559
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   560
};
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   561
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   562
static void remove_unshareable_in_classes() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   563
  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
   564
    Klass* k = _global_klass_objects->at(i);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   565
    if (!k->is_objArray_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   566
      // 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
   567
      // on their array classes.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   568
      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
   569
      k->remove_unshareable_info();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   570
    }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   571
  }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   572
}
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   573
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   574
static void remove_java_mirror_in_classes() {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   575
  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
   576
    Klass* k = _global_klass_objects->at(i);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   577
    if (!k->is_objArray_klass()) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   578
      // 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
   579
      // on their array classes.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   580
      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
   581
      k->remove_java_mirror();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   582
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   583
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   584
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   585
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   586
static void clear_basic_type_mirrors() {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   587
  assert(!HeapShared::is_heap_object_archiving_allowed(), "Sanity");
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   588
  Universe::set_int_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   589
  Universe::set_float_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   590
  Universe::set_double_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   591
  Universe::set_byte_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   592
  Universe::set_bool_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   593
  Universe::set_char_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   594
  Universe::set_long_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   595
  Universe::set_short_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   596
  Universe::set_void_mirror(NULL);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   597
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   598
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
   599
static void rewrite_nofast_bytecode(const methodHandle& method) {
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   600
  BytecodeStream bcs(method);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   601
  while (!bcs.is_last_bytecode()) {
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
   602
    Bytecodes::Code opcode = bcs.next();
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   603
    switch (opcode) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   604
    case Bytecodes::_getfield:      *bcs.bcp() = Bytecodes::_nofast_getfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   605
    case Bytecodes::_putfield:      *bcs.bcp() = Bytecodes::_nofast_putfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   606
    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
   607
    case Bytecodes::_iload: {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   608
      if (!bcs.is_wide()) {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   609
        *bcs.bcp() = Bytecodes::_nofast_iload;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   610
      }
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   611
      break;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   612
    }
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   613
    default: break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   614
    }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   615
  }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   616
}
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   617
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   618
// 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
   619
// run time. This includes:
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   620
// [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
   621
//     at run time by RewriteBytecodes/RewriteFrequentPairs
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   622
// [2] Assign a fingerprint, so one doesn't need to be assigned at run-time.
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
   623
static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   624
  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
   625
    Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   626
    if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   627
      InstanceKlass* ik = InstanceKlass::cast(k);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
   628
      MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(thread, ik);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   629
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   630
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   631
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   632
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
   633
void MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik) {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   634
  for (int i = 0; i < ik->methods()->length(); i++) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
   635
    methodHandle m(thread, ik->methods()->at(i));
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   636
    rewrite_nofast_bytecode(m);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   637
    Fingerprinter fp(m);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   638
    // The side effect of this call sets method's fingerprint field.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   639
    fp.fingerprint();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   640
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   641
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   642
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   643
// 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
   644
// (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
   645
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   646
// 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
   647
// 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
   648
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   649
// 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
   650
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   651
// + 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
   652
//                  the CDS image
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   653
// + 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
   654
//                  into our own tables.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   655
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   656
// 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
   657
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   658
  f(ConstantPool) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   659
  f(InstanceKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   660
  f(InstanceClassLoaderKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   661
  f(InstanceMirrorKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   662
  f(InstanceRefKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   663
  f(Method) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   664
  f(ObjArrayKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   665
  f(TypeArrayKlass)
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
class CppVtableInfo {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   668
  intptr_t _vtable_size;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   669
  intptr_t _cloned_vtable[1];
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   670
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   671
  static int num_slots(int vtable_size) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   672
    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
   673
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   674
  int vtable_size()           { return int(uintx(_vtable_size)); }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   675
  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
   676
  intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   677
  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
   678
  // 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
   679
  static size_t byte_size(int vtable_size) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   680
    CppVtableInfo i;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   681
    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
   682
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   683
};
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   684
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   685
template <class T> class CppVtableCloner : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   686
  static intptr_t* vtable_of(Metadata& m) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   687
    return *((intptr_t**)&m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   688
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   689
  static CppVtableInfo* _info;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   690
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   691
  static int get_vtable_length(const char* name);
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
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   694
  // 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
   695
  static intptr_t* allocate(const char* name);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   696
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   697
  // Clone the vtable to ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   698
  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
   699
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   700
  static void zero_vtable_clone() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   701
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   702
    _info->zero();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   703
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   704
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   705
  // 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
   706
  static void patch(Metadata* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   707
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   708
    *(void**)obj = (void*)(_info->cloned_vtable());
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   709
  }
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
  static bool is_valid_shared_object(const T* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   712
    intptr_t* vptr = *(intptr_t**)obj;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   713
    return vptr == _info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   714
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   715
};
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> CppVtableInfo* CppVtableCloner<T>::_info = NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   718
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   719
template <class T>
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   720
intptr_t* CppVtableCloner<T>::allocate(const char* name) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   721
  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
   722
  int n = get_vtable_length(name);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   723
  _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
   724
  _info->set_vtable_size(n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   725
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   726
  intptr_t* p = clone_vtable(name, _info);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   727
  assert((char*)p == _md_region.top(), "must be");
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   728
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   729
  return _info->cloned_vtable();
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   730
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   731
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   732
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   733
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
   734
  if (!DumpSharedSpaces) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   735
    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
   736
    _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
   737
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   738
  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
   739
  int n = info->vtable_size();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   740
  intptr_t* srcvtable = vtable_of(tmp);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   741
  intptr_t* dstvtable = info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   742
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   743
  // 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
   744
  // safe to do memcpy.
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   745
  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
   746
  memcpy(dstvtable, srcvtable, sizeof(intptr_t) * n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   747
  return dstvtable + n;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   748
}
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
// 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
   751
// trick by declaring 2 subclasses:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   752
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   753
//   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
   754
//   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
   755
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   756
// CppVtableTesterA and CppVtableTesterB's vtables have the following properties:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   757
// - 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
   758
// - 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
   759
// - Their last entry is different.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   760
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   761
// 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
   762
// and find the first entry that's different.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   763
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   764
// 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
   765
// esoteric compilers.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   766
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   767
template <class T> class CppVtableTesterB: public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   768
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   769
  virtual int last_virtual_method() {return 1;}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   770
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   771
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   772
template <class T> class CppVtableTesterA : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   773
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   774
  virtual void* last_virtual_method() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   775
    // 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
   776
    // compiler/linker won't alias the two functions.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   777
    return NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   778
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   779
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   780
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   781
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   782
int CppVtableCloner<T>::get_vtable_length(const char* name) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   783
  CppVtableTesterA<T> a;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   784
  CppVtableTesterB<T> b;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   785
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   786
  intptr_t* avtable = vtable_of(a);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   787
  intptr_t* bvtable = vtable_of(b);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   788
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   789
  // 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
   790
  int vtable_len = 1;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   791
  for (; ; vtable_len++) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   792
    if (avtable[vtable_len] != bvtable[vtable_len]) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   793
      break;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   794
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   795
  }
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   796
  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
   797
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   798
  return vtable_len;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   799
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   800
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   801
#define ALLOC_CPP_VTABLE_CLONE(c) \
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   802
  _cloned_cpp_vtptrs[c##_Kind] = CppVtableCloner<c>::allocate(#c);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   803
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   804
#define CLONE_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   805
  p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   806
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   807
#define ZERO_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   808
 CppVtableCloner<c>::zero_vtable_clone();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   809
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   810
//------------------------------ for DynamicDumpSharedSpaces - start
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   811
#define DECLARE_CLONED_VTABLE_KIND(c) c ## _Kind,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   812
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   813
enum {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   814
  CPP_VTABLE_PATCH_TYPES_DO(DECLARE_CLONED_VTABLE_KIND)
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   815
  _num_cloned_vtable_kinds
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   816
};
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   817
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   818
static intptr_t** _cloned_cpp_vtptrs = NULL;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   819
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   820
void MetaspaceShared::serialize_cloned_cpp_vtptrs(SerializeClosure* soc) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   821
  soc->do_ptr((void**)&_cloned_cpp_vtptrs);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   822
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   823
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   824
intptr_t* MetaspaceShared::fix_cpp_vtable_for_dynamic_archive(MetaspaceObj::Type msotype, address obj) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   825
  assert(DynamicDumpSharedSpaces, "must");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   826
  int kind = -1;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   827
  switch (msotype) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   828
  case MetaspaceObj::SymbolType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   829
  case MetaspaceObj::TypeArrayU1Type:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   830
  case MetaspaceObj::TypeArrayU2Type:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   831
  case MetaspaceObj::TypeArrayU4Type:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   832
  case MetaspaceObj::TypeArrayU8Type:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   833
  case MetaspaceObj::TypeArrayOtherType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   834
  case MetaspaceObj::ConstMethodType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   835
  case MetaspaceObj::ConstantPoolCacheType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   836
  case MetaspaceObj::AnnotationsType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   837
  case MetaspaceObj::MethodCountersType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   838
    // These have no vtables.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   839
    break;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   840
  case MetaspaceObj::ClassType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   841
    {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   842
      Klass* k = (Klass*)obj;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   843
      assert(k->is_klass(), "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   844
      if (k->is_instance_klass()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   845
        kind = InstanceKlass_Kind;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   846
      } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   847
        assert(k->is_objArray_klass(),
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   848
               "We shouldn't archive any other klasses in DynamicDumpSharedSpaces");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   849
        kind = ObjArrayKlass_Kind;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   850
      }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   851
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   852
    break;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   853
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   854
  case MetaspaceObj::MethodType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   855
    {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   856
      Method* m = (Method*)obj;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   857
      assert(m->is_method(), "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   858
      kind = Method_Kind;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   859
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   860
    break;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   861
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   862
  case MetaspaceObj::MethodDataType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   863
    // We don't archive MethodData <-- should have been removed in removed_unsharable_info
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   864
    ShouldNotReachHere();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   865
    break;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   866
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   867
  case MetaspaceObj::ConstantPoolType:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   868
    {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   869
      ConstantPool *cp = (ConstantPool*)obj;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   870
      assert(cp->is_constantPool(), "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   871
      kind = ConstantPool_Kind;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   872
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   873
    break;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   874
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   875
  default:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   876
    ShouldNotReachHere();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   877
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   878
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   879
  if (kind >= 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   880
    assert(kind < _num_cloned_vtable_kinds, "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   881
    return _cloned_cpp_vtptrs[kind];
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   882
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   883
    return NULL;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   884
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   885
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   886
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   887
//------------------------------ for DynamicDumpSharedSpaces - end
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   888
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   889
// 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
   890
intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   891
  assert(DumpSharedSpaces || UseSharedSpaces, "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   892
  CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   893
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   894
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   895
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   896
void MetaspaceShared::zero_cpp_vtable_clones_for_writing() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   897
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   898
  CPP_VTABLE_PATCH_TYPES_DO(ZERO_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   899
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   900
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   901
// 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
   902
void MetaspaceShared::allocate_cpp_vtable_clones() {
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   903
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   904
  // Layout (each slot is a intptr_t):
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   905
  //   [number of slots in the first vtable = n1]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   906
  //   [ <n1> slots for the first vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   907
  //   [number of slots in the first second = n2]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   908
  //   [ <n2> slots for the second vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   909
  //   ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   910
  // 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
   911
  CPP_VTABLE_PATCH_TYPES_DO(ALLOC_CPP_VTABLE_CLONE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   912
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   913
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   914
// 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
   915
// vtable pointer is in first slot in object.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   916
void MetaspaceShared::patch_cpp_vtable_pointers() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   917
  int n = _global_klass_objects->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   918
  for (int i = 0; i < n; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   919
    Klass* obj = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   920
    if (obj->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   921
      InstanceKlass* ik = InstanceKlass::cast(obj);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   922
      if (ik->is_class_loader_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   923
        CppVtableCloner<InstanceClassLoaderKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   924
      } else if (ik->is_reference_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   925
        CppVtableCloner<InstanceRefKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   926
      } else if (ik->is_mirror_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   927
        CppVtableCloner<InstanceMirrorKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   928
      } else {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   929
        CppVtableCloner<InstanceKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   930
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   931
      ConstantPool* cp = ik->constants();
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   932
      CppVtableCloner<ConstantPool>::patch(cp);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   933
      for (int j = 0; j < ik->methods()->length(); j++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   934
        Method* m = ik->methods()->at(j);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   935
        CppVtableCloner<Method>::patch(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   936
        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
   937
      }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   938
    } else if (obj->is_objArray_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   939
      CppVtableCloner<ObjArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   940
    } else {
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   941
      assert(obj->is_typeArray_klass(), "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   942
      CppVtableCloner<TypeArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   943
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   944
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   945
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   946
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   947
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
   948
  assert(is_in_shared_metaspace(m), "must be");
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   949
  return CppVtableCloner<Method>::is_valid_shared_object(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   950
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   951
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   952
void WriteClosure::do_oop(oop* o) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   953
  if (*o == NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   954
    _dump_region->append_intptr_t(0);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   955
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   956
    assert(HeapShared::is_heap_object_archiving_allowed(),
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   957
           "Archiving heap object is not allowed");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   958
    _dump_region->append_intptr_t(
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   959
      (intptr_t)CompressedOops::encode_not_null(*o));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   960
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   961
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   962
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   963
void WriteClosure::do_region(u_char* start, size_t size) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   964
  assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   965
  assert(size % sizeof(intptr_t) == 0, "bad size");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   966
  do_tag((int)size);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   967
  while (size > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   968
    _dump_region->append_intptr_t(*(intptr_t*)start);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   969
    start += sizeof(intptr_t);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   970
    size -= sizeof(intptr_t);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
   971
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
   972
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   973
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   974
// This is for dumping detailed statistics for the allocations
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   975
// in the shared spaces.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   976
class DumpAllocStats : public ResourceObj {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   977
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   978
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   979
  // Here's poor man's enum inheritance
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   980
#define SHAREDSPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   981
  METASPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   982
  f(SymbolHashentry) \
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   983
  f(SymbolBucket) \
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   984
  f(StringHashentry) \
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   985
  f(StringBucket) \
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   986
  f(Other)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   987
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   988
  enum Type {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   989
    // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   990
    SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE)
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   991
    _number_of_types
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   992
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   993
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   994
  static const char * type_name(Type type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   995
    switch(type) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   996
    SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE)
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   997
    default:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   998
      ShouldNotReachHere();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   999
      return NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1000
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1001
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1002
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1003
public:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1004
  enum { RO = 0, RW = 1 };
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1005
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1006
  int _counts[2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1007
  int _bytes [2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1008
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1009
  DumpAllocStats() {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1010
    memset(_counts, 0, sizeof(_counts));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1011
    memset(_bytes,  0, sizeof(_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1012
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1013
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1014
  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
  1015
    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
  1016
    int which = (read_only) ? RO : RW;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1017
    _counts[which][type] ++;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1018
    _bytes [which][type] += byte_size;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1019
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1020
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1021
  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
  1022
    int which = (read_only) ? RO : RW;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1023
    _bytes [which][OtherType] += byte_size;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1024
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1025
  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
  1026
};
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1027
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1028
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
  1029
  // 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
  1030
  MetaspaceSharedStats *stats = MetaspaceShared::stats();
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1031
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1032
  // symbols
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1033
  _counts[RO][SymbolHashentryType] = stats->symbol.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1034
  _bytes [RO][SymbolHashentryType] = stats->symbol.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1035
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1036
  _counts[RO][SymbolBucketType] = stats->symbol.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1037
  _bytes [RO][SymbolBucketType] = stats->symbol.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1038
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1039
  // strings
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1040
  _counts[RO][StringHashentryType] = stats->string.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1041
  _bytes [RO][StringHashentryType] = stats->string.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1042
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1043
  _counts[RO][StringBucketType] = stats->string.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1044
  _bytes [RO][StringBucketType] = stats->string.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1045
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1046
  // TODO: count things like dictionary, vtable, etc
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1047
  _bytes[RW][OtherType] += mc_all + md_all;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1048
  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
  1049
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1050
  // prevent divide-by-zero
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1051
  if (ro_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1052
    ro_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1053
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1054
  if (rw_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1055
    rw_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1056
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1057
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1058
  int all_ro_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1059
  int all_ro_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1060
  int all_rw_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1061
  int all_rw_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1062
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
  1063
// 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
  1064
#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
  1065
  const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1066
  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
  1067
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1068
  LogMessage(cds) msg;
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1069
55296
357c9dcb6eb9 8224497: Remove FIXME in metaspaceClosure.cpp
ccheung
parents: 55251
diff changeset
  1070
  msg.info("Detailed metadata info (excluding st regions; rw stats include md/mc regions):");
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1071
  msg.info("%s", hdr);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1072
  msg.info("%s", sep);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1073
  for (int type = 0; type < int(_number_of_types); type ++) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1074
    const char *name = type_name((Type)type);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1075
    int ro_count = _counts[RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1076
    int ro_bytes = _bytes [RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1077
    int rw_count = _counts[RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1078
    int rw_bytes = _bytes [RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1079
    int count = ro_count + rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1080
    int bytes = ro_bytes + rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1081
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1082
    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
  1083
    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
  1084
    double perc    = percent_of(bytes, ro_all + rw_all);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1085
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1086
    msg.info(fmt_stats, name,
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1087
                         ro_count, ro_bytes, ro_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1088
                         rw_count, rw_bytes, rw_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1089
                         count, bytes, perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1090
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1091
    all_ro_count += ro_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1092
    all_ro_bytes += ro_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1093
    all_rw_count += rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1094
    all_rw_bytes += rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1095
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1096
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1097
  int all_count = all_ro_count + all_rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1098
  int all_bytes = all_ro_bytes + all_rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1099
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1100
  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
  1101
  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
  1102
  double all_perc    = percent_of(all_bytes, ro_all + rw_all);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1103
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1104
  msg.info("%s", sep);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 48794
diff changeset
  1105
  msg.info(fmt_stats, "Total",
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1106
                       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
  1107
                       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
  1108
                       all_count, all_bytes, all_perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1109
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1110
  assert(all_ro_bytes == ro_all, "everything should have been counted");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1111
  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
  1112
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
  1113
#undef fmt_stats
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1114
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1115
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1116
// Populate the shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1117
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1118
class VM_PopulateDumpSharedSpace: public VM_Operation {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1119
private:
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1120
  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
  1121
  GrowableArray<MemRegion> *_open_archive_heap_regions;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1122
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1123
  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
  1124
  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
  1125
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1126
  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
  1127
  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
  1128
  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
  1129
                                 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
  1130
  void dump_symbols();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1131
  char* dump_read_only_tables();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1132
  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
  1133
  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
  1134
                               const char *name, const size_t total_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1135
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1136
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1137
  VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1138
  void doit();   // outline because gdb sucks
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1139
  static void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region, bool read_only,  bool allow_exec) {
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1140
    mapinfo->write_region(region_idx, dump_region->base(), dump_region->used(), read_only, allow_exec);
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1141
  }
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
  1142
  bool allow_nested_vm_operations() const { return true; }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1143
}; // class VM_PopulateDumpSharedSpace
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1144
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1145
class SortedSymbolClosure: public SymbolClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1146
  GrowableArray<Symbol*> _symbols;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1147
  virtual void do_symbol(Symbol** sym) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1148
    assert((*sym)->is_permanent(), "archived symbols must be permanent");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1149
    _symbols.append(*sym);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1150
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1151
  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
  1152
    if (a[0] < b[0]) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1153
      return -1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1154
    } else if (a[0] == b[0]) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1155
      return 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1156
    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1157
      return 1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1158
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1159
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1160
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1161
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1162
  SortedSymbolClosure() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1163
    SymbolTable::symbols_do(this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1164
    _symbols.sort(compare_symbols_by_address);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1165
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1166
  GrowableArray<Symbol*>* get_sorted_symbols() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1167
    return &_symbols;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1168
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1169
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1170
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1171
// ArchiveCompactor --
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1172
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1173
// 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
  1174
// 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
  1175
// 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
  1176
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1177
class ArchiveCompactor : AllStatic {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1178
  static const int INITIAL_TABLE_SIZE = 8087;
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1179
  static const int MAX_TABLE_SIZE     = 1000000;
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1180
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1181
  static DumpAllocStats* _alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1182
  static SortedSymbolClosure* _ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1183
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1184
  typedef KVHashtable<address, address, mtInternal> RelocationTable;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1185
  static RelocationTable* _new_loc_table;
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
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1188
  static void initialize() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1189
    _alloc_stats = new(ResourceObj::C_HEAP, mtInternal)DumpAllocStats;
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1190
    _new_loc_table = new RelocationTable(INITIAL_TABLE_SIZE);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1191
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1192
  static DumpAllocStats* alloc_stats() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1193
    return _alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1194
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1195
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1196
  // Use this when you allocate space with MetaspaceShare::read_only_space_alloc()
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1197
  // outside of ArchiveCompactor::allocate(). These are usually for misc tables
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1198
  // that are allocated in the RO space.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1199
  class OtherROAllocMark {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1200
    char* _oldtop;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1201
  public:
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1202
    OtherROAllocMark() {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1203
      _oldtop = _ro_region.top();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1204
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1205
    ~OtherROAllocMark() {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1206
      char* newtop = _ro_region.top();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1207
      ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - _oldtop), true);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1208
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1209
  };
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1210
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1211
  static void allocate(MetaspaceClosure::Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1212
    address obj = ref->obj();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1213
    int bytes = ref->size() * BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1214
    char* p;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1215
    size_t alignment = BytesPerWord;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1216
    char* oldtop;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1217
    char* newtop;
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
    if (read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1220
      oldtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1221
      p = _ro_region.allocate(bytes, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1222
      newtop = _ro_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1223
    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1224
      oldtop = _rw_region.top();
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1225
      if (ref->msotype() == MetaspaceObj::ClassType) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1226
        // Save a pointer immediate in front of an InstanceKlass, so
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1227
        // we can do a quick lookup from InstanceKlass* -> RunTimeSharedClassInfo*
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1228
        // without building another hashtable. See RunTimeSharedClassInfo::get_for()
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1229
        // in systemDictionaryShared.cpp.
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1230
        Klass* klass = (Klass*)obj;
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1231
        if (klass->is_instance_klass()) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1232
          SystemDictionaryShared::validate_before_archiving(InstanceKlass::cast(klass));
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1233
          _rw_region.allocate(sizeof(address), BytesPerWord);
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1234
        }
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1235
      }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1236
      p = _rw_region.allocate(bytes, alignment);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1237
      newtop = _rw_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1238
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1239
    memcpy(p, obj, bytes);
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1240
    assert(_new_loc_table->lookup(obj) == NULL, "each object can be relocated at most once");
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1241
    _new_loc_table->add(obj, (address)p);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1242
    log_trace(cds)("Copy: " PTR_FORMAT " ==> " PTR_FORMAT " %d", p2i(obj), p2i(p), bytes);
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1243
    if (_new_loc_table->maybe_grow(MAX_TABLE_SIZE)) {
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1244
      log_info(cds, hashtables)("Expanded _new_loc_table to %d", _new_loc_table->table_size());
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1245
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1246
    _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
  1247
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1248
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1249
  static address get_new_loc(MetaspaceClosure::Ref* ref) {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1250
    address* pp = _new_loc_table->lookup(ref->obj());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1251
    assert(pp != NULL, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1252
    return *pp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1253
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1254
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1255
private:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1256
  // Makes a shallow copy of visited MetaspaceObj's
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1257
  class ShallowCopier: public UniqueMetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1258
    bool _read_only;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1259
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1260
    ShallowCopier(bool read_only) : _read_only(read_only) {}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1261
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1262
    virtual bool do_unique_ref(Ref* ref, bool read_only) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1263
      if (read_only == _read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1264
        allocate(ref, read_only);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1265
      }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1266
      return true; // recurse into ref.obj()
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1267
    }
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
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1270
  // Relocate embedded pointers within a MetaspaceObj's shallow copy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1271
  class ShallowCopyEmbeddedRefRelocator: public UniqueMetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1272
  public:
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1273
    virtual bool do_unique_ref(Ref* ref, bool read_only) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1274
      address new_loc = get_new_loc(ref);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1275
      RefRelocator refer;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1276
      ref->metaspace_pointers_do_at(&refer, new_loc);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1277
      return true; // recurse into ref.obj()
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1278
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1279
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1280
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1281
  // Relocate a reference to point to its shallow copy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1282
  class RefRelocator: public MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1283
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1284
    virtual bool do_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1285
      if (ref->not_null()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1286
        ref->update(get_new_loc(ref));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1287
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1288
      return false; // Do not recurse.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1289
    }
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
#ifdef ASSERT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1293
  class IsRefInArchiveChecker: public MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1294
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1295
    virtual bool do_ref(Ref* ref, bool read_only) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1296
      if (ref->not_null()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1297
        char* obj = (char*)ref->obj();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1298
        assert(_ro_region.contains(obj) || _rw_region.contains(obj),
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1299
               "must be relocated to point to CDS archive");
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
      return false; // Do not recurse.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1302
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1303
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1304
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1305
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1306
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1307
  static void copy_and_compact() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1308
    ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1309
    SortedSymbolClosure the_ssc; // StackObj
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1310
    _ssc = &the_ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1311
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1312
    tty->print_cr("Scanning all metaspace objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1313
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1314
      // 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
  1315
      tty->print_cr("Allocating RW objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1316
      _mc_region.pack(&_rw_region);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1317
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1318
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1319
      ShallowCopier rw_copier(false);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1320
      iterate_roots(&rw_copier);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1321
    }
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
      // 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
  1324
      tty->print_cr("Allocating RO objects ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1325
      _rw_region.pack(&_ro_region);
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
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1328
      ShallowCopier ro_copier(true);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1329
      iterate_roots(&ro_copier);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1330
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1331
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1332
      tty->print_cr("Relocating embedded pointers ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1333
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1334
      ShallowCopyEmbeddedRefRelocator emb_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1335
      iterate_roots(&emb_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1336
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1337
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1338
      tty->print_cr("Relocating external roots ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1339
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1340
      RefRelocator ext_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1341
      iterate_roots(&ext_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1342
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1343
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1344
#ifdef ASSERT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1345
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1346
      tty->print_cr("Verifying external roots ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1347
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1348
      IsRefInArchiveChecker checker;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1349
      iterate_roots(&checker);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1350
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1351
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1352
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1353
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1354
    // cleanup
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1355
    _ssc = NULL;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1356
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1357
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1358
  // 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
  1359
  // 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
  1360
  // 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
  1361
  static void relocate_well_known_klasses() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1362
    {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1363
      tty->print_cr("Relocating SystemDictionary::_well_known_klasses[] ... ");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1364
      ResourceMark rm;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1365
      RefRelocator ext_reloc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1366
      SystemDictionary::well_known_klasses_do(&ext_reloc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1367
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1368
    // 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
  1369
    // objects.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1370
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1371
    // We cannot use any of the objects in the heap anymore (except for the
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1372
    // shared strings) because their headers no longer point to valid Klasses.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1373
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1374
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1375
  static void iterate_roots(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1376
    GrowableArray<Symbol*>* symbols = _ssc->get_sorted_symbols();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1377
    for (int i=0; i<symbols->length(); i++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1378
      it->push(symbols->adr_at(i));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1379
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1380
    if (_global_klass_objects != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1381
      // Need to fix up the pointers
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1382
      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
  1383
        // 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
  1384
        it->push(_global_klass_objects->adr_at(i));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1385
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1386
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1387
    FileMapInfo::metaspace_pointers_do(it);
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1388
    SystemDictionaryShared::dumptime_classes_do(it);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1389
    Universe::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1390
    SymbolTable::metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1391
    vmSymbols::metaspace_pointers_do(it);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1392
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1393
    it->finish();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1394
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1395
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1396
  static Klass* get_relocated_klass(Klass* orig_klass) {
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1397
    assert(DumpSharedSpaces, "dump time only");
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 52596
diff changeset
  1398
    address* pp = _new_loc_table->lookup((address)orig_klass);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1399
    assert(pp != NULL, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1400
    Klass* klass = (Klass*)(*pp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1401
    assert(klass->is_klass(), "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1402
    return klass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1403
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1404
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1405
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1406
DumpAllocStats* ArchiveCompactor::_alloc_stats;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1407
SortedSymbolClosure* ArchiveCompactor::_ssc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1408
ArchiveCompactor::RelocationTable* ArchiveCompactor::_new_loc_table;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1409
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1410
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
  1411
  tty->print_cr("Dumping symbol table ...");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1412
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1413
  NOT_PRODUCT(SymbolTable::verify());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1414
  SymbolTable::write_to_archive();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1415
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1416
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1417
char* VM_PopulateDumpSharedSpace::dump_read_only_tables() {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51959
diff changeset
  1418
  ArchiveCompactor::OtherROAllocMark mark;
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1419
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1420
  tty->print("Removing java_mirror ... ");
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1421
  if (!HeapShared::is_heap_object_archiving_allowed()) {
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1422
    clear_basic_type_mirrors();
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1423
  }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1424
  remove_java_mirror_in_classes();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1425
  tty->print_cr("done. ");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1426
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1427
  SystemDictionaryShared::write_to_archive();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1428
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1429
  size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(intptr_t*);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1430
  _cloned_cpp_vtptrs = (intptr_t**)_ro_region.allocate(vtptrs_bytes, sizeof(intptr_t*));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1431
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1432
  // Write the other data to the output array.
58278
e47b459b315c 8231278: Rename FileMapHeader::_read_only_tables_start to _serialized_data_start
iklam
parents: 58277
diff changeset
  1433
  char* start = _ro_region.top();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1434
  WriteClosure wc(&_ro_region);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1435
  MetaspaceShared::serialize(&wc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1436
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1437
  // 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
  1438
  dump_archive_heap_oopmaps();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1439
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1440
  return start;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1441
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1442
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1443
void VM_PopulateDumpSharedSpace::doit() {
52468
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1444
  // We should no longer allocate anything from the metaspace, so that:
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1445
  //
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1446
  // (1) Metaspace::allocate might trigger GC if we have run out of
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1447
  //     committed metaspace, but we can't GC because we're running
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1448
  //     in the VM thread.
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1449
  // (2) ArchiveCompactor needs to work with a stable set of MetaspaceObjs.
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1450
  Metaspace::freeze();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1451
  DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm);
52468
e0fd97beab7e 8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents: 52465
diff changeset
  1452
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1453
  Thread* THREAD = VMThread::vm_thread();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1454
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49769
diff changeset
  1455
  FileMapInfo::check_nonempty_dir_in_shared_path_table();
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 49769
diff changeset
  1456
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1457
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1458
  // 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
  1459
  // 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
  1460
  // 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
  1461
  // shared classes at runtime, where constraints were previously created.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1462
  guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1463
            "loader constraints are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1464
  guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1465
          "placeholders are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1466
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1467
  // At this point, many classes have been loaded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1468
  // 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
  1469
  // that so we don't have to walk the SystemDictionary again.
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1470
  SystemDictionaryShared::check_excluded_classes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1471
  _global_klass_objects = new GrowableArray<Klass*>(1000);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1472
  CollectClassesClosure collect_classes;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1473
  ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1474
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1475
  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
  1476
  {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1477
    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
  1478
    for (int i = 0; i < _global_klass_objects->length(); i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1479
      Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1480
      if (k->is_instance_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1481
        num_inst ++;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1482
      } else if (k->is_objArray_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1483
        num_obj_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1484
      } else {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1485
        assert(k->is_typeArray_klass(), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1486
        num_type_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1487
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1488
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1489
    tty->print_cr("    instance classes   = %5d", num_inst);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1490
    tty->print_cr("    obj array classes  = %5d", num_obj_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1491
    tty->print_cr("    type array classes = %5d", num_type_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1492
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1493
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
  1494
  // Ensure the ConstMethods won't be modified at run-time
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
  1495
  tty->print("Updating ConstMethods ... ");
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58447
diff changeset
  1496
  rewrite_nofast_bytecodes_and_calculate_fingerprints(THREAD);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1497
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1498
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1499
  // Remove all references outside the metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1500
  tty->print("Removing unshareable information ... ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1501
  remove_unshareable_in_classes();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1502
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1503
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1504
  ArchiveCompactor::initialize();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1505
  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
  1506
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1507
  dump_symbols();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1508
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1509
  // Dump supported java heap objects
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1510
  _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
  1511
  _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
  1512
  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
  1513
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1514
  ArchiveCompactor::relocate_well_known_klasses();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1515
58278
e47b459b315c 8231278: Rename FileMapHeader::_read_only_tables_start to _serialized_data_start
iklam
parents: 58277
diff changeset
  1516
  char* serialized_data_start = dump_read_only_tables();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1517
  _ro_region.pack(&_md_region);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1518
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1519
  char* vtbl_list = _md_region.top();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1520
  MetaspaceShared::allocate_cpp_vtable_clones();
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 53547
diff changeset
  1521
  _md_region.pack();
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
  1522
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 53547
diff changeset
  1523
  // The 4 core spaces are allocated consecutively mc->rw->ro->md, so there total size
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1524
  // is just the spaces between the two ends.
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 53547
diff changeset
  1525
  size_t core_spaces_size = _md_region.end() - _mc_region.base();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1526
  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
  1527
         "should already be aligned");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1528
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1529
  // 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
  1530
  // 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
  1531
  MetaspaceShared::patch_cpp_vtable_pointers();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1532
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1533
  // The vtable clones contain addresses of the current process.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1534
  // 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
  1535
  MetaspaceShared::zero_cpp_vtable_clones_for_writing();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1536
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1537
  // 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
  1538
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1539
  FileMapInfo* mapinfo = new FileMapInfo(true);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1540
  mapinfo->populate_header(os::vm_allocation_granularity());
58278
e47b459b315c 8231278: Rename FileMapHeader::_read_only_tables_start to _serialized_data_start
iklam
parents: 58277
diff changeset
  1541
  mapinfo->set_serialized_data_start(serialized_data_start);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1542
  mapinfo->set_misc_data_patching_start(vtbl_list);
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
  1543
  mapinfo->set_i2i_entry_code_buffers(MetaspaceShared::i2i_entry_code_buffers(),
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1544
                                      MetaspaceShared::i2i_entry_code_buffers_size());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1545
  mapinfo->set_core_spaces_size(core_spaces_size);
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1546
  mapinfo->open_for_write();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1547
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1548
  // NOTE: md contains the trampoline code for method entries, which are patched at run time,
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1549
  // so it needs to be read/write.
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1550
  write_region(mapinfo, MetaspaceShared::mc, &_mc_region, /*read_only=*/false,/*allow_exec=*/true);
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1551
  write_region(mapinfo, MetaspaceShared::rw, &_rw_region, /*read_only=*/false,/*allow_exec=*/false);
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1552
  write_region(mapinfo, MetaspaceShared::ro, &_ro_region, /*read_only=*/true, /*allow_exec=*/false);
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1553
  write_region(mapinfo, MetaspaceShared::md, &_md_region, /*read_only=*/false,/*allow_exec=*/false);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1554
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1555
  _total_closed_archive_region_size = mapinfo->write_archive_heap_regions(
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1556
                                        _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
  1557
                                        _closed_archive_heap_oopmaps,
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1558
                                        MetaspaceShared::first_closed_archive_heap_region,
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1559
                                        MetaspaceShared::max_closed_archive_heap_region);
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1560
  _total_open_archive_region_size = mapinfo->write_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
  1561
                                        _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
  1562
                                        _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
  1563
                                        MetaspaceShared::first_open_archive_heap_region,
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1564
                                        MetaspaceShared::max_open_archive_heap_region);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1565
58277
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1566
  mapinfo->set_header_crc(mapinfo->compute_header_crc());
00a98f0aa1b3 8231257: Avoid calling FileMapInfo::write_region twice
iklam
parents: 58110
diff changeset
  1567
  mapinfo->write_header();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1568
  mapinfo->close();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1569
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1570
  // 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
  1571
  MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1572
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1573
  print_region_stats();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1574
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1575
  if (log_is_enabled(Info, cds)) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1576
    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
  1577
                                                 int(_mc_region.used()), int(_md_region.used()));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1578
  }
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1579
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1580
  if (PrintSystemDictionaryAtExit) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1581
    SystemDictionary::print();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1582
  }
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1583
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1584
  if (AllowArchivingWithJavaAgent) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1585
    warning("This archive was created with AllowArchivingWithJavaAgent. It should be used "
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1586
            "for testing purposes only and should not be used in a production environment");
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1587
  }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 52562
diff changeset
  1588
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1589
  // 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
  1590
  // which will fail because InstanceKlasses::remove_unshareable_info()
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1591
  // 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
  1592
  vm_direct_exit(0);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1593
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1594
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1595
void VM_PopulateDumpSharedSpace::print_region_stats() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1596
  // 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
  1597
  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
  1598
                                _mc_region.reserved()  + _md_region.reserved() +
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1599
                                _total_closed_archive_region_size +
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1600
                                _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
  1601
  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
  1602
                             _mc_region.used()  + _md_region.used() +
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1603
                             _total_closed_archive_region_size +
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1604
                             _total_open_archive_region_size;
47679
4cfcb7be4984 8189666: Replace various inlined percentage calculations with global percent_of()
tschatzl
parents: 47599
diff changeset
  1605
  const double total_u_perc = percent_of(total_bytes, total_reserved);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
  1606
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1607
  _mc_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1608
  _rw_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1609
  _ro_region.print(total_reserved);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1610
  _md_region.print(total_reserved);
52402
72d4e10305b9 8212995: Placing the Integer.IntegerCache and cached Integer objects in the closed archive heap region.
jiangli
parents: 52361
diff changeset
  1611
  print_heap_region_stats(_closed_archive_heap_regions, "ca", total_reserved);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1612
  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
  1613
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
  1614
  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
  1615
                 total_bytes, total_reserved, total_u_perc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1616
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1617
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1618
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
  1619
                                                         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
  1620
  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
  1621
  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
  1622
      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
  1623
      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
  1624
      char* top = start + size;
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
  1625
      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
  1626
                    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
  1627
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1628
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1629
}
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1630
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1631
// 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
  1632
// shared archive has been compacted.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1633
void MetaspaceShared::relocate_klass_ptr(oop o) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1634
  assert(DumpSharedSpaces, "sanity");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1635
  Klass* k = ArchiveCompactor::get_relocated_klass(o->klass());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1636
  o->set_klass(k);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1637
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1638
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1639
Klass* MetaspaceShared::get_relocated_klass(Klass *k) {
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1640
  assert(DumpSharedSpaces, "sanity");
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1641
  return ArchiveCompactor::get_relocated_klass(k);
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1642
}
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1643
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1644
class LinkSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1645
  Thread* THREAD;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1646
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1647
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1648
  LinkSharedClassesClosure(Thread* thread) : THREAD(thread), _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1649
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1650
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1651
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1652
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1653
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1654
    if (k->is_instance_klass()) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1655
      InstanceKlass* ik = InstanceKlass::cast(k);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1656
      // 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
  1657
      // cpcache to be created. Class verification is done according
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1658
      // to -Xverify setting.
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1659
      _made_progress |= MetaspaceShared::try_link_class(ik, THREAD);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1660
      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
  1661
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1662
      ik->constants()->resolve_class_constants(THREAD);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1663
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1664
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1665
};
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1666
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1667
class CheckSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1668
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1669
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1670
  CheckSharedClassesClosure() : _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1671
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1672
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1673
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1674
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1675
    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
  1676
      _made_progress = true;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1677
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1678
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1679
};
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1680
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1681
void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1682
  // We need to iterate because verification may cause additional classes
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1683
  // to be loaded.
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1684
  LinkSharedClassesClosure link_closure(THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1685
  do {
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1686
    link_closure.reset();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 51554
diff changeset
  1687
    ClassLoaderDataGraph::unlocked_loaded_classes_do(&link_closure);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1688
    guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1689
  } while (link_closure.made_progress());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1690
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1691
  if (_has_error_classes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1692
    // 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
  1693
    CheckSharedClassesClosure check_closure;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1694
    do {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1695
      // 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
  1696
      // 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
  1697
      // 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
  1698
      check_closure.reset();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 51554
diff changeset
  1699
      ClassLoaderDataGraph::unlocked_loaded_classes_do(&check_closure);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1700
    } while (check_closure.made_progress());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1701
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1702
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1703
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1704
void MetaspaceShared::prepare_for_dumping() {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1705
  Arguments::check_unsupported_dumping_properties();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1706
  ClassLoader::initialize_shared_path();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1707
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1708
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1709
// 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
  1710
// file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1711
void MetaspaceShared::preload_and_dump(TRAPS) {
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 37094
diff changeset
  1712
  { TraceTime timer("Dump Shared Spaces", TRACETIME_LOG(Info, startuptime));
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1713
    ResourceMark rm;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1714
    char class_list_path_str[JVM_MAXPATHLEN];
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1715
    // Preload classes to be shared.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1716
    const char* class_list_path;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1717
    if (SharedClassListFile == NULL) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1718
      // Construct the path to the class list (in jre/lib)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1719
      // Walk up two directories from the location of the VM and
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1720
      // optionally tack on "lib" (depending on platform)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1721
      os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1722
      for (int i = 0; i < 3; i++) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1723
        char *end = strrchr(class_list_path_str, *os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1724
        if (end != NULL) *end = '\0';
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1725
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1726
      int class_list_path_len = (int)strlen(class_list_path_str);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1727
      if (class_list_path_len >= 3) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1728
        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
  1729
          if (class_list_path_len < JVM_MAXPATHLEN - 4) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1730
            jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1731
                         sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1732
                         "%slib", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1733
            class_list_path_len += 4;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1734
          }
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
  1735
        }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1736
      }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1737
      if (class_list_path_len < JVM_MAXPATHLEN - 10) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1738
        jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1739
                     sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1740
                     "%sclasslist", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1741
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1742
      class_list_path = class_list_path_str;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1743
    } else {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1744
      class_list_path = SharedClassListFile;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1745
    }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1746
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1747
    tty->print_cr("Loading classes to share ...");
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1748
    _has_error_classes = false;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1749
    int class_count = preload_classes(class_list_path, THREAD);
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1750
    if (ExtraSharedClassListFile) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1751
      class_count += preload_classes(ExtraSharedClassListFile, THREAD);
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1752
    }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1753
    tty->print_cr("Loading classes to share: done.");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1754
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1755
    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
  1756
52503
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1757
    if (SharedArchiveConfigFile) {
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1758
      tty->print_cr("Reading extra data from %s ...", SharedArchiveConfigFile);
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1759
      read_extra_data(SharedArchiveConfigFile, THREAD);
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1760
    }
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1761
    tty->print_cr("Reading extra data: done.");
7d3b82b338f7 8213563: appcds/sharedStrings/SharedStringsStress.java fails with 'GC triggered before VM initialization completed' error
jiangli
parents: 52468
diff changeset
  1762
52465
3e0ebf913679 8213439: Run class initialization for boot loader classes with registered subgraph archiving entry field during CDS dump time.
jiangli
parents: 52402
diff changeset
  1763
    HeapShared::init_subgraph_entry_fields(THREAD);
3e0ebf913679 8213439: Run class initialization for boot loader classes with registered subgraph archiving entry field during CDS dump time.
jiangli
parents: 52402
diff changeset
  1764
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1765
    // Rewrite and link classes
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1766
    tty->print_cr("Rewriting and linking classes ...");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1767
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1768
    // 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
  1769
    // 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
  1770
    // 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
  1771
    // are implemented by K are not verified.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1772
    link_and_cleanup_shared_classes(CATCH);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1773
    tty->print_cr("Rewriting and linking classes: done");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1774
52811
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1775
    if (HeapShared::is_heap_object_archiving_allowed()) {
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1776
      // Avoid fragmentation while archiving heap objects.
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1777
      Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1778
      Universe::heap()->collect(GCCause::_archive_time_gc);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1779
      Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1780
    }
ff04b71bf6f1 8214388: CDS dumping fails with java heap fragmentation
iklam
parents: 52631
diff changeset
  1781
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1782
    VM_PopulateDumpSharedSpace op;
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1783
    VMThread::execute(&op);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1784
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1785
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1786
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1787
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1788
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
  1789
  ClassListParser parser(class_list_path);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1790
  int class_count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1791
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1792
  while (parser.parse_one_line()) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1793
    Klass* klass = parser.load_current_class(THREAD);
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1794
    if (HAS_PENDING_EXCEPTION) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1795
      if (klass == NULL &&
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1796
          (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1797
        // print a warning only when the pending exception is class not found
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
  1798
        log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1799
      }
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1800
      CLEAR_PENDING_EXCEPTION;
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1801
    }
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1802
    if (klass != NULL) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1803
      if (log_is_enabled(Trace, cds)) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1804
        ResourceMark rm;
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1805
        log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46989
diff changeset
  1806
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1807
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1808
      if (klass->is_instance_klass()) {
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1809
        InstanceKlass* ik = InstanceKlass::cast(klass);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1810
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1811
        // Link the class to cause the bytecodes to be rewritten and the
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1812
        // cpcache to be created. The linking is done as soon as classes
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1813
        // are loaded in order that the related data structures (klass and
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1814
        // cpCache) are located together.
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1815
        try_link_class(ik, THREAD);
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1816
        guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1817
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1818
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1819
      class_count++;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1820
    }
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  1821
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1822
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1823
  return class_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1824
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1825
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1826
// Returns true if the class's status has changed
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1827
bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1828
  assert(DumpSharedSpaces, "should only be called during dumping");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1829
  if (ik->init_state() < InstanceKlass::linked) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1830
    bool saved = BytecodeVerificationLocal;
49769
b8c9bec06921 8197972: Always verify non-system classes during CDS dump time
ccheung
parents: 49739
diff changeset
  1831
    if (ik->loader_type() == 0 && ik->class_loader() == NULL) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1832
      // The verification decision is based on BytecodeVerificationRemote
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1833
      // 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
  1834
      // 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
  1835
      // 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
  1836
      // BytecodeVerificationRemote. Note this can cause the parent system
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1837
      // classes also being verified. The extra overhead is acceptable during
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1838
      // dumping.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1839
      BytecodeVerificationLocal = BytecodeVerificationRemote;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1840
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1841
    ik->link_class(THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1842
    if (HAS_PENDING_EXCEPTION) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1843
      ResourceMark rm;
58110
85e1de070bef 8186988: use log_warning() and log_error() instead of tty->print_cr for CDS warning and error messages
ccheung
parents: 58096
diff changeset
  1844
      log_warning(cds)("Preload Warning: Verification failed for %s",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1845
                    ik->external_name());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1846
      CLEAR_PENDING_EXCEPTION;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1847
      ik->set_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1848
      _has_error_classes = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1849
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1850
    BytecodeVerificationLocal = saved;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1851
    return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1852
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1853
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1854
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1855
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1856
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1857
#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
  1858
void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1859
  // The closed and open archive heap space has maximum two regions.
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1860
  // See FileMapInfo::write_archive_heap_regions() for details.
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1861
  _closed_archive_heap_regions = new GrowableArray<MemRegion>(2);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1862
  _open_archive_heap_regions = new GrowableArray<MemRegion>(2);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1863
  HeapShared::archive_java_heap_objects(_closed_archive_heap_regions,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1864
                                        _open_archive_heap_regions);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1865
  ArchiveCompactor::OtherROAllocMark mark;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1866
  HeapShared::write_subgraph_info_table();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1867
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1868
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1869
void VM_PopulateDumpSharedSpace::dump_archive_heap_oopmaps() {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
  1870
  if (HeapShared::is_heap_object_archiving_allowed()) {
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1871
    _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
  1872
    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
  1873
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1874
    _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
  1875
    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
  1876
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1877
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1878
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1879
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
  1880
                                                           GrowableArray<ArchiveHeapOopmapInfo>* oopmaps) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1881
  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
  1882
    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
  1883
    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
  1884
    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
  1885
    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
  1886
    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
  1887
    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
  1888
                  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
  1889
                  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
  1890
                  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
  1891
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1892
    ArchiveHeapOopmapInfo info;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1893
    info._oopmap = (address)buffer;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1894
    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
  1895
    oopmaps->append(info);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1896
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  1897
}
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
  1898
#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
  1899
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1900
void ReadClosure::do_ptr(void** p) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1901
  assert(*p == NULL, "initializing previous initialized pointer.");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1902
  intptr_t obj = nextPtr();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1903
  assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1904
         "hit tag while initializing ptrs.");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1905
  *p = (void*)obj;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1906
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1907
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1908
void ReadClosure::do_u4(u4* p) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1909
  intptr_t obj = nextPtr();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1910
  *p = (u4)(uintx(obj));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1911
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1912
55251
92eec0732eed 8224853: CDS address sanitizer errors
ngasson
parents: 54927
diff changeset
  1913
void ReadClosure::do_bool(bool* p) {
92eec0732eed 8224853: CDS address sanitizer errors
ngasson
parents: 54927
diff changeset
  1914
  intptr_t obj = nextPtr();
92eec0732eed 8224853: CDS address sanitizer errors
ngasson
parents: 54927
diff changeset
  1915
  *p = (bool)(uintx(obj));
92eec0732eed 8224853: CDS address sanitizer errors
ngasson
parents: 54927
diff changeset
  1916
}
92eec0732eed 8224853: CDS address sanitizer errors
ngasson
parents: 54927
diff changeset
  1917
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1918
void ReadClosure::do_tag(int tag) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1919
  int old_tag;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1920
  old_tag = (int)(intptr_t)nextPtr();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1921
  // do_int(&old_tag);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1922
  assert(tag == old_tag, "old tag doesn't match");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1923
  FileMapInfo::assert_mark(tag == old_tag);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1924
}
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1925
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1926
void ReadClosure::do_oop(oop *p) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1927
  narrowOop o = (narrowOop)nextPtr();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1928
  if (o == 0 || !HeapShared::open_archive_heap_region_mapped()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1929
    p = NULL;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1930
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1931
    assert(HeapShared::is_heap_object_archiving_allowed(),
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1932
           "Archived heap object is not allowed");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1933
    assert(HeapShared::open_archive_heap_region_mapped(),
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1934
           "Open archive heap region is not mapped");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1935
    *p = HeapShared::decode_from_archive(o);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1936
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1937
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1938
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1939
void ReadClosure::do_region(u_char* start, size_t size) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1940
  assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1941
  assert(size % sizeof(intptr_t) == 0, "bad size");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1942
  do_tag((int)size);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1943
  while (size > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1944
    *(intptr_t*)start = nextPtr();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1945
    start += sizeof(intptr_t);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1946
    size -= sizeof(intptr_t);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1947
  }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1948
}
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48962
diff changeset
  1949
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1950
void MetaspaceShared::set_shared_metaspace_range(void* base, void* top) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1951
  _shared_metaspace_static_top = top;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1952
  MetaspaceObj::set_shared_metaspace_range(base, top);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1953
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1954
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1955
// 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
  1956
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
  1957
  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
  1958
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1959
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1960
bool MetaspaceShared::is_in_trampoline_frame(address addr) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1961
  if (UseSharedSpaces && is_in_shared_region(addr, MetaspaceShared::mc)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1962
    return true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1963
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1964
  return false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1965
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1966
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1967
bool MetaspaceShared::is_shared_dynamic(void* p) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1968
  if ((p < MetaspaceObj::shared_metaspace_top()) &&
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1969
      (p >= _shared_metaspace_static_top)) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1970
    return true;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1971
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1972
    return false;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1973
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1974
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1975
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1976
// 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
  1977
bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1978
  size_t image_alignment = mapinfo->alignment();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1979
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1980
#ifndef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1981
  // 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
  1982
  // 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
  1983
  // mappings of the regions to fail.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1984
  ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1985
  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
  1986
#endif
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1987
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1988
  assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1989
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1990
  // Map each shared region
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1991
  int regions[] = {mc, rw, ro, md};
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1992
  size_t len = sizeof(regions)/sizeof(int);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1993
  char* saved_base[] = {NULL, NULL, NULL, NULL};
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1994
  char* top = mapinfo->map_regions(regions, saved_base, len );
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1995
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  1996
  if (top != NULL &&
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  1997
      (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
  1998
      mapinfo->validate_shared_path_table()) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 48383
diff changeset
  1999
    // 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
  2000
    // 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
  2001
    // MetaspaceObj::is_shared().
52562
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
  2002
    _core_spaces_size = mapinfo->core_spaces_size();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2003
    set_shared_metaspace_range((void*)saved_base[0], (void*)top);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2004
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2005
  } else {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2006
    mapinfo->unmap_regions(regions, saved_base, len);
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2007
#ifndef _WINDOWS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2008
    // Release the entire mapped region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2009
    shared_rs.release();
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  2010
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2011
    // 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
  2012
    // 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
  2013
    if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2014
      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
  2015
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2016
      FLAG_SET_DEFAULT(UseSharedSpaces, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2017
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2018
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2019
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2020
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2021
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2022
// Read the miscellaneous data from the shared file, and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2023
// serialize it out to its various destinations.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2024
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2025
void MetaspaceShared::initialize_shared_spaces() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2026
  FileMapInfo *mapinfo = FileMapInfo::current_info();
58096
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
  2027
  _i2i_entry_code_buffers = mapinfo->i2i_entry_code_buffers();
0d97bf7cf8a4 8230586: Encapsulate fields in filemap.hpp
iklam
parents: 55296
diff changeset
  2028
  _i2i_entry_code_buffers_size = mapinfo->i2i_entry_code_buffers_size();
52562
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
  2029
  // _core_spaces_size is loaded from the shared archive immediatelly after mapping
3a9384c12260 8213713: Minor issues during MetaspaceShared::initialize_runtime_shared_and_meta_spaces
jiangli
parents: 52514
diff changeset
  2030
  assert(_core_spaces_size == mapinfo->core_spaces_size(), "sanity");
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  2031
  char* buffer = mapinfo->misc_data_patching_start();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2032
  clone_cpp_vtables((intptr_t*)buffer);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  2033
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2034
  // Verify various attributes of the archive, plus initialize the
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2035
  // shared string/symbol tables
58278
e47b459b315c 8231278: Rename FileMapHeader::_read_only_tables_start to _serialized_data_start
iklam
parents: 58277
diff changeset
  2036
  buffer = mapinfo->serialized_data_start();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2037
  intptr_t* array = (intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2038
  ReadClosure rc(&array);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2039
  serialize(&rc);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2040
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2041
  // Initialize the run-time symbol table.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  2042
  SymbolTable::create_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2043
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51477
diff changeset
  2044
  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
  2045
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2046
  // Close the mapinfo file
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2047
  mapinfo->close();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2048
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2049
  if (PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2050
    if (PrintSharedDictionary) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2051
      tty->print_cr("\nShared classes:\n");
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52503
diff changeset
  2052
      SystemDictionaryShared::print_on(tty);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2053
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2054
    if (_archive_loading_failed) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2055
      tty->print_cr("archive is invalid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2056
      vm_exit(1);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2057
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2058
      tty->print_cr("archive is valid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2059
      vm_exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2060
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  2061
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2062
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2063
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2064
// JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2065
bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2066
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2067
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2068
  if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2069
    // remap the shared readonly space to shared readwrite, private
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2070
    FileMapInfo* mapinfo = FileMapInfo::current_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2071
    if (!mapinfo->remap_shared_readonly_as_readwrite()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2072
      return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2073
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2074
    if (FileMapInfo::dynamic_info() != NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2075
      mapinfo = FileMapInfo::dynamic_info();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2076
      if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2077
        return false;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2078
      }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
  2079
    }
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
  2080
    _remapped_readwrite = true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2081
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2082
  return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2083
}
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2084
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2085
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
  2086
  // 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
  2087
  // 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
  2088
  // or so.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2089
  _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
  2090
  _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
  2091
  _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
  2092
  _md_region.print_out_of_space_msg(name, needed_bytes);
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2093
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
  2094
  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
  2095
                                "Please reduce the number of shared classes.");
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  2096
}