jdk-24/test/hotspot/gtest/gc/z/test_zAddress.cpp
Per Lidén e7af7a4aef 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00

126 lines
5.2 KiB
C++

/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#include "precompiled.hpp"
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zGlobals.hpp"
#include "unittest.hpp"
class ZAddressTest : public ::testing::Test {
protected:
static void is_good_bit(uintptr_t bit_mask) {
// Setup
uintptr_t mask_before = ZAddressGoodMask;
ZAddressMasks::set_good_mask(bit_mask);
// Test that a pointer with only the given bit is considered good.
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataMarked0), (bit_mask == ZAddressMetadataMarked0));
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataMarked1), (bit_mask == ZAddressMetadataMarked1));
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataRemapped), (bit_mask == ZAddressMetadataRemapped));
// Test that a pointer with the given bit and some extra bits is considered good.
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataMarked0 | 0x8),(bit_mask == ZAddressMetadataMarked0));
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataMarked1 | 0x8), (bit_mask == ZAddressMetadataMarked1));
EXPECT_EQ(ZAddress::is_good(ZAddressMetadataRemapped | 0x8), (bit_mask == ZAddressMetadataRemapped));
// Test that null is not considered good.
EXPECT_FALSE(ZAddress::is_good(0));
// Teardown
ZAddressMasks::set_good_mask(mask_before);
}
static void is_good_or_null_bit(uintptr_t bit_mask) {
// Setup
uintptr_t mask_before = ZAddressGoodMask;
ZAddressMasks::set_good_mask(bit_mask);
// Test that a pointer with only the given bit is considered good.
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataMarked0), (bit_mask == ZAddressMetadataMarked0));
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataMarked1), (bit_mask == ZAddressMetadataMarked1));
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataRemapped), (bit_mask == ZAddressMetadataRemapped));
// Test that a pointer with the given bit and some extra bits is considered good.
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataMarked0 | 0x8), (bit_mask == ZAddressMetadataMarked0));
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataMarked1 | 0x8), (bit_mask == ZAddressMetadataMarked1));
EXPECT_EQ(ZAddress::is_good_or_null(ZAddressMetadataRemapped | 0x8), (bit_mask == ZAddressMetadataRemapped));
// Test that null is considered good_or_null.
EXPECT_TRUE(ZAddress::is_good_or_null(0));
// Teardown
ZAddressMasks::set_good_mask(mask_before);
}
static void finalizable() {
// Setup
ZAddressMasks::initialize();
ZAddressMasks::flip_to_marked();
// Test that a normal good pointer is good and weak good, but not finalizable
const uintptr_t addr1 = ZAddress::good(1);
EXPECT_FALSE(ZAddress::is_finalizable(addr1));
EXPECT_TRUE(ZAddress::is_marked(addr1));
EXPECT_FALSE(ZAddress::is_remapped(addr1));
EXPECT_TRUE(ZAddress::is_weak_good(addr1));
EXPECT_TRUE(ZAddress::is_weak_good_or_null(addr1));
EXPECT_TRUE(ZAddress::is_good(addr1));
EXPECT_TRUE(ZAddress::is_good_or_null(addr1));
// Test that a finalizable good pointer is finalizable and weak good, but not good
const uintptr_t addr2 = ZAddress::finalizable_good(1);
EXPECT_TRUE(ZAddress::is_finalizable(addr2));
EXPECT_TRUE(ZAddress::is_marked(addr2));
EXPECT_FALSE(ZAddress::is_remapped(addr2));
EXPECT_TRUE(ZAddress::is_weak_good(addr2));
EXPECT_TRUE(ZAddress::is_weak_good_or_null(addr2));
EXPECT_FALSE(ZAddress::is_good(addr2));
EXPECT_FALSE(ZAddress::is_good_or_null(addr2));
// Flip to remapped and test that it's no longer weak good
ZAddressMasks::flip_to_remapped();
EXPECT_TRUE(ZAddress::is_finalizable(addr2));
EXPECT_TRUE(ZAddress::is_marked(addr2));
EXPECT_FALSE(ZAddress::is_remapped(addr2));
EXPECT_FALSE(ZAddress::is_weak_good(addr2));
EXPECT_FALSE(ZAddress::is_weak_good_or_null(addr2));
EXPECT_FALSE(ZAddress::is_good(addr2));
EXPECT_FALSE(ZAddress::is_good_or_null(addr2));
}
};
TEST_F(ZAddressTest, is_good) {
is_good_bit(ZAddressMetadataMarked0);
is_good_bit(ZAddressMetadataMarked1);
is_good_bit(ZAddressMetadataRemapped);
}
TEST_F(ZAddressTest, is_good_or_null) {
is_good_or_null_bit(ZAddressMetadataMarked0);
is_good_or_null_bit(ZAddressMetadataMarked1);
is_good_or_null_bit(ZAddressMetadataRemapped);
}
TEST_F(ZAddressTest, is_weak_good_or_null) {
#define check_is_weak_good_or_null(value) \
EXPECT_EQ(ZAddress::is_weak_good_or_null(value), \
(ZAddress::is_good_or_null(value) || ZAddress::is_remapped(value))) \
<< "is_good_or_null: " << ZAddress::is_good_or_null(value) \
<< " is_remaped: " << ZAddress::is_remapped(value) \
<< " is_good_or_null_or_remapped: " << ZAddress::is_weak_good_or_null(value)
check_is_weak_good_or_null((uintptr_t)NULL);
check_is_weak_good_or_null(ZAddressMetadataMarked0);
check_is_weak_good_or_null(ZAddressMetadataMarked1);
check_is_weak_good_or_null(ZAddressMetadataRemapped);
check_is_weak_good_or_null((uintptr_t)0x123);
}
TEST_F(ZAddressTest, finalizable) {
finalizable();
}