Skip to content

Commit e1f486f

Browse files
committed
[GR-24927] Fixed TruffleBoundary methods taking a Frame.
1 parent 072fa95 commit e1f486f

File tree

10 files changed

+56
-36
lines changed

10 files changed

+56
-36
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/ParserTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 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
@@ -122,7 +122,7 @@ public Node parse(String src, String moduleName, PythonParser.ParserMode mode, F
122122

123123
private Node parseInternal(Source source, PythonParser.ParserMode mode, Frame fd) {
124124
PythonParser parser = context.getParser();
125-
Node result = ((PythonParserImpl) parser).parseN(mode, 0, context, source, fd, null);
125+
Node result = ((PythonParserImpl) parser).parseN(mode, 0, context, source, fd != null ? fd.materialize() : null, null);
126126
lastGlobalScope = ((PythonParserImpl) parser).getLastGlobaScope();
127127
lastSST = ((PythonParserImpl) parser).getLastSST();
128128
// ensure that node parent pointers are set:

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,13 @@ public boolean isAdoptable() {
11251125
return false;
11261126
}
11271127

1128-
@TruffleBoundary
11291128
@Override
11301129
protected void execute(Frame frame, Object source, Object category, String format, int stackLevel, Object... formatArgs) {
1130+
executeImpl(source, category, format, stackLevel, formatArgs);
1131+
}
1132+
1133+
@TruffleBoundary
1134+
private void executeImpl(Object source, Object category, String format, int stackLevel, Object... formatArgs) {
11311135
PythonModule _warnings = PythonContext.get(this).lookupBuiltinModule("_warnings");
11321136
Object warn = DynamicObjectLibrary.getUncached().getOrDefault(_warnings, "warn", PNone.NONE);
11331137
String message;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import java.util.Date;
8686
import java.util.List;
8787

88+
import com.oracle.truffle.api.frame.MaterializedFrame;
8889
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
8990
import org.bouncycastle.cert.X509CRLHolder;
9091
import org.bouncycastle.cert.X509CertificateHolder;
@@ -619,7 +620,7 @@ public static List<Object> getCertificates(BufferedReader r, boolean onlyCertifi
619620
}
620621

621622
@TruffleBoundary
622-
static PrivateKey getPrivateKey(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, BufferedReader reader, char[] password, X509Certificate cert)
623+
static PrivateKey getPrivateKey(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, BufferedReader reader, char[] password, X509Certificate cert)
623624
throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, NeedsPasswordException {
624625
PEMParser pemParser = new PEMParser(reader);
625626
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import javax.net.ssl.SSLEngine;
7373
import javax.net.ssl.SSLParameters;
7474

75+
import com.oracle.truffle.api.frame.MaterializedFrame;
7576
import org.bouncycastle.util.encoders.DecoderException;
7677

7778
import com.oracle.graal.python.annotations.ArgumentClinic;
@@ -134,7 +135,6 @@
134135
import com.oracle.truffle.api.dsl.NodeFactory;
135136
import com.oracle.truffle.api.dsl.Specialization;
136137
import com.oracle.truffle.api.dsl.TypeSystemReference;
137-
import com.oracle.truffle.api.frame.Frame;
138138
import com.oracle.truffle.api.frame.VirtualFrame;
139139
import com.oracle.truffle.api.library.CachedLibrary;
140140

@@ -199,7 +199,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
199199
}
200200

201201
@TruffleBoundary
202-
static SSLEngine createSSLEngine(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, PNodeWithRaise node, PSSLContext context, boolean serverMode, String serverHostname) {
202+
static SSLEngine createSSLEngine(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, PNodeWithRaise node, PSSLContext context, boolean serverMode, String serverHostname) {
203203
try {
204204
context.init();
205205
} catch (NoSuchAlgorithmException | KeyStoreException | UnrecoverableKeyException | KeyManagementException | InvalidAlgorithmParameterException | IOException | CertificateException ex) {
@@ -275,7 +275,7 @@ Object wrap(VirtualFrame frame, PSSLContext context, PSocket sock, boolean serve
275275
if (!(serverHostnameObj instanceof PNone)) {
276276
serverHostname = cast.cast(serverHostnameObj, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "serverHostname", serverHostnameObj);
277277
}
278-
SSLEngine engine = createSSLEngine(frame, constructAndRaiseNode, this, context, serverSide, serverHostname);
278+
SSLEngine engine = createSSLEngine(frame.materialize(), constructAndRaiseNode, this, context, serverSide, serverHostname);
279279
PSSLSocket sslSocket = factory().createSSLSocket(PythonBuiltinClassType.PSSLSocket, context, engine, sock);
280280
if (!(owner instanceof PNone)) {
281281
sslSocket.setOwner(owner);
@@ -309,7 +309,7 @@ Object wrap(VirtualFrame frame, PSSLContext context, PMemoryBIO incoming, PMemor
309309
if (!(serverHostnameObj instanceof PNone)) {
310310
serverHostname = cast.cast(serverHostnameObj, ErrorMessages.S_MUST_BE_NONE_OR_STRING, "serverHostname", serverHostnameObj);
311311
}
312-
SSLEngine engine = createSSLEngine(frame, constructAndRaiseNode, this, context, serverSide, serverHostname);
312+
SSLEngine engine = createSSLEngine(frame.materialize(), constructAndRaiseNode, this, context, serverSide, serverHostname);
313313
PSSLSocket sslSocket = factory().createSSLSocket(PythonBuiltinClassType.PSSLSocket, context, engine, incoming, outgoing);
314314
if (!(owner instanceof PNone)) {
315315
sslSocket.setOwner(owner);
@@ -696,7 +696,7 @@ Object load(VirtualFrame frame, PSSLContext self, Object cafile, Object capath,
696696
certificates = fromString(frame, constructAndRaiseNode, castToString.execute(cadata));
697697
} catch (CannotCastException cannotCastException) {
698698
if (cadata instanceof PBytesLike) {
699-
certificates = fromBytesLike(frame, constructAndRaiseNode, toBytes, cadata);
699+
certificates = fromBytesLike(frame.materialize(), constructAndRaiseNode, toBytes, cadata);
700700
} else {
701701
throw raise(TypeError, ErrorMessages.S_SHOULD_BE_ASCII_OR_BYTELIKE, "cadata");
702702
}
@@ -734,11 +734,11 @@ private List<Object> fromString(VirtualFrame frame, PConstructAndRaiseNode const
734734
if (dataString.isEmpty()) {
735735
throw raise(ValueError, ErrorMessages.EMPTY_CERTIFICATE_DATA);
736736
}
737-
return getCertificates(frame, constructAndRaiseNode, dataString);
737+
return getCertificates(frame.materialize(), constructAndRaiseNode, dataString);
738738
}
739739

740740
@TruffleBoundary
741-
private List<Object> getCertificates(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, String dataString)
741+
private List<Object> getCertificates(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, String dataString)
742742
throws PException, CRLException, IOException, CertificateException {
743743
try (BufferedReader r = new BufferedReader(new StringReader(dataString))) {
744744
try {
@@ -756,7 +756,7 @@ private List<Object> getCertificates(Frame frame, PConstructAndRaiseNode constru
756756
}
757757

758758
@TruffleBoundary
759-
private Collection<?> fromBytesLike(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, ToByteArrayNode toBytes, Object cadata)
759+
private Collection<?> fromBytesLike(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, ToByteArrayNode toBytes, Object cadata)
760760
throws KeyStoreException, IOException, NoSuchAlgorithmException {
761761
byte[] bytes = toBytes.execute(((PBytesLike) cadata).getSequenceStorage());
762762
try {
@@ -795,12 +795,12 @@ Object load(VirtualFrame frame, PSSLContext self, Object certfile, Object keyfil
795795
TruffleFile keyTruffleFile = toTruffleFile(frame, asPath.execute(frame, kf));
796796
try {
797797
try {
798-
return load(frame, constructAndRaiseNode, certTruffleFile, keyTruffleFile, null, self);
798+
return load(frame.materialize(), constructAndRaiseNode, certTruffleFile, keyTruffleFile, null, self);
799799
} catch (NeedsPasswordException e) {
800800
if (passwordObj != PNone.NONE) {
801801
char[] password = getPasswordNode.execute(frame, passwordObj);
802802
try {
803-
return load(frame, constructAndRaiseNode, certTruffleFile, keyTruffleFile, password, self);
803+
return load(frame.materialize(), constructAndRaiseNode, certTruffleFile, keyTruffleFile, password, self);
804804
} catch (NeedsPasswordException e1) {
805805
throw CompilerDirectives.shouldNotReachHere();
806806
}
@@ -813,7 +813,7 @@ Object load(VirtualFrame frame, PSSLContext self, Object certfile, Object keyfil
813813
}
814814

815815
@TruffleBoundary
816-
private Object load(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, TruffleFile certTruffleFile, TruffleFile keyTruffleFile, char[] password, PSSLContext self)
816+
private Object load(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, TruffleFile certTruffleFile, TruffleFile keyTruffleFile, char[] password, PSSLContext self)
817817
throws IOException, NeedsPasswordException {
818818
try (BufferedReader certReader = getReader(certTruffleFile, "certfile");
819819
BufferedReader keyReader = getReader(keyTruffleFile, "keyfile")) {
@@ -830,7 +830,7 @@ private BufferedReader getReader(TruffleFile file, String arg) throws IOExceptio
830830
}
831831
}
832832

833-
private Object load(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, PSSLContext self, BufferedReader certReader, BufferedReader keyReader, char[] password)
833+
private Object load(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, PSSLContext self, BufferedReader certReader, BufferedReader keyReader, char[] password)
834834
throws NeedsPasswordException {
835835
// TODO add logging
836836
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -67,7 +67,7 @@
6767
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6868
import com.oracle.truffle.api.dsl.Cached;
6969
import com.oracle.truffle.api.dsl.Specialization;
70-
import com.oracle.truffle.api.frame.Frame;
70+
import com.oracle.truffle.api.frame.MaterializedFrame;
7171
import com.oracle.truffle.api.frame.VirtualFrame;
7272
import com.oracle.truffle.api.library.CachedLibrary;
7373

@@ -116,7 +116,7 @@ public void handshake(VirtualFrame frame, PConstructAndRaiseNode constructAndRai
116116
try {
117117
beginHandshake(socket);
118118
} catch (SSLException e) {
119-
throw handleSSLException(frame, constructAndRaiseNode, e);
119+
throw handleSSLException(frame.materialize(), constructAndRaiseNode, e);
120120
}
121121
execute(frame, socket, SSLOperationNode.EMPTY_BUFFER, SSLOperationNode.EMPTY_BUFFER, SSLOperation.HANDSHAKE);
122122
}
@@ -175,8 +175,9 @@ void doSocket(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
175175
SSLOperationStatus status;
176176
PythonContext context = PythonContext.get(this);
177177
while (true) {
178+
MaterializedFrame materializedFrame = frame.materialize();
178179
try {
179-
status = loop(frame, constructAndRaiseNode, this, socket, appInput, targetBuffer, operation);
180+
status = loop(materializedFrame, constructAndRaiseNode, this, socket, appInput, targetBuffer, operation);
180181
switch (status) {
181182
case COMPLETE:
182183
return;
@@ -258,7 +259,7 @@ void doSocket(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
258259
break;
259260
}
260261
} catch (SSLException e) {
261-
throw handleSSLException(frame, constructAndRaiseNode, e);
262+
throw handleSSLException(materializedFrame, constructAndRaiseNode, e);
262263
} catch (OverflowException | OutOfMemoryError node) {
263264
throw raise(MemoryError);
264265
}
@@ -270,8 +271,9 @@ void doSocket(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
270271
void doMemory(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBuffer targetBuffer, SSLOperation operation,
271272
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
272273
SSLOperationStatus status;
274+
MaterializedFrame materializedFrame = frame.materialize();
273275
try {
274-
status = loop(frame, constructAndRaiseNode, this, socket, appInput, targetBuffer, operation);
276+
status = loop(materializedFrame, constructAndRaiseNode, this, socket, appInput, targetBuffer, operation);
275277
switch (status) {
276278
case COMPLETE:
277279
return;
@@ -298,7 +300,7 @@ void doMemory(VirtualFrame frame, PSSLSocket socket, ByteBuffer appInput, ByteBu
298300
throw CompilerDirectives.shouldNotReachHere("MemoryBIO-based socket operation returned WANTS_WRITE");
299301
}
300302
} catch (SSLException e) {
301-
throw handleSSLException(frame, constructAndRaiseNode, e);
303+
throw handleSSLException(materializedFrame, constructAndRaiseNode, e);
302304
} catch (OverflowException | OutOfMemoryError node) {
303305
throw raise(MemoryError);
304306
}
@@ -315,7 +317,7 @@ private static void putAsMuchAsPossible(ByteBuffer target, PMemoryBIO sourceBIO)
315317
}
316318

317319
@TruffleBoundary
318-
private static SSLOperationStatus loop(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, PNodeWithRaise node, PSSLSocket socket, ByteBuffer appInput, ByteBuffer targetBuffer,
320+
private static SSLOperationStatus loop(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, PNodeWithRaise node, PSSLSocket socket, ByteBuffer appInput, ByteBuffer targetBuffer,
319321
SSLOperation op) throws SSLException, OverflowException {
320322
PMemoryBIO applicationInboundBIO = socket.getApplicationInboundBIO();
321323
PMemoryBIO networkInboundBIO = socket.getNetworkInboundBIO();
@@ -527,7 +529,7 @@ private static SSLEngineResult doWrap(SSLEngine engine, ByteBuffer appInput, PMe
527529
}
528530

529531
@TruffleBoundary
530-
private static PException handleSSLException(Frame frame, PConstructAndRaiseNode constructAndRaiseNode, SSLException e) {
532+
private static PException handleSSLException(MaterializedFrame frame, PConstructAndRaiseNode constructAndRaiseNode, SSLException e) {
531533
if (e.getCause() instanceof CertificateException) {
532534
throw constructAndRaiseNode.raiseSSLError(frame, SSLErrorCode.ERROR_CERT_VERIFICATION, ErrorMessages.CERTIFICATE_VERIFY_FAILED, e.toString());
533535
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialMethodSlotNode.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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,6 +47,7 @@
4747
import com.oracle.truffle.api.dsl.Cached;
4848
import com.oracle.truffle.api.dsl.Specialization;
4949
import com.oracle.truffle.api.frame.Frame;
50+
import com.oracle.truffle.api.frame.MaterializedFrame;
5051
import com.oracle.truffle.api.frame.VirtualFrame;
5152

5253
/**
@@ -83,8 +84,12 @@ public UncachedLookup(SpecialMethodSlot slot) {
8384
}
8485

8586
@Override
87+
public Object execute(Frame frame, Object type, Object receiver) {
88+
return executeImpl(frame != null ? frame.materialize() : null, type, receiver);
89+
}
90+
8691
@TruffleBoundary
87-
public Object execute(@SuppressWarnings("unused") Frame frame, Object type, Object receiver) {
92+
private Object executeImpl(MaterializedFrame frame, Object type, Object receiver) {
8893
return MaybeBindDescriptorNode.getUncached().execute(frame, lookup.execute(type), receiver, type);
8994
}
9095

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/GetNextNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ private static final class GetNextUncached extends GetNextNode {
118118
static final GetNextUncached INSTANCE = new GetNextUncached();
119119

120120
@Override
121-
@TruffleBoundary
122121
public Object execute(Frame frame, Object iterator) {
122+
return executeImpl(iterator);
123+
}
124+
125+
@TruffleBoundary
126+
private Object executeImpl(Object iterator) {
123127
Object nextMethod = LookupSpecialMethodSlotNode.getUncached(SpecialMethodSlot.Next).execute(null, GetClassNode.getUncached().execute(iterator), iterator);
124128
if (nextMethod == PNone.NO_VALUE) {
125129
throw PRaiseNode.getUncached().raise(PythonErrorType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, iterator, __NEXT__);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonParserImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.regex.Matcher;
3636
import java.util.regex.Pattern;
3737

38+
import com.oracle.truffle.api.frame.MaterializedFrame;
3839
import org.antlr.v4.runtime.CharStreams;
3940
import org.antlr.v4.runtime.CommonTokenStream;
4041
import org.graalvm.nativeimage.ImageInfo;
@@ -313,11 +314,12 @@ public Node parse(ParserMode mode, int optimizeLevel, ParserErrorCallback errors
313314
}
314315

315316
Node result;
317+
MaterializedFrame materializedFrame = currentFrame != null ? currentFrame.materialize() : null;
316318
if (timeStatistics <= 0) {
317-
result = parseN(mode, optimizeLevel, errors, source, currentFrame, argumentNames);
319+
result = parseN(mode, optimizeLevel, errors, source, materializedFrame, argumentNames);
318320
} else {
319321
long start = System.currentTimeMillis();
320-
result = parseN(mode, optimizeLevel, errors, source, currentFrame, argumentNames);
322+
result = parseN(mode, optimizeLevel, errors, source, materializedFrame, argumentNames);
321323
long end = System.currentTimeMillis();
322324
if (timeStatistics > 0) {
323325
timeInParser = timeInParser + (end - start);
@@ -419,7 +421,7 @@ public CacheItem parseWithANTLR(ParserMode mode, int optimizeLevel, ParserErrorC
419421
}
420422

421423
@TruffleBoundary
422-
public Node parseN(ParserMode mode, int optimizeLevel, ParserErrorCallback errors, Source source, Frame currentFrame, String[] argumentNames) {
424+
public Node parseN(ParserMode mode, int optimizeLevel, ParserErrorCallback errors, Source source, MaterializedFrame currentFrame, String[] argumentNames) {
423425
ArrayList<String> warnings = new ArrayList<>();
424426
// this wrapper tracks the warnings in a list instead of raising them immediately
425427
ParserErrorCallback collectWarnings = new ParserErrorCallback() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -51,6 +51,7 @@
5151
import com.oracle.truffle.api.TruffleLanguage;
5252
import com.oracle.truffle.api.frame.Frame;
5353
import com.oracle.truffle.api.frame.FrameDescriptor;
54+
import com.oracle.truffle.api.frame.MaterializedFrame;
5455
import com.oracle.truffle.api.interop.InteropLibrary;
5556
import com.oracle.truffle.api.interop.TruffleObject;
5657
import com.oracle.truffle.api.interop.UnknownIdentifierException;
@@ -82,7 +83,7 @@ public final class PythonLocalScope implements TruffleObject {
8283
}
8384

8485
@TruffleBoundary
85-
static PythonLocalScope createLocalScope(RootNode root, Frame frame) {
86+
static PythonLocalScope createLocalScope(RootNode root, MaterializedFrame frame) {
8687
LinkedHashMap<String, Integer> slotsMap = new LinkedHashMap<>();
8788

8889
FrameDescriptor fd = frame == null ? root.getFrameDescriptor() : frame.getFrameDescriptor();

0 commit comments

Comments
 (0)