Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/runtime/test_globals.cpp
41144 views
1
/*
2
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. 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 it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 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 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
#include "precompiled.hpp"
25
#include "compiler/compiler_globals.hpp"
26
#include "gc/shared/gc_globals.hpp"
27
#include "runtime/globals.hpp"
28
#include "runtime/globals_extension.hpp"
29
#include "runtime/flags/flagSetting.hpp"
30
#include "runtime/flags/jvmFlag.hpp"
31
#include "runtime/flags/jvmFlagAccess.hpp"
32
#include "unittest.hpp"
33
34
#define TEST_FLAG(f, type, value) \
35
do { \
36
ASSERT_TRUE(JVMFlag::find_flag(#f)->is_ ## type()); \
37
type original_value = f; \
38
{ \
39
AutoSaveRestore<type> FLAG_GUARD(f); \
40
f = value; \
41
} \
42
ASSERT_EQ(original_value, f); \
43
} while (0)
44
45
TEST_VM(FlagGuard, bool_flag) {
46
TEST_FLAG(AlwaysActAsServerClassMachine, bool, true);
47
}
48
49
TEST_VM(FlagGuard, int_flag) {
50
TEST_FLAG(ParGCArrayScanChunk, int, 1337);
51
}
52
53
TEST_VM(FlagGuard, intx_flag) {
54
TEST_FLAG(RefDiscoveryPolicy, intx, 1337);
55
}
56
57
TEST_VM(FlagGuard, uint_flag) {
58
TEST_FLAG(ConcGCThreads, uint, 1337);
59
}
60
61
TEST_VM(FlagGuard, size_t_flag) {
62
TEST_FLAG(HeapSizePerGCThread, size_t, 1337);
63
}
64
65
TEST_VM(FlagGuard, uint64_t_flag) {
66
TEST_FLAG(MaxRAM, uint64_t, 1337);
67
}
68
69
TEST_VM(FlagGuard, double_flag) {
70
TEST_FLAG(CompileThresholdScaling, double, 3.141569);
71
}
72
73
TEST_VM(FlagGuard, ccstr_flag) {
74
TEST_FLAG(PerfDataSaveFile, ccstr, "/a/random/path");
75
}
76
77
78
// SharedArchiveConfigFile is used only during "java -Xshare:dump", so
79
// it's safe to modify its value in gtest
80
81
TEST_VM(FlagAccess, ccstr_flag) {
82
FLAG_SET_CMDLINE(SharedArchiveConfigFile, "");
83
ASSERT_EQ(FLAG_IS_CMDLINE(SharedArchiveConfigFile), true);
84
ASSERT_EQ(strcmp(SharedArchiveConfigFile, ""), 0);
85
86
FLAG_SET_ERGO(SharedArchiveConfigFile, "foobar");
87
ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);
88
ASSERT_EQ(strcmp(SharedArchiveConfigFile, "foobar") , 0);
89
90
FLAG_SET_ERGO(SharedArchiveConfigFile, nullptr);
91
ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);
92
ASSERT_EQ(SharedArchiveConfigFile, nullptr);
93
94
FLAG_SET_ERGO(SharedArchiveConfigFile, "xyz");
95
ASSERT_EQ(FLAG_IS_ERGO(SharedArchiveConfigFile), true);
96
ASSERT_EQ(strcmp(SharedArchiveConfigFile, "xyz"), 0);
97
}
98
99
template <typename T, int type_enum>
100
static JVMFlag::Error get_flag(const char* name) {
101
JVMFlag* flag = (name == NULL) ? NULL : JVMFlag::find_flag(name);
102
103
T val;
104
return JVMFlagAccess::get<T, type_enum>(flag, &val);
105
}
106
107
TEST_VM(FlagAccess, wrong_format) {
108
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(int)>(NULL)), JVMFlag::INVALID_FLAG);
109
110
// MaxRAMPercentage is a double flag
111
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(bool)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
112
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(int)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
113
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uint)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
114
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(intx)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
115
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uintx)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
116
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(uint64_t)>("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
117
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(size_t)> ("MaxRAMPercentage")), JVMFlag::WRONG_FORMAT);
118
ASSERT_EQ((get_flag<JVM_FLAG_TYPE(double)> ("MaxRAMPercentage")), JVMFlag::SUCCESS);
119
}
120
121