Bug Summary

File:jdk/test/hotspot/gtest/oops/test_markWord.cpp
Warning:line 97, column 8
Value stored to 'hash' 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_markWord.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/oops/test_markWord.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/vmClasses.hpp"
26#include "memory/resourceArea.hpp"
27#include "memory/universe.hpp"
28#include "oops/instanceKlass.hpp"
29#include "oops/oop.inline.hpp"
30#include "runtime/atomic.hpp"
31#include "runtime/interfaceSupport.inline.hpp"
32#include "runtime/orderAccess.hpp"
33#include "runtime/os.hpp"
34#include "runtime/synchronizer.hpp"
35#include "runtime/semaphore.inline.hpp"
36#include "threadHelper.inline.hpp"
37#include "unittest.hpp"
38#include "utilities/globalDefinitions.hpp"
39#include "utilities/ostream.hpp"
40
41// The test doesn't work for PRODUCT because it needs WizardMode
42#ifndef PRODUCT
43static bool test_pattern(stringStream* st, const char* pattern) {
44 return (strstr(st->as_string(), pattern) != NULL__null);
45}
46
47static void assert_test_pattern(Handle object, const char* pattern) {
48 stringStream st;
49 object->print_on(&st);
50 ASSERT_TRUE(test_pattern(&st, pattern))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(test_pattern(&st,
pattern))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/oops/test_markWord.cpp"
, 50, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "test_pattern(&st, pattern)", "false", "true").c_str())
= ::testing::Message()
<< pattern << " not in " << st.as_string();
51}
52
53class LockerThread : public JavaTestThread {
54 oop _obj;
55 public:
56 LockerThread(Semaphore* post, oop obj) : JavaTestThread(post), _obj(obj) {}
57 virtual ~LockerThread() {}
58
59 void main_run() {
60 JavaThread* THREAD__the_thread__ = JavaThread::current();
61 HandleMark hm(THREAD__the_thread__);
62 Handle h_obj(THREAD__the_thread__, _obj);
63 ResourceMark rm(THREAD__the_thread__);
64
65 // Wait gets the lock inflated.
66 // The object will stay locked for the context of 'ol' so the lock will
67 // still be inflated after the notify_all() call. Deflation can't happen
68 // while an ObjectMonitor is "busy" and being locked is the most "busy"
69 // state we have...
70 ObjectLocker ol(h_obj, THREAD__the_thread__);
71 ol.notify_all(THREAD__the_thread__);
72 assert_test_pattern(h_obj, "monitor");
73 }
74};
75
76
77TEST_VM(markWord, printing)class markWord_printing_vm_Test : public ::testing::Test { public
: markWord_printing_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); markWord_printing_vm_Test(markWord_printing_vm_Test
const &) = delete; void operator=(markWord_printing_vm_Test
const &) = delete;};::testing::TestInfo* const markWord_printing_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"markWord", "printing_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/oops/test_markWord.cpp"
, 77), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< markWord_printing_vm_Test>
);void markWord_printing_vm_Test::TestBody()
{
78 JavaThread* THREAD__the_thread__ = JavaThread::current();
79 ThreadInVMfromNative invm(THREAD__the_thread__);
80 ResourceMark rm(THREAD__the_thread__);
81
82 oop obj = vmClasses::Byte_klass()->allocate_instance(THREAD__the_thread__);
83
84 FlagSetting fs(WizardMode, true);
85
86 HandleMark hm(THREAD__the_thread__);
87 Handle h_obj(THREAD__the_thread__, obj);
88
89 // Thread tries to lock it.
90 {
91 ObjectLocker ol(h_obj, THREAD__the_thread__);
92 assert_test_pattern(h_obj, "locked");
93 }
94 assert_test_pattern(h_obj, "is_neutral no_hash");
95
96 // Hash the object then print it.
97 intx hash = h_obj->identity_hash();
Value stored to 'hash' during its initialization is never read
98 assert_test_pattern(h_obj, "is_neutral hash=0x");
99
100 // Wait gets the lock inflated.
101 {
102 ObjectLocker ol(h_obj, THREAD__the_thread__);
103
104 Semaphore done(0);
105 LockerThread* st;
106 st = new LockerThread(&done, h_obj());
107 st->doit();
108
109 ol.wait(THREAD__the_thread__);
110 assert_test_pattern(h_obj, "monitor");
111 done.wait_with_safepoint_check(THREAD__the_thread__); // wait till the thread is done.
112 }
113}
114#endif // PRODUCT