Bug Summary

File:jdk/test/hotspot/gtest/memory/test_arena.cpp
Warning:line 361, column 9
Value stored to 'p' 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_arena.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/memory/test_arena.cpp
1/*
2 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2021 SAP SE. All rights reserved.
4 *
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 *
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#include "precompiled.hpp"
27#include "memory/arena.hpp"
28#include "runtime/os.hpp"
29#include "utilities/align.hpp"
30#include "utilities/globalDefinitions.hpp"
31#include "unittest.hpp"
32#include "testutils.hpp"
33
34#define ASSERT_CONTAINS(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ar.contains(p))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 34, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
()
ASSERT_TRUE(ar.contains(p))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ar.contains(p))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 34, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
()
35
36// Note:
37// - Amalloc returns 64bit aligned pointer (also on 32-bit)
38// - AmallocWords returns word-aligned pointer
39#define ASSERT_ALIGN_AMALLOC(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 39, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message()
ASSERT_ALIGN(p, ARENA_AMALLOC_ALIGNMENT)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 39, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message()
40#define ASSERT_ALIGN_AMALLOCWORDS(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerWords
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 40, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerWords)", "false", "true").c_str()) =
::testing::Message()
ASSERT_ALIGN(p, BytesPerWords)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerWords
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 40, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerWords)", "false", "true").c_str()) =
::testing::Message()
41
42// Do a couple of checks on the return of a successful Amalloc
43#define ASSERT_AMALLOC(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 43, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p))) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 43, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 43, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message();
\
44 ASSERT_NOT_NULL(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 44, gtest_ar.failure_message()) = ::testing::Message()
; \
45 ASSERT_CONTAINS(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ar.contains(p))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 45, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
()
; \
46 ASSERT_ALIGN_AMALLOC(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 46, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message()
;
47
48// #define LOG(s) tty->print_cr s;
49#define LOG(s)
50
51// Test behavior for Amalloc(0).
52// Amalloc just ignores Amalloc(0) and returns the current hwm without increasing it.
53// Therefore, the returned pointer should be not null, aligned, but not (!) contained
54// in the arena since hwm points beyond the arena.
55TEST_VM(Arena, alloc_size_0)class Arena_alloc_size_0_vm_Test : public ::testing::Test { public
: Arena_alloc_size_0_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_alloc_size_0_vm_Test(Arena_alloc_size_0_vm_Test
const &) = delete; void operator=(Arena_alloc_size_0_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_alloc_size_0_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "alloc_size_0_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 55), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_alloc_size_0_vm_Test>
);void Arena_alloc_size_0_vm_Test::TestBody()
{
56 Arena ar(mtTest);
57 void* p = ar.Amalloc(0);
58 ASSERT_NOT_NULL(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 58, gtest_ar.failure_message()) = ::testing::Message()
;
59 ASSERT_ALIGN_AMALLOC(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 59, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message()
;
60 if (!UseMallocOnly) {
61 // contains works differently for malloced mode (and there its broken anyway)
62 ASSERT_FALSE(ar.contains(p))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ar.contains(p)))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 62, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "true", "false").c_str()) = ::testing::Message
()
;
63 }
64 // Allocate again. The new allocations should have the same position as the 0-sized
65 // first one.
66 if (!UseMallocOnly) {
67 void* p2 = ar.Amalloc(1);
68 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 68, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p2))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 68, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p2)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p2, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 68, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p2, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
69 ASSERT_EQ(p2, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p2)) == 1)>::Compare("p2",
"p", p2, p))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 69, gtest_ar.failure_message()) = ::testing::Message()
;
70 }
71}
72
73// Test behavior for Arealloc(p, 0)
74TEST_VM(Arena, realloc_size_0)class Arena_realloc_size_0_vm_Test : public ::testing::Test {
public: Arena_realloc_size_0_vm_Test() {} private: virtual void
TestBody(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_realloc_size_0_vm_Test(Arena_realloc_size_0_vm_Test
const &) = delete; void operator=(Arena_realloc_size_0_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_realloc_size_0_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_size_0_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 74), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_size_0_vm_Test>
);void Arena_realloc_size_0_vm_Test::TestBody()
{
75 // Arealloc(p, 0) behaves like Afree(p). It should release the memory
76 // and, if top position, roll back the hwm.
77 Arena ar(mtTest);
78 void* p1 = ar.Amalloc(0x10);
79 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 79, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 79, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 79, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
80 void* p2 = ar.Arealloc(p1, 0x10, 0);
81 ASSERT_NULL(p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p2i(p2))) == 1)>::Compare(
"p2i(p2)", "0", p2i(p2), 0))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 81, gtest_ar.failure_message()) = ::testing::Message()
;
82
83 // a subsequent allocation should get the same pointer
84 if (!UseMallocOnly) {
85 void* p3 = ar.Amalloc(0x20);
86 ASSERT_EQ(p3, p1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p3)) == 1)>::Compare("p3",
"p1", p3, p1))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 86, gtest_ar.failure_message()) = ::testing::Message()
;
87 }
88}
89
90// Realloc equal sizes is a noop
91TEST_VM(Arena, realloc_same_size)class Arena_realloc_same_size_vm_Test : public ::testing::Test
{ public: Arena_realloc_same_size_vm_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_realloc_same_size_vm_Test(Arena_realloc_same_size_vm_Test
const &) = delete; void operator=(Arena_realloc_same_size_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_realloc_same_size_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_same_size_vm", __null, __null, ::testing::
internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 91), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_same_size_vm_Test
>);void Arena_realloc_same_size_vm_Test::TestBody()
{
92 Arena ar(mtTest);
93 void* p1 = ar.Amalloc(0x200);
94 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 94, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
95 GtestUtils::mark_range(p1, 0x200);
96
97 void* p2 = ar.Arealloc(p1, 0x200, 0x200);
98
99 if (!UseMallocOnly) {
100 ASSERT_EQ(p2, p1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p2)) == 1)>::Compare("p2",
"p1", p2, p1))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 100, gtest_ar.failure_message()) = ::testing::Message()
;
101 }
102 ASSERT_RANGE_IS_MARKED(p2, 0x200)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, 0x200))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 102, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, 0x200)", "false", "true").c_str
()) = ::testing::Message()
;
103}
104
105// Test behavior for Afree(NULL) and Arealloc(NULL, x)
106TEST_VM(Arena, free_null)class Arena_free_null_vm_Test : public ::testing::Test { public
: Arena_free_null_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_free_null_vm_Test(Arena_free_null_vm_Test const
&) = delete; void operator=(Arena_free_null_vm_Test const
&) = delete;};::testing::TestInfo* const Arena_free_null_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "free_null_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 106), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_free_null_vm_Test>);
void Arena_free_null_vm_Test::TestBody()
{
107 Arena ar(mtTest);
108 ar.Afree(NULL__null, 10); // should just be ignored
109}
110
111TEST_VM(Arena, realloc_null)class Arena_realloc_null_vm_Test : public ::testing::Test { public
: Arena_realloc_null_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_realloc_null_vm_Test(Arena_realloc_null_vm_Test
const &) = delete; void operator=(Arena_realloc_null_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_realloc_null_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_null_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 111), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_null_vm_Test>
);void Arena_realloc_null_vm_Test::TestBody()
{
112 Arena ar(mtTest);
113 void* p = ar.Arealloc(NULL__null, 0, 20); // equivalent to Amalloc(20)
114 ASSERT_AMALLOC(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 114, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p))) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 114, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 114, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message();
;
115}
116
117// Check Arena.Afree in a non-top position.
118// The free'd allocation should be zapped (debug only),
119// surrounding blocks should be unaffected.
120TEST_VM(Arena, free_nontop)class Arena_free_nontop_vm_Test : public ::testing::Test { public
: Arena_free_nontop_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_free_nontop_vm_Test(Arena_free_nontop_vm_Test
const &) = delete; void operator=(Arena_free_nontop_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_free_nontop_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "free_nontop_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 120), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_free_nontop_vm_Test>
);void Arena_free_nontop_vm_Test::TestBody()
{
121 Arena ar(mtTest);
122
123 void* p_before = ar.Amalloc(0x10);
124 ASSERT_AMALLOC(ar, p_before)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p_before)"
, "0", p2i(p_before), 0))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 124, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p_before))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 124, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p_before)", "false", "true").c_str()) = ::testing
::Message(); switch (0) case 0: default: if (const ::testing::
AssertionResult gtest_ar_ = ::testing::AssertionResult(is_aligned
(p_before, BytesPerLong))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 124, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p_before, BytesPerLong)", "false", "true").c_str
()) = ::testing::Message();
;
125 GtestUtils::mark_range(p_before, 0x10);
126
127 void* p = ar.Amalloc(0x10);
128 ASSERT_AMALLOC(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 128, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p))) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 128, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 128, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message();
;
129 GtestUtils::mark_range_with(p, 0x10, 'Z');
130
131 void* p_after = ar.Amalloc(0x10);
132 ASSERT_AMALLOC(ar, p_after)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p_after)",
"0", p2i(p_after), 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 132, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p_after))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 132, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p_after)", "false", "true").c_str()) = ::testing
::Message(); switch (0) case 0: default: if (const ::testing::
AssertionResult gtest_ar_ = ::testing::AssertionResult(is_aligned
(p_after, BytesPerLong))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 132, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p_after, BytesPerLong)", "false", "true").c_str
()) = ::testing::Message();
;
133 GtestUtils::mark_range(p_after, 0x10);
134
135 ASSERT_RANGE_IS_MARKED(p_before, 0x10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p_before, 0x10))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 135, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p_before, 0x10)", "false", "true")
.c_str()) = ::testing::Message()
;
136 ASSERT_RANGE_IS_MARKED_WITH(p, 0x10, 'Z')switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p, 0x10, 'Z'))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 136, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p, 0x10, 'Z')", "false", "true").c_str
()) = ::testing::Message()
;
137 ASSERT_RANGE_IS_MARKED(p_after, 0x10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p_after, 0x10))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 137, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p_after, 0x10)", "false", "true").
c_str()) = ::testing::Message()
;
138
139 ar.Afree(p, 0x10);
140
141 ASSERT_RANGE_IS_MARKED(p_before, 0x10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p_before, 0x10))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p_before, 0x10)", "false", "true")
.c_str()) = ::testing::Message()
;
142 DEBUG_ONLY(ASSERT_RANGE_IS_MARKED_WITH(p, 0x10, badResourceValue);)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p, 0x10, badResourceValue))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 142, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p, 0x10, badResourceValue)", "false"
, "true").c_str()) = ::testing::Message();
143 ASSERT_RANGE_IS_MARKED(p_after, 0x10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p_after, 0x10))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p_after, 0x10)", "false", "true").
c_str()) = ::testing::Message()
;
144}
145
146// Check Arena.Afree in a top position.
147// The free'd allocation (non-top) should be zapped (debug only),
148// the hwm should have been rolled back.
149TEST_VM(Arena, free_top)class Arena_free_top_vm_Test : public ::testing::Test { public
: Arena_free_top_vm_Test() {} private: virtual void TestBody(
); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_free_top_vm_Test(Arena_free_top_vm_Test const
&) = delete; void operator=(Arena_free_top_vm_Test const
&) = delete;};::testing::TestInfo* const Arena_free_top_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "free_top_vm", __null, __null, ::testing::internal::
CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 149), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_free_top_vm_Test>);void
Arena_free_top_vm_Test::TestBody()
{
150 Arena ar(mtTest);
151
152 void* p = ar.Amalloc(0x10);
153 ASSERT_AMALLOC(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 153, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p))) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 153, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 153, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, BytesPerLong)", "false", "true").c_str()) = ::
testing::Message();
;
154 GtestUtils::mark_range_with(p, 0x10, 'Z');
155
156 ar.Afree(p, 0x10);
157 DEBUG_ONLY(ASSERT_RANGE_IS_MARKED_WITH(p, 0x10, badResourceValue);)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p, 0x10, badResourceValue))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 157, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p, 0x10, badResourceValue)", "false"
, "true").c_str()) = ::testing::Message();
158
159 // a subsequent allocation should get the same pointer
160 if (!UseMallocOnly) {
161 void* p2 = ar.Amalloc(0x20);
162 ASSERT_EQ(p2, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p2)) == 1)>::Compare("p2",
"p", p2, p))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 162, gtest_ar.failure_message()) = ::testing::Message()
;
163 }
164}
165
166// In-place shrinking.
167TEST_VM(Arena, realloc_top_shrink)class Arena_realloc_top_shrink_vm_Test : public ::testing::Test
{ public: Arena_realloc_top_shrink_vm_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_realloc_top_shrink_vm_Test(Arena_realloc_top_shrink_vm_Test
const &) = delete; void operator=(Arena_realloc_top_shrink_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_realloc_top_shrink_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_top_shrink_vm", __null, __null, ::testing::
internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 167), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_top_shrink_vm_Test
>);void Arena_realloc_top_shrink_vm_Test::TestBody()
{
168 if (!UseMallocOnly) {
169 Arena ar(mtTest);
170
171 void* p1 = ar.Amalloc(0x200);
172 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 172, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 172, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 172, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
173 GtestUtils::mark_range(p1, 0x200);
174
175 void* p2 = ar.Arealloc(p1, 0x200, 0x100);
176 ASSERT_EQ(p1, p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p1)) == 1)>::Compare("p1",
"p2", p1, p2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 176, gtest_ar.failure_message()) = ::testing::Message()
;
177 ASSERT_RANGE_IS_MARKED(p2, 0x100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, 0x100))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 177, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, 0x100)", "false", "true").c_str
()) = ::testing::Message()
; // realloc should preserve old content
178
179 // A subsequent allocation should be placed right after the end of the first, shrunk, allocation
180 void* p3 = ar.Amalloc(1);
181 ASSERT_EQ(p3, ((char*)p1) + 0x100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p3)) == 1)>::Compare("p3",
"((char*)p1) + 0x100", p3, ((char*)p1) + 0x100))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 181, gtest_ar.failure_message()) = ::testing::Message()
;
182 }
183}
184
185// not-in-place shrinking.
186TEST_VM(Arena, realloc_nontop_shrink)class Arena_realloc_nontop_shrink_vm_Test : public ::testing::
Test { public: Arena_realloc_nontop_shrink_vm_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_realloc_nontop_shrink_vm_Test
(Arena_realloc_nontop_shrink_vm_Test const &) = delete; void
operator=(Arena_realloc_nontop_shrink_vm_Test const &) =
delete;};::testing::TestInfo* const Arena_realloc_nontop_shrink_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_nontop_shrink_vm", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 186), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_nontop_shrink_vm_Test
>);void Arena_realloc_nontop_shrink_vm_Test::TestBody()
{
187 Arena ar(mtTest);
188
189 void* p1 = ar.Amalloc(200);
190 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 190, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
191 GtestUtils::mark_range(p1, 200);
192
193 void* p_other = ar.Amalloc(20); // new top, p1 not top anymore
194
195 void* p2 = ar.Arealloc(p1, 200, 100);
196 if (!UseMallocOnly) {
197 ASSERT_EQ(p1, p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p1)) == 1)>::Compare("p1",
"p2", p1, p2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 197, gtest_ar.failure_message()) = ::testing::Message()
; // should still shrink in place
198 }
199 ASSERT_RANGE_IS_MARKED(p2, 100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, 100))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 199, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, 100)", "false", "true").c_str(
)) = ::testing::Message()
; // realloc should preserve old content
200}
201
202// in-place growing.
203TEST_VM(Arena, realloc_top_grow)class Arena_realloc_top_grow_vm_Test : public ::testing::Test
{ public: Arena_realloc_top_grow_vm_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_realloc_top_grow_vm_Test(Arena_realloc_top_grow_vm_Test
const &) = delete; void operator=(Arena_realloc_top_grow_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_realloc_top_grow_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_top_grow_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 203), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_top_grow_vm_Test
>);void Arena_realloc_top_grow_vm_Test::TestBody()
{
204 Arena ar(mtTest); // initial chunk size large enough to ensure below allocation grows in-place.
205
206 void* p1 = ar.Amalloc(0x10);
207 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 207, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
208 GtestUtils::mark_range(p1, 0x10);
209
210 void* p2 = ar.Arealloc(p1, 0x10, 0x20);
211 if (!UseMallocOnly) {
212 ASSERT_EQ(p1, p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p1)) == 1)>::Compare("p1",
"p2", p1, p2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 212, gtest_ar.failure_message()) = ::testing::Message()
;
213 }
214 ASSERT_RANGE_IS_MARKED(p2, 0x10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, 0x10))) ; else return ::testing::internal::AssertHelper(
::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, 0x10)", "false", "true").c_str
()) = ::testing::Message()
; // realloc should preserve old content
215}
216
217// not-in-place growing.
218TEST_VM(Arena, realloc_nontop_grow)class Arena_realloc_nontop_grow_vm_Test : public ::testing::Test
{ public: Arena_realloc_nontop_grow_vm_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_realloc_nontop_grow_vm_Test(
Arena_realloc_nontop_grow_vm_Test const &) = delete; void
operator=(Arena_realloc_nontop_grow_vm_Test const &) = delete
;};::testing::TestInfo* const Arena_realloc_nontop_grow_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "realloc_nontop_grow_vm", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 218), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_realloc_nontop_grow_vm_Test
>);void Arena_realloc_nontop_grow_vm_Test::TestBody()
{
219 Arena ar(mtTest);
220
221 void* p1 = ar.Amalloc(10);
222 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 222, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p1))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p1)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
223 GtestUtils::mark_range(p1, 10);
224
225 void* p_other = ar.Amalloc(20); // new top, p1 not top anymore
226
227 void* p2 = ar.Arealloc(p1, 10, 20);
228 ASSERT_AMALLOC(ar, 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/memory/test_arena.cpp"
, 228, gtest_ar.failure_message()) = ::testing::Message(); switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar_
= ::testing::AssertionResult(ar.contains(p2))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 228, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p2)", "false", "true").c_str()) = ::testing::Message
(); switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p2, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 228, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p2, BytesPerLong)", "false", "true").c_str()) =
::testing::Message();
;
229 ASSERT_RANGE_IS_MARKED(p2, 10)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, 10))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 229, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, 10)", "false", "true").c_str()
) = ::testing::Message()
; // realloc should preserve old content
230}
231
232// -------- random alloc test -------------
233
234static uint8_t canary(int i) {
235 return (uint8_t)('A' + i % 26);
236}
237
238// Randomly allocate and reallocate with random sizes and differing alignments;
239// check alignment; check for overwriters.
240// We do this a number of times, to give chunk pool handling a good workout too.
241TEST_VM(Arena, random_allocs)class Arena_random_allocs_vm_Test : public ::testing::Test { public
: Arena_random_allocs_vm_Test() {} private: virtual void TestBody
(); static ::testing::TestInfo* const test_info_ __attribute__
((unused)); Arena_random_allocs_vm_Test(Arena_random_allocs_vm_Test
const &) = delete; void operator=(Arena_random_allocs_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_random_allocs_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "random_allocs_vm", __null, __null, ::testing::internal
::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 241), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_random_allocs_vm_Test>
);void Arena_random_allocs_vm_Test::TestBody()
{
242
243 const int num_allocs = 250 * 1000;
244 const int avg_alloc_size = 64;
245
246 void** ptrs = NEW_C_HEAP_ARRAY(void*, num_allocs, mtTest)(void**) (AllocateHeap((num_allocs) * sizeof(void*), mtTest));
247 size_t* sizes = NEW_C_HEAP_ARRAY(size_t, num_allocs, mtTest)(size_t*) (AllocateHeap((num_allocs) * sizeof(size_t), mtTest
))
;
248 size_t* alignments = NEW_C_HEAP_ARRAY(size_t, num_allocs, mtTest)(size_t*) (AllocateHeap((num_allocs) * sizeof(size_t), mtTest
))
;
249
250 Arena ar(mtTest);
251
252 // Allocate
253 for (int i = 0; i < num_allocs; i ++) {
254 size_t size = os::random() % (avg_alloc_size * 2); // Note: size==0 is okay; we want to test that too
255 size_t alignment = 0;
256 void* p = NULL__null;
257 if (os::random() % 2) { // randomly switch between Amalloc and AmallocWords
258 p = ar.Amalloc(size);
259 alignment = BytesPerLong;
260 } else {
261 // Inconsistency: AmallocWords wants its input size word aligned, whereas Amalloc takes
262 // care of alignment itself. We may want to clean this up, but for now just go with it.
263 size = align_up(size, BytesPerWord);
264 p = ar.AmallocWords(size);
265 alignment = BytesPerWord;
266 }
267 LOG(("[%d]: " PTR_FORMAT ", size " SIZE_FORMAT ", aligned " SIZE_FORMAT,
268 i, p2i(p), size, alignment));
269 ASSERT_NOT_NULL(p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("p2i(p)", "0", p2i
(p), 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 269, gtest_ar.failure_message()) = ::testing::Message()
;
270 ASSERT_ALIGN(p, alignment)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p, alignment
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p, alignment)", "false", "true").c_str()) = ::testing
::Message()
;
271 if (size > 0) {
272 ASSERT_CONTAINS(ar, p)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ar.contains(p))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p)", "false", "true").c_str()) = ::testing::Message
()
;
273 }
274 GtestUtils::mark_range_with(p, size, canary(i));
275 ptrs[i] = p; sizes[i] = size; alignments[i] = alignment;
276 }
277
278 // Check pattern in allocations for overwriters.
279 for (int i = 0; i < num_allocs; i ++) {
280 ASSERT_RANGE_IS_MARKED_WITH(ptrs[i], sizes[i], canary(i))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(ptrs[i], sizes[i], canary(i)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 280, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(ptrs[i], sizes[i], canary(i))", "false"
, "true").c_str()) = ::testing::Message()
;
281 }
282
283 // realloc all of them
284 for (int i = 0; i < num_allocs; i ++) {
285 size_t new_size = os::random() % (avg_alloc_size * 2); // Note: 0 is possible and should work
286 void* p2 = ar.Arealloc(ptrs[i], sizes[i], new_size);
287 if (new_size > 0) {
288 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/memory/test_arena.cpp"
, 288, gtest_ar.failure_message()) = ::testing::Message()
;
289 ASSERT_CONTAINS(ar, p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ar.contains(p2))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ar.contains(p2)", "false", "true").c_str()) = ::testing::Message
()
;
290 ASSERT_ALIGN(p2, alignments[i])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p2, alignments
[i]))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p2, alignments[i])", "false", "true").c_str()) =
::testing::Message()
; // Realloc guarantees at least the original alignment
291 ASSERT_RANGE_IS_MARKED_WITH(p2, MIN2(sizes[i], new_size), canary(i))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(p2, MIN2(sizes[i], new_size), canary(i)))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(p2, MIN2(sizes[i], new_size), canary(i))"
, "false", "true").c_str()) = ::testing::Message()
; // old content should have been preserved
292
293 GtestUtils::mark_range_with(p2, new_size, canary(i)); // mark new range with canary
294 } else {
295 ASSERT_NULL(p2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(p2i(p2))) == 1)>::Compare(
"p2i(p2)", "0", p2i(p2), 0))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 295, gtest_ar.failure_message()) = ::testing::Message()
;
296 }
297 ptrs[i] = p2; sizes[i] = new_size;
298 LOG(("[%d]: realloc " PTR_FORMAT ", size " SIZE_FORMAT ", aligned " SIZE_FORMAT,
299 i, p2i(p2), new_size, alignments[i]));
300 }
301
302 // Check test pattern again
303 // Note that we don't check the gap pattern anymore since if allocations had been shrunk in place
304 // this now gets difficult.
305 for (int i = 0; i < num_allocs; i ++) {
306 ASSERT_RANGE_IS_MARKED_WITH(ptrs[i], sizes[i], canary(i))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(ptrs[i], sizes[i], canary(i)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 306, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(ptrs[i], sizes[i], canary(i))", "false"
, "true").c_str()) = ::testing::Message()
;
307 }
308
309 // Randomly free a bunch of allocations.
310 for (int i = 0; i < num_allocs; i ++) {
311 if (os::random() % 10 == 0) {
312 ar.Afree(ptrs[i], sizes[i]);
313 // In debug builds the freed space should be filled the space with badResourceValue
314 DEBUG_ONLY(ASSERT_RANGE_IS_MARKED_WITH(ptrs[i], sizes[i], badResourceValue))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(ptrs[i], sizes[i], badResourceValue))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(ptrs[i], sizes[i], badResourceValue)"
, "false", "true").c_str()) = ::testing::Message()
;
315 ptrs[i] = NULL__null;
316 }
317 }
318
319 // Check test pattern again
320 for (int i = 0; i < num_allocs; i ++) {
321 ASSERT_RANGE_IS_MARKED_WITH(ptrs[i], sizes[i], canary(i))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(GtestUtils::check_range
(ptrs[i], sizes[i], canary(i)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 321, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "GtestUtils::check_range(ptrs[i], sizes[i], canary(i))", "false"
, "true").c_str()) = ::testing::Message()
;
322 }
323
324 // Free temp data
325 FREE_C_HEAP_ARRAY(char*, ptrs)FreeHeap((char*)(ptrs));
326 FREE_C_HEAP_ARRAY(size_t, sizes)FreeHeap((char*)(sizes));
327 FREE_C_HEAP_ARRAY(size_t, alignments)FreeHeap((char*)(alignments));
328}
329
330#ifndef LP64
331// These tests below are about alignment issues when mixing Amalloc and AmallocWords.
332// Since on 64-bit these APIs offer the same alignment, they only matter for 32-bit.
333
334TEST_VM(Arena, mixed_alignment_allocation)class Arena_mixed_alignment_allocation_vm_Test : public ::testing
::Test { public: Arena_mixed_alignment_allocation_vm_Test() {
} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); Arena_mixed_alignment_allocation_vm_Test
(Arena_mixed_alignment_allocation_vm_Test const &) = delete
; void operator=(Arena_mixed_alignment_allocation_vm_Test const
&) = delete;};::testing::TestInfo* const Arena_mixed_alignment_allocation_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "mixed_alignment_allocation_vm", __null, __null, ::
testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 334), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_mixed_alignment_allocation_vm_Test
>);void Arena_mixed_alignment_allocation_vm_Test::TestBody
()
{
335 // Test that mixed alignment allocations work and provide allocations with the correct
336 // alignment
337 Arena ar(mtTest);
338 void* p1 = ar.AmallocWords(BytesPerWord);
339 void* p2 = ar.Amalloc(BytesPerLong);
340 ASSERT_TRUE(is_aligned(p1, BytesPerWord))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerWord
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerWord)", "false", "true").c_str()) =
::testing::Message()
;
341 ASSERT_TRUE(is_aligned(p2, ARENA_AMALLOC_ALIGNMENT))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p2, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p2, ARENA_AMALLOC_ALIGNMENT)", "false", "true")
.c_str()) = ::testing::Message()
;
342}
343
344TEST_VM(Arena, Arena_with_crooked_initial_size)class Arena_Arena_with_crooked_initial_size_vm_Test : public ::
testing::Test { public: Arena_Arena_with_crooked_initial_size_vm_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); Arena_Arena_with_crooked_initial_size_vm_Test
(Arena_Arena_with_crooked_initial_size_vm_Test const &) =
delete; void operator=(Arena_Arena_with_crooked_initial_size_vm_Test
const &) = delete;};::testing::TestInfo* const Arena_Arena_with_crooked_initial_size_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "Arena_with_crooked_initial_size_vm", __null, __null
, ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 344), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_Arena_with_crooked_initial_size_vm_Test
>);void Arena_Arena_with_crooked_initial_size_vm_Test::TestBody
()
{
345 // Test that an arena with a crooked, not 64-bit aligned initial size
346 // works
347 Arena ar(mtTest, 4097);
348 void* p1 = ar.AmallocWords(BytesPerWord);
349 void* p2 = ar.Amalloc(BytesPerLong);
350 ASSERT_TRUE(is_aligned(p1, BytesPerWord))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p1, BytesPerWord
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p1, BytesPerWord)", "false", "true").c_str()) =
::testing::Message()
;
351 ASSERT_TRUE(is_aligned(p2, ARENA_AMALLOC_ALIGNMENT))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(is_aligned(p2, BytesPerLong
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "is_aligned(p2, ARENA_AMALLOC_ALIGNMENT)", "false", "true")
.c_str()) = ::testing::Message()
;
352}
353
354TEST_VM(Arena, Arena_grows_large_unaligned)class Arena_Arena_grows_large_unaligned_vm_Test : public ::testing
::Test { public: Arena_Arena_grows_large_unaligned_vm_Test() {
} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); Arena_Arena_grows_large_unaligned_vm_Test
(Arena_Arena_grows_large_unaligned_vm_Test const &) = delete
; void operator=(Arena_Arena_grows_large_unaligned_vm_Test const
&) = delete;};::testing::TestInfo* const Arena_Arena_grows_large_unaligned_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "Arena_grows_large_unaligned_vm", __null, __null, ::
testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 354), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_Arena_grows_large_unaligned_vm_Test
>);void Arena_Arena_grows_large_unaligned_vm_Test::TestBody
()
{
355 // Test that if the arena grows with a large unaligned value, nothing bad happens.
356 // We trigger allocation of a new, large, unaligned chunk with a non-standard size
357 // (only possible on 32-bit when allocating with word alignment).
358 // Then we alloc some more. If Arena::grow() does not correctly align, on 32-bit
359 // something should assert at some point.
360 Arena ar(mtTest, 100); // first chunk is small
361 void* p = ar.AmallocWords(Chunk::size + BytesPerWord); // if Arena::grow() misaligns, this asserts
Value stored to 'p' during its initialization is never read
362 // some more allocations for good measure
363 for (int i = 0; i < 100; i ++) {
364 ar.Amalloc(1);
365 }
366}
367
368#endif // LP64
369
370static size_t random_arena_chunk_size() {
371 // Return with a 50% rate a standard size, otherwise some random size
372 if (os::random() % 10 < 5) {
373 static const size_t standard_sizes[4] = {
374 Chunk::tiny_size, Chunk::init_size, Chunk::size, Chunk::medium_size
375 };
376 return standard_sizes[os::random() % 4];
377 }
378 return ARENA_ALIGN(os::random() % 1024)(align_up((os::random() % 1024), BytesPerLong));
379}
380
381TEST_VM(Arena, different_chunk_sizes)class Arena_different_chunk_sizes_vm_Test : public ::testing::
Test { public: Arena_different_chunk_sizes_vm_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); Arena_different_chunk_sizes_vm_Test
(Arena_different_chunk_sizes_vm_Test const &) = delete; void
operator=(Arena_different_chunk_sizes_vm_Test const &) =
delete;};::testing::TestInfo* const Arena_different_chunk_sizes_vm_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"Arena", "different_chunk_sizes_vm", __null, __null, ::testing
::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/memory/test_arena.cpp"
, 381), (::testing::internal::GetTestTypeId()), ::testing::Test
::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< Arena_different_chunk_sizes_vm_Test
>);void Arena_different_chunk_sizes_vm_Test::TestBody()
{
382 // Test the creation/pooling of chunks; since ChunkPool is hidden, the
383 // only way to test this is to create/destroy arenas with different init sizes,
384 // which determines the initial chunk size.
385 // Note that since the chunk pools are global and get cleaned out periodically,
386 // there is no safe way to actually test their occupancy here.
387 for (int i = 0; i < 1000; i ++) {
388 // Unfortunately, Arenas cannot be newed,
389 // so we are left with awkwardly placing a few on the stack.
390 Arena ar0(mtTest, random_arena_chunk_size());
391 Arena ar1(mtTest, random_arena_chunk_size());
392 Arena ar2(mtTest, random_arena_chunk_size());
393 Arena ar3(mtTest, random_arena_chunk_size());
394 Arena ar4(mtTest, random_arena_chunk_size());
395 Arena ar5(mtTest, random_arena_chunk_size());
396 Arena ar6(mtTest, random_arena_chunk_size());
397 Arena ar7(mtTest, random_arena_chunk_size());
398 }
399}