src/hotspot/share/memory/metaspaceShared.hpp
author iklam
Tue, 14 Aug 2018 09:59:37 -0700
changeset 51491 187c84a5efe1
parent 51417 b08c2a94cce1
child 51674 d7dcaacb95dd
permissions -rw-r--r--
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed Summary: Relocate and patch archive regions if necessary Reviewed-by: jiangli, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
30578
8b6c44532ca2 8079148: Fix incorrect include guards
pliden
parents: 28363
diff changeset
    24
8b6c44532ca2 8079148: Fix incorrect include guards
pliden
parents: 28363
diff changeset
    25
#ifndef SHARE_VM_MEMORY_METASPACESHARED_HPP
8b6c44532ca2 8079148: Fix incorrect include guards
pliden
parents: 28363
diff changeset
    26
#define SHARE_VM_MEMORY_METASPACESHARED_HPP
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    27
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    28
#include "classfile/compactHashtable.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "memory/allocation.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "memory/memRegion.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 28363
diff changeset
    31
#include "memory/virtualspace.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49364
diff changeset
    32
#include "oops/oop.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "utilities/exceptions.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "utilities/macros.hpp"
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    35
#include "utilities/resourceHash.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
34242
e530decd7c63 8138983: Runtime: implement ranges for Shared*** flags
gziemski
parents: 31345
diff changeset
    37
#define MAX_SHARED_DELTA                (0x7FFFFFFF)
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    38
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
class FileMapInfo;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 49329
diff changeset
    41
class MetaspaceSharedStats {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    42
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    43
  MetaspaceSharedStats() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    44
    memset(this, 0, sizeof(*this));
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    45
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    46
  CompactHashtableStats symbol;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30579
diff changeset
    47
  CompactHashtableStats string;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    48
};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    49
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
// Class Data Sharing Support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
class MetaspaceShared : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
  // CDS support
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    54
  static ReservedSpace _shared_rs;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    55
  static VirtualSpace _shared_vs;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    56
  static int _max_alignment;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
    57
  static MetaspaceSharedStats _stats;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    58
  static bool _has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    59
  static bool _archive_loading_failed;
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 38634
diff changeset
    60
  static bool _remapped_readwrite;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    61
  static bool _open_archive_heap_region_mapped;
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
    62
  static address _cds_i2i_entry_code_buffers;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
    63
  static size_t  _cds_i2i_entry_code_buffers_size;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    64
  static size_t  _core_spaces_size;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    65
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    66
  enum {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    67
    // core archive spaces
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    68
    mc = 0,  // miscellaneous code for method trampolines
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
    rw = 1,  // read-write shared space in the heap
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    70
    ro = 2,  // read-only shared space in the heap
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    71
    md = 3,  // miscellaneous data for initializing tables, etc.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    72
    num_core_spaces = 4, // number of non-string regions
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    73
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    74
    // optional mapped spaces
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    75
    // Currently it only contains class file data.
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    76
    od = num_core_spaces,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    77
    num_non_heap_spaces = od + 1,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    78
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    79
    // mapped java heap regions
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    80
    first_string = od + 1, // index of first string region
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30579
diff changeset
    81
    max_strings = 2, // max number of string regions in string space
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51417
diff changeset
    82
    last_string = first_string + max_strings - 1,
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    83
    first_open_archive_heap_region = first_string + max_strings,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    84
    max_open_archive_heap_region = 2,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    85
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    86
    last_valid_region = first_open_archive_heap_region + max_open_archive_heap_region - 1,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    87
    n_regions =  last_valid_region + 1 // total number of regions
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    88
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    89
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    90
  static void prepare_for_dumping() NOT_CDS_RETURN;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    91
  static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    92
  static int preload_classes(const char * class_list_path,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
    93
                             TRAPS) NOT_CDS_RETURN_(0);
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    94
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    95
#if INCLUDE_CDS_JAVA_HEAP
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    96
 private:
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    97
  static bool obj_equals(oop const& p1, oop const& p2) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    98
    return p1 == p2;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    99
  }
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49364
diff changeset
   100
  static unsigned obj_hash(oop const& p);
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49364
diff changeset
   101
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   102
  typedef ResourceHashtable<oop, oop,
46989
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   103
      MetaspaceShared::obj_hash,
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   104
      MetaspaceShared::obj_equals,
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   105
      15889, // prime number
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   106
      ResourceObj::C_HEAP> ArchivedObjectCache;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   107
  static ArchivedObjectCache* _archive_object_cache;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   108
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   109
 public:
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   110
  static ArchivedObjectCache* archive_object_cache() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   111
    return _archive_object_cache;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   112
  }
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   113
  static oop find_archived_heap_object(oop obj);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   114
  static oop archive_heap_object(oop obj, Thread* THREAD);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51417
