15
15
import com .oracle .truffle .api .profiles .ConditionProfile ;
16
16
import org .jcodings .Encoding ;
17
17
import org .jcodings .specific .ASCIIEncoding ;
18
+ import org .truffleruby .extra .ffi .Pointer ;
18
19
19
20
public class ConcatRope extends ManagedRope {
20
21
@@ -93,6 +94,7 @@ private ConcatRope withEncoding(Encoding encoding, CodeRange codeRange, int char
93
94
@ Override
94
95
protected byte [] getBytesSlow () {
95
96
bytes = RopeOperations .flattenBytes (this );
97
+ Pointer .UNSAFE .storeFence ();
96
98
left = null ;
97
99
right = null ;
98
100
return bytes ;
@@ -112,22 +114,17 @@ public ConcatState getState() {
112
114
* <p>
113
115
* Outside compiled code, you can use {@link #getState()}. */
114
116
public ConcatState getState (ConditionProfile bytesNotNull ) {
115
- if (bytesNotNull .profile (this .bytes != null )) {
116
- return new ConcatState (null , null , this .bytes );
117
- }
118
-
119
117
final ManagedRope left = this .left ;
120
118
final ManagedRope right = this .right ;
121
- if (left != null && right != null ) {
119
+ Pointer .UNSAFE .loadFence ();
120
+ final byte [] bytes = this .bytes ;
121
+ if (bytesNotNull .profile (bytes != null )) {
122
+ return new ConcatState (null , null , bytes );
123
+ } else if (left != null && right != null ) {
122
124
return new ConcatState (left , right , null );
123
- }
124
-
125
- CompilerDirectives .transferToInterpreterAndInvalidate ();
126
- if (this .bytes != null ) {
125
+ } else {
127
126
throw CompilerDirectives
128
127
.shouldNotReachHere ("our assumptions about reordering and memory barriers seem incorrect" );
129
128
}
130
-
131
- return new ConcatState (null , null , this .bytes );
132
129
}
133
130
}
0 commit comments