Skip to content

Commit 80fca05

Browse files
committed
[GR-20371] Do not save image generator paths in the image heap
1 parent 3b756ce commit 80fca05

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class RubyContext {
9494
@CompilationFinal private Options options;
9595
@CompilationFinal private String rubyHome;
9696
@CompilationFinal private TruffleFile rubyHomeTruffleFile;
97+
@CompilationFinal private boolean hadHome;
9798

9899
private final PrimitiveManager primitiveManager = new PrimitiveManager();
99100
private final SafepointManager safepointManager = new SafepointManager(this);
@@ -122,7 +123,7 @@ public class RubyContext {
122123

123124
@CompilationFinal private SecureRandom random;
124125
private final Hashing hashing;
125-
@CompilationFinal BacktraceFormatter defaultBacktraceFormatter;
126+
@CompilationFinal private BacktraceFormatter defaultBacktraceFormatter;
126127
private final BacktraceFormatter userBacktraceFormatter;
127128
private final RopeCache ropeCache;
128129
private final PathToRopeCache pathToRopeCache = new PathToRopeCache(this);
@@ -258,6 +259,11 @@ public void initialize() {
258259
random = null;
259260
// Cannot save the root Java Thread instance in the image
260261
threadManager.resetMainThread();
262+
// Do not save image generator paths in the image heap
263+
hadHome = rubyHome != null;
264+
rubyHome = null;
265+
rubyHomeTruffleFile = null;
266+
featureLoader.setWorkingDirectory(null);
261267
} else {
262268
initialized = true;
263269
}
@@ -275,9 +281,8 @@ protected boolean patch(Env newEnv) {
275281

276282
final Options oldOptions = this.options;
277283
final Options newOptions = createOptions(newEnv);
278-
final String oldHome = this.rubyHome;
279284
final String newHome = findRubyHome(newOptions);
280-
if (!compatibleOptions(oldOptions, newOptions, oldHome, newHome)) {
285+
if (!compatibleOptions(oldOptions, newOptions, this.hadHome, newHome != null)) {
281286
return false;
282287
}
283288
this.options = newOptions;
@@ -337,7 +342,7 @@ protected boolean patchContext(Env newEnv) {
337342
}
338343
}
339344

340-
private boolean compatibleOptions(Options oldOptions, Options newOptions, String oldHome, String newHome) {
345+
private boolean compatibleOptions(Options oldOptions, Options newOptions, boolean hadHome, boolean hasHome) {
341346
final String notReusingContext = "not reusing pre-initialized context: ";
342347

343348
if (!newOptions.PREINITIALIZATION) {
@@ -350,9 +355,8 @@ private boolean compatibleOptions(Options oldOptions, Options newOptions, String
350355
return false; // Should load the specified core files
351356
}
352357

353-
if ((oldHome != null) != (newHome != null)) {
354-
RubyLanguage.LOGGER
355-
.fine(notReusingContext + "Ruby home is " + (newHome != null ? "set (" + newHome + ")" : "unset"));
358+
if (hadHome != hasHome) {
359+
RubyLanguage.LOGGER.fine(notReusingContext + "Ruby home is " + (hasHome ? "set" : "unset"));
356360
return false;
357361
}
358362

0 commit comments

Comments
 (0)