Skip to content

Commit a46f13f

Browse files
committed
Resolve some DSL warnings in the zlib module
1 parent db7ab8f commit a46f13f

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import com.oracle.graal.python.util.PythonUtils;
9393
import com.oracle.truffle.api.CompilerDirectives;
9494
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
95+
import com.oracle.truffle.api.dsl.Bind;
9596
import com.oracle.truffle.api.dsl.Cached;
9697
import com.oracle.truffle.api.dsl.Cached.Shared;
9798
import com.oracle.truffle.api.dsl.Fallback;
@@ -104,7 +105,8 @@
104105
import com.oracle.truffle.api.frame.VirtualFrame;
105106
import com.oracle.truffle.api.interop.InteropLibrary;
106107
import com.oracle.truffle.api.interop.UnsupportedMessageException;
107-
import com.oracle.truffle.api.profiles.ConditionProfile;
108+
import com.oracle.truffle.api.nodes.Node;
109+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
108110
import com.oracle.truffle.api.strings.TruffleString;
109111

110112
@CoreFunctions(defineModule = ZLibModuleBuiltins.J_ZLIB)
@@ -330,7 +332,7 @@ protected boolean useNative() {
330332

331333
@Specialization
332334
long doitNone(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
333-
@Cached ToBytesNode toBytesNode) {
335+
@Shared("bb") @Cached ToBytesNode toBytesNode) {
334336
return doCRC32(toBytesNode.execute(frame, data));
335337
}
336338

@@ -344,7 +346,7 @@ static long doCRC32(byte[] data) {
344346
@Specialization(guards = "useNative()")
345347
long doNativeBytes(PBytesLike data, int value,
346348
@Shared("b") @Cached SequenceStorageNodes.GetInternalBytesNode toBytes,
347-
@Cached NativeLibrary.InvokeNativeFunction invoke) {
349+
@Shared @Cached NativeLibrary.InvokeNativeFunction invoke) {
348350
byte[] bytes = toBytes.execute(data);
349351
int len = data.getSequenceStorage().length();
350352
return nativeCrc32(bytes, len, value, invoke);
@@ -353,7 +355,7 @@ long doNativeBytes(PBytesLike data, int value,
353355
@Specialization(guards = {"useNative()", "!isBytes(data)"})
354356
long doNativeObject(VirtualFrame frame, Object data, int value,
355357
@Shared("bb") @Cached ToBytesNode toBytesNode,
356-
@Cached NativeLibrary.InvokeNativeFunction invoke) {
358+
@Shared @Cached NativeLibrary.InvokeNativeFunction invoke) {
357359
byte[] bytes = toBytesNode.execute(frame, data);
358360
return nativeCrc32(bytes, bytes.length, value, invoke);
359361
}
@@ -421,7 +423,7 @@ private static long doAdler32(byte[] bytes) {
421423
@Specialization(guards = "useNative()")
422424
long doNativeBytes(PBytesLike data, int value,
423425
@Shared("b") @Cached SequenceStorageNodes.GetInternalBytesNode toBytes,
424-
@Cached NativeLibrary.InvokeNativeFunction invoke) {
426+
@Shared @Cached NativeLibrary.InvokeNativeFunction invoke) {
425427
byte[] bytes = toBytes.execute(data);
426428
int len = data.getSequenceStorage().length();
427429
return nativeAdler32(bytes, len, value, PythonContext.get(this), invoke);
@@ -430,7 +432,7 @@ long doNativeBytes(PBytesLike data, int value,
430432
@Specialization(guards = {"useNative()", "!isBytes(data)"})
431433
long doNativeObject(VirtualFrame frame, Object data, int value,
432434
@Shared("bb") @Cached ToBytesNode toBytesNode,
433-
@Cached NativeLibrary.InvokeNativeFunction invoke) {
435+
@Shared @Cached NativeLibrary.InvokeNativeFunction invoke) {
434436
byte[] bytes = toBytesNode.execute(frame, data);
435437
return nativeAdler32(bytes, bytes.length, value, PythonContext.get(this), invoke);
436438
}
@@ -494,7 +496,7 @@ protected boolean useNative() {
494496
@Specialization(guards = {"useNative()"})
495497
PBytes doNativeBytes(PBytesLike data, int level,
496498
@Cached SequenceStorageNodes.GetInternalBytesNode toByte,
497-
@Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
499+
@Shared @Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
498500
byte[] bytes = toByte.execute(data);
499501
int len = data.getSequenceStorage().length();
500502
byte[] resultArray = nativeCompress.execute(bytes, len, level, getContext());
@@ -504,16 +506,17 @@ PBytes doNativeBytes(PBytesLike data, int level,
504506
@Specialization(guards = {"useNative()", "!isBytes(data)"})
505507
PBytes doNativeObject(VirtualFrame frame, Object data, int level,
506508
@Shared("bb") @Cached ToBytesNode toBytesNode,
507-
@Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
509+
@Shared @Cached ZlibNodes.ZlibNativeCompress nativeCompress) {
508510
byte[] bytes = toBytesNode.execute(frame, data);
509511
return factory().createBytes(nativeCompress.execute(bytes, bytes.length, level, getContext()));
510512
}
511513

512514
@Specialization(guards = {"!useNative()"})
513515
PBytes doJava(VirtualFrame frame, Object data, int level,
516+
@Bind("this") Node inliningTarget,
514517
@Shared("bb") @Cached ToBytesNode toBytesNode,
515-
@Cached ConditionProfile wrongLevelProfile) {
516-
if (wrongLevelProfile.profile(level < -1 || 9 < level)) {
518+
@Cached InlinedConditionProfile wrongLevelProfile) {
519+
if (wrongLevelProfile.profile(inliningTarget, level < -1 || 9 < level)) {
517520
throw raise(ZLibError, ErrorMessages.BAD_COMPRESSION_LEVEL);
518521
}
519522
byte[] array = toBytesNode.execute(frame, data);
@@ -562,7 +565,7 @@ protected boolean useNative() {
562565
@Specialization(guards = {"bufsize >= 0", "useNative()"})
563566
PBytes doNativeBytes(PBytesLike data, int wbits, int bufsize,
564567
@Cached SequenceStorageNodes.GetInternalBytesNode toByte,
565-
@Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
568+
@Shared @Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
566569
byte[] bytes = toByte.execute(data);
567570
int len = data.getSequenceStorage().length();
568571
return factory().createBytes(nativeDecompress.execute(bytes, len, wbits, bufsize, PythonContext.get(this)));
@@ -571,7 +574,7 @@ PBytes doNativeBytes(PBytesLike data, int wbits, int bufsize,
571574
@Specialization(guards = {"bufsize >= 0", "useNative()", "!isBytes(data)"})
572575
PBytes doNativeObject(VirtualFrame frame, Object data, int wbits, int bufsize,
573576
@Shared("bb") @Cached ToBytesNode toBytesNode,
574-
@Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
577+
@Shared @Cached ZlibNodes.ZlibNativeDecompress nativeDecompress) {
575578
byte[] bytes = toBytesNode.execute(frame, data);
576579
int len = bytes.length;
577580
return factory().createBytes(nativeDecompress.execute(bytes, len, wbits, bufsize, PythonContext.get(this)));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZlibNodes.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@
9090
import com.oracle.truffle.api.CompilerDirectives;
9191
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
9292
import com.oracle.truffle.api.dsl.Cached;
93+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
9394
import com.oracle.truffle.api.dsl.Cached.Shared;
9495
import com.oracle.truffle.api.dsl.Fallback;
9596
import com.oracle.truffle.api.dsl.GenerateUncached;
9697
import com.oracle.truffle.api.dsl.ImportStatic;
9798
import com.oracle.truffle.api.dsl.Specialization;
9899
import com.oracle.truffle.api.nodes.Node;
99-
import com.oracle.truffle.api.profiles.ConditionProfile;
100100
import com.oracle.truffle.api.strings.TruffleString;
101101

102102
public class ZlibNodes {
@@ -127,12 +127,11 @@ public abstract static class ZlibNativeCompressObj extends PNodeWithContext {
127127
byte[] nativeCompress(ZLibCompObject.NativeZlibCompObject self, PythonContext context, byte[] bytes, int len,
128128
@Cached NativeLibrary.InvokeNativeFunction compressObj,
129129
@Cached GetNativeBufferNode getBuffer,
130-
@Cached ZlibNativeErrorHandling errorHandling,
131-
@Cached ConditionProfile errProfile) {
130+
@Cached ZlibNativeErrorHandling errorHandling) {
132131
NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
133132
self.lastInput = context.getEnv().asGuestValue(bytes);
134133
int err = zlibSupport.compressObj(self.getZst(), self.lastInput, len, DEF_BUF_SIZE, compressObj);
135-
if (errProfile.profile(err != Z_OK)) {
134+
if (err != Z_OK) {
136135
errorHandling.execute(self.getZst(), err, zlibSupport, false);
137136
}
138137
return getBuffer.getOutputBuffer(self.getZst(), context);
@@ -150,13 +149,12 @@ byte[] nativeCompress(byte[] bytes, int len, int level, PythonContext context,
150149
@Cached NativeLibrary.InvokeNativeFunction deallocateStream,
151150
@Cached NativeLibrary.InvokeNativeFunction deflateOffHeap,
152151
@Cached GetNativeBufferNode getBuffer,
153-
@Cached ZlibNativeErrorHandling errorHandling,
154-
@Cached ConditionProfile errProfile) {
152+
@Cached ZlibNativeErrorHandling errorHandling) {
155153
NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
156154
Object in = context.getEnv().asGuestValue(bytes);
157155
Object zst = zlibSupport.createStream(createStream);
158156
int err = zlibSupport.deflateOffHeap(zst, in, len, DEF_BUF_SIZE, level, deflateOffHeap);
159-
if (errProfile.profile(err != Z_OK)) {
157+
if (err != Z_OK) {
160158
errorHandling.execute(zst, err, zlibSupport, true);
161159
}
162160
byte[] resultArray = getBuffer.getOutputBuffer(zst, context);
@@ -173,12 +171,11 @@ public abstract static class ZlibNativeDecompressObj extends PNodeWithContext {
173171
byte[] nativeDecompress(ZLibCompObject.NativeZlibCompObject self, PythonContext context, byte[] bytes, int len, int maxLength,
174172
@Cached NativeLibrary.InvokeNativeFunction decompressObj,
175173
@Cached GetNativeBufferNode getBuffer,
176-
@Cached ZlibNativeErrorHandling errorHandling,
177-
@Cached ConditionProfile errProfile) {
174+
@Cached ZlibNativeErrorHandling errorHandling) {
178175
NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
179176
Object in = context.getEnv().asGuestValue(bytes);
180177
int err = zlibSupport.decompressObj(self.getZst(), in, len, DEF_BUF_SIZE, maxLength, decompressObj);
181-
if (errProfile.profile(err != Z_OK)) {
178+
if (err != Z_OK) {
182179
errorHandling.execute(self.getZst(), err, zlibSupport, false);
183180
}
184181
return getBuffer.getOutputBuffer(self.getZst(), context);
@@ -196,13 +193,12 @@ byte[] nativeCompress(byte[] bytes, int len, int wbits, int bufsize, PythonConte
196193
@Cached NativeLibrary.InvokeNativeFunction deallocateStream,
197194
@Cached NativeLibrary.InvokeNativeFunction inflateOffHeap,
198195
@Cached GetNativeBufferNode getBuffer,
199-
@Cached ZlibNativeErrorHandling errorHandling,
200-
@Cached ConditionProfile errProfile) {
196+
@Cached ZlibNativeErrorHandling errorHandling) {
201197
NFIZlibSupport zlibSupport = context.getNFIZlibSupport();
202198
Object zst = zlibSupport.createStream(createStream);
203199
Object in = context.getEnv().asGuestValue(bytes);
204200
int err = zlibSupport.inflateOffHeap(zst, in, len, bufsize, wbits, inflateOffHeap);
205-
if (errProfile.profile(err != Z_OK)) {
201+
if (err != Z_OK) {
206202
errorHandling.execute(zst, err, zlibSupport, true);
207203
}
208204
byte[] resultArray = getBuffer.getOutputBuffer(zst, context);
@@ -247,8 +243,8 @@ static void doVersionError(Object zst, int err, TruffleString msg, NFIZlibSuppor
247243
static void doError(Object zst, int err, TruffleString msg, NFIZlibSupport zlibSupport, boolean deallocate,
248244
@Shared("r") @Cached PRaiseNode raise,
249245
@Shared("d") @Cached NativeLibrary.InvokeNativeFunction deallocateStream,
250-
@Cached NativeLibrary.InvokeNativeFunction hasStreamErrorMsg,
251-
@Cached NativeLibrary.InvokeNativeFunction getStreamErrorMsg) {
246+
@Exclusive @Cached NativeLibrary.InvokeNativeFunction hasStreamErrorMsg,
247+
@Exclusive @Cached NativeLibrary.InvokeNativeFunction getStreamErrorMsg) {
252248
TruffleString zmsg = null;
253249
if (zlibSupport.hasStreamErrorMsg(zst, hasStreamErrorMsg) == 1) {
254250
zmsg = zlibSupport.getStreamErrorMsg(zst, getStreamErrorMsg);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3939
* SOFTWARE.
4040
*/
41-
@SuppressPackageWarnings({"truffle-inlining", "truffle-sharing", "truffle-limit", "deprecated", "truffle-static-method"})
41+
@SuppressPackageWarnings({"truffle-inlining"})
4242
package com.oracle.graal.python.builtins.modules.zlib;
4343

4444
import com.oracle.truffle.api.dsl.SuppressPackageWarnings;

0 commit comments

Comments
 (0)