Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/logging/test_gcTraceTime.cpp
41144 views
1
/*
2
* Copyright (c) 2015, 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 "jvm.h"
26
#include "gc/shared/gcTraceTime.inline.hpp"
27
#include "logTestFixture.hpp"
28
#include "logTestUtils.inline.hpp"
29
#include "logging/log.hpp"
30
#include "runtime/interfaceSupport.inline.hpp"
31
#include "unittest.hpp"
32
33
class GCTraceTimeTest : public LogTestFixture {
34
};
35
36
TEST_VM_F(GCTraceTimeTest, full) {
37
set_log_config(TestLogFileName, "gc=debug,gc+start=debug");
38
39
LogTarget(Debug, gc) gc_debug;
40
LogTarget(Debug, gc, start) gc_start_debug;
41
42
EXPECT_TRUE(gc_debug.is_enabled());
43
EXPECT_TRUE(gc_start_debug.is_enabled());
44
45
{
46
ThreadInVMfromNative tvn(JavaThread::current());
47
MutexLocker lock(Heap_lock); // Needed to read heap usage
48
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, true);
49
}
50
51
const char* expected[] = {
52
"[gc,start", "] Test GC (Allocation Failure)",
53
"[gc", "] Test GC (Allocation Failure) ", "M) ", "ms",
54
NULL
55
};
56
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));
57
}
58
59
TEST_VM_F(GCTraceTimeTest, full_multitag) {
60
set_log_config(TestLogFileName, "gc+ref=debug,gc+ref+start=debug");
61
62
LogTarget(Debug, gc, ref) gc_debug;
63
LogTarget(Debug, gc, ref, start) gc_start_debug;
64
65
EXPECT_TRUE(gc_debug.is_enabled());
66
EXPECT_TRUE(gc_start_debug.is_enabled());
67
68
{
69
ThreadInVMfromNative tvn(JavaThread::current());
70
MutexLocker lock(Heap_lock); // Needed to read heap usage
71
GCTraceTime(Debug, gc, ref) timer("Test GC", NULL, GCCause::_allocation_failure, true);
72
}
73
74
const char* expected[] = {
75
"[gc,ref,start", "] Test GC (Allocation Failure)",
76
"[gc,ref", "] Test GC (Allocation Failure) ", "M) ", "ms",
77
NULL
78
};
79
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));
80
}
81
82
TEST_VM_F(GCTraceTimeTest, no_heap) {
83
set_log_config(TestLogFileName, "gc=debug,gc+start=debug");
84
85
LogTarget(Debug, gc) gc_debug;
86
LogTarget(Debug, gc, start) gc_start_debug;
87
88
EXPECT_TRUE(gc_debug.is_enabled());
89
EXPECT_TRUE(gc_start_debug.is_enabled());
90
91
{
92
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, false);
93
}
94
95
const char* expected[] = {
96
// [2.975s][debug][gc,start] Test GC (Allocation Failure)
97
"[gc,start", "] Test GC (Allocation Failure)",
98
// [2.975s][debug][gc ] Test GC (Allocation Failure) 0.026ms
99
"[gc", "] Test GC (Allocation Failure) ", "ms",
100
NULL
101
};
102
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));
103
104
const char* not_expected[] = {
105
// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms
106
"[gc", "] Test GC ", "M) ", "ms",
107
};
108
EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected));
109
}
110
111
TEST_VM_F(GCTraceTimeTest, no_cause) {
112
set_log_config(TestLogFileName, "gc=debug,gc+start=debug");
113
114
LogTarget(Debug, gc) gc_debug;
115
LogTarget(Debug, gc, start) gc_start_debug;
116
117
EXPECT_TRUE(gc_debug.is_enabled());
118
EXPECT_TRUE(gc_start_debug.is_enabled());
119
120
{
121
ThreadInVMfromNative tvn(JavaThread::current());
122
MutexLocker lock(Heap_lock); // Needed to read heap usage
123
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, true);
124
}
125
126
const char* expected[] = {
127
// [2.975s][debug][gc,start] Test GC
128
"[gc,start", "] Test GC",
129
// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms
130
"[gc", "] Test GC ", "M) ", "ms",
131
NULL
132
};
133
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));
134
}
135
136
TEST_VM_F(GCTraceTimeTest, no_heap_no_cause) {
137
set_log_config(TestLogFileName, "gc=debug,gc+start=debug");
138
139
LogTarget(Debug, gc) gc_debug;
140
LogTarget(Debug, gc, start) gc_start_debug;
141
142
EXPECT_TRUE(gc_debug.is_enabled());
143
EXPECT_TRUE(gc_start_debug.is_enabled());
144
145
{
146
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, false);
147
}
148
149
const char* expected[] = {
150
// [2.975s][debug][gc,start] Test GC
151
"[gc,start", "] Test GC",
152
// [2.975s][debug][gc ] Test GC 0.026ms
153
"[gc", "] Test GC ", "ms",
154
NULL
155
};
156
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected));
157
158
const char* not_expected[] = {
159
// [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms
160
"[gc", "] Test GC ", "M) ", "ms",
161
};
162
EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected));
163
}
164
165