Bug Summary

File:jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp
Warning:line 126, column 11
Value stored to 'class_name' 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 objectSampleDescription.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/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp
1/*
2 * Copyright (c) 2017, 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 "jvm_io.h"
27#include "classfile/javaClasses.inline.hpp"
28#include "classfile/symbolTable.hpp"
29#include "classfile/vmClasses.hpp"
30#include "classfile/vmSymbols.hpp"
31#include "jfr/leakprofiler/checkpoint/objectSampleDescription.hpp"
32#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
33#include "oops/oop.inline.hpp"
34#include "runtime/fieldDescriptor.inline.hpp"
35#include "runtime/thread.hpp"
36#include "utilities/ostream.hpp"
37
38static Symbol* symbol_size = NULL__null;
39
40ObjectDescriptionBuilder::ObjectDescriptionBuilder() {
41 reset();
42}
43
44void ObjectDescriptionBuilder::write_int(jint value) {
45 char buf[20];
46 jio_snprintf(buf, sizeof(buf), "%d", value);
47 write_text(buf);
48}
49
50void ObjectDescriptionBuilder::write_text(const char* text) {
51 if (_index == sizeof(_buffer) - 2) {
52 return;
53 }
54 while (*text != '\0' && _index < sizeof(_buffer) - 2) {
55 _buffer[_index] = *text;
56 _index++;
57 text++;
58 }
59 assert(_index < sizeof(_buffer) - 1, "index should not exceed buffer size")do { if (!(_index < sizeof(_buffer) - 1)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp"
, 59, "assert(" "_index < sizeof(_buffer) - 1" ") failed",
"index should not exceed buffer size"); ::breakpoint(); } } while
(0)
;
60 // add ellipsis if we reached end
61 if (_index == sizeof(_buffer) - 2) {
62 _buffer[_index-3] = '.';
63 _buffer[_index-2] = '.';
64 _buffer[_index-1] = '.';
65 }
66 // terminate string
67 _buffer[_index] = '\0';
68}
69
70void ObjectDescriptionBuilder::reset() {
71 _index = 0;
72 _buffer[0] = '\0';
73}
74
75void ObjectDescriptionBuilder::print_description(outputStream* out) {
76 out->print("%s", (const char*)_buffer);
77}
78
79const char* ObjectDescriptionBuilder::description() {
80 if (_buffer[0] == '\0') {
81 return NULL__null;
82 }
83 const size_t len = strlen(_buffer);
84 char* copy = NEW_RESOURCE_ARRAY(char, len + 1)(char*) resource_allocate_bytes((len + 1) * sizeof(char));
85 assert(copy != NULL, "invariant")do { if (!(copy != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp"
, 85, "assert(" "copy != __null" ") failed", "invariant"); ::
breakpoint(); } } while (0)
;
86 strncpy(copy, _buffer, len + 1);
87 return copy;
88}
89
90ObjectSampleDescription::ObjectSampleDescription(oop object) :
91 _object(object) {
92}
93
94void ObjectSampleDescription::ensure_initialized() {
95 if (symbol_size == NULL__null) {
96 symbol_size = SymbolTable::new_permanent_symbol("size");
97 }
98}
99
100void ObjectSampleDescription::print_description(outputStream* out) {
101 write_object_to_buffer();
102 _description.print_description(out);
103}
104
105const char* ObjectSampleDescription::description() {
106 write_object_to_buffer();
107 return _description.description();
108}
109
110void ObjectSampleDescription::write_text(const char* text) {
111 _description.write_text(text);
112}
113
114void ObjectSampleDescription::write_int(jint value) {
115 _description.write_int(value);
116}
117
118void ObjectSampleDescription::write_object_to_buffer() {
119 ensure_initialized();
120 _description.reset();
121 write_object_details();
122}
123
124void ObjectSampleDescription::write_object_details() {
125 Klass* klass = _object->klass();
126 Symbol* class_name = klass->name();
Value stored to 'class_name' during its initialization is never read
127 jint size;
128
129 if (_object->is_a(vmClasses::Class_klass())) {
130 write_class_name();
131 return;
132 }
133
134 if (_object->is_a(vmClasses::Thread_klass())) {
135 write_thread_name();
136 return;
137 }
138
139 if (_object->is_a(vmClasses::ThreadGroup_klass())) {
140 write_thread_group_name();
141 return;
142 }
143
144 if (read_int_size(&size)) {
145 write_size(size);
146 return;
147 }
148}
149
150void ObjectSampleDescription::write_class_name() {
151 assert(_object->is_a(vmClasses::Class_klass()), "invariant")do { if (!(_object->is_a(vmClasses::Class_klass()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp"
, 151, "assert(" "_object->is_a(vmClasses::Class_klass())"
") failed", "invariant"); ::breakpoint(); } } while (0)
;
152 const Klass* const k = java_lang_Class::as_Klass(_object);
153 if (k == NULL__null) {
154 // might represent a primitive
155 const Klass* const ak = java_lang_Class::array_klass_acquire(_object);
156 // If ak is NULL, this is most likely a mirror associated with a
157 // jvmti redefine/retransform scratch klass. We can't get any additional
158 // information from it.
159 if (ak != NULL__null) {
160 write_text(type2name(java_lang_Class::primitive_type(_object)));
161 }
162 return;
163 }
164
165 if (k->is_instance_klass()) {
166 const InstanceKlass* ik = InstanceKlass::cast(k);
167 if (ik->is_hidden()) {
168 return;
169 }
170 const Symbol* name = ik->name();
171 if (name != NULL__null) {
172 write_text("Class Name: ");
173 write_text(name->as_klass_external_name());
174 }
175 }
176}
177
178void ObjectSampleDescription::write_thread_group_name() {
179 assert(_object->is_a(vmClasses::ThreadGroup_klass()), "invariant")do { if (!(_object->is_a(vmClasses::ThreadGroup_klass())))
{ (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp"
, 179, "assert(" "_object->is_a(vmClasses::ThreadGroup_klass())"
") failed", "invariant"); ::breakpoint(); } } while (0)
;
180 const char* tg_name = java_lang_ThreadGroup::name(_object);
181 if (tg_name != NULL__null) {
182 write_text("Thread Group: ");
183 write_text(tg_name);
184 }
185}
186
187void ObjectSampleDescription::write_thread_name() {
188 assert(_object->is_a(vmClasses::Thread_klass()), "invariant")do { if (!(_object->is_a(vmClasses::Thread_klass()))) { (*
g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleDescription.cpp"
, 188, "assert(" "_object->is_a(vmClasses::Thread_klass())"
") failed", "invariant"); ::breakpoint(); } } while (0)
;
189 oop name = java_lang_Thread::name(_object);
190 if (name != NULL__null) {
191 char* p = java_lang_String::as_utf8_string(name);
192 if (p != NULL__null) {
193 write_text("Thread Name: ");
194 write_text(p);
195 }
196 }
197}
198
199void ObjectSampleDescription::write_size(jint size) {
200 if (size >= 0) {
201 write_text("Size: ");
202 write_int(size);
203 }
204}
205
206bool ObjectSampleDescription::read_int_size(jint* result_size) {
207 fieldDescriptor fd;
208 Klass* klass = _object->klass();
209 if (klass->is_instance_klass()) {
210 InstanceKlass* ik = InstanceKlass::cast(klass);
211 if (ik->find_field(symbol_size, vmSymbols::int_signature(), false, &fd) != NULL__null) {
212 jint size = _object->int_field(fd.offset());
213 *result_size = size;
214 return true;
215 }
216 }
217 return false;
218}