@@ -804,45 +804,35 @@ protected Object debugPrintSubstringRope(SubstringRope rope, int currentLevel, b
804
804
}
805
805
806
806
@ TruffleBoundary
807
- @ Specialization (guards = "state.isBytes()" )
808
- protected Object debugPrintConcatRopeBytes (ConcatRope rope , int currentLevel , boolean printString ,
809
- @ Bind ("rope.getState()" ) ConcatState state ) {
810
- printPreamble (currentLevel );
811
-
812
- System .err
813
- .println (StringUtils .format (
814
- "%s (%s; BN: %b; BL: %d; CL: %d; CR: %s; E: %s)" ,
815
- printString ? rope .toString () : "<skipped>" ,
816
- rope .getClass ().getSimpleName (),
817
- false ,
818
- rope .byteLength (),
819
- rope .characterLength (),
820
- rope .getCodeRange (),
821
- rope .getEncoding ()));
822
-
823
- return nil ;
824
- }
825
-
826
- @ TruffleBoundary
827
- @ Specialization (guards = "state.isChildren()" )
828
- protected Object debugPrintConcatRopeChildren (ConcatRope rope , int currentLevel , boolean printString ,
829
- @ Bind ("rope.getState()" ) ConcatState state ) {
807
+ protected Object debugPrintConcatRopeBytes (ConcatRope rope , int currentLevel , boolean printString ) {
830
808
printPreamble (currentLevel );
831
809
832
- System .err
833
- .println (StringUtils .format (
834
- "%s (%s; BN: %b; BL: %d; CL: %d; CR: %s; E: %s)" ,
835
- printString ? rope .toString () : "<skipped>" ,
836
- rope .getClass ().getSimpleName (),
837
- // Note: converting a rope to a java.lang.String may populate the byte[].
838
- true , // are bytes null?
839
- rope .byteLength (),
840
- rope .characterLength (),
841
- rope .getCodeRange (),
842
- rope .getEncoding ()));
843
-
844
- executeDebugPrint (state .left , currentLevel + 1 , printString );
845
- executeDebugPrint (state .right , currentLevel + 1 , printString );
810
+ final ConcatState state = rope .getState ();
811
+ if (state .isBytes ()) {
812
+ System .err .println (StringUtils .format (
813
+ "%s (%s; BN: %b; BL: %d; CL: %d; CR: %s; E: %s)" ,
814
+ printString ? rope .toString () : "<skipped>" ,
815
+ rope .getClass ().getSimpleName (),
816
+ false ,
817
+ rope .byteLength (),
818
+ rope .characterLength (),
819
+ rope .getCodeRange (),
820
+ rope .getEncoding ()));
821
+ } else {
822
+ System .err .println (StringUtils .format (
823
+ "%s (%s; BN: %b; BL: %d; CL: %d; CR: %s; E: %s)" ,
824
+ printString ? rope .toString () : "<skipped>" ,
825
+ rope .getClass ().getSimpleName (),
826
+ // Note: converting a rope to a java.lang.String may populate the byte[].
827
+ true , // are bytes null?
828
+ rope .byteLength (),
829
+ rope .characterLength (),
830
+ rope .getCodeRange (),
831
+ rope .getEncoding ()));
832
+
833
+ executeDebugPrint (state .left , currentLevel + 1 , printString );
834
+ executeDebugPrint (state .right , currentLevel + 1 , printString );
835
+ }
846
836
847
837
return nil ;
848
838
}
@@ -1015,9 +1005,15 @@ protected int getByteRepeatingRope(RepeatingRope rope, int index,
1015
1005
return rope .getChild ().getRawBytes ()[index % rope .getChild ().byteLength ()] & 0xff ;
1016
1006
}
1017
1007
1008
+ // NOTE(norswap, 12 Jan 2021): The order of the two next specialization is significant.
1009
+ // Normally, @Bind expressions should only be run per node, but that's not the case currently (GR-28671).
1010
+ // Therefore it's important to test isChildren first, as it's possible to transition from children to bytes
1011
+ // but not the other way around.
1012
+
1018
1013
@ Specialization (guards = "state.isChildren()" )
1019
1014
protected int getByteConcatRope (ConcatRope rope , int index ,
1020
- @ Bind ("rope.getState()" ) ConcatState state ,
1015
+ @ Cached ConditionProfile stateBytesNotNull ,
1016
+ @ Bind ("rope.getState(stateBytesNotNull)" ) ConcatState state ,
1021
1017
@ Cached ConditionProfile chooseLeftChildProfile ,
1022
1018
@ Cached ConditionProfile leftChildRawBytesNullProfile ,
1023
1019
@ Cached ConditionProfile rightChildRawBytesNullProfile ,
@@ -1042,7 +1038,8 @@ protected int getByteConcatRope(ConcatRope rope, int index,
1042
1038
// before we get to run the other getByteConcatRope.
1043
1039
@ Specialization (guards = "state.isBytes()" )
1044
1040
protected int getByteConcatRope (ConcatRope rope , int index ,
1045
- @ Bind ("rope.getState()" ) ConcatState state ) {
1041
+ @ Cached ConditionProfile stateBytesNotNull ,
1042
+ @ Bind ("rope.getState(stateBytesNotNull)" ) ConcatState state ) {
1046
1043
return state .bytes [index ] & 0xff ;
1047
1044
}
1048
1045
}
0 commit comments