Path: blob/master/test/hotspot/gtest/metaspace/test_metaspaceUtils.cpp
41144 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "memory/metaspace.hpp"27#include "memory/metaspaceUtils.hpp"28#include "unittest.hpp"2930TEST_VM(MetaspaceUtils, reserved) {31size_t reserved = MetaspaceUtils::reserved_bytes();32EXPECT_GT(reserved, 0UL);3334size_t reserved_metadata = MetaspaceUtils::reserved_bytes(Metaspace::NonClassType);35EXPECT_GT(reserved_metadata, 0UL);36EXPECT_LE(reserved_metadata, reserved);37}3839TEST_VM(MetaspaceUtils, reserved_compressed_class_pointers) {40if (!UseCompressedClassPointers) {41return;42}43size_t reserved = MetaspaceUtils::reserved_bytes();44EXPECT_GT(reserved, 0UL);4546size_t reserved_class = MetaspaceUtils::reserved_bytes(Metaspace::ClassType);47EXPECT_GT(reserved_class, 0UL);48EXPECT_LE(reserved_class, reserved);49}5051TEST_VM(MetaspaceUtils, committed) {52size_t committed = MetaspaceUtils::committed_bytes();53EXPECT_GT(committed, 0UL);5455size_t reserved = MetaspaceUtils::reserved_bytes();56EXPECT_LE(committed, reserved);5758size_t committed_metadata = MetaspaceUtils::committed_bytes(Metaspace::NonClassType);59EXPECT_GT(committed_metadata, 0UL);60EXPECT_LE(committed_metadata, committed);61}6263TEST_VM(MetaspaceUtils, committed_compressed_class_pointers) {64if (!UseCompressedClassPointers) {65return;66}67size_t committed = MetaspaceUtils::committed_bytes();68EXPECT_GT(committed, 0UL);6970size_t committed_class = MetaspaceUtils::committed_bytes(Metaspace::ClassType);71EXPECT_GT(committed_class, 0UL);72EXPECT_LE(committed_class, committed);73}7475TEST_VM(MetaspaceUtils, non_compressed_class_pointers) {76if (UseCompressedClassPointers) {77return;78}7980size_t committed_class = MetaspaceUtils::committed_bytes(Metaspace::ClassType);81EXPECT_EQ(committed_class, 0UL);8283size_t used_class = MetaspaceUtils::used_bytes(Metaspace::ClassType);84EXPECT_EQ(used_class, 0UL);8586size_t reserved_class = MetaspaceUtils::reserved_bytes(Metaspace::ClassType);87EXPECT_EQ(reserved_class, 0UL);88}8990static void check_metaspace_stats_are_consistent(const MetaspaceStats& stats) {91EXPECT_LT(stats.committed(), stats.reserved());92EXPECT_LT(stats.used(), stats.committed());93}9495static void check_metaspace_stats_are_not_null(const MetaspaceStats& stats) {96EXPECT_GT(stats.reserved(), 0UL);97EXPECT_GT(stats.committed(), 0UL);98EXPECT_GT(stats.used(), 0UL);99}100101TEST_VM(MetaspaceUtils, get_statistics) {102MetaspaceCombinedStats combined_stats = MetaspaceUtils::get_combined_statistics();103check_metaspace_stats_are_not_null(combined_stats);104check_metaspace_stats_are_consistent(combined_stats);105check_metaspace_stats_are_not_null(combined_stats.non_class_space_stats());106check_metaspace_stats_are_consistent(combined_stats.non_class_space_stats());107108if (UseCompressedClassPointers) {109check_metaspace_stats_are_not_null(combined_stats.class_space_stats());110check_metaspace_stats_are_consistent(combined_stats.class_space_stats());111} else {112// if we don't have a class space, combined stats should equal non-class stats113EXPECT_EQ(combined_stats.non_class_space_stats().reserved(), combined_stats.reserved());114EXPECT_EQ(combined_stats.non_class_space_stats().committed(), combined_stats.committed());115EXPECT_EQ(combined_stats.non_class_space_stats().used(), combined_stats.used());116}117}118119120