1/*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. 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 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/g1/g1CollectedHeap.hpp"
27#include "gc/g1/g1FullCollector.hpp"
28#include "gc/g1/g1FullGCMarker.hpp"
29#include "gc/g1/g1FullGCOopClosures.inline.hpp"
30#include "gc/g1/g1FullGCReferenceProcessorExecutor.hpp"
31#include "gc/shared/gcTraceTime.inline.hpp"
32#include "gc/shared/referenceProcessor.hpp"
33#include "gc/shared/referenceProcessorPhaseTimes.hpp"
34#include "memory/iterator.inline.hpp"
35
36G1FullGCReferenceProcessingExecutor::G1FullGCReferenceProcessingExecutor(G1FullCollector* collector) :
37 _collector(collector),
38 _reference_processor(collector->reference_processor()),
39 _old_mt_degree(_reference_processor->num_queues()) {
40 if (_reference_processor->processing_is_mt()) {
41 _reference_processor->set_active_mt_degree(_collector->workers());
42 }
43}
44
45G1FullGCReferenceProcessingExecutor::~G1FullGCReferenceProcessingExecutor() {
46 if (_reference_processor->processing_is_mt()) {
47 _reference_processor->set_active_mt_degree(_old_mt_degree);
48 }
49}
50
51G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::G1RefProcTaskProxy(ProcessTask& proc_task,
52 G1FullCollector* collector) :
53 AbstractGangTask("G1 reference processing task"),
54 _proc_task(proc_task),
55 _collector(collector),
56 _terminator(_collector->workers(), _collector->oop_queue_set()) { }
57
58void G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::work(uint worker_id) {
59 G1FullGCMarker* marker = _collector->marker(worker_id);
60 G1IsAliveClosure is_alive(_collector->mark_bitmap());
61 G1FullKeepAliveClosure keep_alive(marker);
62 _proc_task.work(worker_id,
63 is_alive,
64 keep_alive,
65 *marker->stack_closure());
66}
67
68void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task) {
69 G1CollectedHeap::heap()->workers()->run_task(task, _collector->workers());
70}
71
72void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task, uint workers) {
73 G1CollectedHeap::heap()->workers()->run_task(task, workers);
74}
75
76void G1FullGCReferenceProcessingExecutor::execute(ProcessTask& proc_task, uint ergo_workers) {
77 G1RefProcTaskProxy proc_task_proxy(proc_task, _collector);
78 run_task(&proc_task_proxy, ergo_workers);
79}
80
81void G1FullGCReferenceProcessingExecutor::execute(STWGCTimer* timer, G1FullGCTracer* tracer) {
82 GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", timer);
83 // Process reference objects found during marking.
84 G1FullGCMarker* marker = _collector->marker(0);
85 G1IsAliveClosure is_alive(_collector->mark_bitmap());
86 G1FullKeepAliveClosure keep_alive(marker);
87 ReferenceProcessorPhaseTimes pt(timer, _reference_processor->max_num_queues());
88 AbstractRefProcTaskExecutor* executor = _reference_processor->processing_is_mt() ? this : NULL;
89
90 // Process discovered references, use this executor if multi-threaded
91 // processing is enabled.
92 const ReferenceProcessorStats& stats =
93 _reference_processor->process_discovered_references(&is_alive,
94 &keep_alive,
95 marker->stack_closure(),
96 executor,
97 &pt);
98
99 tracer->report_gc_reference_stats(stats);
100 pt.print_all_references();
101
102 assert(marker->oop_stack()->is_empty(), "Should be no oops on the stack");
103}
104