author | jcbeyler |
Tue, 28 Aug 2018 21:25:37 -0700 | |
changeset 51559 | 57f1bf06742e |
parent 51175 | 65556ae796ad |
child 52597 | 3cda8fed1524 |
permissions | -rw-r--r-- |
50579 | 1 |
/* |
51559
57f1bf06742e
8210035: Fix copyrights for files created for the HeapMonitor work
jcbeyler
parents:
51175
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
50579 | 3 |
* Copyright (c) 2018, Google and/or its affiliates. All rights reserved. |
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
*/ |
|
24 |
||
25 |
package MyPackage; |
|
26 |
||
27 |
/** |
|
28 |
* @test |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
29 |
* @summary Verifies the JVMTI Heap Monitor sampling interval average. |
50579 | 30 |
* @build Frame HeapMonitor |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
31 |
* @compile HeapMonitorStatIntervalTest.java |
50579 | 32 |
* @requires vm.compMode != "Xcomp" |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
33 |
* @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorStatIntervalTest |
50579 | 34 |
*/ |
35 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
36 |
public class HeapMonitorStatIntervalTest { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
37 |
private static boolean testIntervalOnce(int interval, boolean throwIfFailure) { |
50579 | 38 |
HeapMonitor.resetEventStorage(); |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
39 |
HeapMonitor.setSamplingInterval(interval); |
50579 | 40 |
|
41 |
HeapMonitor.enableSamplingEvents(); |
|
42 |
||
43 |
int allocationTotal = 10 * 1024 * 1024; |
|
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
44 |
int allocationIterations = 10; |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
45 |
|
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
46 |
double actualCount = 0; |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
47 |
for (int i = 0; i < allocationIterations; i++) { |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
48 |
HeapMonitor.resetEventStorage(); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
49 |
HeapMonitor.allocateSize(allocationTotal); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
50 |
actualCount += HeapMonitor.getEventStorageElementCount(); |
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
51 |
} |
50579 | 52 |
|
53 |
HeapMonitor.disableSamplingEvents(); |
|
54 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
55 |
double expectedCount = allocationTotal * allocationIterations / interval; |
50579 | 56 |
|
57 |
double error = Math.abs(actualCount - expectedCount); |
|
58 |
double errorPercentage = error / expectedCount * 100; |
|
59 |
||
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
60 |
boolean success = (errorPercentage < 10.0); |
50579 | 61 |
|
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
62 |
if (!success && throwIfFailure) { |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
63 |
throw new RuntimeException("Interval average over 10% for interval " + interval + " -> " |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
64 |
+ actualCount + ", " + expectedCount); |
50579 | 65 |
} |
66 |
||
51137
e3bcc86855dd
8205652: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java fails
jcbeyler
parents:
50579
diff
changeset
|
67 |
return success; |
50579 | 68 |
} |
69 |
||
70 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
71 |
private static void testInterval(int interval) { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
72 |
// Test the interval twice, it can happen that the test is "unlucky" and the interval just goes above |
50579 | 73 |
// the 10% mark. So try again to squash flakiness. |
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
74 |
// 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
|
75 |
// statistical geometric variable around the sampling interval. This means that the test could be |
50579 | 76 |
// 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
|
77 |
if (!testIntervalOnce(interval, false)) { |
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
51137
diff
changeset
|
78 |
testIntervalOnce(interval, true); |
50579 | 79 |
} |
80 |
} |
|
81 |
||
82 |
public static void main(String[] args) { |
|
83 |
int[] tab = {1024, 8192}; |
|
84 |
||
51175
65556ae796ad
8207765: HeapMonitorStatIntervalTest.java fails with ZGC
jcbeyler
parents:
51140
diff
changeset
|
85 |
HeapMonitor.calculateAverageOneElementSize(); |
65556ae796ad
8207765: HeapMonitorStatIntervalTest.java fails with ZGC
jcbeyler
parents:
51140
diff
changeset
|
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 |
} |