hotspot/src/share/vm/memory/metaspaceShared.cpp
author rprotacio
Mon, 05 Jun 2017 13:13:38 -0400
changeset 46522 86b13b03a053
parent 46464 6432a858a220
child 46560 388aa8d67c80
permissions -rw-r--r--
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging. Summary: Converted -XX:+PrintSharedSpaces to -Xlog:cds=info Reviewed-by: iklam, jiangli, mseledtsov
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
/*
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
     2
 * Copyright (c) 2012, 2017, 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"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    26
#include "classfile/classListParser.hpp"
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    27
#include "classfile/classLoaderExt.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    28
#include "classfile/dictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "classfile/loaderConstraints.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "classfile/placeholders.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    31
#include "classfile/sharedClassUtil.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "classfile/symbolTable.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "classfile/systemDictionary.hpp"
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
    34
#include "classfile/systemDictionaryShared.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
#include "code/codeCache.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    36
#include "gc/shared/gcLocker.hpp"
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
    37
#include "interpreter/bytecodeStream.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    38
#include "interpreter/bytecodes.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    39
#include "logging/log.hpp"
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
    40
#include "logging/logMessage.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
#include "memory/metaspace.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
#include "memory/metaspaceShared.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37179
diff changeset
    44
#include "memory/resourceArea.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    45
#include "oops/instanceClassLoaderKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    46
#include "oops/instanceMirrorKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    47
#include "oops/instanceRefKlass.hpp"
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    48
#include "oops/objArrayKlass.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    49
#include "oops/objArrayOop.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
#include "oops/oop.inline.hpp"
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
    51
#include "oops/typeArrayKlass.hpp"
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 37094
diff changeset
    52
#include "runtime/timerTrace.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    53
#include "runtime/os.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
#include "runtime/signature.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    55
#include "runtime/vmThread.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    56
#include "runtime/vm_operations.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    57
#include "utilities/defaultStream.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    58
#include "utilities/hashtable.inline.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    59
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    60
int MetaspaceShared::_max_alignment = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
ReservedSpace* MetaspaceShared::_shared_rs = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    64
MetaspaceSharedStats MetaspaceShared::_stats;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    65
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    66
bool MetaspaceShared::_has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    67
bool MetaspaceShared::_archive_loading_failed = false;
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
    68
bool MetaspaceShared::_remapped_readwrite = false;
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
    69
address MetaspaceShared::_cds_i2i_entry_code_buffers = NULL;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
    70
size_t MetaspaceShared::_cds_i2i_entry_code_buffers_size = 0;
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    71
SharedMiscRegion MetaspaceShared::_mc;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    72
SharedMiscRegion MetaspaceShared::_md;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
    73
SharedMiscRegion MetaspaceShared::_od;
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    74
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    75
void SharedMiscRegion::initialize(ReservedSpace rs, size_t committed_byte_size,  SharedSpaceType space_type) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    76
  _vs.initialize(rs, committed_byte_size);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    77
  _alloc_top = _vs.low();
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    78
  _space_type = space_type;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    79
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    80
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    81
// NOT thread-safe, but this is called during dump time in single-threaded mode.
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    82
char* SharedMiscRegion::alloc(size_t num_bytes) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    83
  assert(DumpSharedSpaces, "dump time only");
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    84
  size_t alignment = sizeof(char*);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    85
  num_bytes = align_size_up(num_bytes, alignment);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    86
  _alloc_top = (char*)align_ptr_up(_alloc_top, alignment);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    87
  if (_alloc_top + num_bytes > _vs.high()) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    88
    report_out_of_shared_space(_space_type);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    89
  }
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    90
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    91
  char* p = _alloc_top;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    92
  _alloc_top += num_bytes;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    93
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    94
  memset(p, 0, num_bytes);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    95
  return p;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    96
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    97
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    98
void MetaspaceShared::initialize_shared_rs(ReservedSpace* rs) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
    99
  assert(DumpSharedSpaces, "dump time only");
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   100
  _shared_rs = rs;
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   101
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   102
  size_t core_spaces_size = FileMapInfo::core_spaces_size();
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   103
  size_t metadata_size = SharedReadOnlySize + SharedReadWriteSize;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   104
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   105
  // Split into the core and optional sections
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   106
  ReservedSpace core_data = _shared_rs->first_part(core_spaces_size);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   107
  ReservedSpace optional_data = _shared_rs->last_part(core_spaces_size);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   108
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   109
  // The RO/RW and the misc sections
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   110
  ReservedSpace shared_ro_rw = core_data.first_part(metadata_size);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   111
  ReservedSpace misc_section = core_data.last_part(metadata_size);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   112
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   113
  // Now split the misc code and misc data sections.
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   114
  ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   115
  ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   116
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   117
  _md.initialize(md_rs, SharedMiscDataSize, SharedMiscData);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   118
  _mc.initialize(mc_rs, SharedMiscCodeSize, SharedMiscCode);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   119
  _od.initialize(optional_data, metadata_size, SharedOptional);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   120
}
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   121
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   122
// 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
   123
// miscellaneous data from/to the shared archive file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   125
void MetaspaceShared::serialize(SerializeClosure* soc, GrowableArray<MemRegion> *string_space,
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   126
                                size_t* space_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   127
  int tag = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   129
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   130
  // Verify the sizes of various metadata in the system.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
  soc->do_tag(sizeof(Method));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
  soc->do_tag(sizeof(ConstMethod));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   133
  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
   134
  soc->do_tag(sizeof(ConstantPool));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   135
  soc->do_tag(sizeof(ConstantPoolCache));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   136
  soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   137
  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
   138
  soc->do_tag(sizeof(Symbol));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   139
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   140
  // Dump/restore miscellaneous metadata.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   141
  Universe::serialize(soc, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   142
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   143
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   144
  // Dump/restore references to commonly used names and signatures.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   145
  vmSymbols::serialize(soc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   146
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   147
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   148
  // Dump/restore the symbol and string tables
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   149
  SymbolTable::serialize(soc);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   150
  StringTable::serialize(soc, string_space, space_size);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   151
  soc->do_tag(--tag);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   152
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   153
  soc->do_tag(666);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   154
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   155
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   156
address MetaspaceShared::cds_i2i_entry_code_buffers(size_t total_size) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   157
  if (DumpSharedSpaces) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   158
    if (_cds_i2i_entry_code_buffers == NULL) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   159
      _cds_i2i_entry_code_buffers = (address)misc_data_space_alloc(total_size);
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   160
      _cds_i2i_entry_code_buffers_size = total_size;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   161
    }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   162
  } else if (UseSharedSpaces) {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   163
    assert(_cds_i2i_entry_code_buffers != NULL, "must already been initialized");
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   164
  } else {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   165
    return NULL;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   166
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   167
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   168
  assert(_cds_i2i_entry_code_buffers_size == total_size, "must not change");
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   169
  return _cds_i2i_entry_code_buffers;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   170
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   172
// CDS code for dumping shared archive.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   173
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   174
// 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
   175
// 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
   176
static GrowableArray<Klass*>* _global_klass_objects;
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   177
class CollectClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   178
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   179
    _global_klass_objects->append_if_missing(k);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   180
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   181
};
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   182
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   183
static void remove_unshareable_in_classes() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   184
  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
   185
    Klass* k = _global_klass_objects->at(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   186
    k->remove_unshareable_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   187
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   188
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   189
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   190
static void rewrite_nofast_bytecode(Method* method) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   191
  RawBytecodeStream bcs(method);
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   192
  while (!bcs.is_last_bytecode()) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   193
    Bytecodes::Code opcode = bcs.raw_next();
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   194
    switch (opcode) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   195
    case Bytecodes::_getfield:      *bcs.bcp() = Bytecodes::_nofast_getfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   196
    case Bytecodes::_putfield:      *bcs.bcp() = Bytecodes::_nofast_putfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   197
    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
   198
    case Bytecodes::_iload: {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   199
      if (!bcs.is_wide()) {
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   200
        *bcs.bcp() = Bytecodes::_nofast_iload;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   201
      }
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   202
      break;
2e5c855d6b1e 8157189: 'iload_w' in shared class is not interpreted correctly.
jiangli
parents: 38151
diff changeset
   203
    }
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   204
    default: break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   205
    }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   206
  }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   207
}
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   208
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   209
// 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
   210
// run time. This includes:
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   211
// [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
   212
//     at run time by RewriteBytecodes/RewriteFrequentPairs
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   213
// [2] Assign a fingerprint, so one doesn't need to be assigned at run-time.
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   214
static void rewrite_nofast_bytecodes_and_calculate_fingerprints() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   215
  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
   216
    Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   217
    if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   218
      InstanceKlass* ik = InstanceKlass::cast(k);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   219
      for (int i = 0; i < ik->methods()->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   220
        Method* m = ik->methods()->at(i);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   221
        rewrite_nofast_bytecode(m);
20059
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   222
        Fingerprinter fp(m);
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   223
        // The side effect of this call sets method's fingerprint field.
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   224
        fp.fingerprint();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   225
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   226
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   227
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   228
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   229
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   230
// 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
   231
// (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
   232
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   233
// 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
   234
// 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
   235
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   236
// 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
   237
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   238
// + 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
   239
//                  the CDS image
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   240
// + 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
   241
//                  into our own tables.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   242
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   243
// 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
   244
#define CPP_VTABLE_PATCH_TYPES_DO(f) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   245
  f(ConstantPool) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   246
  f(InstanceKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   247
  f(InstanceClassLoaderKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   248
  f(InstanceMirrorKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   249
  f(InstanceRefKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   250
  f(Method) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   251
  f(ObjArrayKlass) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   252
  f(TypeArrayKlass)
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   253
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   254
class CppVtableInfo {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   255
  intptr_t _vtable_size;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   256
  intptr_t _cloned_vtable[1];
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   257
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   258
  static int num_slots(int vtable_size) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   259
    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
   260
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   261
  int vtable_size()           { return int(uintx(_vtable_size)); }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   262
  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
   263
  intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   264
  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
   265
  // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   266
  intptr_t* next(int vtable_size) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   267
    return &_cloned_vtable[vtable_size];
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   268
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   269
};
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   270
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   271
template <class T> class CppVtableCloner : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   272
  static intptr_t* vtable_of(Metadata& m) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   273
    return *((intptr_t**)&m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   274
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   275
  static CppVtableInfo* _info;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   276
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   277
  static int get_vtable_length(const char* name);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   278
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   279
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   280
  // Allocate and initialize the C++ vtable, starting from top, but do not go past end.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   281
  static intptr_t* allocate(const char* name, intptr_t* top, intptr_t* end);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   282
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   283
  // Clone the vtable to ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   284
  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
   285
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   286
  static void zero_vtable_clone() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   287
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   288
    _info->zero();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   289
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   290
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   291
  // 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
   292
  static void patch(Metadata* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   293
    assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   294
    *(void**)obj = (void*)(_info->cloned_vtable());
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   295
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   296
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   297
  static bool is_valid_shared_object(const T* obj) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   298
    intptr_t* vptr = *(intptr_t**)obj;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   299
    return vptr == _info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   300
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   301
};
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   302
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   303
template <class T> CppVtableInfo* CppVtableCloner<T>::_info = NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   304
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   305
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   306
intptr_t* CppVtableCloner<T>::allocate(const char* name, intptr_t* top, intptr_t* end) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   307
  int n = get_vtable_length(name);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   308
  _info = (CppVtableInfo*)top;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   309
  intptr_t* next = _info->next(n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   310
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   311
  if (next > end) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   312
    report_out_of_shared_space(SharedMiscData);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   313
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   314
  _info->set_vtable_size(n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   315
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   316
  intptr_t* p = clone_vtable(name, _info);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   317
  assert(p == next, "must be");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   318
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   319
  return p;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   320
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   321
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   322
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   323
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
   324
  if (!DumpSharedSpaces) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   325
    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
   326
    _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
   327
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   328
  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
   329
  int n = info->vtable_size();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   330
  intptr_t* srcvtable = vtable_of(tmp);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   331
  intptr_t* dstvtable = info->cloned_vtable();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   332
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   333
  // 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
   334
  // safe to do memcpy.
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   335
  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
   336
  memcpy(dstvtable, srcvtable, sizeof(intptr_t) * n);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   337
  return dstvtable + n;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   338
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   339
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   340
// 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
   341
// trick by declaring 2 subclasses:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   342
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   343
//   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
   344
//   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
   345
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   346
// CppVtableTesterA and CppVtableTesterB's vtables have the following properties:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   347
// - 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
   348
// - 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
   349
// - Their last entry is different.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   350
//
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   351
// 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
   352
// and find the first entry that's different.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   353
//
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   354
// 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
   355
// esoteric compilers.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   356
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   357
template <class T> class CppVtableTesterB: public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   358
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   359
  virtual int last_virtual_method() {return 1;}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   360
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   361
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   362
template <class T> class CppVtableTesterA : public T {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   363
public:
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   364
  virtual void* last_virtual_method() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   365
    // 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
   366
    // compiler/linker won't alias the two functions.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   367
    return NULL;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   368
  }
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   369
};
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   370
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   371
template <class T>
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   372
int CppVtableCloner<T>::get_vtable_length(const char* name) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   373
  CppVtableTesterA<T> a;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   374
  CppVtableTesterB<T> b;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   375
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   376
  intptr_t* avtable = vtable_of(a);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   377
  intptr_t* bvtable = vtable_of(b);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   378
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   379
  // 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
   380
  int vtable_len = 1;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   381
  for (; ; vtable_len++) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   382
    if (avtable[vtable_len] != bvtable[vtable_len]) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   383
      break;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   384
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   385
  }
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   386
  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
   387
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   388
  return vtable_len;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   389
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   390
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   391
#define ALLOC_CPP_VTABLE_CLONE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   392
  top = CppVtableCloner<c>::allocate(#c, top, end);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   393
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   394
#define CLONE_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   395
  p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   396
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   397
#define ZERO_CPP_VTABLE(c) \
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   398
 CppVtableCloner<c>::zero_vtable_clone();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   399
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   400
// 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
   401
intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   402
  assert(DumpSharedSpaces || UseSharedSpaces, "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   403
  CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   404
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   405
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   406
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   407
void MetaspaceShared::zero_cpp_vtable_clones_for_writing() {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   408
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   409
  CPP_VTABLE_PATCH_TYPES_DO(ZERO_CPP_VTABLE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   410
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   411
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   412
// Allocate and initialize the C++ vtables, starting from top, but do not go past end.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   413
intptr_t* MetaspaceShared::allocate_cpp_vtable_clones(intptr_t* top, intptr_t* end) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   414
  assert(DumpSharedSpaces, "dump-time only");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   415
  // Layout (each slot is a intptr_t):
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   416
  //   [number of slots in the first vtable = n1]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   417
  //   [ <n1> slots for the first vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   418
  //   [number of slots in the first second = n2]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   419
  //   [ <n2> slots for the second vtable]
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   420
  //   ...
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   421
  // 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
   422
  CPP_VTABLE_PATCH_TYPES_DO(ALLOC_CPP_VTABLE_CLONE);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   423
  return top;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   424
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   425
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   426
// 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
   427
// vtable pointer is in first slot in object.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   428
void MetaspaceShared::patch_cpp_vtable_pointers() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   429
  int n = _global_klass_objects->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   430
  for (int i = 0; i < n; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   431
    Klass* obj = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   432
    if (obj->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   433
      InstanceKlass* ik = InstanceKlass::cast(obj);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   434
      if (ik->is_class_loader_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   435
        CppVtableCloner<InstanceClassLoaderKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   436
      } else if (ik->is_reference_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   437
        CppVtableCloner<InstanceRefKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   438
      } else if (ik->is_mirror_instance_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   439
        CppVtableCloner<InstanceMirrorKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   440
      } else {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   441
        CppVtableCloner<InstanceKlass>::patch(ik);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   442
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   443
      ConstantPool* cp = ik->constants();
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   444
      CppVtableCloner<ConstantPool>::patch(cp);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   445
      for (int j = 0; j < ik->methods()->length(); j++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   446
        Method* m = ik->methods()->at(j);
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   447
        CppVtableCloner<Method>::patch(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   448
        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
   449
      }
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   450
    } else if (obj->is_objArray_klass()) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   451
      CppVtableCloner<ObjArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   452
    } else {
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   453
      assert(obj->is_typeArray_klass(), "sanity");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   454
      CppVtableCloner<TypeArrayKlass>::patch(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   455
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   456
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   457
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   458
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   459
bool MetaspaceShared::is_valid_shared_method(const Method* m) {
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   460
  assert(is_in_shared_space(m), "must be");
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   461
  return CppVtableCloner<Method>::is_valid_shared_object(m);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   462
}
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   463
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   464
// Closure for serializing initialization data out to a data area to be
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   465
// written to the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   466
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   467
class WriteClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   468
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   469
  intptr_t* top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   470
  char* end;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   471
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   472
  inline void check_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   473
    if ((char*)top + sizeof(intptr_t) > end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   474
      report_out_of_shared_space(SharedMiscData);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   475
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   476
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   477
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   478
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   479
  WriteClosure(char* md_top, char* md_end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   480
    top = (intptr_t*)md_top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   481
    end = md_end;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   482
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   483
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   484
  char* get_top() { return (char*)top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   485
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   486
  void do_ptr(void** p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   487
    check_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   488
    *top = (intptr_t)*p;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   489
    ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   490
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   491
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   492
  void do_u4(u4* p) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   493
    void* ptr = (void*)(uintx(*p));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   494
    do_ptr(&ptr);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   495
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   496
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   497
  void do_tag(int tag) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   498
    check_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   499
    *top = (intptr_t)tag;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   500
    ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   501
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   502
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   503
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   504
    if ((char*)top + size > end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   505
      report_out_of_shared_space(SharedMiscData);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   506
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   507
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   508
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   509
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
    while (size > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   511
      *top = *(intptr_t*)start;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   512
      ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   513
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   514
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   515
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   516
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   517
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   518
  bool reading() const { return false; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   519
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   520
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   521
// This is for dumping detailed statistics for the allocations
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   522
// in the shared spaces.
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   523
class DumpAllocClosure : public Metaspace::AllocRecordClosure {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   524
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   525
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   526
  // Here's poor man's enum inheritance
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   527
#define SHAREDSPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   528
  METASPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   529
  f(SymbolHashentry) \
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   530
  f(SymbolBucket) \
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   531
  f(StringHashentry) \
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   532
  f(StringBucket) \
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   533
  f(Other)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   534
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   535
#define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   536
#define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   537
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   538
  enum Type {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   539
    // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   540
    SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   541
    _number_of_types
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   542
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   543
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   544
  static const char * type_name(Type type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   545
    switch(type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   546
    SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   547
    default:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   548
      ShouldNotReachHere();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   549
      return NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   550
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   551
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   552
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   553
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   554
  enum {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   555
    RO = 0,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   556
    RW = 1
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   557
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   558
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   559
  int _counts[2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   560
  int _bytes [2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   561
  int _which;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   562
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   563
  DumpAllocClosure() {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   564
    memset(_counts, 0, sizeof(_counts));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   565
    memset(_bytes,  0, sizeof(_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   566
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   567
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   568
  void iterate_metaspace(Metaspace* space, int which) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   569
    assert(which == RO || which == RW, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   570
    _which = which;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   571
    space->iterate(this);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   572
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   573
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   574
  virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   575
    assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   576
    _counts[_which][type] ++;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   577
    _bytes [_which][type] += byte_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   578
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   579
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   580
  void dump_stats(int ro_all, int rw_all, int md_all, int mc_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   581
};
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   582
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   583
void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   584
  rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   585
  int other_bytes = md_all + mc_all;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   586
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   587
  // 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
   588
  MetaspaceSharedStats *stats = MetaspaceShared::stats();
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   589
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   590
  // symbols
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   591
  _counts[RO][SymbolHashentryType] = stats->symbol.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   592
  _bytes [RO][SymbolHashentryType] = stats->symbol.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   593
  _bytes [RO][TypeArrayU4Type]    -= stats->symbol.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   594
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   595
  _counts[RO][SymbolBucketType] = stats->symbol.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   596
  _bytes [RO][SymbolBucketType] = stats->symbol.bucket_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   597
  _bytes [RO][TypeArrayU4Type] -= stats->symbol.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   598
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   599
  // strings
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   600
  _counts[RO][StringHashentryType] = stats->string.hashentry_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   601
  _bytes [RO][StringHashentryType] = stats->string.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   602
  _bytes [RO][TypeArrayU4Type]    -= stats->string.hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   603
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   604
  _counts[RO][StringBucketType] = stats->string.bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   605
  _bytes [RO][StringBucketType] = stats->string.bucket_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   606
  _bytes [RO][TypeArrayU4Type] -= stats->string.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   607
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   608
  // TODO: count things like dictionary, vtable, etc
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   609
  _bytes[RW][OtherType] =  other_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   610
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   611
  // prevent divide-by-zero
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   612
  if (ro_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   613
    ro_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   614
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   615
  if (rw_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   616
    rw_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   617
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   618
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   619
  int all_ro_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   620
  int all_ro_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   621
  int all_rw_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   622
  int all_rw_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   623
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   624
// 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
   625
#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
   626
  const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   627
  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
   628
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   629
  ResourceMark rm;
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   630
  LogMessage(cds) msg;
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   631
  stringStream info_stream;
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   632
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   633
  info_stream.print_cr("Detailed metadata info (rw includes md and mc):");
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   634
  info_stream.print_cr("%s", hdr);
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   635
  info_stream.print_cr("%s", sep);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   636
  for (int type = 0; type < int(_number_of_types); type ++) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   637
    const char *name = type_name((Type)type);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   638
    int ro_count = _counts[RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   639
    int ro_bytes = _bytes [RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   640
    int rw_count = _counts[RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   641
    int rw_bytes = _bytes [RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   642
    int count = ro_count + rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   643
    int bytes = ro_bytes + rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   644
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   645
    double ro_perc = 100.0 * double(ro_bytes) / double(ro_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   646
    double rw_perc = 100.0 * double(rw_bytes) / double(rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   647
    double perc    = 100.0 * double(bytes)    / double(ro_all + rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   648
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   649
    info_stream.print_cr(fmt_stats, name,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   650
                         ro_count, ro_bytes, ro_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   651
                         rw_count, rw_bytes, rw_perc,
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   652
                         count, bytes, perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   653
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   654
    all_ro_count += ro_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   655
    all_ro_bytes += ro_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   656
    all_rw_count += rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   657
    all_rw_bytes += rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   658
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   659
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   660
  int all_count = all_ro_count + all_rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   661
  int all_bytes = all_ro_bytes + all_rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   662
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   663
  double all_ro_perc = 100.0 * double(all_ro_bytes) / double(ro_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   664
  double all_rw_perc = 100.0 * double(all_rw_bytes) / double(rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   665
  double all_perc    = 100.0 * double(all_bytes)    / double(ro_all + rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   666
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   667
  info_stream.print_cr("%s", sep);
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   668
  info_stream.print_cr(fmt_stats, "Total",
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   669
                       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
   670
                       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
   671
                       all_count, all_bytes, all_perc);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   672
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   673
  assert(all_ro_bytes == ro_all, "everything should have been counted");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   674
  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
   675
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   676
  msg.info("%s", info_stream.as_string());
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   677
#undef fmt_stats
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   678
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   679
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   680
// Populate the shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   681
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   682
class VM_PopulateDumpSharedSpace: public VM_Operation {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   683
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   684
  ClassLoaderData* _loader_data;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   685
  GrowableArray<Klass*> *_class_promote_order;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   686
  VirtualSpace _md_vs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   687
  VirtualSpace _mc_vs;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   688
  VirtualSpace _od_vs;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   689
  GrowableArray<MemRegion> *_string_regions;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   690
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   691
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   692
  VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   693
                             GrowableArray<Klass*> *class_promote_order) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   694
    _loader_data(loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   695
    _class_promote_order = class_promote_order;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   696
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   697
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   698
  VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   699
  void doit();   // outline because gdb sucks
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   700
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   701
private:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   702
  void handle_misc_data_space_failure(bool success) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   703
    if (!success) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   704
      report_out_of_shared_space(SharedMiscData);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   705
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   706
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   707
}; // class VM_PopulateDumpSharedSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   708
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   709
void VM_PopulateDumpSharedSpace::doit() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   710
  Thread* THREAD = VMThread::vm_thread();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   711
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   712
  // 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
   713
  // 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
   714
  // 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
   715
  // shared classes at runtime, where constraints were previously created.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   716
  guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   717
            "loader constraints are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   718
  guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   719
          "placeholders are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   720
  // Revisit and implement this if we prelink method handle call sites:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   721
  guarantee(SystemDictionary::invoke_method_table() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   722
            SystemDictionary::invoke_method_table()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   723
            "invoke method table is not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   724
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   725
  // At this point, many classes have been loaded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   726
  // 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
   727
  // that so we don't have to walk the SystemDictionary again.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   728
  _global_klass_objects = new GrowableArray<Klass*>(1000);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   729
  CollectClassesClosure collect_classes;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   730
  ClassLoaderDataGraph::loaded_classes_do(&collect_classes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   731
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   732
  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
   733
  {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   734
    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
   735
    for (int i = 0; i < _global_klass_objects->length(); i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   736
      Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   737
      if (k->is_instance_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   738
        num_inst ++;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   739
      } else if (k->is_objArray_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   740
        num_obj_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   741
      } else {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   742
        assert(k->is_typeArray_klass(), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   743
        num_type_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   744
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   745
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   746
    tty->print_cr("    instance classes   = %5d", num_inst);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   747
    tty->print_cr("    obj array classes  = %5d", num_obj_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   748
    tty->print_cr("    type array classes = %5d", num_type_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   749
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   750
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   751
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   752
  // Ensure the ConstMethods won't be modified at run-time
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   753
  tty->print("Updating ConstMethods ... ");
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   754
  rewrite_nofast_bytecodes_and_calculate_fingerprints();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   755
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   756
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   757
  // Remove all references outside the metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   758
  tty->print("Removing unshareable information ... ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   759
  remove_unshareable_in_classes();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   760
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   761
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   762
  // Set up the misc data, misc code and optional data segments.
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   763
  _md_vs = *MetaspaceShared::misc_data_region()->virtual_space();
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   764
  _mc_vs = *MetaspaceShared::misc_code_region()->virtual_space();
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   765
  _od_vs = *MetaspaceShared::optional_data_region()->virtual_space();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   766
  char* md_low = _md_vs.low();
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   767
  char* md_top = MetaspaceShared::misc_data_region()->alloc_top();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   768
  char* md_end = _md_vs.high();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   769
  char* mc_low = _mc_vs.low();
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   770
  char* mc_top = MetaspaceShared::misc_code_region()->alloc_top();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   771
  char* mc_end = _mc_vs.high();
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   772
  char* od_low = _od_vs.low();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   773
  char* od_top = MetaspaceShared::optional_data_region()->alloc_top();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   774
  char* od_end = _od_vs.high();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   775
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   776
  char* vtbl_list = md_top;
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   777
  md_top = (char*)MetaspaceShared::allocate_cpp_vtable_clones((intptr_t*)md_top, (intptr_t*)md_end);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   778
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   779
  // We don't use MC section anymore. We will remove it in a future RFE. For now, put one
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   780
  // byte inside so the region writing/mapping code works.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   781
  mc_top ++;
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   782
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   783
  // Reorder the system dictionary.  (Moving the symbols affects
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   784
  // how the hash table indices are calculated.)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   785
  // Not doing this either.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   786
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   787
  SystemDictionary::reorder_dictionary();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   788
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   789
  SystemDictionary::copy_buckets(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   790
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   791
  SystemDictionary::copy_table(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   792
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   793
  // Write the other data to the output array.
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   794
  // SymbolTable, StringTable and extra information for system dictionary
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   795
  NOT_PRODUCT(SymbolTable::verify());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   796
  NOT_PRODUCT(StringTable::verify());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   797
  size_t ss_bytes = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   798
  char* ss_low;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   799
  // The string space has maximum two regions. See FileMapInfo::write_string_regions() for details.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   800
  _string_regions = new GrowableArray<MemRegion>(2);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   801
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   802
  WriteClosure wc(md_top, md_end);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   803
  MetaspaceShared::serialize(&wc, _string_regions, &ss_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   804
  md_top = wc.get_top();
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   805
  ss_low = _string_regions->is_empty() ? NULL : (char*)_string_regions->first().start();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   806
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   807
  // Print shared spaces all the time
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   808
  Metaspace* ro_space = _loader_data->ro_metaspace();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   809
  Metaspace* rw_space = _loader_data->rw_metaspace();
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   810
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   811
  // Allocated size of each space (may not be all occupied)
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   812
  const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   813
  const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   814
  const size_t md_alloced = md_end-md_low;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   815
  const size_t mc_alloced = mc_end-mc_low;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   816
  const size_t od_alloced = od_end-od_low;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   817
  const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   818
                             + ss_bytes + od_alloced;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   819
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   820
  // Occupied size of each space.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   821
  const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   822
  const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   823
  const size_t md_bytes = size_t(md_top - md_low);
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   824
  const size_t mc_bytes = size_t(mc_top - mc_low);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   825
  const size_t od_bytes = size_t(od_top - od_low);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   826
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   827
  // Percent of total size
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   828
  const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes + od_bytes;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   829
  const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   830
  const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   831
  const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   832
  const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   833
  const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   834
  const double od_t_perc = od_bytes / double(total_bytes) * 100.0;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   835
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   836
  // Percent of fullness of each space
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   837
  const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   838
  const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   839
  const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   840
  const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   841
  const double od_u_perc = od_bytes / double(od_alloced) * 100.0;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   842
  const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   843
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   844
#define fmt_space "%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   845
  tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, p2i(ro_space->bottom()));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   846
  tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, p2i(rw_space->bottom()));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   847
  tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, p2i(md_low));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   848
  tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, p2i(mc_low));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   849
  tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes,   100.0,     p2i(ss_low));
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   850
  tty->print_cr(fmt_space, "od", od_bytes, od_t_perc, od_alloced, od_u_perc, p2i(od_low));
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
   851
  tty->print_cr("total   : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used]",
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   852
                 total_bytes, total_alloced, total_u_perc);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   853
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   854
  // 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
   855
  // 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
   856
  MetaspaceShared::patch_cpp_vtable_pointers();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   857
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   858
  // The vtable clones contain addresses of the current process.
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   859
  // 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
   860
  MetaspaceShared::zero_cpp_vtable_clones_for_writing();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   861
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   862
  // 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
   863
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   864
  FileMapInfo* mapinfo = new FileMapInfo();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   865
  mapinfo->populate_header(MetaspaceShared::max_alignment());
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   866
  mapinfo->set_misc_data_patching_start(vtbl_list);
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   867
  mapinfo->set_cds_i2i_entry_code_buffers(MetaspaceShared::cds_i2i_entry_code_buffers());
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   868
  mapinfo->set_cds_i2i_entry_code_buffers_size(MetaspaceShared::cds_i2i_entry_code_buffers_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   869
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   870
  for (int pass=1; pass<=2; pass++) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   871
    if (pass == 1) {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   872
      // The first pass doesn't actually write the data to disk. All it
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   873
      // does is to update the fields in the mapinfo->_header.
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   874
    } else {
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   875
      // After the first pass, the contents of mapinfo->_header are finalized,
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   876
      // so we can compute the header's CRC, and write the contents of the header
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   877
      // and the regions into disk.
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   878
      mapinfo->open_for_write();
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   879
      mapinfo->set_header_crc(mapinfo->compute_header_crc());
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   880
    }
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   881
    mapinfo->write_header();
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   882
    mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   883
    mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   884
    mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   885
                          pointer_delta(md_top, _md_vs.low(), sizeof(char)),
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   886
                          SharedMiscDataSize,
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
   887
                          false, true);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   888
    mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   889
                          pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   890
                          SharedMiscCodeSize,
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   891
                          true, true);
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   892
    mapinfo->write_string_regions(_string_regions);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   893
    mapinfo->write_region(MetaspaceShared::od, _od_vs.low(),
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   894
                          pointer_delta(od_top, _od_vs.low(), sizeof(char)),
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   895
                          pointer_delta(od_end, _od_vs.low(), sizeof(char)),
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
   896
                          true, false);
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
   897
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   898
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   899
  mapinfo->close();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   900
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
   901
  // 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
   902
  MetaspaceShared::clone_cpp_vtables((intptr_t*)vtbl_list);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   903
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
   904
  if (log_is_enabled(Info, cds)) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   905
    DumpAllocClosure dac;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   906
    dac.iterate_metaspace(_loader_data->ro_metaspace(), DumpAllocClosure::RO);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   907
    dac.iterate_metaspace(_loader_data->rw_metaspace(), DumpAllocClosure::RW);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   908
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   909
    dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   910
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   911
#undef fmt_space
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   912
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   913
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   914
class LinkSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   915
  Thread* THREAD;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   916
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   917
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   918
  LinkSharedClassesClosure(Thread* thread) : THREAD(thread), _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   919
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   920
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   921
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   922
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   923
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   924
    if (k->is_instance_klass()) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   925
      InstanceKlass* ik = InstanceKlass::cast(k);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   926
      // 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
   927
      // cpcache to be created. Class verification is done according
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   928
      // to -Xverify setting.
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   929
      _made_progress |= MetaspaceShared::try_link_class(ik, THREAD);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   930
      guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   931
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   932
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   933
};
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   934
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   935
class CheckSharedClassesClosure : public KlassClosure {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   936
  bool    _made_progress;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   937
 public:
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   938
  CheckSharedClassesClosure() : _made_progress(false) {}
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   939
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   940
  void reset()               { _made_progress = false; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   941
  bool made_progress() const { return _made_progress; }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   942
  void do_klass(Klass* k) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   943
    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
   944
      _made_progress = true;
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   945
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   946
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   947
};
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   948
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   949
void MetaspaceShared::check_shared_class_loader_type(Klass* k) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   950
  if (k->is_instance_klass()) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   951
    InstanceKlass* ik = InstanceKlass::cast(k);
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   952
    u2 loader_type = ik->loader_type();
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   953
    ResourceMark rm;
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   954
    guarantee(loader_type != 0,
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   955
              "Class loader type is not set for this class %s", ik->name()->as_C_string());
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   956
  }
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   957
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   958
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   959
void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   960
  // We need to iterate because verification may cause additional classes
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   961
  // to be loaded.
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   962
  LinkSharedClassesClosure link_closure(THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   963
  do {
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   964
    link_closure.reset();
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   965
    ClassLoaderDataGraph::loaded_classes_do(&link_closure);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   966
    guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   967
  } while (link_closure.made_progress());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   968
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   969
  if (_has_error_classes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   970
    // 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
   971
    CheckSharedClassesClosure check_closure;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   972
    do {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   973
      // 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
   974
      // 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
   975
      // 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
   976
      check_closure.reset();
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   977
      ClassLoaderDataGraph::loaded_classes_do(&check_closure);
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
   978
    } while (check_closure.made_progress());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   979
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   980
    if (IgnoreUnverifiableClassesDuringDump) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   981
      // This is useful when running JCK or SQE tests. You should not
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   982
      // enable this when running real apps.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   983
      SystemDictionary::remove_classes_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   984
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   985
      tty->print_cr("Please remove the unverifiable classes from your class list and try again");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   986
      exit(1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   987
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   988
  }
39713
29ece76096cb 8150752: Share Class Data
iklam
parents: 38943
diff changeset
   989
29ece76096cb 8150752: Share Class Data
iklam
parents: 38943
diff changeset
   990
  // Copy the verification constraints from C_HEAP-alloced GrowableArrays to RO-alloced
29ece76096cb 8150752: Share Class Data
iklam
parents: 38943
diff changeset
   991
  // Arrays
29ece76096cb 8150752: Share Class Data
iklam
parents: 38943
diff changeset
   992
  SystemDictionaryShared::finalize_verification_constraints();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   993
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   994
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   995
void MetaspaceShared::prepare_for_dumping() {
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
   996
  Arguments::check_unsupported_dumping_properties();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   997
  ClassLoader::initialize_shared_path();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   998
  FileMapInfo::allocate_classpath_entry_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   999
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1000
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1001
// 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
  1002
// file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1003
void MetaspaceShared::preload_and_dump(TRAPS) {
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents: 37094
diff changeset
  1004
  { TraceTime timer("Dump Shared Spaces", TRACETIME_LOG(Info, startuptime));
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1005
    ResourceMark rm;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1006
    char class_list_path_str[JVM_MAXPATHLEN];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1007
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1008
    tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1009
                  MetaspaceShared::shared_rs()->size(),
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1010
                  p2i(MetaspaceShared::shared_rs()->base()));
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1011
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1012
    // Preload classes to be shared.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1013
    // Should use some os:: method rather than fopen() here. aB.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1014
    const char* class_list_path;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1015
    if (SharedClassListFile == NULL) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1016
      // Construct the path to the class list (in jre/lib)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1017
      // Walk up two directories from the location of the VM and
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1018
      // optionally tack on "lib" (depending on platform)
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1019
      os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1020
      for (int i = 0; i < 3; i++) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1021
        char *end = strrchr(class_list_path_str, *os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1022
        if (end != NULL) *end = '\0';
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1023
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1024
      int class_list_path_len = (int)strlen(class_list_path_str);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1025
      if (class_list_path_len >= 3) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1026
        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
  1027
          if (class_list_path_len < JVM_MAXPATHLEN - 4) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1028
            jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1029
                         sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1030
                         "%slib", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1031
            class_list_path_len += 4;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1032
          }
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
  1033
        }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1034
      }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1035
      if (class_list_path_len < JVM_MAXPATHLEN - 10) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1036
        jio_snprintf(class_list_path_str + class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1037
                     sizeof(class_list_path_str) - class_list_path_len,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1038
                     "%sclasslist", os::file_separator());
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1039
      }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1040
      class_list_path = class_list_path_str;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1041
    } else {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1042
      class_list_path = SharedClassListFile;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1043
    }
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1044
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1045
    int class_count = 0;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1046
    GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1047
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1048
    // sun.io.Converters
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1049
    static const char obj_array_sig[] = "[[Ljava/lang/Object;";
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1050
    SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1051
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1052
    // java.util.HashMap
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1053
    static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1054
    SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1055
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1056
    // Need to allocate the op here:
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1057
    // op.misc_data_space_alloc() will be called during preload_and_dump().
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1058
    ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1059
    VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1060
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1061
    tty->print_cr("Loading classes to share ...");
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1062
    _has_error_classes = false;
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1063
    class_count += preload_and_dump(class_list_path, class_promote_order,
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1064
                                    THREAD);
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1065
    if (ExtraSharedClassListFile) {
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1066
      class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1067
                                      THREAD);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1068
    }
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1069
    tty->print_cr("Loading classes to share: done.");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1070
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1071
    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
  1072
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1073
    // Rewrite and link classes
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1074
    tty->print_cr("Rewriting and linking classes ...");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1075
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1076
    // 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
  1077
    // 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
  1078
    // 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
  1079
    // are implemented by K are not verified.
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1080
    link_and_cleanup_shared_classes(CATCH);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1081
    tty->print_cr("Rewriting and linking classes: done");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1082
36178
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1083
    VMThread::execute(&op);
9739f8c767da 8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents: 35231
diff changeset
  1084
  }
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1085
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1086
  if (PrintSystemDictionaryAtExit) {
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1087
    SystemDictionary::print();
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1088
  }
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46435
diff changeset
  1089
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1090
  // Since various initialization steps have been undone by this process,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1091
  // it is not reasonable to continue running a java process.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1092
  exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1093
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1094
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1095
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1096
int MetaspaceShared::preload_and_dump(const char* class_list_path,
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1097
                                      GrowableArray<Klass*>* class_promote_order,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1098
                                      TRAPS) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1099
  ClassListParser parser(class_list_path);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1100
  int class_count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1101
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1102
    while (parser.parse_one_line()) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1103
      Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1104
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1105
      CLEAR_PENDING_EXCEPTION;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
      if (klass != NULL) {
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1107
        if (log_is_enabled(Trace, cds)) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1108
          ResourceMark rm;
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46464
diff changeset
  1109
          log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1110
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1111
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1112
        InstanceKlass* ik = InstanceKlass::cast(klass);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1113
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37995
diff changeset
  1114
        // Should be class load order as per -Xlog:class+preorder
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1115
        class_promote_order->append(ik);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1116
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1117
        // Link the class to cause the bytecodes to be rewritten and the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1118
        // cpcache to be created. The linking is done as soon as classes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1119
        // are loaded in order that the related data structures (klass and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1120
        // cpCache) are located together.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1121
        try_link_class(ik, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1122
        guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1123
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1124
        class_count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1125
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1126
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1127
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1128
  return class_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1129
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1131
// Returns true if the class's status has changed
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1132
bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1133
  assert(DumpSharedSpaces, "should only be called during dumping");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1134
  if (ik->init_state() < InstanceKlass::linked) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1135
    bool saved = BytecodeVerificationLocal;
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1136
    if (!(ik->is_shared_boot_class())) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1137
      // The verification decision is based on BytecodeVerificationRemote
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1138
      // for non-system classes. Since we are using the NULL classloader
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1139
      // to load non-system classes during dumping, we need to temporarily
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1140
      // change BytecodeVerificationLocal to be the same as
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1141
      // BytecodeVerificationRemote. Note this can cause the parent system
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1142
      // classes also being verified. The extra overhead is acceptable during
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1143
      // dumping.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1144
      BytecodeVerificationLocal = BytecodeVerificationRemote;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1145
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1146
    ik->link_class(THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1147
    if (HAS_PENDING_EXCEPTION) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1148
      ResourceMark rm;
27618
790a8bf5488b 8064375: Change certain errors to warnings in CDS output.
jiangli
parents: 27025
diff changeset
  1149
      tty->print_cr("Preload Warning: Verification failed for %s",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1150
                    ik->external_name());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1151
      CLEAR_PENDING_EXCEPTION;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1152
      ik->set_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1153
      _has_error_classes = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1154
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1155
    BytecodeVerificationLocal = saved;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1156
    return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1157
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1158
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1159
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1160
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1161
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1162
// Closure for serializing initialization data in from a data area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1163
// (ptr_array) read from the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1164
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1165
class ReadClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1166
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1167
  intptr_t** _ptr_array;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1168
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1169
  inline intptr_t nextPtr() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1170
    return *(*_ptr_array)++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1171
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1172
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1173
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1174
  ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1175
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1176
  void do_ptr(void** p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1177
    assert(*p == NULL, "initializing previous initialized pointer.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1178
    intptr_t obj = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1179
    assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1180
           "hit tag while initializing ptrs.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1181
    *p = (void*)obj;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1182
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1183
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1184
  void do_u4(u4* p) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1185
    intptr_t obj = nextPtr();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1186
    *p = (u4)(uintx(obj));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1187
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1188
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1189
  void do_tag(int tag) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1190
    int old_tag;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1191
    old_tag = (int)(intptr_t)nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1192
    // do_int(&old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1193
    assert(tag == old_tag, "old tag doesn't match");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1194
    FileMapInfo::assert_mark(tag == old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1195
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1196
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1197
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1200
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1201
    while (size > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1202
      *(intptr_t*)start = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1205
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1206
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1207
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1208
  bool reading() const { return true; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1209
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1210
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1211
// Return true if given address is in the mapped shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1212
bool MetaspaceShared::is_in_shared_space(const void* p) {
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1213
  return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_space(p);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1214
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1215
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1216
// 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
  1217
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
  1218
  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
  1219
}
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1220
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1221
bool MetaspaceShared::is_string_region(int idx) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1222
  return (idx >= MetaspaceShared::first_string &&
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1223
          idx < MetaspaceShared::first_string + MetaspaceShared::max_strings);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1224
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1225
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1226
void MetaspaceShared::print_shared_spaces() {
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1227
  if (UseSharedSpaces) {
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1228
    FileMapInfo::current_info()->print_shared_spaces();
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1229
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1231
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1232
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1233
// 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
  1234
bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1235
  size_t image_alignment = mapinfo->alignment();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1236
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1237
#ifndef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1238
  // 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
  1239
  // 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
  1240
  // mappings of the regions to fail.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1241
  ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1242
  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
  1243
#endif
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1244
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1245
  assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1246
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1247
  char* _ro_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1248
  char* _rw_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1249
  char* _md_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1250
  char* _mc_base = NULL;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
  1251
  char* _od_base = NULL;
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1252
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1253
  // Map each shared region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1254
  if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1255
      mapinfo->verify_region_checksum(ro) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1256
      (_rw_base = mapinfo->map_region(rw)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1257
      mapinfo->verify_region_checksum(rw) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1258
      (_md_base = mapinfo->map_region(md)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1259
      mapinfo->verify_region_checksum(md) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1260
      (_mc_base = mapinfo->map_region(mc)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1261
      mapinfo->verify_region_checksum(mc) &&
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
  1262
      (_od_base = mapinfo->map_region(od)) != NULL &&
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
  1263
      mapinfo->verify_region_checksum(od) &&
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1264
      (image_alignment == (size_t)max_alignment()) &&
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1265
      mapinfo->validate_classpath_entry_table()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1266
    // Success (no need to do anything)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1267
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1268
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1269
    // If there was a failure in mapping any of the spaces, unmap the ones
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1270
    // that succeeded
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1271
    if (_ro_base != NULL) mapinfo->unmap_region(ro);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1272
    if (_rw_base != NULL) mapinfo->unmap_region(rw);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1273
    if (_md_base != NULL) mapinfo->unmap_region(md);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1274
    if (_mc_base != NULL) mapinfo->unmap_region(mc);
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents: 39714
diff changeset
  1275
    if (_od_base != NULL) mapinfo->unmap_region(od);
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1276
#ifndef _WINDOWS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1277
    // Release the entire mapped region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1278
    shared_rs.release();
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1279
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1280
    // 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
  1281
    // 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
  1282
    if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1283
      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
  1284
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1285
      FLAG_SET_DEFAULT(UseSharedSpaces, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1286
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1287
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1288
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1289
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1290
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1291
// Read the miscellaneous data from the shared file, and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1292
// serialize it out to its various destinations.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1293
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1294
void MetaspaceShared::initialize_shared_spaces() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1295
  FileMapInfo *mapinfo = FileMapInfo::current_info();
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1296
  _cds_i2i_entry_code_buffers = mapinfo->cds_i2i_entry_code_buffers();
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 37248
diff changeset
  1297
  _cds_i2i_entry_code_buffers_size = mapinfo->cds_i2i_entry_code_buffers_size();
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34257
diff changeset
  1298
  char* buffer = mapinfo->misc_data_patching_start();
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1299
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 43410
diff changeset
  1300
  buffer = (char*)clone_cpp_vtables((intptr_t*)buffer);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1301
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1302
  int sharedDictionaryLen = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1303
  buffer += sizeof(intptr_t);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1304
  int number_of_entries = *(intptr_t*)buffer;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1305
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1306
  SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1307
                                          sharedDictionaryLen,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1308
                                          number_of_entries);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1309
  buffer += sharedDictionaryLen;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1310
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1311
  // The following data in the shared misc data region are the linked
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1312
  // list elements (HashtableEntry objects) for the shared dictionary
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36178
diff changeset
  1313
  // table.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1314
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1315
  int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1316
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1317
  buffer += len;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1318
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1319
  // Verify various attributes of the archive, plus initialize the
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1320
  // shared string/symbol tables
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1321
  intptr_t* array = (intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1322
  ReadClosure rc(&array);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1323
  serialize(&rc, NULL, NULL);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1324
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1325
  // Initialize the run-time symbol table.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37439
diff changeset
  1326
  SymbolTable::create_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1327
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1328
  // Close the mapinfo file
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1329
  mapinfo->close();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1330
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1331
  if (PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1332
    if (PrintSharedDictionary) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1333
      tty->print_cr("\nShared classes:\n");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1334
      SystemDictionary::print_shared(false);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1335
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1336
    if (_archive_loading_failed) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1337
      tty->print_cr("archive is invalid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1338
      vm_exit(1);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1339
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1340
      tty->print_cr("archive is valid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1341
      vm_exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1342
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1343
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1344
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1345
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1346
void MetaspaceShared::fixup_shared_string_regions() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1347
  FileMapInfo *mapinfo = FileMapInfo::current_info();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1348
  mapinfo->fixup_string_regions();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1349
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1350
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1351
// JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1352
bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1353
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1354
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1355
  if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1356
    // remap the shared readonly space to shared readwrite, private
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1357
    FileMapInfo* mapinfo = FileMapInfo::current_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1358
    if (!mapinfo->remap_shared_readonly_as_readwrite()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1359
      return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
    }
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 39713
diff changeset
  1361
    _remapped_readwrite = true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
  return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1364
}
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1365
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1366
int MetaspaceShared::count_class(const char* classlist_file) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1367
  if (classlist_file == NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1368
    return 0;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1369
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1370
  char class_name[256];
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1371
  int class_count = 0;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1372
  FILE* file = fopen(classlist_file, "r");
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1373
  if (file != NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1374
    while ((fgets(class_name, sizeof class_name, file)) != NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1375
      if (*class_name == '#') { // comment
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1376
        continue;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1377
      }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1378
      class_count++;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1379
    }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1380
    fclose(file);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1381
  } else {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1382
    char errmsg[JVM_MAXPATHLEN];
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1383
    os::lasterror(errmsg, JVM_MAXPATHLEN);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1384
    tty->print_cr("Loading classlist failed: %s", errmsg);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1385
    exit(1);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1386
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1387
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1388
  return class_count;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1389
}
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1390
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1391
// the sizes are good for typical large applications that have a lot of shared
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1392
// classes
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1393
void MetaspaceShared::estimate_regions_size() {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1394
  int class_count = count_class(SharedClassListFile);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1395
  class_count += count_class(ExtraSharedClassListFile);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1396
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1397
  if (class_count > LargeThresholdClassCount) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1398
    if (class_count < HugeThresholdClassCount) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1399
      SET_ESTIMATED_SIZE(Large, ReadOnly);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1400
      SET_ESTIMATED_SIZE(Large, ReadWrite);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1401
      SET_ESTIMATED_SIZE(Large, MiscData);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1402
      SET_ESTIMATED_SIZE(Large, MiscCode);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1403
    } else {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1404
      SET_ESTIMATED_SIZE(Huge,  ReadOnly);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1405
      SET_ESTIMATED_SIZE(Huge,  ReadWrite);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1406
      SET_ESTIMATED_SIZE(Huge,  MiscData);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1407
      SET_ESTIMATED_SIZE(Huge,  MiscCode);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1408
    }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1409
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1410
}