Skip to content

Commit 3c3be80

Browse files
committed
wip
1 parent 2bcf797 commit 3c3be80

File tree

7 files changed

+63
-5
lines changed

7 files changed

+63
-5
lines changed

src/hotspot/share/memory/metaspace/binList.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class BinListImpl {
9696
// Maximal (incl) word size a block can have to be manageable by this structure.
9797
const static size_t MaxWordSize = num_lists;
9898

99+
// for tests
100+
static constexpr size_t header_wordsize = sizeof(Block) / BytesPerWord;
101+
99102
private:
100103

101104
Block* _blocks[num_lists];
@@ -132,9 +135,9 @@ class BinListImpl {
132135
}
133136
}
134137
static bool check_block_zap(const Block* b, size_t word_size) {
135-
return word_size == 1 || // 1-word-sized blocks have no space for a canary
136-
( Zapper::is_zapped_location(b->base() + 1) &&
137-
Zapper::is_zapped_location(b->base() + word_size - 1) );
138+
return word_size <= header_wordsize || // 1-word-sized blocks have no space for a canary
139+
( Zapper::is_zapped_location(b->base() + header_wordsize) &&
140+
Zapper::is_zapped_location(b->base() + word_size - header_wordsize) );
138141
}
139142
#endif
140143

src/hotspot/share/memory/metaspace/blockTree.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class BlockTree: public CHeapObj<mtMetaspace> {
128128
};
129129

130130
STATIC_ASSERT(is_aligned(sizeof(Node), sizeof(MetaWord)));
131-
static constexpr size_t node_header_wordsize = sizeof(Node) / sizeof(MetaWord);
132131

