Skip to content

Commit 02f5685

Browse files
author
Nicolas Laurent
committed
[GR-29279] Fix exception caused by missing memory barrier in ConcatRope.
PullRequest: truffleruby/2414
2 parents 2334c2b + fb3b1e1 commit 02f5685

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/main/java/org/truffleruby/core/rope/ConcatRope.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.oracle.truffle.api.profiles.ConditionProfile;
1616
import org.jcodings.Encoding;
1717
import org.jcodings.specific.ASCIIEncoding;
18+
import org.truffleruby.extra.ffi.Pointer;
1819

1920
public class ConcatRope extends ManagedRope {
2021

@@ -93,6 +94,7 @@ private ConcatRope withEncoding(Encoding encoding, CodeRange codeRange, int char
9394
@Override
9495
protected byte[] getBytesSlow() {
9596
bytes = RopeOperations.flattenBytes(this);
97+
Pointer.UNSAFE.storeFence();
9698
left = null;
9799
right = null;
98100
return bytes;
@@ -112,22 +114,17 @@ public ConcatState getState() {
112114
* <p>
113115
* Outside compiled code, you can use {@link #getState()}. */
114116
public ConcatState getState(ConditionProfile bytesNotNull) {
115-
if (bytesNotNull.profile(this.bytes != null)) {
116-
return new ConcatState(null, null, this.bytes);
117-
}
118-
119117
final ManagedRope left = this.left;
120118
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) {
122124
return new ConcatState(left, right, null);
123-
}
124-
125-
CompilerDirectives.transferToInterpreterAndInvalidate();
126-
if (this.bytes != null) {
125+
} else {
127126
throw CompilerDirectives
128127
.shouldNotReachHere("our assumptions about reordering and memory barriers seem incorrect");
129128
}
130-
131-
return new ConcatState(null, null, this.bytes);
132129
}
133130
}

0 commit comments

Comments
 (0)