@@ -94,6 +94,7 @@ public class RubyContext {
94
94
@ CompilationFinal private Options options ;
95
95
@ CompilationFinal private String rubyHome ;
96
96
@ CompilationFinal private TruffleFile rubyHomeTruffleFile ;
97
+ @ CompilationFinal private boolean hadHome ;
97
98
98
99
private final PrimitiveManager primitiveManager = new PrimitiveManager ();
99
100
private final SafepointManager safepointManager = new SafepointManager (this );
@@ -122,7 +123,7 @@ public class RubyContext {
122
123
123
124
@ CompilationFinal private SecureRandom random ;
124
125
private final Hashing hashing ;
125
- @ CompilationFinal BacktraceFormatter defaultBacktraceFormatter ;
126
+ @ CompilationFinal private BacktraceFormatter defaultBacktraceFormatter ;
126
127
private final BacktraceFormatter userBacktraceFormatter ;
127
128
private final RopeCache ropeCache ;
128
129
private final PathToRopeCache pathToRopeCache = new PathToRopeCache (this );
@@ -258,6 +259,11 @@ public void initialize() {
258
259
random = null ;
259
260
// Cannot save the root Java Thread instance in the image
260
261
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 );
261
267
} else {
262
268
initialized = true ;
263
269
}
@@ -275,9 +281,8 @@ protected boolean patch(Env newEnv) {
275
281
276
282
final Options oldOptions = this .options ;
277
283
final Options newOptions = createOptions (newEnv );
278
- final String oldHome = this .rubyHome ;
279
284
final String newHome = findRubyHome (newOptions );
280
- if (!compatibleOptions (oldOptions , newOptions , oldHome , newHome )) {
285
+ if (!compatibleOptions (oldOptions , newOptions , this . hadHome , newHome != null )) {
281
286
return false ;
282
287
}
283
288
this .options = newOptions ;
@@ -337,7 +342,7 @@ protected boolean patchContext(Env newEnv) {
337
342
}
338
343
}
339
344
340
- private boolean compatibleOptions (Options oldOptions , Options newOptions , String oldHome , String newHome ) {
345
+ private boolean compatibleOptions (Options oldOptions , Options newOptions , boolean hadHome , boolean hasHome ) {
341
346
final String notReusingContext = "not reusing pre-initialized context: " ;
342
347
343
348
if (!newOptions .PREINITIALIZATION ) {
@@ -350,9 +355,8 @@ private boolean compatibleOptions(Options oldOptions, Options newOptions, String
350
355
return false ; // Should load the specified core files
351
356
}
352
357
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" ));
356
360
return false ;
357
361
}
358
362
0 commit comments