< prev index next >

src/hotspot/share/cds/archiveBuilder.hpp

Print this page

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




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

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

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

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

262 
263   void make_shallow_copies(DumpRegion *dump_region, const SourceObjList* src_objs);
264   void make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* src_info);
265 
266   void relocate_embedded_pointers(SourceObjList* src_objs);
267 
268   bool is_excluded(Klass* k);
269   void clean_up_src_obj_table();
270 
271 protected:
272   virtual void iterate_roots(MetaspaceClosure* it) = 0;
273 
274   static const int _total_dump_regions = 2;
275 
276   void start_dump_region(DumpRegion* next);
277 
278 public:
279   address reserve_buffer();
280 
281   address buffer_bottom()                    const { return _buffer_bottom;                        }

352 
353   template <typename T>
354   T offset_to_buffered(u4 offset) const {
355     return (T)offset_to_buffered_address(offset);
356   }
357 
358 public:
359   ArchiveBuilder();
360   ~ArchiveBuilder();
361 
362   int entropy();
363   void gather_klasses_and_symbols();
364   void gather_source_objs();
365   bool gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool read_only);
366   bool gather_one_source_obj(MetaspaceClosure::Ref* ref, bool read_only);
367   void remember_embedded_pointer_in_enclosing_obj(MetaspaceClosure::Ref* ref);
368   static void serialize_dynamic_archivable_items(SerializeClosure* soc);
369 
370   DumpRegion* rw_region() { return &_rw_region; }
371   DumpRegion* ro_region() { return &_ro_region; }




372 
373   static char* rw_region_alloc(size_t num_bytes) {
374     return current()->rw_region()->allocate(num_bytes);
375   }
376   static char* ro_region_alloc(size_t num_bytes) {
377     return current()->ro_region()->allocate(num_bytes);
378   }



379 
380   template <typename T>
381   static Array<T>* new_ro_array(int length) {
382     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
383     Array<T>* array = (Array<T>*)ro_region_alloc(byte_size);
384     array->initialize(length);
385     return array;
386   }
387 
388   template <typename T>
389   static Array<T>* new_rw_array(int length) {
390     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
391     Array<T>* array = (Array<T>*)rw_region_alloc(byte_size);
392     array->initialize(length);
393     return array;
394   }
395 
396   template <typename T>
397   static size_t ro_array_bytesize(int length) {
398     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
399     return align_up(byte_size, SharedSpaceObjectAlignment);
400   }
401 
402   char* ro_strdup(const char* s);
403 
404   static int compare_src_objs(SourceObjInfo** a, SourceObjInfo** b);
405   void sort_metadata_objs();
406   void dump_rw_metadata();
407   void dump_ro_metadata();
408   void relocate_metaspaceobj_embedded_pointers();
409   void record_regenerated_object(address orig_src_obj, address regen_src_obj);
410   void make_klasses_shareable();

411   void relocate_to_requested();
412   void write_archive(FileMapInfo* mapinfo, ArchiveHeapInfo* heap_info);
413   void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
414                     bool read_only,  bool allow_exec);
415 
416   void write_pointer_in_buffer(address* ptr_location, address src_addr);
417   template <typename T> void write_pointer_in_buffer(T* ptr_location, T src_addr) {
418     write_pointer_in_buffer((address*)ptr_location, (address)src_addr);
419   }
420 
421   void mark_and_relocate_to_buffered_addr(address* ptr_location);
422   template <typename T> void mark_and_relocate_to_buffered_addr(T ptr_location) {
423     mark_and_relocate_to_buffered_addr((address*)ptr_location);
424   }
425 


426   bool has_been_buffered(address src_addr) const;
427   template <typename T> bool has_been_buffered(T src_addr) const {
428     return has_been_buffered((address)src_addr);
429   }
430 
431   address get_buffered_addr(address src_addr) const;
432   template <typename T> T get_buffered_addr(T src_addr) const {
433     return (T)get_buffered_addr((address)src_addr);

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     return (_current != nullptr);

447   }
448 
449   static ArchiveBuilder* current() {
450     assert(_current != nullptr, "ArchiveBuilder must be active");
451     return _current;
452   }
453 
454   static DumpAllocStats* alloc_stats() {
455     return &(current()->_alloc_stats);
456   }
457 
458   static CompactHashtableStats* symbol_stats() {
459     return alloc_stats()->symbol_stats();
460   }
461 
462   static CompactHashtableStats* string_stats() {
463     return alloc_stats()->string_stats();
464   }
465 
466   narrowKlass get_requested_narrow_klass(Klass* k);

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

