Path: blob/master/test/hotspot/gtest/runtime/test_globals.cpp
41144 views
/*1* Copyright (c) 2016, 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*/2223#include "precompiled.hpp"24#include "compiler/compiler_globals.hpp"25#include "gc/shared/gc_globals.hpp"26#include "runtime/globals.hpp"27#include "runtime/globals_extension.hpp"28#include "runtime/flags/flagSetting.hpp"29#include "runtime/flags/jvmFlag.hpp"30#include "runtime/flags/jvmFlagAccess.hpp"31#include "unittest.hpp"3233#define TEST_FLAG(f, type, value) \34do { \35ASSERT_TRUE(JVMFlag::find_flag(#f)->is_ ## type()); \36type original_value = f; \37{ \38AutoSaveRestore<type> FLAG_GUARD(f); \39f = value; \40} \41ASSERT_EQ(original_value, f); \42} while (0)4344TEST_VM(FlagGuard, bool_flag) {45TEST_FLAG(AlwaysActAsServerClassMachine, bool, true);46}4748TEST_VM(FlagGuard, int_flag) {49TEST_FLAG(ParGCArrayScanChunk, int, 1337);50}5152TEST_VM(FlagGuard, intx_flag) {53TEST_FLAG(RefDiscoveryPolicy, intx, 1337);54}5556TEST_VM(FlagGuard, uint_flag) {57TEST_FLAG(ConcGCThreads, uint, 1337);58}5960TEST_VM(FlagGuard, size_t_flag) {61TEST_FLAG(HeapSizePerGCThread, size_t, 1337);62}6364TEST_VM(FlagGuard, uint64_t_flag) {65TEST_FLAG(MaxRAM, uint64_t, 1337);66}6768TEST_VM(FlagGuard, double_flag) {69TEST_FLAG(CompileThresholdScaling, double, 3.141569);70}7172TEST_VM(FlagGuard, ccstr_flag) {73TEST_FLAG(PerfDataSaveFile, ccstr, "/a/random/path");74}757677// SharedArchiveConfigFile is used only during "java -Xshare:dump", so78// it's safe to modify its value in gtest7980TEST_VM(FlagAccess, ccstr_flag) {81FLAG_SET_CMDLINE(SharedArchiveConfigFile, "");82ASSERT_EQ(FLAG_IS_CMDLINE(SharedArchiveConfigFile), true);83ASSERT_EQ(strcmp(SharedArchiveConfigFile, ""), 0);8485FLAG_SET_ERGO(SharedArchiveConfigFile, "foobar");86ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);87ASSERT_EQ(strcmp(SharedArchiveConfigFile, "foobar") , 0);8889FLAG_SET_ERGO(SharedArchiveConfigFile, nullptr);90ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);91ASSERT_EQ(SharedArchiveConfigFile, nullptr);9293FLAG_SET_ERGO(SharedArchiveConfigFile, "xyz");94ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);95ASSERT_EQ(strcmp(SharedArchiveConfigFile, "xyz"), 0);96}9798template <typename T, int type_enum>99static JVMFlag::Error get_flag(const char* name) {100JVMFlag* flag = (name == NULL) ? NULL : JVMFlag::find_flag(name);101102T val;103return JVMFlagAccess::get<T, type_enum>(flag, &val);104}105106TEST_VM(FlagAccess, wrong_format) {107ASSERT_EQ((get_flag<JVM_FLAG_TYPE(int)>(NULL)), JVMFlag::INVALID_FLAG);108109// MaxRAMPercentage is a double flag110ASSERT_EQ((get_flag<JVM_FLAG_TYPE(bool)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);111ASSERT_EQ((get_flag<JVM_FLAG_TYPE(int)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);112ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uint)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);113ASSERT_EQ((get_flag<JVM_FLAG_TYPE(intx)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);114ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uintx)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);115ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uint64_t)>("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);116ASSERT_EQ((get_flag<JVM_FLAG_TYPE(size_t)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);117ASSERT_EQ((get_flag<JVM_FLAG_TYPE(double)> ("MaxRAMPercentage")), JVMFlag::SUCCESS);118}119120121