Skip to content

Commit ff7352a

Browse files
committed
Convert TranslateExceptionNode to DSL inlinable
1 parent 8fb27d4 commit ff7352a

File tree

8 files changed

+39
-31
lines changed

8 files changed

+39
-31
lines changed

src/main/java/org/truffleruby/language/RubyCoreMethodRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Object execute(VirtualFrame frame) {
6161
CompilerDirectives.transferToInterpreterAndInvalidate();
6262
translateExceptionNode = insert(TranslateExceptionNode.create());
6363
}
64-
throw translateExceptionNode.executeTranslation(t);
64+
throw translateExceptionNode.executeCached(t);
6565
}
6666
}
6767

src/main/java/org/truffleruby/language/RubyEvalRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Object execute(VirtualFrame frame) {
7878
CompilerDirectives.transferToInterpreterAndInvalidate();
7979
translateExceptionNode = insert(TranslateExceptionNode.create());
8080
}
81-
throw translateExceptionNode.executeTranslation(t);
81+
throw translateExceptionNode.executeCached(t);
8282
}
8383
}
8484

src/main/java/org/truffleruby/language/RubyLambdaRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public Object execute(VirtualFrame frame) {
146146
CompilerDirectives.transferToInterpreterAndInvalidate();
147147
translateExceptionNode = insert(TranslateExceptionNode.create());
148148
}
149-
throw translateExceptionNode.executeTranslation(t);
149+
throw translateExceptionNode.executeCached(t);
150150
}
151151
}
152152

src/main/java/org/truffleruby/language/RubyMethodRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Object execute(VirtualFrame frame) {
9696
CompilerDirectives.transferToInterpreterAndInvalidate();
9797
translateExceptionNode = insert(TranslateExceptionNode.create());
9898
}
99-
throw translateExceptionNode.executeTranslation(t);
99+
throw translateExceptionNode.executeCached(t);
100100
}
101101
}
102102

src/main/java/org/truffleruby/language/RubyProcRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Object execute(VirtualFrame frame) {
104104
CompilerDirectives.transferToInterpreterAndInvalidate();
105105
translateExceptionNode = insert(TranslateExceptionNode.create());
106106
}
107-
throw translateExceptionNode.executeTranslation(t);
107+
throw translateExceptionNode.executeCached(t);
108108
}
109109
}
110110

src/main/java/org/truffleruby/language/exceptions/TryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Object doTry(VirtualFrame frame,
8484
CompilerDirectives.transferToInterpreterAndInvalidate();
8585
translateExceptionNode = insert(TranslateExceptionNode.create());
8686
}
87-
throw translateExceptionNode.executeTranslation(t);
87+
throw translateExceptionNode.executeCached(t);
8888
}
8989

9090
if (elsePart != null) {

src/main/java/org/truffleruby/language/methods/CallForeignMethodNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Object call(Object receiver, String methodName, Object block, Object[] arguments
6969
return foreignInvokeNode.execute(this, receiver, methodName, newArguments);
7070
} catch (Throwable t) {
7171
errorProfile.enter(this);
72-
throw translateException.executeTranslation(t);
72+
throw translateException.execute(this, t);
7373
}
7474
}
7575

src/main/java/org/truffleruby/language/methods/TranslateExceptionNode.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.language.methods;
1111

1212
import com.oracle.truffle.api.dsl.Fallback;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
1314
import com.oracle.truffle.api.dsl.NeverDefault;
1415
import com.oracle.truffle.api.exception.AbstractTruffleException;
1516
import com.oracle.truffle.api.strings.TruffleString;
@@ -35,14 +36,19 @@
3536
import org.truffleruby.language.control.TerminationException;
3637

