[ 
https://issues.apache.org/jira/browse/GROOVY-11935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18074614#comment-18074614
 ] 

ASF GitHub Bot commented on GROOVY-11935:
-----------------------------------------

Copilot commented on code in PR #2473:
URL: https://github.com/apache/groovy/pull/2473#discussion_r3106264697


##########
src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java:
##########
@@ -339,18 +339,28 @@ private static MethodHandle 
fromCacheHandle(CacheableCallSite callSite, Class<?>
             mhw = fallbackSupplier.get();
         }
 
-        if (mhw.isCanSetTarget() && (callSite.getTarget() != 
mhw.getTargetMethodHandle()) && (mhw.getLatestHitCount() > 
INDY_OPTIMIZE_THRESHOLD)) {
-            if (callSite.getFallbackRound().get() > INDY_FALLBACK_CUTOFF) {
-                if (callSite.getTarget() != callSite.getDefaultTarget()) {
-                    // reset the call site target to default forever to avoid 
JIT deoptimization storm further
-                    callSite.setTarget(callSite.getDefaultTarget());
+        if (mhw.isCanSetTarget() && (callSite.getTarget() != 
mhw.getTargetMethodHandle())) {
+            // GROOVY-11935: Set invokedynamic call site target immediately 
for static method calls to enable earlier JIT inlining
+            if (receiver instanceof Class) {
+                var method = mhw.getMethod();
+                if (method != null && 
Modifier.isStatic(method.getModifiers())) {
+                    callSite.setTarget(mhw.getTargetMethodHandle());
                 }
-            } else {
-                callSite.setTarget(mhw.getTargetMethodHandle());
-                if (LOG_ENABLED) LOG.info("call site target set, preparing 
outside invocation");
             }

Review Comment:
   The new “early setTarget” path for static calls runs even when caching was 
intentionally bypassed (e.g., when `bypassCache(...)` is true due to 
per-instance meta classes on the receiver’s class). In those cases 
`latestHitCount` won’t be incremented, but this new block can still relink the 
call site on the first hit, which defeats the bypass-cache safety and can lead 
to stale dispatch when meta behavior is per-instance/mutable.
   
   Suggested fix: gate the early static relink behind the same condition used 
to allow caching (e.g., only run it when `!bypassCache(spreadCall, 
arguments)`), or explicitly ensure the receiver’s class has no per-instance 
meta classes before setting the target.





> Set invokedynamic call site target immediately for static method calls to 
> enable earlier JIT inlining
> -----------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11935
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11935
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> Static calls are inherently monomorphic (receiver is always a Class object) , 
> so no need to wait for the 1,000-hit threshold. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to