Skip to content

Commit c2c3f61

Browse files
committed
Resolved review comments.
1 parent e1ae1b0 commit c2c3f61

File tree

1 file changed

+59
-68
lines changed

1 file changed

+59
-68
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/JFRPartialEvaluationTest.java

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ public void testException() throws IOException, InterruptedException {
5656
}
5757

5858
private void performTestException() {
59-
RootTestNode root = new RootTestNode(new FrameDescriptor(), "NewException", new NewTruffleExceptionNode());
59+
RootTestNode root = new RootTestNode(new FrameDescriptor(), "NewException", new AbstractTestNode() {
60+
@Override
61+
public int execute(VirtualFrame frame) {
62+
try {
63+
throw new TruffleExceptionImpl(42);
64+
} catch (TruffleExceptionImpl e) {
65+
return e.value;
66+
}
67+
}
68+
});
6069
if (Runtime.version().feature() < 22) {
6170
Class<?> throwableTracer = findThrowableTracerClass();
6271
ResolvedJavaMethod traceThrowable = getResolvedJavaMethod(throwableTracer, "traceThrowable");
@@ -72,6 +81,15 @@ private void performTestException() {
7281
}
7382
}
7483

84+
@SuppressWarnings("serial")
85+
private static final class TruffleExceptionImpl extends AbstractTruffleException {
86+
final int value;
87+
88+
TruffleExceptionImpl(int value) {
89+
this.value = value;
90+
}
91+
}
92+
7593
private static Class<?> findThrowableTracerClass() {
7694
try {
7795
return Class.forName("jdk.jfr.internal.instrument.ThrowableTracer");
@@ -86,7 +104,16 @@ public void testError() throws IOException, InterruptedException {
86104
}
87105

88106
private void performTestError() {
89-
RootTestNode root = new RootTestNode(new FrameDescriptor(), "NewError", new NewErrorNode());
107+
RootTestNode root = new RootTestNode(new FrameDescriptor(), "NewError", new AbstractTestNode() {
108+
@Override
109+
public int execute(VirtualFrame frame) {
110+
try {
111+
throw new ErrorImpl(42);
112+
} catch (ErrorImpl e) {
113+
return e.value;
114+
}
115+
}
116+
});
90117
if (Runtime.version().feature() < 22) {
91118
Class<?> throwableTracer = findThrowableTracerClass();
92119
ResolvedJavaMethod traceThrowable = getResolvedJavaMethod(throwableTracer, "traceThrowable");
@@ -104,6 +131,22 @@ private void performTestError() {
104131
}
105132
}
106133

134+
@SuppressWarnings("serial")
135+
private static final class ErrorImpl extends Error {
136+
137+
final int value;
138+
139+
ErrorImpl(int value) {
140+
this.value = value;
141+
}
142+
143+
@Override
144+
@SuppressWarnings("sync-override")
145+
public Throwable fillInStackTrace() {
146+
return this;
147+
}
148+
}
149+
107150
@Test
108151
public void testJFREvent() throws IOException, InterruptedException {
109152
runInSubprocessWithJFREnabled(this::performTestJFREvent);
@@ -112,7 +155,16 @@ public void testJFREvent() throws IOException, InterruptedException {
112155
private void performTestJFREvent() {
113156
ResolvedJavaMethod shouldCommit = getResolvedJavaMethod(TestEvent.class, "shouldCommit");
114157
ResolvedJavaMethod commit = getResolvedJavaMethod(TestEvent.class, "commit");
115-
RootTestNode root = new RootTestNode(new FrameDescriptor(), "JFREvent", new JFREventNode());
158+
RootTestNode root = new RootTestNode(new FrameDescriptor(), "JFREvent", new AbstractTestNode() {
159+
@Override
160+
public int execute(VirtualFrame frame) {
161+
TestEvent event = new TestEvent();
162+
if (event.shouldCommit()) {
163+
event.commit();
164+
}
165+
return 1;
166+
}
167+
});
116168
OptimizedCallTarget callTarget = (OptimizedCallTarget) root.getCallTarget();
117169
StructuredGraph graph = partialEval(callTarget, new Object[0]);
118170
// Calls to JFR event methods must not be inlined.
@@ -122,6 +174,10 @@ private void performTestJFREvent() {
122174
assertTrue("The number of graal nodes for an exception instantiation exceeded 100.", graph.getNodeCount() < 100);
123175
}
124176

177+
@Name("test.JFRPartialEvaluationTestEvent")
178+
private static class TestEvent extends Event {
179+
}
180+
125181
private static MethodCallTargetNode findInvoke(StructuredGraph graph, ResolvedJavaMethod expectedMethod) {
126182
for (MethodCallTargetNode node : graph.getNodes(MethodCallTargetNode.TYPE)) {
127183
ResolvedJavaMethod targetMethod = node.targetMethod();
@@ -156,69 +212,4 @@ private static void runInSubprocessWithJFREnabled(Runnable action) throws IOExce
156212
}
157213
}
158214
}
159-
160-
private static final class NewTruffleExceptionNode extends AbstractTestNode {
161-
162-
@Override
163-
public int execute(VirtualFrame frame) {
164-
try {
165-
throw new TruffleExceptionImpl(42);
166-
} catch (TruffleExceptionImpl e) {
167-
return e.value;
168-
}
169-
}
170-
171-
@SuppressWarnings("serial")
172-
private static final class TruffleExceptionImpl extends AbstractTruffleException {
173-
final int value;
174-
175-
TruffleExceptionImpl(int value) {
176-
this.value = value;
177-
}
178-
}
179-
}
180-
181-
private static final class NewErrorNode extends AbstractTestNode {
182-
183-
@Override
184-
public int execute(VirtualFrame frame) {
185-
try {
186-
throw new ErrorImpl(42);
187-
} catch (ErrorImpl e) {
188-
return e.value;
189-
}
190-
}
191-
192-
@SuppressWarnings("serial")
193-
private static final class ErrorImpl extends Error {
194-
195-
final int value;
196-
197-
ErrorImpl(int value) {
198-
this.value = value;
199-
}
200-
201-
@Override
202-
@SuppressWarnings("sync-override")
203-
public Throwable fillInStackTrace() {
204-
return this;
205-
}
206-
}
207-
}
208-
209-
private static final class JFREventNode extends AbstractTestNode {
210-
211-
@Override
212-
public int execute(VirtualFrame frame) {
213-
TestEvent event = new TestEvent();
214-
if (event.shouldCommit()) {
215-
event.commit();
216-
}
217-
return 1;
218-
}
219-
}
220-
221-
@Name("test.JFRPartialEvaluationTestEvent")
222-
private static class TestEvent extends Event {
223-
}
224215
}

0 commit comments

Comments
 (0)