Skip to content

Commit 0db283f

Browse files
committed
[GR-15990] Make frozen strings context independent
PullRequest: truffleruby/2134
2 parents 4e928a9 + 149e587 commit 0db283f

File tree

97 files changed

+2185
-1302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2185
-1302
lines changed

src/main/.checkstyle_checks.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@
214214
<property name="format" value='"isNil'/>
215215
<property name="message" value="Type the argument as Nil instead of using a positive isNil() guard."/>
216216
</module>
217+
<module name="RegexpSinglelineJava">
218+
<property name="format" value='@CachedLibrary\(".+RubyStringLibrary'/>
219+
<property name="message" value="Use @CachedLibrary(limit = &quot;2&quot;) RubyStringLibrary instead."/>
220+
</module>
217221
<module name="IllegalType">
218222
<!-- Use PrintStream instead of PrintWriter, PrintWriter does not consistently flush, even when writing \n.-->
219223
<property name="illegalClassNames" value="TruffleObject,DynamicObject,PrintWriter"/>

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,16 @@
5151
import org.truffleruby.core.proc.ProcOperations;
5252
import org.truffleruby.core.proc.RubyProc;
5353
import org.truffleruby.core.regexp.RegexpCacheKey;
54+
import org.truffleruby.core.rope.NativeRope;
5455
import org.truffleruby.core.rope.PathToRopeCache;
55-
import org.truffleruby.core.rope.Rope;
56-
import org.truffleruby.core.string.FrozenStringLiterals;
57-
import org.truffleruby.core.string.RubyString;
5856
import org.truffleruby.core.symbol.RubySymbol;
5957
import org.truffleruby.core.thread.ThreadManager;
6058
import org.truffleruby.core.time.GetTimeZoneNode;
6159
import org.truffleruby.debug.MetricsProfiler;
6260
import org.truffleruby.extra.ffi.Pointer;
6361
import org.truffleruby.interop.InteropManager;
6462
import org.truffleruby.language.CallStackManager;
63+
import org.truffleruby.language.ImmutableRubyString;
6564
import org.truffleruby.language.LexicalScope;
6665
import org.truffleruby.language.RubyBaseNode;
6766
import org.truffleruby.language.SafepointManager;
@@ -117,7 +116,6 @@ public class RubyContext {
117116
private final SharedObjects sharedObjects = new SharedObjects(this);
118117
private final AtExitManager atExitManager = new AtExitManager(this);
119118
private final CallStackManager callStack = new CallStackManager(this);
120-
private final FrozenStringLiterals frozenStringLiterals;
121119
private final CoreExceptions coreExceptions;
122120
private final EncodingManager encodingManager;
123121
private final MetricsProfiler metricsProfiler = new MetricsProfiler(this);
@@ -128,6 +126,7 @@ public class RubyContext {
128126
private final Map<Source, Integer> sourceLineOffsets = Collections.synchronizedMap(new WeakHashMap<>());
129127
/** (Symbol, refinements) -> Proc for Symbol#to_proc */
130128
public final Map<Pair<RubySymbol, Map<RubyModule, RubyModule[]>>, RootCallTarget> cachedSymbolToProcTargetsWithRefinements = new ConcurrentHashMap<>();
129+
private final Map<ImmutableRubyString, NativeRope> immutableNativeRopes = new ConcurrentHashMap<>();
131130

132131
@CompilationFinal private SecureRandom random;
133132
private final Hashing hashing;
@@ -173,7 +172,6 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
173172
options = createOptions(env, language.options);
174173

175174
safepointManager = new SafepointManager(this, language);
176-
frozenStringLiterals = new FrozenStringLiterals(this, language);
177175
coreExceptions = new CoreExceptions(this, language);
178176
encodingManager = new EncodingManager(this, language);
179177

@@ -626,14 +624,6 @@ public CallStackManager getCallStack() {
626624
return callStack;
627625
}
628626

629-
public RubyString getFrozenStringLiteral(Rope rope) {
630-
return frozenStringLiterals.getFrozenStringLiteral(rope);
631-
}
632-
633-
public RubyString getInternedString(RubyString string) {
634-
return frozenStringLiterals.getFrozenStringLiteral(string);
635-
}
636-
637627
public Object getClassVariableDefinitionLock() {
638628
return classVariableDefinitionLock;
639629
}
@@ -758,6 +748,10 @@ public Map<Source, Integer> getSourceLineOffsets() {
758748
return sourceLineOffsets;
759749
}
760750

751+
public Map<ImmutableRubyString, NativeRope> getImmutableNativeRopes() {
752+
return immutableNativeRopes;
753+
}
754+
761755
private static SecureRandom createRandomInstance() {
762756
try {
763757
/* We want to use a non-blocking source because this is what MRI does (via /dev/urandom) and it's been found

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
import org.truffleruby.core.range.RubyObjectRange;
5151
import org.truffleruby.core.regexp.RubyMatchData;
5252
import org.truffleruby.core.regexp.RubyRegexp;
53+
import org.truffleruby.core.rope.LeafRope;
5354
import org.truffleruby.core.rope.Rope;
5455
import org.truffleruby.core.rope.RopeCache;
5556
import org.truffleruby.core.string.CoreStrings;
57+
import org.truffleruby.core.string.FrozenStringLiterals;
5658
import org.truffleruby.core.string.RubyString;
5759
import org.truffleruby.core.string.StringUtils;
5860
import org.truffleruby.core.support.RubyByteArray;
@@ -67,6 +69,7 @@
6769
import org.truffleruby.core.tracepoint.RubyTracePoint;
6870
import org.truffleruby.extra.RubyAtomicReference;
6971
import org.truffleruby.extra.ffi.RubyPointer;
72+
import org.truffleruby.language.ImmutableRubyString;
7073
import org.truffleruby.language.NotProvided;
7174
import org.truffleruby.language.RubyDynamicObject;
7275
import org.truffleruby.language.RubyEvalInteractiveRootNode;
@@ -148,6 +151,7 @@ public final class RubyLanguage extends TruffleLanguage<RubyContext> {
148151
public final CoreStrings coreStrings;
149152
public final CoreSymbols coreSymbols;
150153
public final PrimitiveManager primitiveManager;
154+
public final FrozenStringLiterals frozenStringLiterals;
151155
public final RopeCache ropeCache;
152156
public final SymbolTable symbolTable;
153157
@CompilationFinal public LanguageOptions options;
@@ -204,6 +208,7 @@ public RubyLanguage() {
204208
coreStrings = new CoreStrings(this);
205209
coreSymbols = new CoreSymbols();
206210
primitiveManager = new PrimitiveManager();
211+
frozenStringLiterals = new FrozenStringLiterals();
207212
ropeCache = new RopeCache(coreSymbols);
208213
symbolTable = new SymbolTable(ropeCache, coreSymbols);
209214
}
@@ -420,6 +425,10 @@ public AllocationReporter getAllocationReporter() {
420425
return allocationReporter;
421426
}
422427

428+
public ImmutableRubyString getFrozenStringLiteral(LeafRope rope) {
429+
return frozenStringLiterals.getFrozenStringLiteral(rope);
430+
}
431+
423432
public long getNextObjectID() {
424433
final long id = nextObjectID.getAndAdd(ObjectSpaceManager.OBJECT_ID_INCREMENT_BY);
425434

0 commit comments

Comments
 (0)