Path: blob/master/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp
41149 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc/shared/oopStorage.hpp"26#include "gc/shared/oopStorageSet.hpp"27#include "memory/allocation.inline.hpp"28#include "utilities/debug.hpp"29#include "utilities/enumIterator.hpp"30#include "utilities/globalDefinitions.hpp"31#include "utilities/macros.hpp"32#include "unittest.hpp"3334class OopStorageSetTest : public ::testing::Test {35protected:36// Returns index of s in storages, or size if not found.37template <uint count>38static size_t find_storage(OopStorage* s, OopStorage* storages[count]) {39for (uint i = 0; i < count; ++i) {40if (s == storages[i]) {41return i;42}43}44return count;45}4647template <uint count, typename Range>48static void check_iteration(Range range, OopStorage* storages[count]) {49ASSERT_EQ(range.size(), count);50for (auto id : range) {51OopStorage* storage = OopStorageSet::storage(id);52size_t index = find_storage<count>(storage, storages);53ASSERT_LT(index, count);54storages[index] = nullptr;55}56for (uint i = 0; i < count; ++i) {57ASSERT_EQ(nullptr /* null_storage */, storages[i]);58}59}6061template<uint count, typename Range>62static void test_iteration(Range range, void (*fill)(OopStorage*[count])) {63OopStorage* storages[count];64fill(storages);65check_iteration<count>(range, storages);66}6768static void test_strong_iteration() {69test_iteration<OopStorageSet::strong_count>(70EnumRange<OopStorageSet::StrongId>(),71&OopStorageSet::fill_strong);7273}74static void test_weak_iteration() {75test_iteration<OopStorageSet::weak_count>(76EnumRange<OopStorageSet::WeakId>(),77&OopStorageSet::fill_weak);7879}80static void test_all_iteration() {81test_iteration<OopStorageSet::all_count>(82EnumRange<OopStorageSet::Id>(),83&OopStorageSet::fill_all);84}85};8687TEST_VM_F(OopStorageSetTest, strong_iteration) {88test_strong_iteration();89}9091TEST_VM_F(OopStorageSetTest, weak_iteration) {92test_weak_iteration();93}9495TEST_VM_F(OopStorageSetTest, all_iteration) {96test_all_iteration();97}9899100