Skip to content

Commit d0c6c2f

Browse files
committed
GROOVY-11640: GC pause by Metadata GC Threshold for weeks then turned to Full GC
1 parent fdfd3fa commit d0c6c2f

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
* @since 3.0.0
4242
*/
4343
public class CacheableCallSite extends MutableCallSite {
44-
private static final int CACHE_SIZE = SystemUtil.getIntegerSafe("groovy.indy.callsite.cache.size", 4);
44+
private static final int CACHE_SIZE = SystemUtil.getIntegerSafe("groovy.indy.callsite.cache.size", 8);
4545
private static final float LOAD_FACTOR = 0.75f;
4646
private static final int INITIAL_CAPACITY = (int) Math.ceil(CACHE_SIZE / LOAD_FACTOR) + 1;
4747
private final MethodHandles.Lookup lookup;
4848
private volatile SoftReference<MethodHandleWrapper> latestHitMethodHandleWrapperSoftReference = null;
4949
private final AtomicLong fallbackCount = new AtomicLong();
50+
private final AtomicLong fallbackRound = new AtomicLong();
5051
private MethodHandle defaultTarget;
5152
private MethodHandle fallbackTarget;
5253
private final Map<String, SoftReference<MethodHandleWrapper>> lruCache =
@@ -119,6 +120,11 @@ public long incrementFallbackCount() {
119120

120121
public void resetFallbackCount() {
121122
fallbackCount.set(0);
123+
fallbackRound.incrementAndGet();
124+
}
125+
126+
public AtomicLong getFallbackRound() {
127+
return fallbackRound;
122128
}
123129

124130
public MethodHandle getDefaultTarget() {

src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848
* methods and classes.
4949
*/
5050
public class IndyInterface {
51-
private static final long INDY_OPTIMIZE_THRESHOLD = SystemUtil.getLongSafe("groovy.indy.optimize.threshold", 10_000L);
52-
private static final long INDY_FALLBACK_THRESHOLD = SystemUtil.getLongSafe("groovy.indy.fallback.threshold", 10_000L);
51+
private static final long INDY_OPTIMIZE_THRESHOLD = SystemUtil.getLongSafe("groovy.indy.optimize.threshold", 1_000L);
52+
private static final long INDY_FALLBACK_THRESHOLD = SystemUtil.getLongSafe("groovy.indy.fallback.threshold", 1_000L);
53+
private static final long INDY_FALLBACK_CUTOFF = SystemUtil.getLongSafe("groovy.indy.fallback.cutoff", 100L);
5354

5455
/**
5556
* flags for method and property calls
@@ -327,8 +328,15 @@ public static Object fromCache(CacheableCallSite callSite, Class<?> sender, Stri
327328
}
328329

329330
if (mhw.isCanSetTarget() && (callSite.getTarget() != mhw.getTargetMethodHandle()) && (mhw.getLatestHitCount() > INDY_OPTIMIZE_THRESHOLD)) {
330-
callSite.setTarget(mhw.getTargetMethodHandle());
331-
if (LOG_ENABLED) LOG.info("call site target set, preparing outside invocation");
331+
if (callSite.getFallbackRound().get() > INDY_FALLBACK_CUTOFF) {
332+
if (callSite.getTarget() != callSite.getDefaultTarget()) {
333+
// reset the call site target to default forever to avoid JIT deoptimization storm further
334+
callSite.setTarget(callSite.getDefaultTarget());
335+
}
336+
} else {
337+
callSite.setTarget(mhw.getTargetMethodHandle());
338+
if (LOG_ENABLED) LOG.info("call site target set, preparing outside invocation");
339+
}
332340

333341
mhw.resetLatestHitCount();
334342
}

0 commit comments

Comments
 (0)