1 /* 2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 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 #ifndef SHARE_VM_MEMORY_METASPACE_SHARED_HPP 25 #define SHARE_VM_MEMORY_METASPACE_SHARED_HPP 26 27 #include "memory/allocation.hpp" 28 #include "memory/memRegion.hpp" 29 #include "runtime/virtualspace.hpp" 30 #include "utilities/exceptions.hpp" 31 #include "utilities/macros.hpp" 32 33 #define LargeSharedArchiveSize (300*M) 34 #define HugeSharedArchiveSize (800*M) 35 #define ReadOnlyRegionPercentage 0.39 36 #define ReadWriteRegionPercentage 0.50 37 #define MiscDataRegionPercentage 0.09 38 #define MiscCodeRegionPercentage 0.02 39 #define LargeThresholdClassCount 5000 40 #define HugeThresholdClassCount 40000 41 42 #define SET_ESTIMATED_SIZE(type, region) \ 43 Shared ##region## Size = FLAG_IS_DEFAULT(Shared ##region## Size) ? \ 44 (uintx)(type ## SharedArchiveSize * region ## RegionPercentage) : Shared ## region ## Size 45 46 class FileMapInfo; 47 48 // Class Data Sharing Support 49 class MetaspaceShared : AllStatic { 50 51 // CDS support 52 static ReservedSpace* _shared_rs; 53 static int _max_alignment; 54 static bool _link_classes_made_progress; 55 static bool _check_classes_made_progress; 56 static bool _has_error_classes; 57 static bool _archive_loading_failed; 58 static bool _remapped_readwrite; 59 public: 60 enum { 61 vtbl_list_size = 17, // number of entries in the shared space vtable list. 62 num_virtuals = 200, // maximum number of virtual functions 63 // If virtual functions are added to Metadata, 64 // this number needs to be increased. Also, 65 // SharedMiscCodeSize will need to be increased. 66 // The following 2 sizes were based on 67 // MetaspaceShared::generate_vtable_methods() 68 vtbl_method_size = 16, // conservative size of the mov1 and jmp instructions 69 // for the x64 platform 70 vtbl_common_code_size = (1*K) // conservative size of the "common_code" for the x64 platform 71 }; 72 73 enum { 74 ro = 0, // read-only shared space in the heap 75 rw = 1, // read-write shared space in the heap 76 md = 2, // miscellaneous data for initializing tables, etc. 77 mc = 3, // miscellaneous code - vtable replacement. 78 n_regions = 4 79 }; 80 81 // Accessor functions to save shared space created for metadata, which has 82 // extra space allocated at the end for miscellaneous data and code. set_max_alignment(int alignment)83 static void set_max_alignment(int alignment) { 84 CDS_ONLY(_max_alignment = alignment); 85 } 86 max_alignment()87 static int max_alignment() { 88 CDS_ONLY(return _max_alignment); 89 NOT_CDS(return 0); 90 } 91 92 static void prepare_for_dumping() NOT_CDS_RETURN; 93 static void preload_and_dump(TRAPS) NOT_CDS_RETURN; 94 static int preload_and_dump(const char * class_list_path, 95 GrowableArray<Klass*>* class_promote_order, 96 TRAPS) NOT_CDS_RETURN_(0); 97 shared_rs()98 static ReservedSpace* shared_rs() { 99 CDS_ONLY(return _shared_rs); 100 NOT_CDS(return NULL); 101 } 102 set_shared_rs(ReservedSpace * rs)103 static void set_shared_rs(ReservedSpace* rs) { 104 CDS_ONLY(_shared_rs = rs;) 105 } 106 set_archive_loading_failed()107 static void set_archive_loading_failed() { 108 _archive_loading_failed = true; 109 } 110 static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false); 111 static void initialize_shared_spaces() NOT_CDS_RETURN; 112 113 // Return true if given address is in the mapped shared space. 114 static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false); 115 116 static void generate_vtable_methods(void** vtbl_list, 117 void** vtable, 118 char** md_top, char* md_end, 119 char** mc_top, char* mc_end); 120 static void serialize(SerializeClosure* sc); 121 122 // JVM/TI RedefineClasses() support: 123 // Remap the shared readonly space to shared readwrite, private if 124 // sharing is enabled. Simply returns true if sharing is not enabled 125 // or if the remapping has already been done by a prior call. 126 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true); remapped_readwrite()127 static bool remapped_readwrite() { 128 CDS_ONLY(return _remapped_readwrite); 129 NOT_CDS(return false); 130 } 131 132 static void print_shared_spaces(); 133 134 static bool try_link_class(InstanceKlass* ik, TRAPS); 135 static void link_one_shared_class(Klass* obj, TRAPS); 136 static void check_one_shared_class(Klass* obj); 137 static void link_and_cleanup_shared_classes(TRAPS); 138 139 static int count_class(const char* classlist_file); 140 static void estimate_regions_size() NOT_CDS_RETURN; 141 }; 142 #endif // SHARE_VM_MEMORY_METASPACE_SHARED_HPP 143