< prev index next >

src/hotspot/share/cds/archiveBuilder.hpp

Print this page

128     bool _read_only;
129     bool _has_embedded_pointer;
130     FollowMode _follow_mode;
131     int _size_in_bytes;
132     int _id; // Each object has a unique serial ID, starting from zero. The ID is assigned
133              // when the object is added into _source_objs.
134     MetaspaceObj::Type _msotype;
135     address _source_addr;    // The source object to be copied.
136     address _buffered_addr;  // The copy of this object insider the buffer.
137   public:
138     SourceObjInfo(MetaspaceClosure::Ref* ref, bool read_only, FollowMode follow_mode) :
139       _ptrmap_start(0), _ptrmap_end(0), _read_only(read_only), _has_embedded_pointer(false), _follow_mode(follow_mode),
140       _size_in_bytes(ref->size() * BytesPerWord), _id(0), _msotype(ref->msotype()),
141       _source_addr(ref->obj()) {
142       if (follow_mode == point_to_it) {
143         _buffered_addr = ref->obj();
144       } else {
145         _buffered_addr = nullptr;
146       }
147     }




148 
149     // This constructor is only used for regenerated objects (created by LambdaFormInvokers, etc).
150     //   src = address of a Method or InstanceKlass that has been regenerated.
151     //   renegerated_obj_info = info for the regenerated version of src.
152     SourceObjInfo(address src, SourceObjInfo* renegerated_obj_info) :
153       _ptrmap_start(0), _ptrmap_end(0), _read_only(false),
154       _follow_mode(renegerated_obj_info->_follow_mode),
155       _size_in_bytes(0), _msotype(renegerated_obj_info->_msotype),
156       _source_addr(src),  _buffered_addr(renegerated_obj_info->_buffered_addr) {}
157 
158     bool should_copy() const { return _follow_mode == make_a_copy; }
159     void set_buffered_addr(address addr)  {
160       assert(should_copy(), "must be");
161       assert(_buffered_addr == nullptr, "cannot be copied twice");
162       assert(addr != nullptr, "must be a valid copy");
163       _buffered_addr = addr;
164     }
165     void set_ptrmap_start(uintx v) { _ptrmap_start = v;    }
166     void set_ptrmap_end(uintx v)   { _ptrmap_end = v;      }
167     uintx ptrmap_start()  const    { return _ptrmap_start; } // inclusive

194     GrowableArray<SourceObjInfo*>* objs() const { return _objs; }
195 
196     void append(SourceObjInfo* src_info);
197     void remember_embedded_pointer(SourceObjInfo* pointing_obj, MetaspaceClosure::Ref* ref);
198     void relocate(int i, ArchiveBuilder* builder);
199 
200     // convenience accessor
201     SourceObjInfo* at(int i) const { return objs()->at(i); }
202   };
203 
204   class CDSMapLogger;
205 
206   static const int INITIAL_TABLE_SIZE = 15889;
207   static const int MAX_TABLE_SIZE     = 1000000;
208 
209   ReservedSpace _shared_rs;
210   VirtualSpace _shared_vs;
211 
212   DumpRegion _rw_region;
213   DumpRegion _ro_region;

214 
215   // Combined bitmap to track pointers in both RW and RO regions. This is updated
216   // as objects are copied into RW and RO.
217   CHeapBitMap _ptrmap;
218 
219   // _ptrmap is split into these two bitmaps which are written into the archive.
220   CHeapBitMap _rw_ptrmap;   // marks pointers in the RW region
221   CHeapBitMap _ro_ptrmap;   // marks pointers in the RO region

