Skip to content

Commit

Permalink
8303605: Memory leaks in Metaspace gtests
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: ddcb369ceabd2207699632e90a358baf251c6f36
  • Loading branch information
GoeLin committed Jan 8, 2024
1 parent f001819 commit f59ca35
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/hotspot/gtest/gtestMain.cpp
Expand Up @@ -92,6 +92,7 @@ static int init_jvm(int argc, char **argv, bool disable_error_handling, JavaVM**
JNIEnv* env;

int ret = JNI_CreateJavaVM(jvm_ptr, (void**)&env, &args);
delete[] options;
if (ret == JNI_OK) {
// CreateJavaVM leaves WXExec context, while gtests
// calls internal functions assuming running in WXWwrite.
Expand Down
4 changes: 4 additions & 0 deletions test/hotspot/gtest/metaspace/metaspaceGtestSparseArray.hpp
Expand Up @@ -99,6 +99,10 @@ class SparseArray : public StackObj {
}
}

~SparseArray() {
FREE_C_HEAP_ARRAY(T, _slots);
}

T at(int i) { return _slots[i]; }
const T at(int i) const { return _slots[i]; }
void set_at(int i, T e) { _slots[i] = e; }
Expand Down
12 changes: 11 additions & 1 deletion test/hotspot/gtest/metaspace/test_freeblocks.cpp
Expand Up @@ -79,7 +79,7 @@ class FreeBlocksTest {
return false;
}

void deallocate_top() {
bool deallocate_top() {

allocation_t* a = _allocations;
if (a != NULL) {
Expand All @@ -88,7 +88,13 @@ class FreeBlocksTest {
_freeblocks.add_block(a->p, a->word_size);
delete a;
DEBUG_ONLY(_freeblocks.verify();)
return true;
}
return false;
}

void deallocate_all() {
while (deallocate_top());
}

bool allocate() {
Expand Down Expand Up @@ -182,6 +188,10 @@ class FreeBlocksTest {
CHECK_CONTENT(_freeblocks, 1, 1024);
}

~FreeBlocksTest() {
deallocate_all();
}

static void test_small_allocations() {
FreeBlocksTest test(10);
test.test_loop();
Expand Down
3 changes: 3 additions & 0 deletions test/hotspot/gtest/metaspace/test_virtualspacenode.cpp
Expand Up @@ -532,6 +532,9 @@ TEST_VM(metaspace, virtual_space_node_test_basics) {
ASSERT_EQ(node->committed_words(), scomm.get());
DEBUG_ONLY(node->verify_locked();)

delete node;
ASSERT_EQ(scomm.get(), (size_t)0);
ASSERT_EQ(sres.get(), (size_t)0);
}

// Note: we unfortunately need TEST_VM even though the system tested
Expand Down

1 comment on commit f59ca35

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.