Skip to content

Commit cc6b74f

Browse files
committed
Make call targets for builtin methods always lazy, without option
1 parent 54998fe commit cc6b74f

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/CachedLazyCalltargetSupplier.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class CachedLazyCalltargetSupplier {
4949
private volatile RootCallTarget callTarget = null;
5050
private Supplier<RootCallTarget> supplier;
5151

52-
5352
public CachedLazyCalltargetSupplier(Supplier<RootCallTarget> supplier) {
5453
this.supplier = supplier;
5554
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@
4747
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
4848
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
4949
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
50-
import com.oracle.graal.python.runtime.PythonOptions;
5150
import com.oracle.graal.python.runtime.object.PFactory;
5251
import com.oracle.graal.python.util.BiConsumer;
53-
import com.oracle.truffle.api.RootCallTarget;
5452
import com.oracle.truffle.api.TruffleLanguage.Env;
5553
import com.oracle.truffle.api.dsl.NodeFactory;
5654
import com.oracle.truffle.api.strings.TruffleString;
@@ -95,21 +93,13 @@ public void initialize(Python3Core core) {
9593
}
9694
TruffleString tsName = toTruffleStringUncached(builtin.name());
9795
PythonLanguage language = core.getLanguage();
98-
boolean lazyCallTargets = core.getContext().getOption(PythonOptions.BuiltinLazyCallTargets);
9996
PBuiltinFunction function;
100-
if (lazyCallTargets) {
101-
Signature signature = BuiltinFunctionRootNode.createSignature(factory, builtin, declaresExplicitSelf, false);
102-
int flags = PBuiltinFunction.getFlags(builtin, signature);
103-
var callTargetSupplier = new CachedLazyCalltargetSupplier(() -> language.initBuiltinCallTarget(l -> new BuiltinFunctionRootNode(l, signature, builtin, factory, declaresExplicitSelf, null), factory.getNodeClass(),
104-
builtin.name()));
105-
function = PFactory.createBuiltinFunction(language, tsName, numDefaults(builtin),signature, flags, callTargetSupplier);
106-
} else {
107-
RootCallTarget callTarget = language.initBuiltinCallTarget(l -> new BuiltinFunctionRootNode(l, builtin, factory, declaresExplicitSelf), factory.getNodeClass(),
108-
builtin.name());
109-
int flags = PBuiltinFunction.getFlags(builtin, callTarget);
110-
function = PFactory.createBuiltinFunction(language, tsName, null, numDefaults(builtin), flags, callTarget);
111-
}
112-
97+
Signature signature = BuiltinFunctionRootNode.createSignature(factory, builtin, declaresExplicitSelf, false);
98+
int flags = PBuiltinFunction.getFlags(builtin, signature);
99+
var callTargetSupplier = new CachedLazyCalltargetSupplier(
100+
() -> language.initBuiltinCallTarget(l -> new BuiltinFunctionRootNode(l, signature, builtin, factory, declaresExplicitSelf, null), factory.getNodeClass(),
101+
builtin.name()));
102+
function = PFactory.createBuiltinFunction(language, tsName, numDefaults(builtin), signature, flags, callTargetSupplier);
113103
Object builtinDoc = builtin.doc().isEmpty() ? PNone.NONE : toTruffleStringUncached(builtin.doc());
114104
function.setAttribute(T___DOC__, builtinDoc);
115105
BoundBuiltinCallable<?> callable = function;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public final class PBuiltinFunction extends PythonBuiltinObject implements Bound
8686
@CompilationFinal(dimensions = 1) private final Object[] defaults;
8787
@CompilationFinal(dimensions = 1) private final PKeyword[] kwDefaults;
8888

89-
public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, Signature signature, int flags, RootCallTarget callTarget, CachedLazyCalltargetSupplier callTargetSupplier,
89+
public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, Signature signature, int flags,
90+
RootCallTarget callTarget, CachedLazyCalltargetSupplier callTargetSupplier,
9091
TpSlot slot, PExternalFunctionWrapper slotWrapper) {
9192
super(cls, shape);
9293
this.name = PythonUtils.toPString(name);
@@ -105,8 +106,11 @@ public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString n
105106
this.slotWrapper = slotWrapper;
106107
this.callTargetSupplier = callTargetSupplier;
107108

108-
/* If the call target supplier has already been run, then don't wait until the first time the InternalMethod is
109-
* asked for the call target, because can cause deoptimization in getCallTarget(). */
109+
/*
110+
* If the call target supplier has already been run, then don't wait until the first time
111+
* the InternalMethod is asked for the call target, because can cause deoptimization in
112+
* getCallTarget().
113+
*/
110114
if (callTarget == null && callTargetSupplier != null) {
111115
this.callTarget = callTargetSupplier.getIfExists();
112116
}
@@ -116,7 +120,8 @@ public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString n
116120
this(cls, shape, name, enclosingType, defaults, kwDefaults, ((PRootNode) callTarget.getRootNode()).getSignature(), flags, callTarget, null, null, null);
117121
}
118122

119-
public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, Signature signature, int flags, CachedLazyCalltargetSupplier callTargetSupplier) {
123+
public PBuiltinFunction(PythonBuiltinClassType cls, Shape shape, TruffleString name, Object enclosingType, Object[] defaults, PKeyword[] kwDefaults, Signature signature, int flags,
124+
CachedLazyCalltargetSupplier callTargetSupplier) {
120125
this(cls, shape, name, enclosingType, defaults, kwDefaults, signature, flags, null, callTargetSupplier, null, null);
121126
}
122127

@@ -225,7 +230,7 @@ public Signature getSignature() {
225230
}
226231

227232
public RootCallTarget getCallTarget() {
228-
if (callTarget == null) {
233+
if (callTarget == null) {
229234
CompilerDirectives.transferToInterpreterAndInvalidate();
230235
callTarget = callTargetSupplier.get();
231236
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ public static void checkBytecodeDSLEnv() {
389389
@EngineOption @Option(category = OptionCategory.INTERNAL, usageSyntax = "true|false", help = "If true, uses native storage strategy for primitive types") //
390390
public static final OptionKey<Boolean> UseNativePrimitiveStorageStrategy = new OptionKey<>(false);
391391

392-
@Option(category = OptionCategory.INTERNAL, usageSyntax = "true|false", help = "If true, CallTargets for builtins are initialized lazily") //
393-
public static final OptionKey<Boolean> BuiltinLazyCallTargets = new OptionKey<>(true);
394-
395392
@Option(category = OptionCategory.EXPERT, usageSyntax = "true|false", help = "Print warnings when using experimental features at runtime.", stability = OptionStability.STABLE) //
396393
public static final OptionKey<Boolean> WarnExperimentalFeatures = new OptionKey<>(true);
397394

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,10 @@ public static PFunction createFunction(PythonLanguage language, TruffleString na
545545
return trace(language, new PFunction(language, name, qualname, code, globals, defaultValues, kwDefaultValues, closure, codeStableAssumption));
546546
}
547547

548-
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, int numDefaults, Signature signature, int flags, CachedLazyCalltargetSupplier callTargetSupplier) {
548+
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, int numDefaults, Signature signature, int flags,
549+
CachedLazyCalltargetSupplier callTargetSupplier) {
549550
return trace(language, new PBuiltinFunction(PythonBuiltinClassType.PBuiltinFunction, PythonBuiltinClassType.PBuiltinFunction.getInstanceShape(language), name, null,
550-
PBuiltinFunction.generateDefaults(numDefaults), null, signature, flags, callTargetSupplier));
551+
PBuiltinFunction.generateDefaults(numDefaults), null, signature, flags, callTargetSupplier));
551552
}
552553

553554
public static PBuiltinFunction createBuiltinFunction(PythonLanguage language, TruffleString name, Object type, int numDefaults, int flags, RootCallTarget callTarget) {
@@ -568,8 +569,10 @@ public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language,
568569

569570
public static PBuiltinFunction createWrapperDescriptor(PythonLanguage language, TruffleString name, Object type, Object[] defaults, PKeyword[] kw, int flags, RootCallTarget callTarget,
570571
TpSlot slot, PExternalFunctionWrapper slotWrapper) {
571-
return trace(language, new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type, defaults, kw, ((PRootNode) callTarget.getRootNode()).getSignature(), flags,
572-
callTarget, null, slot, slotWrapper));
572+
return trace(language,
573+
new PBuiltinFunction(PythonBuiltinClassType.WrapperDescriptor, PythonBuiltinClassType.WrapperDescriptor.getInstanceShape(language), name, type, defaults, kw,
574+
((PRootNode) callTarget.getRootNode()).getSignature(), flags,
575+
callTarget, null, slot, slotWrapper));
573576
}
574577

575578
public static PBuiltinMethod createNewWrapper(PythonLanguage language, Object type, Object[] defaults, PKeyword[] kwdefaults, RootCallTarget callTarget, TpSlot slot) {

0 commit comments

Comments
 (0)