57
57
import com .oracle .truffle .api .library .ExportMessage ;
58
58
import com .oracle .truffle .api .nodes .ExplodeLoop ;
59
59
import com .oracle .truffle .api .nodes .Node ;
60
- import com .oracle .truffle .api .profiles .BranchProfile ;
60
+ import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
61
61
import com .oracle .truffle .api .utilities .TriState ;
62
62
import com .oracle .truffle .espresso .EspressoLanguage ;
63
63
import com .oracle .truffle .espresso .classfile .ConstantPool ;
81
81
import com .oracle .truffle .espresso .meta .Meta ;
82
82
import com .oracle .truffle .espresso .meta .MetaUtil ;
83
83
import com .oracle .truffle .espresso .meta .ModifiersProvider ;
84
- import com .oracle .truffle .espresso .nodes .interop .InvokeEspressoNode ;
85
- import com .oracle .truffle .espresso .nodes .interop .InvokeEspressoNodeGen ;
86
84
import com .oracle .truffle .espresso .nodes .interop .LookupDeclaredMethod ;
87
85
import com .oracle .truffle .espresso .nodes .interop .LookupDeclaredMethodNodeGen ;
88
86
import com .oracle .truffle .espresso .nodes .interop .LookupFieldNode ;
89
87
import com .oracle .truffle .espresso .nodes .interop .LookupFieldNodeGen ;
90
- import com .oracle .truffle .espresso .nodes .interop .OverLoadedMethodSelectorNode ;
91
- import com .oracle .truffle .espresso .nodes .interop .OverLoadedMethodSelectorNodeGen ;
92
88
import com .oracle .truffle .espresso .nodes .interop .ToEspressoNode ;
93
89
import com .oracle .truffle .espresso .nodes .interop .ToEspressoNodeFactory ;
94
90
import com .oracle .truffle .espresso .nodes .interop .ToPrimitive ;
102
98
import com .oracle .truffle .espresso .runtime .MethodHandleIntrinsics ;
103
99
import com .oracle .truffle .espresso .runtime .dispatch .staticobject .BaseInterop ;
104
100
import com .oracle .truffle .espresso .runtime .dispatch .staticobject .EspressoInterop ;
101
+ import com .oracle .truffle .espresso .runtime .dispatch .staticobject .InteropLookupAndInvoke ;
102
+ import com .oracle .truffle .espresso .runtime .dispatch .staticobject .InteropLookupAndInvokeFactory ;
105
103
import com .oracle .truffle .espresso .runtime .staticobject .StaticObject ;
106
104
import com .oracle .truffle .espresso .substitutions .JavaType ;
107
105
import com .oracle .truffle .espresso .vm .InterpreterToVM ;
@@ -179,15 +177,18 @@ abstract static class ReadMember {
179
177
@ Specialization (guards = "language.isShared()" )
180
178
static Object doShared (Klass receiver , String member ,
181
179
@ CachedLibrary ("receiver" ) InteropLibrary lib ,
180
+ @ Bind ("$node" ) Node node ,
181
+ @ Cached @ Shared InlinedBranchProfile error ,
182
182
@ Bind ("getLang(lib)" ) @ SuppressWarnings ("unused" ) EspressoLanguage language ) throws UnknownIdentifierException {
183
- return readMember (receiver , member , LookupFieldNodeGen .getUncached (), LookupDeclaredMethodNodeGen .getUncached (), BranchProfile . getUncached () , lib , language );
183
+ return readMember (receiver , member , LookupFieldNodeGen .getUncached (), LookupDeclaredMethodNodeGen .getUncached (), node , error , lib , language );
184
184
}
185
185
186
186
@ Specialization
187
187
static Object readMember (Klass receiver , String member ,
188
188
@ Shared ("lookupField" ) @ Cached LookupFieldNode lookupFieldNode ,
189
189
@ Shared ("lookupMethod" ) @ Cached LookupDeclaredMethod lookupMethod ,
190
- @ Shared ("error" ) @ Cached BranchProfile error ,
190
+ @ Bind ("$node" ) Node node ,
191
+ @ Cached @ Shared InlinedBranchProfile error ,
191
192
@ CachedLibrary ("receiver" ) InteropLibrary lib ,
192
193
@ Bind ("getLang(lib)" ) @ SuppressWarnings ("unused" ) EspressoLanguage language ) throws UnknownIdentifierException {
193
194
EspressoContext ctx = EspressoContext .get (lib );
@@ -229,7 +230,7 @@ static Object readMember(Klass receiver, String member,
229
230
return receiver .getSuperKlass ();
230
231
}
231
232
232
- error .enter ();
233
+ error .enter (node );
233
234
throw UnknownIdentifierException .create (member );
234
235
}
235
236
}
@@ -263,24 +264,26 @@ abstract static class WriteMember {
263
264
// Specialization prevents caching a node that would leak the context
264
265
@ Specialization (guards = "language.isShared()" )
265
266
static void doShared (Klass receiver , String member , Object value ,
266
- @ Shared ("error" ) @ Cached BranchProfile error ,
267
+ @ Bind ("$node" ) Node node ,
268
+ @ Cached @ Shared InlinedBranchProfile error ,
267
269
@ CachedLibrary ("receiver" ) @ SuppressWarnings ("unused" ) InteropLibrary lib ,
268
270
@ Bind ("getLang(lib)" ) @ SuppressWarnings ("unused" ) EspressoLanguage language ) throws UnknownIdentifierException , UnsupportedTypeException {
269
- writeMember (receiver , member , value , LookupFieldNodeGen .getUncached (), ToEspressoNodeFactory .DynamicToEspressoNodeGen .getUncached (), error );
271
+ writeMember (receiver , member , value , LookupFieldNodeGen .getUncached (), ToEspressoNodeFactory .DynamicToEspressoNodeGen .getUncached (), node , error );
270
272
}
271
273
272
274
@ Specialization
273
275
static void writeMember (Klass receiver , String member , Object value ,
274
276
@ Shared ("lookupField" ) @ Cached LookupFieldNode lookupFieldNode ,
275
277
@ Exclusive @ Cached ToEspressoNode .DynamicToEspresso toEspressoNode ,
276
- @ Shared ("error" ) @ Cached BranchProfile error ) throws UnknownIdentifierException , UnsupportedTypeException {
278
+ @ Bind ("$node" ) Node node ,
279
+ @ Cached @ Shared InlinedBranchProfile error ) throws UnknownIdentifierException , UnsupportedTypeException {
277
280
Field field = lookupFieldNode .execute (receiver , member , true );
278
281
// Can only write to non-final fields.
279
282
if (field != null && !field .isFinalFlagSet ()) {
280
283
Object espressoValue = toEspressoNode .execute (value , field .resolveTypeKlass ());
281
284
field .set (receiver .tryInitializeAndGetStatics (), espressoValue );
282
285
} else {
283
- error .enter ();
286
+ error .enter (node );
284
287
throw UnknownIdentifierException .create (member );
285
288
}
286
289
}
@@ -308,35 +311,27 @@ abstract static class InvokeMember {
308
311
// Specialization prevents caching a node that would leak the context
309
312
@ Specialization (guards = "language.isShared()" )
310
313
static Object doShared (Klass receiver , String member , Object [] arguments ,
314
+ @ Bind ("$node" ) Node node ,
315
+ @ Cached @ Shared InlinedBranchProfile error ,
311
316
@ CachedLibrary ("receiver" ) @ SuppressWarnings ("unused" ) InteropLibrary receiverInterop ,
312
317
@ Bind ("getLang(receiverInterop)" ) @ SuppressWarnings ("unused" ) EspressoLanguage language ) throws ArityException , UnknownIdentifierException , UnsupportedTypeException {
313
- return invokeMember (receiver , member , arguments , receiverInterop , LookupDeclaredMethodNodeGen .getUncached (), OverLoadedMethodSelectorNodeGen .getUncached (),
314
- InvokeEspressoNodeGen .getUncached (),
315
- ToEspressoNodeFactory .DynamicToEspressoNodeGen .getUncached ());
318
+ return invokeMember (receiver , member , arguments , node , receiverInterop , error , InteropLookupAndInvokeFactory .NonVirtualNodeGen .getUncached ());
316
319
}
317
320
318
321
@ Specialization
319
322
static Object invokeMember (Klass receiver , String member ,
320
323
Object [] arguments ,
324
+ @ Bind ("$node" ) Node node ,
321
325
@ CachedLibrary ("receiver" ) InteropLibrary receiverInterop ,
322
- @ Cached LookupDeclaredMethod lookupMethod ,
323
- @ Cached OverLoadedMethodSelectorNode overloadSelector ,
324
- @ Exclusive @ Cached InvokeEspressoNode invoke ,
325
- @ Cached ToEspressoNode .DynamicToEspresso toEspressoNode )
326
+ @ Cached InlinedBranchProfile error ,
327
+ @ Cached InteropLookupAndInvoke .NonVirtual lookupAndInvoke )
326
328
throws ArityException , UnknownIdentifierException , UnsupportedTypeException {
327
329
if (!receiverInterop .isMemberInvocable (receiver , member )) {
328
330
// Not invocable, no matter the arity or argument types.
331
+ error .enter (node );
329
332
throw UnknownIdentifierException .create (member );
330
333
}
331
- // The member (static method) may be invocable only for a certain arity and argument
332
- // types.
333
- Method [] candidates = lookupMethod .execute (receiver , member , true , true , arguments .length );
334
- if (candidates != null ) {
335
- return EspressoInterop .invokeEspressoMethodHelper (null , member , arguments , overloadSelector , invoke , toEspressoNode , candidates );
336
- }
337
- // TODO(peterssen): The expected arity is not known, only that the given one is not
338
- // correct.
339
- throw ArityException .create (arguments .length + 1 , -1 , arguments .length );
334
+ return lookupAndInvoke .execute (null , receiver , arguments , member );
340
335
}
341
336
}
342
337
@@ -415,6 +410,7 @@ abstract static class Instantiate {
415
410
@ Specialization (guards = "language.isShared()" )
416
411
static Object doShared (Klass receiver , Object [] args ,
417
412
@ CachedLibrary ("receiver" ) @ SuppressWarnings ("unused" ) InteropLibrary receiverInterop ,
413
+ @ Bind ("$node" ) Node node ,
418
414
@ Bind ("getLang(receiverInterop)" ) @ SuppressWarnings ("unused" ) EspressoLanguage language ) throws UnsupportedMessageException , UnsupportedTypeException , ArityException {
419
415
if (receiver .isPrimitive ()) {
420
416
return doPrimitive (receiver , args );
@@ -426,11 +422,10 @@ static Object doShared(Klass receiver, Object[] args,
426
422
return doReferenceArray (receiver , args , ToPrimitiveFactory .ToIntNodeGen .getUncached ());
427
423
}
428
424
if (isMultidimensionalArray (receiver )) {
429
- return doMultidimensionalArray (receiver , args , ToPrimitiveFactory .ToIntNodeGen .getUncached ());
425
+ return doMultidimensionalArray (receiver , args , node , InlinedBranchProfile . getUncached (), ToPrimitiveFactory .ToIntNodeGen .getUncached ());
430
426
}
431
427
if (isObjectKlass (receiver )) {
432
- return doObject (receiver , args , receiverInterop , LookupDeclaredMethodNodeGen .getUncached (), OverLoadedMethodSelectorNodeGen .getUncached (), InvokeEspressoNodeGen .getUncached (),
433
- ToEspressoNodeFactory .DynamicToEspressoNodeGen .getUncached ());
428
+ return doObject (receiver , args , node , InlinedBranchProfile .getUncached (), receiverInterop , InteropLookupAndInvokeFactory .NonVirtualNodeGen .getUncached ());
434
429
}
435
430
CompilerDirectives .transferToInterpreterAndInvalidate ();
436
431
throw EspressoError .shouldNotReachHere ();
@@ -498,10 +493,13 @@ static StaticObject doReferenceArray(Klass receiver, Object[] arguments,
498
493
499
494
@ Specialization (guards = "isMultidimensionalArray(receiver)" )
500
495
static StaticObject doMultidimensionalArray (Klass receiver , Object [] arguments ,
496
+ @ Bind ("$node" ) Node node ,
497
+ @ Cached InlinedBranchProfile error ,
501
498
@ Cached ToPrimitive .ToInt toInt ) throws ArityException , UnsupportedTypeException {
502
499
ArrayKlass arrayKlass = (ArrayKlass ) receiver ;
503
500
assert arrayKlass .getElementalType ().getJavaKind () != JavaKind .Void ;
504
501
if (arrayKlass .getDimension () != arguments .length ) {
502
+ error .enter (node );
505
503
throw ArityException .create (arrayKlass .getDimension (), arrayKlass .getDimension (), arguments .length );
506
504
}
507
505
EspressoContext context = EspressoContext .get (toInt );
@@ -517,24 +515,18 @@ static StaticObject doMultidimensionalArray(Klass receiver, Object[] arguments,
517
515
518
516
@ Specialization (guards = "isObjectKlass(receiver)" )
519
517
static Object doObject (Klass receiver , Object [] arguments ,
518
+ @ Bind ("$node" ) Node node ,
519
+ @ Cached InlinedBranchProfile error ,
520
520
@ CachedLibrary ("receiver" ) InteropLibrary receiverInterop ,
521
- @ Shared ("lookupMethod" ) @ Cached LookupDeclaredMethod lookupMethod ,
522
- @ Cached OverLoadedMethodSelectorNode overloadSelector ,
523
- @ Exclusive @ Cached InvokeEspressoNode invoke ,
524
- @ Cached ToEspressoNode .DynamicToEspresso toEspressoNode ) throws UnsupportedTypeException , ArityException , UnsupportedMessageException {
521
+ @ Cached InteropLookupAndInvoke .NonVirtual lookupAndInvoke ) throws UnsupportedTypeException , ArityException , UnsupportedMessageException {
525
522
if (!receiverInterop .isInstantiable (receiver )) {
523
+ error .enter (node );
526
524
throw UnsupportedMessageException .create ();
527
525
}
528
526
ObjectKlass objectKlass = (ObjectKlass ) receiver ;
529
- Method [] initCandidates = lookupMethod .execute (receiver , INIT_NAME , true , false , arguments .length );
530
- if (initCandidates != null ) {
531
- StaticObject instance = allocateNewInstance (EspressoContext .get (invoke ), objectKlass );
532
- EspressoInterop .invokeEspressoMethodHelper (instance , INIT_NAME , arguments , overloadSelector , invoke , toEspressoNode , initCandidates );
533
- return instance ;
534
- }
535
- // TODO(peterssen): We don't know the expected arity of this method, only that the given
536
- // arity is incorrect.
537
- throw ArityException .create (arguments .length + 1 , -1 , arguments .length );
527
+ StaticObject instance = allocateNewInstance (EspressoContext .get (lookupAndInvoke ), objectKlass );
528
+ lookupAndInvoke .execute (instance , objectKlass , arguments , INIT_NAME );
529
+ return instance ;
538
530
}
539
531
540
532
private static StaticObject allocateNewInstance (EspressoContext context , ObjectKlass objectKlass ) {
0 commit comments