Skip to content

Commit 09c334f

Browse files
authored
Merge pull request #787 from fglock/fix/dbic-ordered-code-weaken-gc
Fix DBIx::Class ordered test CODE weaken GC stall
2 parents 347070b + 5463d25 commit 09c334f

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/org/perlonjava/runtime/runtimetypes/WeakRefRegistry.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,23 @@ public static void weaken(RuntimeScalar ref) {
188188
ref.refCountOwned = false;
189189
base.refCount = WEAKLY_TRACKED;
190190
}
191-
boolean shouldSweepLiveCodeRef = weakenedLiveCodeRef
191+
boolean shouldCheckLiveCodeRef = weakenedLiveCodeRef
192192
&& codeRefHasCountedOwners(base)
193193
&& !ModuleInitGuard.inModuleInit();
194194
if (base instanceof RuntimeCode code
195195
&& code.refCount >= 0
196196
&& weakRefsExist
197-
&& (shouldSweepLiveCodeRef
197+
&& (shouldCheckLiveCodeRef
198198
|| (code.hadStashRef
199199
&& code.stashRefCount <= 0
200200
&& !isInstalledGlobalCodeRef(code)))) {
201-
ReachabilityWalker.sweepWeakRefs(true);
201+
// Keep this path targeted to the CODE referent. DBIC weakens
202+
// callback CODE refs in hot cursor paths; running a full
203+
// ReachabilityWalker sweep here forces repeated System.gc() calls.
204+
// The CODE-specific stale-ref decision below is enough: live CODE
205+
// refs are protected by clearWeakRefsTo()/shouldKeepCodeWeakRefs,
206+
// while expired anonymous or former-stash CODE refs can still clear
207+
// their weak registry entries immediately.
202208
if (hasWeakRefsTo(code)
203209
&& code.stashRefCount <= 0
204210
&& !isInstalledGlobalCodeRef(code)

0 commit comments

Comments
 (0)