Skip to content

Commit 77b957f

Browse files
committed
[GR-39476] Fix a few compilation bailouts
PullRequest: graalpython/2320
2 parents 13acfa3 + 752df81 commit 77b957f

File tree

8 files changed

+69
-115
lines changed

8 files changed

+69
-115
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ long start(VirtualFrame frame, Object cls, Object callable, Object args, Object
208208
// TODO: python thread stack size != java thread stack size
209209
// ignore setting the stack size for the moment
210210
Thread thread = env.createThread(() -> {
211-
Object[] arguments = getArgsNode.executeWith(frame, args);
212-
PKeyword[] keywords = getKwArgsNode.execute(kwargs);
213-
214211
try (GilNode.UncachedAcquire gil = GilNode.uncachedAcquire()) {
212+
// if args is an arbitrary iterable, converting it to an Object[] may run
213+
// Python code
214+
Object[] arguments = getArgsNode.executeWith(null, args);
215+
PKeyword[] keywords = getKwArgsNode.execute(kwargs);
216+
215217
// the increment is protected by the gil
216218
DynamicObjectLibrary lib = DynamicObjectLibrary.getUncached();
217219
int curCount = 0;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ManagedMethodWrappers.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -47,7 +47,7 @@
4747
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.ToPyObjectNode;
4848
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4949
import com.oracle.graal.python.nodes.argument.keywords.ExpandKeywordStarargsNode;
50-
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode;
50+
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode;
5151
import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode;
5252
import com.oracle.graal.python.nodes.call.CallNode;
5353
import com.oracle.graal.python.runtime.GilNode;
@@ -128,7 +128,7 @@ public Object execute(Object[] arguments,
128128
@Exclusive @Cached ToJavaNode toJavaNode,
129129
@Exclusive @Cached CExtNodes.ToNewRefNode toSulongNode,
130130
@Exclusive @Cached CallNode callNode,
131-
@Exclusive @Cached ExecutePositionalStarargsInteropNode posStarargsNode,
131+
@Exclusive @Cached ExecutePositionalStarargsNode posStarargsNode,
132132
@Exclusive @Cached ExpandKeywordStarargsNode expandKwargsNode,
133133
@Exclusive @Cached GilNode gil) throws ArityException {
134134
boolean mustRelease = gil.acquire();
@@ -143,7 +143,7 @@ public Object execute(Object[] arguments,
143143
Object starArgs = toJavaNode.execute(arguments[1]);
144144
Object kwArgs = toJavaNode.execute(arguments[2]);
145145

146-
Object[] starArgsArray = posStarargsNode.executeWithGlobalState(starArgs);
146+
Object[] starArgsArray = posStarargsNode.executeWith(null, starArgs);
147147
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
148148
PKeyword[] kwArgsArray = expandKwargsNode.execute(kwArgs);
149149

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyDateTimeCAPIWrapper.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
5454

5555
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
56-
import com.oracle.graal.python.builtins.modules.cext.PythonCextAbstractBuiltins.PyMappingKeysNode;
5756
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AllToJavaNode;
5857
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.IsPointerNode;
5958
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
@@ -64,12 +63,11 @@
6463
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.ToPyObjectNode;
6564
import com.oracle.graal.python.builtins.objects.function.PKeyword;
6665
import com.oracle.graal.python.lib.PyObjectGetAttr;
67-
import com.oracle.graal.python.lib.PyObjectGetItem;
6866
import com.oracle.graal.python.lib.PyObjectLookupAttr;
6967
import com.oracle.graal.python.lib.PyObjectSetAttr;
7068
import com.oracle.graal.python.nodes.ErrorMessages;
7169
import com.oracle.graal.python.nodes.argument.keywords.ExpandKeywordStarargsNodeGen;
72-
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNodeGen.ExecutePositionalStarargsInteropNodeGen;
70+
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNodeGen;
7371
import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
7472
import com.oracle.graal.python.nodes.statement.AbstractImportNode;
7573
import com.oracle.graal.python.runtime.GilNode;
@@ -547,18 +545,16 @@ protected Object execute(Object[] args,
547545
@Cached ToSulongNode toSulongNode,
548546
@Cached CallVarargsMethodNode callNode,
549547
@Cached AllToJavaNode allToJavaNode,
550-
@Cached PyObjectGetItem getItemNode,
551-
@Cached(allowUncached = true) PyMappingKeysNode keysNode,
552548
@Cached PyObjectLookupAttr lookupNode,
553549
@Cached CExtNodes.AddRefCntNode incRefNode,
554550
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
555-
@Exclusive @Cached GilNode gil) throws ArityException {
551+
@Exclusive @Cached GilNode gil) {
556552
boolean mustRelease = gil.acquire();
557553
try {
558554
Object[] convertedArgs = allToJavaNode.execute(args);
559555
Object type = convertedArgs[0];
560556

561-
Object[] callArgs = ExecutePositionalStarargsInteropNodeGen.getUncached().executeWithGlobalState(convertedArgs[1]);
557+
Object[] callArgs = ExecutePositionalStarargsNodeGen.getUncached().executeWith(null, convertedArgs[1]);
562558
PKeyword[] kwds;
563559
if (convertedArgs.length > 2) {
564560
kwds = ExpandKeywordStarargsNodeGen.getUncached().execute(convertedArgs[2]);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static class Execute {
217217
@Specialization(guards = "arguments.length == 3")
218218
static int init(InitWrapper self, Object[] arguments,
219219
@CachedLibrary("self") PythonNativeWrapperLibrary lib,
220-
@Cached ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode posStarargsNode,
220+
@Cached ExecutePositionalStarargsNode posStarargsNode,
221221
@Cached ExpandKeywordStarargsNode expandKwargsNode,
222222
@Cached CallVarargsMethodNode callNode,
223223
@Cached ToJavaNode toJavaNode,
@@ -231,7 +231,7 @@ static int init(InitWrapper self, Object[] arguments,
231231
Object starArgs = toJavaNode.execute(arguments[1]);
232232
Object kwArgs = toJavaNode.execute(arguments[2]);
233233

234-
Object[] starArgsArray = posStarargsNode.executeWithGlobalState(starArgs);
234+
Object[] starArgsArray = posStarargsNode.executeWith(null, starArgs);
235235
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
236236
PKeyword[] kwArgsArray = expandKwargsNode.execute(kwArgs);
237237
callNode.execute(null, lib.getDelegate(self), pArgs, kwArgsArray);
@@ -266,7 +266,7 @@ static class Execute {
266266
@Specialization(guards = "arguments.length == 3")
267267
static Object call(TernaryFunctionWrapper self, Object[] arguments,
268268
@CachedLibrary("self") PythonNativeWrapperLibrary lib,
269-
@Cached ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode posStarargsNode,
269+
@Cached ExecutePositionalStarargsNode posStarargsNode,
270270
@Cached ExpandKeywordStarargsNode expandKwargsNode,
271271
@Cached CallVarargsMethodNode callNode,
272272
@Cached ToJavaNode toJavaNode,
@@ -281,7 +281,7 @@ static Object call(TernaryFunctionWrapper self, Object[] arguments,
281281
Object starArgs = toJavaNode.execute(arguments[1]);
282282
Object kwArgs = toJavaNode.execute(arguments[2]);
283283

284-
Object[] starArgsArray = posStarargsNode.executeWithGlobalState(starArgs);
284+
Object[] starArgsArray = posStarargsNode.executeWith(null, starArgs);
285285
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
286286
PKeyword[] kwArgsArray = expandKwargsNode.execute(kwArgs);
287287
Object result = callNode.execute(null, lib.getDelegate(self), pArgs, kwArgsArray);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
import com.oracle.graal.python.nodes.SpecialMethodNames;
180180
import com.oracle.graal.python.nodes.WriteUnraisableNode;
181181
import com.oracle.graal.python.nodes.argument.keywords.ExpandKeywordStarargsNode;
182-
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode.ExecutePositionalStarargsInteropNode;
182+
import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode;
183183
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
184184
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
185185
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
@@ -2736,7 +2736,7 @@ public static final class GraalHPyCallTupleDict extends GraalHPyContextFunction
27362736
Object execute(Object[] arguments,
27372737
@Cached HPyAsContextNode asContextNode,
27382738
@Cached HPyAsPythonObjectNode asPythonObjectNode,
2739-
@Cached ExecutePositionalStarargsInteropNode expandArgsNode,
2739+
@Cached ExecutePositionalStarargsNode expandArgsNode,
27402740
@Cached HashingCollectionNodes.LenNode lenNode,
27412741
@Cached ExpandKeywordStarargsNode expandKwargsNode,
27422742
@Cached HPyAsHandleNode asHandleNode,
@@ -2764,14 +2764,14 @@ Object execute(Object[] arguments,
27642764
}
27652765

27662766
private static Object[] castArgs(Object args,
2767-
ExecutePositionalStarargsInteropNode expandArgsNode,
2767+
ExecutePositionalStarargsNode expandArgsNode,
27682768
PRaiseNode raiseNode) {
27692769
// this indicates that a NULL handle was passed (which is valid)
27702770
if (args == PNone.NO_VALUE) {
27712771
return PythonUtils.EMPTY_OBJECT_ARRAY;
27722772
}
27732773
if (PGuards.isPTuple(args)) {
2774-
return expandArgsNode.executeWithGlobalState(args);
2774+
return expandArgsNode.executeWith(null, args);
27752775
}
27762776
throw raiseNode.raise(TypeError, ErrorMessages.HPY_CALLTUPLEDICT_REQUIRES_ARGS_TUPLE_OR_NULL);
27772777
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/posix/DirEntryBuiltins.java

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@
7878
import com.oracle.graal.python.runtime.PosixSupportLibrary;
7979
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
8080
import com.oracle.truffle.api.CompilerDirectives;
81+
import com.oracle.truffle.api.dsl.Bind;
8182
import com.oracle.truffle.api.dsl.Cached;
8283
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8384
import com.oracle.truffle.api.dsl.NodeFactory;
8485
import com.oracle.truffle.api.dsl.Specialization;
86+
import com.oracle.truffle.api.dsl.Cached.Shared;
8587
import com.oracle.truffle.api.frame.VirtualFrame;
8688
import com.oracle.truffle.api.library.CachedLibrary;
8789
import com.oracle.truffle.api.profiles.ConditionProfile;
@@ -237,7 +239,7 @@ static Object stat(VirtualFrame frame, PDirEntry self, boolean followSymlinks,
237239
}
238240
}
239241

240-
abstract static class StatHelperNode extends PythonBuiltinBaseNode {
242+
abstract static class StatHelperSimpleNode extends PythonBuiltinBaseNode {
241243

242244
abstract PTuple execute(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent);
243245

@@ -253,44 +255,60 @@ static PTuple cachedLStat(PDirEntry self, boolean followSymlinks, boolean catchN
253255
return self.lstatCache;
254256
}
255257

256-
@Specialization(guards = "self.getStatCache(followSymlinks) == null")
257-
PTuple stat(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
258+
@Specialization(guards = {"followSymlinks", "self.statCache == null", "isSymlink"}, limit = "1")
259+
PTuple uncachedStatWithSymlink(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
260+
@SuppressWarnings("unused") @Cached IsSymlinkNode isSymlinkNode,
261+
@SuppressWarnings("unused") @Bind("isSymlinkNode.executeBoolean(frame, self)") boolean isSymlink,
258262
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
259-
@Cached IsSymlinkNode isSymlinkNode,
260-
@Cached StatHelperNode recursiveNode,
261-
@Cached CachedPosixPathNode cachedPosixPathNode,
262-
@Cached ConditionProfile positiveLongProfile,
263-
@Cached ConditionProfile noSymlinkProfile) {
264-
PTuple res;
263+
@Shared("cachedPosixPathNode") @Cached CachedPosixPathNode cachedPosixPathNode,
264+
@Shared("positiveLongProfile") @Cached ConditionProfile positiveLongProfile) {
265265
// There are two caches - one for `follow_symlinks=True` and the other for
266266
// 'follow_symlinks=False`. They are different only when the dir entry is a symlink.
267-
// If it is not, they need to be the same, so we must make sure that fstatat() gets
268-
// called only once.
269-
if (noSymlinkProfile.profile(followSymlinks && !isSymlinkNode.execute(frame, self))) {
270-
// The entry is not a symlink, so both stat caches need to have the
271-
// same value. Also, the `follow_symlinks=False` cache might already be filled
272-
// in. (In fact, the call to isSymlinkNode in the condition may fill it.)
273-
// So we call ourselves recursively to either use or fill that cache first, and
274-
// the `follow_symlinks=True` cache will be filled below.
275-
res = recursiveNode.execute(frame, self, false, catchNoent);
276-
} else {
277-
int dirFd = self.scandirPath instanceof PosixFd ? ((PosixFd) self.scandirPath).fd : AT_FDCWD.value;
278-
PosixPath posixPath = cachedPosixPathNode.execute(frame, self);
279-
try {
280-
long[] rawStat = posixLib.fstatat(getPosixSupport(), dirFd, posixPath.value, followSymlinks);
281-
res = PosixModuleBuiltins.createStatResult(factory(), positiveLongProfile, rawStat);
282-
} catch (PosixException e) {
283-
if (catchNoent && e.getErrorCode() == OSErrorEnum.ENOENT.getNumber()) {
284-
return null;
285-
}
286-
throw raiseOSErrorFromPosixException(frame, e, posixPath.originalObject);
267+
return uncachedLStatWithSymlink(frame, self, followSymlinks, catchNoent, posixLib, cachedPosixPathNode, positiveLongProfile);
268+
}
269+
270+
@Specialization(guards = {"!followSymlinks", "self.lstatCache == null"})
271+
PTuple uncachedLStatWithSymlink(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
272+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
273+
@Shared("cachedPosixPathNode") @Cached CachedPosixPathNode cachedPosixPathNode,
274+
@Shared("positiveLongProfile") @Cached ConditionProfile positiveLongProfile) {
275+
PTuple res;
276+
int dirFd = self.scandirPath instanceof PosixFd ? ((PosixFd) self.scandirPath).fd : AT_FDCWD.value;
277+
PosixPath posixPath = cachedPosixPathNode.execute(frame, self);
278+
try {
279+
long[] rawStat = posixLib.fstatat(getPosixSupport(), dirFd, posixPath.value, followSymlinks);
280+
res = PosixModuleBuiltins.createStatResult(factory(), positiveLongProfile, rawStat);
281+
} catch (PosixException e) {
282+
if (catchNoent && e.getErrorCode() == OSErrorEnum.ENOENT.getNumber()) {
283+
return null;
287284
}
285+
throw raiseOSErrorFromPosixException(frame, e, posixPath.originalObject);
288286
}
289287
self.setStatCache(followSymlinks, res);
290288
return res;
291289
}
292290
}
293291

292+
abstract static class StatHelperNode extends StatHelperSimpleNode {
293+
@Specialization(guards = {"followSymlinks", "self.statCache == null", "!isSymlink"})
294+
static PTuple uncachedStatWithSymlink(VirtualFrame frame, PDirEntry self, boolean followSymlinks, boolean catchNoent,
295+
@SuppressWarnings("unused") @Cached IsSymlinkNode isSymlinkNode,
296+
@SuppressWarnings("unused") @Bind("isSymlinkNode.executeBoolean(frame, self)") boolean isSymlink,
297+
@Cached StatHelperSimpleNode recursiveNode) {
298+
// There are two caches - one for `follow_symlinks=True` and the other for
299+
// 'follow_symlinks=False`. They are different only when the dir entry is a symlink.
300+
// If it is not, they need to be the same, so we must make sure that fstatat() gets
301+
// called only once. The entry is not a symlink, so both stat caches need to have the
302+
// same value. Also, the `follow_symlinks=False` cache might already be filled
303+
// in. (In fact, the call to isSymlinkNode in the condition may fill it.)
304+
// So we call ourselves recursively to either use or fill that cache first, and
305+
// the `follow_symlinks=True` cache will be filled below.
306+
PTuple res = recursiveNode.execute(frame, self, false, catchNoent);
307+
self.setStatCache(followSymlinks, res);
308+
return res;
309+
}
310+
}
311+
294312
abstract static class TestModeNode extends PythonBuiltinBaseNode {
295313

296314
private final long expectedMode;
@@ -355,7 +373,7 @@ static TestModeNode createDir() {
355373
@GenerateNodeFactory
356374
abstract static class IsSymlinkNode extends PythonUnaryBuiltinNode {
357375

358-
abstract boolean execute(VirtualFrame frame, PDirEntry self);
376+
abstract boolean executeBoolean(VirtualFrame frame, PDirEntry self);
359377

360378
@Specialization
361379
static boolean isSymlink(VirtualFrame frame, PDirEntry self,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public static Object[] toCharacterArray(TruffleString arg, TruffleString.CodePoi
248248
return values;
249249
}
250250

251+
@TruffleBoundary
251252
public static boolean isPrintable(int codepoint) {
252253
if (ImageInfo.inImageBuildtimeCode()) {
253254
// Executing ICU4J at image build time causes issues with runtime/build time

0 commit comments

Comments
 (0)