< prev index next >

test/hotspot/gtest/metaspace/test_metachunklist.cpp

Print this page
rev 60811 : imported patch jep387-all.patch
rev 60812 : [mq]: diff1

*** 1,8 **** /* ! * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. ! * Copyright (c) 2018, 2020 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,8 ---- /* ! * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. ! * Copyright (c) 2020 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 23,49 **** * */ #include "precompiled.hpp" //#define LOG_PLEASE ! #include "metaspace/metaspaceTestsCommon.hpp" ! #include "metaspace/metaspaceTestContexts.hpp" ! #include "metaspace/metaspace_rangehelpers.hpp" TEST_VM(metaspace, metachunklist) { ! ChunkTestsContext helper; MetachunkList lst; Metachunk* chunks[10]; size_t total_size = 0; ! for (int i = 0; i < 10; i ++) { Metachunk* c = NULL; ! helper.alloc_chunk_expect_success(&c, ChunkLevelRanges::all_chunks().random_value()); chunks[i] = c; total_size += c->committed_words(); lst.add(c); EXPECT_EQ(lst.first(), c); --- 23,58 ---- * */ #include "precompiled.hpp" + #include "memory/metaspace/msCounter.hpp" + #include "memory/metaspace/msFreeChunkList.hpp" + #include "memory/metaspace/msMetachunkList.hpp" + //#define LOG_PLEASE ! #include "metaspaceGtestCommon.hpp" ! #include "metaspaceGtestContexts.hpp" ! #include "metaspaceGtestRangeHelpers.hpp" ! ! using metaspace::MemRangeCounter; ! using metaspace::MetachunkList; ! using metaspace::FreeChunkListVector; ! TEST_VM(metaspace, metachunklist) { ! ChunkGtestContext context; MetachunkList lst; Metachunk* chunks[10]; size_t total_size = 0; ! for (int i = 0; i < 10; i++) { Metachunk* c = NULL; ! context.alloc_chunk_expect_success(&c, ChunkLevelRanges::all_chunks().random_value()); chunks[i] = c; total_size += c->committed_words(); lst.add(c); EXPECT_EQ(lst.first(), c);
*** 56,99 **** EXPECT_EQ(lst.count(), i + 1); EXPECT_EQ(lst.calc_committed_word_size(), total_size); } ! for (int i = 0; i < 10; i ++) { DEBUG_ONLY(EXPECT_TRUE(lst.contains(chunks[i]));) } ! for (int i = 0; i < 10; i ++) { Metachunk* c = lst.remove_first(); DEBUG_ONLY(EXPECT_FALSE(lst.contains(c));) ! helper.return_chunk(c); } EXPECT_EQ(lst.count(), 0); EXPECT_EQ(lst.calc_committed_word_size(), (size_t)0); } - TEST_VM(metaspace, freechunklist) { ! ChunkTestsContext helper; FreeChunkListVector lst; MemRangeCounter cnt; MemRangeCounter committed_cnt; // Add random chunks to list and check the counter apis (word_size, commited_word_size, num_chunks) // Make every other chunk randomly uncommitted, and later we check that committed chunks are sorted in at the front // of the lists. ! for (int i = 0; i < 100; i ++) { Metachunk* c = NULL; ! helper.alloc_chunk_expect_success(&c, ChunkLevelRanges::all_chunks().random_value()); bool uncommitted_chunk = i % 3; if (uncommitted_chunk) { ! helper.uncommit_chunk_with_test(c); c->set_in_use(); } lst.add(c); --- 65,107 ---- EXPECT_EQ(lst.count(), i + 1); EXPECT_EQ(lst.calc_committed_word_size(), total_size); } ! for (int i = 0; i < 10; i++) { DEBUG_ONLY(EXPECT_TRUE(lst.contains(chunks[i]));) } ! for (int i = 0; i < 10; i++) { Metachunk* c = lst.remove_first(); DEBUG_ONLY(EXPECT_FALSE(lst.contains(c));) ! context.return_chunk(c); } EXPECT_EQ(lst.count(), 0); EXPECT_EQ(lst.calc_committed_word_size(), (size_t)0); } TEST_VM(metaspace, freechunklist) { ! ChunkGtestContext context; FreeChunkListVector lst; MemRangeCounter cnt; MemRangeCounter committed_cnt; // Add random chunks to list and check the counter apis (word_size, commited_word_size, num_chunks) // Make every other chunk randomly uncommitted, and later we check that committed chunks are sorted in at the front // of the lists. ! for (int i = 0; i < 100; i++) { Metachunk* c = NULL; ! context.alloc_chunk_expect_success(&c, ChunkLevelRanges::all_chunks().random_value()); bool uncommitted_chunk = i % 3; if (uncommitted_chunk) { ! context.uncommit_chunk_with_test(c); c->set_in_use(); } lst.add(c);
*** 106,116 **** EXPECT_EQ(lst.word_size(), cnt.total_size()); EXPECT_EQ(lst.committed_word_size(), committed_cnt.total_size()); } // Drain each list separately ! for (chunklevel_t lvl = LOWEST_CHUNK_LEVEL; lvl <= HIGHEST_CHUNK_LEVEL; lvl ++) { Metachunk* c = lst.remove_first(lvl); bool found_uncommitted = false; while (c != NULL) { LOG("<-" METACHUNK_FULL_FORMAT, METACHUNK_FULL_FORMAT_ARGS(c)); --- 114,124 ---- EXPECT_EQ(lst.word_size(), cnt.total_size()); EXPECT_EQ(lst.committed_word_size(), committed_cnt.total_size()); } // Drain each list separately ! for (chunklevel_t lvl = LOWEST_CHUNK_LEVEL; lvl <= HIGHEST_CHUNK_LEVEL; lvl++) { Metachunk* c = lst.remove_first(lvl); bool found_uncommitted = false; while (c != NULL) { LOG("<-" METACHUNK_FULL_FORMAT, METACHUNK_FULL_FORMAT_ARGS(c));
*** 127,137 **** EXPECT_EQ(lst.num_chunks(), (int)cnt.count()); EXPECT_EQ(lst.word_size(), cnt.total_size()); EXPECT_EQ(lst.committed_word_size(), committed_cnt.total_size()); ! helper.return_chunk(c); c = lst.remove_first(lvl); } } --- 135,145 ---- EXPECT_EQ(lst.num_chunks(), (int)cnt.count()); EXPECT_EQ(lst.word_size(), cnt.total_size()); EXPECT_EQ(lst.committed_word_size(), committed_cnt.total_size()); ! context.return_chunk(c); c = lst.remove_first(lvl); } }
< prev index next >