|
1 /* |
|
2 * Copyright (c) 2017, 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 |
|
34 G1FullGCReferenceProcessingExecutor::G1FullGCReferenceProcessingExecutor(G1FullCollector* collector) : |
|
35 _collector(collector), |
|
36 _reference_processor(collector->reference_processor()), |
|
37 _old_mt_degree(_reference_processor->num_q()) { |
|
38 if (_reference_processor->processing_is_mt()) { |
|
39 _reference_processor->set_active_mt_degree(_collector->workers()); |
|
40 } |
|
41 } |
|
42 |
|
43 G1FullGCReferenceProcessingExecutor::~G1FullGCReferenceProcessingExecutor() { |
|
44 if (_reference_processor->processing_is_mt()) { |
|
45 _reference_processor->set_active_mt_degree(_old_mt_degree); |
|
46 } |
|
47 } |
|
48 |
|
49 G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::G1RefProcTaskProxy(ProcessTask& proc_task, |
|
50 G1FullCollector* collector) : |
|
51 AbstractGangTask("G1 reference processing task"), |
|
52 _proc_task(proc_task), |
|
53 _collector(collector), |
|
54 _terminator(_collector->workers(), _collector->oop_queue_set()) { } |
|
55 |
|
56 void G1FullGCReferenceProcessingExecutor::G1RefProcTaskProxy::work(uint worker_id) { |
|
57 G1FullGCMarker* marker = _collector->marker(worker_id); |
|
58 G1IsAliveClosure is_alive(_collector->mark_bitmap()); |
|
59 G1FullKeepAliveClosure keep_alive(marker); |
|
60 _proc_task.work(worker_id, |
|
61 is_alive, |
|
62 keep_alive, |
|
63 *marker->stack_closure()); |
|
64 } |
|
65 |
|
66 G1FullGCReferenceProcessingExecutor::G1RefEnqueueTaskProxy::G1RefEnqueueTaskProxy(EnqueueTask& enq_task) : |
|
67 AbstractGangTask("G1 reference enqueue task"), |
|
68 _enq_task(enq_task) { } |
|
69 |
|
70 void G1FullGCReferenceProcessingExecutor::G1RefEnqueueTaskProxy::work(uint worker_id) { |
|
71 _enq_task.work(worker_id); |
|
72 } |
|
73 |
|
74 void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task) { |
|
75 G1CollectedHeap::heap()->workers()->run_task(task, _collector->workers()); |
|
76 } |
|
77 |
|
78 void G1FullGCReferenceProcessingExecutor::execute(ProcessTask& proc_task) { |
|
79 G1RefProcTaskProxy proc_task_proxy(proc_task, _collector); |
|
80 run_task(&proc_task_proxy); |
|
81 } |
|
82 |
|
83 // Driver routine for parallel reference processing. |
|
84 void G1FullGCReferenceProcessingExecutor::execute(EnqueueTask& enq_task) { |
|
85 G1RefEnqueueTaskProxy enq_task_proxy(enq_task); |
|
86 run_task(&enq_task_proxy); |
|
87 } |
|
88 |
|
89 void G1FullGCReferenceProcessingExecutor::execute(STWGCTimer* timer, G1FullGCTracer* tracer) { |
|
90 GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", timer); |
|
91 // Process reference objects found during marking. |
|
92 G1FullGCMarker* marker = _collector->marker(0); |
|
93 G1IsAliveClosure is_alive(_collector->mark_bitmap()); |
|
94 G1FullKeepAliveClosure keep_alive(marker); |
|
95 ReferenceProcessorPhaseTimes pt(timer, _reference_processor->num_q()); |
|
96 AbstractRefProcTaskExecutor* executor = _reference_processor->processing_is_mt() ? this : NULL; |
|
97 |
|
98 // Process discovered references, use this executor if multi-threaded |
|
99 // processing is enabled. |
|
100 const ReferenceProcessorStats& stats = |
|
101 _reference_processor->process_discovered_references(&is_alive, |
|
102 &keep_alive, |
|
103 marker->stack_closure(), |
|
104 executor, |
|
105 &pt); |
|
106 |
|
107 tracer->report_gc_reference_stats(stats); |
|
108 pt.print_all_references(); |
|
109 |
|
110 assert(marker->oop_stack()->is_empty(), "Should be no oops on the stack"); |
|
111 |
|
112 // Now enqueue the references. |
|
113 _reference_processor->enqueue_discovered_references(executor, &pt); |
|
114 pt.print_enqueue_phase(); |
|
115 } |