Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/ThresholdNotificationsTest.java
41153 views
1
/*
2
* Copyright (c) 2014, 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
/*
25
* @test ThresholdNotificationsTest
26
* @summary testing of getUsageThreshold()
27
* @library /test/lib /
28
* @modules java.base/jdk.internal.misc
29
* java.management
30
*
31
* @build sun.hotspot.WhiteBox
32
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
33
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing
34
* -XX:+WhiteBoxAPI -XX:-MethodFlushing -XX:CompileCommand=compileonly,null::*
35
* -XX:+SegmentedCodeCache
36
* compiler.codecache.jmx.ThresholdNotificationsTest
37
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing
38
* -XX:+WhiteBoxAPI -XX:-MethodFlushing -XX:CompileCommand=compileonly,null::*
39
* -XX:-SegmentedCodeCache
40
* compiler.codecache.jmx.ThresholdNotificationsTest
41
*/
42
43
package compiler.codecache.jmx;
44
45
import jdk.test.lib.Asserts;
46
import jdk.test.lib.Utils;
47
import sun.hotspot.code.BlobType;
48
49
import javax.management.ListenerNotFoundException;
50
import javax.management.Notification;
51
import javax.management.NotificationEmitter;
52
import javax.management.NotificationListener;
53
import java.lang.management.ManagementFactory;
54
import java.lang.management.MemoryNotificationInfo;
55
import java.lang.management.MemoryPoolMXBean;
56
57
public class ThresholdNotificationsTest implements NotificationListener {
58
59
private final static long WAIT_TIME = 10000L;
60
private volatile long counter;
61
private final BlobType btype;
62
63
public static void main(String[] args) {
64
for (BlobType bt : BlobType.getAvailable()) {
65
if (CodeCacheUtils.isCodeHeapPredictable(bt)) {
66
new ThresholdNotificationsTest(bt).runTest();
67
}
68
}
69
}
70
71
public ThresholdNotificationsTest(BlobType btype) {
72
this.btype = btype;
73
counter = 0L;
74
CodeCacheUtils.disableCollectionUsageThresholds();
75
}
76
77
@Override
78
public void handleNotification(Notification notification, Object handback) {
79
String nType = notification.getType();
80
String poolName
81
= CodeCacheUtils.getPoolNameFromNotification(notification);
82
// consider code cache events only
83
if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) {
84
Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
85
nType, "Unexpected event received: " + nType);
86
if (poolName.equals(btype.getMemoryPool().getName())) {
87
counter++;
88
}
89
}
90
}
91
92
protected void runTest() {
93
int iterationsCount
94
= Integer.getInteger("jdk.test.lib.iterations", 1);
95
MemoryPoolMXBean bean = btype.getMemoryPool();
96
((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
97
addNotificationListener(this, null, null);
98
for (int i = 0; i < iterationsCount; i++) {
99
CodeCacheUtils.hitUsageThreshold(bean, btype);
100
}
101
Asserts.assertTrue(
102
Utils.waitForCondition(
103
() -> (CodeCacheUtils.isCodeHeapPredictable(btype) ?
104
(counter == iterationsCount) : (counter >= iterationsCount)),
105
WAIT_TIME),
106
"Couldn't receive expected notifications count");
107
try {
108
((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
109
removeNotificationListener(this);
110
} catch (ListenerNotFoundException ex) {
111
throw new AssertionError("Can't remove notification listener", ex);
112
}
113
System.out.printf("INFO: Scenario finished successfully for %s%n",
114
bean.getName());
115
}
116
}
117
118