diff changeset
   115
  static oop materialize_archived_object(narrowOop v);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   116
  static void archive_klass_objects(Thread* THREAD);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   117
#endif
50056
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
   118
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
   119
  static bool is_archive_object(oop p) NOT_CDS_JAVA_HEAP_RETURN_(false);
ca1f2d4d4ec8 8202709: Move oopDesc::is_archive_object to MetaspaceShared::is_archive_object
stefank
parents: 50039
diff changeset
   120
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   121
  static bool is_heap_object_archiving_allowed() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   122
    CDS_JAVA_HEAP_ONLY(return (UseG1GC && UseCompressedOops && UseCompressedClassPointers);)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   123
    NOT_CDS_JAVA_HEAP(return false;)
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   124
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   125
  static void create_archive_object_cache() {
46989
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   126
    CDS_JAVA_HEAP_ONLY(_archive_object_cache = new (ResourceObj::C_HEAP, mtClass)ArchivedObjectCache(););
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   127
  }
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   128
  static void destroy_archive_object_cache() {
119e1e88cf15 8186706: ArchivedObjectCache obj_hash() is broken.
jiangli
parents: 46810
diff changeset
   129
    CDS_JAVA_HEAP_ONLY(delete _archive_object_cache; _archive_object_cache = NULL;);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   130
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   131
  static void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   132
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   133
  static void dump_closed_archive_heap_objects(GrowableArray<MemRegion> * closed_archive) NOT_CDS_JAVA_HEAP_RETURN;
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   134
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   135
  static void dump_open_archive_heap_objects(GrowableArray<MemRegion> * open_archive) NOT_CDS_JAVA_HEAP_RETURN;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   136
  static void set_open_archive_heap_region_mapped() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   137
    CDS_JAVA_HEAP_ONLY(_open_archive_heap_region_mapped = true);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   138
    NOT_CDS_JAVA_HEAP_RETURN;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   139
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   140
  static bool open_archive_heap_region_mapped() {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   141
    CDS_JAVA_HEAP_ONLY(return _open_archive_heap_region_mapped);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   142
    NOT_CDS_JAVA_HEAP_RETURN_(false);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   143
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   144
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   145
  static ReservedSpace* shared_rs() {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   146
    CDS_ONLY(return &_shared_rs);
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   147
    NOT_CDS(return NULL);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   148
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   149
  static void commit_shared_space_to(char* newtop) NOT_CDS_RETURN;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   150
  static size_t core_spaces_size() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   151
    return _core_spaces_size;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   152
  }
47599
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   153
  static void initialize_dumptime_shared_and_meta_spaces() NOT_CDS_RETURN;
0fb1d501c408 8174986: CDS archived java heap region may not compatible with AOT
jiangli
parents: 47216
diff changeset
   154
  static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49480
diff changeset
   155
  static void post_initialize(TRAPS) NOT_CDS_RETURN;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   156
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   157
  // Delta of this object from the bottom of the archive.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   158
  static uintx object_delta(void* obj) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   159
    assert(DumpSharedSpaces, "supported only for dumping");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   160
    assert(shared_rs()->contains(obj), "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   161
    address base_address = address(shared_rs()->base());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   162
    uintx delta = address(obj) - base_address;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   163
    return delta;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   164
  }
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   165
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   166
  static void set_archive_loading_failed() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   167
    _archive_loading_failed = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   168
  }
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   169
  static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   170
  static void initialize_shared_spaces() NOT_CDS_RETURN;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   172
  // Return true if given address is in the shared metaspace regions (i.e., excluding any
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   173
  // mapped shared heap regions.)
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   174
  static bool is_in_shared_metaspace(const void* p) {
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   175
    // If no shared metaspace regions are mapped, MetaspceObj::_shared_metaspace_{base,top} will
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   176
    // both be NULL and all values of p will be rejected quickly.
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   177
    return (p < MetaspaceObj::_shared_metaspace_top && p >= MetaspaceObj::_shared_metaspace_base);
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47599
diff changeset
   178
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   179
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   180
  // Return true if given address is in the shared region corresponding to the idx
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   181
  static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   182
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   183
  static bool is_heap_region(int idx) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   184
    CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_string &&
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   185
                               idx < MetaspaceShared::first_open_archive_heap_region +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   186
                                     MetaspaceShared::max_open_archive_heap_region));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   187
    NOT_CDS_JAVA_HEAP_RETURN_(false);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   188
  }