222 
223   SourceObjList _rw_src_objs;                 // objs to put in rw region
224   SourceObjList _ro_src_objs;                 // objs to put in ro region
225   ResizeableResourceHashtable<address, SourceObjInfo, AnyObj::C_HEAP, mtClassShared> _src_obj_table;
226   ResizeableResourceHashtable<address, address, AnyObj::C_HEAP, mtClassShared> _buffered_to_src_table;
227   GrowableArray<Klass*>* _klasses;
228   GrowableArray<Symbol*>* _symbols;
229   unsigned int _entropy_seed;
230 
231   // statistics
232   DumpAllocStats _alloc_stats;
233   size_t _total_heap_region_size;
234 
235   void print_region_stats(FileMapInfo *map_info, ArchiveHeapInfo* heap_info);
236   void print_bitmap_region_stats(size_t size, size_t total_size);
237   void print_heap_region_stats(ArchiveHeapInfo* heap_info, size_t total_size);
238 
239   // For global access.
240   static ArchiveBuilder* _current;
241 
242 public:
243   // Use this when you allocate space outside of ArchiveBuilder::dump_{rw,ro}_region.
244   // These are usually for misc tables that are allocated in the RO space.
245   class OtherROAllocMark {
246     char* _oldtop;
247   public:
248     OtherROAllocMark() {
249       _oldtop = _current->_ro_region.top();
250     }
251     ~OtherROAllocMark();
252   };
253 
254 private:
255   FollowMode get_follow_mode(MetaspaceClosure::Ref *ref);
256 
257   void iterate_sorted_roots(MetaspaceClosure* it);
258   void sort_klasses();
259   static int compare_symbols_by_address(Symbol** a, Symbol** b);
260   static int compare_klass_by_name(Klass** a, Klass** b);

261 
262   void make_shallow_copies(DumpRegion *dump_region, const SourceObjList* src_objs);
263   void make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* src_info);
264 
265   void relocate_embedded_pointers(SourceObjList* src_objs);
266 
267   bool is_excluded(Klass* k);
268   void clean_up_src_obj_table();
269 
270 protected:
271   virtual void iterate_roots(MetaspaceClosure* it) = 0;
272 
273   // Conservative estimate for number of bytes needed for:
274   size_t _estimated_metaspaceobj_bytes;   // all archived MetaspaceObj's.
275   size_t _estimated_hashtable_bytes;     // symbol table and dictionaries
276 
277   static const int _total_dump_regions = 2;
278 
279   size_t estimate_archive_size();
280 
281   void start_dump_region(DumpRegion* next);
282   void verify_estimate_size(size_t estimate, const char* which);
283 
284 public:
285   address reserve_buffer();
286 
287   address buffer_bottom()                    const { return _buffer_bottom;                        }
288   address buffer_top()                       const { return (address)current_dump_region()->top(); }
289   address requested_static_archive_bottom()  const { return  _requested_static_archive_bottom;     }
290   address mapped_static_archive_bottom()     const { return  _mapped_static_archive_bottom;        }
291   intx buffer_to_requested_delta()           const { return _buffer_to_requested_delta;            }
292 
293   bool is_in_buffer_space(address p) const {
294     return (buffer_bottom() <= p && p < buffer_top());
295   }
296 
297   template <typename T> bool is_in_requested_static_archive(T p) const {
298     return _requested_static_archive_bottom <= (address)p && (address)p < _requested_static_archive_top;
299   }
300 
301   template <typename T> bool is_in_mapped_static_archive(T p) const {
302     return _mapped_static_archive_bottom <= (address)p && (address)p < _mapped_static_archive_top;
303   }
304 
305   template <typename T> bool is_in_buffer_space(T obj) const {
306     return is_in_buffer_space(address(obj));
307   }
308 
309   template <typename T> T to_requested(T obj) const {
310     assert(is_in_buffer_space(obj), "must be");
311     return (T)(address(obj) + _buffer_to_requested_delta);
312   }
313 
314   static intx get_buffer_to_requested_delta() {

340   template <typename T>
341   u4 any_to_offset_u4(T p) const {
342     uintx offset = any_to_offset((address)p);
343     return to_offset_u4(offset);
344   }
345 
346 public:
347   ArchiveBuilder();
348   ~ArchiveBuilder();
349 
350   int entropy();
351   void gather_klasses_and_symbols();
352   void gather_source_objs();
353   bool gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool read_only);
354   bool gather_one_source_obj(MetaspaceClosure::Ref* ref, bool read_only);
355   void remember_embedded_pointer_in_enclosing_obj(MetaspaceClosure::Ref* ref);
356   static void serialize_dynamic_archivable_items(SerializeClosure* soc);
357 
358   DumpRegion* rw_region() { return &_rw_region; }
359   DumpRegion* ro_region() { return &_ro_region; }




