Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name g1RootProcessor.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1RootProcessor.cpp
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
49G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) :
50 _g1h(g1h),
51 _process_strong_tasks(G1RP_PS_NumElements),
52 _srs(n_workers) {}
53
54void 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.
81class StrongRootsClosures : public G1RootClosures {
82 OopClosure* _roots;
83 CLDClosure* _clds;
84 CodeBlobClosure* _blobs;
85public:
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
98void 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.
113class AllRootsClosures : public G1RootClosures {
114 OopClosure* _roots;
115 CLDClosure* _clds;
116public:
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
134void 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
148void 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
196void 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
208void 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
216uint G1RootProcessor::n_workers() const {
217 return _srs.n_threads();
218}