Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/ptrQueue.hpp @ 453:c96030fff130
6684579: SoftReference processing can be made more efficient
Summary: For current soft-ref clearing policies, we can decide at marking time if a soft-reference will definitely not be cleared, postponing the decision of whether it will definitely be cleared to the final reference processing phase. This can be especially beneficial in the case of concurrent collectors where the marking is usually concurrent but reference processing is usually not.
Reviewed-by: jmasa
author | ysr |
---|---|
date | Thu, 20 Nov 2008 16:56:09 -0800 |
parents | da9cb4e97a5f |
children | ad8c8ca4ab0f |
rev | line source |
---|---|
342 | 1 /* |
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // There are various techniques that require threads to be able to log | |
26 // addresses. For example, a generational write barrier might log | |
27 // the addresses of modified old-generation objects. This type supports | |
28 // this operation. | |
29 | |
30 class PtrQueueSet; | |
31 | |
32 class PtrQueue: public CHeapObj { | |
33 | |
34 protected: | |
35 // The ptr queue set to which this queue belongs. | |
36 PtrQueueSet* _qset; | |
37 | |
38 // Whether updates should be logged. | |
39 bool _active; | |
40 | |
41 // The buffer. | |
42 void** _buf; | |
43 // The index at which an object was last enqueued. Starts at "_sz" | |
44 // (indicating an empty buffer) and goes towards zero. | |
45 size_t _index; | |
46 | |
47 // The size of the buffer. | |
48 size_t _sz; | |
49 | |
50 // If true, the queue is permanent, and doesn't need to deallocate | |
51 // its buffer in the destructor (since that obtains a lock which may not | |
52 // be legally locked by then. | |
53 bool _perm; | |
54 | |
55 // If there is a lock associated with this buffer, this is that lock. | |
56 Mutex* _lock; | |
57 | |
58 PtrQueueSet* qset() { return _qset; } | |
59 | |
60 public: | |
61 // Initialize this queue to contain a null buffer, and be part of the | |
62 // given PtrQueueSet. | |
63 PtrQueue(PtrQueueSet*, bool perm = false); | |
64 // Release any contained resources. | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
342
diff
changeset
|
65 void flush(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
342
diff
changeset
|
66 // Calls flush() when destroyed. |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
342
diff
changeset
|
67 ~PtrQueue() { flush(); } |
342 | 68 |
69 // Associate a lock with a ptr queue. | |
70 void set_lock(Mutex* lock) { _lock = lock; } | |
71 | |
72 void reset() { if (_buf != NULL) _index = _sz; } | |
73 | |
74 // Enqueues the given "obj". | |
75 void enqueue(void* ptr) { | |
76 if (!_active) return; | |
77 else enqueue_known_active(ptr); | |
78 } | |
79 | |
80 inline void handle_zero_index(); | |
81 void locking_enqueue_completed_buffer(void** buf); | |
82 | |
83 void enqueue_known_active(void* ptr); | |
84 | |
85 size_t size() { | |
86 assert(_sz >= _index, "Invariant."); | |
87 return _buf == NULL ? 0 : _sz - _index; | |
88 } | |
89 | |
90 // Set the "active" property of the queue to "b". An enqueue to an | |
91 // inactive thread is a no-op. Setting a queue to inactive resets its | |
92 // log to the empty state. | |
93 void set_active(bool b) { | |
94 _active = b; | |
95 if (!b && _buf != NULL) { | |
96 _index = _sz; | |
97 } else if (b && _buf != NULL) { | |
98 assert(_index == _sz, "invariant: queues are empty when activated."); | |
99 } | |
100 } | |
101 | |
102 static int byte_index_to_index(int ind) { | |
103 assert((ind % oopSize) == 0, "Invariant."); | |
104 return ind / oopSize; | |
105 } | |
106 | |
107 static int index_to_byte_index(int byte_ind) { | |
108 return byte_ind * oopSize; | |
109 } | |
110 | |
111 // To support compiler. | |
112 static ByteSize byte_offset_of_index() { | |
113 return byte_offset_of(PtrQueue, _index); | |
114 } | |
115 static ByteSize byte_width_of_index() { return in_ByteSize(sizeof(size_t)); } | |
116 | |
117 static ByteSize byte_offset_of_buf() { | |
118 return byte_offset_of(PtrQueue, _buf); | |
119 } | |
120 static ByteSize byte_width_of_buf() { return in_ByteSize(sizeof(void*)); } | |
121 | |
122 static ByteSize byte_offset_of_active() { | |
123 return byte_offset_of(PtrQueue, _active); | |
124 } | |
125 static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); } | |
126 | |
127 }; | |
128 | |
129 // A PtrQueueSet represents resources common to a set of pointer queues. | |
130 // In particular, the individual queues allocate buffers from this shared | |
131 // set, and return completed buffers to the set. | |
132 // All these variables are are protected by the TLOQ_CBL_mon. XXX ??? | |
133 class PtrQueueSet: public CHeapObj { | |
134 | |
135 protected: | |
136 | |
137 class CompletedBufferNode: public CHeapObj { | |
138 public: | |
139 void** buf; | |
140 size_t index; | |
141 CompletedBufferNode* next; | |
142 CompletedBufferNode() : buf(NULL), | |
143 index(0), next(NULL){ } | |
144 }; | |
145 | |
146 Monitor* _cbl_mon; // Protects the fields below. | |
147 CompletedBufferNode* _completed_buffers_head; | |
148 CompletedBufferNode* _completed_buffers_tail; | |
149 size_t _n_completed_buffers; | |
150 size_t _process_completed_threshold; | |
151 volatile bool _process_completed; | |
152 | |
153 // This (and the interpretation of the first element as a "next" | |
154 // pointer) are protected by the TLOQ_FL_lock. | |
155 Mutex* _fl_lock; | |
156 void** _buf_free_list; | |
157 size_t _buf_free_list_sz; | |
158 | |
159 // The size of all buffers in the set. | |
160 size_t _sz; | |
161 | |
162 bool _all_active; | |
163 | |
164 // If true, notify_all on _cbl_mon when the threshold is reached. | |
165 bool _notify_when_complete; | |
166 | |
167 // Maximum number of elements allowed on completed queue: after that, | |
168 // enqueuer does the work itself. Zero indicates no maximum. | |
169 int _max_completed_queue; | |
170 | |
171 int completed_buffers_list_length(); | |
172 void assert_completed_buffer_list_len_correct_locked(); | |
173 void assert_completed_buffer_list_len_correct(); | |
174 | |
175 protected: | |
176 // A mutator thread does the the work of processing a buffer. | |
177 // Returns "true" iff the work is complete (and the buffer may be | |
178 // deallocated). | |
179 virtual bool mut_process_buffer(void** buf) { | |
180 ShouldNotReachHere(); | |
181 return false; | |
182 } | |
183 | |
184 public: | |
185 // Create an empty ptr queue set. | |
186 PtrQueueSet(bool notify_when_complete = false); | |
187 | |
188 // Because of init-order concerns, we can't pass these as constructor | |
189 // arguments. | |
190 void initialize(Monitor* cbl_mon, Mutex* fl_lock, | |
191 int max_completed_queue = 0) { | |
192 _max_completed_queue = max_completed_queue; | |
193 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); | |
194 _cbl_mon = cbl_mon; _fl_lock = fl_lock; | |
195 } | |
196 | |
197 // Return an empty oop array of size _sz (required to be non-zero). | |
198 void** allocate_buffer(); | |
199 | |
200 // Return an empty buffer to the free list. The "buf" argument is | |
201 // required to be a pointer to the head of an array of length "_sz". | |
202 void deallocate_buffer(void** buf); | |
203 | |
204 // Declares that "buf" is a complete buffer. | |
205 void enqueue_complete_buffer(void** buf, size_t index = 0, | |
206 bool ignore_max_completed = false); | |
207 | |
208 bool completed_buffers_exist_dirty() { | |
209 return _n_completed_buffers > 0; | |
210 } | |
211 | |
212 bool process_completed_buffers() { return _process_completed; } | |
213 | |
214 bool active() { return _all_active; } | |
215 | |
216 // Set the buffer size. Should be called before any "enqueue" operation | |
217 // can be called. And should only be called once. | |
218 void set_buffer_size(size_t sz); | |
219 | |
220 // Get the buffer size. | |
221 size_t buffer_size() { return _sz; } | |
222 | |
223 // Set the number of completed buffers that triggers log processing. | |
224 void set_process_completed_threshold(size_t sz); | |
225 | |
226 // Must only be called at a safe point. Indicates that the buffer free | |
227 // list size may be reduced, if that is deemed desirable. | |
228 void reduce_free_list(); | |
229 | |
230 size_t completed_buffers_num() { return _n_completed_buffers; } | |
231 }; |