Bug Summary

File:jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp
Warning:line 132, column 11
Value stored to 'next_state' 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 g1SegmentedArrayFreeMemoryTask.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/g1SegmentedArrayFreeMemoryTask.cpp
1/*
2 * Copyright (c) 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 "ci/ciUtilities.hpp"
27#include "gc/g1/g1CardSetMemory.inline.hpp"
28#include "gc/g1/g1CollectedHeap.hpp"
29#include "gc/g1/g1SegmentedArrayFreeMemoryTask.hpp"
30#include "gc/g1/g1_globals.hpp"
31#include "gc/g1/heapRegionRemSet.hpp"
32#include "gc/shared/gcTraceTime.inline.hpp"
33#include "gc/shared/suspendibleThreadSet.hpp"
34#include "runtime/os.hpp"
35
36constexpr const char* G1SegmentedArrayFreeMemoryTask::_state_names[];
37
38const char* G1SegmentedArrayFreeMemoryTask::get_state_name(State value) const {
39 return _state_names[static_cast<std::underlying_type_t<State>>(value)];
40}
41
42bool G1SegmentedArrayFreeMemoryTask::deadline_exceeded(jlong deadline) {
43 return os::elapsed_counter() >= deadline;
44}
45
46static size_t keep_size(size_t free, size_t used, double percent) {
47 size_t to_keep = used * percent;
48 return MIN2(free, to_keep);
49}
50
51bool G1SegmentedArrayFreeMemoryTask::calculate_return_infos(jlong deadline) {
52 // Ignore the deadline in this step as it is very short.
53
54 G1SegmentedArrayMemoryStats used = _total_used;
55 G1SegmentedArrayMemoryStats free = G1SegmentedArrayFreePool<mtGCCardSet>::free_list_sizes();
56
57 _return_info = new G1ReturnMemoryProcessorSet(used.num_pools());
58 for (uint i = 0; i < used.num_pools(); i++) {
59 size_t return_to_vm_size = keep_size(free._num_mem_sizes[i],
60 used._num_mem_sizes[i],
61 G1RemSetFreeMemoryKeepExcessRatio);
62 log_trace(gc, task)(!(LogImpl<(LogTag::_gc), (LogTag::_task), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::_task), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Segmented Array Free Memory: Type %s: Free: %zu (%zu) "
63 "Used: %zu Keep: %zu",
64 G1CardSetConfiguration::mem_object_type_name_str(i),
65 free._num_mem_sizes[i], free._num_segments[i],
66 used._num_mem_sizes[i], return_to_vm_size);
67
68 _return_info->append(new G1ReturnMemoryProcessor(return_to_vm_size));
69 }
70
71 G1SegmentedArrayFreePool<mtGCCardSet>::update_unlink_processors(_return_info);
72 return false;
73}
74
75bool G1SegmentedArrayFreeMemoryTask::return_memory_to_vm(jlong deadline) {
76 for (int i = 0; i < _return_info->length(); i++) {
77 G1ReturnMemoryProcessor* info = _return_info->at(i);
78 if (!info->finished_return_to_vm()) {
79 if (info->return_to_vm(deadline)) {
80 return true;
81 }
82 }
83 }
84 return false;
85}
86
87bool G1SegmentedArrayFreeMemoryTask::return_memory_to_os(jlong deadline) {
88 for (int i = 0; i < _return_info->length(); i++) {
89 G1ReturnMemoryProcessor* info = _return_info->at(i);
90 if (!info->finished_return_to_os()) {
91 if (info->return_to_os(deadline)) {
92 return true;
93 }
94 }
95 }
96 return false;
97}
98
99bool G1SegmentedArrayFreeMemoryTask::cleanup_return_infos() {
100 for (int i = 0; i < _return_info->length(); i++) {
101 G1ReturnMemoryProcessor* info = _return_info->at(i);
102 delete info;
103 }
104 delete _return_info;
105
106 _return_info = nullptr;
107 return false;
108}
109
110bool G1SegmentedArrayFreeMemoryTask::free_excess_segmented_array_memory() {
111 jlong start = os::elapsed_counter();
112 jlong end = start +
113 (os::elapsed_frequency() / 1000) * G1RemSetFreeMemoryStepDurationMillis;
114
115 log_trace(gc, task)(!(LogImpl<(LogTag::_gc), (LogTag::_task), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::_task), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Segmented Array Free Memory: Step start %1.3f end %1.3f",
116 TimeHelper::counter_to_millis(start), TimeHelper::counter_to_millis(end));
117
118 State next_state;
119
120 do {
121 switch (_state) {
122 case State::CalculateUsed: {
123 if (calculate_return_infos(end)) {
124 next_state = _state;
125 return true;
126 }
127 next_state = State::ReturnToVM;
128 break;
129 }
130 case State::ReturnToVM: {
131 if (return_memory_to_vm(end)) {
132 next_state = _state;
Value stored to 'next_state' is never read
133 return true;
134 }
135 next_state = State::ReturnToOS;
136 break;
137 }
138 case State::ReturnToOS: {
139 if (return_memory_to_os(end)) {
140 next_state = _state;
141 return true;
142 }
143 next_state = State::Cleanup;
144 break;
145 }
146 case State::Cleanup: {
147 cleanup_return_infos();
148 next_state = State::Inactive;
149 break;
150 }
151 default:
152 log_error(gc, task)(!(LogImpl<(LogTag::_gc), (LogTag::_task), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Error))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::_task), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Error>
("Should not try to free excess segmented array memory in %s state", get_state_name(_state));
153 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp"
, 153); ::breakpoint(); } while (0)
;
154 break;
155 }
156
157 set_state(next_state);
158 } while (_state != State::Inactive && !deadline_exceeded(end));
159
160 log_trace(gc, task)(!(LogImpl<(LogTag::_gc), (LogTag::_task), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::_task), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Segmented Array Free Memory: Step took %1.3fms, done %s",
161 TimeHelper::counter_to_millis(os::elapsed_counter() - start),
162 bool_to_str(_state == State::CalculateUsed));
163
164 return is_active();
165}
166
167void G1SegmentedArrayFreeMemoryTask::set_state(State new_state) {
168 log_trace(gc, task)(!(LogImpl<(LogTag::_gc), (LogTag::_task), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::_task), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Trace>
("Segmented Array Free Memory: State change from %s to %s",
169 get_state_name(_state),
170 get_state_name(new_state));
171 _state = new_state;
172}
173
174bool G1SegmentedArrayFreeMemoryTask::is_active() const {
175 return _state != State::Inactive;
176}
177
178jlong G1SegmentedArrayFreeMemoryTask::reschedule_delay_ms() const {
179 return G1RemSetFreeMemoryRescheduleDelayMillis;
180}
181
182G1SegmentedArrayFreeMemoryTask::G1SegmentedArrayFreeMemoryTask(const char* name) :
183 G1ServiceTask(name), _state(State::CalculateUsed), _return_info(nullptr) { }
184
185void G1SegmentedArrayFreeMemoryTask::execute() {
186 SuspendibleThreadSetJoiner sts;
187
188 if (free_excess_segmented_array_memory()) {
189 schedule(reschedule_delay_ms());
190 }
191}
192
193void G1SegmentedArrayFreeMemoryTask::notify_new_stats(G1SegmentedArrayMemoryStats* young_gen_stats,
194 G1SegmentedArrayMemoryStats* collection_set_candidate_stats) {
195 assert_at_safepoint_on_vm_thread()do { do { if (!(SafepointSynchronize::is_at_safepoint())) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp"
, 195, "assert(" "SafepointSynchronize::is_at_safepoint()" ") failed"
, "should be at a safepoint"); ::breakpoint(); } } while (0);
do { if (!(Thread::current_or_null() != __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp"
, 195, "assert(" "Thread::current_or_null() != __null" ") failed"
, "no current thread"); ::breakpoint(); } } while (0); do { if
(!(Thread::current()->is_VM_thread())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp"
, 195, "assert(" "Thread::current()->is_VM_thread()" ") failed"
, "current thread is not VM thread"); ::breakpoint(); } } while
(0); } while (0)
;
196
197 _total_used = *young_gen_stats;
198 _total_used.add(*collection_set_candidate_stats);
199
200 if (!is_active()) {
201 set_state(State::CalculateUsed);
202 G1CollectedHeap::heap()->service_thread()->schedule_task(this, 0);
203 }
204}