Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/management/HotspotRuntimeMBean/GetSafepointSyncTime.java
41149 views
1
/*
2
* Copyright (c) 2003, 2018, 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
/*
25
* @test
26
* @bug 4858522 8174734
27
* @summary Basic unit test of HotspotRuntimeMBean.getSafepointSyncTime()
28
* @author Steve Bohne
29
*
30
* @run main/othervm -XX:+UsePerfData GetSafepointSyncTime
31
*/
32
33
/*
34
* This test is just a sanity check and does not check for the correct value.
35
*/
36
37
import sun.management.*;
38
39
public class GetSafepointSyncTime {
40
41
private static HotspotRuntimeMBean mbean =
42
(HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean();
43
44
private static final long NUM_THREAD_DUMPS = 300;
45
46
static void checkPositive(long value, String label) {
47
if (value < 0)
48
throw new RuntimeException(label + " had a negative value of "
49
+ value);
50
}
51
52
static void validate(long count1, long count2, long time1, long time2,
53
String label) {
54
checkPositive(count1, label + ":count1");
55
checkPositive(count2, label + ":count2");
56
checkPositive(time1, label + ":time1");
57
checkPositive(time2, label + ":time2");
58
59
long countDiff = count2 - count1;
60
long timeDiff = time2 - time1;
61
62
if (countDiff < NUM_THREAD_DUMPS) {
63
throw new RuntimeException(label +
64
": Expected at least " + NUM_THREAD_DUMPS +
65
" safepoints but only got " + countDiff);
66
}
67
68
// getSafepointSyncTime is the accumulated time spent getting to a
69
// safepoint, so each safepoint will add a little to this, but the
70
// resolution is only milliseconds so we may not see it.
71
if (timeDiff < 0) {
72
throw new RuntimeException(label + ": Safepoint sync time " +
73
"decreased unexpectedly " +
74
"(time1 = " + time1 + "; " +
75
"time2 = " + time2 + ")");
76
}
77
78
System.out.format("%s: Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n",
79
label, count2, countDiff, time2, timeDiff);
80
81
}
82
83
public static void main(String args[]) throws Exception {
84
long count = mbean.getSafepointCount();
85
long time = mbean.getSafepointSyncTime();
86
87
checkPositive(count, "count");
88
checkPositive(time, "time");
89
90
// Thread.getAllStackTraces() should cause a safepoint.
91
92
for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
93
Thread.getAllStackTraces();
94
}
95
96
long count1 = mbean.getSafepointCount();
97
long time1 = mbean.getSafepointSyncTime();
98
99
validate(count, count1, time, time1, "Pass 1");
100
101
// repeat the experiment
102
103
for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
104
Thread.getAllStackTraces();
105
}
106
107
long count2 = mbean.getSafepointCount();
108
long time2 = mbean.getSafepointSyncTime();
109
110
validate(count1, count2, time1, time2, "Pass 2");
111
112
System.out.println("Test passed.");
113
}
114
}
115
116