< prev index next >

src/hotspot/share/cds/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_CDS_METASPACESHARED_HPP
 26 #define SHARE_CDS_METASPACESHARED_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "memory/virtualspace.hpp"
 31 #include "oops/oop.hpp"
 32 #include "utilities/macros.hpp"
 33 


 34 class FileMapInfo;

 35 class outputStream;
 36 class SerializeClosure;
 37 

 38 template<class E> class GrowableArray;
 39 
 40 enum MapArchiveResult {
 41   MAP_ARCHIVE_SUCCESS,
 42   MAP_ARCHIVE_MMAP_FAILURE,
 43   MAP_ARCHIVE_OTHER_FAILURE
 44 };
 45 


 46 // Class Data Sharing Support
 47 class MetaspaceShared : AllStatic {
 48   static ReservedSpace _symbol_rs;  // used only during -Xshare:dump
 49   static VirtualSpace _symbol_vs;   // used only during -Xshare:dump
 50   static bool _archive_loading_failed;
 51   static bool _remapped_readwrite;
 52   static void* _shared_metaspace_static_top;
 53   static intx _relocation_delta;
 54   static char* _requested_base_address;
 55   static bool _use_optimized_module_handling;

 56  public:
 57   enum {
 58     // core archive spaces
 59     rw = 0,  // read-write shared space
 60     ro = 1,  // read-only shared space
 61     bm = 2,  // relocation bitmaps (freed after file mapping is finished)
 62     hp = 3,  // heap region

 63     num_core_region = 2,       // rw and ro
 64     n_regions = 4              // total number of regions
 65   };
 66 
 67   static void prepare_for_dumping() NOT_CDS_RETURN;
 68   static void preload_and_dump() NOT_CDS_RETURN;
 69 #ifdef _LP64
 70   static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
 71 #endif
 72 
 73 private:
 74   static void preload_and_dump_impl(TRAPS) NOT_CDS_RETURN;
 75   static void preload_classes(TRAPS) NOT_CDS_RETURN;
 76 
 77 public:
 78   static Symbol* symbol_rs_base() {
 79     return (Symbol*)_symbol_rs.base();
 80   }
 81 
 82   static void initialize_for_static_dump() NOT_CDS_RETURN;

 83   static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
 84   static void post_initialize(TRAPS) NOT_CDS_RETURN;
 85 
 86   static void print_on(outputStream* st);
 87 
 88   static void set_archive_loading_failed() {
 89     _archive_loading_failed = true;
 90   }
 91 
 92   static void initialize_shared_spaces() NOT_CDS_RETURN;
 93 
 94   // Return true if given address is in the shared metaspace regions (i.e., excluding the
 95   // mapped heap region.)
 96   static bool is_in_shared_metaspace(const void* p) {
 97     return MetaspaceObj::is_shared((const MetaspaceObj*)p);
 98   }
 99 
100   static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
101 
102   static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
103   static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
104 
105   static void unrecoverable_loading_error(const char* message = nullptr);
106   static void unrecoverable_writing_error(const char* message = nullptr);
107 



108   static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
109 
110   // JVM/TI RedefineClasses() support:
111   // Remap the shared readonly space to shared readwrite, private if
112   // sharing is enabled. Simply returns true if sharing is not enabled
113   // or if the remapping has already been done by a prior call.
114   static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
115   static bool remapped_readwrite() {
116     CDS_ONLY(return _remapped_readwrite);
117     NOT_CDS(return false);
118   }
119 
120   static bool try_link_class(JavaThread* current, InstanceKlass* ik);
121   static void link_shared_classes(bool jcmd_request, TRAPS) NOT_CDS_RETURN;
122   static bool link_class_for_cds(InstanceKlass* ik, TRAPS) NOT_CDS_RETURN_(false);
123   static bool may_be_eagerly_linked(InstanceKlass* ik) NOT_CDS_RETURN_(false);
124 
125 #if INCLUDE_CDS
126   // Alignment for the 2 core CDS regions (RW/RO) only.
127   // (Heap region alignments are decided by GC).
128   static size_t core_region_alignment();
129   static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
130   // print loaded classes names to file.
131   static void dump_loaded_classes(const char* file_name, TRAPS);
132 #endif
133 
134   // Allocate a block of memory from the temporary "symbol" region.
135   static char* symbol_space_alloc(size_t num_bytes);
136 
137   // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
138   // Both the base/top archives are written using this as their base address.
139   //
140   // During static dump: _requested_base_address == SharedBaseAddress.
141   //
142   // During dynamic dump: _requested_base_address is not always the same as SharedBaseAddress:

148   //   0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
149   static char* requested_base_address() {
150     return _requested_base_address;
151   }
152 
153   // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
154   static intx relocation_delta() { return _relocation_delta; }
155 
156   static bool use_windows_memory_mapping() {
157     const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
158     //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
159     return is_windows;
160   }
161 
162   // Can we skip some expensive operations related to modules?
163   static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
164   static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
165 
166 private:
167   static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
168   static FileMapInfo* open_static_archive();

169   static FileMapInfo* open_dynamic_archive();
170   // use_requested_addr: If true (default), attempt to map at the address the
171   static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
172                                        bool use_requested_addr);
173   static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
174                                                   FileMapInfo* dynamic_mapinfo,
175                                                   bool use_archive_base_addr,
176                                                   ReservedSpace& total_space_rs,
177                                                   ReservedSpace& archive_space_rs,
178                                                   ReservedSpace& class_space_rs);
179  static void release_reserved_spaces(ReservedSpace& total_space_rs,
180                                      ReservedSpace& archive_space_rs,
181                                      ReservedSpace& class_space_rs);
182   static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
183   static void unmap_archive(FileMapInfo* mapinfo);
184   static void get_default_classlist(char* default_classlist, const size_t buf_size);
185 };
186 #endif // SHARE_CDS_METASPACESHARED_HPP

 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_CDS_METASPACESHARED_HPP
 26 #define SHARE_CDS_METASPACESHARED_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "memory/virtualspace.hpp"
 31 #include "oops/oop.hpp"
 32 #include "utilities/macros.hpp"
 33 
 34 class ArchiveBuilder;
 35 class ArchiveHeapInfo;
 36 class FileMapInfo;
 37 class Method;
 38 class outputStream;
 39 class SerializeClosure;
 40 
 41 template<class E> class Array;
 42 template<class E> class GrowableArray;
 43 
 44 enum MapArchiveResult {
 45   MAP_ARCHIVE_SUCCESS,
 46   MAP_ARCHIVE_MMAP_FAILURE,
 47   MAP_ARCHIVE_OTHER_FAILURE
 48 };
 49 
 50 class StaticArchiveBuilder;
 51 
 52 // Class Data Sharing Support
 53 class MetaspaceShared : AllStatic {
 54   static ReservedSpace _symbol_rs;  // used only during -Xshare:dump
 55   static VirtualSpace _symbol_vs;   // used only during -Xshare:dump
 56   static bool _archive_loading_failed;
 57   static bool _remapped_readwrite;
 58   static void* _shared_metaspace_static_top;
 59   static intx _relocation_delta;
 60   static char* _requested_base_address;
 61   static bool _use_optimized_module_handling;
 62   static Array<Method*>* _archived_method_handle_intrinsics;
 63  public:
 64   enum {
 65     // core archive spaces
 66     rw = 0,  // read-write shared space
 67     ro = 1,  // read-only shared space
 68     bm = 2,  // relocation bitmaps (freed after file mapping is finished)
 69     hp = 3,  // heap region
 70     cc = 4,  // cached code
 71     num_core_region = 2,       // rw and ro
 72     n_regions = 5              // total number of regions
 73   };
 74 
 75   static void prepare_for_dumping() NOT_CDS_RETURN;
 76   static void preload_and_dump() NOT_CDS_RETURN;
 77 #ifdef _LP64
 78   static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
 79 #endif
 80 
 81 private:
 82   static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
 83   static void preload_classes(TRAPS) NOT_CDS_RETURN;
 84 
 85 public:
 86   static Symbol* symbol_rs_base() {
 87     return (Symbol*)_symbol_rs.base();
 88   }
 89 
 90   static void initialize_for_static_dump() NOT_CDS_RETURN;
 91   static void open_static_archive() NOT_CDS_RETURN;
 92   static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
 93   static void post_initialize(TRAPS) NOT_CDS_RETURN;
 94 
 95   static void print_on(outputStream* st);
 96 
 97   static void set_archive_loading_failed() {
 98     _archive_loading_failed = true;
 99   }
100 
101   static void initialize_shared_spaces() NOT_CDS_RETURN;
102 
103   // Return true if given address is in the shared metaspace regions (i.e., excluding the
104   // mapped heap region.)
105   static bool is_in_shared_metaspace(const void* p) {
106     return MetaspaceObj::is_shared((const MetaspaceObj*)p);
107   }
108 
109   static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
110 
111   static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
112   static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
113 
114   static void unrecoverable_loading_error(const char* message = nullptr);
115   static void unrecoverable_writing_error(const char* message = nullptr);
116 
117   static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
118   static void write_method_handle_intrinsics() NOT_CDS_RETURN;
119   static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
120   static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
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);
127   static bool remapped_readwrite() {
128     CDS_ONLY(return _remapped_readwrite);
129     NOT_CDS(return false);
130   }
131 
132   static bool try_link_class(JavaThread* current, InstanceKlass* ik);
133   static void link_shared_classes(bool jcmd_request, TRAPS) NOT_CDS_RETURN;

