You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/12/13 06:28:35 UTC

[groovy] branch master updated: GROOVY-9513: Enable indy by default

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e36fc3e88 GROOVY-9513: Enable indy by default
6e36fc3e88 is described below

commit 6e36fc3e887297294094b686fc4819391414843c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Dec 5 01:43:08 2022 +0800

    GROOVY-9513: Enable indy by default
---
 .../groovy/classgen/asm/WriterController.java      |  8 +++---
 .../codehaus/groovy/vmplugin/v8/IndyInterface.java | 30 ++++++++++++++--------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index 39f05cb26e..97b7000f87 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -76,18 +76,20 @@ public class WriterController {
     public void init(final AsmClassGenerator asmClassGenerator, final GeneratorContext gcon, final ClassVisitor cv, final ClassNode cn) {
         CompilerConfiguration config = cn.getCompileUnit().getConfig();
         Map<String,Boolean> optOptions = config.getOptimizationOptions();
-        boolean invokedynamic = false;
+        boolean invokedynamic = true;
         if (optOptions.isEmpty()) {
             // IGNORE
         } else if (Boolean.FALSE.equals(optOptions.get("all"))) {
+            invokedynamic = false;
             this.optimizeForInt = false;
             // set other optimizations options to false here
         } else {
-            if (config.isIndyEnabled()) invokedynamic = true;
+            if (!config.isIndyEnabled()) invokedynamic = false;
             if (Boolean.FALSE.equals(optOptions.get("int"))) this.optimizeForInt = false;
-            if (invokedynamic) this.optimizeForInt = false;
             // set other optimizations options to false here
         }
+        if (invokedynamic) this.optimizeForInt = false;
+
         this.classNode = cn;
         this.outermostClass = null;
         this.internalClassName = BytecodeHelper.getClassInternalName(cn);
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
index 746a6d8495..4d2ae2b300 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
@@ -21,6 +21,7 @@ package org.codehaus.groovy.vmplugin.v8;
 import groovy.lang.GroovySystem;
 import org.apache.groovy.util.SystemUtil;
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.reflection.ClassInfo;
 import org.codehaus.groovy.runtime.NullObject;
 
 import java.lang.invoke.CallSite;
@@ -292,17 +293,19 @@ public class IndyInterface {
         FallbackSupplier fallbackSupplier = new FallbackSupplier(callSite, sender, methodName, callID, safeNavigation, thisCall, spreadCall, dummyReceiver, arguments);
 
         MethodHandleWrapper mhw =
-                doWithCallSite(
-                        callSite, arguments,
-                        (cs, receiver) ->
-                                cs.getAndPut(
-                                        receiver.getClass().getName(),
-                                        c -> {
-                                            MethodHandleWrapper fbMhw = fallbackSupplier.get();
-                                            return fbMhw.isCanSetTarget() ? fbMhw : NULL_METHOD_HANDLE_WRAPPER;
-                                        }
-                                )
-                );
+                bypassCache(arguments)
+                    ? NULL_METHOD_HANDLE_WRAPPER
+                    : doWithCallSite(
+                            callSite, arguments,
+                            (cs, receiver) ->
+                                    cs.getAndPut(
+                                            receiver.getClass().getName(),
+                                            c -> {
+                                                MethodHandleWrapper fbMhw = fallbackSupplier.get();
+                                                return fbMhw.isCanSetTarget() ? fbMhw : NULL_METHOD_HANDLE_WRAPPER;
+                                            }
+                                    )
+                    );
 
         if (NULL_METHOD_HANDLE_WRAPPER == mhw) {
             mhw = fallbackSupplier.get();
@@ -318,6 +321,11 @@ public class IndyInterface {
         return mhw.getCachedMethodHandle().invokeExact(arguments);
     }
 
+    private static boolean bypassCache(Object[] arguments) {
+        final Object receiver = arguments[0];
+        return null != receiver && ClassInfo.getClassInfo(receiver.getClass()).hasPerInstanceMetaClasses();
+    }
+
     /**
      * Core method for indy method selection using runtime types.
      */