Skip to content

Commit 4a2aeca

Browse files
committed
Remove IndirectCallNode
1 parent 41cfa6f commit 4a2aeca

File tree

79 files changed

+756
-1225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+756
-1225
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
import java.nio.file.InvalidPathException;
4040
import java.util.ArrayList;
4141
import java.util.Arrays;
42+
import java.util.Collections;
4243
import java.util.EnumSet;
4344
import java.util.HashSet;
4445
import java.util.List;
46+
import java.util.Map;
47+
import java.util.WeakHashMap;
4548
import java.util.concurrent.ConcurrentHashMap;
4649
import java.util.concurrent.Semaphore;
4750
import java.util.logging.Level;
@@ -90,6 +93,7 @@
9093
import com.oracle.graal.python.pegparser.sst.StmtTy;
9194
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
9295
import com.oracle.graal.python.runtime.GilNode;
96+
import com.oracle.graal.python.runtime.IndirectCallData;
9397
import com.oracle.graal.python.runtime.PythonContext;
9498
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
9599
import com.oracle.graal.python.runtime.PythonOptions;
@@ -1025,4 +1029,16 @@ protected void exitContext(PythonContext context, ExitMode exitMode, int exitCod
10251029
}
10261030
}
10271031
}
1032+
1033+
private final Map<Node, IndirectCallData> indirectCallDataMap = Collections.synchronizedMap(new WeakHashMap<>());
1034+
1035+
public static IndirectCallData lookupIndirectCallData(Node node) {
1036+
CompilerAsserts.neverPartOfCompilation();
1037+
return get(node).indirectCallDataMap.get(node);
1038+
}
1039+
1040+
public static IndirectCallData createIndirectCallData(Node node) {
1041+
CompilerAsserts.neverPartOfCompilation();
1042+
return get(node).indirectCallDataMap.computeIfAbsent(node, n -> new IndirectCallData(node));
1043+
}
10281044
}

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@
7070
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
7171
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryClinicBuiltinNode;
7272
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
73-
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaiseAndIndirectCall;
73+
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaise;
7474
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
7575
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
76+
import com.oracle.graal.python.runtime.IndirectCallData;
7677
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7778
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7879
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -102,11 +103,12 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
102103
return BinasciiModuleBuiltinsFactory.getFactories();
103104
}
104105

