Skip to content

Commit dde532f

Browse files
committed
Avoid inline caching Ropes containing the TruffleRuby home
* Otherwise they would end up in the pre-initialized heap. * post-boot.rb calls Kernel#require calls $LOADED_FEATURES.include? calls String#==. * With splitting, #require might have a copy of String#== per #require call site. (cherry picked from commit 6bfd87c)
1 parent 421f47c commit dde532f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,12 @@ protected boolean sameRopes(Rope a, Rope b) {
13671367
return true;
13681368
}
13691369

1370-
@Specialization(guards = { "a == cachedA", "b == cachedB", }, limit = "getIdentityCacheLimit()")
1370+
@Specialization(guards = { "a == cachedA", "b == cachedB", "canBeCached" }, limit = "getIdentityCacheLimit()")
13711371
protected boolean cachedRopes(Rope a, Rope b,
13721372
@Cached("a") Rope cachedA,
13731373
@Cached("b") Rope cachedB,
1374-
@Cached("a.bytesEqual(b)") boolean equal) {
1374+
@Cached("canBeCached(cachedA, cachedB)") boolean canBeCached,
1375+
@Cached("cachedA.bytesEqual(cachedB)") boolean equal) {
13751376
return equal;
13761377
}
13771378

@@ -1428,6 +1429,19 @@ protected boolean fullRopeEqual(Rope a, Rope b,
14281429
return Arrays.equals(aBytes, bBytes);
14291430
}
14301431

1432+
protected boolean canBeCached(Rope a, Rope b) {
1433+
if (getContext().isPreInitializing()) {
1434+
final String home = getContext().getRubyHome();
1435+
if (a.byteLength() < home.length() && b.byteLength() < home.length()) {
1436+
return true;
1437+
}
1438+
return !RopeOperations.decodeOrEscapeBinaryRope(a).contains(home) &&
1439+
!RopeOperations.decodeOrEscapeBinaryRope(b).contains(home);
1440+
} else {
1441+
return true;
1442+
}
1443+
}
1444+
14311445
}
14321446

14331447
@GenerateUncached

0 commit comments

Comments
 (0)