92
92
import com .oracle .graal .python .util .PythonUtils ;
93
93
import com .oracle .truffle .api .CompilerDirectives ;
94
94
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
95
+ import com .oracle .truffle .api .dsl .Bind ;
95
96
import com .oracle .truffle .api .dsl .Cached ;
96
97
import com .oracle .truffle .api .dsl .Cached .Shared ;
97
98
import com .oracle .truffle .api .dsl .Fallback ;
104
105
import com .oracle .truffle .api .frame .VirtualFrame ;
105
106
import com .oracle .truffle .api .interop .InteropLibrary ;
106
107
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 ;
108
110
import com .oracle .truffle .api .strings .TruffleString ;
109
111
110
112
@ CoreFunctions (defineModule = ZLibModuleBuiltins .J_ZLIB )
@@ -330,7 +332,7 @@ protected boolean useNative() {
330
332
331
333
@ Specialization
332
334
long doitNone (VirtualFrame frame , Object data , @ SuppressWarnings ("unused" ) PNone value ,
333
- @ Cached ToBytesNode toBytesNode ) {
335
+ @ Shared ( "bb" ) @ Cached ToBytesNode toBytesNode ) {
334
336
return doCRC32 (toBytesNode .execute (frame , data ));
335
337
}
336
338
@@ -344,7 +346,7 @@ static long doCRC32(byte[] data) {
344
346
@ Specialization (guards = "useNative()" )
345
347
long doNativeBytes (PBytesLike data , int value ,
346
348
@ Shared ("b" ) @ Cached SequenceStorageNodes .GetInternalBytesNode toBytes ,
347
- @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
349
+ @ Shared @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
348
350
byte [] bytes = toBytes .execute (data );
349
351
int len = data .getSequenceStorage ().length ();
350
352
return nativeCrc32 (bytes , len , value , invoke );
@@ -353,7 +355,7 @@ long doNativeBytes(PBytesLike data, int value,
353
355
@ Specialization (guards = {"useNative()" , "!isBytes(data)" })
354
356
long doNativeObject (VirtualFrame frame , Object data , int value ,
355
357
@ Shared ("bb" ) @ Cached ToBytesNode toBytesNode ,
356
- @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
358
+ @ Shared @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
357
359
byte [] bytes = toBytesNode .execute (frame , data );
358
360
return nativeCrc32 (bytes , bytes .length , value , invoke );
359
361
}
@@ -421,7 +423,7 @@ private static long doAdler32(byte[] bytes) {
421
423
@ Specialization (guards = "useNative()" )
422
424
long doNativeBytes (PBytesLike data , int value ,
423
425
@ Shared ("b" ) @ Cached SequenceStorageNodes .GetInternalBytesNode toBytes ,
424
- @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
426
+ @ Shared @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
425
427
byte [] bytes = toBytes .execute (data );
426
428
int len = data .getSequenceStorage ().length ();
427
429
return nativeAdler32 (bytes , len , value , PythonContext .get (this ), invoke );
@@ -430,7 +432,7 @@ long doNativeBytes(PBytesLike data, int value,
430
432
@ Specialization (guards = {"useNative()" , "!isBytes(data)" })
431
433
long doNativeObject (VirtualFrame frame , Object data , int value ,
432
434
@ Shared ("bb" ) @ Cached ToBytesNode toBytesNode ,
433
- @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
435
+ @ Shared @ Cached NativeLibrary .InvokeNativeFunction invoke ) {
434
436
byte [] bytes = toBytesNode .execute (frame , data );
435
437
return nativeAdler32 (bytes , bytes .length , value , PythonContext .get (this ), invoke );
436
438
}
@@ -494,7 +496,7 @@ protected boolean useNative() {
494
496
@ Specialization (guards = {"useNative()" })
495
497
PBytes doNativeBytes (PBytesLike data , int level ,
496
498
@ Cached SequenceStorageNodes .GetInternalBytesNode toByte ,
497
- @ Cached ZlibNodes .ZlibNativeCompress nativeCompress ) {
499
+ @ Shared @ Cached ZlibNodes .ZlibNativeCompress nativeCompress ) {
498
500
byte [] bytes = toByte .execute (data );
499
501
int len = data .getSequenceStorage ().length ();
500
502
byte [] resultArray = nativeCompress .execute (bytes , len , level , getContext ());
@@ -504,16 +506,17 @@ PBytes doNativeBytes(PBytesLike data, int level,
504
506
@ Specialization (guards = {"useNative()" , "!isBytes(data)" })
505
507
PBytes doNativeObject (VirtualFrame frame , Object data , int level ,
506
508
@ Shared ("bb" ) @ Cached ToBytesNode toBytesNode ,
507
- @ Cached ZlibNodes .ZlibNativeCompress nativeCompress ) {
509
+ @ Shared @ Cached ZlibNodes .ZlibNativeCompress nativeCompress ) {
508
510
byte [] bytes = toBytesNode .execute (frame , data );
509
511
return factory ().createBytes (nativeCompress .execute (bytes , bytes .length , level , getContext ()));
510
512
}
511
513
512
514
@ Specialization (guards = {"!useNative()" })
513
515
PBytes doJava (VirtualFrame frame , Object data , int level ,
516
+ @ Bind ("this" ) Node inliningTarget ,
514
517
@ 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 )) {
517
520
throw raise (ZLibError , ErrorMessages .BAD_COMPRESSION_LEVEL );
518
521
}
519
522
byte [] array = toBytesNode .execute (frame , data );
@@ -562,7 +565,7 @@ protected boolean useNative() {
562
565
@ Specialization (guards = {"bufsize >= 0" , "useNative()" })
563
566
PBytes doNativeBytes (PBytesLike data , int wbits , int bufsize ,
564
567
@ Cached SequenceStorageNodes .GetInternalBytesNode toByte ,
565
- @ Cached ZlibNodes .ZlibNativeDecompress nativeDecompress ) {
568
+ @ Shared @ Cached ZlibNodes .ZlibNativeDecompress nativeDecompress ) {
566
569
byte [] bytes = toByte .execute (data );
567
570
int len = data .getSequenceStorage ().length ();
568
571
return factory ().createBytes (nativeDecompress .execute (bytes , len , wbits , bufsize , PythonContext .get (this )));
@@ -571,7 +574,7 @@ PBytes doNativeBytes(PBytesLike data, int wbits, int bufsize,
571
574
@ Specialization (guards = {"bufsize >= 0" , "useNative()" , "!isBytes(data)" })
572
575
PBytes doNativeObject (VirtualFrame frame , Object data , int wbits , int bufsize ,
573
576
@ Shared ("bb" ) @ Cached ToBytesNode toBytesNode ,
574
- @ Cached ZlibNodes .ZlibNativeDecompress nativeDecompress ) {
577
+ @ Shared @ Cached ZlibNodes .ZlibNativeDecompress nativeDecompress ) {
575
578
byte [] bytes = toBytesNode .execute (frame , data );
576
579
int len = bytes .length ;
577
580
return factory ().createBytes (nativeDecompress .execute (bytes , len , wbits , bufsize , PythonContext .get (this )));
0 commit comments