author | dcubed |
Tue, 05 Jul 2016 14:00:21 -0700 | |
changeset 39696 | 80c9894e18f9 |
parent 36851 | 03e2f4d0a421 |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
28384 | 1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28645
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
28384 | 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 |
||
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
24 |
import jdk.test.lib.Asserts; |
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
25 |
import jdk.test.lib.Utils; |
28384 | 26 |
import java.lang.management.ManagementFactory; |
27 |
import java.lang.management.MemoryNotificationInfo; |
|
28 |
import java.lang.management.MemoryPoolMXBean; |
|
29 |
import javax.management.ListenerNotFoundException; |
|
30 |
import javax.management.Notification; |
|
31 |
import javax.management.NotificationEmitter; |
|
32 |
import javax.management.NotificationListener; |
|
33 |
import sun.hotspot.code.BlobType; |
|
34 |
||
35 |
/* |
|
36 |
* @test ThresholdNotificationsTest |
|
33730
30e064828045
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents:
31522
diff
changeset
|
37 |
* @library /testlibrary /test/lib |
36851 | 38 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28645
diff
changeset
|
39 |
* java.management |
28384 | 40 |
* @build ThresholdNotificationsTest |
41 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
|
42 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
|
43 |
* @run main/othervm -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing |
|
44 |
* -XX:-MethodFlushing -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
45 |
* -XX:+SegmentedCodeCache -XX:CompileCommand=compileonly,null::* |
|
46 |
* ThresholdNotificationsTest |
|
47 |
* @summary testing of getUsageThreshold() |
|
48 |
*/ |
|
49 |
public class ThresholdNotificationsTest implements NotificationListener { |
|
50 |
||
51 |
private final static long WAIT_TIME = 10000L; |
|
52 |
private volatile long counter; |
|
53 |
private final BlobType btype; |
|
54 |
||
55 |
public static void main(String[] args) { |
|
56 |
for (BlobType bt : BlobType.getAvailable()) { |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
57 |
new ThresholdNotificationsTest(bt).runTest(); |
28384 | 58 |
} |
59 |
} |
|
60 |
||
61 |
public ThresholdNotificationsTest(BlobType btype) { |
|
62 |
this.btype = btype; |
|
63 |
counter = 0L; |
|
64 |
CodeCacheUtils.disableCollectionUsageThresholds(); |
|
65 |
} |
|
66 |
||
67 |
@Override |
|
68 |
public void handleNotification(Notification notification, Object handback) { |
|
69 |
String nType = notification.getType(); |
|
70 |
String poolName |
|
71 |
= CodeCacheUtils.getPoolNameFromNotification(notification); |
|
72 |
// consider code cache events only |
|
73 |
if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) { |
|
74 |
Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, |
|
75 |
nType, "Unexpected event received: " + nType); |
|
76 |
if (poolName.equals(btype.getMemoryPool().getName())) { |
|
77 |
counter++; |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
protected void runTest() { |
|
83 |
int iterationsCount = |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
84 |
Integer.getInteger("jdk.test.lib.iterations", 1); |
28384 | 85 |
MemoryPoolMXBean bean = btype.getMemoryPool(); |
86 |
((NotificationEmitter) ManagementFactory.getMemoryMXBean()). |
|
87 |
addNotificationListener(this, null, null); |
|
88 |
for (int i = 0; i < iterationsCount; i++) { |
|
89 |
CodeCacheUtils.hitUsageThreshold(bean, btype); |
|
90 |
} |
|
91 |
Asserts.assertTrue( |
|
92 |
Utils.waitForCondition( |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
93 |
() -> (CodeCacheUtils.isCodeHeapPredictable(btype) ? |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
94 |
(counter == iterationsCount) : (counter >= iterationsCount)), |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
95 |
WAIT_TIME), |
28384 | 96 |
"Couldn't receive expected notifications count"); |
97 |
try { |
|
98 |
((NotificationEmitter) ManagementFactory.getMemoryMXBean()). |
|
99 |
removeNotificationListener(this); |
|
100 |
} catch (ListenerNotFoundException ex) { |
|
101 |
throw new AssertionError("Can't remove notification listener", ex); |
|
102 |
} |
|
103 |
System.out.printf("INFO: Scenario finished successfully for %s%n", |
|
104 |
bean.getName()); |
|
105 |
} |
|
106 |
} |