< prev index next >

src/hotspot/share/cds/archiveUtils.hpp

Print this page

 37 #include "utilities/bitMap.hpp"
 38 #include "utilities/exceptions.hpp"
 39 #include "utilities/macros.hpp"
 40 
 41 class BootstrapInfo;
 42 class DumpAllocStats;
 43 class ReservedSpace;
 44 class VirtualSpace;
 45 
 46 template<class E> class Array;
 47 template<class E> class GrowableArray;
 48 
 49 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
 50 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
 51 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
 52 // fixed, but _ptr_end can be expanded as more objects are dumped.
 53 class ArchivePtrMarker : AllStatic {
 54   static CHeapBitMap*  _ptrmap;
 55   static CHeapBitMap*  _rw_ptrmap;
 56   static CHeapBitMap*  _ro_ptrmap;

 57   static VirtualSpace* _vs;
 58 
 59   // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
 60   // avoid unintentional copy operations after the bitmap has been finalized and written.
 61   static bool         _compacted;
 62 
 63   static address* ptr_base() { return (address*)_vs->low();  } // committed lower bound (inclusive)
 64   static address* ptr_end()  { return (address*)_vs->high(); } // committed upper bound (exclusive)
 65 
 66 public:
 67   static void initialize(CHeapBitMap* ptrmap, VirtualSpace* vs);
 68   static void initialize_rw_ro_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap);
 69   static void mark_pointer(address* ptr_loc);
 70   static void clear_pointer(address* ptr_loc);
 71   static void compact(address relocatable_base, address relocatable_end);
 72   static void compact(size_t max_non_null_offset);
 73 
 74   template <typename T>
 75   static void mark_pointer(T* ptr_loc) {
 76     mark_pointer((address*)ptr_loc);
 77   }
 78 
 79   template <typename T>
 80   static void set_and_mark_pointer(T* ptr_loc, T ptr_value) {
 81     *ptr_loc = ptr_value;
 82     mark_pointer(ptr_loc);
 83   }
 84 
 85   static CHeapBitMap* ptrmap() {
 86     return _ptrmap;
 87   }
 88 
 89   static CHeapBitMap* rw_ptrmap() {
 90     return _rw_ptrmap;
 91   }
 92 
 93   static CHeapBitMap* ro_ptrmap() {
 94     return _ro_ptrmap;
 95   }
 96 




 97   static void reset_map_and_vs() {
 98     _ptrmap = nullptr;
 99     _rw_ptrmap = nullptr;
100     _ro_ptrmap = nullptr;

101     _vs = nullptr;
102   }
103 };
104 
105 // SharedDataRelocator is used to shift pointers in the CDS archive.
106 //
107 // The CDS archive is basically a contiguous block of memory (divided into several regions)
108 // that contains multiple objects. The objects may contain direct pointers that point to other objects
109 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
110 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
111 //
112 // The contents of the archive assumes that it's mapped at the default SharedBaseAddress (e.g. 0x800000000).
113 // If the archive ends up being mapped at a different address (e.g. 0x810000000), SharedDataRelocator
114 // is used to shift each marked pointer by a delta (0x10000000 in this example), so that it points to
115 // the actually mapped location of the target object.
116 class SharedDataRelocator: public BitMapClosure {
117   // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; }
118 
119   // Patch all pointers within this region that are marked.
120   address* _patch_base;

272   char* region_top() { return nullptr; }
273 };
274 
275 class ArchiveUtils {
276   template <typename T> static Array<T>* archive_non_ptr_array(GrowableArray<T>* tmp_array);
277   template <typename T> static Array<T>* archive_ptr_array(GrowableArray<T>* tmp_array);
278 
279 public:
280   static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
281   static bool has_aot_initialized_mirror(InstanceKlass* src_ik);
282 
283   template <typename T, ENABLE_IF(!std::is_pointer<T>::value)>
284   static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
285     return archive_non_ptr_array(tmp_array);
286   }
287 
288   template <typename T, ENABLE_IF(std::is_pointer<T>::value)>
289   static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
290     return archive_ptr_array(tmp_array);
291   }






