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 2020/07/19 14:23:50 UTC

[groovy] branch danielsun/tweak-vmplugin updated (9c5db3c -> a550854)

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

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


 discard 9c5db3c  Try to fix the failing build on JDK14
     add 19ad9b6  fix unintentional glitch on JDK14
     new a550854  Minor tweak: create `Lookup` instance according to vm plugin

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (9c5db3c)
            \
             N -- N -- N   refs/heads/danielsun/tweak-vmplugin (a550854)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:


[groovy] 01/01: Minor tweak: create `Lookup` instance according to vm plugin

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-vmplugin
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit a5508545087d7a4b0ed7e150c264caac6952e8af
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 19 22:22:53 2020 +0800

    Minor tweak: create `Lookup` instance according to vm plugin
---
 src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java | 11 ++++++-----
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 15 +++++----------
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
index bf865da..c8e2301 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
@@ -141,6 +141,10 @@ public class Java8 implements VMPlugin {
         mn.setAnnotationDefault(true);
     }
 
+    protected MethodHandles.Lookup newLookup(final Class<?> declaringClass) {
+        return of(declaringClass);
+    }
+
     private static Constructor<MethodHandles.Lookup> getLookupConstructor() {
         return LookupHolder.LOOKUP_Constructor;
     }
@@ -618,16 +622,13 @@ public class Java8 implements VMPlugin {
     public Object getInvokeSpecialHandle(Method method, Object receiver) {
         final Class<?> receiverType = receiver.getClass();
         try {
-            return of(receiverType).unreflectSpecial(method, receiverType).bindTo(receiver);
+            return newLookup(receiverType).unreflectSpecial(method, receiverType).bindTo(receiver);
         } catch (ReflectiveOperationException e) {
             return getInvokeSpecialHandleFallback(method, receiver);
         }
     }
 
     private Object getInvokeSpecialHandleFallback(Method method, Object receiver) {
-        if (getLookupConstructor() == null) {
-            throw new GroovyBugError("getInvokeSpecialHandle requires at least JDK 7 for private access to Lookup");
-        }
         if (!method.isAccessible()) {
             AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
                 ReflectionUtils.trySetAccessible(method);
@@ -636,7 +637,7 @@ public class Java8 implements VMPlugin {
         }
         Class<?> declaringClass = method.getDeclaringClass();
         try {
-            return getLookupConstructor().newInstance(declaringClass, -1).
+            return newLookup(declaringClass).
                     unreflectSpecial(method, declaringClass).
                     bindTo(receiver);
         } catch (ReflectiveOperationException e) {
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 9249449..90a21c2 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -156,6 +156,11 @@ public class Java9 extends Java8 {
         }
     }
 
+    @Override
+    protected MethodHandles.Lookup newLookup(final Class<?> declaringClass) {
+        return of(declaringClass);
+    }
+
     private static Constructor<MethodHandles.Lookup> getLookupConstructor() {
         return LookupHolder.LOOKUP_Constructor;
     }
@@ -188,16 +193,6 @@ public class Java9 extends Java8 {
         return 9;
     }
 
-    @Override
-    public Object getInvokeSpecialHandle(Method method, Object receiver) {
-        final Class<?> receiverType = receiver.getClass();
-        try {
-            return of(receiverType).unreflectSpecial(method, receiverType).bindTo(receiver);
-        } catch (ReflectiveOperationException e) {
-            return super.getInvokeSpecialHandle(method, receiver);
-        }
-    }
-
     /**
      * This method may be used by a caller in class C to check whether to enable access to a member of declaring class D successfully
      * if {@link Java8#checkCanSetAccessible(java.lang.reflect.AccessibleObject, java.lang.Class)} returns true and any of the following hold: