author | jcbeyler |
Thu, 19 Jul 2018 18:21:24 -0700 | |
changeset 51210 | e750c1a054fa |
parent 51138 | 914f305ba6fa |
child 51559 | 57f1bf06742e |
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 |
|
28 |
* @build Frame HeapMonitor |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
50579
diff
changeset
|
29 |
* @summary Verifies the JVMTI Heap Monitor interval when allocating arrays. |
50579 | 30 |
* @compile HeapMonitorArrayAllSampledTest.java |
31 |
* @run main/othervm/native -agentlib:HeapMonitorTest MyPackage.HeapMonitorArrayAllSampledTest |
|
32 |
*/ |
|
33 |
||
34 |
public class HeapMonitorArrayAllSampledTest { |
|
35 |
||
36 |
// Do 1000 iterations and expect maxIteration samples. |
|
37 |
private static final int maxIteration = 1000; |
|
38 |
private static int array[]; |
|
39 |
||
40 |
private static void allocate(int size) { |
|
41 |
for (int j = 0; j < maxIteration; j++) { |
|
42 |
array = new int[size]; |
|
43 |
} |
|
44 |
} |
|
45 |
||
46 |
public static void main(String[] args) { |
|
47 |
int sizes[] = {1000, 10000, 100000, 1000000}; |
|
48 |
||
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
50579
diff
changeset
|
49 |
HeapMonitor.setSamplingInterval(0); |
50579 | 50 |
HeapMonitor.enableSamplingEvents(); |
51 |
||
52 |
for (int currentSize : sizes) { |
|
53 |
System.out.println("Testing size " + currentSize); |
|
54 |
||
55 |
HeapMonitor.resetEventStorage(); |
|
56 |
allocate(currentSize); |
|
57 |
||
58 |
// 10% error ensures a sanity test without becoming flaky. |
|
51138
914f305ba6fa
8205725: Update the JVMTI Spec for Heap Sampling
jcbeyler
parents:
50579
diff
changeset
|
59 |
// 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:
50579
diff
changeset
|
60 |
// statistical geometric variable around the sampling interval. This means that the test could be |
50579 | 61 |
// unlucky and not achieve the mean average fast enough for the test case. |
62 |
if (!HeapMonitor.statsHaveExpectedNumberSamples(maxIteration, 10)) { |
|
63 |
throw new RuntimeException("Statistics should show about " + maxIteration + " samples."); |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
} |