Bug Summary

File:jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp
Warning:line 357, column 10
Value stored to 'adjusted_threshold' 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 test_g1CardSet.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/gtest/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/googletest/googletest/include -I /home/daniel/Projects/java/googletest/googlemock/include -I /home/daniel/Projects/java/jdk/test/hotspot/gtest -I /home/daniel/Projects/java/jdk/test/hotspot/gtest -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 -Wno-undef -Wno-stringop-overflow -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/test/hotspot/gtest/gc/g1/test_g1CardSet.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#include "precompiled.hpp"
25#include "gc/g1/g1CardSet.inline.hpp"
26#include "gc/g1/g1CardSetContainers.hpp"
27#include "gc/g1/g1CardSetMemory.hpp"
28#include "gc/g1/g1SegmentedArrayFreePool.hpp"
29#include "gc/g1/heapRegionRemSet.hpp"
30#include "gc/shared/gcTraceTime.inline.hpp"
31#include "gc/shared/workerThread.hpp"
32#include "logging/log.hpp"
33#include "memory/allocation.hpp"
34#include "unittest.hpp"
35#include "utilities/powerOfTwo.hpp"
36
37class G1CardSetTest : public ::testing::Test {
38
39 class G1CountCardsClosure : public G1CardSet::CardClosure {
40 public:
41 size_t _num_cards;
42
43 G1CountCardsClosure() : _num_cards(0) { }
44 void do_card(uint region_idx, uint card_idx) override {
45 _num_cards++;
46 }
47 };
48
49 static WorkerThreads* _workers;
50 static uint _max_workers;
51
52 static WorkerThreads* workers() {
53 if (_workers == NULL__null) {
54 _max_workers = os::processor_count();
55 _workers = new WorkerThreads("G1CardSetTest Workers", _max_workers);
56 _workers->initialize_workers();
57 _workers->set_active_workers(_max_workers);
58 }
59 return _workers;
60 }
61
62 // Check whether iteration agrees with the expected number of entries. If the
63 // add has been single-threaded, we can also check whether the occupied()
64 // (which is an estimate in that case) agrees.
65 static void check_iteration(G1CardSet* card_set,
66 const size_t expected,
67 const bool add_was_single_threaded = true);
68
69public:
70 G1CardSetTest() { }
71 ~G1CardSetTest() { }
72
73 static uint next_random(uint& seed, uint i) {
74 // Park–Miller random number generator
75 seed = (seed * 279470273u) % 0xfffffffb;
76 return (seed % i);
77 }
78
79 static void cardset_basic_test();
80 static void cardset_mt_test();
81
82 static void add_cards(G1CardSet* card_set, uint cards_per_region, uint* cards, uint num_cards, G1AddCardResult* results);
83 static void contains_cards(G1CardSet* card_set, uint cards_per_region, uint* cards, uint num_cards);
84
85 static void translate_cards(uint cards_per_region, uint region_idx, uint* cards, uint num_cards);
86
87 static void iterate_cards(G1CardSet* card_set, G1CardSet::CardClosure* cl);
88};
89
90WorkerThreads* G1CardSetTest::_workers = NULL__null;
91uint G1CardSetTest::_max_workers = 0;
92
93void G1CardSetTest::add_cards(G1CardSet* card_set, uint cards_per_region, uint* cards, uint num_cards, G1AddCardResult* results) {
94 for (uint i = 0; i < num_cards; i++) {
95
96 uint region_idx = cards[i] / cards_per_region;
97 uint card_idx = cards[i] % cards_per_region;
98
99 G1AddCardResult res = card_set->add_card(region_idx, card_idx);
100 if (results != NULL__null) {
101 ASSERT_TRUE(res == results[i])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == results[i])) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == results[i]", "false", "true").c_str()) = ::testing::
Message()
;
102 }
103 }
104}
105
106class G1CheckCardClosure : public G1CardSet::CardClosure {
107 G1CardSet* _card_set;
108
109 uint _cards_per_region;
110 uint* _cards_to_expect;
111 uint _num_cards;
112
113 bool _wrong_region_idx;
114
115public:
116 G1CheckCardClosure(G1CardSet* card_set, uint cards_per_region, uint* cards_to_expect, uint num_cards) :
117 _card_set(card_set),
118 _cards_per_region(cards_per_region),
119 _cards_to_expect(cards_to_expect),
120 _num_cards(num_cards),
121 _wrong_region_idx(false) {
122 }
123
124 void do_card(uint region_idx, uint card_idx) override {
125 uint card = _cards_per_region * region_idx + card_idx;
126 for (uint i = 0; i < _num_cards; i++) {
127 if (_cards_to_expect[i] == card) {
128 _cards_to_expect[i] = (uint)-1;
129 }
130 }
131 }
132
133 bool all_found() const {
134 bool all_good = true;
135 for (uint i = 0; i < _num_cards; i++) {
136 if (_cards_to_expect[i] != (uint)-1) {
137 log_error(gc)(!(LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)
>::is_level(LogLevel::Error))) ? (void)0 : LogImpl<(LogTag
::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG
), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel
::Error>
("Could not find card %u in region %u",
138 _cards_to_expect[i] % _cards_per_region,
139 _cards_to_expect[i] / _cards_per_region);
140 all_good = false;
141 }
142 }
143 return all_good;
144 }
145};
146
147void G1CardSetTest::contains_cards(G1CardSet* card_set, uint cards_per_region, uint* cards, uint num_cards) {
148 for (uint i = 0; i < num_cards; i++) {
149 uint region_idx = cards[i] / cards_per_region;
150 uint card_idx = cards[i] % cards_per_region;
151
152 ASSERT_TRUE(card_set->contains_card(region_idx, card_idx))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set->contains_card
(region_idx, card_idx))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set->contains_card(region_idx, card_idx)", "false"
, "true").c_str()) = ::testing::Message()
;
153 }
154
155 G1CheckCardClosure cl(card_set, cards_per_region, cards, num_cards);
156 card_set->iterate_cards(cl);
157
158 ASSERT_TRUE(cl.all_found())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(cl.all_found())) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 158, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "cl.all_found()", "false", "true").c_str()) = ::testing::Message
()
;
159}
160
161// Offsets the card indexes in the cards array by the region_idx.
162void G1CardSetTest::translate_cards(uint cards_per_region, uint region_idx, uint* cards, uint num_cards) {
163 for (uint i = 0; i < num_cards; i++) {
164 cards[i] = cards_per_region * region_idx + cards[i];
165 }
166}
167
168class G1CountCardsOccupied : public G1CardSet::CardSetPtrClosure {
169 size_t _num_occupied;
170
171public:
172 G1CountCardsOccupied() : _num_occupied(0) { }
173
174 void do_cardsetptr(uint region_idx, size_t num_occupied, G1CardSet::CardSetPtr card_set) override {
175 _num_occupied += num_occupied;
176 }
177
178 size_t num_occupied() const { return _num_occupied; }
179};
180
181void G1CardSetTest::check_iteration(G1CardSet* card_set, const size_t expected, const bool single_threaded) {
182
183 class CheckIterator : public G1CardSet::CardClosure {
184 public:
185 G1CardSet* _card_set;
186 size_t _num_found;
187
188 CheckIterator(G1CardSet* card_set) : _card_set(card_set), _num_found(0) { }
189
190 void do_card(uint region_idx, uint card_idx) override {
191 ASSERT_TRUE(_card_set->contains_card(region_idx, card_idx))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(_card_set->contains_card
(region_idx, card_idx))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 191, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "_card_set->contains_card(region_idx, card_idx)", "false"
, "true").c_str()) = ::testing::Message()
;
192 _num_found++;
193 }
194 } cl(card_set);
195
196 card_set->iterate_cards(cl);
197
198 ASSERT_TRUE(expected == cl._num_found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(expected == cl._num_found
)) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 198, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "expected == cl._num_found", "false", "true").c_str()) = ::
testing::Message()
;
199 // We can assert this only if we are single-threaded.
200 if (single_threaded) {
201 ASSERT_EQ(card_set->occupied(), cl._num_found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(card_set->occupied())) == 1
)>::Compare("card_set->occupied()", "cl._num_found", card_set
->occupied(), cl._num_found))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 201, gtest_ar.failure_message()) = ::testing::Message()
;
202 }
203}
204
205void G1CardSetTest::cardset_basic_test() {
206
207 const uint CardsPerRegion = 2048;
208 const double FullCardSetThreshold = 0.8;
209 const double BitmapCoarsenThreshold = 0.9;
210
211 G1CardSetConfiguration config(28,
212 BitmapCoarsenThreshold,
213 8,
214 FullCardSetThreshold,
215 CardsPerRegion,
216 0);
217 G1CardSetFreePool free_pool(config.num_mem_object_types());
218 G1CardSetMemoryManager mm(&config, &free_pool);
219
220 {
221 G1CardSet card_set(&config, &mm);
222
223 uint cards1[] = { 1, 2, 3 };
224 G1AddCardResult results1[] = { Added, Added, Added };
225 translate_cards(CardsPerRegion, 99, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)));
226 add_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)), results1);
227 contains_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)));
228 ASSERT_TRUE(card_set.occupied() == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
sizeof(array_size_impl(cards1)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 228, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
229
230 G1CountCardsClosure count_cards;
231 card_set.iterate_cards(count_cards);
232 ASSERT_TRUE(count_cards._num_cards == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
== sizeof(array_size_impl(cards1)))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 232, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
233
234 check_iteration(&card_set, card_set.occupied());
235
236 card_set.clear();
237 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 237, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
238
239 check_iteration(&card_set, 0);
240 }
241
242 {
243 G1CardSet card_set(&config, &mm);
244
245 uint cards1[] = { 0, 2047, 17, 17 };
246 G1AddCardResult results1[] = { Added, Added, Added, Found };
247 translate_cards(CardsPerRegion, 100, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)));
248 add_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)), results1);
249 // -1 because of the duplicate at the end.
250 contains_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)) - 1);
251 ASSERT_TRUE(card_set.occupied() == ARRAY_SIZE(cards1) - 1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
sizeof(array_size_impl(cards1)) - 1)) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 251, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == ARRAY_SIZE(cards1) - 1", "false", "true"
).c_str()) = ::testing::Message()
;
252
253 G1CountCardsClosure count_cards;
254 card_set.iterate_cards(count_cards);
255 ASSERT_TRUE(count_cards._num_cards == ARRAY_SIZE(cards1) - 1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
== sizeof(array_size_impl(cards1)) - 1)) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards == ARRAY_SIZE(cards1) - 1", "false"
, "true").c_str()) = ::testing::Message()
;
256
257 check_iteration(&card_set, card_set.occupied());
258
259 card_set.clear();
260 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 260, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
261 }
262
263 {
264 G1CardSet card_set(&config, &mm);
265
266 uint cards1[] = { 0, 2047, 17, 18 /* for region 100 */,
267 1, 128, 35, 17 /* for region 990 */
268 };
269 translate_cards(CardsPerRegion, 100, &cards1[0], 4);
270 translate_cards(CardsPerRegion, 990, &cards1[4], 4);
271
272 add_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)), NULL__null);
273 contains_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)));
274 ASSERT_TRUE(card_set.occupied() == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
sizeof(array_size_impl(cards1)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 274, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
275
276 G1CountCardsClosure count_cards;
277 card_set.iterate_cards(count_cards);
278 ASSERT_TRUE(count_cards._num_cards == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
== sizeof(array_size_impl(cards1)))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 278, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
279
280 check_iteration(&card_set, card_set.occupied());
281
282 card_set.clear();
283 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
284 }
285
286 {
287 G1CardSet card_set(&config, &mm);
288
289 uint cards1[100];
290 for (uint i = 0; i < ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)); i++) {
291 cards1[i] = i + 3;
292 translate_cards(CardsPerRegion, i, &cards1[i], 1);
293 }
294 add_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)), NULL__null);
295 contains_cards(&card_set, CardsPerRegion, cards1, ARRAY_SIZE(cards1)sizeof(array_size_impl(cards1)));
296
297 ASSERT_TRUE(card_set.num_containers() == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.num_containers
() == sizeof(array_size_impl(cards1)))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 297, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.num_containers() == ARRAY_SIZE(cards1)", "false",
"true").c_str()) = ::testing::Message()
;
298 ASSERT_TRUE(card_set.occupied() == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
sizeof(array_size_impl(cards1)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
299
300 G1CountCardsClosure count_cards;
301 card_set.iterate_cards(count_cards);
302 ASSERT_TRUE(count_cards._num_cards == ARRAY_SIZE(cards1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
== sizeof(array_size_impl(cards1)))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 302, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards == ARRAY_SIZE(cards1)", "false", "true"
).c_str()) = ::testing::Message()
;
303
304 check_iteration(&card_set, card_set.occupied());
305
306 card_set.clear();
307 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 307, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
308 }
309
310 {
311 G1CardSet card_set(&config, &mm);
312
313 // Generate non-prime numbers from 1 to 1000
314 uint count = 0;
315 for (uint i = 2; i < 33; i++) {
316 if (!card_set.contains_card(100, i)) {
317 for (uint j = i * i; j < 1000; j += i) {
318 G1AddCardResult res = card_set.add_card(100, j);
319 count += (res == Added);
320 }
321 }
322 }
323
324 G1CountCardsOccupied cl;
325 card_set.iterate_containers(&cl);
326
327 ASSERT_TRUE(count == card_set.occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count == card_set.occupied
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 327, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count == card_set.occupied()", "false", "true").c_str()) =
::testing::Message()
;
328 ASSERT_TRUE(card_set.occupied() == cl.num_occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
cl.num_occupied())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 328, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == cl.num_occupied()", "false", "true"
).c_str()) = ::testing::Message()
;
329
330 check_iteration(&card_set, card_set.occupied());
331
332 card_set.clear();
333 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 333, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
334 }
335 { // Test coarsening to full
336 G1CardSet card_set(&config, &mm);
337
338 uint count = 0;
339 uint i = 10;
340 uint bitmap_threshold = config.cards_in_howl_bitmap_threshold();
341 for (; i < bitmap_threshold + 10; i++) {
342 G1AddCardResult res = card_set.add_card(99, i);
343 ASSERT_TRUE(res == Added)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Added)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 343, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Added", "false", "true").c_str()) = ::testing::Message
()
;
344 count++;
345 ASSERT_TRUE(count == card_set.occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count == card_set.occupied
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 345, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count == card_set.occupied()", "false", "true").c_str()) =
::testing::Message()
;
346 }
347
348 G1AddCardResult res = card_set.add_card(99, config.max_cards_in_howl_bitmap() - 1);
349 // Adding above card should have coarsened Bitmap -> Full.
350 ASSERT_TRUE(res == Added)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Added)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Added", "false", "true").c_str()) = ::testing::Message
()
;
351 ASSERT_TRUE(config.max_cards_in_howl_bitmap() == card_set.occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(config.max_cards_in_howl_bitmap
() == card_set.occupied())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "config.max_cards_in_howl_bitmap() == card_set.occupied()",
"false", "true").c_str()) = ::testing::Message()
;
352
353 res = card_set.add_card(99, config.max_cards_in_howl_bitmap() - 2);
354 ASSERT_TRUE(res == Found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Found)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 354, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Found", "false", "true").c_str()) = ::testing::Message
()
;
355
356 uint threshold = config.cards_in_howl_threshold();
357 uint adjusted_threshold = config.cards_in_howl_bitmap_threshold() * config.num_buckets_in_howl();
Value stored to 'adjusted_threshold' during its initialization is never read
358 i = config.max_cards_in_howl_bitmap();
359 count = i;
360 for (; i < threshold; i++) {
361 G1AddCardResult res = card_set.add_card(99, i);
362 ASSERT_TRUE(res == Added)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Added)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 362, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Added", "false", "true").c_str()) = ::testing::Message
()
;
363 count++;
364 ASSERT_TRUE(count == card_set.occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count == card_set.occupied
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 364, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count == card_set.occupied()", "false", "true").c_str()) =
::testing::Message()
;
365 }
366
367 res = card_set.add_card(99, CardsPerRegion - 1);
368 // Adding above card should have coarsened Howl -> Full.
369 ASSERT_TRUE(res == Added)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Added)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Added", "false", "true").c_str()) = ::testing::Message
()
;
370 ASSERT_TRUE(CardsPerRegion == card_set.occupied())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(CardsPerRegion == card_set
.occupied())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 370, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "CardsPerRegion == card_set.occupied()", "false", "true").c_str
()) = ::testing::Message()
;
371
372 check_iteration(&card_set, card_set.occupied());
373
374 res = card_set.add_card(99, CardsPerRegion - 2);
375 ASSERT_TRUE(res == Found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Found)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 375, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Found", "false", "true").c_str()) = ::testing::Message
()
;
376
377 G1CountCardsClosure count_cards;
378 card_set.iterate_cards(count_cards);
379 ASSERT_TRUE(count_cards._num_cards == config.max_cards_in_region())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
== config.max_cards_in_region())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 379, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards == config.max_cards_in_region()", "false"
, "true").c_str()) = ::testing::Message()
;
380
381 card_set.clear();
382 ASSERT_TRUE(card_set.occupied() == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(card_set.occupied() ==
0)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 382, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "card_set.occupied() == 0", "false", "true").c_str()) = ::testing
::Message()
;
383 }
384}
385
386class G1CardSetMtTestTask : public WorkerTask {
387 G1CardSet* _card_set;
388
389 size_t _added;
390 size_t _found;
391
392public:
393 G1CardSetMtTestTask(G1CardSet* card_set) :
394 WorkerTask(""),
395 _card_set(card_set),
396 _added(0),
397 _found(0) { }
398
399 void work(uint worker_id) {
400 uint seed = worker_id;
401 size_t added = 0;
402 size_t found = 0;
403
404 for (uint i = 0; i < 100000; i++) {
405 uint region = G1CardSetTest::next_random(seed, 1000);
406 uint card = G1CardSetTest::next_random(seed, 10000);
407
408 G1AddCardResult res = _card_set->add_card(region, card);
409
410 ASSERT_TRUE(res == Added || res == Found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(res == Added || res ==
Found)) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 410, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "res == Added || res == Found", "false", "true").c_str()) =
::testing::Message()
;
411 if (res == Added) {
412 added++;
413 } else if (res == Found) {
414 found++;
415 }
416 }
417 Atomic::add(&_added, added);
418 Atomic::add(&_found, found);
419 }
420
421 size_t added() const { return _added; }
422 size_t found() const { return _found; }
423};
424
425void G1CardSetTest::cardset_mt_test() {
426 const uint CardsPerRegion = 16384;
427 const double FullCardSetThreshold = 1.0;
428 const uint BitmapCoarsenThreshold = 1.0;
429
430 G1CardSetConfiguration config(120,
431 BitmapCoarsenThreshold,
432 8,
433 FullCardSetThreshold,
434 CardsPerRegion,
435 0);
436 G1CardSetFreePool free_pool(config.num_mem_object_types());
437 G1CardSetMemoryManager mm(&config, &free_pool);
438
439 G1CardSet card_set(&config, &mm);
440
441 const uint num_workers = workers()->active_workers();
442
443 G1CardSetMtTestTask cl(&card_set);
444
445 {
446 GCTraceTime(Error, gc)GCTraceTimeWrapper<LogLevel::Error, (LogTag::_gc), (LogTag
::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::
__NO_TAG), (LogTag::__NO_TAG)>
x("Cardset test");
447 _workers->run_task(&cl, num_workers);
448 }
449
450 size_t num_found = 0;
451 // Now check the contents of the card set.
452 for (uint i = 0; i < num_workers; i++) {
453 uint seed = i;
454
455 for (uint j = 0; j < 100000; j++) {
456 uint region = G1CardSetTest::next_random(seed, 1000);
457 uint card = G1CardSetTest::next_random(seed, 10000);
458
459 bool contains = card_set.contains_card(region, card);
460 ASSERT_TRUE(contains)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(contains)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 460, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "contains", "false", "true").c_str()) = ::testing::Message(
)
;
461
462 num_found += contains;
463 }
464 }
465
466 ASSERT_TRUE(num_found == cl.added() + cl.found())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(num_found == cl.added
() + cl.found())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "num_found == cl.added() + cl.found()", "false", "true").c_str
()) = ::testing::Message()
;
467
468 G1CountCardsClosure count_cards;
469 card_set.iterate_cards(count_cards);
470
471 check_iteration(&card_set, count_cards._num_cards, false /* add_was_single_threaded */);
472
473 // During coarsening we try to unblock concurrent threads as soon as possible,
474 // so we do not add the cards from the smaller CardSetContainer to the larger
475 // one immediately, allowing addition by concurrent threads after allocating
476 // the space immediately. So the amount of "successfully added" results may be
477 // (and in case of many threads typically is) higher than the number of unique
478 // cards.
479 ASSERT_TRUE(count_cards._num_cards <= cl.added())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(count_cards._num_cards
<= cl.added())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 479, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "count_cards._num_cards <= cl.added()", "false", "true")
.c_str()) = ::testing::Message()
;
480}
481
482TEST_VM(G1CardSetTest, basic_cardset_test)class G1CardSetTest_basic_cardset_test_vm_Test : public ::testing
::Test { public: G1CardSetTest_basic_cardset_test_vm_Test() {
} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); G1CardSetTest_basic_cardset_test_vm_Test
(G1CardSetTest_basic_cardset_test_vm_Test const &) = delete
; void operator=(G1CardSetTest_basic_cardset_test_vm_Test const
&) = delete;};::testing::TestInfo* const G1CardSetTest_basic_cardset_test_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"G1CardSetTest", "basic_cardset_test_vm", __null, __null, ::
testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 482), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< G1CardSetTest_basic_cardset_test_vm_Test
>);void G1CardSetTest_basic_cardset_test_vm_Test::TestBody
()
{
483 G1CardSetTest::cardset_basic_test();
484}
485
486TEST_VM(G1CardSetTest, mt_cardset_test)class G1CardSetTest_mt_cardset_test_vm_Test : public ::testing
::Test { public: G1CardSetTest_mt_cardset_test_vm_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); G1CardSetTest_mt_cardset_test_vm_Test
(G1CardSetTest_mt_cardset_test_vm_Test const &) = delete;
void operator=(G1CardSetTest_mt_cardset_test_vm_Test const &
) = delete;};::testing::TestInfo* const G1CardSetTest_mt_cardset_test_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"G1CardSetTest", "mt_cardset_test_vm", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/gc/g1/test_g1CardSet.cpp"
, 486), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< G1CardSetTest_mt_cardset_test_vm_Test
>);void G1CardSetTest_mt_cardset_test_vm_Test::TestBody()
{
487 G1CardSetTest::cardset_mt_test();
488}