360 
361   static char* rw_region_alloc(size_t num_bytes) {
362     return current()->rw_region()->allocate(num_bytes);
363   }
364   static char* ro_region_alloc(size_t num_bytes) {
365     return current()->ro_region()->allocate(num_bytes);
366   }



367 
368   template <typename T>
369   static Array<T>* new_ro_array(int length) {
370     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
371     Array<T>* array = (Array<T>*)ro_region_alloc(byte_size);
372     array->initialize(length);
373     return array;
374   }
375 
376   template <typename T>
377   static Array<T>* new_rw_array(int length) {
378     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
379     Array<T>* array = (Array<T>*)rw_region_alloc(byte_size);
380     array->initialize(length);
381     return array;
382   }
383 
384   template <typename T>
385   static size_t ro_array_bytesize(int length) {
386     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
387     return align_up(byte_size, SharedSpaceObjectAlignment);
388   }
389 
390   char* ro_strdup(const char* s);
391 
392   static int compare_src_objs(SourceObjInfo** a, SourceObjInfo** b);
393   void sort_metadata_objs();
394   void dump_rw_metadata();
395   void dump_ro_metadata();
396   void relocate_metaspaceobj_embedded_pointers();
397   void record_regenerated_object(address orig_src_obj, address regen_src_obj);
398   void make_klasses_shareable();

399   void relocate_to_requested();
400   void write_archive(FileMapInfo* mapinfo, ArchiveHeapInfo* heap_info);
401   void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
402                     bool read_only,  bool allow_exec);
403 
404   void write_pointer_in_buffer(address* ptr_location, address src_addr);
405   template <typename T> void write_pointer_in_buffer(T* ptr_location, T src_addr) {
406     write_pointer_in_buffer((address*)ptr_location, (address)src_addr);
407   }
408 
409   void mark_and_relocate_to_buffered_addr(address* ptr_location);
410   template <typename T> void mark_and_relocate_to_buffered_addr(T ptr_location) {
411     mark_and_relocate_to_buffered_addr((address*)ptr_location);
412   }
413 

414   address get_buffered_addr(address src_addr) const;
415   template <typename T> T get_buffered_addr(T src_addr) const {
416     return (T)get_buffered_addr((address)src_addr);

417   }
418 
419   address get_source_addr(address buffered_addr) const;
420   template <typename T> T get_source_addr(T buffered_addr) const {
421     return (T)get_source_addr((address)buffered_addr);
422   }
423 
424   // All klasses and symbols that will be copied into the archive
425   GrowableArray<Klass*>*  klasses() const { return _klasses; }
426   GrowableArray<Symbol*>* symbols() const { return _symbols; }
427 
428   static bool is_active() {
429     return (_current != nullptr);

430   }
431 
432   static ArchiveBuilder* current() {
433     assert(_current != nullptr, "ArchiveBuilder must be active");
434     return _current;
435   }
436 
437   static DumpAllocStats* alloc_stats() {
438     return &(current()->_alloc_stats);
439   }
440 
441   static CompactHashtableStats* symbol_stats() {
442     return alloc_stats()->symbol_stats();
443   }
444 
445   static CompactHashtableStats* string_stats() {
446     return alloc_stats()->string_stats();
447   }
448 
449   narrowKlass get_requested_narrow_klass(Klass* k);

