< prev index next >

src/share/vm/memory/metaspaceShared.hpp

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_METASPACESHARED_HPP
  26 #define SHARE_VM_MEMORY_METASPACESHARED_HPP
  27 
  28 #include "classfile/compactHashtable.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "memory/memRegion.hpp"
  31 #include "memory/virtualspace.hpp"
  32 #include "utilities/exceptions.hpp"
  33 #include "utilities/macros.hpp"

  34 
  35 #define MAX_SHARED_DELTA                (0x7FFFFFFF)
  36 
  37 class FileMapInfo;
  38 
  39 class MetaspaceSharedStats VALUE_OBJ_CLASS_SPEC {
  40 public:
  41   MetaspaceSharedStats() {
  42     memset(this, 0, sizeof(*this));
  43   }
  44   CompactHashtableStats symbol;
  45   CompactHashtableStats string;
  46 };
  47 
  48 // Class Data Sharing Support
  49 class MetaspaceShared : AllStatic {
  50 
  51   // CDS support
  52   static ReservedSpace _shared_rs;
  53   static VirtualSpace _shared_vs;
  54   static int _max_alignment;
  55   static MetaspaceSharedStats _stats;
  56   static bool _has_error_classes;
  57   static bool _archive_loading_failed;
  58   static bool _remapped_readwrite;

  59   static address _cds_i2i_entry_code_buffers;
  60   static size_t  _cds_i2i_entry_code_buffers_size;
  61   static size_t  _core_spaces_size;
  62  public:
  63   enum {

  64     mc = 0,  // miscellaneous code for method trampolines
  65     rw = 1,  // read-write shared space in the heap
  66     ro = 2,  // read-only shared space in the heap
  67     md = 3,  // miscellaneous data for initializing tables, etc.
  68     max_strings = 2, // max number of string regions in string space
  69     num_non_strings = 4, // number of non-string regions
  70     first_string = num_non_strings, // index of first string region
  71     // The optional data region is the last region.
  72     // Currently it only contains class file data.
  73     od = max_strings + num_non_strings,
  74     last_valid_region = od,
  75     n_regions = od + 1 // total number of regions








  76   };
  77 
  78   static void prepare_for_dumping() NOT_CDS_RETURN;
  79   static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
  80   static int preload_classes(const char * class_list_path,
  81                              TRAPS) NOT_CDS_RETURN_(0);
  82 







































  83   static ReservedSpace* shared_rs() {
  84     CDS_ONLY(return &_shared_rs);
  85     NOT_CDS(return NULL);
  86   }
  87   static void commit_shared_space_to(char* newtop) NOT_CDS_RETURN;
  88   static size_t core_spaces_size() {
  89     return _core_spaces_size;
  90   }
  91   static void initialize_shared_rs() NOT_CDS_RETURN;
  92 
  93   // Delta of this object from the bottom of the archive.
  94   static uintx object_delta(void* obj) {
  95     assert(DumpSharedSpaces, "supported only for dumping");
  96     assert(shared_rs()->contains(obj), "must be");
  97     address base_address = address(shared_rs()->base());
  98     uintx delta = address(obj) - base_address;
  99     return delta;
 100   }
 101 
 102   static void set_archive_loading_failed() {
 103     _archive_loading_failed = true;
 104   }
 105   static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
 106   static void initialize_shared_spaces() NOT_CDS_RETURN;
 107   static void fixup_shared_string_regions() NOT_CDS_RETURN;
 108 
 109   // Return true if given address is in the mapped shared space.
 110   static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
 111 
 112   // Return true if given address is in the shared region corresponding to the idx
 113   static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);







 114   static bool is_string_region(int idx) {
 115       CDS_ONLY(return (idx >= first_string && idx < first_string + max_strings));
 116       NOT_CDS(return false);







 117   }
 118   static bool is_in_trampoline_frame(address addr) NOT_CDS_RETURN_(false);
 119 
 120   static void allocate_cpp_vtable_clones();
 121   static intptr_t* clone_cpp_vtables(intptr_t* p);
 122   static void zero_cpp_vtable_clones_for_writing();
 123   static void patch_cpp_vtable_pointers();
 124   static bool is_valid_shared_method(const Method* m) NOT_CDS_RETURN_(false);
 125   static void serialize(SerializeClosure* sc);
 126 
 127 
 128   static MetaspaceSharedStats* stats() {
 129     return &_stats;
 130   }
 131 
 132   static void report_out_of_space(const char* name, size_t needed_bytes);
 133 
 134   // JVM/TI RedefineClasses() support:
 135   // Remap the shared readonly space to shared readwrite, private if
 136   // sharing is enabled. Simply returns true if sharing is not enabled
 137   // or if the remapping has already been done by a prior call.
 138   static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
 139   static bool remapped_readwrite() {
 140     CDS_ONLY(return _remapped_readwrite);
 141     NOT_CDS(return false);
 142   }
 143 
 144   static void print_shared_spaces();
 145 
 146   static bool try_link_class(InstanceKlass* ik, TRAPS);




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_METASPACESHARED_HPP
  26 #define SHARE_VM_MEMORY_METASPACESHARED_HPP
  27 
  28 #include "classfile/compactHashtable.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "memory/memRegion.hpp"
  31 #include "memory/virtualspace.hpp"
  32 #include "utilities/exceptions.hpp"
  33 #include "utilities/macros.hpp"
  34 #include "utilities/resourceHash.hpp"
  35 
  36 #define MAX_SHARED_DELTA                (0x7FFFFFFF)
  37 
  38 class FileMapInfo;
  39 
  40 class MetaspaceSharedStats VALUE_OBJ_CLASS_SPEC {
  41 public:
  42   MetaspaceSharedStats() {
  43     memset(this, 0, sizeof(*this));
  44   }
  45   CompactHashtableStats symbol;
  46   CompactHashtableStats string;
  47 };
  48 
  49 // Class Data Sharing Support
  50 class MetaspaceShared : AllStatic {
  51 
  52   // CDS support
  53   static ReservedSpace _shared_rs;
  54   static VirtualSpace _shared_vs;
  55   static int _max_alignment;
  56   static MetaspaceSharedStats _stats;
  57   static bool _has_error_classes;
  58   static bool _archive_loading_failed;
  59   static bool _remapped_readwrite;
  60   static bool _open_archive_heap_region_mapped;
  61   static address _cds_i2i_entry_code_buffers;
  62   static size_t  _cds_i2i_entry_code_buffers_size;
  63   static size_t  _core_spaces_size;
  64  public:
  65   enum {
  66     // core archive spaces
  67     mc = 0,  // miscellaneous code for method trampolines
  68     rw = 1,  // read-write shared space in the heap
  69     ro = 2,  // read-only shared space in the heap
  70     md = 3,  // miscellaneous data for initializing tables, etc.
  71     num_core_spaces = 4, // number of non-string regions
  72 
  73     // optional mapped spaces

  74     // Currently it only contains class file data.
  75     od = num_core_spaces,
  76     num_non_heap_spaces = od + 1,
  77 
  78     // mapped java heap regions
  79     first_string = od + 1, // index of first string region
  80     max_strings = 2, // max number of string regions in string space
  81     first_open_archive_heap_region = first_string + max_strings,
  82     max_open_archive_heap_region = 2,
  83 
  84     last_valid_region = first_open_archive_heap_region + max_open_archive_heap_region - 1,
  85     n_regions =  last_valid_region + 1 // total number of regions
  86   };
  87 
  88   static void prepare_for_dumping() NOT_CDS_RETURN;
  89   static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
  90   static int preload_classes(const char * class_list_path,
  91                              TRAPS) NOT_CDS_RETURN_(0);
  92 
  93 #if INCLUDE_CDS_JAVA_HEAP
  94  private:
  95   static bool obj_equals(oop const& p1, oop const& p2) {
  96     return p1 == p2;
  97   }
  98   static unsigned obj_hash(oop const& p) {
  99     unsigned hash = (unsigned)((uintptr_t)&p);
 100     return hash ^ (hash >> LogMinObjAlignment);
 101   }
 102   typedef ResourceHashtable<oop, oop,
 103       MetaspaceShared::obj_hash, MetaspaceShared::obj_equals> ArchivedObjectCache;
 104   static ArchivedObjectCache* _archive_object_cache;
 105 
 106  public:
 107   static ArchivedObjectCache* archive_object_cache() {
 108     return _archive_object_cache;
 109   }
 110   static oop archive_heap_object(oop obj, Thread* THREAD);
 111   static void archive_resolved_constants(Thread* THREAD);
 112 #endif
 113   static bool is_heap_object_archiving_allowed() {
 114     CDS_JAVA_HEAP_ONLY(return (UseG1GC && UseCompressedOops && UseCompressedClassPointers);)
 115     NOT_CDS_JAVA_HEAP(return false;)
 116   }
 117   static void create_archive_object_cache() {
 118     CDS_JAVA_HEAP_ONLY(_archive_object_cache = new ArchivedObjectCache(););
 119   }
 120   static void fixup_mapped_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;
 121 
 122   static void dump_open_archive_heap_objects(GrowableArray<MemRegion> * open_archive) NOT_CDS_JAVA_HEAP_RETURN;
 123   static void set_open_archive_heap_region_mapped() {
 124     CDS_JAVA_HEAP_ONLY(_open_archive_heap_region_mapped = true);
 125     NOT_CDS_JAVA_HEAP_RETURN;
 126   }
 127   static bool open_archive_heap_region_mapped() {
 128     CDS_JAVA_HEAP_ONLY(return _open_archive_heap_region_mapped);
 129     NOT_CDS_JAVA_HEAP_RETURN_(false);
 130   }
 131 
 132   static ReservedSpace* shared_rs() {
 133     CDS_ONLY(return &_shared_rs);
 134     NOT_CDS(return NULL);
 135   }
 136   static void commit_shared_space_to(char* newtop) NOT_CDS_RETURN;
 137   static size_t core_spaces_size() {
 138     return _core_spaces_size;
 139   }
 140   static void initialize_shared_rs() NOT_CDS_RETURN;
 141 
 142   // Delta of this object from the bottom of the archive.
 143   static uintx object_delta(void* obj) {
 144     assert(DumpSharedSpaces, "supported only for dumping");
 145     assert(shared_rs()->contains(obj), "must be");
 146     address base_address = address(shared_rs()->base());
 147     uintx delta = address(obj) - base_address;
 148     return delta;
 149   }
 150 
 151   static void set_archive_loading_failed() {
 152     _archive_loading_failed = true;
 153   }
 154   static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
 155   static void initialize_shared_spaces() NOT_CDS_RETURN;

 156 
 157   // Return true if given address is in the mapped shared space.
 158   static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
 159 
 160   // Return true if given address is in the shared region corresponding to the idx
 161   static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
 162 
 163   static bool is_heap_region(int idx) {
 164     CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_string &&
 165                                idx < MetaspaceShared::first_open_archive_heap_region +
 166                                      MetaspaceShared::max_open_archive_heap_region));
 167     NOT_CDS_JAVA_HEAP_RETURN_(false);
 168   }
 169   static bool is_string_region(int idx) {
 170     CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_string &&
 171                                idx < MetaspaceShared::first_string + MetaspaceShared::max_strings));
 172     NOT_CDS_JAVA_HEAP_RETURN_(false);
 173   }
 174   static bool is_open_archive_heap_region(int idx) {
 175     CDS_JAVA_HEAP_ONLY(return (idx >= MetaspaceShared::first_open_archive_heap_region &&
 176                                idx < MetaspaceShared::first_open_archive_heap_region +
 177                                      MetaspaceShared::max_open_archive_heap_region));
 178     NOT_CDS_JAVA_HEAP_RETURN_(false);
 179   }
 180   static bool is_in_trampoline_frame(address addr) NOT_CDS_RETURN_(false);
 181 
 182   static void allocate_cpp_vtable_clones();
 183   static intptr_t* clone_cpp_vtables(intptr_t* p);
 184   static void zero_cpp_vtable_clones_for_writing();
 185   static void patch_cpp_vtable_pointers();
 186   static bool is_valid_shared_method(const Method* m) NOT_CDS_RETURN_(false);
 187   static void serialize(SerializeClosure* sc);

 188 
 189   static MetaspaceSharedStats* stats() {
 190     return &_stats;
 191   }
 192 
 193   static void report_out_of_space(const char* name, size_t needed_bytes);
 194 
 195   // JVM/TI RedefineClasses() support:
 196   // Remap the shared readonly space to shared readwrite, private if
 197   // sharing is enabled. Simply returns true if sharing is not enabled
 198   // or if the remapping has already been done by a prior call.
 199   static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
 200   static bool remapped_readwrite() {
 201     CDS_ONLY(return _remapped_readwrite);
 202     NOT_CDS(return false);
 203   }
 204 
 205   static void print_shared_spaces();
 206 
 207   static bool try_link_class(InstanceKlass* ik, TRAPS);


< prev index next >