Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/jdk/jfr/event/gc/objectcount/ObjectCountAfterGCEvent.java
41710 views
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.
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 jdk.jfr.event.gc.objectcount;
25
26
import java.util.List;
27
import java.util.Optional;
28
import java.util.stream.Collectors;
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.Events;
35
36
37
public class ObjectCountAfterGCEvent {
38
39
private static final String objectCountEventPath = EventNames.ObjectCountAfterGC;
40
private static final String gcEventPath = EventNames.GarbageCollection;
41
private static final String heapSummaryEventPath = EventNames.GCHeapSummary;
42
43
public static void test(String gcName) throws Exception {
44
Recording recording = new Recording();
45
recording.enable(objectCountEventPath);
46
recording.enable(gcEventPath);
47
recording.enable(heapSummaryEventPath);
48
49
ObjectCountEventVerifier.createTestData();
50
recording.start();
51
System.gc();
52
System.gc();
53
recording.stop();
54
55
System.out.println("gcName=" + gcName);
56
for (RecordedEvent event : Events.fromRecording(recording)) {
57
System.out.println("Event: " + event);
58
}
59
60
List<RecordedEvent> events= Events.fromRecording(recording);
61
Optional<RecordedEvent> gcEvent = events.stream()
62
.filter(e -> isMySystemGc(e, gcName))
63
.findFirst();
64
Asserts.assertTrue(gcEvent.isPresent(), "No event System.gc event of type " + gcEventPath);
65
System.out.println("Found System.gc event: " + gcEvent.get());
66
int gcId = Events.assertField(gcEvent.get(), "gcId").getValue();
67
68
List<RecordedEvent> objCountEvents = events.stream()
69
.filter(e -> Events.isEventType(e, objectCountEventPath))
70
.filter(e -> isGcId(e, gcId))
71
.collect(Collectors.toList());
72
Asserts.assertFalse(objCountEvents.isEmpty(), "No objCountEvents for gcId=" + gcId);
73
74
Optional<RecordedEvent> heapSummaryEvent = events.stream()
75
.filter(e -> Events.isEventType(e, heapSummaryEventPath))
76
.filter(e -> isGcId(e, gcId))
77
.filter(e -> "After GC".equals(Events.assertField(e, "when").getValue()))
78
.findFirst();
79
Asserts.assertTrue(heapSummaryEvent.isPresent(), "No heapSummary for gcId=" + gcId);
80
System.out.println("Found heapSummaryEvent: " + heapSummaryEvent.get());
81
82
Events.assertField(heapSummaryEvent.get(), "heapUsed").atLeast(0L).getValue();
83
ObjectCountEventVerifier.verify(objCountEvents);
84
}
85
86
private static boolean isGcId(RecordedEvent event, int gcId) {
87
return gcId == (int)Events.assertField(event, "gcId").getValue();
88
}
89
90
private static boolean isMySystemGc(RecordedEvent event, String gcName) {
91
return Events.isEventType(event, gcEventPath) &&
92
gcName.equals(Events.assertField(event, "name").getValue()) &&
93
"System.gc()".equals(Events.assertField(event, "cause").getValue());
94
}
95
96
}
97
98