Skip to content

Commit 2adaebf

Browse files
committed
Use lazy version of PConstructAndRaiseNode
1 parent c3d76b6 commit 2adaebf

File tree

11 files changed

+52
-41
lines changed

11 files changed

+52
-41
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ private static Semaphore newSemaphore(int value) {
172172
abstract static class SemUnlink extends PythonUnaryBuiltinNode {
173173
@Specialization
174174
PNone doit(VirtualFrame frame, TruffleString name,
175-
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
175+
@Bind("this") Node inliningTarget,
176+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
176177
Semaphore prev = getContext().getSharedMultiprocessingData().removeNamedSemaphore(name);
177178
if (prev == null) {
178-
throw constructAndRaiseNode.raiseFileNotFoundError(frame, ErrorMessages.NO_SUCH_FILE_OR_DIR, "semaphores", name);
179+
throw constructAndRaiseNode.get(inliningTarget).raiseFileNotFoundError(frame, ErrorMessages.NO_SUCH_FILE_OR_DIR, "semaphores", name);
179180
}
180181
return PNone.NONE;
181182
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Object doGeneric(VirtualFrame frame, TruffleString ip,
288288
@Cached SocketNodes.SetIpAddrNode setIpAddrNode,
289289
@Cached SequenceStorageNodes.AppendNode appendNode,
290290
@Cached SocketNodes.MakeIpAddrNode makeIpAddrNode,
291-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
291+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
292292
@Cached SysModuleBuiltins.AuditNode auditNode,
293293
@Cached GilNode gil) {
294294
/*
@@ -327,7 +327,7 @@ Object doGeneric(VirtualFrame frame, TruffleString ip,
327327
return factory().createTuple(new Object[]{hostname, factory().createList(), factory().createList(storage)});
328328
} catch (GetAddrInfoException e) {
329329
// TODO convert error code from gaierror to herror
330-
throw constructAndRaiseNode.executeWithArgsOnly(frame, SocketHError, new Object[]{1, e.getMessageAsTruffleString()});
330+
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketHError, new Object[]{1, e.getMessageAsTruffleString()});
331331
}
332332
}
333333

@@ -507,7 +507,7 @@ Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
507507
@Cached CastToTruffleStringNode castAddress,
508508
@Cached PyLongAsIntNode asIntNode,
509509
@Cached SysModuleBuiltins.AuditNode auditNode,
510-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
510+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
511511
@Cached TruffleString.FromLongNode fromLongNode) {
512512
SequenceStorage addr = sockaddr.getSequenceStorage();
513513
int addrLen = addr.length();
@@ -574,7 +574,7 @@ Object getNameInfo(VirtualFrame frame, PTuple sockaddr, int flags,
574574
TruffleString service = posixLib.getPathAsString(getPosixSupport(), getnameinfo[1]);
575575
return factory().createTuple(new Object[]{host, service});
576576
} catch (GetAddrInfoException e) {
577-
throw constructAndRaiseNode.executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessageAsTruffleString()});
577+
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessageAsTruffleString()});
578578
}
579579
}
580580

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ public abstract static class EnumKeyNode extends PythonBinaryBuiltinNode {
111111
@SuppressWarnings("unused")
112112
@Specialization
113113
static Object enumKey(VirtualFrame frame, Object key, Object index,
114-
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
115-
throw constructAndRaiseNode.raiseOSError(frame, OSErrorEnum.ENOENT);
114+
@Bind("this") Node inliningTarget,
115+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
116+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
116117
}
117118
}
118119
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,13 +1796,14 @@ private final void checkIndex(long idx) throws InvalidBufferOffsetException {
17961796

17971797
@ExportMessage
17981798
byte readBufferByte(long idx,
1799+
@Bind("$node") Node inliningTarget,
17991800
@CachedLibrary(limit = "1") PosixSupportLibrary posixSupportLib,
1800-
@Cached PConstructAndRaiseNode raise) throws InvalidBufferOffsetException {
1801+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) throws InvalidBufferOffsetException {
18011802
checkIndex(idx);
18021803
try {
18031804
return (posixSupportLib.mmapReadByte(PythonContext.get(posixSupportLib).getPosixSupport(), delegate.getPosixSupportHandle(), idx));
18041805
} catch (PosixException e) {
1805-
throw raise.raiseOSError(null, e.getErrorCode(), e.getMessageAsTruffleString(), null, null);
1806+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(null, e.getErrorCode(), e.getMessageAsTruffleString(), null, null);
18061807
}
18071808
}
18081809

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/PMMap.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.oracle.truffle.api.library.ExportMessage;
6161
import com.oracle.truffle.api.nodes.Node;
6262
import com.oracle.truffle.api.object.Shape;
63-
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
6463
import com.oracle.truffle.api.strings.TruffleString;
6564

6665
@ExportLibrary(PythonBufferAcquireLibrary.class)
@@ -140,31 +139,27 @@ int getBufferLength(
140139
byte readByte(int byteOffset,
141140
@Bind("$node") Node inliningTarget,
142141
@Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
143-
@Shared("gotException") @Cached InlinedBranchProfile gotException,
144-
@Shared("raiseNode") @Cached PConstructAndRaiseNode raiseNode,
142+
@Shared("raiseNode") @Cached PConstructAndRaiseNode.Lazy raiseNode,
145143
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
146144
try {
147145
return posixLib.mmapReadByte(PythonContext.get(raiseNode).getPosixSupport(), getPosixSupportHandle(), byteOffset);
148146
} catch (PosixException e) {
149147
// TODO(fa) how to handle?
150-
gotException.enter(inliningTarget);
151-
throw raiseNode.raiseOSError(null, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
148+
throw raiseNode.get(inliningTarget).raiseOSError(null, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
152149
}
153150
}
154151

155152
@ExportMessage
156153
void writeByte(int byteOffset, byte value,
157154
@Bind("$node") Node inliningTarget,
158155
@Shared @CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
159-
@Shared("gotException") @Cached InlinedBranchProfile gotException,
160-
@Shared("raiseNode") @Cached PConstructAndRaiseNode raiseNode,
156+
@Shared("raiseNode") @Cached PConstructAndRaiseNode.Lazy raiseNode,
161157
@Shared("js2ts") @Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
162158
try {
163159
posixLib.mmapWriteByte(PythonContext.get(raiseNode).getPosixSupport(), getPosixSupportHandle(), byteOffset, value);
164160
} catch (PosixException e) {
165161
// TODO(fa) how to handle?
166-
gotException.enter(inliningTarget);
167-
throw raiseNode.raiseOSError(null, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
162+
throw raiseNode.get(inliningTarget).raiseOSError(null, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
168163
}
169164
}
170165

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/socket/SocketNodes.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ public abstract static class SetIpAddrNode extends PNodeWithRaise {
267267

268268
@Specialization
269269
UniversalSockAddr setipaddr(VirtualFrame frame, TruffleString name, int family,
270+
@Bind("this") Node inliningTarget,
270271
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
271272
@CachedLibrary(limit = "1") AddrInfoCursorLibrary addrInfoLib,
272-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
273+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
273274
@Cached TruffleString.EqualNode equalNode,
274275
@Cached TruffleString.ByteIndexOfCodePointNode byteIndexOfCodePointNode,
275276
@Cached GilNode gil) {
@@ -343,7 +344,7 @@ UniversalSockAddr setipaddr(VirtualFrame frame, TruffleString name, int family,
343344
gil.acquire();
344345
}
345346
} catch (GetAddrInfoException e) {
346-
throw constructAndRaiseNode.executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessage()});
347+
throw constructAndRaiseNode.get(inliningTarget).executeWithArgsOnly(frame, SocketGAIError, new Object[]{e.getErrorCode(), e.getMessage()});
347348
}
348349
}
349350

@@ -359,11 +360,13 @@ public abstract static class MakeSockAddrNode extends PNodeWithRaise {
359360
public abstract Object execute(VirtualFrame frame, UniversalSockAddr addr);
360361

361362
@Specialization(limit = "1")
363+
@SuppressWarnings("truffle-static-method")
362364
Object makeSockAddr(VirtualFrame frame, UniversalSockAddr addr,
365+
@Bind("this") Node inliningTarget,
363366
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
364367
@CachedLibrary("addr") UniversalSockAddrLibrary addrLib,
365368
@Cached PythonObjectFactory factory,
366-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
369+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
367370
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
368371
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
369372
@Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
@@ -395,7 +398,7 @@ Object makeSockAddr(VirtualFrame frame, UniversalSockAddr addr,
395398
throw raise(NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
396399
}
397400
} catch (PosixException e) {
398-
throw constructAndRaiseNode.raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
401+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
399402
}
400403
}
401404

@@ -417,10 +420,12 @@ public abstract static class MakeIpAddrNode extends PNodeWithRaise {
417420
public abstract Object execute(VirtualFrame frame, UniversalSockAddr addr);
418421

419422
@Specialization(limit = "1")
423+
@SuppressWarnings("truffle-static-method")
420424
Object makeAddr(VirtualFrame frame, UniversalSockAddr addr,
425+
@Bind("this") Node inliningTarget,
421426
@CachedLibrary(limit = "1") PosixSupportLibrary posixLib,
422427
@CachedLibrary("addr") UniversalSockAddrLibrary addrLib,
423-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
428+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
424429
@Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
425430
try {
426431
PythonContext context = PythonContext.get(this);
@@ -437,7 +442,7 @@ Object makeAddr(VirtualFrame frame, UniversalSockAddr addr,
437442
throw raise(NotImplementedError, toTruffleStringUncached("makesockaddr: unknown address family"));
438443
}
439444
} catch (PosixException e) {
440-
throw constructAndRaiseNode.raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
445+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e.getErrorCode(), fromJavaStringNode.execute(e.getMessage(), TS_ENCODING), null, null);
441446
}
442447
}
443448
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@
5959
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6060
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
6161
import com.oracle.graal.python.util.OverflowException;
62+
import com.oracle.truffle.api.dsl.Bind;
6263
import com.oracle.truffle.api.dsl.Cached;
6364
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6465
import com.oracle.truffle.api.dsl.NodeFactory;
6566
import com.oracle.truffle.api.dsl.Specialization;
6667
import com.oracle.truffle.api.frame.VirtualFrame;
6768
import com.oracle.truffle.api.library.CachedLibrary;
69+
import com.oracle.truffle.api.nodes.Node;
6870

6971
@CoreFunctions(extendClasses = PythonBuiltinClassType.PMemoryBIO)
7072
public final class MemoryBIOBuiltins extends PythonBuiltins {
@@ -121,12 +123,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
121123
@GenerateNodeFactory
122124
abstract static class WriteNode extends PythonBinaryClinicBuiltinNode {
123125
@Specialization(limit = "3")
126+
@SuppressWarnings("truffle-static-method")
124127
int write(VirtualFrame frame, PMemoryBIO self, Object buffer,
125-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
128+
@Bind("this") Node inliningTarget,
129+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
126130
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
127131
try {
128132
if (self.didWriteEOF()) {
129-
throw constructAndRaiseNode.raiseSSLError(frame, SSL_CANNOT_WRITE_AFTER_EOF);
133+
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSL_CANNOT_WRITE_AFTER_EOF);
130134
}
131135
try {
132136
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ abstract static class SSLContextNode extends PythonBinaryClinicBuiltinNode {
163163

164164
@Specialization
165165
PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
166-
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
166+
@Bind("this") Node inliningTarget,
167+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
167168
SSLMethod method = SSLMethod.fromPythonId(protocol);
168169
if (method == null) {
169170
throw raise(ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, "NULL");
@@ -188,7 +189,7 @@ PSSLContext createContext(VirtualFrame frame, Object type, int protocol,
188189
} catch (NoSuchAlgorithmException e) {
189190
throw raise(ValueError, ErrorMessages.INVALID_OR_UNSUPPORTED_PROTOCOL_VERSION, e);
190191
} catch (KeyManagementException e) {
191-
throw constructAndRaiseNode.raiseSSLError(frame, SSLErrorCode.ERROR_SSL, e);
192+
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, e);
192193
}
193194
}
194195

@@ -670,7 +671,8 @@ abstract static class CertStoreStatsNode extends PythonUnaryBuiltinNode {
670671

671672
@Specialization
672673
Object storeStats(VirtualFrame frame, PSSLContext self,
673-
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
674+
@Bind("this") Node inliningTarget,
675+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
674676
try {
675677
int x509 = 0, crl = 0, ca = 0;
676678
for (X509Certificate cert : self.getCACerts()) {
@@ -686,7 +688,7 @@ Object storeStats(VirtualFrame frame, PSSLContext self,
686688
}
687689
return factory().createDict(new PKeyword[]{new PKeyword(T_X509, x509), new PKeyword(T_CRL, crl), new PKeyword(T_X509_CA, ca)});
688690
} catch (Exception ex) {
689-
throw constructAndRaiseNode.raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
691+
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
690692
}
691693
}
692694
}
@@ -1037,7 +1039,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
10371039
abstract static class GetCACerts extends PythonBinaryClinicBuiltinNode {
10381040
@Specialization(guards = "!binary_form")
10391041
Object getCerts(VirtualFrame frame, PSSLContext self, @SuppressWarnings("unused") boolean binary_form,
1040-
@Cached PConstructAndRaiseNode constructAndRaiseNode) {
1042+
@Bind("this") Node inliningTarget,
1043+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
10411044
try {
10421045
List<PDict> result = PythonUtils.newList();
10431046
for (X509Certificate cert : self.getCACerts()) {
@@ -1047,7 +1050,7 @@ Object getCerts(VirtualFrame frame, PSSLContext self, @SuppressWarnings("unused"
10471050
}
10481051
return factory().createList(PythonUtils.toArray(result));
10491052
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateParsingException ex) {
1050-
throw constructAndRaiseNode.raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
1053+
throw constructAndRaiseNode.get(inliningTarget).raiseSSLError(frame, SSLErrorCode.ERROR_SSL, ex);
10511054
}
10521055
}
10531056

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ Object setName(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarn
11131113
Object setName(VirtualFrame frame, PythonClass cls, Object value,
11141114
@Bind("this") Node inliningTarget,
11151115
@Exclusive @Cached CastToTruffleStringNode castToTruffleStringNode,
1116-
@Cached PConstructAndRaiseNode constructAndRaiseNode,
1116+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
11171117
@Cached TruffleString.IsValidNode isValidNode,
11181118
@Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode,
11191119
@Shared("indexOf") @Cached TruffleString.IndexOfCodePointNode indexOfCodePointNode) {
@@ -1123,7 +1123,7 @@ Object setName(VirtualFrame frame, PythonClass cls, Object value,
11231123
throw raise(PythonBuiltinClassType.ValueError, ErrorMessages.TYPE_NAME_NO_NULL_CHARS);
11241124
}
11251125
if (!isValidNode.execute(string, TS_ENCODING)) {
1126-
throw constructAndRaiseNode.raiseUnicodeEncodeError(frame, "utf-8", string, 0, string.codePointLengthUncached(TS_ENCODING), "can't encode classname");
1126+
throw constructAndRaiseNode.get(inliningTarget).raiseUnicodeEncodeError(frame, "utf-8", string, 0, string.codePointLengthUncached(TS_ENCODING), "can't encode classname");
11271127
}
11281128
cls.setName(string);
11291129
return PNone.NONE;

0 commit comments

Comments
 (0)