Skip to content

Commit 910c5c7

Browse files
author
Nicolas Laurent
committed
[GR-27063] Make Shape fields in RubyLanguage non-static
PullRequest: truffleruby/2127
2 parents 2990292 + afc479c commit 910c5c7

File tree

90 files changed

+501
-412
lines changed

Some content is hidden

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

90 files changed

+501
-412
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class RubyContext {
103103
private final SafepointManager safepointManager = new SafepointManager(this);
104104
private final InteropManager interopManager = new InteropManager(this);
105105
private final CodeLoader codeLoader = new CodeLoader(this);
106-
private final FeatureLoader featureLoader = new FeatureLoader(this);
106+
private final FeatureLoader featureLoader;
107107
private final TraceManager traceManager;
108108
private final ReferenceProcessor referenceProcessor;
109109
private final FinalizationService finalizationService;
@@ -112,9 +112,9 @@ public class RubyContext {
112112
private final SharedObjects sharedObjects = new SharedObjects(this);
113113
private final AtExitManager atExitManager = new AtExitManager(this);
114114
private final CallStackManager callStack = new CallStackManager(this);
115-
private final FrozenStringLiterals frozenStringLiterals = new FrozenStringLiterals(this);
115+
private final FrozenStringLiterals frozenStringLiterals;
116116
private final CoreExceptions coreExceptions;
117-
private final EncodingManager encodingManager = new EncodingManager(this);
117+
private final EncodingManager encodingManager;
118118
private final MetricsProfiler metricsProfiler = new MetricsProfiler(this);
119119
private final WeakValueCache<RegexpCacheKey, Regex> regexpCache = new WeakValueCache<>();
120120
private final PreInitializationManager preInitializationManager;
@@ -165,8 +165,11 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
165165

166166
options = createOptions(env, language.options);
167167

168+
frozenStringLiterals = new FrozenStringLiterals(this, language);
168169
coreExceptions = new CoreExceptions(this, language);
170+
encodingManager = new EncodingManager(this, language);
169171

172+
featureLoader = new FeatureLoader(this, language);
170173
referenceProcessor = new ReferenceProcessor(this);
171174
finalizationService = new FinalizationService(this, referenceProcessor);
172175
markingService = new MarkingService(this, referenceProcessor);
@@ -176,16 +179,16 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
176179

177180
hashing = new Hashing(generateHashingSeed());
178181

179-
defaultBacktraceFormatter = BacktraceFormatter.createDefaultFormatter(this);
180-
userBacktraceFormatter = new BacktraceFormatter(this, BacktraceFormatter.USER_BACKTRACE_FLAGS);
182+
defaultBacktraceFormatter = BacktraceFormatter.createDefaultFormatter(this, language);
183+
userBacktraceFormatter = new BacktraceFormatter(this, language, BacktraceFormatter.USER_BACKTRACE_FLAGS);
181184

182185
rubyHome = findRubyHome(options);
183186
rubyHomeTruffleFile = rubyHome == null ? null : env.getInternalTruffleFile(rubyHome);
184187

185188
// Load the core library classes
186189

187190
Metrics.printTime("before-create-core-library");
188-
coreLibrary = new CoreLibrary(this);
191+
coreLibrary = new CoreLibrary(this, language);
189192
nativeConfiguration = NativeConfiguration.loadNativeConfiguration(this);
190193
coreLibrary.initialize();
191194
valueWrapperManager = new ValueWrapperManager(this);
@@ -205,7 +208,7 @@ public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
205208
Metrics.printTime("after-initialize-encodings");
206209

207210
Metrics.printTime("before-thread-manager");
208-
threadManager = new ThreadManager(this);
211+
threadManager = new ThreadManager(this, language);
209212
threadManager.initialize(truffleNFIPlatform, nativeConfiguration);
210213
threadManager.initializeMainThread(Thread.currentThread());
211214
Metrics.printTime("after-thread-manager");
@@ -285,7 +288,7 @@ protected boolean patch(Env newEnv) {
285288
random = createRandomInstance();
286289
hashing.patchSeed(generateHashingSeed());
287290

288-
this.defaultBacktraceFormatter = BacktraceFormatter.createDefaultFormatter(this);
291+
this.defaultBacktraceFormatter = BacktraceFormatter.createDefaultFormatter(this, language);
289292

290293
this.truffleNFIPlatform = createNativePlatform();
291294
encodingManager.initializeDefaultEncodings(truffleNFIPlatform, nativeConfiguration);
@@ -663,7 +666,7 @@ public ConsoleHolder getConsoleHolder() {
663666
if (consoleHolder == null) {
664667
synchronized (this) {
665668
if (consoleHolder == null) {
666-
consoleHolder = ConsoleHolder.create(this);
669+
consoleHolder = ConsoleHolder.create(this, language);
667670
}
668671
}
669672
}

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

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -156,47 +156,42 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
156156
public final Shape moduleShape = createShape(RubyModule.class);
157157
public final Shape classShape = createShape(RubyClass.class);
158158

159-
// TODO (eregon, 25 Sep 2020): These Shapes should ideally be stored in the language instance,
160-
// so different Engines/RubyLanguage instances can have different type profiles.
161-
// However that requires passing the language instance around a lot which is inconvenient
162-
// and does not seem worth it currently. Also these builtin types are rather unlikely to have
163-
// instance variables.
164-
public static final Shape arrayShape = createShape(RubyArray.class);
165-
public static final Shape atomicReferenceShape = createShape(RubyAtomicReference.class);
166-
public static final Shape bigDecimalShape = createShape(RubyBigDecimal.class);
167-
public static final Shape bindingShape = createShape(RubyBinding.class);
168-
public static final Shape byteArrayShape = createShape(RubyByteArray.class);
169-
public static final Shape conditionVariableShape = createShape(RubyConditionVariable.class);
170-
public static final Shape digestShape = createShape(RubyDigest.class);
171-
public static final Shape encodingConverterShape = createShape(RubyEncodingConverter.class);
172-
public static final Shape encodingShape = createShape(RubyEncoding.class);
173-
public static final Shape exceptionShape = createShape(RubyException.class);
174-
public static final Shape fiberShape = createShape(RubyFiber.class);
175-
public static final Shape handleShape = createShape(RubyHandle.class);
176-
public static final Shape hashShape = createShape(RubyHash.class);
177-
public static final Shape intRangeShape = createShape(RubyIntRange.class);
178-
public static final Shape ioShape = createShape(RubyIO.class);
179-
public static final Shape longRangeShape = createShape(RubyLongRange.class);
180-
public static final Shape matchDataShape = createShape(RubyMatchData.class);
181-
public static final Shape methodShape = createShape(RubyMethod.class);
182-
public static final Shape mutexShape = createShape(RubyMutex.class);
183-
public static final Shape nameErrorShape = createShape(RubyNameError.class);
184-
public static final Shape noMethodErrorShape = createShape(RubyNoMethodError.class);
185-
public static final Shape objectRangeShape = createShape(RubyObjectRange.class);
186-
public static final Shape procShape = createShape(RubyProc.class);
187-
public static final Shape queueShape = createShape(RubyQueue.class);
188-
public static final Shape randomizerShape = createShape(RubyRandomizer.class);
189-
public static final Shape regexpShape = createShape(RubyRegexp.class);
190-
public static final Shape sizedQueueShape = createShape(RubySizedQueue.class);
191-
public static final Shape stringShape = createShape(RubyString.class);
192-
public static final Shape systemCallErrorShape = createShape(RubySystemCallError.class);
193-
public static final Shape threadBacktraceLocationShape = createShape(RubyBacktraceLocation.class);
194-
public static final Shape threadShape = createShape(RubyThread.class);
195-
public static final Shape timeShape = createShape(RubyTime.class);
196-
public static final Shape tracePointShape = createShape(RubyTracePoint.class);
197-
public static final Shape truffleFFIPointerShape = createShape(RubyPointer.class);
198-
public static final Shape unboundMethodShape = createShape(RubyUnboundMethod.class);
199-
public static final Shape weakMapShape = createShape(RubyWeakMap.class);
159+
public final Shape arrayShape = createShape(RubyArray.class);
160+
public final Shape atomicReferenceShape = createShape(RubyAtomicReference.class);
161+
public final Shape bigDecimalShape = createShape(RubyBigDecimal.class);
162+
public final Shape bindingShape = createShape(RubyBinding.class);
163+
public final Shape byteArrayShape = createShape(RubyByteArray.class);
164+
public final Shape conditionVariableShape = createShape(RubyConditionVariable.class);
165+
public final Shape digestShape = createShape(RubyDigest.class);
166+
public final Shape encodingConverterShape = createShape(RubyEncodingConverter.class);
167+
public final Shape encodingShape = createShape(RubyEncoding.class);
168+
public final Shape exceptionShape = createShape(RubyException.class);
169+
public final Shape fiberShape = createShape(RubyFiber.class);
170+
public final Shape handleShape = createShape(RubyHandle.class);
171+
public final Shape hashShape = createShape(RubyHash.class);
172+
public final Shape intRangeShape = createShape(RubyIntRange.class);
173+
public final Shape ioShape = createShape(RubyIO.class);
174+
public final Shape longRangeShape = createShape(RubyLongRange.class);
175+
public final Shape matchDataShape = createShape(RubyMatchData.class);
176+
public final Shape methodShape = createShape(RubyMethod.class);
177+
public final Shape mutexShape = createShape(RubyMutex.class);
178+
public final Shape nameErrorShape = createShape(RubyNameError.class);
179+
public final Shape noMethodErrorShape = createShape(RubyNoMethodError.class);
180+
public final Shape objectRangeShape = createShape(RubyObjectRange.class);
181+
public final Shape procShape = createShape(RubyProc.class);
182+
public final Shape queueShape = createShape(RubyQueue.class);
183+
public final Shape randomizerShape = createShape(RubyRandomizer.class);
184+
public final Shape regexpShape = createShape(RubyRegexp.class);
185+
public final Shape sizedQueueShape = createShape(RubySizedQueue.class);
186+
public final Shape stringShape = createShape(RubyString.class);
187+
public final Shape systemCallErrorShape = createShape(RubySystemCallError.class);
188+
public final Shape threadBacktraceLocationShape = createShape(RubyBacktraceLocation.class);
189+
public final Shape threadShape = createShape(RubyThread.class);
190+
public final Shape timeShape = createShape(RubyTime.class);
191+
public final Shape tracePointShape = createShape(RubyTracePoint.class);
192+
public final Shape truffleFFIPointerShape = createShape(RubyPointer.class);
193+
public final Shape unboundMethodShape = createShape(RubyUnboundMethod.class);
194+
public final Shape weakMapShape = createShape(RubyWeakMap.class);
200195

201196
public RubyLanguage() {
202197
coreMethodAssumptions = new CoreMethodAssumptions(this);

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.jcodings.specific.USASCIIEncoding;
1919
import org.jcodings.specific.UTF8Encoding;
2020
import org.truffleruby.Layouts;
21-
import org.truffleruby.RubyLanguage;
2221
import org.truffleruby.builtins.CoreMethod;
2322
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2423
import org.truffleruby.builtins.CoreMethodNode;
@@ -31,7 +30,6 @@
3130
import org.truffleruby.core.CoreLibrary;
3231
import org.truffleruby.core.MarkingService.ExtensionCallStack;
3332
import org.truffleruby.core.MarkingServiceNodes;
34-
import org.truffleruby.core.array.ArrayHelpers;
3533
import org.truffleruby.core.array.ArrayToObjectArrayNode;
3634
import org.truffleruby.core.array.RubyArray;
3735
import org.truffleruby.core.encoding.RubyEncoding;
@@ -358,7 +356,7 @@ private RubyArray bytes(BigInteger bi, int num_words, int word_length, boolean m
358356
}
359357
}
360358
}
361-
return ArrayHelpers.createArray(getContext(), bytes);
359+
return createArray(bytes);
362360
}
363361

364362

@@ -1027,7 +1025,7 @@ protected RubyPointer toNative(RubyString string,
10271025

10281026
final RubyPointer instance = new RubyPointer(
10291027
coreLibrary().truffleFFIPointerClass,
1030-
RubyLanguage.truffleFFIPointerShape,
1028+
getLanguage().truffleFFIPointerShape,
10311029
nativeRope.getNativePointer());
10321030
AllocationTracing.trace(instance, this);
10331031
return instance;
@@ -1211,7 +1209,6 @@ protected Object rbTrEncMbcCaseFold(RubyEncoding enc, int flags, RubyString stri
12111209
System.arraycopy(to, 0, result, 0, resultLength);
12121210
}
12131211
return StringOperations.createString(
1214-
getContext(),
12151212
this,
12161213
RopeOperations.create(result, USASCIIEncoding.INSTANCE, CodeRange.CR_UNKNOWN));
12171214
}
@@ -1235,7 +1232,6 @@ protected Object rbTrEncMbcPut(RubyEncoding enc, int code) {
12351232
System.arraycopy(buf, 0, result, 0, resultLength);
12361233
}
12371234
return StringOperations.createString(
1238-
getContext(),
12391235
this,
12401236
RopeOperations.create(result, USASCIIEncoding.INSTANCE, CodeRange.CR_UNKNOWN));
12411237
}

0 commit comments

Comments
 (0)