You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/02/03 01:45:24 UTC

[groovy] branch GROOVY_4_0_X updated (c87fceb -> a21f980)

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

paulk pushed a change to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from c87fceb  GROOVY-10464: stubgen: super ctor call: handle class cases
     new a843655  GROOVY-10465: Consolidation of VMPlugin didn't account for API calls in the Groovy runtime
     new a21f980  JDK18 test fixes - setting security manager is an UnsupportedOperationException from 18 onwards as part of JEP-411

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:
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java | 140 +++++++++++++++++++++
 .../codehaus/groovy/reflection/SecurityTest.java   |  16 ++-
 2 files changed, 153 insertions(+), 3 deletions(-)
 create mode 100644 src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java

[groovy] 02/02: JDK18 test fixes - setting security manager is an UnsupportedOperationException from 18 onwards as part of JEP-411

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

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

commit a21f980c0b125452f4d41d0fbd77bbf4cf92620b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Feb 3 11:44:48 2022 +1000

    JDK18 test fixes - setting security manager is an UnsupportedOperationException from 18 onwards as part of JEP-411
---
 .../org/codehaus/groovy/reflection/SecurityTest.java     | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/test/org/codehaus/groovy/reflection/SecurityTest.java b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
index cdc4b7c..2020420 100644
--- a/src/test/org/codehaus/groovy/reflection/SecurityTest.java
+++ b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
@@ -138,12 +138,14 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testInvokesPublicMethodsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("publicMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         assertTrue(invokesCachedMethod());
     }
 
     public void testReturnsAccesiblePublicMethodsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("publicMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         assertEquals("publicMethod", cachedMethodUnderTest.setAccessible().getName());
@@ -151,6 +153,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testAccessesPublicFieldsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedFieldUnderTest = createCachedField("publicField");
         System.setSecurityManager(restrictiveSecurityManager);
         TestClass object = new TestClass();
@@ -164,6 +167,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testAccessesPrivateFieldsWithoutSecurityManager() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedFieldUnderTest = createCachedField("privateField");
         System.setSecurityManager(null);
         TestClass object = new TestClass();
@@ -172,6 +176,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testReturnsAccesiblePrivateMethodsWithoutSecurityManager() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("privateMethod");
         System.setSecurityManager(null);
         assertEquals("privateMethod", cachedMethodUnderTest.setAccessible().getName());
@@ -179,6 +184,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testChecksReflectPermissionForInvokeOnPrivateMethods() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("privateMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         try {
@@ -191,6 +197,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testChecksReflectPermissionForFieldAccessOnPrivateFields() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedFieldUnderTest = createCachedField("privateField");
         System.setSecurityManager(restrictiveSecurityManager);
         TestClass object = new TestClass();
@@ -210,6 +217,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testChecksReflectPermissionForMethodAccessOnPrivateMethods() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("privateMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         try {
@@ -228,6 +236,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testInvokesPackagePrivateMethodsWithoutChecksInNonRestrictedPackages() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("packagePrivateMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         assertTrue(invokesCachedMethod());
@@ -235,9 +244,7 @@ public class SecurityTest extends GroovyTestCase {
 
     public void testChecksReflectPermissionForInvokeOnPackagePrivateMethodsInRestrictedJavaPackages() throws Exception {
         // FIX_JDK9 remove this exemption for JDK9
-        if (isAtLeastJdk("9.0")) {
-            return;
-        }
+        if (isAtLeastJdk("9.0")) return;
         cachedMethodUnderTest = createCachedMethod(ClassLoader.class, "getBootstrapClassPath");
         System.setSecurityManager(restrictiveSecurityManager);
 
@@ -251,6 +258,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testInvokesProtectedMethodsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod("protectedMethod");
         System.setSecurityManager(restrictiveSecurityManager);
         assertTrue(invokesCachedMethod());
@@ -278,6 +286,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testInvokesPrivateMethodsInGroovyObjectsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         cachedMethodUnderTest = createCachedMethod(TestGroovyClass.class, "privateMethod");
         TestGroovyClass object = new TestGroovyClass();
         System.setSecurityManager(restrictiveSecurityManager);
@@ -286,6 +295,7 @@ public class SecurityTest extends GroovyTestCase {
     }
 
     public void testAccessesPrivateFieldsInGroovyObjectsWithoutChecks() throws Exception {
+        if (isAtLeastJdk("18.0")) return;
         Field field = TestGroovyClass.class.getDeclaredField("privateField");
         field.setAccessible(true);
         cachedFieldUnderTest = new CachedField(field);

[groovy] 01/02: GROOVY-10465: Consolidation of VMPlugin didn't account for API calls in the Groovy runtime

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

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

commit a843655a9ced6c4765eeaac9849e90c501a63e91
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Jan 28 17:49:24 2022 +1000

    GROOVY-10465: Consolidation of VMPlugin didn't account for API calls in the Groovy runtime
---
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java | 140 +++++++++++++++++++++
 1 file changed, 140 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
new file mode 100644
index 0000000..3a12a52
--- /dev/null
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
@@ -0,0 +1,140 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.vmplugin.v7;
+
+import java.lang.invoke.CallSite;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.MutableCallSite;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Legacy class containing methods called by Groovy 2.5 Indy compiled bytecode.
+ * Includes the interfacing methods with bytecode for invokedynamic and some helper methods and classes.
+ */
+@Deprecated
+public class IndyInterface {
+
+    /**
+     * flags for method and property calls
+     */
+    public static final int
+            SAFE_NAVIGATION = 1, THIS_CALL = 2,
+            GROOVY_OBJECT = 4, IMPLICIT_THIS = 8,
+            SPREAD_CALL = 16, UNCACHED_CALL = 32;
+
+    /**
+     * Enum for easy differentiation between call types
+     */
+    public enum CallType {
+        /**
+         * Method invocation type
+         */
+        METHOD("invoke"),
+        /**
+         * Constructor invocation type
+         */
+        INIT("init"),
+        /**
+         * Get property invocation type
+         */
+        GET("getProperty"),
+        /**
+         * Set property invocation type
+         */
+        SET("setProperty"),
+        /**
+         * Cast invocation type
+         */
+        CAST("cast");
+
+        private static final Map<String, CallType> NAME_CALLTYPE_MAP =
+                Stream.of(CallType.values()).collect(Collectors.toMap(CallType::getCallSiteName, Function.identity()));
+
+        /**
+         * The name of the call site type
+         */
+        private final String name;
+
+        CallType(String callSiteName) {
+            name = callSiteName;
+        }
+
+        /**
+         * Returns the name of the call site type
+         */
+        public String getCallSiteName() {
+            return name;
+        }
+
+        public static CallType fromCallSiteName(String callSiteName) {
+            return NAME_CALLTYPE_MAP.get(callSiteName);
+        }
+    }
+
+    /**
+     * LOOKUP constant used for for example unreflect calls
+     */
+    public static final MethodHandles.Lookup LOOKUP = org.codehaus.groovy.vmplugin.v8.IndyInterface.LOOKUP;
+
+    /**
+     * bootstrap method for method calls from Groovy compiled code with indy
+     * enabled. This method gets a flags parameter which uses the following
+     * encoding:<ul>
+     * <li>{@value #SAFE_NAVIGATION} is the flag value for safe navigation see {@link #SAFE_NAVIGATION}</li>
+     * <li>{@value #THIS_CALL} is the flag value for a call on this see {@link #THIS_CALL}</li>
+     * </ul>
+     *
+     * @param caller   - the caller
+     * @param callType - the type of the call
+     * @param type     - the call site type
+     * @param name     - the real method name
+     * @param flags    - call flags
+     * @return the produced CallSite
+     * @since 2.1.0
+     */
+    public static CallSite bootstrap(Lookup caller, String callType, MethodType type, String name, int flags) {
+        return org.codehaus.groovy.vmplugin.v8.IndyInterface.bootstrap(caller, callType, type, name, flags);
+    }
+
+    /**
+     * Get the cached methodhandle. if the related methodhandle is not found in the inline cache, cache and return it.
+     */
+    public static Object fromCache(MutableCallSite callSite, Class<?> sender, String methodName, int callID, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object dummyReceiver, Object[] arguments) throws Throwable {
+        return org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(callSite, sender, methodName, callID, safeNavigation, thisCall, spreadCall, dummyReceiver, arguments);
+    }
+
+    /**
+     * Core method for indy method selection using runtime types.
+     */
+    public static Object selectMethod(MutableCallSite callSite, Class<?> sender, String methodName, int callID, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object dummyReceiver, Object[] arguments) throws Throwable {
+        return org.codehaus.groovy.vmplugin.v8.IndyInterface.selectMethod(callSite, sender, methodName, callID, safeNavigation, thisCall, spreadCall, dummyReceiver, arguments);
+    }
+
+    /**
+     * @since 2.5.0
+     */
+    public static CallSite staticArrayAccess(MethodHandles.Lookup lookup, String name, MethodType type) {
+        return org.codehaus.groovy.vmplugin.v8.IndyInterface.staticArrayAccess(lookup, name, type);
+    }
+}