105-
abstract static class AsciiBufferConverter extends ArgumentCastNodeWithRaiseAndIndirectCall {
106+
abstract static class AsciiBufferConverter extends ArgumentCastNodeWithRaise {
106107
@Specialization(guards = "acquireLib.hasBuffer(value)", limit = "getCallSiteInlineCacheMaxDepth()")
107108
Object doObject(VirtualFrame frame, Object value,
109+
@Cached("createFor(this)") IndirectCallData indirectCallData,
108110
@CachedLibrary("value") PythonBufferAcquireLibrary acquireLib) {
109-
return acquireLib.acquireReadonly(value, frame, getContext(), getLanguage(), this);
111+
return acquireLib.acquireReadonly(value, frame, getContext(), getLanguage(), indirectCallData);
110112
}
111113

112114
@ExportLibrary(PythonBufferAccessLibrary.class)
@@ -184,13 +186,14 @@ public static AsciiBufferConverter create() {
184186
abstract static class A2bBase64Node extends PythonUnaryClinicBuiltinNode {
185187
@Specialization(limit = "3")
186188
PBytes doConvert(VirtualFrame frame, Object buffer,
189+
@Cached("createFor(this)") IndirectCallData indirectCallData,
187190
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
188191
@Cached PythonObjectFactory factory) {
189192
try {
190193
ByteSequenceStorage storage = b64decode(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
191194
return factory.createBytes(storage);
192195
} finally {
193-
bufferLib.release(buffer, frame, this);
196+
bufferLib.release(buffer, frame, indirectCallData);
194197
}
195198
}
196199

@@ -259,13 +262,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
259262
abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
260263
@Specialization(limit = "3")
261264
PBytes a2b(VirtualFrame frame, Object buffer,
265+
@Cached("createFor(this)") IndirectCallData indirectCallData,
262266
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
263267
@Cached PythonObjectFactory factory) {
264268
try {
265269
byte[] bytes = a2b(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
266270
return factory.createBytes(bytes);
267271
} finally {
268-
bufferLib.release(buffer, frame, this);
272+
bufferLib.release(buffer, frame, indirectCallData);
269273
}
270274
}
271275

@@ -322,12 +326,13 @@ private PBytes b2a(byte[] data, int lenght, int newline, PythonObjectFactory fac
322326

323327
@Specialization(limit = "3")
324328
PBytes b2aBuffer(VirtualFrame frame, Object buffer, int newline,
329+
@Cached("createFor(this)") IndirectCallData indirectCallData,
325330
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
326331
@Cached PythonObjectFactory factory) {
327332
try {
328333
return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), newline, factory);
329334
} finally {
330-
bufferLib.release(buffer, frame, this);
335+
bufferLib.release(buffer, frame, indirectCallData);
331336
}
332337
}
333338

@@ -346,9 +351,9 @@ abstract static class B2aHexNode extends PythonTernaryClinicBuiltinNode {
346351
@CompilationFinal(dimensions = 1) private static final byte[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
347352

348353
@Specialization(limit = "3")
349-
@SuppressWarnings("truffle-static-method")
350-
PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep,
354+
static PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep,
351355
@Bind("this") Node inliningTarget,
356+
@Cached("createFor(this)") IndirectCallData indirectCallData,
352357
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
353358
@Cached PythonObjectFactory factory,
354359
@Cached PRaiseNode.Lazy raiseNode) {
@@ -359,7 +364,7 @@ PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep,
359364
try {
360365
return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), factory);
361366
} finally {
362-
bufferLib.release(buffer, frame, this);
367+
bufferLib.release(buffer, frame, indirectCallData);
363368
}
364369
}
365370

@@ -387,12 +392,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
387392
abstract static class Crc32Node extends PythonBinaryClinicBuiltinNode {
388393

389394
@Specialization(limit = "3")
390-
long b2a(VirtualFrame frame, Object buffer, long crc,
395+
static long b2a(VirtualFrame frame, Object buffer, long crc,
396+
@Cached("createFor(this)") IndirectCallData indirectCallData,
391397
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
392398
try {
393399
return crc32((int) crc, bufferLib.getInternalOrCopiedByteArray(buffer), 0, bufferLib.getBufferLength(buffer));
394400
} finally {
395-
bufferLib.release(buffer, frame, this);
401+
bufferLib.release(buffer, frame, indirectCallData);
396402
}
397403
}
398404

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
232232
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
233233
import com.oracle.graal.python.nodes.util.SplitArgsNode;
234+
import com.oracle.graal.python.runtime.IndirectCallData;
234235
import com.oracle.graal.python.runtime.PythonContext;
235236
import com.oracle.graal.python.runtime.exception.PException;
236237
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -1653,6 +1654,7 @@ static Object fail(Object cls, Object arg, Object base,
16531654
@Megamorphic
16541655
Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") PNone base,
16551656
@Bind("this") Node inliningTarget,
1657+
@Cached("createFor(this)") IndirectCallData indirectCallData,
16561658
@Cached PyIndexCheckNode indexCheckNode,
16571659
@Cached PyLongCheckExactNode longCheckExact,
16581660
@Exclusive @Cached IsBuiltinClassExactProfile isPrimitiveIntProfile,
@@ -1684,7 +1686,7 @@ Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWar
16841686
if (truncResult == PNone.NO_VALUE) {
16851687
Object buffer;
16861688
try {
1687-
buffer = bufferAcquireLib.acquireReadonly(obj, frame, this);
1689+
buffer = bufferAcquireLib.acquireReadonly(obj, frame, indirectCallData);
16881690
} catch (PException e) {
16891691
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.ARG_MUST_BE_STRING_OR_BYTELIKE_OR_NUMBER, "int()", obj);
16901692
}
@@ -1693,7 +1695,7 @@ Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWar
16931695
return stringToInt(frame, cls, number, 10, obj, inliningTarget, isPrimitiveIntProfile,
16941696
notSimpleDecimalLiteralProfile, invalidValueProfile, bigIntegerProfile, primitiveIntProfile, fullIntProfile, factory, raiseNode);
16951697
} finally {
1696-
bufferLib.release(buffer, frame, this);
1698+
bufferLib.release(buffer, frame, indirectCallData);
16971699
}
16981700
}
16991701
if (isIntegerType(truncResult)) {
@@ -2202,9 +2204,9 @@ static Object strOneArg(VirtualFrame frame, Object cls, Object obj, @SuppressWar
22022204
}
22032205

22042206
@Specialization(guards = {"!needsNativeAllocationNode.execute(inliningTarget, cls)", "!isNoValue(encoding) || !isNoValue(errors)"}, limit = "3")
2205-
@SuppressWarnings("truffle-static-method")
2206-
Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encoding, Object errors,
2207+
static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encoding, Object errors,
22072208
@Bind("this") Node inliningTarget,
2209+
@Cached("createFor(this)") IndirectCallData indirectCallData,
22082210
@SuppressWarnings("unused") @Exclusive @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode,
22092211
@Exclusive @Cached IsBuiltinClassExactProfile isPrimitiveProfile,
22102212
@Exclusive @Cached InlinedConditionProfile isStringProfile,
@@ -2216,7 +2218,7 @@ Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encoding, Obj
22162218
@Cached PRaiseNode.Lazy raiseNode) {
22172219
Object buffer;
22182220
try {
2219-
buffer = acquireLib.acquireReadonly(obj, frame, this);
2221+
buffer = acquireLib.acquireReadonly(obj, frame, indirectCallData);
22202222
} catch (PException e) {
22212223
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.NEED_BYTELIKE_OBJ, obj);
22222224
}
@@ -2233,7 +2235,7 @@ Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encoding, Obj
22332235
}
22342236
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.P_S_RETURNED_NON_STRING, bytesObj, "decode", result);
22352237
} finally {
2236-
bufferLib.release(buffer, frame, this);
2238+
bufferLib.release(buffer, frame, indirectCallData);
22372239
}
22382240
}
22392241

0 commit comments

Comments
 (0)