| File: | jdk/src/hotspot/share/gc/g1/g1RootProcessor.cpp |
| Warning: | line 199, column 15 Value stored to 'strong_roots' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2015, 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 "classfile/stringTable.hpp" |
| 28 | #include "code/codeCache.hpp" |
| 29 | #include "gc/g1/g1BarrierSet.hpp" |
| 30 | #include "gc/g1/g1CodeBlobClosure.hpp" |
| 31 | #include "gc/g1/g1CollectedHeap.inline.hpp" |
| 32 | #include "gc/g1/g1CollectorState.hpp" |
| 33 | #include "gc/g1/g1GCParPhaseTimesTracker.hpp" |
| 34 | #include "gc/g1/g1GCPhaseTimes.hpp" |
| 35 | #include "gc/g1/g1ParScanThreadState.inline.hpp" |
| 36 | #include "gc/g1/g1Policy.hpp" |
| 37 | #include "gc/g1/g1RootClosures.hpp" |
| 38 | #include "gc/g1/g1RootProcessor.hpp" |
| 39 | #include "gc/g1/heapRegion.inline.hpp" |
| 40 | #include "gc/shared/oopStorage.inline.hpp" |
| 41 | #include "gc/shared/oopStorageSet.hpp" |
| 42 | #include "gc/shared/oopStorageSetParState.inline.hpp" |
| 43 | #include "gc/shared/referenceProcessor.hpp" |
| 44 | #include "memory/allocation.inline.hpp" |
| 45 | #include "runtime/mutex.hpp" |
| 46 | #include "utilities/enumIterator.hpp" |
| 47 | #include "utilities/macros.hpp" |
| 48 | |
| 49 | G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) : |
| 50 | _g1h(g1h), |
| 51 | _process_strong_tasks(G1RP_PS_NumElements), |
| 52 | _srs(n_workers) {} |
| 53 | |
| 54 | void G1RootProcessor::evacuate_roots(G1ParScanThreadState* pss, uint worker_id) { |
| 55 | G1GCPhaseTimes* phase_times = _g1h->phase_times(); |
| 56 | |
| 57 | G1EvacPhaseTimesTracker timer(phase_times, pss, G1GCPhaseTimes::ExtRootScan, worker_id); |
| 58 | |
| 59 | G1EvacuationRootClosures* closures = pss->closures(); |
| 60 | process_java_roots(closures, phase_times, worker_id); |
| 61 | |
| 62 | process_vm_roots(closures, phase_times, worker_id); |
| 63 | |
| 64 | { |
| 65 | // Now the CM ref_processor roots. |
| 66 | G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CMRefRoots, worker_id); |
| 67 | if (_process_strong_tasks.try_claim_task(G1RP_PS_refProcessor_oops_do)) { |
| 68 | // We need to treat the discovered reference lists of the |
| 69 | // concurrent mark ref processor as roots and keep entries |
| 70 | // (which are added by the marking threads) on them live |
| 71 | // until they can be processed at the end of marking. |
| 72 | _g1h->ref_processor_cm()->weak_oops_do(closures->strong_oops()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // CodeCache is already processed in java roots |
| 77 | _process_strong_tasks.all_tasks_claimed(G1RP_PS_CodeCache_oops_do); |
| 78 | } |
| 79 | |
| 80 | // Adaptor to pass the closures to the strong roots in the VM. |
| 81 | class StrongRootsClosures : public G1RootClosures { |
| 82 | OopClosure* _roots; |
| 83 | CLDClosure* _clds; |
| 84 | CodeBlobClosure* _blobs; |
| 85 | public: |
| 86 | StrongRootsClosures(OopClosure* roots, CLDClosure* clds, CodeBlobClosure* blobs) : |
| 87 | _roots(roots), _clds(clds), _blobs(blobs) {} |
| 88 | |
| 89 | OopClosure* weak_oops() { return NULL__null; } |
| 90 | OopClosure* strong_oops() { return _roots; } |
| 91 | |
| 92 | CLDClosure* weak_clds() { return NULL__null; } |
| 93 | CLDClosure* strong_clds() { return _clds; } |
| 94 | |
| 95 | CodeBlobClosure* strong_codeblobs() { return _blobs; } |
| 96 | }; |
| 97 | |
| 98 | void G1RootProcessor::process_strong_roots(OopClosure* oops, |
| 99 | CLDClosure* clds, |
| 100 | CodeBlobClosure* blobs) { |
| 101 | StrongRootsClosures closures(oops, clds, blobs); |
| 102 | |
| 103 | process_java_roots(&closures, NULL__null, 0); |
| 104 | process_vm_roots(&closures, NULL__null, 0); |
| 105 | |
| 106 | // CodeCache is already processed in java roots |
| 107 | // refProcessor is not needed since we are inside a safe point |
| 108 | _process_strong_tasks.all_tasks_claimed(G1RP_PS_CodeCache_oops_do, |
| 109 | G1RP_PS_refProcessor_oops_do); |
| 110 | } |
| 111 | |
| 112 | // Adaptor to pass the closures to all the roots in the VM. |
| 113 | class AllRootsClosures : public G1RootClosures { |
| 114 | OopClosure* _roots; |
| 115 | CLDClosure* _clds; |
| 116 | public: |
| 117 | AllRootsClosures(OopClosure* roots, CLDClosure* clds) : |
| 118 | _roots(roots), _clds(clds) {} |
| 119 | |
| 120 | OopClosure* weak_oops() { return _roots; } |
| 121 | OopClosure* strong_oops() { return _roots; } |
| 122 | |
| 123 | // By returning the same CLDClosure for both weak and strong CLDs we ensure |
| 124 | // that a single walk of the CLDG will invoke the closure on all CLDs i the |
| 125 | // system. |
| 126 | CLDClosure* weak_clds() { return _clds; } |
| 127 | CLDClosure* strong_clds() { return _clds; } |
| 128 | |
| 129 | // We don't want to visit code blobs more than once, so we return NULL for the |
| 130 | // strong case and walk the entire code cache as a separate step. |
| 131 | CodeBlobClosure* strong_codeblobs() { return NULL__null; } |
| 132 | }; |
| 133 | |
| 134 | void G1RootProcessor::process_all_roots(OopClosure* oops, |
| 135 | CLDClosure* clds, |
| 136 | CodeBlobClosure* blobs) { |
| 137 | AllRootsClosures closures(oops, clds); |
| 138 | |
| 139 | process_java_roots(&closures, NULL__null, 0); |
| 140 | process_vm_roots(&closures, NULL__null, 0); |
| 141 | |
| 142 | process_code_cache_roots(blobs, NULL__null, 0); |
| 143 | |
| 144 | // refProcessor is not needed since we are inside a safe point |
| 145 | _process_strong_tasks.all_tasks_claimed(G1RP_PS_refProcessor_oops_do); |
| 146 | } |
| 147 | |
| 148 | void G1RootProcessor::process_java_roots(G1RootClosures* closures, |
| 149 | G1GCPhaseTimes* phase_times, |
| 150 | uint worker_id) { |
| 151 | // In the concurrent start pause, when class unloading is enabled, G1 |
| 152 | // processes nmethods in two ways, as "strong" and "weak" nmethods. |
| 153 | // |
| 154 | // 1) Strong nmethods are reachable from the thread stack frames. G1 applies |
| 155 | // the G1RootClosures::strong_codeblobs() closure on them. The closure |
| 156 | // iterates over all oops embedded inside each nmethod, and performs 3 |
| 157 | // operations: |
| 158 | // a) evacuates; relocate objects outside of collection set |
| 159 | // b) fixes up; remap oops to reflect new addresses |
| 160 | // c) mark; mark object alive |
| 161 | // This keeps these oops alive wrt. to the upcoming marking phase, and their |
| 162 | // classes will not be unloaded. |
| 163 | // |
| 164 | // 2) Weak nmethods are reachable only from the code root remembered set (see |
| 165 | // G1CodeRootSet). G1 applies the G1RootClosures::weak_codeblobs() closure on |
| 166 | // them. The closure iterates over all oops embedded inside each nmethod, and |
| 167 | // performs 2 operations: a) and b). |
| 168 | // Since these oops are *not* marked, their classes can potentially be |
| 169 | // unloaded. |
| 170 | // |
| 171 | // G1 doesn't segregate strong/weak nmethods processing (finish processing |
| 172 | // all strong nmethods before starting with any weak nmethods, or vice |
| 173 | // versa), as that could lead to poor CPU utilization (a single slow thread |
| 174 | // prevents all other thread from crossing the synchronization barrier). |
| 175 | // Instead, G1 interleaves strong and weak nmethods processing via |
| 176 | // per-nmethod synchronization. A nmethod is either *strongly* or *weakly* |
| 177 | // claimed before processing. A weakly claimed nmethod could be strongly |
| 178 | // claimed again for performing marking (the c) operation above); see |
| 179 | // oops_do_process_weak and oops_do_process_strong in nmethod.hpp |
| 180 | { |
| 181 | G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_id); |
| 182 | bool is_par = n_workers() > 1; |
| 183 | Threads::possibly_parallel_oops_do(is_par, |
| 184 | closures->strong_oops(), |
| 185 | closures->strong_codeblobs()); |
| 186 | } |
| 187 | |
| 188 | { |
| 189 | G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CLDGRoots, worker_id); |
| 190 | if (_process_strong_tasks.try_claim_task(G1RP_PS_ClassLoaderDataGraph_oops_do)) { |
| 191 | ClassLoaderDataGraph::roots_cld_do(closures->strong_clds(), closures->weak_clds()); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void G1RootProcessor::process_vm_roots(G1RootClosures* closures, |
| 197 | G1GCPhaseTimes* phase_times, |
| 198 | uint worker_id) { |
| 199 | OopClosure* strong_roots = closures->strong_oops(); |
Value stored to 'strong_roots' during its initialization is never read | |
| 200 | |
| 201 | for (auto id : EnumRange<OopStorageSet::StrongId>()) { |
| 202 | G1GCPhaseTimes::GCParPhases phase = G1GCPhaseTimes::strong_oopstorage_phase(id); |
| 203 | G1GCParPhaseTimesTracker x(phase_times, phase, worker_id); |
| 204 | _oop_storage_set_strong_par_state.par_state(id)->oops_do(closures->strong_oops()); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void G1RootProcessor::process_code_cache_roots(CodeBlobClosure* code_closure, |
| 209 | G1GCPhaseTimes* phase_times, |
| 210 | uint worker_id) { |
| 211 | if (_process_strong_tasks.try_claim_task(G1RP_PS_CodeCache_oops_do)) { |
| 212 | CodeCache::blobs_do(code_closure); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | uint G1RootProcessor::n_workers() const { |
| 217 | return _srs.n_threads(); |
| 218 | } |