@@ -446,28 +446,32 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
446
446
return PythonClassNativeWrapper .wrap (object , getNameNode .execute (object ));
447
447
}
448
448
449
- @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
449
+ @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
450
450
static Object runAbstractObjectCached (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
451
451
@ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
452
- @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ) {
452
+ @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ,
453
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
453
454
assert object != PNone .NO_VALUE ;
454
455
return PythonObjectNativeWrapper .wrap (CompilerDirectives .castExact (object , cachedClass ), noWrapperProfile );
455
456
}
456
457
457
- @ Specialization (guards = {"!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" )
458
+ @ Specialization (guards = {"!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" , limit = "3 " )
458
459
static Object runAbstractObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
459
- @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ) {
460
+ @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
461
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
460
462
assert object != PNone .NO_VALUE ;
461
463
return PythonObjectNativeWrapper .wrap (object , noWrapperProfile );
462
464
}
463
465
464
- @ Specialization (guards = {"isForeignObject(object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
465
- static Object doForeignObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ) {
466
+ @ Specialization (guards = {"isForeignObject(object, lib)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "3" )
467
+ static Object doForeignObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , TruffleObject object ,
468
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
466
469
return TruffleObjectNativeWrapper .wrap (object );
467
470
}
468
471
469
- @ Specialization (guards = "isFallback(object)" )
470
- static Object run (@ SuppressWarnings ("unused" ) CExtContext cextContext , Object object ) {
472
+ @ Specialization (guards = "isFallback(object, lib)" , limit = "1" )
473
+ static Object run (@ SuppressWarnings ("unused" ) CExtContext cextContext , Object object ,
474
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
471
475
assert object != null : "Java 'null' cannot be a Sulong value" ;
472
476
assert CApiGuards .isNativeWrapper (object ) : "unknown object cannot be a Sulong value" ;
473
477
return object ;
@@ -477,9 +481,10 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonManagedClass obj
477
481
return PythonClassNativeWrapper .wrap (object , GetNameNode .doSlowPath (object ));
478
482
}
479
483
480
- static boolean isFallback (Object object ) {
484
+ static boolean isFallback (Object object , InteropLibrary lib ) {
481
485
return !(object instanceof String || object instanceof Boolean || object instanceof Integer || object instanceof Long || object instanceof Double ||
482
- object instanceof PythonNativeNull || object instanceof PythonAbstractObject || (PGuards .isForeignObject (object ) && !CApiGuards .isNativeWrapper (object )));
486
+ object instanceof PythonNativeNull || object instanceof PythonAbstractObject ) &&
487
+ !(PGuards .isForeignObject (object , lib ) && !CApiGuards .isNativeWrapper (object ));
483
488
}
484
489
485
490
protected static boolean isNaN (double d ) {
@@ -679,38 +684,42 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
679
684
return PythonClassNativeWrapper .wrapNewRef (object , getNameNode .execute (object ));
680
685
}
681
686
682
- @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
687
+ @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
683
688
static Object runAbstractObjectCached (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
684
689
@ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
685
- @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ) {
690
+ @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ,
691
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
686
692
assert object != PNone .NO_VALUE ;
687
693
return PythonObjectNativeWrapper .wrapNewRef (CompilerDirectives .castExact (object , cachedClass ), noWrapperProfile );
688
694
}
689
695
690
- @ Specialization (guards = {"!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" )
696
+ @ Specialization (guards = {"!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" , limit = "3 " )
691
697
static Object runAbstractObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
692
- @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ) {
698
+ @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
699
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
693
700
assert object != PNone .NO_VALUE ;
694
701
return PythonObjectNativeWrapper .wrapNewRef (object , noWrapperProfile );
695
702
}
696
703
697
- @ Specialization (guards = {"isForeignObject(object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
698
- static Object doForeignObject (CExtContext cextContext , TruffleObject object ) {
704
+ @ Specialization (guards = {"isForeignObject(object, lib)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "3" )
705
+ static Object doForeignObject (CExtContext cextContext , TruffleObject object ,
706
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
699
707
// this will always be a new wrapper; it's implicitly always a new reference in any case
700
- return ToSulongNode .doForeignObject (cextContext , object );
708
+ return ToSulongNode .doForeignObject (cextContext , object , lib );
701
709
}
702
710
703
- @ Specialization (guards = "isFallback(object)" )
704
- static Object run (CExtContext cextContext , Object object ) {
705
- return ToSulongNode .run (cextContext , object );
711
+ @ Specialization (guards = "isFallback(object, lib)" , limit = "1" )
712
+ static Object run (CExtContext cextContext , Object object ,
713
+ @ CachedLibrary ("object" ) InteropLibrary lib ) {
714
+ return ToSulongNode .run (cextContext , object , lib );
706
715
}
707
716
708
717
protected static PythonClassNativeWrapper wrapNativeClass (PythonManagedClass object ) {
709
718
return PythonClassNativeWrapper .wrap (object , GetNameNode .doSlowPath (object ));
710
719
}
711
720
712
- static boolean isFallback (Object object ) {
713
- return ToSulongNode .isFallback (object );
721
+ static boolean isFallback (Object object , InteropLibrary lib ) {
722
+ return ToSulongNode .isFallback (object , lib );
714
723
}
715
724
716
725
protected static boolean isNaN (double d ) {
@@ -725,7 +734,7 @@ protected static boolean isNaN(double d) {
725
734
* ref count of all {@link PythonNativeWrapper} (and subclasses) (but not if they are newly
726
735
* created since the ref count is already one in this case). But it does not increase the ref
727
736
* count on {@link PythonAbstractNativeObject}.
728
- *
737
+ *
729
738
* The reason for this behavior is that after the native function returns, one can decrease the
730
739
* ref count by one and therefore release any allocated handles that would cause a memory leak.
731
740
* This is not necessary for {@link PythonAbstractNativeObject} since they are managed by a weak
@@ -834,38 +843,42 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
834
843
return PythonClassNativeWrapper .wrapNewRef (object , getNameNode .execute (object ));
835
844
}
836
845
837
- @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
846
+ @ Specialization (guards = {"cachedClass == object.getClass()" , "!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, limit = "3" )
838
847
static Object runAbstractObjectCached (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
839
848
@ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
840
- @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ) {
849
+ @ Cached ("object.getClass()" ) Class <? extends PythonAbstractObject > cachedClass ,
850
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
841
851
assert object != PNone .NO_VALUE ;
842
852
return PythonObjectNativeWrapper .wrapNewRef (CompilerDirectives .castExact (object , cachedClass ), noWrapperProfile );
843
853
}
844
854
845
- @ Specialization (guards = {"!isClass(object)" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" )
855
+ @ Specialization (guards = {"!isClass(object, lib )" , "!isNativeObject(object)" , "!isSpecialSingleton(object)" }, replaces = "runAbstractObjectCached" , limit = "3 " )
846
856
static Object runAbstractObject (@ SuppressWarnings ("unused" ) CExtContext cextContext , PythonAbstractObject object ,
847
- @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ) {
857
+ @ Cached ("createBinaryProfile()" ) ConditionProfile noWrapperProfile ,
858
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
848
859
assert object != PNone .NO_VALUE ;
849
860
return PythonObjectNativeWrapper .wrapNewRef (object , noWrapperProfile );
850
861
}
851
862
852
- @ Specialization (guards = {"isForeignObject(object)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" })
853
- static Object doForeignObject (CExtContext cextContext , TruffleObject object ) {
863
+ @ Specialization (guards = {"isForeignObject(object, lib)" , "!isNativeWrapper(object)" , "!isNativeNull(object)" }, limit = "3" )
864
+ static Object doForeignObject (CExtContext cextContext , TruffleObject object ,
865
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("object" ) InteropLibrary lib ) {
854
866
// this will always be a new wrapper; it's implicitly always a new reference in any case
855
- return ToSulongNode .doForeignObject (cextContext , object );
867
+ return ToSulongNode .doForeignObject (cextContext , object , lib );
856
868
}
857
869
858
- @ Specialization (guards = "isFallback(object)" )
859
- static Object run (CExtContext cextContext , Object object ) {
860
- return ToSulongNode .run (cextContext , object );
870
+ @ Specialization (guards = "isFallback(object, lib)" , limit = "1" )
871
+ static Object run (CExtContext cextContext , Object object ,
872
+ @ CachedLibrary ("object" ) InteropLibrary lib ) {
873
+ return ToSulongNode .run (cextContext , object , lib );
861
874
}
862
875
863
876
protected static PythonClassNativeWrapper wrapNativeClass (PythonManagedClass object ) {
864
877
return PythonClassNativeWrapper .wrap (object , GetNameNode .doSlowPath (object ));
865
878
}
866
879
867
- static boolean isFallback (Object object ) {
868
- return ToSulongNode .isFallback (object );
880
+ static boolean isFallback (Object object , InteropLibrary lib ) {
881
+ return ToSulongNode .isFallback (object , lib );
869
882
}
870
883
871
884
protected static boolean isNaN (double d ) {
0 commit comments