< prev index next >

src/hotspot/share/cds/metaspaceShared.hpp

Print this page

 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 class StaticArchiveBuilder;
 41 
 42 template<class E> class Array;
 43 template<class E> class GrowableArray;
 44 
 45 enum MapArchiveResult {
 46   MAP_ARCHIVE_SUCCESS,
 47   MAP_ARCHIVE_MMAP_FAILURE,
 48   MAP_ARCHIVE_OTHER_FAILURE
 49 };
 50 


 51 // Class Data Sharing Support
 52 class MetaspaceShared : AllStatic {
 53   static ReservedSpace _symbol_rs;  // used only during -Xshare:dump
 54   static VirtualSpace _symbol_vs;   // used only during -Xshare:dump
 55   static bool _archive_loading_failed;
 56   static bool _remapped_readwrite;
 57   static void* _shared_metaspace_static_top;
 58   static intx _relocation_delta;
 59   static char* _requested_base_address;
 60   static bool _use_optimized_module_handling;
 61   static Array<Method*>* _archived_method_handle_intrinsics;

 62 
 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     num_core_region = 2,       // rw and ro
 71     n_regions = 4              // total number of regions
 72   };
 73 
 74   static void prepare_for_dumping() NOT_CDS_RETURN;
 75   static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
 76 #ifdef _LP64
 77   static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
 78 #endif
 79 
 80 private:
 81   static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN;
 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 initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
 92   static void post_initialize(TRAPS) NOT_CDS_RETURN;
 93 
 94   static void print_on(outputStream* st);
 95 
 96   static void set_archive_loading_failed() {
 97     _archive_loading_failed = true;
 98   }
 99 
100   static void initialize_shared_spaces() NOT_CDS_RETURN;
101 
102   // Return true if given address is in the shared metaspace regions (i.e., excluding the
103   // mapped heap region.)
104   static bool is_in_shared_metaspace(const void* p) {
105     return MetaspaceObj::is_shared((const MetaspaceObj*)p);
106   }
107 
108   static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
109 
110   static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
111   static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
112 


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

161   //   0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
162   static char* requested_base_address() {
163     return _requested_base_address;
164   }
165 
166   // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
167   static intx relocation_delta() { return _relocation_delta; }
168 
169   static bool use_windows_memory_mapping() {
170     const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
171     //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
172     return is_windows;
173   }
174 
175   // Can we skip some expensive operations related to modules?
176   static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
177   static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
178 
179 private:
180   static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;

