24 |
24 |
25 #ifndef SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |
25 #ifndef SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |
26 #define SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |
26 #define SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |
27 |
27 |
28 #include "memory/allocation.hpp" |
28 #include "memory/allocation.hpp" |
|
29 #include "oops/oop.hpp" |
29 #include "oops/oopsHierarchy.hpp" |
30 #include "oops/oopsHierarchy.hpp" |
30 #include "utilities/bitMap.inline.hpp" |
31 #include "utilities/bitMap.hpp" |
|
32 #include "utilities/hashtable.hpp" |
31 |
33 |
32 class JfrVirtualMemory; |
34 class JfrVirtualMemory; |
33 class MemRegion; |
35 class MemRegion; |
34 |
36 |
35 class BitSet : public CHeapObj<mtTracing> { |
37 class BitSet : public CHeapObj<mtTracing> { |
36 private: |
38 const static size_t _bitmap_granularity_shift = 26; // 64M |
37 JfrVirtualMemory* _vmm; |
39 const static size_t _bitmap_granularity_size = (size_t)1 << _bitmap_granularity_shift; |
38 const HeapWord* const _region_start; |
40 const static size_t _bitmap_granularity_mask = _bitmap_granularity_size - 1; |
39 BitMapView _bits; |
41 |
40 const size_t _region_size; |
42 class BitMapFragment; |
|
43 |
|
44 class BitMapFragmentTable : public BasicHashtable<mtTracing> { |
|
45 class Entry : public BasicHashtableEntry<mtTracing> { |
|
46 public: |
|
47 uintptr_t _key; |
|
48 CHeapBitMap* _value; |
|
49 |
|
50 Entry* next() { |
|
51 return (Entry*)BasicHashtableEntry<mtTracing>::next(); |
|
52 } |
|
53 }; |
|
54 |
|
55 protected: |
|
56 Entry* bucket(int i) const; |
|
57 |
|
58 Entry* new_entry(unsigned int hashValue, uintptr_t key, CHeapBitMap* value); |
|
59 |
|
60 unsigned hash_segment(uintptr_t key) { |
|
61 unsigned hash = (unsigned)key; |
|
62 return hash ^ (hash >> 3); |
|
63 } |
|
64 |
|
65 unsigned hash_to_index(unsigned hash) { |
|
66 return hash & (BasicHashtable<mtTracing>::table_size() - 1); |
|
67 } |
|
68 |
|
69 public: |
|
70 BitMapFragmentTable(int table_size) : BasicHashtable<mtTracing>(table_size, sizeof(Entry)) {} |
|
71 void add(uintptr_t key, CHeapBitMap* value); |
|
72 CHeapBitMap** lookup(uintptr_t key); |
|
73 }; |
|
74 |
|
75 CHeapBitMap* get_fragment_bits(uintptr_t addr); |
|
76 |
|
77 BitMapFragmentTable _bitmap_fragments; |
|
78 BitMapFragment* _fragment_list; |
|
79 CHeapBitMap* _last_fragment_bits; |
|
80 uintptr_t _last_fragment_granule; |
41 |
81 |
42 public: |
82 public: |
43 BitSet(const MemRegion& covered_region); |
83 BitSet(); |
44 ~BitSet(); |
84 ~BitSet(); |
45 |
85 |
46 bool initialize(); |
86 BitMap::idx_t addr_to_bit(uintptr_t addr) const; |
47 |
87 |
48 BitMap::idx_t mark_obj(const HeapWord* addr) { |
88 void mark_obj(uintptr_t addr); |
49 const BitMap::idx_t bit = addr_to_bit(addr); |
89 |
50 _bits.set_bit(bit); |
90 void mark_obj(oop obj) { |
51 return bit; |
91 return mark_obj(cast_from_oop<uintptr_t>(obj)); |
52 } |
92 } |
53 |
93 |
54 BitMap::idx_t mark_obj(oop obj) { |
94 bool is_marked(uintptr_t addr); |
55 return mark_obj((HeapWord*)obj); |
95 |
|
96 bool is_marked(oop obj) { |
|
97 return is_marked(cast_from_oop<uintptr_t>(obj)); |
|
98 } |
|
99 }; |
|
100 |
|
101 class BitSet::BitMapFragment : public CHeapObj<mtTracing> { |
|
102 CHeapBitMap _bits; |
|
103 BitMapFragment* _next; |
|
104 |
|
105 public: |
|
106 BitMapFragment(uintptr_t granule, BitMapFragment* next); |
|
107 |
|
108 BitMapFragment* next() const { |
|
109 return _next; |
56 } |
110 } |
57 |
111 |
58 bool is_marked(const HeapWord* addr) const { |
112 CHeapBitMap* bits() { |
59 return is_marked(addr_to_bit(addr)); |
113 return &_bits; |
60 } |
|
61 |
|
62 bool is_marked(oop obj) const { |
|
63 return is_marked((HeapWord*)obj); |
|
64 } |
|
65 |
|
66 BitMap::idx_t size() const { |
|
67 return _bits.size(); |
|
68 } |
|
69 |
|
70 BitMap::idx_t addr_to_bit(const HeapWord* addr) const { |
|
71 return pointer_delta(addr, _region_start) >> LogMinObjAlignment; |
|
72 } |
|
73 |
|
74 bool is_marked(const BitMap::idx_t bit) const { |
|
75 return _bits.at(bit); |
|
76 } |
114 } |
77 }; |
115 }; |
78 |
116 |
79 #endif // SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |
117 #endif // SHARE_JFR_LEAKPROFILER_CHAINS_BITSET_HPP |