3738
@GenerateUncached
39+
@GenerateInline(inlineByDefault = true)
3840
public abstract class TranslateExceptionNode extends RubyBaseNode {
3941

4042
@NeverDefault
4143
public static TranslateExceptionNode create() {
4244
return TranslateExceptionNodeGen.create();
4345
}
4446

45-
public abstract RuntimeException executeTranslation(Throwable throwable);
47+
public abstract RuntimeException execute(Node node, Throwable throwable);
48+
49+
public final RuntimeException executeCached(Throwable throwable) {
50+
return execute(this, throwable);
51+
}
4652

4753
public static void logJavaException(RubyContext context, Node currentNode, Throwable exception) {
4854
if (context.getOptions().EXCEPTIONS_PRINT_JAVA) {
@@ -65,35 +71,35 @@ public static void logUncaughtJavaException(RubyContext context, Node currentNod
6571
}
6672

6773
@Specialization
68-
RuntimeException translate(ControlFlowException e) {
74+
static RuntimeException translate(ControlFlowException e) {
6975
throw e;
7076
}
7177

7278
@Specialization
73-
RuntimeException translate(AbstractTruffleException e) {
79+
static RuntimeException translate(AbstractTruffleException e) {
7480
throw e;
7581
}
7682

7783
@Specialization
78-
RuntimeException translate(TerminationException e) {
84+
static RuntimeException translate(TerminationException e) {
7985
throw e;
8086
}
8187

8288
@Specialization
83-
RuntimeException translate(ThreadDeath e) {
89+
static RuntimeException translate(ThreadDeath e) {
8490
throw e;
8591
}
8692

8793
@Specialization(guards = "needsSpecialTranslation(e)")
88-
RuntimeException translateSpecial(Throwable e) {
89-
throw doTranslateSpecial(e);
94+
static RuntimeException translateSpecial(Node node, Throwable e) {
95+
throw doTranslateSpecial(node, e);
9096
}
9197

9298
@Fallback
93-
RuntimeException translate(Throwable e) {
99+
static RuntimeException translate(Node node, Throwable e) {
94100
// An internal exception
95101
CompilerDirectives.transferToInterpreterAndInvalidate();
96-
logUncaughtJavaException(getContext(), this, e);
102+
logUncaughtJavaException(getContext(node), node, e);
97103
throw ExceptionOperations.rethrow(e);
98104
}
99105

@@ -105,50 +111,52 @@ protected boolean needsSpecialTranslation(Throwable e) {
105111
}
106112

107113
@TruffleBoundary
108-
private RaiseException doTranslateSpecial(Throwable e) {
114+
private static RaiseException doTranslateSpecial(Node node, Throwable e) {
109115
if (e instanceof TruffleString.IllegalByteArrayLengthException) {
110-
return new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this));
116+
return new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node));
111117
} else if (e instanceof UnsupportedSpecializationException) {
112-
return new RaiseException(getContext(),
113-
translateUnsupportedSpecialization(getContext(), (UnsupportedSpecializationException) e));
118+
return new RaiseException(getContext(node),
119+
translateUnsupportedSpecialization(node, getContext(node), (UnsupportedSpecializationException) e));
114120
} else if (e instanceof StackOverflowError) {
115-
return new RaiseException(getContext(), translateStackOverflow(getContext(), (StackOverflowError) e));
121+
return new RaiseException(getContext(node),
122+
translateStackOverflow(node, getContext(node), (StackOverflowError) e));
116123
} else {
117-
return new RaiseException(getContext(), translateOutOfMemory(getContext(), (OutOfMemoryError) e));
124+
return new RaiseException(getContext(node),
125+
translateOutOfMemory(node, getContext(node), (OutOfMemoryError) e));
118126
}
119127
}
120128

121129
@TruffleBoundary
122-
private RubyException translateStackOverflow(RubyContext context, StackOverflowError error) {
130+
private static RubyException translateStackOverflow(Node node, RubyContext context, StackOverflowError error) {
123131
boolean ignore = InitStackOverflowClassesEagerlyNode.ignore(error);
124132
if (!ignore) {
125133
if (context.getOptions().EXCEPTIONS_WARN_STACKOVERFLOW) {
126134
// We cannot afford to initialize the Log class
127135
System.err.print("[ruby] WARNING StackOverflowError\n");
128136
}
129137

130-
logJavaException(context, this, error);
138+
logJavaException(context, node, error);
131139
}
132140

133-
return context.getCoreExceptions().systemStackErrorStackLevelTooDeep(this, error, !ignore);
141+
return context.getCoreExceptions().systemStackErrorStackLevelTooDeep(node, error, !ignore);
134142
}
135143

136144
@TruffleBoundary
137-
private RubyException translateOutOfMemory(RubyContext context, OutOfMemoryError error) {
145+
private static RubyException translateOutOfMemory(Node node, RubyContext context, OutOfMemoryError error) {
138146
if (context.getOptions().EXCEPTIONS_WARN_OUT_OF_MEMORY) {
139147
// We cannot afford to initialize the Log class
140148
System.err.print("[ruby] WARNING OutOfMemoryError\n");
141149
}
142150

143-
logJavaException(context, this, error);
144-
return context.getCoreExceptions().noMemoryError(this, error);
151+
logJavaException(context, node, error);
152+
return context.getCoreExceptions().noMemoryError(node, error);
145153
}
146154

147155
@TruffleBoundary
148-
private RubyException translateUnsupportedSpecialization(RubyContext context,
156+
private static RubyException translateUnsupportedSpecialization(Node node, RubyContext context,
149157
UnsupportedSpecializationException exception) {
150158

151-
logJavaException(context, this, exception);
159+
logJavaException(context, node, exception);
152160

153161
final StringBuilder builder = new StringBuilder();
154162
builder.append("TruffleRuby doesn't have a case for the ");
@@ -158,7 +166,7 @@ private RubyException translateUnsupportedSpecialization(RubyContext context,
158166
builder.append('\n');
159167
BacktraceFormatter.appendJavaStackTrace(exception, builder);
160168
String message = builder.toString().strip();
161-
return context.getCoreExceptions().typeError(message, this, exception);
169+
return context.getCoreExceptions().typeError(message, node, exception);
162170
}
163171

164172
public static StringBuilder argumentsToString(StringBuilder builder, Object[] arguments) {

0 commit comments

Comments
 (0)