author | jcbeyler |
Tue, 17 Jul 2018 19:59:38 -0700 | |
changeset 51138 | 914f305ba6fa |
parent 51137 | e3bcc86855dd |
permissions | -rw-r--r-- |
50579 | 1 |
/* |
2 |
* Copyright (c) 2018, Google 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 |
package MyPackage; |
|
25 |
||
26 |
/** |
|
27 |
* @test |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
28 |
* @summary Verifies the JVMTI Heap Monitor sampling interval average. |
50579 | 29 |
* @build Frame HeapMonitor |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
30 |
* @compile HeapMonitorStatIntervalTest.java |
50579 | 31 |
* @requires vm.compMode != "Xcomp" |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
32 |
* @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorStatIntervalTest |
50579 | 33 |
*/ |
34 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
35 |
public class HeapMonitorStatIntervalTest { |
50579 | 36 |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
37 |
private native static double getAverageInterval(); |
50579 | 38 |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
39 |
private static boolean testIntervalOnce(int interval, boolean throwIfFailure) { |
50579 | 40 |
HeapMonitor.resetEventStorage(); |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
41 |
HeapMonitor.setSamplingInterval(interval); |
50579 | 42 |
|
43 |
HeapMonitor.enableSamplingEvents(); |
|
44 |
||
45 |
int allocationTotal = 10 * 1024 * 1024; |
|
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
46 |
int allocationIterations = 10; |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
47 |
|
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
48 |
double actualCount = 0; |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
49 |
for (int i = 0; i < allocationIterations; i++) { |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
50 |
HeapMonitor.resetEventStorage(); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
51 |
HeapMonitor.allocateSize(allocationTotal); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
52 |
actualCount += HeapMonitor.getEventStorageElementCount(); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
53 |
} |
50579 | 54 |
|
55 |
HeapMonitor.disableSamplingEvents(); |
|
56 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
57 |
double expectedCount = allocationTotal * allocationIterations / interval; |
50579 | 58 |
|
59 |
double error = Math.abs(actualCount - expectedCount); |
|
60 |
double errorPercentage = error / expectedCount * 100; |
|
61 |
||
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
62 |
boolean success = (errorPercentage < 10.0); |
50579 | 63 |
|
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
64 |
if (!success && throwIfFailure) { |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
65 |
throw new RuntimeException("Interval average over 10% for interval " + interval + " -> " |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
66 |
+ actualCount + ", " + expectedCount); |
50579 | 67 |
} |
68 |
||
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
69 |
return success; |
50579 | 70 |
} |
71 |
||
72 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
73 |
private static void testInterval(int interval) { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
74 |
// Test the interval twice, it can happen that the test is "unlucky" and the interval just goes above |
50579 | 75 |
// the 10% mark. So try again to squash flakiness. |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
76 |
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
77 |
// statistical geometric variable around the sampling interval. This means that the test could be |
50579 | 78 |
// unlucky and not achieve the mean average fast enough for the test case. |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
79 |
if (!testIntervalOnce(interval, false)) { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
80 |
testIntervalOnce(interval, true); |
50579 | 81 |
} |
82 |
} |
|
83 |
||
84 |
public static void main(String[] args) { |
|
85 |
int[] tab = {1024, 8192}; |
|
86 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
87 |
for (int intervalIdx = 0; intervalIdx < tab.length; intervalIdx++) { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
88 |
testInterval(tab[intervalIdx]); |
50579 | 89 |
} |
90 |
} |
|
91 |
} |