199     GrowableArray<SourceObjInfo*>* objs() const { return _objs; }
200 
201     void append(SourceObjInfo* src_info);
202     void remember_embedded_pointer(SourceObjInfo* pointing_obj, MetaspaceClosure::Ref* ref);
203     void relocate(int i, ArchiveBuilder* builder);
204 
205     // convenience accessor
206     SourceObjInfo* at(int i) const { return objs()->at(i); }
207   };
208 
209   class CDSMapLogger;
210 
211   static const int INITIAL_TABLE_SIZE = 15889;
212   static const int MAX_TABLE_SIZE     = 1000000;
213 
214   ReservedSpace _shared_rs;
215   VirtualSpace _shared_vs;
216 
217   DumpRegion _rw_region;
218   DumpRegion _ro_region;
219   DumpRegion _cc_region;
220 
221   // Combined bitmap to track pointers in both RW and RO regions. This is updated
222   // as objects are copied into RW and RO.
223   CHeapBitMap _ptrmap;
224 
225   // _ptrmap is split into these two bitmaps which are written into the archive.
226   CHeapBitMap _rw_ptrmap;   // marks pointers in the RW region
227   CHeapBitMap _ro_ptrmap;   // marks pointers in the RO region
228   CHeapBitMap _cc_ptrmap;   // marks pointers in the CC region
229 
230   SourceObjList _rw_src_objs;                 // objs to put in rw region
231   SourceObjList _ro_src_objs;                 // objs to put in ro region
232   ResizeableResourceHashtable<address, SourceObjInfo, AnyObj::C_HEAP, mtClassShared> _src_obj_table;
233   ResizeableResourceHashtable<address, address, AnyObj::C_HEAP, mtClassShared> _buffered_to_src_table;
234   GrowableArray<Klass*>* _klasses;
235   GrowableArray<Symbol*>* _symbols;
236   unsigned int _entropy_seed;
237 
238   // statistics
239   DumpAllocStats _alloc_stats;
240   size_t _total_heap_region_size;
241 
242   void print_region_stats(FileMapInfo *map_info, ArchiveHeapInfo* heap_info);
243   void print_bitmap_region_stats(size_t size, size_t total_size);
244   void print_heap_region_stats(ArchiveHeapInfo* heap_info, size_t total_size);
245 
246   // For global access.
247   static ArchiveBuilder* _current;
248 
249 public:
250   // Use this when you allocate space outside of ArchiveBuilder::dump_{rw,ro}_region.
251   // These are usually for misc tables that are allocated in the RO space.
252   class OtherROAllocMark {
253     char* _oldtop;
254   public:
255     OtherROAllocMark() {
256       _oldtop = _current->_ro_region.top();
257     }
258     ~OtherROAllocMark();
259   };
260 
261 private:
262   FollowMode get_follow_mode(MetaspaceClosure::Ref *ref);
263 
264   void iterate_sorted_roots(MetaspaceClosure* it);
265   void sort_klasses();
266   static int compare_symbols_by_address(Symbol** a, Symbol** b);
267   static int compare_klass_by_name(Klass** a, Klass** b);
268   void update_hidden_class_loader_type(InstanceKlass* ik) NOT_CDS_JAVA_HEAP_RETURN;
269 
270   void make_shallow_copies(DumpRegion *dump_region, const SourceObjList* src_objs);
271   void make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* src_info);
272 
273   void relocate_embedded_pointers(SourceObjList* src_objs);
274 
275   bool is_excluded(Klass* k);
276   void clean_up_src_obj_table();
277 
278 protected:
279   virtual void iterate_roots(MetaspaceClosure* it) = 0;
280 
281   static const int _total_dump_regions = 2;
282 
283   void start_dump_region(DumpRegion* next);
284 
285 public:
286   address reserve_buffer();
287 
288   address buffer_bottom()                    const { return _buffer_bottom;                        }

