< prev index next >

src/hotspot/share/cds/archiveUtils.hpp

Print this page

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

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




 92   static void reset_map_and_vs() {
 93     _ptrmap = nullptr;
 94     _rw_ptrmap = nullptr;
 95     _ro_ptrmap = nullptr;

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

242 public:
243   ReadClosure(intptr_t** ptr_array, intptr_t base_address) :
244     _ptr_array(ptr_array), _base_address(base_address) {}
245 
246   void do_ptr(void** p);
247   void do_u4(u4* p);
248   void do_int(int* p);
249   void do_bool(bool *p);
250   void do_tag(int tag);
251   bool reading() const { return true; }
252   char* region_top() { return nullptr; }
253 };
254 
255 class ArchiveUtils {
256 public:
257   static const uintx MAX_SHARED_DELTA = 0x7FFFFFFF;
258   static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
259   static bool has_aot_initialized_mirror(InstanceKlass* src_ik);
260   template <typename T> static Array<T>* archive_array(GrowableArray<T>* tmp_array);
261 






262   // offset must represent an object of type T in the mapped shared space. Return
263   // a direct pointer to this object.
264   template <typename T> T static from_offset(u4 offset) {
265     T p = (T)(SharedBaseAddress + offset);
266     assert(Metaspace::is_in_shared_metaspace(p), "must be");
267     return p;
268   }
269 
270   // p must be an archived object. Get its offset from SharedBaseAddress
271   template <typename T> static u4 to_offset(T p) {
272     uintx pn = (uintx)p;
273     uintx base = (uintx)SharedBaseAddress;
274     assert(Metaspace::is_in_shared_metaspace(p), "must be");
275     assert(pn > base, "sanity"); // No valid object is stored at 0 offset from SharedBaseAddress
276     uintx offset = pn - base;
277     assert(offset <= MAX_SHARED_DELTA, "range check");
278     return static_cast<u4>(offset);
279   }
280 };
281 

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

248 public:
249   ReadClosure(intptr_t** ptr_array, intptr_t base_address) :
250     _ptr_array(ptr_array), _base_address(base_address) {}
251 
252   void do_ptr(void** p);
253   void do_u4(u4* p);
254   void do_int(int* p);
255   void do_bool(bool *p);
256   void do_tag(int tag);
257   bool reading() const { return true; }
258   char* region_top() { return nullptr; }
259 };
260 
261 class ArchiveUtils {
262 public:
263   static const uintx MAX_SHARED_DELTA = 0x7FFFFFFF;
264   static void log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) NOT_CDS_RETURN;
265   static bool has_aot_initialized_mirror(InstanceKlass* src_ik);
266   template <typename T> static Array<T>* archive_array(GrowableArray<T>* tmp_array);
267 
268   static const char* builtin_loader_name_or_null(oop loader); // "boot", "platform", "app", or nullptr
269   static const char* builtin_loader_name(oop loader); // "boot", "platform", or "app". Asserts if not a built-in-loader.
270 
271   static bool builtin_loader_from_type(const char* loader_type, oop* value_ret);
272   static oop builtin_loader_from_type(int loader_type);
273 
274   // offset must represent an object of type T in the mapped shared space. Return
275   // a direct pointer to this object.
276   template <typename T> T static from_offset(u4 offset) {
277     T p = (T)(SharedBaseAddress + offset);
278     assert(Metaspace::is_in_shared_metaspace(p), "must be");
279     return p;
280   }
281 
282   // p must be an archived object. Get its offset from SharedBaseAddress
283   template <typename T> static u4 to_offset(T p) {
284     uintx pn = (uintx)p;
285     uintx base = (uintx)SharedBaseAddress;
286     assert(Metaspace::is_in_shared_metaspace(p), "must be");
287     assert(pn > base, "sanity"); // No valid object is stored at 0 offset from SharedBaseAddress
288     uintx offset = pn - base;
289     assert(offset <= MAX_SHARED_DELTA, "range check");
290     return static_cast<u4>(offset);
291   }
292 };
293 
< prev index next >