46 #include "memory/metaspace.hpp" |
46 #include "memory/metaspace.hpp" |
47 #include "memory/metaspaceClosure.hpp" |
47 #include "memory/metaspaceClosure.hpp" |
48 #include "memory/metaspaceShared.hpp" |
48 #include "memory/metaspaceShared.hpp" |
49 #include "memory/resourceArea.hpp" |
49 #include "memory/resourceArea.hpp" |
50 #include "memory/universe.hpp" |
50 #include "memory/universe.hpp" |
|
51 #include "memory/dynamicArchive.hpp" |
51 #include "oops/compressedOops.inline.hpp" |
52 #include "oops/compressedOops.inline.hpp" |
52 #include "oops/instanceClassLoaderKlass.hpp" |
53 #include "oops/instanceClassLoaderKlass.hpp" |
53 #include "oops/instanceMirrorKlass.hpp" |
54 #include "oops/instanceMirrorKlass.hpp" |
54 #include "oops/instanceRefKlass.hpp" |
55 #include "oops/instanceRefKlass.hpp" |
|
56 #include "oops/methodData.hpp" |
55 #include "oops/objArrayKlass.hpp" |
57 #include "oops/objArrayKlass.hpp" |
56 #include "oops/objArrayOop.hpp" |
58 #include "oops/objArrayOop.hpp" |
57 #include "oops/oop.inline.hpp" |
59 #include "oops/oop.inline.hpp" |
58 #include "oops/typeArrayKlass.hpp" |
60 #include "oops/typeArrayKlass.hpp" |
59 #include "prims/jvmtiRedefineClasses.hpp" |
61 #include "prims/jvmtiRedefineClasses.hpp" |
110 // [6] Original class files are copied into the od region. |
113 // [6] Original class files are copied into the od region. |
111 // |
114 // |
112 // The s0/s1 and oa0/oa1 regions are populated inside HeapShared::archive_java_heap_objects. |
115 // The s0/s1 and oa0/oa1 regions are populated inside HeapShared::archive_java_heap_objects. |
113 // Their layout is independent of the other 5 regions. |
116 // Their layout is independent of the other 5 regions. |
114 |
117 |
115 class DumpRegion { |
118 char* DumpRegion::expand_top_to(char* newtop) { |
116 private: |
119 assert(is_allocatable(), "must be initialized and not packed"); |
117 const char* _name; |
120 assert(newtop >= _top, "must not grow backwards"); |
118 char* _base; |
121 if (newtop > _end) { |
119 char* _top; |
122 MetaspaceShared::report_out_of_space(_name, newtop - _top); |
120 char* _end; |
123 ShouldNotReachHere(); |
121 bool _is_packed; |
124 } |
122 |
125 uintx delta; |
123 char* expand_top_to(char* newtop) { |
126 if (DynamicDumpSharedSpaces) { |
124 assert(is_allocatable(), "must be initialized and not packed"); |
127 delta = DynamicArchive::object_delta_uintx(newtop); |
125 assert(newtop >= _top, "must not grow backwards"); |
128 } else { |
126 if (newtop > _end) { |
129 delta = MetaspaceShared::object_delta_uintx(newtop); |
127 MetaspaceShared::report_out_of_space(_name, newtop - _top); |
130 } |
128 ShouldNotReachHere(); |
131 if (delta > MAX_SHARED_DELTA) { |
129 } |
132 // This is just a sanity check and should not appear in any real world usage. This |
130 uintx delta = MetaspaceShared::object_delta_uintx(newtop); |
133 // happens only if you allocate more than 2GB of shared objects and would require |
131 if (delta > MAX_SHARED_DELTA) { |
134 // millions of shared classes. |
132 // This is just a sanity check and should not appear in any real world usage. This |
135 vm_exit_during_initialization("Out of memory in the CDS archive", |
133 // happens only if you allocate more than 2GB of shared objects and would require |
136 "Please reduce the number of shared classes."); |
134 // millions of shared classes. |
137 } |
135 vm_exit_during_initialization("Out of memory in the CDS archive", |
138 |
136 "Please reduce the number of shared classes."); |
139 MetaspaceShared::commit_shared_space_to(newtop); |
137 } |
140 _top = newtop; |
138 |
141 return _top; |
139 MetaspaceShared::commit_shared_space_to(newtop); |
142 } |
140 _top = newtop; |
143 |
141 return _top; |
144 char* DumpRegion::allocate(size_t num_bytes, size_t alignment) { |
142 } |
145 char* p = (char*)align_up(_top, alignment); |
143 |
146 char* newtop = p + align_up(num_bytes, alignment); |
144 public: |
147 expand_top_to(newtop); |
145 DumpRegion(const char* name) : _name(name), _base(NULL), _top(NULL), _end(NULL), _is_packed(false) {} |
148 memset(p, 0, newtop - p); |
146 |
149 return p; |
147 char* allocate(size_t num_bytes, size_t alignment=BytesPerWord) { |
150 } |
148 char* p = (char*)align_up(_top, alignment); |
151 |
149 char* newtop = p + align_up(num_bytes, alignment); |
152 void DumpRegion::print(size_t total_bytes) const { |
150 expand_top_to(newtop); |
153 tty->print_cr("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT, |
151 memset(p, 0, newtop - p); |
154 _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()), p2i(_base)); |
152 return p; |
155 } |
153 } |
156 |
154 |
157 void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) { |
155 void append_intptr_t(intptr_t n) { |
158 tty->print("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d", |
156 assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment"); |
159 _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base)); |
157 intptr_t *p = (intptr_t*)_top; |
160 if (strcmp(_name, failing_region) == 0) { |
158 char* newtop = _top + sizeof(intptr_t); |
161 tty->print_cr(" required = %d", int(needed_bytes)); |
159 expand_top_to(newtop); |
162 } else { |
160 *p = n; |
163 tty->cr(); |
161 } |
164 } |
162 |
165 } |
163 char* base() const { return _base; } |
166 |
164 char* top() const { return _top; } |
167 void DumpRegion::pack(DumpRegion* next) { |
165 char* end() const { return _end; } |
168 assert(!is_packed(), "sanity"); |
166 size_t reserved() const { return _end - _base; } |
169 _end = (char*)align_up(_top, Metaspace::reserve_alignment()); |
167 size_t used() const { return _top - _base; } |
170 _is_packed = true; |
168 bool is_packed() const { return _is_packed; } |
171 if (next != NULL) { |
169 bool is_allocatable() const { |
172 next->_base = next->_top = this->_end; |
170 return !is_packed() && _base != NULL; |
173 next->_end = MetaspaceShared::shared_rs()->end(); |
171 } |
174 } |
172 |
175 } |
173 void print(size_t total_bytes) const { |
176 |
174 tty->print_cr("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT, |
177 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"), _od_region("od"); |
175 _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()), p2i(_base)); |
|
176 } |
|
177 void print_out_of_space_msg(const char* failing_region, size_t needed_bytes) { |
|
178 tty->print("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d", |
|
179 _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base)); |
|
180 if (strcmp(_name, failing_region) == 0) { |
|
181 tty->print_cr(" required = %d", int(needed_bytes)); |
|
182 } else { |
|
183 tty->cr(); |
|
184 } |
|
185 } |
|
186 |
|
187 void init(const ReservedSpace* rs) { |
|
188 _base = _top = rs->base(); |
|
189 _end = rs->end(); |
|
190 } |
|
191 void init(char* b, char* t, char* e) { |
|
192 _base = b; |
|
193 _top = t; |
|
194 _end = e; |
|
195 } |
|
196 |
|
197 void pack(DumpRegion* next = NULL) { |
|
198 assert(!is_packed(), "sanity"); |
|
199 _end = (char*)align_up(_top, Metaspace::reserve_alignment()); |
|
200 _is_packed = true; |
|
201 if (next != NULL) { |
|
202 next->_base = next->_top = this->_end; |
|
203 next->_end = MetaspaceShared::shared_rs()->end(); |
|
204 } |
|
205 } |
|
206 bool contains(char* p) { |
|
207 return base() <= p && p < top(); |
|
208 } |
|
209 }; |
|
210 |
|
211 |
|
212 DumpRegion _mc_region("mc"), _ro_region("ro"), _rw_region("rw"), _md_region("md"); |
|
213 size_t _total_closed_archive_region_size = 0, _total_open_archive_region_size = 0; |
178 size_t _total_closed_archive_region_size = 0, _total_open_archive_region_size = 0; |
|
179 |
|
180 void MetaspaceShared::init_shared_dump_space(DumpRegion* first_space, address first_space_bottom) { |
|
181 // Start with 0 committed bytes. The memory will be committed as needed by |
|
182 // MetaspaceShared::commit_shared_space_to(). |
|
183 if (!_shared_vs.initialize(_shared_rs, 0)) { |
|
184 vm_exit_during_initialization("Unable to allocate memory for shared space"); |
|
185 } |
|
186 first_space->init(&_shared_rs, (char*)first_space_bottom); |
|
187 } |
|
188 |
|
189 DumpRegion* MetaspaceShared::misc_code_dump_space() { |
|
190 return &_mc_region; |
|
191 } |
|
192 |
|
193 DumpRegion* MetaspaceShared::read_write_dump_space() { |
|
194 return &_rw_region; |
|
195 } |
|
196 |
|
197 DumpRegion* MetaspaceShared::read_only_dump_space() { |
|
198 return &_ro_region; |
|
199 } |
|
200 |
|
201 DumpRegion* MetaspaceShared::optional_data_dump_space() { |
|
202 return &_od_region; |
|
203 } |
|
204 |
|
205 void MetaspaceShared::pack_dump_space(DumpRegion* current, DumpRegion* next, |
|
206 ReservedSpace* rs) { |
|
207 current->pack(next); |
|
208 } |
214 |
209 |
215 char* MetaspaceShared::misc_code_space_alloc(size_t num_bytes) { |
210 char* MetaspaceShared::misc_code_space_alloc(size_t num_bytes) { |
216 return _mc_region.allocate(num_bytes); |
211 return _mc_region.allocate(num_bytes); |
217 } |
212 } |
218 |
213 |
224 assert(UseSharedSpaces, "Must be called when UseSharedSpaces is enabled"); |
219 assert(UseSharedSpaces, "Must be called when UseSharedSpaces is enabled"); |
225 |
220 |
226 // If using shared space, open the file that contains the shared space |
221 // If using shared space, open the file that contains the shared space |
227 // and map in the memory before initializing the rest of metaspace (so |
222 // and map in the memory before initializing the rest of metaspace (so |
228 // the addresses don't conflict) |
223 // the addresses don't conflict) |
229 address cds_address = NULL; |
224 FileMapInfo* mapinfo = new FileMapInfo(true); |
230 FileMapInfo* mapinfo = new FileMapInfo(); |
|
231 |
225 |
232 // Open the shared archive file, read and validate the header. If |
226 // Open the shared archive file, read and validate the header. If |
233 // initialization fails, shared spaces [UseSharedSpaces] are |
227 // initialization fails, shared spaces [UseSharedSpaces] are |
234 // disabled and the file is closed. |
228 // disabled and the file is closed. |
235 // Map in spaces now also |
229 // Map in spaces now also |
236 if (mapinfo->initialize() && map_shared_spaces(mapinfo)) { |
230 if (mapinfo->initialize(true) && map_shared_spaces(mapinfo)) { |
237 size_t cds_total = core_spaces_size(); |
231 size_t cds_total = core_spaces_size(); |
238 cds_address = (address)mapinfo->region_addr(0); |
232 address cds_address = (address)mapinfo->region_addr(0); |
|
233 char* cds_end = (char *)align_up(cds_address + cds_total, |
|
234 Metaspace::reserve_alignment()); |
|
235 |
|
236 // Mapping the dynamic archive before allocating the class space |
|
237 cds_end = initialize_dynamic_runtime_shared_spaces((char*)cds_address, cds_end); |
|
238 |
239 #ifdef _LP64 |
239 #ifdef _LP64 |
240 if (Metaspace::using_class_space()) { |
240 if (Metaspace::using_class_space()) { |
241 char* cds_end = (char*)(cds_address + cds_total); |
|
242 cds_end = (char *)align_up(cds_end, Metaspace::reserve_alignment()); |
|
243 // If UseCompressedClassPointers is set then allocate the metaspace area |
241 // If UseCompressedClassPointers is set then allocate the metaspace area |
244 // above the heap and above the CDS area (if it exists). |
242 // above the heap and above the CDS area (if it exists). |
245 Metaspace::allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); |
243 Metaspace::allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address); |
246 // map_heap_regions() compares the current narrow oop and klass encodings |
244 // map_heap_regions() compares the current narrow oop and klass encodings |
247 // with the archived ones, so it must be done after all encodings are determined. |
245 // with the archived ones, so it must be done after all encodings are determined. |
251 #endif // _LP64 |
249 #endif // _LP64 |
252 } else { |
250 } else { |
253 assert(!mapinfo->is_open() && !UseSharedSpaces, |
251 assert(!mapinfo->is_open() && !UseSharedSpaces, |
254 "archive file not closed or shared spaces not disabled."); |
252 "archive file not closed or shared spaces not disabled."); |
255 } |
253 } |
|
254 } |
|
255 |
|
256 char* MetaspaceShared::initialize_dynamic_runtime_shared_spaces( |
|
257 char* static_start, char* static_end) { |
|
258 assert(UseSharedSpaces, "must be runtime"); |
|
259 char* cds_end = static_end; |
|
260 if (!DynamicDumpSharedSpaces) { |
|
261 address dynamic_top = DynamicArchive::map(); |
|
262 if (dynamic_top != NULL) { |
|
263 assert(dynamic_top > (address)static_start, "Unexpected layout"); |
|
264 MetaspaceObj::expand_shared_metaspace_range(dynamic_top); |
|
265 cds_end = (char *)align_up(dynamic_top, Metaspace::reserve_alignment()); |
|
266 } |
|
267 } |
|
268 return cds_end; |
|
269 } |
|
270 |
|
271 ReservedSpace* MetaspaceShared::reserve_shared_rs(size_t size, size_t alignment, |
|
272 bool large, char* requested_address) { |
|
273 if (requested_address != NULL) { |
|
274 _shared_rs = ReservedSpace(size, alignment, large, requested_address); |
|
275 } else { |
|
276 _shared_rs = ReservedSpace(size, alignment, large); |
|
277 } |
|
278 return &_shared_rs; |
256 } |
279 } |
257 |
280 |
258 void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() { |
281 void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() { |
259 assert(DumpSharedSpaces, "should be called for dump time only"); |
282 assert(DumpSharedSpaces, "should be called for dump time only"); |
260 const size_t reserve_alignment = Metaspace::reserve_alignment(); |
283 const size_t reserve_alignment = Metaspace::reserve_alignment(); |
278 // We don't support archives larger than 256MB on 32-bit due to limited virtual address space. |
301 // We don't support archives larger than 256MB on 32-bit due to limited virtual address space. |
279 size_t cds_total = align_down(256*M, reserve_alignment); |
302 size_t cds_total = align_down(256*M, reserve_alignment); |
280 #endif |
303 #endif |
281 |
304 |
282 // First try to reserve the space at the specified SharedBaseAddress. |
305 // First try to reserve the space at the specified SharedBaseAddress. |
283 _shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages, shared_base); |
306 //_shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages, shared_base); |
|
307 reserve_shared_rs(cds_total, reserve_alignment, large_pages, shared_base); |
284 if (_shared_rs.is_reserved()) { |
308 if (_shared_rs.is_reserved()) { |
285 assert(shared_base == 0 || _shared_rs.base() == shared_base, "should match"); |
309 assert(shared_base == 0 || _shared_rs.base() == shared_base, "should match"); |
286 } else { |
310 } else { |
287 // Get a mmap region anywhere if the SharedBaseAddress fails. |
311 // Get a mmap region anywhere if the SharedBaseAddress fails. |
288 _shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages); |
312 //_shared_rs = ReservedSpace(cds_total, reserve_alignment, large_pages); |
|
313 reserve_shared_rs(cds_total, reserve_alignment, large_pages, NULL); |
289 } |
314 } |
290 if (!_shared_rs.is_reserved()) { |
315 if (!_shared_rs.is_reserved()) { |
291 vm_exit_during_initialization("Unable to reserve memory for shared space", |
316 vm_exit_during_initialization("Unable to reserve memory for shared space", |
292 err_msg(SIZE_FORMAT " bytes.", cds_total)); |
317 err_msg(SIZE_FORMAT " bytes.", cds_total)); |
293 } |
318 } |
757 |
804 |
758 return vtable_len; |
805 return vtable_len; |
759 } |
806 } |
760 |
807 |
761 #define ALLOC_CPP_VTABLE_CLONE(c) \ |
808 #define ALLOC_CPP_VTABLE_CLONE(c) \ |
762 CppVtableCloner<c>::allocate(#c); |
809 _cloned_cpp_vtptrs[c##_Kind] = CppVtableCloner<c>::allocate(#c); |
763 |
810 |
764 #define CLONE_CPP_VTABLE(c) \ |
811 #define CLONE_CPP_VTABLE(c) \ |
765 p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p); |
812 p = CppVtableCloner<c>::clone_vtable(#c, (CppVtableInfo*)p); |
766 |
813 |
767 #define ZERO_CPP_VTABLE(c) \ |
814 #define ZERO_CPP_VTABLE(c) \ |
768 CppVtableCloner<c>::zero_vtable_clone(); |
815 CppVtableCloner<c>::zero_vtable_clone(); |
|
816 |
|
817 //------------------------------ for DynamicDumpSharedSpaces - start |
|
818 #define DECLARE_CLONED_VTABLE_KIND(c) c ## _Kind, |
|
819 |
|
820 enum { |
|
821 CPP_VTABLE_PATCH_TYPES_DO(DECLARE_CLONED_VTABLE_KIND) |
|
822 _num_cloned_vtable_kinds |
|
823 }; |
|
824 |
|
825 static intptr_t** _cloned_cpp_vtptrs = NULL; |
|
826 |
|
827 void MetaspaceShared::serialize_cloned_cpp_vtptrs(SerializeClosure* soc) { |
|
828 soc->do_ptr((void**)&_cloned_cpp_vtptrs); |
|
829 } |
|
830 |
|
831 intptr_t* MetaspaceShared::fix_cpp_vtable_for_dynamic_archive(MetaspaceObj::Type msotype, address obj) { |
|
832 assert(DynamicDumpSharedSpaces, "must"); |
|
833 int kind = -1; |
|
834 switch (msotype) { |
|
835 case MetaspaceObj::SymbolType: |
|
836 case MetaspaceObj::TypeArrayU1Type: |
|
837 case MetaspaceObj::TypeArrayU2Type: |
|
838 case MetaspaceObj::TypeArrayU4Type: |
|
839 case MetaspaceObj::TypeArrayU8Type: |
|
840 case MetaspaceObj::TypeArrayOtherType: |
|
841 case MetaspaceObj::ConstMethodType: |
|
842 case MetaspaceObj::ConstantPoolCacheType: |
|
843 case MetaspaceObj::AnnotationsType: |
|
844 case MetaspaceObj::MethodCountersType: |
|
845 // These have no vtables. |
|
846 break; |
|
847 case MetaspaceObj::ClassType: |
|
848 { |
|
849 Klass* k = (Klass*)obj; |
|
850 assert(k->is_klass(), "must be"); |
|
851 if (k->is_instance_klass()) { |
|
852 kind = InstanceKlass_Kind; |
|
853 } else { |
|
854 assert(k->is_objArray_klass(), |
|
855 "We shouldn't archive any other klasses in DynamicDumpSharedSpaces"); |
|
856 kind = ObjArrayKlass_Kind; |
|
857 } |
|
858 } |
|
859 break; |
|
860 |
|
861 case MetaspaceObj::MethodType: |
|
862 { |
|
863 Method* m = (Method*)obj; |
|
864 assert(m->is_method(), "must be"); |
|
865 kind = Method_Kind; |
|
866 } |
|
867 break; |
|
868 |
|
869 case MetaspaceObj::MethodDataType: |
|
870 // We don't archive MethodData <-- should have been removed in removed_unsharable_info |
|
871 ShouldNotReachHere(); |
|
872 break; |
|
873 |
|
874 case MetaspaceObj::ConstantPoolType: |
|
875 { |
|
876 ConstantPool *cp = (ConstantPool*)obj; |
|
877 assert(cp->is_constantPool(), "must be"); |
|
878 kind = ConstantPool_Kind; |
|
879 } |
|
880 break; |
|
881 |
|
882 default: |
|
883 ShouldNotReachHere(); |
|
884 } |
|
885 |
|
886 if (kind >= 0) { |
|
887 assert(kind < _num_cloned_vtable_kinds, "must be"); |
|
888 return _cloned_cpp_vtptrs[kind]; |
|
889 } else { |
|
890 return NULL; |
|
891 } |
|
892 } |
|
893 |
|
894 //------------------------------ for DynamicDumpSharedSpaces - end |
769 |
895 |
770 // This can be called at both dump time and run time. |
896 // This can be called at both dump time and run time. |
771 intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) { |
897 intptr_t* MetaspaceShared::clone_cpp_vtables(intptr_t* p) { |
772 assert(DumpSharedSpaces || UseSharedSpaces, "sanity"); |
898 assert(DumpSharedSpaces || UseSharedSpaces, "sanity"); |
773 CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE); |
899 CPP_VTABLE_PATCH_TYPES_DO(CLONE_CPP_VTABLE); |
828 bool MetaspaceShared::is_valid_shared_method(const Method* m) { |
954 bool MetaspaceShared::is_valid_shared_method(const Method* m) { |
829 assert(is_in_shared_metaspace(m), "must be"); |
955 assert(is_in_shared_metaspace(m), "must be"); |
830 return CppVtableCloner<Method>::is_valid_shared_object(m); |
956 return CppVtableCloner<Method>::is_valid_shared_object(m); |
831 } |
957 } |
832 |
958 |
833 // Closure for serializing initialization data out to a data area to be |
959 void WriteClosure::do_oop(oop* o) { |
834 // written to the shared file. |
960 if (*o == NULL) { |
835 |
961 _dump_region->append_intptr_t(0); |
836 class WriteClosure : public SerializeClosure { |
962 } else { |
837 private: |
963 assert(HeapShared::is_heap_object_archiving_allowed(), |
838 DumpRegion* _dump_region; |
964 "Archiving heap object is not allowed"); |
839 |
965 _dump_region->append_intptr_t( |
840 public: |
966 (intptr_t)CompressedOops::encode_not_null(*o)); |
841 WriteClosure(DumpRegion* r) { |
967 } |
842 _dump_region = r; |
968 } |
843 } |
969 |
844 |
970 void WriteClosure::do_region(u_char* start, size_t size) { |
845 void do_ptr(void** p) { |
971 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
846 _dump_region->append_intptr_t((intptr_t)*p); |
972 assert(size % sizeof(intptr_t) == 0, "bad size"); |
847 } |
973 do_tag((int)size); |
848 |
974 while (size > 0) { |
849 void do_u4(u4* p) { |
975 _dump_region->append_intptr_t(*(intptr_t*)start); |
850 void* ptr = (void*)(uintx(*p)); |
976 start += sizeof(intptr_t); |
851 do_ptr(&ptr); |
977 size -= sizeof(intptr_t); |
852 } |
978 } |
853 |
979 } |
854 void do_tag(int tag) { |
|
855 _dump_region->append_intptr_t((intptr_t)tag); |
|
856 } |
|
857 |
|
858 void do_oop(oop* o) { |
|
859 if (*o == NULL) { |
|
860 _dump_region->append_intptr_t(0); |
|
861 } else { |
|
862 assert(HeapShared::is_heap_object_archiving_allowed(), |
|
863 "Archiving heap object is not allowed"); |
|
864 _dump_region->append_intptr_t( |
|
865 (intptr_t)CompressedOops::encode_not_null(*o)); |
|
866 } |
|
867 } |
|
868 |
|
869 void do_region(u_char* start, size_t size) { |
|
870 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
|
871 assert(size % sizeof(intptr_t) == 0, "bad size"); |
|
872 do_tag((int)size); |
|
873 while (size > 0) { |
|
874 _dump_region->append_intptr_t(*(intptr_t*)start); |
|
875 start += sizeof(intptr_t); |
|
876 size -= sizeof(intptr_t); |
|
877 } |
|
878 } |
|
879 |
|
880 bool reading() const { return false; } |
|
881 }; |
|
882 |
980 |
883 // This is for dumping detailed statistics for the allocations |
981 // This is for dumping detailed statistics for the allocations |
884 // in the shared spaces. |
982 // in the shared spaces. |
885 class DumpAllocStats : public ResourceObj { |
983 class DumpAllocStats : public ResourceObj { |
886 public: |
984 public: |
1814 oopmaps->append(info); |
1920 oopmaps->append(info); |
1815 } |
1921 } |
1816 } |
1922 } |
1817 #endif // INCLUDE_CDS_JAVA_HEAP |
1923 #endif // INCLUDE_CDS_JAVA_HEAP |
1818 |
1924 |
1819 // Closure for serializing initialization data in from a data area |
1925 void ReadClosure::do_ptr(void** p) { |
1820 // (ptr_array) read from the shared file. |
1926 assert(*p == NULL, "initializing previous initialized pointer."); |
1821 |
1927 intptr_t obj = nextPtr(); |
1822 class ReadClosure : public SerializeClosure { |
1928 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100, |
1823 private: |
1929 "hit tag while initializing ptrs."); |
1824 intptr_t** _ptr_array; |
1930 *p = (void*)obj; |
1825 |
1931 } |
1826 inline intptr_t nextPtr() { |
1932 |
1827 return *(*_ptr_array)++; |
1933 void ReadClosure::do_u4(u4* p) { |
1828 } |
1934 intptr_t obj = nextPtr(); |
1829 |
1935 *p = (u4)(uintx(obj)); |
1830 public: |
1936 } |
1831 ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; } |
1937 |
1832 |
1938 void ReadClosure::do_tag(int tag) { |
1833 void do_ptr(void** p) { |
1939 int old_tag; |
1834 assert(*p == NULL, "initializing previous initialized pointer."); |
1940 old_tag = (int)(intptr_t)nextPtr(); |
1835 intptr_t obj = nextPtr(); |
1941 // do_int(&old_tag); |
1836 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100, |
1942 assert(tag == old_tag, "old tag doesn't match"); |
1837 "hit tag while initializing ptrs."); |
1943 FileMapInfo::assert_mark(tag == old_tag); |
1838 *p = (void*)obj; |
1944 } |
1839 } |
1945 |
1840 |
1946 void ReadClosure::do_oop(oop *p) { |
1841 void do_u4(u4* p) { |
1947 narrowOop o = (narrowOop)nextPtr(); |
1842 intptr_t obj = nextPtr(); |
1948 if (o == 0 || !HeapShared::open_archive_heap_region_mapped()) { |
1843 *p = (u4)(uintx(obj)); |
1949 p = NULL; |
1844 } |
1950 } else { |
1845 |
1951 assert(HeapShared::is_heap_object_archiving_allowed(), |
1846 void do_tag(int tag) { |
1952 "Archived heap object is not allowed"); |
1847 int old_tag; |
1953 assert(HeapShared::open_archive_heap_region_mapped(), |
1848 old_tag = (int)(intptr_t)nextPtr(); |
1954 "Open archive heap region is not mapped"); |
1849 // do_int(&old_tag); |
1955 *p = HeapShared::decode_from_archive(o); |
1850 assert(tag == old_tag, "old tag doesn't match"); |
1956 } |
1851 FileMapInfo::assert_mark(tag == old_tag); |
1957 } |
1852 } |
1958 |
1853 |
1959 void ReadClosure::do_region(u_char* start, size_t size) { |
1854 void do_oop(oop *p) { |
1960 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
1855 narrowOop o = (narrowOop)nextPtr(); |
1961 assert(size % sizeof(intptr_t) == 0, "bad size"); |
1856 if (o == 0 || !HeapShared::open_archive_heap_region_mapped()) { |
1962 do_tag((int)size); |
1857 p = NULL; |
1963 while (size > 0) { |
1858 } else { |
1964 *(intptr_t*)start = nextPtr(); |
1859 assert(HeapShared::is_heap_object_archiving_allowed(), |
1965 start += sizeof(intptr_t); |
1860 "Archived heap object is not allowed"); |
1966 size -= sizeof(intptr_t); |
1861 assert(HeapShared::open_archive_heap_region_mapped(), |
1967 } |
1862 "Open archive heap region is not mapped"); |
1968 } |
1863 *p = HeapShared::decode_from_archive(o); |
1969 |
1864 } |
1970 void MetaspaceShared::set_shared_metaspace_range(void* base, void* top) { |
1865 } |
1971 _shared_metaspace_static_top = top; |
1866 |
1972 MetaspaceObj::set_shared_metaspace_range(base, top); |
1867 void do_region(u_char* start, size_t size) { |
1973 } |
1868 assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment"); |
|
1869 assert(size % sizeof(intptr_t) == 0, "bad size"); |
|
1870 do_tag((int)size); |
|
1871 while (size > 0) { |
|
1872 *(intptr_t*)start = nextPtr(); |
|
1873 start += sizeof(intptr_t); |
|
1874 size -= sizeof(intptr_t); |
|
1875 } |
|
1876 } |
|
1877 |
|
1878 bool reading() const { return true; } |
|
1879 }; |
|
1880 |
1974 |
1881 // Return true if given address is in the misc data region |
1975 // Return true if given address is in the misc data region |
1882 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) { |
1976 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) { |
1883 return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx); |
1977 return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx); |
1884 } |
1978 } |
1902 if (!shared_rs.is_reserved()) return false; |
2005 if (!shared_rs.is_reserved()) return false; |
1903 #endif |
2006 #endif |
1904 |
2007 |
1905 assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces"); |
2008 assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces"); |
1906 |
2009 |
1907 char* ro_base = NULL; char* ro_top; |
|
1908 char* rw_base = NULL; char* rw_top; |
|
1909 char* mc_base = NULL; char* mc_top; |
|
1910 char* md_base = NULL; char* md_top; |
|
1911 |
|
1912 // Map each shared region |
2010 // Map each shared region |
1913 if ((mc_base = mapinfo->map_region(mc, &mc_top)) != NULL && |
2011 int regions[] = {mc, rw, ro, md}; |
1914 (rw_base = mapinfo->map_region(rw, &rw_top)) != NULL && |
2012 size_t len = sizeof(regions)/sizeof(int); |
1915 (ro_base = mapinfo->map_region(ro, &ro_top)) != NULL && |
2013 char* saved_base[] = {NULL, NULL, NULL, NULL}; |
1916 (md_base = mapinfo->map_region(md, &md_top)) != NULL && |
2014 char* top = mapinfo->map_regions(regions, saved_base, len ); |
|
2015 |
|
2016 if (top != NULL && |
1917 (image_alignment == (size_t)os::vm_allocation_granularity()) && |
2017 (image_alignment == (size_t)os::vm_allocation_granularity()) && |
1918 mapinfo->validate_shared_path_table()) { |
2018 mapinfo->validate_shared_path_table()) { |
1919 // Success -- set up MetaspaceObj::_shared_metaspace_{base,top} for |
2019 // Success -- set up MetaspaceObj::_shared_metaspace_{base,top} for |
1920 // fast checking in MetaspaceShared::is_in_shared_metaspace() and |
2020 // fast checking in MetaspaceShared::is_in_shared_metaspace() and |
1921 // MetaspaceObj::is_shared(). |
2021 // MetaspaceObj::is_shared(). |
1922 // |
|
1923 // We require that mc->rw->ro->md to be laid out consecutively, with no |
|
1924 // gaps between them. That way, we can ensure that the OS won't be able to |
|
1925 // allocate any new memory spaces inside _shared_metaspace_{base,top}, which |
|
1926 // would mess up the simple comparision in MetaspaceShared::is_in_shared_metaspace(). |
|
1927 assert(mc_base < ro_base && mc_base < rw_base && mc_base < md_base, "must be"); |
|
1928 assert(md_top > ro_top && md_top > rw_top && md_top > mc_top , "must be"); |
|
1929 assert(mc_top == rw_base, "must be"); |
|
1930 assert(rw_top == ro_base, "must be"); |
|
1931 assert(ro_top == md_base, "must be"); |
|
1932 |
|
1933 _core_spaces_size = mapinfo->core_spaces_size(); |
2022 _core_spaces_size = mapinfo->core_spaces_size(); |
1934 MetaspaceObj::set_shared_metaspace_range((void*)mc_base, (void*)md_top); |
2023 set_shared_metaspace_range((void*)saved_base[0], (void*)top); |
1935 return true; |
2024 return true; |
1936 } else { |
2025 } else { |
1937 // If there was a failure in mapping any of the spaces, unmap the ones |
2026 mapinfo->unmap_regions(regions, saved_base, len); |
1938 // that succeeded |
|
1939 if (ro_base != NULL) mapinfo->unmap_region(ro); |
|
1940 if (rw_base != NULL) mapinfo->unmap_region(rw); |
|
1941 if (mc_base != NULL) mapinfo->unmap_region(mc); |
|
1942 if (md_base != NULL) mapinfo->unmap_region(md); |
|
1943 #ifndef _WINDOWS |
2027 #ifndef _WINDOWS |
1944 // Release the entire mapped region |
2028 // Release the entire mapped region |
1945 shared_rs.release(); |
2029 shared_rs.release(); |
1946 #endif |
2030 #endif |
1947 // If -Xshare:on is specified, print out the error message and exit VM, |
2031 // If -Xshare:on is specified, print out the error message and exit VM, |