Skip to content

Commit 6517478

Browse files
committed
Add profile-less TruffleString.EqualNode.checkContentEqualsUncached.
1 parent bd83554 commit 6517478

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

truffle/src/com.oracle.truffle.api.strings/src/com/oracle/truffle/api/strings/AbstractTruffleString.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
import com.oracle.truffle.api.CompilerDirectives;
6464
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6565
import com.oracle.truffle.api.nodes.Node;
66-
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
67-
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6866
import com.oracle.truffle.api.strings.TruffleString.Encoding;
6967

7068
/**
@@ -1292,10 +1290,9 @@ public final boolean equals(Object obj) {
12921290
if (this == obj) {
12931291
return true;
12941292
}
1295-
if (!(obj instanceof AbstractTruffleString)) {
1293+
if (!(obj instanceof AbstractTruffleString b)) {
12961294
return false;
12971295
}
1298-
AbstractTruffleString b = (AbstractTruffleString) obj;
12991296
int enc = encoding();
13001297
if (enc != b.encoding()) {
13011298
if (!b.isLooselyCompatibleTo(enc, TruffleString.Encoding.getMaxCompatibleCodeRange(enc), b.codeRange())) {
@@ -1305,14 +1302,7 @@ public final boolean equals(Object obj) {
13051302
return false;
13061303
}
13071304
}
1308-
return TruffleString.EqualNode.checkContentEquals(TruffleString.EqualNode.getUncached(), this, b,
1309-
InlinedConditionProfile.getUncached(),
1310-
InlinedConditionProfile.getUncached(),
1311-
InlinedConditionProfile.getUncached(),
1312-
InlinedConditionProfile.getUncached(),
1313-
InlinedConditionProfile.getUncached(),
1314-
InlinedBranchProfile.getUncached(),
1315-
InlinedConditionProfile.getUncached());
1305+
return TruffleString.EqualNode.checkContentEqualsUncached(this, b);
13161306
}
13171307

13181308
/**

truffle/src/com.oracle.truffle.api.strings/src/com/oracle/truffle/api/strings/TruffleString.java

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,7 +5953,8 @@ static boolean sameObject(AbstractTruffleString a, AbstractTruffleString b, Enco
59535953
}
59545954

59555955
@Fallback
5956-
final boolean check(AbstractTruffleString a, AbstractTruffleString b, Encoding expectedEncoding,
5956+
static boolean check(AbstractTruffleString a, AbstractTruffleString b, Encoding expectedEncoding,
5957+
@Cached Node node,
59575958
@Cached InlinedConditionProfile managedProfileA,
59585959
@Cached InlinedConditionProfile nativeProfileA,
59595960
@Cached InlinedConditionProfile managedProfileB,
@@ -5963,7 +5964,7 @@ final boolean check(AbstractTruffleString a, AbstractTruffleString b, Encoding e
59635964
@Cached InlinedConditionProfile checkFirstByteProfile) {
59645965
a.looseCheckEncoding(expectedEncoding, a.codeRange());
59655966
b.looseCheckEncoding(expectedEncoding, b.codeRange());
5966-
return checkContentEquals(this, a, b, managedProfileA, nativeProfileA, managedProfileB, nativeProfileB, lengthAndCodeRangeCheckProfile, compareHashProfile, checkFirstByteProfile);
5967+
return checkContentEquals(node, a, b, managedProfileA, nativeProfileA, managedProfileB, nativeProfileB, lengthAndCodeRangeCheckProfile, compareHashProfile, checkFirstByteProfile);
59675968
}
59685969

59695970
static boolean checkContentEquals(
@@ -6046,6 +6047,79 @@ static boolean checkContentEquals(
60466047
}
60476048
}
60486049

6050+
/**
6051+
* A copy of {@link #checkContentEquals} but without profiles. Keep in sync.
6052+
*/
6053+
static boolean checkContentEqualsUncached(AbstractTruffleString a, AbstractTruffleString b) {
6054+
Node node = TruffleString.EqualNode.getUncached();
6055+
int codeRangeA = a.codeRange();
6056+
int codeRangeB = b.codeRange();
6057+
int lengthCMP = a.length();
6058+
if (lengthCMP != b.length() ||
6059+
(TSCodeRange.isPrecise(codeRangeA, codeRangeB) && codeRangeA != codeRangeB)) {
6060+
return false;
6061+
}
6062+
if (a.isHashCodeCalculated() && b.isHashCodeCalculated()) {
6063+
if (a.getHashCodeUnsafe() != b.getHashCodeUnsafe()) {
6064+
return false;
6065+
}
6066+
}
6067+
if (lengthCMP == 0) {
6068+
return true;
6069+
}
6070+
Object dataA = a.data();
6071+
Object dataB = b.data();
6072+
try {
6073+
final byte[] arrayA;
6074+
final long addOffsetA;
6075+
if (dataA instanceof byte[]) {
6076+
arrayA = (byte[]) dataA;
6077+
addOffsetA = byteArrayBaseOffset();
6078+
} else if (dataA instanceof NativePointer) {
6079+
arrayA = null;
6080+
addOffsetA = NativePointer.unwrap(dataA);
6081+
} else {
6082+
if (dataA instanceof LazyLong lazyLongA && dataB instanceof LazyLong lazyLongB) {
6083+
return lazyLongA.value == lazyLongB.value;
6084+
}
6085+
arrayA = a.materializeLazy(node, dataA);
6086+
addOffsetA = byteArrayBaseOffset();
6087+
}
6088+
final long offsetA = a.offset() + addOffsetA;
6089+
6090+
final byte[] arrayB;
6091+
final long addOffsetB;
6092+
if (dataB instanceof byte[]) {
6093+
arrayB = (byte[]) dataB;
6094+
addOffsetB = byteArrayBaseOffset();
6095+
} else if (dataB instanceof NativePointer) {
6096+
arrayB = null;
6097+
addOffsetB = NativePointer.unwrap(dataB);
6098+
} else {
6099+
arrayB = b.materializeLazy(node, dataB);
6100+
addOffsetB = byteArrayBaseOffset();
6101+
}
6102+
final long offsetB = b.offset() + addOffsetB;
6103+
6104+
int strideA = a.stride();
6105+
int strideB = b.stride();
6106+
if ((strideA | strideB) == 0) {
6107+
// fast path: check first byte
6108+
if (TStringOps.readS0(arrayA, offsetA, a.length(), 0) != TStringOps.readS0(arrayB, offsetB, b.length(), 0)) {
6109+
return false;
6110+
} else if (lengthCMP == 1) {
6111+
return true;
6112+
}
6113+
}
6114+
return TStringOps.regionEqualsWithOrMaskWithStride(node,
6115+
a, arrayA, offsetA, strideA, 0,
6116+
b, arrayB, offsetB, strideB, 0, null, lengthCMP);
6117+
} finally {
6118+
Reference.reachabilityFence(dataA);
6119+
Reference.reachabilityFence(dataB);
6120+
}
6121+
}
6122+
60496123
/**
60506124
* Create a new {@link EqualNode}.
60516125
*

0 commit comments

Comments
 (0)