50113
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 2018, 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. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.jfr.event.gc.heapsummary;
|
|
27 |
|
|
28 |
import java.time.Duration;
|
|
29 |
|
|
30 |
import jdk.jfr.Recording;
|
|
31 |
import jdk.jfr.consumer.RecordedEvent;
|
|
32 |
import jdk.test.lib.Asserts;
|
|
33 |
import jdk.test.lib.jfr.EventNames;
|
|
34 |
import jdk.test.lib.jfr.EventVerifier;
|
|
35 |
import jdk.test.lib.jfr.Events;
|
|
36 |
import jdk.test.lib.jfr.GCHelper;
|
|
37 |
import sun.hotspot.WhiteBox;
|
|
38 |
|
51214
|
39 |
/**
|
50113
|
40 |
* @test
|
|
41 |
* @key jfr
|
51214
|
42 |
* @requires vm.hasJFR
|
50113
|
43 |
* @requires vm.gc == "Parallel" | vm.gc == null
|
|
44 |
* @library /test/lib /test/jdk
|
|
45 |
* @build sun.hotspot.WhiteBox
|
|
46 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
|
47 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
|
48 |
-XX:-UseFastUnorderedTimeStamps -Xmx16m -XX:+UseParallelGC
|
|
49 |
-Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
|
|
50 |
jdk.jfr.event.gc.heapsummary.TestHeapSummaryCommittedSize
|
|
51 |
*/
|
|
52 |
public class TestHeapSummaryCommittedSize {
|
|
53 |
private final static String EVENT_NAME = EventNames.GCHeapSummary;
|
|
54 |
|
|
55 |
public static void main(String[] args) throws Exception {
|
|
56 |
Recording recording = new Recording();
|
|
57 |
recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
|
|
58 |
|
|
59 |
recording.start();
|
|
60 |
System.gc();
|
|
61 |
recording.stop();
|
|
62 |
|
|
63 |
boolean isAnyFound = false;
|
|
64 |
for (RecordedEvent event : Events.fromRecording(recording)) {
|
|
65 |
System.out.println("Event: " + event);
|
|
66 |
if (!Events.isEventType(event, EVENT_NAME)) {
|
|
67 |
continue;
|
|
68 |
}
|
|
69 |
isAnyFound = true;
|
|
70 |
CommittedHeapSizeVerifier verifier = new CommittedHeapSizeVerifier(event);
|
|
71 |
verifier.verify();
|
|
72 |
}
|
|
73 |
Asserts.assertTrue(isAnyFound, "No matching event");
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
class CommittedHeapSizeVerifier extends EventVerifier {
|
|
78 |
private final static long MAX_UNALIGNED_COMMITTED_SIZE = 16 * 1024 * 1024;
|
|
79 |
private final long MAX_ALIGNED_COMMITTED_SIZE;
|
|
80 |
|
|
81 |
public CommittedHeapSizeVerifier(RecordedEvent event) {
|
|
82 |
super(event);
|
|
83 |
WhiteBox wb = WhiteBox.getWhiteBox();
|
|
84 |
long heapAlignment = wb.getHeapAlignment();
|
|
85 |
MAX_ALIGNED_COMMITTED_SIZE = GCHelper.alignUp(
|
|
86 |
MAX_UNALIGNED_COMMITTED_SIZE,heapAlignment);
|
|
87 |
}
|
|
88 |
|
|
89 |
public void verify() throws Exception {
|
|
90 |
Events.assertField(event, "heapSpace.committedSize").atLeast(0L).atMost(MAX_ALIGNED_COMMITTED_SIZE);
|
|
91 |
}
|
|
92 |
}
|