Skip to content

Commit 706427f

Browse files
committed
Move callableStableAssumption to language
1 parent ec8dad4 commit 706427f

File tree

4 files changed

+19
-42
lines changed

4 files changed

+19
-42
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
184184
@CompilationFinal(dimensions = 1) private volatile Object[] engineOptionsStorage;
185185
@CompilationFinal private volatile OptionValues engineOptions;
186186

187+
/**
188+
* A shared assumption that indicates that the delegate of a built-in function that decorates a
189+
* native member method or similar did not change.
190+
*/
191+
@CompilationFinal private Assumption callableStableAssumption;
192+
187193
public static int getNumberOfSpecialSingletons() {
188194
return CONTEXT_INSENSITIVE_SINGLETONS.length;
189195
}
@@ -767,4 +773,12 @@ private RootCallTarget getOrCreateArithmeticCallTarget(Object arithmeticOperator
767773
assert callTarget != null;
768774
return callTarget;
769775
}
776+
777+
public Assumption getCallableStableAssumption() {
778+
if (callableStableAssumption == null) {
779+
CompilerDirectives.transferToInterpreterAndInvalidate();
780+
callableStableAssumption = Truffle.getRuntime().createAssumption("method descriptor delegate stable assumption");
781+
}
782+
return callableStableAssumption;
783+
}
770784
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,10 @@
251251
import com.oracle.graal.python.util.OverflowException;
252252
import com.oracle.graal.python.util.PythonUtils;
253253
import com.oracle.graal.python.util.Supplier;
254-
import com.oracle.truffle.api.Assumption;
255254
import com.oracle.truffle.api.CompilerAsserts;
256255
import com.oracle.truffle.api.CompilerDirectives;
257256
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
258257
import com.oracle.truffle.api.RootCallTarget;
259-
import com.oracle.truffle.api.Truffle;
260258
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
261259
import com.oracle.truffle.api.TruffleLogger;
262260
import com.oracle.truffle.api.dsl.Bind;
@@ -510,8 +508,7 @@ Object doPythonCallable(String name, PythonNativeWrapper callable, PExternalFunc
510508
Object managedCallable = nativeWrapperLibrary.getDelegate(callable);
511509
RootCallTarget wrappedCallTarget = wrapper.getOrCreateCallTarget(lang, name, false);
512510
if (wrappedCallTarget != null) {
513-
Assumption callableStableAssumption = getCallableStableAssumption();
514-
PCell[] closure = ExternalFunctionNodes.createPythonClosure(managedCallable, factory(), callableStableAssumption);
511+
PCell[] closure = ExternalFunctionNodes.createPythonClosure(managedCallable, factory(), lang.getCallableStableAssumption());
515512
return factory().createBuiltinFunction(name, type, 0, closure, wrappedCallTarget);
516513
}
517514
return managedCallable;
@@ -542,8 +539,7 @@ Object doDecoratedManaged(String name, PyCFunctionDecorator callable, PExternalF
542539
Object managedCallable = nativeWrapperLibrary.getDelegate(callable.getNativeFunction());
543540
RootCallTarget wrappedCallTarget = wrapper.getOrCreateCallTarget(lang, name, false);
544541
if (wrappedCallTarget != null) {
545-
Assumption callableStableAssumption = getCallableStableAssumption();
546-
PCell[] closure = ExternalFunctionNodes.createPythonClosure(managedCallable, factory(), callableStableAssumption);
542+
PCell[] closure = ExternalFunctionNodes.createPythonClosure(managedCallable, factory(), lang.getCallableStableAssumption());
547543
return factory().createBuiltinFunction(name, type, 0, closure, wrappedCallTarget);
548544
}
549545

@@ -558,8 +554,7 @@ PBuiltinFunction doNativeCallableWithType(String name, Object callable, PExterna
558554
@Shared("lang") @CachedLanguage PythonLanguage lang,
559555
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
560556
RootCallTarget wrappedCallTarget = wrapper.getOrCreateCallTarget(lang, name, true);
561-
Assumption callableStableAssumption = getCallableStableAssumption();
562-
PCell[] closure = ExternalFunctionNodes.createPythonClosure(callable, factory(), callableStableAssumption);
557+
PCell[] closure = ExternalFunctionNodes.createPythonClosure(callable, factory(), lang.getCallableStableAssumption());
563558
return factory().createBuiltinFunction(name, type, 0, closure, wrappedCallTarget);
564559
}
565560

@@ -574,8 +569,7 @@ PBuiltinFunction doNativeCallableWithoutWrapper(String name, Object callable, Ob
574569
@Shared("lang") @CachedLanguage PythonLanguage lang,
575570
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
576571
RootCallTarget callTarget = PythonUtils.getOrCreateCallTarget(MethDirectRoot.create(lang, name));
577-
Assumption callableStableAssumption = getCallableStableAssumption();
578-
PCell[] closure = ExternalFunctionNodes.createPythonClosure(callable, factory(), callableStableAssumption);
572+
PCell[] closure = ExternalFunctionNodes.createPythonClosure(callable, factory(), lang.getCallableStableAssumption());
579573
return factory().createBuiltinFunction(name, type, 0, closure, callTarget);
580574
}
581575

@@ -585,19 +579,6 @@ PBuiltinFunction doNativeCallableWithoutWrapperAndType(String name, Object calla
585579
return doNativeCallableWithoutWrapper(name, callable, null, wrapper, lang, null);
586580
}
587581

588-
private Assumption getCallableStableAssumption() {
589-
CApiContext cApiContext = getContext().getCApiContext();
590-
if (cApiContext != null) {
591-
return cApiContext.getCallableStableAssumption();
592-
}
593-
return createAssumption();
594-
}
595-
596-
@TruffleBoundary
597-
private static Assumption createAssumption() {
598-
return Truffle.getRuntime().createAssumption();
599-
}
600-
601582
static boolean isNativeWrapper(Object obj) {
602583
return CApiGuards.isNativeWrapper(obj) || isDecoratedManagedFunction(obj);
603584
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
package com.oracle.graal.python.builtins.objects.cext.common;
4242

4343
import com.oracle.graal.python.runtime.PythonContext;
44-
import com.oracle.truffle.api.Assumption;
45-
import com.oracle.truffle.api.CompilerDirectives;
46-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
47-
import com.oracle.truffle.api.Truffle;
4844

4945
public abstract class CExtContext {
5046

@@ -67,12 +63,6 @@ public abstract class CExtContext {
6763
/** A factory for creating context-specific conversion nodes. */
6864
private final ConversionNodeSupplier supplier;
6965

70-
/**
71-
* A shared assumption that indicates that the delegate of a built-in function that decorates a
72-
* native member method or similar did not change.
73-
*/
74-
@CompilationFinal private Assumption callableStableAssumption;
75-
7666
public CExtContext(PythonContext context, Object llvmLibrary, ConversionNodeSupplier supplier) {
7767
this.context = context;
7868
this.llvmLibrary = llvmLibrary;
@@ -115,12 +105,4 @@ public static boolean isMethFastcall(int flags) {
115105
public static boolean isMethFastcallWithKeywords(int flags) {
116106
return (flags & METH_FASTCALL) != 0 && (flags & METH_KEYWORDS) != 0;
117107
}
118-
119-
public Assumption getCallableStableAssumption() {
120-
if (callableStableAssumption == null) {
121-
CompilerDirectives.transferToInterpreterAndInvalidate();
122-
callableStableAssumption = Truffle.getRuntime().createAssumption("method descriptor delegate stable assumption");
123-
}
124-
return callableStableAssumption;
125-
}
126108
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static PBuiltinFunction doIt(GraalHPyContext context, Object methodDef,
447447
// CPy-style methods
448448
// TODO(fa) support static and class methods
449449
PRootNode rootNode = createWrapperRootNode(language, flags, methodName);
450-
PCell[] closure = ExternalFunctionNodes.createPythonClosure(mlMethObj, factory, context.getCallableStableAssumption());
450+
PCell[] closure = ExternalFunctionNodes.createPythonClosure(mlMethObj, factory, language.getCallableStableAssumption());
451451
PBuiltinFunction function = factory.createBuiltinFunction(methodName, null, 0, closure, PythonUtils.getOrCreateCallTarget(rootNode));
452452

453453
// write doc string; we need to directly write to the storage otherwise it is disallowed

0 commit comments

Comments
 (0)