10
10
package org .truffleruby .language .methods ;
11
11
12
12
import com .oracle .truffle .api .dsl .Fallback ;
13
+ import com .oracle .truffle .api .dsl .GenerateInline ;
13
14
import com .oracle .truffle .api .dsl .NeverDefault ;
14
15
import com .oracle .truffle .api .exception .AbstractTruffleException ;
15
16
import com .oracle .truffle .api .strings .TruffleString ;
35
36
import org .truffleruby .language .control .TerminationException ;
36
37
37
38
@ GenerateUncached
39
+ @ GenerateInline (inlineByDefault = true )
38
40
public abstract class TranslateExceptionNode extends RubyBaseNode {
39
41
40
42
@ NeverDefault
41
43
public static TranslateExceptionNode create () {
42
44
return TranslateExceptionNodeGen .create ();
43
45
}
44
46
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
+ }
46
52
47
53
public static void logJavaException (RubyContext context , Node currentNode , Throwable exception ) {
48
54
if (context .getOptions ().EXCEPTIONS_PRINT_JAVA ) {
@@ -65,35 +71,35 @@ public static void logUncaughtJavaException(RubyContext context, Node currentNod
65
71
}
66
72
67
73
@ Specialization
68
- RuntimeException translate (ControlFlowException e ) {
74
+ static RuntimeException translate (ControlFlowException e ) {
69
75
throw e ;
70
76
}
71
77
72
78
@ Specialization
73
- RuntimeException translate (AbstractTruffleException e ) {
79
+ static RuntimeException translate (AbstractTruffleException e ) {
74
80
throw e ;
75
81
}
76
82
77
83
@ Specialization
78
- RuntimeException translate (TerminationException e ) {
84
+ static RuntimeException translate (TerminationException e ) {
79
85
throw e ;
80
86
}
81
87
82
88
@ Specialization
83
- RuntimeException translate (ThreadDeath e ) {
89
+ static RuntimeException translate (ThreadDeath e ) {
84
90
throw e ;
85
91
}
86
92
87
93
@ 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 );
90
96
}
91
97
92
98
@ Fallback
93
- RuntimeException translate (Throwable e ) {
99
+ static RuntimeException translate (Node node , Throwable e ) {
94
100
// An internal exception
95
101
CompilerDirectives .transferToInterpreterAndInvalidate ();
96
- logUncaughtJavaException (getContext (), this , e );
102
+ logUncaughtJavaException (getContext (node ), node , e );
97
103
throw ExceptionOperations .rethrow (e );
98
104
}
99
105
@@ -105,50 +111,52 @@ protected boolean needsSpecialTranslation(Throwable e) {
105
111
}
106
112
107
113
@ TruffleBoundary
108
- private RaiseException doTranslateSpecial (Throwable e ) {
114
+ private static RaiseException doTranslateSpecial (Node node , Throwable e ) {
109
115
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 ));
111
117
} 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 ));
114
120
} 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 ));
116
123
} else {
117
- return new RaiseException (getContext (), translateOutOfMemory (getContext (), (OutOfMemoryError ) e ));
124
+ return new RaiseException (getContext (node ),
125
+ translateOutOfMemory (node , getContext (node ), (OutOfMemoryError ) e ));
118
126
}
119
127
}
120
128
121
129
@ TruffleBoundary
122
- private RubyException translateStackOverflow (RubyContext context , StackOverflowError error ) {
130
+ private static RubyException translateStackOverflow (Node node , RubyContext context , StackOverflowError error ) {
123
131
boolean ignore = InitStackOverflowClassesEagerlyNode .ignore (error );
124
132
if (!ignore ) {
125
133
if (context .getOptions ().EXCEPTIONS_WARN_STACKOVERFLOW ) {
126
134
// We cannot afford to initialize the Log class
127
135
System .err .print ("[ruby] WARNING StackOverflowError\n " );
128
136
}
129
137
130
- logJavaException (context , this , error );
138
+ logJavaException (context , node , error );
131
139
}
132
140
133
- return context .getCoreExceptions ().systemStackErrorStackLevelTooDeep (this , error , !ignore );
141
+ return context .getCoreExceptions ().systemStackErrorStackLevelTooDeep (node , error , !ignore );
134
142
}
135
143
136
144
@ TruffleBoundary
137
- private RubyException translateOutOfMemory (RubyContext context , OutOfMemoryError error ) {
145
+ private static RubyException translateOutOfMemory (Node node , RubyContext context , OutOfMemoryError error ) {
138
146
if (context .getOptions ().EXCEPTIONS_WARN_OUT_OF_MEMORY ) {
139
147
// We cannot afford to initialize the Log class
140
148
System .err .print ("[ruby] WARNING OutOfMemoryError\n " );
141
149
}
142
150
143
- logJavaException (context , this , error );
144
- return context .getCoreExceptions ().noMemoryError (this , error );
151
+ logJavaException (context , node , error );
152
+ return context .getCoreExceptions ().noMemoryError (node , error );
145
153
}
146
154
147
155
@ TruffleBoundary
148
- private RubyException translateUnsupportedSpecialization (RubyContext context ,
156
+ private static RubyException translateUnsupportedSpecialization (Node node , RubyContext context ,
149
157
UnsupportedSpecializationException exception ) {
150
158
151
- logJavaException (context , this , exception );
159
+ logJavaException (context , node , exception );
152
160
153
161
final StringBuilder builder = new StringBuilder ();
154
162
builder .append ("TruffleRuby doesn't have a case for the " );
@@ -158,7 +166,7 @@ private RubyException translateUnsupportedSpecialization(RubyContext context,
158
166
builder .append ('\n' );
159
167
BacktraceFormatter .appendJavaStackTrace (exception , builder );
160
168
String message = builder .toString ().strip ();
161
- return context .getCoreExceptions ().typeError (message , this , exception );
169
+ return context .getCoreExceptions ().typeError (message , node , exception );
162
170
}
163
171
164
172
public static StringBuilder argumentsToString (StringBuilder builder , Object [] arguments ) {
0 commit comments