359 
360   template <typename T>
361   T offset_to_buffered(u4 offset) const {
362     return (T)offset_to_buffered_address(offset);
363   }
364 
365 public:
366   ArchiveBuilder();
367   ~ArchiveBuilder();
368 
369   int entropy();
370   void gather_klasses_and_symbols();
371   void gather_source_objs();
372   bool gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool read_only);
373   bool gather_one_source_obj(MetaspaceClosure::Ref* ref, bool read_only);
374   void remember_embedded_pointer_in_enclosing_obj(MetaspaceClosure::Ref* ref);
375   static void serialize_dynamic_archivable_items(SerializeClosure* soc);
376 
377   DumpRegion* rw_region() { return &_rw_region; }
378   DumpRegion* ro_region() { return &_ro_region; }
379   DumpRegion* cc_region() { return &_cc_region; }
380 
381   void start_cc_region();
382   void end_cc_region();
383 
384   static char* rw_region_alloc(size_t num_bytes) {
385     return current()->rw_region()->allocate(num_bytes);
386   }
387   static char* ro_region_alloc(size_t num_bytes) {
388     return current()->ro_region()->allocate(num_bytes);
389   }
390   static char* cc_region_alloc(size_t num_bytes) {
391     return current()->cc_region()->allocate(num_bytes);
392   }
393 
394   template <typename T>
395   static Array<T>* new_ro_array(int length) {
396     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
397     Array<T>* array = (Array<T>*)ro_region_alloc(byte_size);
398     array->initialize(length);
399     return array;
400   }
401 
402   template <typename T>
403   static Array<T>* new_rw_array(int length) {
404     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
405     Array<T>* array = (Array<T>*)rw_region_alloc(byte_size);
406     array->initialize(length);
407     return array;
408   }
409 
410   template <typename T>
411   static size_t ro_array_bytesize(int length) {
412     size_t byte_size = Array<T>::byte_sizeof(length, sizeof(T));
413     return align_up(byte_size, SharedSpaceObjectAlignment);
414   }
415 
416   char* ro_strdup(const char* s);
417 
418   static int compare_src_objs(SourceObjInfo** a, SourceObjInfo** b);
419   void sort_metadata_objs();
420   void dump_rw_metadata();
421   void dump_ro_metadata();
422   void relocate_metaspaceobj_embedded_pointers();
423   void record_regenerated_object(address orig_src_obj, address regen_src_obj);
424   void make_klasses_shareable();
425   void make_training_data_shareable();
426   void relocate_to_requested();
427   void write_archive(FileMapInfo* mapinfo, ArchiveHeapInfo* heap_info);
428   void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
429                     bool read_only,  bool allow_exec);
430 
431   void write_pointer_in_buffer(address* ptr_location, address src_addr);
432   template <typename T> void write_pointer_in_buffer(T* ptr_location, T src_addr) {
433     write_pointer_in_buffer((address*)ptr_location, (address)src_addr);
434   }
435 
436   void mark_and_relocate_to_buffered_addr(address* ptr_location);
437   template <typename T> void mark_and_relocate_to_buffered_addr(T ptr_location) {
438     mark_and_relocate_to_buffered_addr((address*)ptr_location);
439   }
440 
441   bool has_been_archived(address src_addr) const;
442 
443   bool has_been_buffered(address src_addr) const;
444   template <typename T> bool has_been_buffered(T src_addr) const {
445     return has_been_buffered((address)src_addr);
446   }

447   address get_buffered_addr(address src_addr) const;
448   template <typename T> T get_buffered_addr(T src_addr) const {
449     CDS_ONLY(return (T)get_buffered_addr((address)src_addr);)
450     NOT_CDS(return nullptr;)
451   }
452 
453   address get_source_addr(address buffered_addr) const;
454   template <typename T> T get_source_addr(T buffered_addr) const {
455     return (T)get_source_addr((address)buffered_addr);
456   }
457 
458   // All klasses and symbols that will be copied into the archive
459   GrowableArray<Klass*>*  klasses() const { return _klasses; }
460   GrowableArray<Symbol*>* symbols() const { return _symbols; }
461 
462   static bool is_active() {
463     CDS_ONLY(return (_current != nullptr));
464     NOT_CDS(return false;)
465   }
466 
467   static ArchiveBuilder* current() {
468     assert(_current != nullptr, "ArchiveBuilder must be active");
469     return _current;
470   }
471 
472   static DumpAllocStats* alloc_stats() {
473     return &(current()->_alloc_stats);
474   }
475 
476   static CompactHashtableStats* symbol_stats() {
477     return alloc_stats()->symbol_stats();
478   }
479 
480   static CompactHashtableStats* string_stats() {
481     return alloc_stats()->string_stats();
482   }
483 
484   narrowKlass get_requested_narrow_klass(Klass* k);
< prev index next >