Skip to content

Commit 98c4d6e

Browse files
committed
[GR-44043] Avoid storing the RubyLanguage Cleaner in image heap for SVM
1 parent 34e127f commit 98c4d6e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ private RubyThread getOrCreateForeignThread(RubyContext context, Thread thread)
245245
public final SymbolTable symbolTable;
246246
public final KeywordArgumentsDescriptorManager keywordArgumentsDescriptorManager = new KeywordArgumentsDescriptorManager();
247247
public final FrozenStringLiterals frozenStringLiterals;
248-
public final Cleaner cleaner = Cleaner.create();
249248

249+
// GR-44025: We store the cleanerThread explicitly here to make it a clear image building failure if it would still be set.
250+
public Thread cleanerThread = null;
251+
@CompilationFinal public Cleaner cleaner = newCleaner();
250252

251253
public volatile ValueWrapperManager.HandleBlockWeakReference[] handleBlockSharedMap = new ValueWrapperManager.HandleBlockWeakReference[0];
252254
public final ValueWrapperManager.HandleBlockAllocator handleBlockAllocator = new ValueWrapperManager.HandleBlockAllocator();
@@ -461,8 +463,11 @@ protected void initializeContext(RubyContext context) {
461463
try {
462464
Metrics.printTime("before-initialize-context");
463465
context.initialize();
466+
464467
if (context.isPreInitializing()) {
465468
setRubyHome(context.getEnv(), null);
469+
this.cleanerThread = null;
470+
this.cleaner = null;
466471
}
467472
Metrics.printTime("after-initialize-context");
468473
} catch (Throwable e) {
@@ -494,6 +499,7 @@ protected boolean patchContext(RubyContext context, Env newEnv) {
494499
}
495500

496501
setRubyHome(newEnv, findRubyHome());
502+
this.cleaner = newCleaner();
497503

498504
boolean patched = context.patchContext(newEnv);
499505
Metrics.printTime("after-patch-context");
@@ -653,6 +659,10 @@ protected Object getScope(RubyContext context) {
653659
return context.getTopScopeObject();
654660
}
655661

662+
private Cleaner newCleaner() {
663+
return Cleaner.create(runnable -> this.cleanerThread = new Thread(runnable, "Ruby-Cleaner"));
664+
}
665+
656666
public String getRubyHome() {
657667
return rubyHome;
658668
}

0 commit comments

Comments
 (0)