16
16
import com .oracle .truffle .api .CompilerDirectives ;
17
17
import com .oracle .truffle .api .TruffleSafepoint ;
18
18
import com .oracle .truffle .api .dsl .Bind ;
19
+ import com .oracle .truffle .api .dsl .GenerateCached ;
20
+ import com .oracle .truffle .api .dsl .GenerateInline ;
19
21
import com .oracle .truffle .api .interop .InvalidArrayIndexException ;
20
22
import com .oracle .truffle .api .nodes .ExplodeLoop ;
23
+ import com .oracle .truffle .api .nodes .Node ;
21
24
import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
22
25
import com .oracle .truffle .api .profiles .LoopConditionProfile ;
23
26
import org .truffleruby .language .NotProvided ;
36
39
import com .oracle .truffle .api .library .CachedLibrary ;
37
40
38
41
@ GenerateUncached
42
+ @ GenerateInline
43
+ @ GenerateCached (false )
39
44
@ ImportStatic (ValueWrapperManager .class )
40
45
public abstract class UnwrapNode extends RubyBaseNode {
41
46
42
47
@ GenerateUncached
48
+ @ GenerateInline
49
+ @ GenerateCached (false )
43
50
@ ImportStatic (ValueWrapperManager .class )
44
51
public abstract static class UnwrapNativeNode extends RubyBaseNode {
45
52
46
- public abstract Object execute (long handle );
53
+ public static Object executeUncached (long handle ) {
54
+ return UnwrapNodeGen .UnwrapNativeNodeGen .getUncached ().execute (null , handle );
55
+ }
56
+
57
+ public abstract Object execute (Node node , long handle );
47
58
48
59
@ Specialization (guards = "handle == FALSE_HANDLE" )
49
- protected boolean unwrapFalse (long handle ) {
60
+ protected static boolean unwrapFalse (long handle ) {
50
61
return false ;
51
62
}
52
63
53
64
@ Specialization (guards = "handle == TRUE_HANDLE" )
54
- protected boolean unwrapTrue (long handle ) {
65
+ protected static boolean unwrapTrue (long handle ) {
55
66
return true ;
56
67
}
57
68
58
69
@ Specialization (guards = "handle == UNDEF_HANDLE" )
59
- protected NotProvided unwrapUndef (long handle ) {
70
+ protected static NotProvided unwrapUndef (long handle ) {
60
71
return NotProvided .INSTANCE ;
61
72
}
62
73
63
74
@ Specialization (guards = "handle == NIL_HANDLE" )
64
- protected Object unwrapNil (long handle ) {
75
+ protected static Object unwrapNil (long handle ) {
65
76
return nil ;
66
77
}
67
78
68
79
@ Specialization (guards = "isTaggedLong(handle)" )
69
- protected long unwrapTaggedLong (long handle ) {
80
+ protected static long unwrapTaggedLong (long handle ) {
70
81
return ValueWrapperManager .untagTaggedLong (handle );
71
82
}
72
83
73
84
@ Specialization (guards = "isTaggedObject(handle)" )
74
- protected Object unwrapTaggedObject (long handle ,
85
+ protected static Object unwrapTaggedObject (Node node , long handle ,
75
86
@ Cached InlinedBranchProfile noHandleProfile ) {
76
- final ValueWrapper wrapper = getContext ()
87
+ final ValueWrapper wrapper = getContext (node )
77
88
.getValueWrapperManager ()
78
- .getWrapperFromHandleMap (handle , getLanguage ());
89
+ .getWrapperFromHandleMap (handle , getLanguage (node ));
79
90
if (wrapper == null ) {
80
- noHandleProfile .enter (this );
91
+ noHandleProfile .enter (node );
81
92
raiseError (handle );
82
93
}
83
94
return wrapper .getObject ();
84
95
}
85
96
86
97
@ Fallback
87
- protected ValueWrapper unWrapUnexpectedHandle (long handle ) {
98
+ protected static ValueWrapper unWrapUnexpectedHandle (long handle ) {
88
99
// Avoid throwing a specialization exception when given an uninitialized or corrupt
89
100
// handle.
90
101
CompilerDirectives .transferToInterpreterAndInvalidate ();
91
102
throw CompilerDirectives .shouldNotReachHere ("corrupt handle 0x" + Long .toHexString (handle ));
92
103
}
93
104
94
105
@ TruffleBoundary
95
- private void raiseError (long handle ) {
106
+ private static void raiseError (long handle ) {
96
107
throw CompilerDirectives .shouldNotReachHere ("dead handle 0x" + Long .toHexString (handle ));
97
108
}
98
109
}
99
110
100
111
@ GenerateUncached
112
+ @ GenerateInline
113
+ @ GenerateCached (false )
101
114
@ ImportStatic (ValueWrapperManager .class )
102
115
public abstract static class NativeToWrapperNode extends RubyBaseNode {
103
116
104
- public abstract ValueWrapper execute (long handle );
117
+ public abstract ValueWrapper execute (Node node , long handle );
105
118
106
119
@ Specialization (guards = "handle == FALSE_HANDLE" )
107
- protected ValueWrapper unwrapFalse (long handle ) {
120
+ protected static ValueWrapper unwrapFalse (long handle ) {
108
121
return new ValueWrapper (false , FALSE_HANDLE , null );
109
122
}
110
123
111
124
@ Specialization (guards = "handle == TRUE_HANDLE" )
112
- protected ValueWrapper unwrapTrue (long handle ) {
125
+ protected static ValueWrapper unwrapTrue (long handle ) {
113
126
return new ValueWrapper (true , TRUE_HANDLE , null );
114
127
}
115
128
116
129
@ Specialization (guards = "handle == UNDEF_HANDLE" )
117
- protected ValueWrapper unwrapUndef (long handle ) {
130
+ protected static ValueWrapper unwrapUndef (long handle ) {
118
131
return new ValueWrapper (NotProvided .INSTANCE , UNDEF_HANDLE , null );
119
132
}
120
133
121
134
@ Specialization (guards = "handle == NIL_HANDLE" )
122
- protected ValueWrapper unwrapNil (long handle ) {
135
+ protected static ValueWrapper unwrapNil (long handle ) {
123
136
return nil .getValueWrapper ();
124
137
}
125
138
126
139
@ Specialization (guards = "isTaggedLong(handle)" )
127
- protected ValueWrapper unwrapTaggedLong (long handle ) {
140
+ protected static ValueWrapper unwrapTaggedLong (long handle ) {
128
141
return new ValueWrapper (null , handle , null );
129
142
}
130
143
131
144
@ Specialization (guards = "isTaggedObject(handle)" )
132
- protected ValueWrapper unwrapTaggedObject (long handle ) {
133
- return getContext ().getValueWrapperManager ().getWrapperFromHandleMap (handle , getLanguage ());
145
+ protected static ValueWrapper unwrapTaggedObject (Node node , long handle ) {
146
+ return getContext (node ).getValueWrapperManager ().getWrapperFromHandleMap (handle , getLanguage (node ));
134
147
}
135
148
136
149
@ Fallback
137
- protected ValueWrapper unWrapUnexpectedHandle (long handle ) {
150
+ protected static ValueWrapper unWrapUnexpectedHandle (long handle ) {
138
151
// Avoid throwing a specialization exception when given an uninitialized or corrupt
139
152
// handle.
140
153
return null ;
141
154
}
142
155
}
143
156
157
+ @ GenerateInline
158
+ @ GenerateCached (false )
144
159
@ ImportStatic (ValueWrapperManager .class )
145
160
public abstract static class ToWrapperNode extends RubyBaseNode {
146
161
147
- public abstract ValueWrapper execute (Object value );
162
+ public abstract ValueWrapper execute (Node node , Object value );
148
163
149
164
@ Specialization
150
- protected ValueWrapper wrappedValueWrapper (ValueWrapper value ) {
165
+ protected static ValueWrapper wrappedValueWrapper (ValueWrapper value ) {
151
166
return value ;
152
167
}
153
168
154
169
@ Specialization
155
- protected ValueWrapper longToWrapper (long value ,
170
+ protected static ValueWrapper longToWrapper (Node node , long value ,
156
171
@ Cached @ Shared NativeToWrapperNode nativeToWrapperNode ) {
157
- return nativeToWrapperNode .execute (value );
172
+ return nativeToWrapperNode .execute (node , value );
158
173
}
159
174
160
175
@ Fallback
161
- protected ValueWrapper genericToWrapper (Object value ,
176
+ protected static ValueWrapper genericToWrapper (Node node , Object value ,
162
177
@ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary values ,
163
178
@ Cached @ Shared NativeToWrapperNode nativeToWrapperNode ,
164
179
@ Cached InlinedBranchProfile unsupportedProfile ) {
165
180
long handle ;
166
181
try {
167
182
handle = values .asPointer (value );
168
183
} catch (UnsupportedMessageException e ) {
169
- unsupportedProfile .enter (this );
170
- throw new RaiseException (getContext (), coreExceptions ().argumentError (e .getMessage (), this , e ));
184
+ unsupportedProfile .enter (node );
185
+ throw new RaiseException (getContext (node ),
186
+ coreExceptions (node ).argumentError (e .getMessage (), getNode (node ), e ));
171
187
}
172
- return nativeToWrapperNode .execute (handle );
188
+ return nativeToWrapperNode .execute (node , handle );
173
189
}
174
190
175
191
protected int getCacheLimit () {
@@ -194,7 +210,7 @@ protected Object[] unwrapCArrayExplode(Object cArray,
194
210
final Object [] store = new Object [cachedSize ];
195
211
for (int i = 0 ; i < cachedSize ; i ++) {
196
212
final Object cValue = readArrayElement (cArray , interop , i );
197
- store [i ] = unwrapNode .execute (cValue );
213
+ store [i ] = unwrapNode .execute (this , cValue );
198
214
}
199
215
return store ;
200
216
}
@@ -210,7 +226,7 @@ protected Object[] unwrapCArray(Object cArray,
210
226
try {
211
227
for (; loopProfile .inject (i < size ); i ++) {
212
228
final Object cValue = readArrayElement (cArray , interop , i );
213
- store [i ] = unwrapNode .execute (cValue );
229
+ store [i ] = unwrapNode .execute (this , cValue );
214
230
TruffleSafepoint .poll (this );
215
231
}
216
232
} finally {
@@ -236,37 +252,38 @@ private static Object readArrayElement(Object cArray, InteropLibrary interop, in
236
252
}
237
253
}
238
254
239
- public abstract Object execute (Object value );
255
+ public abstract Object execute (Node node , Object value );
240
256
241
257
@ Specialization (guards = "!isTaggedLong(value.getHandle())" )
242
- protected Object unwrapValueObject (ValueWrapper value ) {
258
+ protected static Object unwrapValueObject (ValueWrapper value ) {
243
259
return value .getObject ();
244
260
}
245
261
246
262
@ Specialization (guards = "isTaggedLong(value.getHandle())" )
247
- protected long unwrapValueTaggedLong (ValueWrapper value ) {
263
+ protected static long unwrapValueTaggedLong (ValueWrapper value ) {
248
264
return ValueWrapperManager .untagTaggedLong (value .getHandle ());
249
265
}
250
266
251
267
@ Specialization
252
- protected Object longToWrapper (long value ,
268
+ protected static Object longToWrapper (Node node , long value ,
253
269
@ Cached @ Shared UnwrapNativeNode unwrapNativeNode ) {
254
- return unwrapNativeNode .execute (value );
270
+ return unwrapNativeNode .execute (node , value );
255
271
}
256
272
257
273
@ Specialization (guards = { "!isWrapper(value)" , "!isImplicitLong(value)" })
258
- protected Object unwrapGeneric (Object value ,
274
+ protected static Object unwrapGeneric (Node node , Object value ,
259
275
@ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary values ,
260
276
@ Cached @ Shared UnwrapNativeNode unwrapNativeNode ,
261
277
@ Cached InlinedBranchProfile unsupportedProfile ) {
262
278
long handle ;
263
279
try {
264
280
handle = values .asPointer (value );
265
281
} catch (UnsupportedMessageException e ) {
266
- unsupportedProfile .enter (this );
267
- throw new RaiseException (getContext (), coreExceptions ().argumentError (e .getMessage (), this , e ));
282
+ unsupportedProfile .enter (node );
283
+ throw new RaiseException (getContext (node ),
284
+ coreExceptions (node ).argumentError (e .getMessage (), getNode (node ), e ));
268
285
}
269
- return unwrapNativeNode .execute (handle );
286
+ return unwrapNativeNode .execute (node , handle );
270
287
}
271
288
272
289
protected int getCacheLimit () {
0 commit comments