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 LargeSharedArchiveSize (300*M) 36 #define HugeSharedArchiveSize (800*M) 37 #define ReadOnlyRegionPercentage 0.4 38 #define ReadWriteRegionPercentage 0.55 39 #define MiscDataRegionPercentage 0.03 40 #define MiscCodeRegionPercentage 0.02 41 #define LargeThresholdClassCount 5000 42 #define HugeThresholdClassCount 40000 43 44 #define SET_ESTIMATED_SIZE(type, region) \ 45 Shared ##region## Size = FLAG_IS_DEFAULT(Shared ##region## Size) ? \ 46 (uintx)(type ## SharedArchiveSize * region ## RegionPercentage) : Shared ## region ## Size 47 48 class FileMapInfo; 49 50 class MetaspaceSharedStats VALUE_OBJ_CLASS_SPEC { 51 public: 52 MetaspaceSharedStats() { 53 memset(this, 0, sizeof(*this)); 54 } 55 CompactHashtableStats symbol; 56 CompactHashtableStats string; 57 }; 58 59 // Class Data Sharing Support 60 class MetaspaceShared : AllStatic { 61 62 // CDS support 63 static ReservedSpace* _shared_rs; 64 static int _max_alignment; 65 static MetaspaceSharedStats _stats; 66 static bool _link_classes_made_progress; 67 static bool _check_classes_made_progress; 68 static bool _has_error_classes; 69 static bool _archive_loading_failed; 70 public: 71 enum { 72 vtbl_list_size = 17, // number of entries in the shared space vtable list. 73 num_virtuals = 200, // maximum number of virtual functions 74 // If virtual functions are added to Metadata, 75 // this number needs to be increased. Also, 76 // SharedMiscCodeSize will need to be increased. 77 // The following 2 sizes were based on 78 // MetaspaceShared::generate_vtable_methods() 79 vtbl_method_size = 16, // conservative size of the mov1 and jmp instructions 80 // for the x64 platform 81 vtbl_common_code_size = (1*K) // conservative size of the "common_code" for the x64 platform 82 }; 83 84 enum { 85 min_ro_size = NOT_LP64(8*M) LP64_ONLY(9*M), // minimum ro and rw regions sizes based on dumping 86 min_rw_size = NOT_LP64(7*M) LP64_ONLY(12*M) // of a shared archive using the default classlist 87 }; 88 89 enum { 90 ro = 0, // read-only shared space in the heap 91 rw = 1, // read-write shared space in the heap 92 md = 2, // miscellaneous data for initializing tables, etc. 93 mc = 3, // miscellaneous code - vtable replacement. 94 max_strings = 2, // max number of string regions in string space 95 num_non_strings = 4, // number of non-string regions 96 first_string = num_non_strings, // index of first string region 97 n_regions = max_strings + num_non_strings // total number of regions 98 }; 99 100 // Accessor functions to save shared space created for metadata, which has 101 // extra space allocated at the end for miscellaneous data and code. 102 static void set_max_alignment(int alignment) { 103 CDS_ONLY(_max_alignment = alignment); 104 } 105 106 static int max_alignment() { | 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 DEFAULT_VTBL_LIST_SIZE (17) // number of entries in the shared space vtable list. 36 #define DEFAULT_VTBL_VIRTUALS_COUNT (200) // maximum number of virtual functions 37 // If virtual functions are added to Metadata, 38 // this number needs to be increased. Also, 39 // SharedMiscCodeSize will need to be increased. 40 // The following 2 sizes were based on 41 // MetaspaceShared::generate_vtable_methods() 42 #define DEFAULT_VTBL_METHOD_SIZE (16) // conservative size of the mov1 and jmp instructions 43 // for the x64 platform 44 #define DEFAULT_VTBL_COMMON_CODE_SIZE (1*K) // conservative size of the "common_code" for the x64 platform 45 46 #define DEFAULT_SHARED_READ_WRITE_SIZE (NOT_LP64(12*M) LP64_ONLY(16*M)) 47 #define MIN_SHARED_READ_WRITE_SIZE (NOT_LP64(7*M) LP64_ONLY(12*M)) 48 49 #define DEFAULT_SHARED_READ_ONLY_SIZE (NOT_LP64(12*M) LP64_ONLY(16*M)) 50 #define MIN_SHARED_READ_ONLY_SIZE (NOT_LP64(8*M) LP64_ONLY(9*M)) 51 52 // the MIN_SHARED_MISC_DATA_SIZE and MIN_SHARED_MISC_CODE_SIZE estimates are based on 53 // MetaspaceShared::generate_vtable_methods(). 54 // The minimum size only accounts for the vtable methods. Any size less than the 55 // minimum required size would cause vm crash when allocating the vtable methods. 56 #define SHARED_MISC_SIZE_FOR(size) (DEFAULT_VTBL_VIRTUALS_COUNT*DEFAULT_VTBL_LIST_SIZE*size) 57 58 #define DEFAULT_SHARED_MISC_DATA_SIZE (NOT_LP64(2*M) LP64_ONLY(4*M)) 59 #define MIN_SHARED_MISC_DATA_SIZE (SHARED_MISC_SIZE_FOR(sizeof(void*))) 60 61 #define DEFAULT_SHARED_MISC_CODE_SIZE (120*K) 62 #define MIN_SHARED_MISC_CODE_SIZE (SHARED_MISC_SIZE_FOR(sizeof(void*))+SHARED_MISC_SIZE_FOR(DEFAULT_VTBL_METHOD_SIZE)+DEFAULT_VTBL_COMMON_CODE_SIZE) 63 64 #define DEFAULT_COMBINED_SIZE (DEFAULT_SHARED_READ_WRITE_SIZE+DEFAULT_SHARED_READ_ONLY_SIZE+DEFAULT_SHARED_MISC_DATA_SIZE+DEFAULT_SHARED_MISC_CODE_SIZE) 65 66 // the max size is the MAX size (ie. 0x7FFFFFFF) - the total size of 67 // the other 3 sections - page size (to avoid overflow in case the final 68 // size will get aligned up on page size) 69 #define SHARED_PAGE ((size_t)os::vm_page_size()) 70 #define MAX_SHARED_DELTA (0x7FFFFFFF) 71 #define MAX_SHARED_READ_WRITE_SIZE (MAX_SHARED_DELTA-(MIN_SHARED_READ_ONLY_SIZE+MIN_SHARED_MISC_DATA_SIZE+MIN_SHARED_MISC_CODE_SIZE)-SHARED_PAGE) 72 #define MAX_SHARED_READ_ONLY_SIZE (MAX_SHARED_DELTA-(MIN_SHARED_READ_WRITE_SIZE+MIN_SHARED_MISC_DATA_SIZE+MIN_SHARED_MISC_CODE_SIZE)-SHARED_PAGE) 73 #define MAX_SHARED_MISC_DATA_SIZE (MAX_SHARED_DELTA-(MIN_SHARED_READ_WRITE_SIZE+MIN_SHARED_READ_ONLY_SIZE+MIN_SHARED_MISC_CODE_SIZE)-SHARED_PAGE) 74 #define MAX_SHARED_MISC_CODE_SIZE (MAX_SHARED_DELTA-(MIN_SHARED_READ_WRITE_SIZE+MIN_SHARED_READ_ONLY_SIZE+MIN_SHARED_MISC_DATA_SIZE)-SHARED_PAGE) 75 76 #define LargeSharedArchiveSize (300*M) 77 #define HugeSharedArchiveSize (800*M) 78 #define ReadOnlyRegionPercentage 0.4 79 #define ReadWriteRegionPercentage 0.55 80 #define MiscDataRegionPercentage 0.03 81 #define MiscCodeRegionPercentage 0.02 82 #define LargeThresholdClassCount 5000 83 #define HugeThresholdClassCount 40000 84 85 #define SET_ESTIMATED_SIZE(type, region) \ 86 Shared ##region## Size = FLAG_IS_DEFAULT(Shared ##region## Size) ? \ 87 (uintx)(type ## SharedArchiveSize * region ## RegionPercentage) : Shared ## region ## Size 88 89 class FileMapInfo; 90 91 class MetaspaceSharedStats VALUE_OBJ_CLASS_SPEC { 92 public: 93 MetaspaceSharedStats() { 94 memset(this, 0, sizeof(*this)); 95 } 96 CompactHashtableStats symbol; 97 CompactHashtableStats string; 98 }; 99 100 // Class Data Sharing Support 101 class MetaspaceShared : AllStatic { 102 103 // CDS support 104 static ReservedSpace* _shared_rs; 105 static int _max_alignment; 106 static MetaspaceSharedStats _stats; 107 static bool _link_classes_made_progress; 108 static bool _check_classes_made_progress; 109 static bool _has_error_classes; 110 static bool _archive_loading_failed; 111 public: 112 enum { 113 vtbl_list_size = DEFAULT_VTBL_LIST_SIZE, 114 num_virtuals = DEFAULT_VTBL_VIRTUALS_COUNT, 115 vtbl_method_size = DEFAULT_VTBL_METHOD_SIZE, 116 vtbl_common_code_size = DEFAULT_VTBL_COMMON_CODE_SIZE 117 }; 118 119 enum { 120 ro = 0, // read-only shared space in the heap 121 rw = 1, // read-write shared space in the heap 122 md = 2, // miscellaneous data for initializing tables, etc. 123 mc = 3, // miscellaneous code - vtable replacement. 124 max_strings = 2, // max number of string regions in string space 125 num_non_strings = 4, // number of non-string regions 126 first_string = num_non_strings, // index of first string region 127 n_regions = max_strings + num_non_strings // total number of regions 128 }; 129 130 // Accessor functions to save shared space created for metadata, which has 131 // extra space allocated at the end for miscellaneous data and code. 132 static void set_max_alignment(int alignment) { 133 CDS_ONLY(_max_alignment = alignment); 134 } 135 136 static int max_alignment() { |