annotate src/hotspot/share/memory/metaspaceShared.cpp @ 53564:dfa02b3f728c

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