128     bool _read_only;
129     bool _has_embedded_pointer;
130     FollowMode _follow_mode;
131     int _size_in_bytes;
132     int _id; // Each object has a unique serial ID, starting from zero. The ID is assigned
133              // when the object is added into _source_objs.
134     MetaspaceObj::Type _msotype;
135     address _source_addr;    // The source object to be copied.
136     address _buffered_addr;  // The copy of this object insider the buffer.
137   public:
138     SourceObjInfo(MetaspaceClosure::Ref* ref, bool read_only, FollowMode follow_mode) :
139       _ptrmap_start(0), _ptrmap_end(0), _read_only(read_only), _has_embedded_pointer(false), _follow_mode(follow_mode),
140       _size_in_bytes(ref->size() * BytesPerWord), _id(0), _msotype(ref->msotype()),
141       _source_addr(ref->obj()) {
142       if (follow_mode == point_to_it) {
143         _buffered_addr = ref->obj();
144       } else {
145         _buffered_addr = nullptr;
146       }
147     }
148     SourceObjInfo(address src, address buf) {
149       _source_addr = src;
150       _buffered_addr = buf;
151     }
152 
153     // This constructor is only used for regenerated objects (created by LambdaFormInvokers, etc).
154     //   src = address of a Method or InstanceKlass that has been regenerated.
155     //   renegerated_obj_info = info for the regenerated version of src.
156     SourceObjInfo(address src, SourceObjInfo* renegerated_obj_info) :
157       _ptrmap_start(0), _ptrmap_end(0), _read_only(false),
158       _follow_mode(renegerated_obj_info->_follow_mode),
159       _size_in_bytes(0), _msotype(renegerated_obj_info->_msotype),
160       _source_addr(src),  _buffered_addr(renegerated_obj_info->_buffered_addr) {}
161 
162     bool should_copy() const { return _follow_mode == make_a_copy; }
163     void set_buffered_addr(address addr)  {
164       assert(should_copy(), "must be");
165       assert(_buffered_addr == nullptr, "cannot be copied twice");
166       assert(addr != nullptr, "must be a valid copy");
167       _buffered_addr = addr;
168     }
169     void set_ptrmap_start(uintx v) { _ptrmap_start = v;    }
170     void set_ptrmap_end(uintx v)   { _ptrmap_end = v;      }
171     uintx ptrmap_start()  const    { return _ptrmap_start; } // inclusive

