56
56
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .CextUpcallNodeGen ;
57
57
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .DirectUpcallNodeGen ;
58
58
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .GetNativeClassNodeGen ;
59
+ import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .IsPointerNodeGen ;
59
60
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .MaterializeDelegateNodeGen ;
60
61
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ObjectUpcallNodeGen ;
61
62
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ToJavaNodeGen ;
105
106
import com .oracle .graal .python .runtime .exception .PException ;
106
107
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
107
108
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
109
+ import com .oracle .truffle .api .Assumption ;
108
110
import com .oracle .truffle .api .CompilerDirectives ;
109
111
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
110
112
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -377,6 +379,7 @@ public static ToSulongNode create() {
377
379
*/
378
380
public abstract static class AsPythonObjectNode extends CExtBaseNode {
379
381
@ Child private MaterializeDelegateNode materializeNode ;
382
+ @ Child private IsPointerNode isPointerNode ;
380
383
381
384
public abstract Object execute (Object value );
382
385
@@ -385,27 +388,27 @@ boolean doBoolNativeWrapper(BoolNativeWrapper object) {
385
388
return object .getValue ();
386
389
}
387
390
388
- @ Specialization (guards = "!object. isNative()" )
391
+ @ Specialization (guards = "!isNative(object )" )
389
392
byte doByteNativeWrapper (ByteNativeWrapper object ) {
390
393
return object .getValue ();
391
394
}
392
395
393
- @ Specialization (guards = "!object. isNative()" )
396
+ @ Specialization (guards = "!isNative(object )" )
394
397
int doIntNativeWrapper (IntNativeWrapper object ) {
395
398
return object .getValue ();
396
399
}
397
400
398
- @ Specialization (guards = "!object. isNative()" )
401
+ @ Specialization (guards = "!isNative(object )" )
399
402
long doLongNativeWrapper (LongNativeWrapper object ) {
400
403
return object .getValue ();
401
404
}
402
405
403
- @ Specialization (guards = "!object. isNative()" )
406
+ @ Specialization (guards = "!isNative(object )" )
404
407
double doDoubleNativeWrapper (DoubleNativeWrapper object ) {
405
408
return object .getValue ();
406
409
}
407
410
408
- @ Specialization (guards = {"!isBoolNativeWrapper(object)" , "object. isNative()" })
411
+ @ Specialization (guards = {"!isBoolNativeWrapper(object)" , "isNative(object )" })
409
412
Object doPrimitiveNativeWrapper (PrimitiveNativeWrapper object ) {
410
413
return getMaterializeNode ().execute (object );
411
414
}
@@ -467,6 +470,14 @@ Object run(Object obj) {
467
470
throw raise (PythonErrorType .SystemError , "invalid object from native: %s" , obj );
468
471
}
469
472
473
+ protected boolean isNative (PythonNativeWrapper object ) {
474
+ if (isPointerNode == null ) {
475
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
476
+ isPointerNode = insert (IsPointerNode .create ());
477
+ }
478
+ return isPointerNode .execute (object );
479
+ }
480
+
470
481
protected static boolean isPrimitiveNativeWrapper (PythonNativeWrapper object ) {
471
482
return object instanceof PrimitiveNativeWrapper ;
472
483
}
@@ -1456,4 +1467,27 @@ protected ReadArgumentNode[] getArguments() {
1456
1467
throw new IllegalAccessError ();
1457
1468
}
1458
1469
}
1470
+
1471
+ public abstract static class IsPointerNode extends PNodeWithContext {
1472
+
1473
+ public abstract boolean execute (PythonNativeWrapper obj );
1474
+
1475
+ @ Specialization (assumptions = {"singleContextAssumption()" , "nativeObjectsAllManagedAssumption()" })
1476
+ boolean doFalse (@ SuppressWarnings ("unused" ) PythonNativeWrapper obj ) {
1477
+ return false ;
1478
+ }
1479
+
1480
+ @ Specialization
1481
+ boolean doGeneric (PythonNativeWrapper obj ) {
1482
+ return obj .isNative ();
1483
+ }
1484
+
1485
+ protected Assumption nativeObjectsAllManagedAssumption () {
1486
+ return getContext ().getNativeObjectsAllManagedAssumption ();
1487
+ }
1488
+
1489
+ public static IsPointerNode create () {
1490
+ return IsPointerNodeGen .create ();
1491
+ }
1492
+ }
1459
1493
}
0 commit comments