133132
// Needed for verify() and print_tree()
134133
struct walkinfo;
@@ -140,9 +139,12 @@ class BlockTree: public CHeapObj<mtMetaspace> {
140139

141140
public:
142141

142+
// Public only for tests
143+
static constexpr size_t header_wordsize = sizeof(Node) / sizeof(MetaWord);
144+
143145
// Minimum word size a block has to be to be added to this structure
144146
// (Node size + at least one word; smaller blocks -> BinList)
145-
constexpr static size_t MinWordSize = node_header_wordsize + 1;
147+
constexpr static size_t MinWordSize = header_wordsize + 1;
146148

147149
private:
148150

test/hotspot/gtest/metaspace/metaspaceGtestCommon.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "metaspaceGtestCommon.hpp"
2727
#include "metaspaceGtestRangeHelpers.hpp"
28+
#include "memory/metaspace/metaspaceZapper.hpp"
2829
#include "runtime/os.hpp"
2930

3031
void zap_range(MetaWord* p, size_t word_size) {
@@ -95,3 +96,14 @@ void check_marked_range(const MetaWord* p, size_t word_size) {
9596
check_marked_range(p, word_size, pattern);
9697
}
9798

99+
// using metaspace zapper
100+
101+
#ifdef ASSERT
102+
// Helper function checks if region x is zapped
103+
void check_metaspace_zap(const MetaWord* start, size_t size) {
104+
size_t interval = MAX(1, size / 256);
105+
for (const MetaWord* p = start; p < start + size; p += interval) {
106+
ASSERT_TRUE(metaspace::Zapper::is_zapped_location(p));
107+
}
108+
}
109+
#endif

test/hotspot/gtest/metaspace/metaspaceGtestCommon.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,7 @@ class FeederBuffer {
216216

217217
};
218218

219+
// Check an area for being zapped with the metaspace zap pattern
220+
DEBUG_ONLY(void check_metaspace_zap(const MetaWord* start, size_t size);)
221+
219222
#endif // GTEST_METASPACE_METASPACEGTESTCOMMON_HPP

test/hotspot/gtest/metaspace/test_binlist.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ struct TestedBinList : public BinListImpl<num_lists> {
5757
}
5858
};
5959

60+
#ifdef ASSERT
61+
template <class BINLISTTYPE>
62+
void check_block_zap(const MetaWord* p, size_t size) {
63+
check_metaspace_zap(p + BINLISTTYPE::header_wordsize, size - BINLISTTYPE::header_wordsize);
64+
}
65+
#endif
66+
6067
template <class BINLISTTYPE>
6168
struct BinListBasicTest {
6269

@@ -89,6 +96,7 @@ struct BinListBasicTest {
8996
EXPECT_EQ(p, arr);
9097
EXPECT_EQ((size_t)innocous_size, real_size);
9198
CHECK_BL_CONTENT(bl, 0, 0);
99+
DEBUG_ONLY(check_block_zap<BINLISTTYPE>(p, real_size);)
92100
DEBUG_ONLY(bl.verify();)
93101

94102
}
@@ -114,6 +122,7 @@ struct BinListBasicTest {
114122
EXPECT_EQ(p, arr);
115123
EXPECT_EQ((size_t)s1, real_size);
116124
CHECK_BL_CONTENT(bl, 0, 0);
125+
DEBUG_ONLY(check_block_zap<BINLISTTYPE>(p, real_size);)
117126
DEBUG_ONLY(bl.verify();)
118127
} else {
119128
EXPECT_EQ(p, (MetaWord*)nullptr);
@@ -125,6 +134,7 @@ struct BinListBasicTest {
125134
EXPECT_EQ(p, arr);
126135
EXPECT_EQ((size_t)s1, real_size);
127136
CHECK_BL_CONTENT(bl, 0, 0);
137+
DEBUG_ONLY(check_block_zap<BINLISTTYPE>(p, real_size);)
128138
}
129139
}
130140
}

test/hotspot/gtest/metaspace/test_blocktree.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using metaspace::BlockTree;
3434
using metaspace::MemRangeCounter;
3535
using metaspace::MetaBlock;
36+
using metaspace::Zapper;
3637

3738
struct TestedBlockTree : public BlockTree {
3839
void add_block(MetaWord* p, size_t word_size) {
@@ -65,6 +66,12 @@ static void create_nodes(const size_t sizes[], FeederBuffer& fb, TestedBlockTree
6566
} \
6667
}
6768

69+
#ifdef ASSERT
70+
void check_node_zap(const MetaWord* p, size_t size) {
71+
check_metaspace_zap(p + BlockTree::header_wordsize, size - BlockTree::header_wordsize);
72+
}
73+
#endif
74+
6875
TEST_VM(metaspace, BlockTree_basic) {
6976

7077
TestedBlockTree bt;
@@ -94,14 +101,17 @@ TEST_VM(metaspace, BlockTree_basic) {
94101
};
95102

96103
for (int i = 0; sizes[i] > 0; i++) {
104+
DEBUG_ONLY(memset(arr, 0, sizes[i]);)
97105
bt.add_block(arr, sizes[i]);
98106
CHECK_BT_CONTENT(bt, 1, sizes[i]);
107+
DEBUG_ONLY(check_node_zap(arr, sizes[i]);)
99108

100109
DEBUG_ONLY(bt.verify();)
101110

102111
MetaWord* p = bt.remove_block(sizes[i], &real_size);
103112
EXPECT_EQ(p, arr);
104113
EXPECT_EQ(real_size, (size_t)sizes[i]);
114+
DEBUG_ONLY(check_node_zap(p, sizes[i]);)
105115
CHECK_BT_CONTENT(bt, 0, 0);
106116
}
107117

@@ -138,6 +148,7 @@ static void test_find_nearest_fit_with_tree(const size_t sizes[], size_t request
138148
if (expected_size != SIZE_MAX) {
139149
EXPECT_NOT_NULL(p);
140150
EXPECT_EQ(real_size, expected_size);
151+
DEBUG_ONLY(check_node_zap(p, real_size);)
141152
} else {
142153
EXPECT_NULL(p);
143154
EXPECT_0(real_size);

test/hotspot/gtest/metaspace/test_metachunk.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,20 @@ TEST_VM(metaspace, chunk_enlarge_in_place) {
427427

428428
}
429429

430+
#ifdef ASSERT
431+
// Test ChunkManager::get_chunk
432+
TEST_VM(metaspace, chunk_zap) {
433+
ChunkGtestContext context;
434+
Metachunk* c = nullptr;
435+
RandSizeGenerator rand(1, K);
436+
for (chunklevel_t l = LOWEST_CHUNK_LEVEL; l < HIGHEST_CHUNK_LEVEL; l++) {
437+
context.alloc_chunk_expect_success(&c, HIGHEST_CHUNK_LEVEL);
438+
for (size_t s = 0; s < c->word_size(); s += rand.get()) {
439+
c->ensure_committed(s);
440+
c->zap();
441+
check_metaspace_zap(c->base(), c->committed_words());
442+
}
443+
context.return_chunk(c);
444+
}
445+
}
446+
#endif

0 commit comments

Comments
 (0)