292 };
293 
294 class HeapRootSegments {
295 private:
296   size_t _base_offset;
297   size_t _count;
298   int _roots_count;
299   size_t _max_size_in_bytes;
300   int _max_size_in_elems;
301 
302 public:
303   size_t base_offset() { return _base_offset; }
304   size_t count() { return _count; }
305   int roots_count() { return _roots_count; }
306   size_t max_size_in_bytes() { return _max_size_in_bytes; }
307   int max_size_in_elems() { return _max_size_in_elems; }
308 
309   size_t size_in_bytes(size_t seg_idx);
310   int size_in_elems(size_t seg_idx);
311   size_t segment_offset(size_t seg_idx);

 37 #include "utilities/bitMap.hpp"
 38 #include "utilities/exceptions.hpp"
 39 #include "utilities/macros.hpp"
 40 
 41 class BootstrapInfo;
 42 class DumpAllocStats;
 43 class ReservedSpace;
 44 class VirtualSpace;
 45 
 46 template<class E> class Array;
 47 template<class E> class GrowableArray;
 48 
 49 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
 50 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
 51 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
 52 // fixed, but _ptr_end can be expanded as more objects are dumped.
 53 class ArchivePtrMarker : AllStatic {
 54   static CHeapBitMap*  _ptrmap;
 55   static CHeapBitMap*  _rw_ptrmap;
 56   static CHeapBitMap*  _ro_ptrmap;
 57   static CHeapBitMap*  _ac_ptrmap;
 58   static VirtualSpace* _vs;
 59 
 60   // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
 61   // avoid unintentional copy operations after the bitmap has been finalized and written.
 62   static bool         _compacted;
 63 
 64   static address* ptr_base() { return (address*)_vs->low();  } // committed lower bound (inclusive)
 65   static address* ptr_end()  { return (address*)_vs->high(); } // committed upper bound (exclusive)
 66 
 67 public:
 68   static void initialize(CHeapBitMap* ptrmap, VirtualSpace* vs);
 69   static void initialize_rw_ro_ac_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, CHeapBitMap* ac_ptrmap);
 70   static void mark_pointer(address* ptr_loc);
 71   static void clear_pointer(address* ptr_loc);
 72   static void compact(address relocatable_base, address relocatable_end);
 73   static void compact(size_t max_non_null_offset);
 74 
 75   template <typename T>
 76   static void mark_pointer(T* ptr_loc) {
 77     mark_pointer((address*)ptr_loc);
 78   }
 79 
 80   template <typename T>
 81   static void set_and_mark_pointer(T* ptr_loc, T ptr_value) {
 82     *ptr_loc = ptr_value;
 83     mark_pointer(ptr_loc);
 84   }
 85 
 86   static CHeapBitMap* ptrmap() {
 87     return _ptrmap;
 88   }
 89 
 90   static CHeapBitMap* rw_ptrmap() {
 91     return _rw_ptrmap;
 92   }
 93 
 94   static CHeapBitMap* ro_ptrmap() {
 95     return _ro_ptrmap;
 96   }
 97 
 98   static CHeapBitMap* ac_ptrmap() {
 99     return _ac_ptrmap;
100   }
101 
102   static void reset_map_and_vs() {
103     _ptrmap = nullptr;
104     _rw_ptrmap = nullptr;
105     _ro_ptrmap = nullptr;
106     _ac_ptrmap = nullptr;
107     _vs = nullptr;
108   }
109 };
110 
111 // SharedDataRelocator is used to shift pointers in the CDS archive.
112 //
113 // The CDS archive is basically a contiguous block of memory (divided into several regions)
114 // that contains multiple objects. The objects may contain direct pointers that point to other objects
115 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
116 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
117 //
118 // The contents of the archive assumes that it's mapped at the default SharedBaseAddress (e.g. 0x800000000).
119 // If the archive ends up being mapped at a different address (e.g. 0x810000000), SharedDataRelocator
120 // is used to shift each marked pointer by a delta (0x10000000 in this example), so that it points to
121 // the actually mapped location of the target object.
122 class SharedDataRelocator: public BitMapClosure {
123   // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; }
124 
125   // Patch all pointers within this region that are marked.
126   address* _patch_base;

278   char* region_top() { return nullptr; }
279 };
280 
281 class ArchiveUtils {
282   template <typename T> static Array<T>* archive_non_ptr_array(GrowableArray<T>* tmp_array);
283   template <typename T> static Array<T>* archive_ptr_array(GrowableArray<T>* tmp_array);
284 
285 public:
286   static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
287   static bool has_aot_initialized_mirror(InstanceKlass* src_ik);
288 
289   template <typename T, ENABLE_IF(!std::is_pointer<T>::value)>
290   static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
291     return archive_non_ptr_array(tmp_array);
292   }
293 
294   template <typename T, ENABLE_IF(std::is_pointer<T>::value)>
295   static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
296     return archive_ptr_array(tmp_array);
297   }
298 
299   static const char* builtin_loader_name_or_null(oop loader); // "boot", "platform", "app", or nullptr
300   static const char* builtin_loader_name(oop loader); // "boot", "platform", or "app". Asserts if not a built-in-loader.
301 
302   static bool builtin_loader_from_type(const char* loader_type, oop* value_ret);
303   static oop builtin_loader_from_type(int loader_type);
304 };
305 
306 class HeapRootSegments {
307 private:
308   size_t _base_offset;
309   size_t _count;
310   int _roots_count;
311   size_t _max_size_in_bytes;
312   int _max_size_in_elems;
313 
314 public:
315   size_t base_offset() { return _base_offset; }
316   size_t count() { return _count; }
317   int roots_count() { return _roots_count; }
318   size_t max_size_in_bytes() { return _max_size_in_bytes; }
319   int max_size_in_elems() { return _max_size_in_elems; }
320 
321   size_t size_in_bytes(size_t seg_idx);
322   int size_in_elems(size_t seg_idx);
323   size_t segment_offset(size_t seg_idx);
< prev index next >