Bug Summary

File:jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp
Warning:line 135, column 11
Value stored to 'p2' 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_nmt_buffer_overflow_detection.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/nmt/test_nmt_buffer_overflow_detection.cpp
1/*
2 * Copyright (c) 2021 SAP SE. All rights reserved.
3 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25#include "precompiled.hpp"
26#include "memory/allocation.hpp"
27#include "runtime/os.hpp"
28#include "services/memTracker.hpp"
29#include "utilities/debug.hpp"
30#include "utilities/ostream.hpp"
31#include "unittest.hpp"
32#include "testutils.hpp"
33
34#if INCLUDE_NMT1
35
36// This prefix shows up on any c heap corruption NMT detects. If unsure which assert will
37// come, just use this one.
38#define COMMON_NMT_HEAP_CORRUPTION_MESSAGE_PREFIX"NMT corruption" "NMT corruption"
39
40
41
42#define DEFINE_TEST(test_function, expected_assertion_message)static void test_NMT_test_function_(); static void child_NMT_test_function_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_function_
(); exit(0); } class NMT_test_function_vm_assert_Test : public
::testing::Test { public: NMT_test_function_vm_assert_Test()
{} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_function_vm_assert_Test
(NMT_test_function_vm_assert_Test const &) = delete; void
operator=(NMT_test_function_vm_assert_Test const &) = delete
;};::testing::TestInfo* const NMT_test_function_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_function_vm_assert", __null, __null, ::testing::
internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 42), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_function_vm_assert_Test
>);void NMT_test_function_vm_assert_Test::TestBody() { switch
(0) case 0: default: if (::testing::internal::AlwaysTrue()) {
const ::testing::internal::RE& gtest_regex = (".*" expected_assertion_message
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_function_()", &
gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 42, &gtest_dt)) { goto gtest_label_42; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_42; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_function_(); }; gtest_dt->
Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); break
; } default: break; } } } else gtest_label_42: return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 42, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_function_() { if (MemTracker
::tracking_level() > NMT_off) { tty->print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_function (); } else { do { if (!(false)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 42, "guarantee(" "false" ") failed", "fake message ignore this - "
expected_assertion_message); ::breakpoint(); } } while (0); }
}
\
43 TEST_VM_FATAL_ERROR_MSG(NMT, test_function, ".*" expected_assertion_message ".*")static void test_NMT_test_function_(); static void child_NMT_test_function_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_function_
(); exit(0); } class NMT_test_function_vm_assert_Test : public
::testing::Test { public: NMT_test_function_vm_assert_Test()
{} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_function_vm_assert_Test
(NMT_test_function_vm_assert_Test const &) = delete; void
operator=(NMT_test_function_vm_assert_Test const &) = delete
;};::testing::TestInfo* const NMT_test_function_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_function_vm_assert", __null, __null, ::testing::
internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 43), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_function_vm_assert_Test
>);void NMT_test_function_vm_assert_Test::TestBody() { switch
(0) case 0: default: if (::testing::internal::AlwaysTrue()) {
const ::testing::internal::RE& gtest_regex = (".*" expected_assertion_message
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_function_()", &
gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 43, &gtest_dt)) { goto gtest_label_43; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_43; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_function_(); }; gtest_dt->
Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); break
; } default: break; } } } else gtest_label_43: return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 43, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_function_()
{ \
44 if (MemTracker::tracking_level() > NMT_off) { \
45 tty->print_cr("NMT overwrite death test, please ignore subsequent error dump."); \
46 test_function (); \
47 } else { \
48 /* overflow detection requires NMT to be on. If off, fake assert. */ \
49 guarantee(false, \do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 50, "guarantee(" "false" ") failed", "fake message ignore this - "
expected_assertion_message); ::breakpoint(); } } while (0)
50 "fake message ignore this - " expected_assertion_message)do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 50, "guarantee(" "false" ") failed", "fake message ignore this - "
expected_assertion_message); ::breakpoint(); } } while (0)
; \
51 } \
52 }
53
54///////
55
56static void test_overwrite_front() {
57 address p = (address) os::malloc(1, mtTest);
58 *(p - 1) = 'a';
59 os::free(p);
60}
61
62DEFINE_TEST(test_overwrite_front, "header canary broken")static void test_NMT_test_overwrite_front_(); static void child_NMT_test_overwrite_front_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_overwrite_front_
(); exit(0); } class NMT_test_overwrite_front_vm_assert_Test :
public ::testing::Test { public: NMT_test_overwrite_front_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_overwrite_front_vm_assert_Test
(NMT_test_overwrite_front_vm_assert_Test const &) = delete
; void operator=(NMT_test_overwrite_front_vm_assert_Test const
&) = delete;};::testing::TestInfo* const NMT_test_overwrite_front_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_overwrite_front_vm_assert", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 62), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_overwrite_front_vm_assert_Test
>);void NMT_test_overwrite_front_vm_assert_Test::TestBody(
) { switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::RE& gtest_regex = (".*" "header canary broken"
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_overwrite_front_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 62, &gtest_dt)) { goto gtest_label_62; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_62; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_overwrite_front_(); }; gtest_dt
->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE);
break; } default: break; } } } else gtest_label_62: return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 62, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_overwrite_front_() { if (MemTracker
::tracking_level() > NMT_off) { tty->print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_overwrite_front (); } else { do { if (!(false)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 62, "guarantee(" "false" ") failed", "fake message ignore this - "
"header canary broken"); ::breakpoint(); } } while (0); } }
63
64///////
65
66static void test_overwrite_back() {
67 address p = (address) os::malloc(1, mtTest);
68 *(p + 1) = 'a';
69 os::free(p);
70}
71
72DEFINE_TEST(test_overwrite_back, "footer canary broken")static void test_NMT_test_overwrite_back_(); static void child_NMT_test_overwrite_back_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_overwrite_back_
(); exit(0); } class NMT_test_overwrite_back_vm_assert_Test :
public ::testing::Test { public: NMT_test_overwrite_back_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_overwrite_back_vm_assert_Test
(NMT_test_overwrite_back_vm_assert_Test const &) = delete
; void operator=(NMT_test_overwrite_back_vm_assert_Test const
&) = delete;};::testing::TestInfo* const NMT_test_overwrite_back_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_overwrite_back_vm_assert", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 72), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_overwrite_back_vm_assert_Test
>);void NMT_test_overwrite_back_vm_assert_Test::TestBody()
{ switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::RE& gtest_regex = (".*" "footer canary broken"
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_overwrite_back_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 72, &gtest_dt)) { goto gtest_label_72; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_72; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_overwrite_back_(); }; gtest_dt
->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE);
break; } default: break; } } } else gtest_label_72: return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 72, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_overwrite_back_() { if (MemTracker
::tracking_level() > NMT_off) { tty->print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_overwrite_back (); } else { do { if (!(false)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 72, "guarantee(" "false" ") failed", "fake message ignore this - "
"footer canary broken"); ::breakpoint(); } } while (0); } }
73
74///////
75
76// A overwrite farther away from the NMT header; the report should show the hex dump split up
77// in two parts, containing both header and corruption site.
78static void test_overwrite_back_long(size_t distance) {
79 address p = (address) os::malloc(distance, mtTest);
80 *(p + distance) = 'a';
81 os::free(p);
82}
83static void test_overwrite_back_long_aligned_distance() { test_overwrite_back_long(0x2000); }
84DEFINE_TEST(test_overwrite_back_long_aligned_distance, "footer canary broken")static void test_NMT_test_overwrite_back_long_aligned_distance_
(); static void child_NMT_test_overwrite_back_long_aligned_distance_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_overwrite_back_long_aligned_distance_
(); exit(0); } class NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
: public ::testing::Test { public: NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
(NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
const &) = delete; void operator=(NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_overwrite_back_long_aligned_distance_vm_assert"
, __null, __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 84), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
>);void NMT_test_overwrite_back_long_aligned_distance_vm_assert_Test
::TestBody() { switch (0) case 0: default: if (::testing::internal
::AlwaysTrue()) { const ::testing::internal::RE& gtest_regex
= (".*" "footer canary broken" ".*"); ::testing::internal::DeathTest
* gtest_dt; if (!::testing::internal::DeathTest::Create("child_NMT_test_overwrite_back_long_aligned_distance_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 84, &gtest_dt)) { goto gtest_label_84; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_84; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_overwrite_back_long_aligned_distance_
(); }; gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_84: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 84, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_overwrite_back_long_aligned_distance_
() { if (MemTracker::tracking_level() > NMT_off) { tty->
print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_overwrite_back_long_aligned_distance (); } else { do {
if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 84, "guarantee(" "false" ") failed", "fake message ignore this - "
"footer canary broken"); ::breakpoint(); } } while (0); } }
85static void test_overwrite_back_long_unaligned_distance() { test_overwrite_back_long(0x2001); }
86DEFINE_TEST(test_overwrite_back_long_unaligned_distance, "footer canary broken")static void test_NMT_test_overwrite_back_long_unaligned_distance_
(); static void child_NMT_test_overwrite_back_long_unaligned_distance_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_overwrite_back_long_unaligned_distance_
(); exit(0); } class NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
: public ::testing::Test { public: NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
(NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
const &) = delete; void operator=(NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_overwrite_back_long_unaligned_distance_vm_assert"
, __null, __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 86), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
>);void NMT_test_overwrite_back_long_unaligned_distance_vm_assert_Test
::TestBody() { switch (0) case 0: default: if (::testing::internal
::AlwaysTrue()) { const ::testing::internal::RE& gtest_regex
= (".*" "footer canary broken" ".*"); ::testing::internal::DeathTest
* gtest_dt; if (!::testing::internal::DeathTest::Create("child_NMT_test_overwrite_back_long_unaligned_distance_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 86, &gtest_dt)) { goto gtest_label_86; } if (gtest_dt !=
__null) { ::testing::internal::scoped_ptr< ::testing::internal
::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt->
AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_86; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_overwrite_back_long_unaligned_distance_
(); }; gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_86: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 86, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_overwrite_back_long_unaligned_distance_
() { if (MemTracker::tracking_level() > NMT_off) { tty->
print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_overwrite_back_long_unaligned_distance (); } else { do
{ if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 86, "guarantee(" "false" ") failed", "fake message ignore this - "
"footer canary broken"); ::breakpoint(); } } while (0); } }
87
88///////
89
90static void test_double_free() {
91 address p = (address) os::malloc(1, mtTest);
92 os::free(p);
93 // Now a double free. Note that this is susceptible to concurrency issues should
94 // a concurrent thread have done a malloc and gotten the same address after the
95 // first free. To decrease chance of this happening, we repeat the double free
96 // several times.
97 for (int i = 0; i < 100; i ++) {
98 os::free(p);
99 }
100}
101
102// What assertion message we will see depends on whether the VM wipes the memory-to-be-freed
103// on the first free(), and whether the libc uses the freed memory to store bookkeeping information.
104// If the death marker in the header is still intact after the first free, we will recognize this as
105// double free; if it got wiped, we should at least see a broken header canary.
106// The message would be either
107// - "header canary broken" or
108// - "header canary dead (double free?)".
109// However, since gtest regex expressions do not support unions (a|b), I search for a reasonable
110// subset here.
111DEFINE_TEST(test_double_free, "header canary")static void test_NMT_test_double_free_(); static void child_NMT_test_double_free_
() { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_double_free_
(); exit(0); } class NMT_test_double_free_vm_assert_Test : public
::testing::Test { public: NMT_test_double_free_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_double_free_vm_assert_Test
(NMT_test_double_free_vm_assert_Test const &) = delete; void
operator=(NMT_test_double_free_vm_assert_Test const &) =
delete;};::testing::TestInfo* const NMT_test_double_free_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_double_free_vm_assert", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 111), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_double_free_vm_assert_Test
>);void NMT_test_double_free_vm_assert_Test::TestBody() { switch
(0) case 0: default: if (::testing::internal::AlwaysTrue()) {
const ::testing::internal::RE& gtest_regex = (".*" "header canary"
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_double_free_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 111, &gtest_dt)) { goto gtest_label_111; } if (gtest_dt
!= __null) { ::testing::internal::scoped_ptr< ::testing::
internal::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt
->AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_111; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_double_free_(); }; gtest_dt->
Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); break
; } default: break; } } } else gtest_label_111: return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 111, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_double_free_() { if (MemTracker
::tracking_level() > NMT_off) { tty->print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_double_free (); } else { do { if (!(false)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 111, "guarantee(" "false" ") failed", "fake message ignore this - "
"header canary"); ::breakpoint(); } } while (0); } }
112
113///////
114
115static void test_invalid_block_address() {
116 // very low, like the result of an overflow or of accessing a NULL this pointer
117 os::free((void*)0x100);
118}
119DEFINE_TEST(test_invalid_block_address, "invalid block address")static void test_NMT_test_invalid_block_address_(); static void
child_NMT_test_invalid_block_address_() { ::testing::FLAGS_gtest_throw_on_failure
= true; test_NMT_test_invalid_block_address_(); exit(0); } class
NMT_test_invalid_block_address_vm_assert_Test : public ::testing
::Test { public: NMT_test_invalid_block_address_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_invalid_block_address_vm_assert_Test
(NMT_test_invalid_block_address_vm_assert_Test const &) =
delete; void operator=(NMT_test_invalid_block_address_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_invalid_block_address_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_invalid_block_address_vm_assert", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 119), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_invalid_block_address_vm_assert_Test
>);void NMT_test_invalid_block_address_vm_assert_Test::TestBody
() { switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::RE& gtest_regex = (".*" "invalid block address"
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_invalid_block_address_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 119, &gtest_dt)) { goto gtest_label_119; } if (gtest_dt
!= __null) { ::testing::internal::scoped_ptr< ::testing::
internal::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt
->AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_119; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_invalid_block_address_(); };
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_119: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 119, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_invalid_block_address_() { if
(MemTracker::tracking_level() > NMT_off) { tty->print_cr
("NMT overwrite death test, please ignore subsequent error dump."
); test_invalid_block_address (); } else { do { if (!(false))
{ (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 119, "guarantee(" "false" ") failed", "fake message ignore this - "
"invalid block address"); ::breakpoint(); } } while (0); } }
120
121///////
122
123static void test_unaliged_block_address() {
124 address p = (address) os::malloc(1, mtTest);
125 os::free(p + 6);
126}
127DEFINE_TEST(test_unaliged_block_address, "block address is unaligned")static void test_NMT_test_unaliged_block_address_(); static void
child_NMT_test_unaliged_block_address_() { ::testing::FLAGS_gtest_throw_on_failure
= true; test_NMT_test_unaliged_block_address_(); exit(0); } class
NMT_test_unaliged_block_address_vm_assert_Test : public ::testing
::Test { public: NMT_test_unaliged_block_address_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_unaliged_block_address_vm_assert_Test
(NMT_test_unaliged_block_address_vm_assert_Test const &) =
delete; void operator=(NMT_test_unaliged_block_address_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_unaliged_block_address_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_unaliged_block_address_vm_assert", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 127), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_unaliged_block_address_vm_assert_Test
>);void NMT_test_unaliged_block_address_vm_assert_Test::TestBody
() { switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::RE& gtest_regex = (".*" "block address is unaligned"
".*"); ::testing::internal::DeathTest* gtest_dt; if (!::testing
::internal::DeathTest::Create("child_NMT_test_unaliged_block_address_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 127, &gtest_dt)) { goto gtest_label_127; } if (gtest_dt
!= __null) { ::testing::internal::scoped_ptr< ::testing::
internal::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt
->AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_127; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_unaliged_block_address_(); }
; gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_127: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 127, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_unaliged_block_address_() {
if (MemTracker::tracking_level() > NMT_off) { tty->print_cr
("NMT overwrite death test, please ignore subsequent error dump."
); test_unaliged_block_address (); } else { do { if (!(false)
) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 127, "guarantee(" "false" ") failed", "fake message ignore this - "
"block address is unaligned"); ::breakpoint(); } } while (0)
; } }
;
128
129///////
130
131// Test that we notice block corruption on realloc too
132static void test_corruption_on_realloc(size_t s1, size_t s2) {
133 address p1 = (address) os::malloc(s1, mtTest);
134 *(p1 + s1) = 'a';
135 address p2 = (address) os::realloc(p1, s2, mtTest);
Value stored to 'p2' during its initialization is never read
136
137 // Still here?
138 tty->print_cr("NMT did not detect corruption on os::realloc?");
139 // Note: don't use ASSERT here, that does not work as expected in death tests. Just
140 // let the test run its course, it should notice something is amiss.
141}
142static void test_corruption_on_realloc_growing() { test_corruption_on_realloc(0x10, 0x11); }
143DEFINE_TEST(test_corruption_on_realloc_growing, COMMON_NMT_HEAP_CORRUPTION_MESSAGE_PREFIX)static void test_NMT_test_corruption_on_realloc_growing_(); static
void child_NMT_test_corruption_on_realloc_growing_() { ::testing
::FLAGS_gtest_throw_on_failure = true; test_NMT_test_corruption_on_realloc_growing_
(); exit(0); } class NMT_test_corruption_on_realloc_growing_vm_assert_Test
: public ::testing::Test { public: NMT_test_corruption_on_realloc_growing_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_corruption_on_realloc_growing_vm_assert_Test
(NMT_test_corruption_on_realloc_growing_vm_assert_Test const &
) = delete; void operator=(NMT_test_corruption_on_realloc_growing_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_corruption_on_realloc_growing_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_corruption_on_realloc_growing_vm_assert", __null
, __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 143), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_corruption_on_realloc_growing_vm_assert_Test
>);void NMT_test_corruption_on_realloc_growing_vm_assert_Test
::TestBody() { switch (0) case 0: default: if (::testing::internal
::AlwaysTrue()) { const ::testing::internal::RE& gtest_regex
= (".*" "NMT corruption" ".*"); ::testing::internal::DeathTest
* gtest_dt; if (!::testing::internal::DeathTest::Create("child_NMT_test_corruption_on_realloc_growing_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 143, &gtest_dt)) { goto gtest_label_143; } if (gtest_dt
!= __null) { ::testing::internal::scoped_ptr< ::testing::
internal::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt
->AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_143; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_corruption_on_realloc_growing_
(); }; gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_143: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 143, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_corruption_on_realloc_growing_
() { if (MemTracker::tracking_level() > NMT_off) { tty->
print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_corruption_on_realloc_growing (); } else { do { if (!
(false)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 143, "guarantee(" "false" ") failed", "fake message ignore this - "
"NMT corruption"); ::breakpoint(); } } while (0); } }
;
144static void test_corruption_on_realloc_shrinking() { test_corruption_on_realloc(0x11, 0x10); }
145DEFINE_TEST(test_corruption_on_realloc_shrinking, COMMON_NMT_HEAP_CORRUPTION_MESSAGE_PREFIX)static void test_NMT_test_corruption_on_realloc_shrinking_();
static void child_NMT_test_corruption_on_realloc_shrinking_(
) { ::testing::FLAGS_gtest_throw_on_failure = true; test_NMT_test_corruption_on_realloc_shrinking_
(); exit(0); } class NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
: public ::testing::Test { public: NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
(NMT_test_corruption_on_realloc_shrinking_vm_assert_Test const
&) = delete; void operator=(NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
const &) = delete;};::testing::TestInfo* const NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_corruption_on_realloc_shrinking_vm_assert", __null
, __null, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 145), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
>);void NMT_test_corruption_on_realloc_shrinking_vm_assert_Test
::TestBody() { switch (0) case 0: default: if (::testing::internal
::AlwaysTrue()) { const ::testing::internal::RE& gtest_regex
= (".*" "NMT corruption" ".*"); ::testing::internal::DeathTest
* gtest_dt; if (!::testing::internal::DeathTest::Create("child_NMT_test_corruption_on_realloc_shrinking_()"
, &gtest_regex, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 145, &gtest_dt)) { goto gtest_label_145; } if (gtest_dt
!= __null) { ::testing::internal::scoped_ptr< ::testing::
internal::DeathTest> gtest_dt_ptr(gtest_dt); switch (gtest_dt
->AssumeRole()) { case ::testing::internal::DeathTest::OVERSEE_TEST
: if (!gtest_dt->Passed(::testing::ExitedWithCode(1)(gtest_dt
->Wait()))) { goto gtest_label_145; } break; case ::testing
::internal::DeathTest::EXECUTE_TEST: { ::testing::internal::DeathTest
::ReturnSentinel gtest_sentinel(gtest_dt); if (::testing::internal
::AlwaysTrue()) { child_NMT_test_corruption_on_realloc_shrinking_
(); }; gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE
); break; } default: break; } } } else gtest_label_145: return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 145, ::testing::internal::DeathTest::LastMessage()) = ::testing
::Message(); } void test_NMT_test_corruption_on_realloc_shrinking_
() { if (MemTracker::tracking_level() > NMT_off) { tty->
print_cr("NMT overwrite death test, please ignore subsequent error dump."
); test_corruption_on_realloc_shrinking (); } else { do { if (
!(false)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 145, "guarantee(" "false" ") failed", "fake message ignore this - "
"NMT corruption"); ::breakpoint(); } } while (0); } }
;
146
147///////
148
149// realloc is the trickiest of the bunch. Test that realloc works and correctly takes over
150// NMT header and footer to the resized block. We just test that nothing crashes - if the
151// header/footer get corrupted, NMT heap corruption checker will trigger alert on os::free()).
152TEST_VM(NMT, test_realloc)class NMT_test_realloc_vm_Test : public ::testing::Test { public
: NMT_test_realloc_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); NMT_test_realloc_vm_Test(NMT_test_realloc_vm_Test
const &) = delete; void operator=(NMT_test_realloc_vm_Test
const &) = delete;};::testing::TestInfo* const NMT_test_realloc_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"NMT", "test_realloc_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 152), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< NMT_test_realloc_vm_Test>)
;void NMT_test_realloc_vm_Test::TestBody()
{
153 // We test both directions (growing and shrinking) and a small range for each to cover all
154 // size alignment variants. Should not matter, but this should be cheap.
155 for (size_t s1 = 0xF0; s1 < 0x110; s1 ++) {
156 for (size_t s2 = 0x100; s2 > 0xF0; s2 --) {
157 address p1 = (address) os::malloc(s1, mtTest);
158 ASSERT_NOT_NULL(p1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p1)", "0",
p2i(p1), 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 158, gtest_ar.failure_message()) = ::testing::Message()
;
159 GtestUtils::mark_range(p1, s1); // mark payload range...
160 address p2 = (address) os::realloc(p1, s2, mtTest);
161 ASSERT_NOT_NULL(p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p2)", "0",
p2i(p2), 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 161, gtest_ar.failure_message()) = ::testing::Message()
;
162 ASSERT_RANGE_IS_MARKED(p2, MIN2(s1, s2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, MIN2(s1, s2)))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp"
, 162, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, MIN2(s1, s2))", "false", "true"
).c_str()) = ::testing::Message()
// ... and check that it survived the resize
163 << s1 << "->" << s2 << std::endl;
164 os::free(p2); // <- if NMT headers/footers got corrupted this asserts
165 }
166 }
167}
168
169#endif // INCLUDE_NMT