Bug Summary

File:jdk/src/hotspot/share/code/stubs.cpp
Warning:line 75, column 22
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 stubs.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/code/stubs.cpp
1/*
2 * Copyright (c) 1997, 2019, 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/codeBlob.hpp"
27#include "code/codeCache.hpp"
28#include "code/stubs.hpp"
29#include "memory/allocation.inline.hpp"
30#include "oops/oop.inline.hpp"
31#include "runtime/mutexLocker.hpp"
32#include "utilities/align.hpp"
33
34
35// Implementation of StubQueue
36//
37// Standard wrap-around queue implementation; the queue dimensions
38// are specified by the _queue_begin & _queue_end indices. The queue
39// can be in two states (transparent to the outside):
40//
41// a) contiguous state: all queue entries in one block (or empty)
42//
43// Queue: |...|XXXXXXX|...............|
44// ^0 ^begin ^end ^size = limit
45// |_______|
46// one block
47//
48// b) non-contiguous state: queue entries in two blocks
49//
50// Queue: |XXX|.......|XXXXXXX|.......|
51// ^0 ^end ^begin ^limit ^size
52// |___| |_______|
53// 1st block 2nd block
54//
55// In the non-contiguous state, the wrap-around point is
56// indicated via the _buffer_limit index since the last
57// queue entry may not fill up the queue completely in
58// which case we need to know where the 2nd block's end
59// is to do the proper wrap-around. When removing the
60// last entry of the 2nd block, _buffer_limit is reset
61// to _buffer_size.
62//
63// CAUTION: DO NOT MESS WITH THIS CODE IF YOU CANNOT PROVE
64// ITS CORRECTNESS! THIS CODE IS MORE SUBTLE THAN IT LOOKS!
65
66
67StubQueue::StubQueue(StubInterface* stub_interface, int buffer_size,
68 Mutex* lock, const char* name) : _mutex(lock) {
69 intptr_t size = align_up(buffer_size, 2*BytesPerWord);
70 BufferBlob* blob = BufferBlob::create(name, size);
1
'blob' initialized here
71 if( blob == NULL__null) {
2
Assuming 'blob' is equal to NULL
3
Taking true branch
72 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for %s", name)do { report_vm_out_of_memory("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 72, size, OOM_MALLOC_ERROR, "CodeCache: no room for %s", name
); ::breakpoint(); } while (0)
;
4
Loop condition is false. Exiting loop
73 }
74 _stub_interface = stub_interface;
75 _buffer_size = blob->content_size();
5
Called C++ object pointer is null
76 _buffer_limit = blob->content_size();
77 _stub_buffer = blob->content_begin();
78 _queue_begin = 0;
79 _queue_end = 0;
80 _number_of_stubs = 0;
81}
82
83
84StubQueue::~StubQueue() {
85 // Note: Currently StubQueues are never destroyed so nothing needs to be done here.
86 // If we want to implement the destructor, we need to release the BufferBlob
87 // allocated in the constructor (i.e., we need to keep it around or look it
88 // up via CodeCache::find_blob(...).
89 Unimplemented()do { (*g_assert_poison) = 'X';; report_unimplemented("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 89); ::breakpoint(); } while (0)
;
90}
91
92void StubQueue::deallocate_unused_tail() {
93 CodeBlob* blob = CodeCache::find_blob((void*)_stub_buffer);
94 CodeCache::free_unused_tail(blob, used_space());
95 // Update the limits to the new, trimmed CodeBlob size
96 _buffer_size = blob->content_size();
97 _buffer_limit = blob->content_size();
98}
99
100Stub* StubQueue::stub_containing(address pc) const {
101 if (contains(pc)) {
102 for (Stub* s = first(); s != NULL__null; s = next(s)) {
103 if (stub_contains(s, pc)) return s;
104 }
105 }
106 return NULL__null;
107}
108
109
110Stub* StubQueue::request_committed(int code_size) {
111 Stub* s = request(code_size);
112 if (s != NULL__null) commit(code_size);
113 return s;
114}
115
116
117Stub* StubQueue::request(int requested_code_size) {
118 assert(requested_code_size > 0, "requested_code_size must be > 0")do { if (!(requested_code_size > 0)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 118, "assert(" "requested_code_size > 0" ") failed", "requested_code_size must be > 0"
); ::breakpoint(); } } while (0)
;
119 if (_mutex != NULL__null) _mutex->lock_without_safepoint_check();
120 Stub* s = current_stub();
121 int requested_size = align_up(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);
122 if (requested_size <= available_space()) {
123 if (is_contiguous()) {
124 // Queue: |...|XXXXXXX|.............|
125 // ^0 ^begin ^end ^size = limit
126 assert(_buffer_limit == _buffer_size, "buffer must be fully usable")do { if (!(_buffer_limit == _buffer_size)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 126, "assert(" "_buffer_limit == _buffer_size" ") failed", "buffer must be fully usable"
); ::breakpoint(); } } while (0)
;
127 if (_queue_end + requested_size <= _buffer_size) {
128 // code fits in at the end => nothing to do
129 stub_initialize(s, requested_size);
130 return s;
131 } else {
132 // stub doesn't fit in at the queue end
133 // => reduce buffer limit & wrap around
134 assert(!is_empty(), "just checkin'")do { if (!(!is_empty())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 134, "assert(" "!is_empty()" ") failed", "just checkin'"); ::
breakpoint(); } } while (0)
;
135 _buffer_limit = _queue_end;
136 _queue_end = 0;
137 }
138 }
139 }
140 if (requested_size <= available_space()) {
141 assert(!is_contiguous(), "just checkin'")do { if (!(!is_contiguous())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 141, "assert(" "!is_contiguous()" ") failed", "just checkin'"
); ::breakpoint(); } } while (0)
;
142 assert(_buffer_limit <= _buffer_size, "queue invariant broken")do { if (!(_buffer_limit <= _buffer_size)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 142, "assert(" "_buffer_limit <= _buffer_size" ") failed"
, "queue invariant broken"); ::breakpoint(); } } while (0)
;
143 // Queue: |XXX|.......|XXXXXXX|.......|
144 // ^0 ^end ^begin ^limit ^size
145 s = current_stub();
146 stub_initialize(s, requested_size);
147 return s;
148 }
149 // Not enough space left
150 if (_mutex != NULL__null) _mutex->unlock();
151 return NULL__null;
152}
153
154
155void StubQueue::commit(int committed_code_size) {
156 assert(committed_code_size > 0, "committed_code_size must be > 0")do { if (!(committed_code_size > 0)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 156, "assert(" "committed_code_size > 0" ") failed", "committed_code_size must be > 0"
); ::breakpoint(); } } while (0)
;
157 int committed_size = align_up(stub_code_size_to_size(committed_code_size), CodeEntryAlignment);
158 Stub* s = current_stub();
159 assert(committed_size <= stub_size(s), "committed size must not exceed requested size")do { if (!(committed_size <= stub_size(s))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 159, "assert(" "committed_size <= stub_size(s)" ") failed"
, "committed size must not exceed requested size"); ::breakpoint
(); } } while (0)
;
160 stub_initialize(s, committed_size);
161 _queue_end += committed_size;
162 _number_of_stubs++;
163 if (_mutex != NULL__null) _mutex->unlock();
164 debug_only(stub_verify(s);)stub_verify(s);
165}
166
167
168void StubQueue::remove_first() {
169 if (number_of_stubs() == 0) return;
170 Stub* s = first();
171 debug_only(stub_verify(s);)stub_verify(s);
172 stub_finalize(s);
173 _queue_begin += stub_size(s);
174 assert(_queue_begin <= _buffer_limit, "sanity check")do { if (!(_queue_begin <= _buffer_limit)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 174, "assert(" "_queue_begin <= _buffer_limit" ") failed"
, "sanity check"); ::breakpoint(); } } while (0)
;
175 if (_queue_begin == _queue_end) {
176 // buffer empty
177 // => reset queue indices
178 _queue_begin = 0;
179 _queue_end = 0;
180 _buffer_limit = _buffer_size;
181 } else if (_queue_begin == _buffer_limit) {
182 // buffer limit reached
183 // => reset buffer limit & wrap around
184 _buffer_limit = _buffer_size;
185 _queue_begin = 0;
186 }
187 _number_of_stubs--;
188}
189
190
191void StubQueue::remove_first(int n) {
192 int i = MIN2(n, number_of_stubs());
193 while (i-- > 0) remove_first();
194}
195
196
197void StubQueue::remove_all(){
198 debug_only(verify();)verify();
199 remove_first(number_of_stubs());
200 assert(number_of_stubs() == 0, "sanity check")do { if (!(number_of_stubs() == 0)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 200, "assert(" "number_of_stubs() == 0" ") failed", "sanity check"
); ::breakpoint(); } } while (0)
;
201}
202
203
204void StubQueue::verify() {
205 // verify only if initialized
206 if (_stub_buffer == NULL__null) return;
207 MutexLocker lock(_mutex, Mutex::_no_safepoint_check_flag);
208 // verify index boundaries
209 guarantee(0 <= _buffer_size, "buffer size must be positive")do { if (!(0 <= _buffer_size)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 209, "guarantee(" "0 <= _buffer_size" ") failed", "buffer size must be positive"
); ::breakpoint(); } } while (0)
;
210 guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds")do { if (!(0 <= _buffer_limit && _buffer_limit <=
_buffer_size)) { (*g_assert_poison) = 'X';; report_vm_error(
"/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 210, "guarantee(" "0 <= _buffer_limit && _buffer_limit <= _buffer_size"
") failed", "_buffer_limit out of bounds"); ::breakpoint(); }
} while (0)
;
211 guarantee(0 <= _queue_begin && _queue_begin < _buffer_limit, "_queue_begin out of bounds")do { if (!(0 <= _queue_begin && _queue_begin < _buffer_limit
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 211, "guarantee(" "0 <= _queue_begin && _queue_begin < _buffer_limit"
") failed", "_queue_begin out of bounds"); ::breakpoint(); }
} while (0)
;
212 guarantee(0 <= _queue_end && _queue_end <= _buffer_limit, "_queue_end out of bounds")do { if (!(0 <= _queue_end && _queue_end <= _buffer_limit
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 212, "guarantee(" "0 <= _queue_end && _queue_end <= _buffer_limit"
") failed", "_queue_end out of bounds"); ::breakpoint(); }
} while (0)
;
213 // verify alignment
214 guarantee(_buffer_size % CodeEntryAlignment == 0, "_buffer_size not aligned")do { if (!(_buffer_size % CodeEntryAlignment == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 214, "guarantee(" "_buffer_size % CodeEntryAlignment == 0" ") failed"
, "_buffer_size not aligned"); ::breakpoint(); } } while (0)
;
215 guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned")do { if (!(_buffer_limit % CodeEntryAlignment == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 215, "guarantee(" "_buffer_limit % CodeEntryAlignment == 0"
") failed", "_buffer_limit not aligned"); ::breakpoint(); } }
while (0)
;
216 guarantee(_queue_begin % CodeEntryAlignment == 0, "_queue_begin not aligned")do { if (!(_queue_begin % CodeEntryAlignment == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 216, "guarantee(" "_queue_begin % CodeEntryAlignment == 0" ") failed"
, "_queue_begin not aligned"); ::breakpoint(); } } while (0)
;
217 guarantee(_queue_end % CodeEntryAlignment == 0, "_queue_end not aligned")do { if (!(_queue_end % CodeEntryAlignment == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 217, "guarantee(" "_queue_end % CodeEntryAlignment == 0" ") failed"
, "_queue_end not aligned"); ::breakpoint(); } } while (0)
;
218 // verify buffer limit/size relationship
219 if (is_contiguous()) {
220 guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size")do { if (!(_buffer_limit == _buffer_size)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 220, "guarantee(" "_buffer_limit == _buffer_size" ") failed"
, "_buffer_limit must equal _buffer_size"); ::breakpoint(); }
} while (0)
;
221 }
222 // verify contents
223 int n = 0;
224 for (Stub* s = first(); s != NULL__null; s = next(s)) {
225 stub_verify(s);
226 n++;
227 }
228 guarantee(n == number_of_stubs(), "number of stubs inconsistent")do { if (!(n == number_of_stubs())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 228, "guarantee(" "n == number_of_stubs()" ") failed", "number of stubs inconsistent"
); ::breakpoint(); } } while (0)
;
229 guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same")do { if (!(_queue_begin != _queue_end || n == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp"
, 229, "guarantee(" "_queue_begin != _queue_end || n == 0" ") failed"
, "buffer indices must be the same"); ::breakpoint(); } } while
(0)
;
230}
231
232
233void StubQueue::print() {
234 MutexLocker lock(_mutex, Mutex::_no_safepoint_check_flag);
235 for (Stub* s = first(); s != NULL__null; s = next(s)) {
236 stub_print(s);
237 }
238}