24
24
*/
25
25
package org .graalvm .compiler .core .test .jfr ;
26
26
27
+ import java .io .IOException ;
27
28
import java .lang .reflect .Constructor ;
28
29
import java .lang .reflect .InvocationTargetException ;
30
+ import java .util .List ;
29
31
30
32
import org .graalvm .compiler .core .common .PermanentBailoutException ;
31
- import org .graalvm .compiler .core .test .GraalCompilerTest ;
33
+ import org .graalvm .compiler .core .test .SubprocessTest ;
32
34
import org .graalvm .compiler .serviceprovider .GraalServices ;
33
35
import org .graalvm .compiler .serviceprovider .JavaVersionUtil ;
34
36
import org .graalvm .compiler .test .AddExports ;
37
+ import org .graalvm .compiler .test .SubprocessUtil ;
35
38
import org .junit .Assert ;
36
39
import org .junit .Assume ;
37
- import org .junit .BeforeClass ;
38
40
import org .junit .Test ;
39
41
import org .objectweb .asm .AnnotationVisitor ;
40
42
import org .objectweb .asm .ClassWriter ;
52
54
* {@code jdk.jfr.Event.commit()} method.
53
55
*
54
56
* See the documentation attached to {@code jdk.jfr.internal.event.EventWriter} for more detail.
57
+ *
58
+ * This test must run in a separate JVM process. It enables JFR instrumentation, which affects
59
+ * Truffle PartialEvaluationTests.
55
60
*/
56
61
@ AddExports ("jdk.jfr/jdk.jfr.internal.event" )
57
- public class TestGetEventWriter extends GraalCompilerTest {
62
+ public class TestGetEventWriter extends SubprocessTest {
58
63
59
- @ BeforeClass
60
- public static void beforeClass () throws Throwable {
64
+ private static void initializeJFR () {
61
65
Assume .assumeTrue ("JDK-8282420 came in JDK 19" , JavaVersionUtil .JAVA_SPEC >= 19 );
62
66
Assume .assumeTrue ("Requires JDK-8290075" , GraalServices .hasLookupMethodWithCaller ());
63
67
try (Recording r = new Recording ()) {
@@ -78,6 +82,34 @@ static class InitializationEvent extends Event {
78
82
}
79
83
80
84
@ Test
85
+ public void test () throws IOException , InterruptedException {
86
+ Assume .assumeTrue ("JDK-8282420 came in JDK 19" , JavaVersionUtil .JAVA_SPEC >= 19 );
87
+ launchSubprocess (() -> {
88
+ try {
89
+ initializeJFR ();
90
+ testInitializationEvent ();
91
+ testNonEvent ();
92
+ testRegisteredTrueEvent ();
93
+ testRegisteredFalseEvent ();
94
+ testMyCommitRegisteredTrue ();
95
+ testMyCommitRegisteredFalse ();
96
+ testStaticCommit ();
97
+ } catch (Throwable t ) {
98
+ throw rethrowSilently (RuntimeException .class , t );
99
+ }
100
+ });
101
+ }
102
+
103
+ @ Override
104
+ public void configSubprocess (List <String > vmArgs ) {
105
+ vmArgs .add (SubprocessUtil .PACKAGE_OPENING_OPTIONS );
106
+ }
107
+
108
+ @ SuppressWarnings ({"unused" , "unchecked" })
109
+ private static <E extends Throwable > E rethrowSilently (Class <E > type , Throwable ex ) throws E {
110
+ throw (E ) ex ;
111
+ }
112
+
81
113
public void testInitializationEvent () {
82
114
InitializationEvent event = new InitializationEvent ();
83
115
ResolvedJavaMethod method = getResolvedJavaMethod (event .getClass (), "commit" );
@@ -90,15 +122,13 @@ public void testInitializationEvent() {
90
122
// API. It has its own stand-alone "commit()V", which is not an override, that
91
123
// attempts to resolve and link against EventWriterFactory. This user implementation
92
124
// is not blessed for linkage.
93
- @ Test
94
125
public void testNonEvent () throws Throwable {
95
126
testEvent ("Non" , "java/lang/Object" , null , "commit" , false );
96
127
}
97
128
98
129
// The user has defined a class which overrides and implements the "commit()V"
99
130
// method declared final in jdk.jfr.Event.
100
131
// This user implementation is not blessed for linkage.
101
- @ Test
102
132
public void testRegisteredTrueEvent () throws Throwable {
103
133
testEvent ("Registered" , "jdk/jfr/Event" , true , "commit" , false );
104
134
}
@@ -111,15 +141,13 @@ public void testRegisteredTrueEvent() throws Throwable {
111
141
// classify it as being outside of the JFR system. Attempting to register
112
142
// such a class throws an IllegalArgumentException. The user-defined
113
143
// "commit()V" method is still not blessed for linkage, even after registration.
114
- @ Test
115
144
public void testRegisteredFalseEvent () throws Throwable {
116
145
testEvent ("Registered" , "jdk/jfr/Event" , false , "commit" , false );
117
146
}
118
147
119
148
// The user has implemented another method, "myCommit()V", not an override nor
120
149
// overload. that attempts to resolve and link EventWriterFactory. This will fail,
121
150
// because "myCommit()V" is not blessed for linkage.
122
- @ Test
123
151
public void testMyCommitRegisteredTrue () throws Throwable {
124
152
testEvent ("MyCommit" , "jdk/jfr/Event" , true , "myCommit" , false );
125
153
}
@@ -129,15 +157,13 @@ public void testMyCommitRegisteredTrue() throws Throwable {
129
157
// Since the user has not defined any final methods in jdk.jfr.Event,
130
158
// the class is not excluded wholesale from the JFR system.
131
159
// Invoking the real "commit()V", installed by the framework, is OK.
132
- @ Test
133
160
public void testMyCommitRegisteredFalse () throws Throwable {
134
161
testEvent ("MyCommit" , "jdk/jfr/Event" , false , "myCommit" , false );
135
162
}
136
163
137
164
// Events located in the boot class loader can create a static
138
165
// commit-method to emit events. It must not be used by code
139
166
// outside of the boot class loader.
140
- @ Test
141
167
public void testStaticCommit () throws Throwable {
142
168
testEvent ("StaticCommit" , "jdk/jfr/Event" , null , "commit" , true );
143
169
}
0 commit comments