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 34 G1FullGCReferenceProcessingExecutor::G1FullGCReferenceProcessingExecutor(G1FullCollector* collector) : 35 _collector(collector), 36 _reference_processor(collector->reference_processor()), 37 _old_mt_degree(_reference_processor->num_queues()) { 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 void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task) { 67 G1CollectedHeap::heap()->workers()->run_task(task, _collector->workers()); 68 } 69 70 void G1FullGCReferenceProcessingExecutor::run_task(AbstractGangTask* task, uint workers) { 71 G1CollectedHeap::heap()->workers()->run_task(task, workers); 72 } 73 74 void G1FullGCReferenceProcessingExecutor::execute(ProcessTask& proc_task, uint ergo_workers) { 75 G1RefProcTaskProxy proc_task_proxy(proc_task, _collector); 76 run_task(&proc_task_proxy, ergo_workers); 77 } 78 79 void G1FullGCReferenceProcessingExecutor::execute(STWGCTimer* timer, G1FullGCTracer* tracer) { 80 GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", timer); 81 // Process reference objects found during marking. 82 G1FullGCMarker* marker = _collector->marker(0); 83 G1IsAliveClosure is_alive(_collector->mark_bitmap()); 84 G1FullKeepAliveClosure keep_alive(marker); 85 ReferenceProcessorPhaseTimes pt(timer, _reference_processor->max_num_queues()); 86 AbstractRefProcTaskExecutor* executor = _reference_processor->processing_is_mt() ? this : NULL; 87 88 // Process discovered references, use this executor if multi-threaded 89 // processing is enabled. 90 const ReferenceProcessorStats& stats = 91 _reference_processor->process_discovered_references(&is_alive, 92 &keep_alive, 93 marker->stack_closure(), 94 executor, 95 &pt); 96 97 tracer->report_gc_reference_stats(stats); 98 pt.print_all_references(); 99 100 assert(marker->oop_stack()->is_empty(), "Should be no oops on the stack"); 101 }