File: | jdk/src/hotspot/share/gc/g1/g1SegmentedArrayFreeMemoryTask.cpp |
Warning: | line 140, column 11 Value stored to 'next_state' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | |
36 | constexpr const char* G1SegmentedArrayFreeMemoryTask::_state_names[]; |
37 | |
38 | const char* G1SegmentedArrayFreeMemoryTask::get_state_name(State value) const { |
39 | return _state_names[static_cast<std::underlying_type_t<State>>(value)]; |
40 | } |
41 | |
42 | bool G1SegmentedArrayFreeMemoryTask::deadline_exceeded(jlong deadline) { |
43 | return os::elapsed_counter() >= deadline; |
44 | } |
45 | |
46 | static 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 | |
51 | bool 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 | |
75 | bool 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 | |
87 | bool 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 | |
99 | bool 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 | |
110 | bool 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; |
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; |
Value stored to 'next_state' is never read | |
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 | |
167 | void 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 | |
174 | bool G1SegmentedArrayFreeMemoryTask::is_active() const { |
175 | return _state != State::Inactive; |
176 | } |
177 | |
178 | jlong G1SegmentedArrayFreeMemoryTask::reschedule_delay_ms() const { |
179 | return G1RemSetFreeMemoryRescheduleDelayMillis; |
180 | } |
181 | |
182 | G1SegmentedArrayFreeMemoryTask::G1SegmentedArrayFreeMemoryTask(const char* name) : |
183 | G1ServiceTask(name), _state(State::CalculateUsed), _return_info(nullptr) { } |
184 | |
185 | void G1SegmentedArrayFreeMemoryTask::execute() { |
186 | SuspendibleThreadSetJoiner sts; |
187 | |
188 | if (free_excess_segmented_array_memory()) { |
189 | schedule(reschedule_delay_ms()); |
190 | } |
191 | } |
192 | |
193 | void 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 | } |