Repository navigation
feat(gc): run finalizers, clear soft references and unload class loaders that nothing refers to - #92
Conversation
…erence callbacks of its collection
…tem.gc loop does not recompile
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
This PR implements comprehensive GC features: System.gc() now clears weak/phantom references and enqueues them, runs finalizers (with --finalization=disabled flag), clears soft references under memory pressure, unloads unreachable class loaders, and manages pins on inline caches/compiled code referencing unloadable classes. Thread.exit is made private for direct VM invocation. Documentation updated in support.md and node.md.
Not approved: the diff of test/java/SoftRefs.java, test/java/StructuredThreadExit.java, test/jtreg/passing.txt, test/jtreg/times.tsv, test/programs.test.ts was too large to read.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict comment
…r and pin constants of unloadable classes
|
Review of the files the review bot could not read (test/java/SoftRefs.java, test/java/StructuredThreadExit.java, test/jtreg/passing.txt, test/jtreg/times.tsv, test/programs.test.ts): no findings. The two programs print deterministic output on HotSpot (SoftRefs waits on the queue with a timeout instead of racing the reference handler). The |
There was a problem hiding this comment.
The PR adds finalization, class unloading and related GC behavior to the Java‑web runtime, extending Node options and implementing finalizer handling, soft reference clearing and class loader unloading.
Not approved: the diff of test/java/SoftRefs.java, test/java/StructuredThreadExit.java, test/jtreg/passing.txt, test/jtreg/times.tsv, test/programs.test.ts was too large to read.
review-bot, model nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free, verdict comment
What this changes
System.gc()now does what a program expects from it under Node, on top of the JS engine's collector:Runtime.gcreturns once the engine has delivered the reference callbacks of its collection, so a weak or phantom reference is cleared and enqueued by the timeSystem.gc()returns.finalize()runs on objects nothing refers to.--finalization=disabledturns it off, as on HotSpot. An object on a cycle through its own fields cannot be finalized by JS; the VM finds such cycles with a bounded scan and drops their finalizer so they are freed.OutOfMemoryError, and bySystem.gc()when more than half the heap limit is in use.Thread.exitis private, so the VM invokes it directly instead of selecting it virtually.System.gc(), finalizers and class unloading do, and which cycles leak.Tests
RefsAfterGc,Finalizers,FinalizerCycles,FinalizationDisabled,SoftRefs,ClassUnloadandStructuredThreadExit.System.gc(), a URLClassLoader loop with 60 calls, 5 alternating runs, median per call: master 7.9 ms, branch 8.8 ms, HotSpot 1.9 ms directly in the call; about 12 ms more per call on the branch counting the recompiles after pins are released.Noticed, not fixed
ReachabilityFenceTeststill fails: a local that is dead in the bytecode stays live in a frame.Test4809008still fails: a class loader with afinalize()sits on a cycle the scan does not follow, so it is never freed (documented).