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 2021/06/14 07:53:29 UTC

[groovy] branch danielsun/tweak-build updated (2c5c26b -> 423048c)

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

sunlan pushed a change to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 2c5c26b  GROOVY-10138: [JDK16] Failed to invoke default method of proxy
     new a6f8dc4  Tweak `ProxyMethodHandle`
     new 423048c  Exclude jdk16 vmplugin classes conditionally

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 buildSrc/src/main/groovy/org.apache.groovy-core.gradle   | 12 ++++++++++++
 .../codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java  | 16 ++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

[groovy] 01/02: Tweak `ProxyMethodHandle`

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit a6f8dc48967408e76a2abea4791a465de8a309bd
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jun 14 15:48:25 2021 +0800

    Tweak `ProxyMethodHandle`
---
 .../codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java  | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java b/src/main/java/org/codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java
index d6a1e39..90afca2 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v16/ProxyMethodHandle.java
@@ -2,16 +2,23 @@ package org.codehaus.groovy.vmplugin.v16;
 
 import org.codehaus.groovy.GroovyBugError;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 
 class ProxyMethodHandle {
-    private static final Method INVOKE_DEFAULT_METHOD;
+    private static final MethodHandle INVOKE_DEFAULT_METHOD_HANDLE;
     static {
         try {
-            INVOKE_DEFAULT_METHOD = InvocationHandler.class.getDeclaredMethod("invokeDefault", Object.class, Method.class, Object[].class);
-        } catch (NoSuchMethodException e) {
+            // `invokeDefault` is JDK 16+ API, but we still build Groovy with JDK11,
+            // so use method handle instead of invoking the method directly
+            INVOKE_DEFAULT_METHOD_HANDLE = MethodHandles.lookup().findStatic(
+                                                InvocationHandler.class, "invokeDefault",
+                                                MethodType.methodType(Object.class, Object.class, Method.class, Object[].class));
+        } catch (NoSuchMethodException | IllegalAccessException e) {
             throw new GroovyBugError(e);
         }
     }
@@ -25,6 +32,7 @@ class ProxyMethodHandle {
     }
 
     Object invokeWithArguments(Object... arguments) throws Throwable {
-        return INVOKE_DEFAULT_METHOD.invoke(null, proxy, method, arguments);
+        Object proxy = this.proxy;
+        return INVOKE_DEFAULT_METHOD_HANDLE.invokeExact(proxy, method, arguments);
     }
 }

[groovy] 02/02: Exclude jdk16 vmplugin classes conditionally

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 423048c8859d9aaeff8cf557c95d330ae4101d0b
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jun 14 15:53:04 2021 +0800

    Exclude jdk16 vmplugin classes conditionally
---
 buildSrc/src/main/groovy/org.apache.groovy-core.gradle | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/buildSrc/src/main/groovy/org.apache.groovy-core.gradle b/buildSrc/src/main/groovy/org.apache.groovy-core.gradle
index e937221..fb52abf 100644
--- a/buildSrc/src/main/groovy/org.apache.groovy-core.gradle
+++ b/buildSrc/src/main/groovy/org.apache.groovy-core.gradle
@@ -50,6 +50,10 @@ sourceSets {
                 exclude '**/v10/*'
                 exclude '**/vm10/*'
             }
+            if (!JavaVersion.current().isJava11Compatible()) {
+                exclude '**/v16/*'
+                exclude '**/vm16/*'
+            }
         }
         groovy {
             if (!JavaVersion.current().isJava9Compatible()) {
@@ -60,6 +64,10 @@ sourceSets {
                 exclude '**/v10/*'
                 exclude '**/vm10/*'
             }
+            if (!JavaVersion.current().isJava11Compatible()) {
+                exclude '**/v16/*'
+                exclude '**/vm16/*'
+            }
         }
         antlr {
             srcDirs = ['src/antlr']
@@ -79,6 +87,10 @@ sourceSets {
                 exclude '**/v10/*'
                 exclude '**/vm10/*'
             }
+            if (!JavaVersion.current().isJava11Compatible()) {
+                exclude '**/v16/*'
+                exclude '**/vm16/*'
+            }
         }
         resources {
             srcDirs += ['src/test-resources']