1 /*
 2  * Copyright (c) 2017, 2021, 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 "classfile/classLoaderDataGraph.hpp"
27 #include "gc/g1/g1CollectedHeap.hpp"
28 #include "gc/g1/g1FullCollector.hpp"
29 #include "gc/g1/g1FullGCMarker.hpp"
30 #include "gc/g1/g1FullGCMarkTask.hpp"
31 #include "gc/g1/g1FullGCOopClosures.inline.hpp"
32 #include "gc/shared/gcTraceTime.inline.hpp"
33 #include "gc/shared/referenceProcessor.hpp"
34 #include "memory/iterator.inline.hpp"
35 
36 G1FullGCMarkTask::G1FullGCMarkTask(G1FullCollector* collector) :
37     G1FullGCTask("G1 Parallel Marking Task", collector),
38     _root_processor(G1CollectedHeap::heap(), collector->workers()),
39     _terminator(collector->workers(), collector->array_queue_set()) {
40   // Need cleared claim bits for the roots processing
41   ClassLoaderDataGraph::clear_claimed_marks();
42 }
43 
44 void G1FullGCMarkTask::work(uint worker_id) {
45   Ticks start = Ticks::now();
46   ResourceMark rm;
47   G1FullGCMarker* marker = collector()->marker(worker_id);
48   MarkingCodeBlobClosure code_closure(marker->mark_closure(), !CodeBlobToOopClosure::FixRelocations, true /* keepalive nmethods */);
49 
50   if (ClassUnloading) {
51     _root_processor.process_strong_roots(marker->mark_closure(),
52                                          marker->cld_closure(),
53                                          &code_closure);
54   } else {
55     _root_processor.process_all_roots(marker->mark_closure(),
56                                       marker->cld_closure(),
57                                       &code_closure);
58   }
59 
60   // Mark stack is populated, now process and drain it.
61   marker->complete_marking(collector()->oop_queue_set(), collector()->array_queue_set(), &_terminator);
62   marker->flush_mark_stats_cache();
63 
64   // This is the point where the entire marking should have completed.
65   assert(marker->oop_stack()->is_empty(), "Marking should have completed");
66   assert(marker->objarray_stack()->is_empty(), "Array marking should have completed");
67   log_task("Marking task", worker_id, start);
68 }
--- EOF ---