Bug Summary

File:jdk/src/hotspot/share/jvmci/metadataHandles.cpp
Warning:line 153, column 13
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 metadataHandles.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/jvmci/metadataHandles.cpp
1/*
2 * Copyright (c) 2019, 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 "classfile/classLoaderData.hpp"
26#include "jvmci/metadataHandles.hpp"
27#include "runtime/atomic.hpp"
28
29jmetadata MetadataHandles::allocate_metadata_handle(Metadata* obj) {
30 assert(obj->is_valid() && obj->is_metadata(), "must be")do { if (!(obj->is_valid() && obj->is_metadata(
))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 30, "assert(" "obj->is_valid() && obj->is_metadata()"
") failed", "must be"); ::breakpoint(); } } while (0)
;
31
32 if (_head == NULL__null) {
33 // This is the first allocation.
34 _head = new MetadataHandleBlock();
35 _last = _head;
36 _num_blocks++;
37 }
38
39 HandleRecord* handle = get_handle();
40
41 if (handle != NULL__null) {
42 handle->set_value(obj);
43#ifdef METADATA_TRACK_NAMES
44 handle->set_name(obj->print_value_string());
45#endif
46 return (jmetadata) handle;
47 }
48
49 // Check if an unused block follows last
50 if (_last->_next != NULL__null) {
51 // update last and retry
52 _last = _last->_next;
53 return allocate_metadata_handle(obj);
54 }
55
56 // No space available, we have to rebuild free list or expand
57 if (_allocate_before_rebuild == 0) {
58 rebuild_free_list(); // updates _allocate_before_rebuild counter
59 } else {
60 // Append new block
61 _last->_next = new MetadataHandleBlock();
62 _last = _last->_next;
63 _allocate_before_rebuild--;
64 _num_blocks++;
65 }
66 return allocate_metadata_handle(obj); // retry
67}
68
69
70void MetadataHandles::rebuild_free_list() {
71 assert(_allocate_before_rebuild == 0 && _free_list == 0, "just checking")do { if (!(_allocate_before_rebuild == 0 && _free_list
== 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 71, "assert(" "_allocate_before_rebuild == 0 && _free_list == 0"
") failed", "just checking"); ::breakpoint(); } } while (0)
;
72 int free = 0;
73 int blocks = 0;
74 for (MetadataHandleBlock* current = _head; current != NULL__null; current = current->_next) {
75 for (int index = 0; index < current->_top; index++) {
76 HandleRecord* handle = &(current->_handles)[index];
77 if (handle->value() == NULL__null) {
78 // this handle was cleared out by a delete call, reuse it
79 chain_free_list(handle);
80 free++;
81 }
82 }
83 // we should not rebuild free list if there are unused handles at the end
84 assert(current->_top == MetadataHandleBlock::block_size_in_handles, "just checking")do { if (!(current->_top == MetadataHandleBlock::block_size_in_handles
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 84, "assert(" "current->_top == MetadataHandleBlock::block_size_in_handles"
") failed", "just checking"); ::breakpoint(); } } while (0)
;
85 blocks++;
86 }
87 assert(_num_blocks == blocks, "%d != %d", _num_blocks, blocks)do { if (!(_num_blocks == blocks)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 87, "assert(" "_num_blocks == blocks" ") failed", "%d != %d"
, _num_blocks, blocks); ::breakpoint(); } } while (0)
;
88 assert(_num_free_handles == free, "%d != %d", _num_free_handles, free)do { if (!(_num_free_handles == free)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 88, "assert(" "_num_free_handles == free" ") failed", "%d != %d"
, _num_free_handles, free); ::breakpoint(); } } while (0)
;
89 // Heuristic: if more than half of the handles are NOT free we rebuild next time
90 // as well, otherwise we append a corresponding number of new blocks before
91 // attempting a free list rebuild again.
92 int total = blocks * MetadataHandleBlock::block_size_in_handles;
93 int extra = total - 2*free;
94 if (extra > 0) {
95 // Not as many free handles as we would like - compute number of new blocks to append
96 _allocate_before_rebuild = (extra + MetadataHandleBlock::block_size_in_handles - 1) / MetadataHandleBlock::block_size_in_handles;
97 }
98}
99
100void MetadataHandles::clear() {
101 _free_list = 0;
102 _last = _head;
103 if (_head != NULL__null) {
104 for (MetadataHandleBlock* block = _head; block != NULL__null; block = block->_next) {
105 block->_top = 0;
106 }
107 }
108 _num_handles = 0;
109 _num_free_handles = 0;
110}
111
112void MetadataHandles::metadata_do(void f(Metadata*)) {
113 for (MetadataHandleBlock* current = _head; current != NULL__null; current = current->_next) {
114 for (int index = 0; index < current->_top; index++) {
115 HandleRecord* root = &(current->_handles)[index];
116 Metadata* value = root->value();
117 // traverse heap pointers only, not deleted handles or free list
118 // pointers
119 if (value != NULL__null && ((intptr_t) value & ptr_tag) == 0) {
120 assert(value->is_valid(), "invalid metadata %s", current->get_name(index))do { if (!(value->is_valid())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 120, "assert(" "value->is_valid()" ") failed", "invalid metadata %s"
, current->get_name(index)); ::breakpoint(); } } while (0)
;
121 f(value);
122 }
123 }
124 // the next handle block is valid only if current block is full
125 if (current->_top < MetadataHandleBlock::block_size_in_handles) {
126 break;
127 }
128 }
129}
130
131// Visit any live metadata handles and clean them up. Since clearing of these handles is driven by
132// weak references they will be cleared at some point in the future when the reference cleaning logic is run.
133void MetadataHandles::do_unloading() {
134 for (MetadataHandleBlock* current = _head; current != NULL__null; current = current->_next) {
1
Assuming 'current' is not equal to NULL
2
Loop condition is true. Entering loop body
135 for (int index = 0; index < current->_top; index++) {
3
Assuming 'index' is < field '_top'
4
Loop condition is true. Entering loop body
136 HandleRecord* handle = &(current->_handles)[index];
137 Metadata* value = handle->value();
138 // traverse heap pointers only, not deleted handles or free list
139 // pointers
140 if (value != NULL__null && ((intptr_t) value & ptr_tag) == 0) {
5
Assuming 'value' is not equal to NULL
6
Assuming the condition is true
7
Taking true branch
141 Klass* klass = NULL__null;
8
'klass' initialized to a null pointer value
142 if (value->is_klass()) {
9
Assuming the condition is false
10
Taking false branch
143 klass = (Klass*)value;
144 } else if (value->is_method()) {
11
Assuming the condition is false
12
Taking false branch
145 Method* m = (Method*)value;
146 klass = m->method_holder();
147 } else if (value->is_constantPool()) {
13
Assuming the condition is false
14
Taking false branch
148 ConstantPool* cp = (ConstantPool*)value;
149 klass = cp->pool_holder();
150 } else {
151 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 151); ::breakpoint(); } while (0)
;
15
Loop condition is false. Exiting loop
152 }
153 if (klass->class_loader_data()->is_unloading()) {
16
Called C++ object pointer is null
154 // This needs to be marked so that it's no longer scanned
155 // but can't be put on the free list yet. The
156 // HandleCleaner will set this to NULL and
157 // put it on the free list.
158 jlong old_value = Atomic::cmpxchg((jlong*)handle, (jlong) value, (jlong) (ptr_tag));
159 if (old_value == (jlong) value) {
160 // Success
161 } else {
162 guarantee(old_value == 0, "only other possible value")do { if (!(old_value == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/jvmci/metadataHandles.cpp"
, 162, "guarantee(" "old_value == 0" ") failed", "only other possible value"
); ::breakpoint(); } } while (0)
;
163 }
164 }
165 }
166 }
167 // the next handle block is valid only if current block is full
168 if (current->_top < MetadataHandleBlock::block_size_in_handles) {
169 break;
170 }
171 }
172}