46600
fdde0f192cde 8183001: Various inlining improvements
redestad
parents: 46464
diff changeset
   189
  static bool is_string_region(int idx) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   190
    CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_string &&
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   191
                               idx < MetaspaceShared::first_string + MetaspaceShared::max_strings));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   192
    NOT_CDS_JAVA_HEAP_RETURN_(false);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   193
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   194
  static bool is_open_archive_heap_region(int idx) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   195
    CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_open_archive_heap_region &&
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   196
                               idx < MetaspaceShared::first_open_archive_heap_region +
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   197
                                     MetaspaceShared::max_open_archive_heap_region));
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   198
    NOT_CDS_JAVA_HEAP_RETURN_(false);
46600
fdde0f192cde 8183001: Various inlining improvements
redestad
parents: 46464
diff changeset
   199
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   200
  static bool is_in_trampoline_frame(address addr) NOT_CDS_RETURN_(false);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30579
diff changeset
   201
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   202
  static void allocate_cpp_vtable_clones();
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 41182
diff changeset
   203
  static intptr_t* clone_cpp_vtables(intptr_t* p);
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 41182
diff changeset
   204
  static void zero_cpp_vtable_clones_for_writing();
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 41182
diff changeset
   205
  static void patch_cpp_vtable_pointers();
46718
1fd6f7bc17c9 8183038: Minimal vm slowdebug build fails with undefined reference to MetaspaceShared::is_valid_shared_method
iklam
parents: 46600
diff changeset
   206
  static bool is_valid_shared_method(const Method* m) NOT_CDS_RETURN_(false);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   207
  static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
46324
8764956ec928 8005165: Remove CPU-dependent code in self-patching vtables
iklam
parents: 41182
diff changeset
   208
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
   209
  static MetaspaceSharedStats* stats() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
   210
    return &_stats;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
   211
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28023
diff changeset
   212
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   213
  static void report_out_of_space(const char* name, size_t needed_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   214
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   215
  // JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   216
  // Remap the shared readonly space to shared readwrite, private if
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   217
  // sharing is enabled. Simply returns true if sharing is not enabled
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   218
  // or if the remapping has already been done by a prior call.
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   219
  static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
39714
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 38634
diff changeset
   220
  static bool remapped_readwrite() {
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 38634
diff changeset
   221
    CDS_ONLY(return _remapped_readwrite);
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 38634
diff changeset
   222
    NOT_CDS(return false);
976b97b59d87 8153312: Constrain AppCDS behavior
jiangli
parents: 38634
diff changeset
   223
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   224
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   225
  static bool try_link_class(InstanceKlass* ik, TRAPS);
46464
6432a858a220 8180325: Use ClassLoaderData::classes_do for CDS classes
coleenp
parents: 46427
diff changeset
   226
  static void link_and_cleanup_shared_classes(TRAPS);
50206
adec398d9051 8193332: MetaspaceShared::check_shared_class_loader_type is not used during archive creation
iklam
parents: 50056
diff changeset
   227
  static void check_shared_class_loader_type(InstanceKlass* ik);
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
   228
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   229
  // Allocate a block of memory from the "mc", "ro", or "rw" regions.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   230
  static char* misc_code_space_alloc(size_t num_bytes);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   231
  static char* read_only_space_alloc(size_t num_bytes);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 31345
diff changeset
   232
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50532
diff changeset
   233
  static char* read_only_space_top();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 50532
diff changeset
   234
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   235
  template <typename T>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   236
  static Array<T>* new_ro_array(int length) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   237
#if INCLUDE_CDS
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   238
    size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   239
    Array<T>* array = (Array<T>*)read_only_space_alloc(byte_size);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   240
    array->initialize(length);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   241
    return array;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   242
#else
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   243
    return NULL;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   244
#endif
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   245
  }
35231
e89989198037 8145593: Clean up metaspaceShared.cpp
iklam
parents: 34259
diff changeset
   246
37439
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   247
  static address cds_i2i_entry_code_buffers(size_t total_size);
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   248
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   249
  static address cds_i2i_entry_code_buffers() {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   250
    return _cds_i2i_entry_code_buffers;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   251
  }
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   252
  static size_t cds_i2i_entry_code_buffers_size() {
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   253
    return _cds_i2i_entry_code_buffers_size;
e8970711113b 8145221: Use trampolines for i2i and i2c entries in Methods that are stored in CDS archive
ccheung
parents: 36508
diff changeset
   254
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46718
diff changeset
   255
  static void relocate_klass_ptr(oop o);
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   256
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48794
diff changeset
   257
  static Klass* get_relocated_klass(Klass *k);
50039
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49480
diff changeset
   258
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49480
diff changeset
   259
private:
9fec54fe663d 8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents: 49480
diff changeset
   260
  static void read_extra_data(const char* filename, TRAPS) NOT_CDS_RETURN;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   261
};
30578
8b6c44532ca2 8079148: Fix incorrect include guards
pliden
parents: 28363
diff changeset
   262
#endif // SHARE_VM_MEMORY_METASPACESHARED_HPP