198     GrowableArray<SourceObjInfo*>* objs() const { return _objs; }
199 
200     void append(SourceObjInfo* src_info);
201     void remember_embedded_pointer(SourceObjInfo* pointing_obj, MetaspaceClosure::Ref* ref);
202     void relocate(int i, ArchiveBuilder* builder);
203 
204     // convenience accessor
205     SourceObjInfo* at(int i) const { return objs()->at(i); }
206   };
207 
208   class CDSMapLogger;
209 
210   static const int INITIAL_TABLE_SIZE = 15889;
211   static const int MAX_TABLE_SIZE     = 1000000;
212 
213   ReservedSpace _shared_rs;
214   VirtualSpace _shared_vs;
215 
216   DumpRegion _rw_region;
217   DumpRegion _ro_region;
218   DumpRegion _cc_region;
219 
220   // Combined bitmap to track pointers in both RW and RO regions. This is updated
221   // as objects are copied into RW and RO.
222   CHeapBitMap _ptrmap;
223 
224   // _ptrmap is split into these two bitmaps which are written into the archive.
225   CHeapBitMap _rw_ptrmap;   // marks pointers in the RW region
226   CHeapBitMap _ro_ptrmap;   // marks pointers in the RO region
227   CHeapBitMap _cc_ptrmap;   // marks pointers in the CC region
228 
229   SourceObjList _rw_src_objs;                 // objs to put in rw region
230   SourceObjList _ro_src_objs;                 // objs to put in ro region
231   ResizeableResourceHashtable<address, SourceObjInfo, AnyObj::C_HEAP, mtClassShared> _src_obj_table;
232   ResizeableResourceHashtable<address, address, AnyObj::C_HEAP, mtClassShared> _buffered_to_src_table;
233   GrowableArray<Klass*>* _klasses;
234   GrowableArray<Symbol*>* _symbols;
235   unsigned int _entropy_seed;
236 
237   // statistics
238   DumpAllocStats _alloc_stats;
239   size_t _total_heap_region_size;
240 
241   void print_region_stats(FileMapInfo *map_info, ArchiveHeapInfo* heap_info);
242   void print_bitmap_region_stats(size_t size, size_t total_size);
243   void print_heap_region_stats(ArchiveHeapInfo* heap_info, size_t total_size);
244 
245   // For global access.
246   static ArchiveBuilder* _current;
247 
248 public:
249   // Use this when you allocate space outside of ArchiveBuilder::dump_{rw,ro}_region.
250   // These are usually for misc tables that are allocated in the RO space.
251   class OtherROAllocMark {
252     char* _oldtop;
253   public:
254     OtherROAllocMark() {
255       _oldtop = _current->_ro_region.top();
256     }
257     ~OtherROAllocMark();
258   };
259 
260 private:
261   FollowMode get_follow_mode(MetaspaceClosure::Ref *ref);
262 
263   void iterate_sorted_roots(MetaspaceClosure* it);
264   void sort_klasses();
265   static int compare_symbols_by_address(Symbol** a, Symbol** b);
266   static int compare_klass_by_name(Klass** a, Klass** b);
267   void update_hidden_class_loader_type(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN;
268 
269   void make_shallow_copies(DumpRegion *dump_region, const SourceObjList* src_objs);
270   void make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* src_info);
271 
272   void relocate_embedded_pointers(SourceObjList* src_objs);
273 
274   bool is_excluded(Klass* k);
275   void clean_up_src_obj_table();
276 
277 protected:
278   virtual void iterate_roots(MetaspaceClosure* it) = 0;
279 
280   // Conservative estimate for number of bytes needed for:
281   size_t _estimated_metaspaceobj_bytes;   // all archived MetaspaceObj's.
282   size_t _estimated_hashtable_bytes;     // symbol table and dictionaries
283 
284   static const int _total_dump_regions = 2;
285 
286   size_t estimate_archive_size();
287 
288   void start_dump_region(DumpRegion* next);
289   void verify_estimate_size(size_t estimate, const char* which);
290 
291 public:
292   address reserve_buffer();
293 
294   address buffer_bottom()                    const { return _buffer_bottom;                        }
295   address buffer_top()                       const { return (address)current_dump_region()->top(); }
296   address requested_static_archive_bottom()  const { return  _requested_static_archive_bottom;     }
297   address mapped_static_archive_bottom()     const { return  _mapped_static_archive_bottom;        }
298   intx buffer_to_requested_delta()           const { return _buffer_to_requested_delta;            }
299 
300   bool is_in_buffer_space(address p) const {
301     return (buffer_bottom() != nullptr && buffer_bottom() <= p && p < buffer_top());
302   }
303 
304   template <typename T> bool is_in_requested_static_archive(T p) const {
305     return _requested_static_archive_bottom <= (address)p && (address)p < _requested_static_archive_top;
306   }
307 
308   template <typename T> bool is_in_mapped_static_archive(T p) const {
309     return _mapped_static_archive_bottom <= (address)p && (address)p < _mapped_static_archive_top;
310   }
311 
312   template <typename T> bool is_in_buffer_space(T obj) const {
313     return is_in_buffer_space(address(obj));
314   }
315 
316   template <typename T> T to_requested(T obj) const {
317     assert(is_in_buffer_space(obj), "must be");
318     return (T)(address(obj) + _buffer_to_requested_delta);
319   }
320 
321   static intx get_buffer_to_requested_delta() {

347   template <typename T>
348   u4 any_to_offset_u4(T p) const {
349     uintx offset = any_to_offset((address)p);
350     return to_offset_u4(offset);
351   }
352 
353 public:
354   ArchiveBuilder();
355   ~ArchiveBuilder();
356 
357   int entropy();
358   void gather_klasses_and_symbols();
359   void gather_source_objs();
360   bool gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool read_only);
361   bool gather_one_source_obj(MetaspaceClosure::Ref* ref, bool read_only);
362   void remember_embedded_pointer_in_enclosing_obj(MetaspaceClosure::Ref* ref);
363   static void serialize_dynamic_archivable_items(SerializeClosure* soc);
364 
365   DumpRegion* rw_region() { return &_rw_region; }
366   DumpRegion* ro_region() { return &_ro_region; }
367   DumpRegion* cc_region() { return &_cc_region; }
368 
369   void start_cc_region();
370   void end_cc_region();
371 
372   static char* rw_region_alloc(size_t num_bytes) {
373     return current()->rw_region()->allocate(num_bytes);
374   }
375   static char* ro_region_alloc(size_t num_bytes) {
376     return current()->ro_region()->allocate(num_bytes);
377   }
378   static char* cc_region_alloc(size_t num_bytes) {
379     return current()->cc_region()->allocate(num_bytes);
380   }
381 
382   template <typename T>
383   static Array<T>* new_ro_array(int length) {
384     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
385     Array<T>* array = (Array<T>*)ro_region_alloc(byte_size);
386     array->initialize(length);
387     return array;
388   }
389 
390   template <typename T>
391   static Array<T>* new_rw_array(int length) {
392     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
393     Array<T>* array = (Array<T>*)rw_region_alloc(byte_size);
394     array->initialize(length);
395     return array;
396   }
397 
398   template <typename T>
399   static size_t ro_array_bytesize(int length) {
400     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
401     return align_up(byte_size, SharedSpaceObjectAlignment);
402   }
403 
404   char* ro_strdup(const char* s);
405 
406   static int compare_src_objs(SourceObjInfo** a, SourceObjInfo** b);
407   void sort_metadata_objs();
408   void dump_rw_metadata();
409   void dump_ro_metadata();
410   void relocate_metaspaceobj_embedded_pointers();
411   void record_regenerated_object(address orig_src_obj, address regen_src_obj);
412   void make_klasses_shareable();
413   void make_training_data_shareable();
414   void relocate_to_requested();
415   void write_archive(FileMapInfo* mapinfo, ArchiveHeapInfo* heap_info);
416   void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
417                     bool read_only,  bool allow_exec);
418 
419   void write_pointer_in_buffer(address* ptr_location, address src_addr);
420   template <typename T> void write_pointer_in_buffer(T* ptr_location, T src_addr) {
421     write_pointer_in_buffer((address*)ptr_location, (address)src_addr);
422   }
423 
424   void mark_and_relocate_to_buffered_addr(address* ptr_location);
425   template <typename T> void mark_and_relocate_to_buffered_addr(T ptr_location) {
426     mark_and_relocate_to_buffered_addr((address*)ptr_location);
427   }
428 
429   bool has_been_archived(address src_addr) const;
430   address get_buffered_addr(address src_addr) const;
431   template <typename T> T get_buffered_addr(T src_addr) const {
432     CDS_ONLY(return (T)get_buffered_addr((address)src_addr);)
433     NOT_CDS(return nullptr;)
434   }
435 
436   address get_source_addr(address buffered_addr) const;
437   template <typename T> T get_source_addr(T buffered_addr) const {
438     return (T)get_source_addr((address)buffered_addr);
439   }
440 
441   // All klasses and symbols that will be copied into the archive
442   GrowableArray<Klass*>*  klasses() const { return _klasses; }
443   GrowableArray<Symbol*>* symbols() const { return _symbols; }
444 
445   static bool is_active() {
446     CDS_ONLY(return (_current != nullptr));
447     NOT_CDS(return false;)
448   }
449 
450   static ArchiveBuilder* current() {
451     assert(_current != nullptr, "ArchiveBuilder must be active");
452     return _current;
453   }
454 
455   static DumpAllocStats* alloc_stats() {
456     return &(current()->_alloc_stats);
457   }
458 
459   static CompactHashtableStats* symbol_stats() {
460     return alloc_stats()->symbol_stats();
461   }
462 
463   static CompactHashtableStats* string_stats() {
464     return alloc_stats()->string_stats();
465   }
466 
467   narrowKlass get_requested_narrow_klass(Klass* k);
< prev index next >