jdk-24/test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp
Stefan Karlsson d20034b09c 8307058: Implementation of Generational ZGC
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Axel Boldt-Christmas <aboldtch@openjdk.org>
Co-authored-by: Per Liden <pliden@openjdk.org>
Co-authored-by: Stefan Johansson <sjohanss@openjdk.org>
Co-authored-by: Albert Mingkun Yang <ayang@openjdk.org>
Co-authored-by: Erik Helin <ehelin@openjdk.org>
Co-authored-by: Roberto Castañeda Lozano <rcastanedalo@openjdk.org>
Co-authored-by: Nils Eliasson <neliasso@openjdk.org>
Co-authored-by: Martin Doerr <mdoerr@openjdk.org>
Co-authored-by: Leslie Zhai <lzhai@openjdk.org>
Co-authored-by: Fei Yang <fyang@openjdk.org>
Co-authored-by: Yadong Wang <yadongwang@openjdk.org>
Reviewed-by: eosterlund, aboldtch, rcastanedalo
2023-05-11 13:59:37 +00:00

175 lines
5.6 KiB
C++

/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "precompiled.hpp"
#include "gc/z/zPhysicalMemory.inline.hpp"
#include "unittest.hpp"
TEST(ZPhysicalMemoryTest, copy) {
const ZPhysicalMemorySegment seg0(zoffset(0), 100, true);
const ZPhysicalMemorySegment seg1(zoffset(200), 100, true);
ZPhysicalMemory pmem0;
pmem0.add_segment(seg0);
EXPECT_EQ(pmem0.nsegments(), 1);
EXPECT_EQ(pmem0.segment(0).size(), 100u);
ZPhysicalMemory pmem1;
pmem1.add_segment(seg0);
pmem1.add_segment(seg1);
EXPECT_EQ(pmem1.nsegments(), 2);
EXPECT_EQ(pmem1.segment(0).size(), 100u);
EXPECT_EQ(pmem1.segment(1).size(), 100u);
ZPhysicalMemory pmem2(pmem0);
EXPECT_EQ(pmem2.nsegments(), 1);
EXPECT_EQ(pmem2.segment(0).size(), 100u);
pmem2 = pmem1;
EXPECT_EQ(pmem2.nsegments(), 2);
EXPECT_EQ(pmem2.segment(0).size(), 100u);
EXPECT_EQ(pmem2.segment(1).size(), 100u);
}
TEST(ZPhysicalMemoryTest, add) {
const ZPhysicalMemorySegment seg0(zoffset(0), 1, true);
const ZPhysicalMemorySegment seg1(zoffset(1), 1, true);
const ZPhysicalMemorySegment seg2(zoffset(2), 1, true);
const ZPhysicalMemorySegment seg3(zoffset(3), 1, true);
const ZPhysicalMemorySegment seg4(zoffset(4), 1, true);
const ZPhysicalMemorySegment seg5(zoffset(5), 1, true);
const ZPhysicalMemorySegment seg6(zoffset(6), 1, true);
ZPhysicalMemory pmem0;
EXPECT_EQ(pmem0.nsegments(), 0);
EXPECT_EQ(pmem0.is_null(), true);
ZPhysicalMemory pmem1;
pmem1.add_segment(seg0);
pmem1.add_segment(seg1);
pmem1.add_segment(seg2);
pmem1.add_segment(seg3);
pmem1.add_segment(seg4);
pmem1.add_segment(seg5);
pmem1.add_segment(seg6);
EXPECT_EQ(pmem1.nsegments(), 1);
EXPECT_EQ(pmem1.segment(0).size(), 7u);
EXPECT_EQ(pmem1.is_null(), false);
ZPhysicalMemory pmem2;
pmem2.add_segment(seg0);
pmem2.add_segment(seg1);
pmem2.add_segment(seg2);
pmem2.add_segment(seg4);
pmem2.add_segment(seg5);
pmem2.add_segment(seg6);
EXPECT_EQ(pmem2.nsegments(), 2);
EXPECT_EQ(pmem2.segment(0).size(), 3u);
EXPECT_EQ(pmem2.segment(1).size(), 3u);
EXPECT_EQ(pmem2.is_null(), false);
ZPhysicalMemory pmem3;
pmem3.add_segment(seg0);
pmem3.add_segment(seg2);
pmem3.add_segment(seg3);
pmem3.add_segment(seg4);
pmem3.add_segment(seg6);
EXPECT_EQ(pmem3.nsegments(), 3);
EXPECT_EQ(pmem3.segment(0).size(), 1u);
EXPECT_EQ(pmem3.segment(1).size(), 3u);
EXPECT_EQ(pmem3.segment(2).size(), 1u);
EXPECT_EQ(pmem3.is_null(), false);
ZPhysicalMemory pmem4;
pmem4.add_segment(seg0);
pmem4.add_segment(seg2);
pmem4.add_segment(seg4);
pmem4.add_segment(seg6);
EXPECT_EQ(pmem4.nsegments(), 4);
EXPECT_EQ(pmem4.segment(0).size(), 1u);
EXPECT_EQ(pmem4.segment(1).size(), 1u);
EXPECT_EQ(pmem4.segment(2).size(), 1u);
EXPECT_EQ(pmem4.segment(3).size(), 1u);
EXPECT_EQ(pmem4.is_null(), false);
}
TEST(ZPhysicalMemoryTest, remove) {
ZPhysicalMemory pmem;
pmem.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, true));
pmem.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, true));
pmem.add_segment(ZPhysicalMemorySegment(zoffset(50), 10, true));
EXPECT_EQ(pmem.nsegments(), 3);
EXPECT_EQ(pmem.size(), 30u);
EXPECT_FALSE(pmem.is_null());
pmem.remove_segments();
EXPECT_EQ(pmem.nsegments(), 0);
EXPECT_EQ(pmem.size(), 0u);
EXPECT_TRUE(pmem.is_null());
}
TEST(ZPhysicalMemoryTest, split) {
ZPhysicalMemory pmem;
pmem.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
pmem.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, true));
pmem.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, true));
EXPECT_EQ(pmem.nsegments(), 2);
EXPECT_EQ(pmem.size(), 30u);
ZPhysicalMemory pmem0 = pmem.split(1);
EXPECT_EQ(pmem0.nsegments(), 1);
EXPECT_EQ(pmem0.size(), 1u);
EXPECT_EQ(pmem.nsegments(), 2);
EXPECT_EQ(pmem.size(), 29u);
ZPhysicalMemory pmem1 = pmem.split(25);
EXPECT_EQ(pmem1.nsegments(), 2);
EXPECT_EQ(pmem1.size(), 25u);
EXPECT_EQ(pmem.nsegments(), 1);
EXPECT_EQ(pmem.size(), 4u);
ZPhysicalMemory pmem2 = pmem.split(4);
EXPECT_EQ(pmem2.nsegments(), 1);
EXPECT_EQ(pmem2.size(), 4u);
EXPECT_EQ(pmem.nsegments(), 0);
EXPECT_EQ(pmem.size(), 0u);
}
TEST(ZPhysicalMemoryTest, split_committed) {
ZPhysicalMemory pmem0;
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, false));
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(20), 10, true));
pmem0.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, false));
EXPECT_EQ(pmem0.nsegments(), 4);
EXPECT_EQ(pmem0.size(), 40u);
ZPhysicalMemory pmem1 = pmem0.split_committed();
EXPECT_EQ(pmem0.nsegments(), 2);
EXPECT_EQ(pmem0.size(), 20u);
EXPECT_EQ(pmem1.nsegments(), 2);
EXPECT_EQ(pmem1.size(), 20u);
}