Bug Summary

File:jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp
Warning:line 221, column 3
Called C++ object pointer is null

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 g1CodeCacheRemSet.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/g1CodeCacheRemSet.cpp
1/*
2 * Copyright (c) 2014, 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 "code/codeCache.hpp"
27#include "code/nmethod.hpp"
28#include "gc/g1/g1CodeRootSetTable.hpp"
29#include "gc/g1/g1CodeCacheRemSet.hpp"
30#include "gc/g1/heapRegion.hpp"
31#include "memory/heap.hpp"
32#include "memory/iterator.hpp"
33#include "oops/access.inline.hpp"
34#include "oops/oop.inline.hpp"
35#include "runtime/atomic.hpp"
36#include "services/memTracker.hpp"
37#include "utilities/hashtable.inline.hpp"
38#include "utilities/stack.inline.hpp"
39
40G1CodeRootSetTable* volatile G1CodeRootSetTable::_purge_list = NULL__null;
41
42size_t G1CodeRootSetTable::mem_size() {
43 return sizeof(G1CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size());
44}
45
46G1CodeRootSetTable::Entry* G1CodeRootSetTable::new_entry(nmethod* nm) {
47 unsigned int hash = compute_hash(nm);
48 return (Entry*)Hashtable<nmethod*, mtGC>::new_entry(hash, nm);
49}
50
51void G1CodeRootSetTable::remove_entry(Entry* e, Entry* previous) {
52 int index = hash_to_index(e->hash());
53 assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null")do { if (!((e == bucket(index)) == (previous == __null))) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 53, "assert(" "(e == bucket(index)) == (previous == __null)"
") failed", "if e is the first entry then previous should be null"
); ::breakpoint(); } } while (0)
;
54
55 if (previous == NULL__null) {
56 set_entry(index, e->next());
57 } else {
58 previous->set_next(e->next());
59 }
60 free_entry(e);
61}
62
63G1CodeRootSetTable::~G1CodeRootSetTable() {
64 for (int index = 0; index < table_size(); ++index) {
65 for (Entry* e = bucket(index); e != NULL__null; ) {
66 Entry* to_remove = e;
67 // read next before freeing.
68 e = e->next();
69 BasicHashtable<mtGC>::free_entry(to_remove);
70 }
71 }
72 assert(number_of_entries() == 0, "should have removed all entries")do { if (!(number_of_entries() == 0)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 72, "assert(" "number_of_entries() == 0" ") failed", "should have removed all entries"
); ::breakpoint(); } } while (0)
;
73}
74
75bool G1CodeRootSetTable::add(nmethod* nm) {
76 if (!contains(nm)) {
77 Entry* e = new_entry(nm);
78 int index = hash_to_index(e->hash());
79 add_entry(index, e);
80 return true;
81 }
82 return false;
83}
84
85bool G1CodeRootSetTable::contains(nmethod* nm) {
86 int index = hash_to_index(compute_hash(nm));
87 for (Entry* e = bucket(index); e != NULL__null; e = e->next()) {
88 if (e->literal() == nm) {
89 return true;
90 }
91 }
92 return false;
93}
94
95bool G1CodeRootSetTable::remove(nmethod* nm) {
96 int index = hash_to_index(compute_hash(nm));
97 Entry* previous = NULL__null;
98 for (Entry* e = bucket(index); e != NULL__null; previous = e, e = e->next()) {
99 if (e->literal() == nm) {
100 remove_entry(e, previous);
101 return true;
102 }
103 }
104 return false;
105}
106
107void G1CodeRootSetTable::copy_to(G1CodeRootSetTable* new_table) {
108 for (int index = 0; index < table_size(); ++index) {
109 for (Entry* e = bucket(index); e != NULL__null; e = e->next()) {
110 new_table->add(e->literal());
111 }
112 }
113}
114
115void G1CodeRootSetTable::nmethods_do(CodeBlobClosure* blk) {
116 for (int index = 0; index < table_size(); ++index) {
117 for (Entry* e = bucket(index); e != NULL__null; e = e->next()) {
118 blk->do_code_blob(e->literal());
119 }
120 }
121}
122
123template<typename CB>
124int G1CodeRootSetTable::remove_if(CB& should_remove) {
125 int num_removed = 0;
126 for (int index = 0; index < table_size(); ++index) {
127 Entry* previous = NULL__null;
128 Entry* e = bucket(index);
129 while (e != NULL__null) {
130 Entry* next = e->next();
131 if (should_remove(e->literal())) {
132 remove_entry(e, previous);
133 ++num_removed;
134 } else {
135 previous = e;
136 }
137 e = next;
138 }
139 }
140 return num_removed;
141}
142
143G1CodeRootSet::~G1CodeRootSet() {
144 delete _table;
145}
146
147G1CodeRootSetTable* G1CodeRootSet::load_acquire_table() {
148 return Atomic::load_acquire(&_table);
149}
150
151void G1CodeRootSet::allocate_small_table() {
152 G1CodeRootSetTable* temp = new G1CodeRootSetTable(SmallSize);
153
154 Atomic::release_store(&_table, temp);
155}
156
157void G1CodeRootSetTable::purge_list_append(G1CodeRootSetTable* table) {
158 for (;;) {
159 table->_purge_next = _purge_list;
160 G1CodeRootSetTable* old = Atomic::cmpxchg(&_purge_list, table->_purge_next, table);
161 if (old == table->_purge_next) {
162 break;
163 }
164 }
165}
166
167void G1CodeRootSetTable::purge() {
168 G1CodeRootSetTable* table = _purge_list;
169 _purge_list = NULL__null;
170 while (table != NULL__null) {
171 G1CodeRootSetTable* to_purge = table;
172 table = table->_purge_next;
173 delete to_purge;
174 }
175}
176
177void G1CodeRootSet::move_to_large() {
178 G1CodeRootSetTable* temp = new G1CodeRootSetTable(LargeSize);
179
180 _table->copy_to(temp);
181
182 G1CodeRootSetTable::purge_list_append(_table);
183
184 Atomic::release_store(&_table, temp);
185}
186
187void G1CodeRootSet::purge() {
188 G1CodeRootSetTable::purge();
189}
190
191size_t G1CodeRootSet::static_mem_size() {
192 return G1CodeRootSetTable::static_mem_size();
193}
194
195void G1CodeRootSet::add(nmethod* method) {
196 bool added = false;
197 if (is_empty()) {
198 allocate_small_table();
199 }
200 added = _table->add(method);
201 if (added) {
202 if (_length == Threshold) {
203 move_to_large();
204 }
205 ++_length;
206 }
207 assert(_length == (size_t)_table->number_of_entries(), "sizes should match")do { if (!(_length == (size_t)_table->number_of_entries())
) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 207, "assert(" "_length == (size_t)_table->number_of_entries()"
") failed", "sizes should match"); ::breakpoint(); } } while
(0)
;
208}
209
210bool G1CodeRootSet::remove(nmethod* method) {
211 bool removed = false;
212 if (_table != NULL__null) {
1
Assuming field '_table' is equal to NULL
2
Taking false branch
213 removed = _table->remove(method);
214 }
215 if (removed
2.1
'removed' is false
) {
3
Taking false branch
216 _length--;
217 if (_length == 0) {
218 clear();
219 }
220 }
221 assert((_length == 0 && _table == NULL) ||do { if (!((_length == 0 && _table == __null) || (_length
== (size_t)_table->number_of_entries()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 222, "assert(" "(_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries())"
") failed", "sizes should match"); ::breakpoint(); } } while
(0)
4
Assuming field '_length' is not equal to 0
5
Called C++ object pointer is null
222 (_length == (size_t)_table->number_of_entries()), "sizes should match")do { if (!((_length == 0 && _table == __null) || (_length
== (size_t)_table->number_of_entries()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 222, "assert(" "(_length == 0 && _table == __null) || (_length == (size_t)_table->number_of_entries())"
") failed", "sizes should match"); ::breakpoint(); } } while
(0)
;
223 return removed;
224}
225
226bool G1CodeRootSet::contains(nmethod* method) {
227 G1CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync.
228 if (table != NULL__null) {
229 return table->contains(method);
230 }
231 return false;
232}
233
234void G1CodeRootSet::clear() {
235 delete _table;
236 _table = NULL__null;
237 _length = 0;
238}
239
240size_t G1CodeRootSet::mem_size() {
241 return sizeof(*this) + (_table != NULL__null ? _table->mem_size() : 0);
242}
243
244void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
245 if (_table != NULL__null) {
246 _table->nmethods_do(blk);
247 }
248}
249
250class CleanCallback : public StackObj {
251 class PointsIntoHRDetectionClosure : public OopClosure {
252 HeapRegion* _hr;
253 public:
254 bool _points_into;
255 PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {}
256
257 void do_oop(narrowOop* o) {
258 do_oop_work(o);
259 }
260
261 void do_oop(oop* o) {
262 do_oop_work(o);
263 }
264
265 template <typename T>
266 void do_oop_work(T* p) {
267 if (_hr->is_in(RawAccess<>::oop_load(p))) {
268 _points_into = true;
269 }
270 }
271 };
272
273 PointsIntoHRDetectionClosure _detector;
274 CodeBlobToOopClosure _blobs;
275
276 public:
277 CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {}
278
279 bool operator() (nmethod* nm) {
280 _detector._points_into = false;
281 _blobs.do_code_blob(nm);
282 return !_detector._points_into;
283 }
284};
285
286void G1CodeRootSet::clean(HeapRegion* owner) {
287 CleanCallback should_clean(owner);
288 if (_table != NULL__null) {
289 int removed = _table->remove_if(should_clean);
290 assert((size_t)removed <= _length, "impossible")do { if (!((size_t)removed <= _length)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/g1/g1CodeCacheRemSet.cpp"
, 290, "assert(" "(size_t)removed <= _length" ") failed", "impossible"
); ::breakpoint(); } } while (0)
;
291 _length -= removed;
292 }
293 if (_length == 0) {
294 clear();
295 }
296}