134   static bool may_be_eagerly_linked(InstanceKlass* ik) NOT_CDS_RETURN_(false);
135 
136 #if INCLUDE_CDS
137   // Alignment for the 2 core CDS regions (RW/RO) only.
138   // (Heap region alignments are decided by GC).
139   static size_t core_region_alignment();
140   static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik);
141   // print loaded classes names to file.
142   static void dump_loaded_classes(const char* file_name, TRAPS);
143 #endif
144 
145   // Allocate a block of memory from the temporary "symbol" region.
146   static char* symbol_space_alloc(size_t num_bytes);
147 
148   // This is the base address as specified by -XX:SharedBaseAddress during -Xshare:dump.
149   // Both the base/top archives are written using this as their base address.
150   //
151   // During static dump: _requested_base_address == SharedBaseAddress.
152   //
153   // During dynamic dump: _requested_base_address is not always the same as SharedBaseAddress:

159   //   0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
160   static char* requested_base_address() {
161     return _requested_base_address;
162   }
163 
164   // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
165   static intx relocation_delta() { return _relocation_delta; }
166 
167   static bool use_windows_memory_mapping() {
168     const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
169     //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
170     return is_windows;
171   }
172 
173   // Can we skip some expensive operations related to modules?
174   static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
175   static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
176 
177 private:
178   static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
179   static void write_static_archive(ArchiveBuilder* builder, FileMapInfo *mapinfo, ArchiveHeapInfo* heap_info);
180   static void fork_and_dump_final_static_archive();
181   static FileMapInfo* open_dynamic_archive();
182   // use_requested_addr: If true (default), attempt to map at the address the
183   static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
184                                        bool use_requested_addr);
185   static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
186                                                   FileMapInfo* dynamic_mapinfo,
187                                                   bool use_archive_base_addr,
188                                                   ReservedSpace& total_space_rs,
189                                                   ReservedSpace& archive_space_rs,
190                                                   ReservedSpace& class_space_rs);
191  static void release_reserved_spaces(ReservedSpace& total_space_rs,
192                                      ReservedSpace& archive_space_rs,
193                                      ReservedSpace& class_space_rs);
194   static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
195   static void unmap_archive(FileMapInfo* mapinfo);
196   static void get_default_classlist(char* default_classlist, const size_t buf_size);
197 };
198 #endif // SHARE_CDS_METASPACESHARED_HPP
< prev index next >