Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java
42332 views
1
/*
2
* Copyright (c) 2016, 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
package jdk.jfr.api.consumer;
24
25
import static jdk.test.lib.Asserts.assertEquals;
26
import static jdk.test.lib.Asserts.assertFalse;
27
import static jdk.test.lib.Asserts.assertNotNull;
28
import static jdk.test.lib.Asserts.assertTrue;
29
30
import java.util.List;
31
32
import jdk.jfr.Event;
33
import jdk.jfr.Recording;
34
import jdk.jfr.consumer.RecordedEvent;
35
import jdk.jfr.consumer.RecordedFrame;
36
import jdk.jfr.consumer.RecordedMethod;
37
import jdk.jfr.consumer.RecordedStackTrace;
38
import jdk.test.lib.jfr.Events;
39
40
41
/**
42
* @test
43
* @summary Verifies that the method descriptor is correct
44
* @key jfr
45
* @requires vm.hasJFR
46
* @library /test/lib
47
* @run main/othervm jdk.jfr.api.consumer.TestRecordedMethodDescriptor
48
*/
49
public final class TestRecordedMethodDescriptor {
50
51
public static class MyEvent extends Event {
52
}
53
54
private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";
55
private static final String MAIN_METHOD_NAME = "main";
56
57
public static void main(String[] args) throws Exception {
58
try (Recording recording = new Recording()) {
59
recording.enable(MyEvent.class);
60
recording.start();
61
62
MyEvent event = new MyEvent();
63
event.commit();
64
recording.stop();
65
66
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
67
assertEquals(1, recordedEvents.size(), "Expected one event");
68
RecordedEvent recordedEvent = recordedEvents.get(0);
69
70
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
71
List<RecordedFrame> frames = stacktrace.getFrames();
72
assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
73
74
boolean foundMainMethod = false;
75
for (RecordedFrame frame : frames) {
76
RecordedMethod method = frame.getMethod();
77
String descr = method.getDescriptor();
78
assertNotNull(descr, "Method descriptor is null");
79
String name = method.getName();
80
assertNotNull(name, "Method name is null");
81
if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {
82
assertFalse(foundMainMethod, "main() method descriptor already recorded");
83
foundMainMethod = true;
84
}
85
}
86
assertTrue(foundMainMethod, "main() method descriptor has never been recorded");
87
}
88
}
89
}
90
91