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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/satbQueue.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/sharedHeap.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/thread.hpp"
32
33 // This method removes entries from an SATB buffer that will not be
34 // useful to the concurrent marking threads. An entry is removed if it
35 // satisfies one of the following conditions:
36 //
37 // * it points to an object outside the G1 heap (G1's concurrent
38 // marking only visits objects inside the G1 heap),
39 // * it points to an object that has been allocated since marking
40 // started (according to SATB those objects do not need to be
41 // visited during marking), or
42 // * it points to an object that has already been marked (no need to
43 // process it again).
44 //
45 // The rest of the entries will be retained and are compacted towards
46 // the top of the buffer. If with this filtering we clear a large
47 // enough chunk of the buffer we can re-use it (instead of enqueueing
48 // it) and we can just allow the mutator to carry on executing.
49
50 bool ObjPtrQueue::should_enqueue_buffer() {
51 assert(_lock == NULL || _lock->owned_by_self(),
235 assert(ParallelGCThreads > 0 && _par_closures != NULL, "Precondition");
236 _par_closures[i] = par_closure;
237 }
238
239 void SATBMarkQueueSet::iterate_closure_all_threads() {
240 for(JavaThread* t = Threads::first(); t; t = t->next()) {
241 t->satb_mark_queue().apply_closure(_closure);
242 }
243 shared_satb_queue()->apply_closure(_closure);
244 }
245
246 void SATBMarkQueueSet::par_iterate_closure_all_threads(int worker) {
247 SharedHeap* sh = SharedHeap::heap();
248 int parity = sh->strong_roots_parity();
249
250 for(JavaThread* t = Threads::first(); t; t = t->next()) {
251 if (t->claim_oops_do(true, parity)) {
252 t->satb_mark_queue().apply_closure(_par_closures[worker]);
253 }
254 }
255 // We'll have worker 0 do this one.
256 if (worker == 0) {
257 shared_satb_queue()->apply_closure(_par_closures[0]);
258 }
259 }
260
261 bool SATBMarkQueueSet::apply_closure_to_completed_buffer_work(bool par,
262 int worker) {
263 BufferNode* nd = NULL;
264 {
265 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
266 if (_completed_buffers_head != NULL) {
267 nd = _completed_buffers_head;
268 _completed_buffers_head = nd->next();
269 if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
270 _n_completed_buffers--;
271 if (_n_completed_buffers == 0) _process_completed = false;
272 }
273 }
274 ObjectClosure* cl = (par ? _par_closures[worker] : _closure);
275 if (nd != NULL) {
276 void **buf = BufferNode::make_buffer_from_node(nd);
277 ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz);
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/satbQueue.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/sharedHeap.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/thread.hpp"
32 #include "runtime/vmThread.hpp"
33
34 // This method removes entries from an SATB buffer that will not be
35 // useful to the concurrent marking threads. An entry is removed if it
36 // satisfies one of the following conditions:
37 //
38 // * it points to an object outside the G1 heap (G1's concurrent
39 // marking only visits objects inside the G1 heap),
40 // * it points to an object that has been allocated since marking
41 // started (according to SATB those objects do not need to be
42 // visited during marking), or
43 // * it points to an object that has already been marked (no need to
44 // process it again).
45 //
46 // The rest of the entries will be retained and are compacted towards
47 // the top of the buffer. If with this filtering we clear a large
48 // enough chunk of the buffer we can re-use it (instead of enqueueing
49 // it) and we can just allow the mutator to carry on executing.
50
51 bool ObjPtrQueue::should_enqueue_buffer() {
52 assert(_lock == NULL || _lock->owned_by_self(),
236 assert(ParallelGCThreads > 0 && _par_closures != NULL, "Precondition");
237 _par_closures[i] = par_closure;
238 }
239
240 void SATBMarkQueueSet::iterate_closure_all_threads() {
241 for(JavaThread* t = Threads::first(); t; t = t->next()) {
242 t->satb_mark_queue().apply_closure(_closure);
243 }
244 shared_satb_queue()->apply_closure(_closure);
245 }
246
247 void SATBMarkQueueSet::par_iterate_closure_all_threads(int worker) {
248 SharedHeap* sh = SharedHeap::heap();
249 int parity = sh->strong_roots_parity();
250
251 for(JavaThread* t = Threads::first(); t; t = t->next()) {
252 if (t->claim_oops_do(true, parity)) {
253 t->satb_mark_queue().apply_closure(_par_closures[worker]);
254 }
255 }
256
257 // We also need to claim the VMThread so that its parity is updated
258 // otherwise the next call to Thread::possibly_parallel_oops_do inside
259 // a StrongRootsScope might skip the VMThread because it has a stale
260 // parity that matches the parity set by the StrongRootsScope
261 //
262 // Whichever worker succeeds in claiming the VMThread gets to do
263 // the shared queue.
264
265 VMThread* vmt = VMThread::vm_thread();
266 if (vmt->claim_oops_do(true, parity)) {
267 shared_satb_queue()->apply_closure(_par_closures[worker]);
268 }
269 }
270
271 bool SATBMarkQueueSet::apply_closure_to_completed_buffer_work(bool par,
272 int worker) {
273 BufferNode* nd = NULL;
274 {
275 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
276 if (_completed_buffers_head != NULL) {
277 nd = _completed_buffers_head;
278 _completed_buffers_head = nd->next();
279 if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
280 _n_completed_buffers--;
281 if (_n_completed_buffers == 0) _process_completed = false;
282 }
283 }
284 ObjectClosure* cl = (par ? _par_closures[worker] : _closure);
285 if (nd != NULL) {
286 void **buf = BufferNode::make_buffer_from_node(nd);
287 ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz);
|