Skip to content

Commit 7332b7c

Browse files
committed
split CastToJavaInt/LongNode into an explicit lossy and exact class
1 parent 570119a commit 7332b7c

26 files changed

+375
-215
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.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.truffle.PythonArithmeticTypes;
180180
import com.oracle.graal.python.nodes.util.CannotCastException;
181181
import com.oracle.graal.python.nodes.util.CastToByteNode;
182-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
182+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
183183
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
184184
import com.oracle.graal.python.nodes.util.CastToJavaStringNodeGen;
185185
import com.oracle.graal.python.nodes.util.SplitArgsNode;
@@ -2106,7 +2106,7 @@ public abstract static class TypeNode extends PythonBuiltinNode {
21062106
@Child private ReadAttributeFromObjectNode readAttrNode;
21072107
@Child private SetAttributeNode.Dynamic writeAttrNode;
21082108
@Child private GetAnyAttributeNode getAttrNode;
2109-
@Child private CastToJavaIntNode castToInt;
2109+
@Child private CastToJavaIntExactNode castToInt;
21102110
@Child private CastToListNode castToList;
21112111
@Child private CastToJavaStringNode castToStringNode;
21122112
@Child private SequenceStorageNodes.LenNode slotLenNode;
@@ -2572,10 +2572,10 @@ private SetAttributeNode.Dynamic ensureWriteAttrNode() {
25722572
return writeAttrNode;
25732573
}
25742574

2575-
private CastToJavaIntNode ensureCastToIntNode() {
2575+
private CastToJavaIntExactNode ensureCastToIntNode() {
25762576
if (castToInt == null) {
25772577
CompilerDirectives.transferToInterpreterAndInvalidate();
2578-
castToInt = insert(CastToJavaIntNode.create());
2578+
castToInt = insert(CastToJavaIntExactNode.create());
25792579
}
25802580
return castToInt;
25812581
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5656
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5757
import com.oracle.graal.python.nodes.util.CannotCastException;
58-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
58+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
5959
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6060
import com.oracle.graal.python.runtime.PythonCore;
6161
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -85,10 +85,10 @@ abstract static class ConstructSemLockNode extends PythonBuiltinNode {
8585
@Specialization
8686
PSemLock construct(LazyPythonClass cls, Object kindObj, Object valueObj, Object maxvalueObj, Object nameObj, Object unlinkObj,
8787
@Cached CastToJavaStringNode castNameNode,
88-
@Cached CastToJavaIntNode castKindToIntNode,
89-
@Cached CastToJavaIntNode castValueToIntNode,
90-
@Cached CastToJavaIntNode castMaxvalueToIntNode,
91-
@Cached CastToJavaIntNode castUnlinkToIntNode,
88+
@Cached CastToJavaIntExactNode castKindToIntNode,
89+
@Cached CastToJavaIntExactNode castValueToIntNode,
90+
@Cached CastToJavaIntExactNode castMaxvalueToIntNode,
91+
@Cached CastToJavaIntExactNode castUnlinkToIntNode,
9292
@CachedLanguage PythonLanguage lang) {
9393
int kind = castKindToIntNode.execute(kindObj);
9494
if (kind != PSemLock.RECURSIVE_MUTEX && kind != PSemLock.SEMAPHORE) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
125125
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
126126
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
127-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
127+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
128128
import com.oracle.graal.python.nodes.util.ChannelNodes.ReadFromChannelNode;
129129
import com.oracle.graal.python.runtime.PosixResources;
130130
import com.oracle.graal.python.runtime.PythonContext;
@@ -879,7 +879,7 @@ int dupInt(int fd) {
879879

880880
@Specialization(replaces = "dupInt")
881881
int dupGeneric(Object fd,
882-
@Cached CastToJavaIntNode castToJavaIntNode) {
882+
@Cached CastToJavaIntExactNode castToJavaIntNode) {
883883
return getResources().dup(castToJavaIntNode.execute(fd));
884884
}
885885
}
@@ -1033,7 +1033,7 @@ Object lseekGeneric(VirtualFrame frame, Object fd, Object pos, Object how,
10331033
@Shared("channelClassProfile") @Cached("createClassProfile()") ValueProfile channelClassProfile,
10341034
@CachedLibrary("fd") PythonObjectLibrary libFd,
10351035
@CachedLibrary("pos") PythonObjectLibrary libPos,
1036-
@Cached CastToJavaIntNode castHowNode) {
1036+
@Cached CastToJavaIntExactNode castHowNode) {
10371037

10381038
return lseek(frame, libFd.asJavaLong(fd), libPos.asJavaLong(pos), castHowNode.execute(how), channelClassProfile);
10391039
}
@@ -1246,7 +1246,7 @@ Object readFdGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object fd,
12461246
@Shared("profile") @Cached("createClassProfile()") ValueProfile channelClassProfile,
12471247
@Shared("readNode") @Cached ReadFromChannelNode readNode,
12481248
@CachedLibrary("requestedSize") PythonObjectLibrary libSize,
1249-
@Cached CastToJavaIntNode castToIntNode) {
1249+
@Cached CastToJavaIntExactNode castToIntNode) {
12501250
return readLong(frame, castToIntNode.execute(fd), libSize.asJavaLong(requestedSize), channelClassProfile, readNode);
12511251
}
12521252
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
import com.oracle.graal.python.nodes.truffle.PythonTypes;
228228
import com.oracle.graal.python.nodes.util.CannotCastException;
229229
import com.oracle.graal.python.nodes.util.CastToByteNode;
230-
import com.oracle.graal.python.nodes.util.CastToJavaLongNode;
230+
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
231231
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
232232
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
233233
import com.oracle.graal.python.runtime.PythonContext;
@@ -3567,7 +3567,7 @@ abstract static class PyTruffleTraceFree extends PythonBinaryBuiltinNode {
35673567

35683568
@Specialization(limit = "2")
35693569
static int doNativeWrapper(Object ptr, Object sizeObject,
3570-
@Cached(value = "createLossy()", uncached = "getLossyUncached()") CastToJavaLongNode castToJavaLongNode,
3570+
@Cached CastToJavaLongLossyNode castToJavaLongNode,
35713571
@CachedLibrary("ptr") InteropLibrary lib,
35723572
@Cached GetCurrentFrameRef getCurrentFrameRef,
35733573
@CachedContext(PythonLanguage.class) PythonContext context) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
7979
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
8080
import com.oracle.graal.python.nodes.util.CannotCastException;
81-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
81+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
8282
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
8383
import com.oracle.graal.python.runtime.PythonCore;
8484
import com.oracle.graal.python.runtime.exception.PException;
@@ -233,7 +233,7 @@ Object socket(LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @Su
233233

234234
@Specialization(guards = {"isNoValue(family)", "isNoValue(type)", "isNoValue(proto)", "!isNoValue(fileno)"})
235235
Object socket(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused") PNone family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto, Object fileno,
236-
@Cached CastToJavaIntNode cast) {
236+
@Cached CastToJavaIntExactNode cast) {
237237
try {
238238
return createSocketInternal(frame, cls, -1, -1, -1, cast.execute(fileno));
239239
} catch (CannotCastException e) {
@@ -243,7 +243,7 @@ Object socket(VirtualFrame frame, LazyPythonClass cls, @SuppressWarnings("unused
243243

244244
@Specialization(guards = {"!isNoValue(family)", "isNoValue(type)", "isNoValue(proto)", "isNoValue(fileno)"})
245245
Object socket(LazyPythonClass cls, Object family, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno,
246-
@Cached CastToJavaIntNode cast) {
246+
@Cached CastToJavaIntExactNode cast) {
247247
try {
248248
return createSocketInternal(cls, cast.execute(family), PSocket.SOCK_STREAM, 0);
249249
} catch (CannotCastException e) {
@@ -253,7 +253,7 @@ Object socket(LazyPythonClass cls, Object family, @SuppressWarnings("unused") PN
253253

254254
@Specialization(guards = {"!isNoValue(family)", "!isNoValue(type)", "isNoValue(proto)", "isNoValue(fileno)"})
255255
Object socket(LazyPythonClass cls, Object family, Object type, @SuppressWarnings("unused") PNone proto, @SuppressWarnings("unused") PNone fileno,
256-
@Cached CastToJavaIntNode cast) {
256+
@Cached CastToJavaIntExactNode cast) {
257257
try {
258258
return createSocketInternal(cls, cast.execute(family), cast.execute(type), 0);
259259
} catch (CannotCastException e) {
@@ -263,7 +263,7 @@ Object socket(LazyPythonClass cls, Object family, Object type, @SuppressWarnings
263263

264264
@Specialization(guards = {"!isNoValue(family)", "!isNoValue(type)", "!isNoValue(proto)", "isNoValue(fileno)"})
265265
Object socket(LazyPythonClass cls, Object family, Object type, Object proto, @SuppressWarnings("unused") PNone fileno,
266-
@Cached CastToJavaIntNode cast) {
266+
@Cached CastToJavaIntExactNode cast) {
267267
try {
268268
return createSocketInternal(cls, cast.execute(family), cast.execute(type), cast.execute(proto));
269269
} catch (CannotCastException e) {
@@ -273,7 +273,7 @@ Object socket(LazyPythonClass cls, Object family, Object type, Object proto, @Su
273273

274274
@Specialization(guards = {"!isNoValue(family)", "!isNoValue(type)", "!isNoValue(proto)", "!isNoValue(fileno)"})
275275
Object socket(VirtualFrame frame, LazyPythonClass cls, Object family, Object type, Object proto, Object fileno,
276-
@Cached CastToJavaIntNode cast) {
276+
@Cached CastToJavaIntExactNode cast) {
277277
try {
278278
return createSocketInternal(frame, cls, cast.execute(family), cast.execute(type), cast.execute(proto), cast.execute(fileno));
279279
} catch (CannotCastException e) {
@@ -490,11 +490,11 @@ Object getServByPort(int port, String protocolName) {
490490
public abstract static class GetNameInfoNode extends PythonBuiltinNode {
491491
@Specialization
492492
Object getNameInfo(VirtualFrame frame, PTuple sockaddr, Object flagArg,
493-
@Cached CastToJavaIntNode castFlags,
493+
@Cached CastToJavaIntExactNode castFlags,
494494
@Cached SequenceStorageNodes.LenNode lenNode,
495495
@Cached SequenceStorageNodes.GetItemNode getItem,
496496
@Cached CastToJavaStringNode castAddress,
497-
@Cached CastToJavaIntNode castPort) {
497+
@Cached CastToJavaIntExactNode castPort) {
498498
int flags = castFlags.execute(flagArg);
499499
SequenceStorage addr = sockaddr.getSequenceStorage();
500500
int addLen = lenNode.execute(addr);
@@ -548,19 +548,19 @@ public abstract static class GetAddrInfoNode extends PythonBuiltinNode {
548548

549549
@Specialization
550550
Object getAddrInfoPString(PString host, Object port, Object family, Object type, Object proto, Object flags,
551-
@Cached CastToJavaIntNode cast) {
551+
@Cached CastToJavaIntExactNode cast) {
552552
return getAddrInfoString(host.getValue(), port, family, type, proto, flags, cast);
553553
}
554554

555555
@Specialization
556556
Object getAddrInfoNone(@SuppressWarnings("unused") PNone host, Object port, Object family, Object type, Object proto, Object flags,
557-
@Cached CastToJavaIntNode cast) {
557+
@Cached CastToJavaIntExactNode cast) {
558558
return getAddrInfoString("localhost", port, family, type, proto, flags, cast);
559559
}
560560

561561
@Specialization
562562
Object getAddrInfoString(String host, Object port, Object family, Object type, Object proto, Object flags,
563-
@Cached CastToJavaIntNode cast) {
563+
@Cached CastToJavaIntExactNode cast) {
564564
InetAddress[] addresses;
565565
try {
566566
addresses = getAllByName(host);
@@ -786,7 +786,7 @@ static BytesNodes.ToBytesNode createToBytes() {
786786
abstract static class InetPtoNNode extends PythonBinaryBuiltinNode {
787787
@Specialization
788788
PBytes doConvert(@SuppressWarnings("unused") VirtualFrame frame, Object addrFamily, String addr,
789-
@Cached CastToJavaIntNode castToJavaIntNode) {
789+
@Cached CastToJavaIntExactNode castToJavaIntNode) {
790790
return factory().createBytes(aton(castToJavaIntNode.execute(addrFamily), addr));
791791
}
792792

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5555
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
5656
import com.oracle.graal.python.nodes.util.CannotCastException;
57-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
57+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
5858
import com.oracle.graal.python.runtime.PythonCore;
5959
import com.oracle.truffle.api.CompilerAsserts;
6060
import com.oracle.truffle.api.CompilerDirectives;
@@ -375,7 +375,7 @@ private Object castToPInt(Object obj, PythonObjectLibrary asPIntLib) {
375375
throw raise(PythonBuiltinClassType.TypeError, "an integer is required (got type %p)", obj);
376376
}
377377

378-
private int getIntValue(Object oValue, int min, int max, String errorMessage, CastToJavaIntNode toJavaIntExact) {
378+
private int getIntValue(Object oValue, int min, int max, String errorMessage, CastToJavaIntExactNode toJavaIntExact) {
379379
long value;
380380
try {
381381
value = toJavaIntExact.execute(oValue);
@@ -411,7 +411,7 @@ private static String twoDigit(int i) {
411411
return padInt(i, 2, '0');
412412
}
413413

414-
private int[] checkStructtime(PTuple time, PythonObjectLibrary asPIntLib, CastToJavaIntNode toJavaIntExact) {
414+
private int[] checkStructtime(PTuple time, PythonObjectLibrary asPIntLib, CastToJavaIntExactNode toJavaIntExact) {
415415
CompilerAsserts.neverPartOfCompilation();
416416
Object[] date = GetObjectArrayNodeGen.getUncached().execute(time);
417417
if (date.length < 9) {
@@ -489,7 +489,7 @@ private static GregorianCalendar getCalendar(int[] time) {
489489
// This taken from JPython + some switches were corrected to provide the
490490
// same result as CPython
491491
@TruffleBoundary
492-
private String format(String format, PTuple date, PythonObjectLibrary asPIntLib, CastToJavaIntNode toJavaIntExact) {
492+
private String format(String format, PTuple date, PythonObjectLibrary asPIntLib, CastToJavaIntExactNode toJavaIntExact) {
493493

494494
int[] items = checkStructtime(date, asPIntLib, toJavaIntExact);
495495

@@ -686,14 +686,14 @@ private String format(String format, PTuple date, PythonObjectLibrary asPIntLib,
686686
@Specialization
687687
public String formatTime(String format, @SuppressWarnings("unused") PNone time,
688688
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
689-
@Cached CastToJavaIntNode castToInt) {
689+
@Cached CastToJavaIntExactNode castToInt) {
690690
return format(format, factory().createTuple(getTimeStruct(timeSeconds(), true)), lib, castToInt);
691691
}
692692

693693
@Specialization
694694
public String formatTime(String format, PTuple time,
695695
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
696-
@Cached CastToJavaIntNode castToInt) {
696+
@Cached CastToJavaIntExactNode castToInt) {
697697
return format(format, time, lib, castToInt);
698698
}
699699

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
6969
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
7070
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
71-
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
71+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
7272
import com.oracle.graal.python.runtime.PythonCore;
7373
import com.oracle.truffle.api.CompilerDirectives;
7474
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -492,7 +492,7 @@ Object decompress(VirtualFrame frame, InflaterWrapper stream, PIBytesLike pb, in
492492

493493
@Specialization
494494
Object decompress(VirtualFrame frame, InflaterWrapper stream, PIBytesLike pb, long maxLen,
495-
@Cached CastToJavaIntNode castInt) {
495+
@Cached CastToJavaIntExactNode castInt) {
496496
return decompress(frame, stream, pb, castInt.execute(maxLen));
497497
}
498498

0 commit comments

Comments
 (0)