181   static bool write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info);
182   static FileMapInfo* open_static_archive();
183   static FileMapInfo* open_dynamic_archive();
184   // use_requested_addr: If true (default), attempt to map at the address the
185   static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
186                                        bool use_requested_addr);
187   static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
188                                                   FileMapInfo* dynamic_mapinfo,
189                                                   bool use_archive_base_addr,
190                                                   ReservedSpace& total_space_rs,
191                                                   ReservedSpace& archive_space_rs,
192                                                   ReservedSpace& class_space_rs);
193  static void release_reserved_spaces(ReservedSpace& total_space_rs,
194                                      ReservedSpace& archive_space_rs,
195                                      ReservedSpace& class_space_rs);
196   static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
197   static void unmap_archive(FileMapInfo* mapinfo);
198   static void get_default_classlist(char* default_classlist, const size_t buf_size);
199 };
200 #endif // SHARE_CDS_METASPACESHARED_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 class StaticArchiveBuilder;
 41 
 42 template<class E> class Array;
 43 template<class E> class GrowableArray;
 44 
 45 enum MapArchiveResult {
 46   MAP_ARCHIVE_SUCCESS,
 47   MAP_ARCHIVE_MMAP_FAILURE,
 48   MAP_ARCHIVE_OTHER_FAILURE
 49 };
 50 
 51 class StaticArchiveBuilder;
 52 
 53 // Class Data Sharing Support
 54 class MetaspaceShared : AllStatic {
 55   static ReservedSpace _symbol_rs;  // used only during -Xshare:dump
 56   static VirtualSpace _symbol_vs;   // used only during -Xshare:dump
 57   static bool _archive_loading_failed;
 58   static bool _remapped_readwrite;
 59   static void* _shared_metaspace_static_top;
 60   static intx _relocation_delta;
 61   static char* _requested_base_address;
 62   static bool _use_optimized_module_handling;
 63   static Array<Method*>* _archived_method_handle_intrinsics;
 64   static int volatile _preimage_static_archive_dumped;
 65 
 66  public:
 67   enum {
 68     // core archive spaces
 69     rw = 0,  // read-write shared space
 70     ro = 1,  // read-only shared space
 71     bm = 2,  // relocation bitmaps (freed after file mapping is finished)
 72     hp = 3,  // heap region
 73     cc = 4,  // cached code
 74     num_core_region = 2,       // rw and ro
 75     n_regions = 5              // 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 #ifdef _LP64
 81   static void adjust_heap_sizes_for_dumping() NOT_CDS_JAVA_HEAP_RETURN;
 82 #endif
 83 
 84 private:
 85   static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN;
 86   static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN;
 87   static void preload_classes(TRAPS) NOT_CDS_RETURN;
 88 
 89 public:
 90   static Symbol* symbol_rs_base() {
 91     return (Symbol*)_symbol_rs.base();
 92   }
 93 
 94   static void initialize_for_static_dump() NOT_CDS_RETURN;
 95   static void open_static_archive() NOT_CDS_RETURN;
 96   static void initialize_runtime_shared_and_meta_spaces() NOT_CDS_RETURN;
 97   static void post_initialize(TRAPS) NOT_CDS_RETURN;
 98 
 99   static void print_on(outputStream* st);
100 
101   static void set_archive_loading_failed() {
102     _archive_loading_failed = true;
103   }
104 
105   static void initialize_shared_spaces() NOT_CDS_RETURN;
106 
107   // Return true if given address is in the shared metaspace regions (i.e., excluding the
108   // mapped heap region.)
109   static bool is_in_shared_metaspace(const void* p) {
110     return MetaspaceObj::is_shared((const MetaspaceObj*)p);
111   }
112 
113   static void set_shared_metaspace_range(void* base, void *static_top, void* top) NOT_CDS_RETURN;
114 
115   static bool is_shared_dynamic(void* p) NOT_CDS_RETURN_(false);
116   static bool is_shared_static(void* p) NOT_CDS_RETURN_(false);
117 
118   static bool is_recording_preimage_static_archive() NOT_CDS_RETURN_(false);
119 
120   static void unrecoverable_loading_error(const char* message = nullptr);
121   static void unrecoverable_writing_error(const char* message = nullptr);
122   static void writing_error(const char* message = nullptr);
123 
124   static void make_method_handle_intrinsics_shareable() NOT_CDS_RETURN;
125   static void write_method_handle_intrinsics() NOT_CDS_RETURN;
126   static Array<Method*>* archived_method_handle_intrinsics() { return _archived_method_handle_intrinsics; }
127   static void early_serialize(SerializeClosure* sc) NOT_CDS_RETURN;
128   static void serialize(SerializeClosure* sc) NOT_CDS_RETURN;
129 
130   // JVM/TI RedefineClasses() support:
131   // Remap the shared readonly space to shared readwrite, private if
132   // sharing is enabled. Simply returns true if sharing is not enabled
133   // or if the remapping has already been done by a prior call.
134   static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
135   static bool remapped_readwrite() {
136     CDS_ONLY(return _remapped_readwrite);
137     NOT_CDS(return false);
138   }
139 
140   static bool try_link_class(JavaThread* current, InstanceKlass* ik);
141   static void link_shared_classes(bool jcmd_request, TRAPS) NOT_CDS_RETURN;

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

167   //   0x800000000 (unless it was set by -XX:SharedBaseAddress during -Xshare:dump).
168   static char* requested_base_address() {
169     return _requested_base_address;
170   }
171 
172   // Non-zero if the archive(s) need to be mapped a non-default location due to ASLR.
173   static intx relocation_delta() { return _relocation_delta; }
174 
175   static bool use_windows_memory_mapping() {
176     const bool is_windows = (NOT_WINDOWS(false) WINDOWS_ONLY(true));
177     //const bool is_windows = true; // enable this to allow testing the windows mmap semantics on Linux, etc.
178     return is_windows;
179   }
180 
181   // Can we skip some expensive operations related to modules?
182   static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
183   static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
184 
185 private:
186   static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
187   static void fork_and_dump_final_static_archive();
188   static bool write_static_archive(ArchiveBuilder* builder, FileMapInfo* map_info, ArchiveHeapInfo* heap_info);

189   static FileMapInfo* open_dynamic_archive();
190   // use_requested_addr: If true (default), attempt to map at the address the
191   static MapArchiveResult map_archives(FileMapInfo* static_mapinfo, FileMapInfo* dynamic_mapinfo,
192                                        bool use_requested_addr);
193   static char* reserve_address_space_for_archives(FileMapInfo* static_mapinfo,
194                                                   FileMapInfo* dynamic_mapinfo,
195                                                   bool use_archive_base_addr,
196                                                   ReservedSpace& total_space_rs,
197                                                   ReservedSpace& archive_space_rs,
198                                                   ReservedSpace& class_space_rs);
199  static void release_reserved_spaces(ReservedSpace& total_space_rs,
200                                      ReservedSpace& archive_space_rs,
201                                      ReservedSpace& class_space_rs);
202   static MapArchiveResult map_archive(FileMapInfo* mapinfo, char* mapped_base_address, ReservedSpace rs);
203   static void unmap_archive(FileMapInfo* mapinfo);
204   static void get_default_classlist(char* default_classlist, const size_t buf_size);
205 };
206 #endif // SHARE_CDS_METASPACESHARED_HPP
< prev index next >