src/share/vm/gc_implementation/g1/g1CodeCacheRemSet.hpp

changeset 7208
7baf47cb97cb
parent 6992
2c6ef90f030a
equal deleted inserted replaced
7207:152cf4afc11f 7208:7baf47cb97cb
24 24
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP
27 27
28 #include "memory/allocation.hpp" 28 #include "memory/allocation.hpp"
29 #include "memory/freeList.hpp"
30 #include "runtime/globals.hpp"
31 29
32 class CodeBlobClosure; 30 class CodeBlobClosure;
33 31 class CodeRootSetTable;
34 // The elements of the G1CodeRootChunk is either: 32 class HeapRegion;
35 // 1) nmethod pointers 33 class nmethod;
36 // 2) nodes in an internally chained free list
37 typedef union {
38 nmethod* _nmethod;
39 void* _link;
40 } NmethodOrLink;
41
42 class G1CodeRootChunk : public CHeapObj<mtGC> {
43 private:
44 static const int NUM_ENTRIES = 32;
45 public:
46 G1CodeRootChunk* _next;
47 G1CodeRootChunk* _prev;
48
49 NmethodOrLink* _top;
50 // First free position within the chunk.
51 volatile NmethodOrLink* _free;
52
53 NmethodOrLink _data[NUM_ENTRIES];
54
55 NmethodOrLink* bottom() const {
56 return (NmethodOrLink*) &(_data[0]);
57 }
58
59 NmethodOrLink* end() const {
60 return (NmethodOrLink*) &(_data[NUM_ENTRIES]);
61 }
62
63 bool is_link(NmethodOrLink* nmethod_or_link) {
64 return nmethod_or_link->_link == NULL ||
65 (bottom() <= nmethod_or_link->_link
66 && nmethod_or_link->_link < end());
67 }
68
69 bool is_nmethod(NmethodOrLink* nmethod_or_link) {
70 return !is_link(nmethod_or_link);
71 }
72
73 public:
74 G1CodeRootChunk();
75 ~G1CodeRootChunk() {}
76
77 static size_t word_size() { return (size_t)(align_size_up_(sizeof(G1CodeRootChunk), HeapWordSize) / HeapWordSize); }
78
79 // FreeList "interface" methods
80
81 G1CodeRootChunk* next() const { return _next; }
82 G1CodeRootChunk* prev() const { return _prev; }
83 void set_next(G1CodeRootChunk* v) { _next = v; assert(v != this, "Boom");}
84 void set_prev(G1CodeRootChunk* v) { _prev = v; assert(v != this, "Boom");}
85 void clear_next() { set_next(NULL); }
86 void clear_prev() { set_prev(NULL); }
87
88 size_t size() const { return word_size(); }
89
90 void link_next(G1CodeRootChunk* ptr) { set_next(ptr); }
91 void link_prev(G1CodeRootChunk* ptr) { set_prev(ptr); }
92 void link_after(G1CodeRootChunk* ptr) {
93 link_next(ptr);
94 if (ptr != NULL) ptr->link_prev((G1CodeRootChunk*)this);
95 }
96
97 bool is_free() { return true; }
98
99 // New G1CodeRootChunk routines
100
101 void reset();
102
103 bool is_empty() const {
104 return _top == bottom();
105 }
106
107 bool is_full() const {
108 return _top == end() && _free == NULL;
109 }
110
111 bool contains(nmethod* method) {
112 NmethodOrLink* cur = bottom();
113 while (cur != _top) {
114 if (cur->_nmethod == method) return true;
115 cur++;
116 }
117 return false;
118 }
119
120 bool add(nmethod* method) {
121 if (is_full()) {
122 return false;
123 }
124
125 if (_free != NULL) {
126 // Take from internally chained free list
127 NmethodOrLink* first_free = (NmethodOrLink*)_free;
128 _free = (NmethodOrLink*)_free->_link;
129 first_free->_nmethod = method;
130 } else {
131 // Take from top.
132 _top->_nmethod = method;
133 _top++;
134 }
135
136 return true;
137 }
138
139 bool remove_lock_free(nmethod* method);
140
141 void nmethods_do(CodeBlobClosure* blk);
142
143 nmethod* pop() {
144 if (_free != NULL) {
145 // Kill the free list.
146 _free = NULL;
147 }
148
149 while (!is_empty()) {
150 _top--;
151 if (is_nmethod(_top)) {
152 return _top->_nmethod;
153 }
154 }
155
156 return NULL;
157 }
158 };
159
160 // Manages free chunks.
161 class G1CodeRootChunkManager VALUE_OBJ_CLASS_SPEC {
162 private:
163 // Global free chunk list management
164 FreeList<G1CodeRootChunk> _free_list;
165 // Total number of chunks handed out
166 size_t _num_chunks_handed_out;
167
168 public:
169 G1CodeRootChunkManager();
170
171 G1CodeRootChunk* new_chunk();
172 void free_chunk(G1CodeRootChunk* chunk);
173 // Free all elements of the given list.
174 void free_all_chunks(FreeList<G1CodeRootChunk>* list);
175
176 void initialize();
177 void purge_chunks(size_t keep_ratio);
178
179 static size_t static_mem_size();
180 size_t fl_mem_size();
181
182 #ifndef PRODUCT
183 size_t num_chunks_handed_out() const;
184 size_t num_free_chunks() const;
185 #endif
186 };
187 34
188 // Implements storage for a set of code roots. 35 // Implements storage for a set of code roots.
189 // All methods that modify the set are not thread-safe except if otherwise noted. 36 // All methods that modify the set are not thread-safe except if otherwise noted.
190 class G1CodeRootSet VALUE_OBJ_CLASS_SPEC { 37 class G1CodeRootSet VALUE_OBJ_CLASS_SPEC {
38 friend class G1CodeRootSetTest;
191 private: 39 private:
192 // Global default free chunk manager instance.
193 static G1CodeRootChunkManager _default_chunk_manager;
194 40
195 G1CodeRootChunk* new_chunk() { return _manager->new_chunk(); } 41 const static size_t SmallSize = 32;
196 void free_chunk(G1CodeRootChunk* chunk) { _manager->free_chunk(chunk); } 42 const static size_t Threshold = 24;
197 // Free all elements of the given list. 43 const static size_t LargeSize = 512;
198 void free_all_chunks(FreeList<G1CodeRootChunk>* list) { _manager->free_all_chunks(list); }
199 44
200 // Return the chunk that contains the given nmethod, NULL otherwise. 45 CodeRootSetTable* _table;
201 // Scans the list of chunks backwards, as this method is used to add new 46 CodeRootSetTable* load_acquire_table();
202 // entries, which are typically added in bulk for a single nmethod.
203 G1CodeRootChunk* find(nmethod* method);
204 void free(G1CodeRootChunk* chunk);
205 47
206 size_t _length; 48 size_t _length;
207 FreeList<G1CodeRootChunk> _list; 49
208 G1CodeRootChunkManager* _manager; 50 void move_to_large();
51 void allocate_small_table();
209 52
210 public: 53 public:
211 // If an instance is initialized with a chunk manager of NULL, use the global 54 G1CodeRootSet() : _table(NULL), _length(0) {}
212 // default one.
213 G1CodeRootSet(G1CodeRootChunkManager* manager = NULL);
214 ~G1CodeRootSet(); 55 ~G1CodeRootSet();
215 56
216 static void purge_chunks(size_t keep_ratio); 57 static void purge();
217 58
218 static size_t free_chunks_static_mem_size(); 59 static size_t static_mem_size();
219 static size_t free_chunks_mem_size();
220 60
221 // Search for the code blob from the recently allocated ones to find duplicates more quickly, as this
222 // method is likely to be repeatedly called with the same nmethod.
223 void add(nmethod* method); 61 void add(nmethod* method);
224 62
225 void remove_lock_free(nmethod* method); 63 bool remove(nmethod* method);
226 nmethod* pop();
227 64
65 // Safe to call without synchronization, but may return false negatives.
228 bool contains(nmethod* method); 66 bool contains(nmethod* method);
229 67
230 void clear(); 68 void clear();
231 69
232 void nmethods_do(CodeBlobClosure* blk) const; 70 void nmethods_do(CodeBlobClosure* blk) const;
233 71
234 bool is_empty() { return length() == 0; } 72 // Remove all nmethods which no longer contain pointers into our "owner" region
73 void clean(HeapRegion* owner);
74
75 bool is_empty() {
76 bool empty = length() == 0;
77 assert(empty == (_table == NULL), "is empty only if table is deallocated");
78 return empty;
79 }
235 80
236 // Length in elements 81 // Length in elements
237 size_t length() const { return _length; } 82 size_t length() const { return _length; }
238 83
239 // Static data memory size in bytes of this set.
240 static size_t static_mem_size();
241 // Memory size in bytes taken by this set. 84 // Memory size in bytes taken by this set.
242 size_t mem_size(); 85 size_t mem_size();
243 86
244 static void test() PRODUCT_RETURN;
245 }; 87 };
246 88
247 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP 89 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP

mercurial