14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "memory/allocation.hpp"
26 #include "memory/metaspace/metachunk.hpp"
27 #include "unittest.hpp"
28 #include "utilities/align.hpp"
29 #include "utilities/copy.hpp"
30 #include "utilities/debug.hpp"
31
32 using namespace metaspace;
33
34 class MetachunkTest {
35 public:
36 static MetaWord* initial_top(Metachunk* metachunk) {
37 return metachunk->initial_top();
38 }
39 static MetaWord* top(Metachunk* metachunk) {
40 return metachunk->top();
41 }
42
43 };
44
45 TEST(Metachunk, basic) {
46 const ChunkIndex chunk_type = MediumIndex;
47 const bool is_class = false;
48 const size_t word_size = get_size_for_nonhumongous_chunktype(chunk_type, is_class);
49 // Allocate the chunk with correct alignment.
50 void* memory = malloc(word_size * BytesPerWord * 2);
51 ASSERT_TRUE(NULL != memory) << "Failed to malloc 2MB";
52
53 void* p_placement = align_up(memory, word_size * BytesPerWord);
79 // Check post alloc
80 EXPECT_EQ(MetachunkTest::initial_top(metachunk), mem);
81 EXPECT_EQ(MetachunkTest::top(metachunk), mem + alloc_size);
82 EXPECT_EQ(metachunk->overhead() + alloc_size, metachunk->used_word_size());
83 EXPECT_EQ(metachunk->word_size() - metachunk->used_word_size(),
84 metachunk->free_word_size());
85 EXPECT_FALSE(metachunk->is_empty());
86
87 // Clear chunk
88 metachunk->reset_empty();
89
90 // Check post clear
91 EXPECT_EQ(metachunk->used_word_size(), metachunk->overhead());
92 EXPECT_EQ(metachunk->word_size() - metachunk->used_word_size(),
93 metachunk->free_word_size());
94 EXPECT_EQ(MetachunkTest::top(metachunk), MetachunkTest::initial_top(metachunk));
95 EXPECT_TRUE(metachunk->is_empty());
96
97 free(memory);
98 }
|
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "precompiled.hpp"
25 #include "memory/allocation.hpp"
26 #include "memory/metaspace/metachunk.hpp"
27 #include "unittest.hpp"
28 #include "utilities/align.hpp"
29 #include "utilities/copy.hpp"
30 #include "utilities/debug.hpp"
31
32 using namespace metaspace;
33
34 #if 0
35
36 class MetachunkTest {
37 public:
38 static MetaWord* initial_top(Metachunk* metachunk) {
39 return metachunk->initial_top();
40 }
41 static MetaWord* top(Metachunk* metachunk) {
42 return metachunk->top();
43 }
44
45 };
46
47 TEST(Metachunk, basic) {
48 const ChunkIndex chunk_type = MediumIndex;
49 const bool is_class = false;
50 const size_t word_size = get_size_for_nonhumongous_chunktype(chunk_type, is_class);
51 // Allocate the chunk with correct alignment.
52 void* memory = malloc(word_size * BytesPerWord * 2);
53 ASSERT_TRUE(NULL != memory) << "Failed to malloc 2MB";
54
55 void* p_placement = align_up(memory, word_size * BytesPerWord);
81 // Check post alloc
82 EXPECT_EQ(MetachunkTest::initial_top(metachunk), mem);
83 EXPECT_EQ(MetachunkTest::top(metachunk), mem + alloc_size);
84 EXPECT_EQ(metachunk->overhead() + alloc_size, metachunk->used_word_size());
85 EXPECT_EQ(metachunk->word_size() - metachunk->used_word_size(),
86 metachunk->free_word_size());
87 EXPECT_FALSE(metachunk->is_empty());
88
89 // Clear chunk
90 metachunk->reset_empty();
91
92 // Check post clear
93 EXPECT_EQ(metachunk->used_word_size(), metachunk->overhead());
94 EXPECT_EQ(metachunk->word_size() - metachunk->used_word_size(),
95 metachunk->free_word_size());
96 EXPECT_EQ(MetachunkTest::top(metachunk), MetachunkTest::initial_top(metachunk));
97 EXPECT_TRUE(metachunk->is_empty());
98
99 free(memory);
100 }
101
102 #endif
|