Soft/WeakReference: real GC eviction via Chez weak pairs + guardians
Replace the strong-ref stub with genuine reclamation. The referent is held through a weak-cons, so Chez's generational collector reclaims it once it is otherwise unreachable (the pair's car becomes the bwp object, and .get returns nil). A guardian registered on the referent makes the reference itself available the instant its referent is collected, which ReferenceQueue.poll surfaces as enqueued — the same hook clojure.core.cache's clear-soft-cache! drains. Chez has no softer-than-weak reference, so a SoftReference clears on unreachability rather than under memory pressure: a SoftCache evicts more eagerly than the JVM's but is now real GC eviction, not an unbounded strong cache. WeakReference gets the same (faithful) semantics. Added System/gc -> a full collect so callers (and the queue) can force the cycle. core.cache stays 1314/0/0 (its test values are immortal literals). Corpus row for System/gc; make test + shakesmoke green.
This commit is contained in:
parent
e955b2072a
commit
80b2dfa9f9
3 changed files with 41 additions and 25 deletions
|
|
@ -106,6 +106,9 @@
|
|||
(list (cons "currentTimeMillis" (lambda () (->num (now-millis))))
|
||||
(cons "nanoTime" (lambda () (->num (* 1000000 (now-millis)))))
|
||||
(cons "exit" (lambda args (exit (if (null? args) 0 (jnum->exact (car args))))))
|
||||
;; System/gc -> a full Chez collection (so weak references clear and their
|
||||
;; guardians fire); Runtime.gc() routes here too.
|
||||
(cons "gc" (lambda _ (collect (collect-maximum-generation)) jolt-nil))
|
||||
;; wrapped in lambdas: the helpers are defined below, resolved at call time.
|
||||
(cons "getProperty" (lambda (k . d) (apply sys-get-property k d)))
|
||||
(cons "setProperty" (lambda (k v) (sys-set-property k v)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue