Skip to content

Commit a55dac3

Browse files
committed
[GR-21867] Clean up performance warnings
PullRequest: graalpython/1164
2 parents 5e37557 + 9d14227 commit a55dac3

Some content is hidden

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

44 files changed

+699
-481
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public Object bytearray(Object cls, @SuppressWarnings("unused") PNone source, @S
268268

269269
@Specialization(guards = {"lib.canBeIndex(capObj)", "isNoValue(encoding)", "isNoValue(errors)"})
270270
public Object bytearray(VirtualFrame frame, Object cls, Object capObj, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
271-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
271+
@SuppressWarnings("unused") @CachedLibrary(limit = "5") PythonObjectLibrary lib) {
272272
int cap = lib.asSizeWithState(capObj, PArguments.getThreadState(frame));
273273
return create(cls, BytesUtils.fromSize(getCore(), cap));
274274
}
@@ -302,13 +302,13 @@ public Object bytearray(Object cls, PByteArray iterable, @SuppressWarnings("unus
302302
return create(cls, (byte[]) ((ByteSequenceStorage) iterable.getSequenceStorage()).getCopyOfInternalArrayObject());
303303
}
304304

305-
@Specialization(guards = {"!lib.canBeIndex(iterable)", "!isNoValue(iterable)", "isNoValue(encoding)", "isNoValue(errors)"}, limit = "1")
305+
@Specialization(guards = {"!lib.canBeIndex(iterable)", "!isNoValue(iterable)", "isNoValue(encoding)", "isNoValue(errors)"})
306306
public Object bytearray(VirtualFrame frame, Object cls, Object iterable, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
307307
@Cached("create()") GetIteratorNode getIteratorNode,
308308
@Cached("create()") GetNextNode getNextNode,
309309
@Cached("create()") IsBuiltinClassProfile stopIterationProfile,
310310
@Cached("create()") CastToByteNode castToByteNode,
311-
@SuppressWarnings("unused") @CachedLibrary("iterable") PythonObjectLibrary lib) {
311+
@SuppressWarnings("unused") @CachedLibrary(limit = "3") PythonObjectLibrary lib) {
312312

313313
Object it = getIteratorNode.executeWith(frame, iterable);
314314
byte[] arr = new byte[16];
@@ -887,7 +887,7 @@ public PythonObject reversed(Object cls, String value) {
887887
return factory().createStringReverseIterator(cls, value);
888888
}
889889

890-
@Specialization(guards = {"!isString(sequence)", "!isPRange(sequence)"}, limit = "3")
890+
@Specialization(guards = {"!isString(sequence)", "!isPRange(sequence)"}, limit = "4")
891891
public Object reversed(VirtualFrame frame, Object cls, Object sequence,
892892
@CachedLibrary("sequence") PythonObjectLibrary lib,
893893
@Cached("create(__REVERSED__)") LookupSpecialMethodNode reversedNode,
@@ -1602,7 +1602,7 @@ Object fail(Object cls, Object arg, Object base) {
16021602
throw raise(TypeError, ErrorMessages.INT_CANT_CONVERT_STRING_WITH_EXPL_BASE);
16031603
}
16041604

1605-
@Specialization(guards = {"isNoValue(base)", "!isNoValue(obj)", "!isHandledType(obj)"}, limit = "2")
1605+
@Specialization(guards = {"isNoValue(base)", "!isNoValue(obj)", "!isHandledType(obj)"}, limit = "5")
16061606
Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") PNone base,
16071607
@CachedLibrary("obj") PythonObjectLibrary lib) {
16081608
// This method (together with callInt and callIndex) reflects the logic of PyNumber_Long
@@ -3105,20 +3105,19 @@ protected static boolean isPFrame(Object obj) {
31053105
public abstract static class CodeTypeNode extends PythonBuiltinNode {
31063106

31073107
// limit is 2 because we expect PBytes or String
3108-
@Specialization(guards = {"codestringBufferLib.isBuffer(codestring)", "lnotabBufferLib.isBuffer(lnotab)"}, limit = "2", rewriteOn = UnsupportedMessageException.class)
3108+
@Specialization(guards = {"bufferLib.isBuffer(codestring)", "bufferLib.isBuffer(lnotab)"}, rewriteOn = UnsupportedMessageException.class)
31093109
Object call(VirtualFrame frame, Object cls, int argcount,
31103110
int posonlyargcount, int kwonlyargcount,
31113111
int nlocals, int stacksize, int flags,
31123112
Object codestring, PTuple constants, PTuple names,
31133113
PTuple varnames, Object filename, Object name,
31143114
int firstlineno, Object lnotab,
31153115
PTuple freevars, PTuple cellvars,
3116-
@CachedLibrary("codestring") PythonObjectLibrary codestringBufferLib,
3117-
@CachedLibrary("lnotab") PythonObjectLibrary lnotabBufferLib,
3116+
@CachedLibrary(limit = "2") PythonObjectLibrary bufferLib,
31183117
@Cached CodeNodes.CreateCodeNode createCodeNode,
31193118
@Cached GetObjectArrayNode getObjectArrayNode) throws UnsupportedMessageException {
3120-
byte[] codeBytes = codestringBufferLib.getBufferBytes(codestring);
3121-
byte[] lnotabBytes = lnotabBufferLib.getBufferBytes(lnotab);
3119+
byte[] codeBytes = bufferLib.getBufferBytes(codestring);
3120+
byte[] lnotabBytes = bufferLib.getBufferBytes(lnotab);
31223121

31233122
Object[] constantsArr = getObjectArrayNode.execute(constants);
31243123
Object[] namesArr = getObjectArrayNode.execute(names);
@@ -3134,21 +3133,20 @@ Object call(VirtualFrame frame, Object cls, int argcount,
31343133
lnotabBytes);
31353134
}
31363135

3137-
@Specialization(guards = {"codestringBufferLib.isBuffer(codestring)", "lnotabBufferLib.isBuffer(lnotab)"}, limit = "2", rewriteOn = UnsupportedMessageException.class)
3136+
@Specialization(guards = {"bufferLib.isBuffer(codestring)", "bufferLib.isBuffer(lnotab)"}, rewriteOn = UnsupportedMessageException.class)
31383137
Object call(VirtualFrame frame, Object cls, Object argcount,
31393138
int posonlyargcount, Object kwonlyargcount,
31403139
Object nlocals, Object stacksize, Object flags,
31413140
Object codestring, PTuple constants, PTuple names,
31423141
PTuple varnames, Object filename, Object name,
31433142
Object firstlineno, Object lnotab,
31443143
PTuple freevars, PTuple cellvars,
3145-
@CachedLibrary("codestring") PythonObjectLibrary codestringBufferLib,
3146-
@CachedLibrary("lnotab") PythonObjectLibrary lnotabBufferLib,
3144+
@CachedLibrary(limit = "2") PythonObjectLibrary bufferLib,
31473145
@CachedLibrary(limit = "2") PythonObjectLibrary objectLibrary,
31483146
@Cached CodeNodes.CreateCodeNode createCodeNode,
31493147
@Cached GetObjectArrayNode getObjectArrayNode) throws UnsupportedMessageException {
3150-
byte[] codeBytes = codestringBufferLib.getBufferBytes(codestring);
3151-
byte[] lnotabBytes = lnotabBufferLib.getBufferBytes(lnotab);
3148+
byte[] codeBytes = bufferLib.getBufferBytes(codestring);
3149+
byte[] lnotabBytes = bufferLib.getBufferBytes(lnotab);
31523150

31533151
Object[] constantsArr = getObjectArrayNode.execute(constants);
31543152
Object[] namesArr = getObjectArrayNode.execute(names);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ public Object iter(Object callable, Object sentinel) {
13191319
@GenerateNodeFactory
13201320
@ReportPolymorphism
13211321
public abstract static class LenNode extends PythonUnaryBuiltinNode {
1322-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
1322+
@Specialization(limit = "6")
13231323
public int len(VirtualFrame frame, Object obj,
13241324
@CachedLibrary("obj") PythonObjectLibrary lib) {
13251325
return lib.lengthWithFrame(obj, frame);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.oracle.graal.python.builtins.objects.common.HashingStorage.DictEntry;
5757
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
5858
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
59+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
5960
import com.oracle.graal.python.builtins.objects.complex.PComplex;
6061
import com.oracle.graal.python.builtins.objects.dict.PDict;
6162
import com.oracle.graal.python.builtins.objects.floats.PFloat;
@@ -402,9 +403,10 @@ void handlePTuple(VirtualFrame frame, PTuple t, int version, DataOutputStream bu
402403
}
403404

404405
@Specialization
405-
void handlePList(VirtualFrame frame, PList l, int version, DataOutputStream buffer) {
406+
void handlePList(VirtualFrame frame, PList l, int version, DataOutputStream buffer,
407+
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getArray) {
406408
writeByte(TYPE_LIST, version, buffer);
407-
Object[] items = l.getSequenceStorage().getInternalArray();
409+
Object[] items = getArray.execute(l.getSequenceStorage());
408410
writeInt(items.length, version, buffer);
409411
for (int i = 0; i < items.length; i++) {
410412
getRecursiveNode().execute(frame, items[i], version, buffer);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,19 @@
137137
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
138138
import com.oracle.graal.python.util.FileDeleteShutdownHook;
139139
import com.oracle.truffle.api.CompilerDirectives;
140-
import com.oracle.truffle.api.TruffleFile;
141-
import com.oracle.truffle.api.TruffleLogger;
142140
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
143141
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
142+
import com.oracle.truffle.api.TruffleFile;
144143
import com.oracle.truffle.api.TruffleLanguage.Env;
144+
import com.oracle.truffle.api.TruffleLogger;
145145
import com.oracle.truffle.api.dsl.Cached;
146+
import com.oracle.truffle.api.dsl.Cached.Shared;
146147
import com.oracle.truffle.api.dsl.Fallback;
147148
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
148149
import com.oracle.truffle.api.dsl.ImportStatic;
149150
import com.oracle.truffle.api.dsl.NodeFactory;
150151
import com.oracle.truffle.api.dsl.Specialization;
151152
import com.oracle.truffle.api.dsl.TypeSystemReference;
152-
import com.oracle.truffle.api.dsl.Cached.Shared;
153153
import com.oracle.truffle.api.frame.VirtualFrame;
154154
import com.oracle.truffle.api.library.CachedLibrary;
155155
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -803,7 +803,7 @@ public static StatNode create() {
803803
@GenerateNodeFactory
804804
@TypeSystemReference(PythonArithmeticTypes.class)
805805
public abstract static class ListdirNode extends PythonBuiltinNode {
806-
@Specialization(limit = "1")
806+
@Specialization(limit = "3")
807807
Object listdir(VirtualFrame frame, Object pathArg,
808808
@CachedLibrary("pathArg") PythonObjectLibrary lib) {
809809
String path = lib.asPath(pathArg);
@@ -918,13 +918,13 @@ int dupOvf(VirtualFrame frame, PInt fd, PInt fd2) {
918918
@TypeSystemReference(PythonArithmeticTypes.class)
919919
public abstract static class OpenNode extends PythonFileNode {
920920

921-
@Specialization(guards = {"isNoValue(mode)", "isNoValue(dir_fd)"}, limit = "1")
921+
@Specialization(guards = {"isNoValue(mode)", "isNoValue(dir_fd)"}, limit = "3")
922922
Object open(VirtualFrame frame, Object pathname, long flags, @SuppressWarnings("unused") PNone mode, PNone dir_fd,
923923
@CachedLibrary("pathname") PythonObjectLibrary lib) {
924924
return openMode(frame, pathname, flags, 0777, dir_fd, lib);
925925
}
926926

927-
@Specialization(guards = {"isNoValue(dir_fd)"}, limit = "1")
927+
@Specialization(guards = {"isNoValue(dir_fd)"}, limit = "3")
928928
Object openMode(VirtualFrame frame, Object pathArg, long flags, long fileMode, @SuppressWarnings("unused") PNone dir_fd,
929929
@CachedLibrary("pathArg") PythonObjectLibrary lib) {
930930
String pathname = lib.asPath(pathArg);
@@ -1085,7 +1085,7 @@ private static void closeChannel(Channel channel) throws IOException {
10851085
@TypeSystemReference(PythonArithmeticTypes.class)
10861086
public abstract static class UnlinkNode extends PythonFileNode {
10871087

1088-
@Specialization(limit = "1")
1088+
@Specialization(limit = "3")
10891089
Object unlink(VirtualFrame frame, Object pathArg,
10901090
@CachedLibrary("pathArg") PythonObjectLibrary lib) {
10911091
String path = lib.asPath(pathArg);
@@ -1113,13 +1113,13 @@ public abstract static class RmdirNode extends UnlinkNode {
11131113
@TypeSystemReference(PythonArithmeticTypes.class)
11141114
public abstract static class MkdirNode extends PythonFileNode {
11151115

1116-
@Specialization(limit = "1")
1116+
@Specialization(limit = "3")
11171117
Object mkdir(VirtualFrame frame, Object path, @SuppressWarnings("unused") PNone mode, PNone dirFd,
11181118
@CachedLibrary("path") PythonObjectLibrary lib) {
11191119
return mkdirMode(frame, path, 511, dirFd, lib);
11201120
}
11211121

1122-
@Specialization(limit = "1")
1122+
@Specialization(limit = "3")
11231123
Object mkdirMode(VirtualFrame frame, Object pathArg, @SuppressWarnings("unused") int mode, @SuppressWarnings("unused") PNone dirFd,
11241124
@CachedLibrary("pathArg") PythonObjectLibrary lib) {
11251125
String path = lib.asPath(pathArg);

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.builtins.objects.PNone;
6060
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
6161
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
62+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
6263
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
6364
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.ErrorAndMessagePair;
6465
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -101,18 +102,18 @@ abstract static class ForkExecNode extends PythonBuiltinNode {
101102
@Child private BytesNodes.ToBytesNode toBytes = BytesNodes.ToBytesNode.create();
102103

103104
@Specialization
104-
@SuppressWarnings("try")
105105
int forkExec(VirtualFrame frame, PList args, @SuppressWarnings("unused") PList execList, @SuppressWarnings("unused") boolean closeFds,
106106
@SuppressWarnings("unused") PList fdsToKeep, String cwd, PList env,
107107
int p2cread, int p2cwrite, int c2pread, int c2pwrite,
108108
int errread, int errwrite, @SuppressWarnings("unused") int errpipe_read, int errpipe_write,
109-
@SuppressWarnings("unused") boolean restore_signals, @SuppressWarnings("unused") boolean call_setsid, @SuppressWarnings("unused") PNone preexec_fn) {
109+
@SuppressWarnings("unused") boolean restore_signals, @SuppressWarnings("unused") boolean call_setsid, @SuppressWarnings("unused") PNone preexec_fn,
110+
@Cached SequenceStorageNodes.CopyInternalArrayNode copy) {
110111

111112
PythonContext context = getContext();
112113
Object state = IndirectCallContext.enter(frame, context, this);
113114
try {
114115
return forkExec(args, execList, closeFds, fdsToKeep, cwd, env, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, errpipe_read, errpipe_write, restore_signals, call_setsid,
115-
preexec_fn);
116+
preexec_fn, copy);
116117
} finally {
117118
IndirectCallContext.exit(frame, context, state);
118119
}
@@ -123,15 +124,16 @@ private synchronized int forkExec(PList args, @SuppressWarnings("unused") PList
123124
@SuppressWarnings("unused") PList fdsToKeep, String cwd, PList env,
124125
int p2cread, int p2cwrite, int c2pread, int c2pwrite,
125126
int errread, int errwrite, @SuppressWarnings("unused") int errpipe_read, int errpipe_write,
126-
@SuppressWarnings("unused") boolean restore_signals, @SuppressWarnings("unused") boolean call_setsid, @SuppressWarnings("unused") PNone preexec_fn) {
127+
@SuppressWarnings("unused") boolean restore_signals, @SuppressWarnings("unused") boolean call_setsid, @SuppressWarnings("unused") PNone preexec_fn,
128+
@Cached SequenceStorageNodes.CopyInternalArrayNode copy) {
127129
PythonContext context = getContext();
128130
PosixResources resources = context.getResources();
129131
if (!context.isExecutableAccessAllowed()) {
130132
return -1;
131133
}
132134

133135
ArrayList<String> argStrings = new ArrayList<>();
134-
Object[] copyOfInternalArray = args.getSequenceStorage().getCopyOfInternalArray();
136+
Object[] copyOfInternalArray = copy.execute(args.getSequenceStorage());
135137
for (Object o : copyOfInternalArray) {
136138
if (o instanceof String) {
137139
argStrings.add((String) o);
@@ -249,6 +251,7 @@ int forkExecDefault(VirtualFrame frame, Object args, Object executable_list, Obj
249251
@Cached CastToListNode castFdsToKeep,
250252
@Cached CastToJavaStringNode castCwd,
251253
@Cached CastToListNode castEnv,
254+
@Cached SequenceStorageNodes.CopyInternalArrayNode copy,
252255
@CachedLibrary(limit = "3") PythonObjectLibrary lib) {
253256

254257
String actualCwd;
@@ -281,7 +284,7 @@ int forkExecDefault(VirtualFrame frame, Object args, Object executable_list, Obj
281284
lib.asSizeWithState(errpipe_read, PArguments.getThreadState(frame)),
282285
lib.asSizeWithState(errpipe_write, PArguments.getThreadState(frame)),
283286
lib.isTrueWithState(restore_signals, PArguments.getThreadState(frame)),
284-
lib.isTrueWithState(call_setsid, PArguments.getThreadState(frame)), preexec_fn);
287+
lib.isTrueWithState(call_setsid, PArguments.getThreadState(frame)), preexec_fn, copy);
285288
}
286289
}
287290
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
import com.oracle.graal.python.builtins.objects.PNone;
5454
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
5555
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
56-
import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike;
56+
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
57+
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
5758
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
5859
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
5960
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
@@ -144,7 +145,13 @@ Object run(String str) {
144145
}
145146

146147
@Specialization
147-
Object run(PIBytesLike str) {
148+
Object run(PBytes str) {
149+
byte[] bytes = doBytes(getToByteArrayNode().execute(str.getSequenceStorage()));
150+
return factory().createByteArray(bytes);
151+
}
152+
153+
@Specialization
154+
Object run(PByteArray str) {
148155
byte[] bytes = doBytes(getToByteArrayNode().execute(str.getSequenceStorage()));
149156
return factory().createByteArray(bytes);
150157
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,6 @@ public Object getLazyPythonClass() {
602602
throw new AbstractMethodError(getClass().getCanonicalName());
603603
}
604604

605-
public Object getInternalLazyPythonClass() {
606-
CompilerDirectives.bailout("Abstract method");
607-
throw new AbstractMethodError(getClass().getCanonicalName());
608-
}
609-
610605
@ExportMessage
611606
public boolean isInstantiable(
612607
@Cached TypeNodes.IsTypeNode isTypeNode) {

0 commit comments

Comments
 (0)