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

blackdrag pushed a commit to branch feature/indy_perf
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 4fa8fb20df328a841d1b8318079e3408b9888ec5
Author: Jochen Theodorou <[email protected]>
AuthorDate: Thu Dec 21 13:18:43 2023 +0100

    make use of Runtime.version().feature()
---
 build.gradle                                       | 41 +++++++++++++++++-----
 gradle.properties                                  |  3 ++
 .../codehaus/groovy/control/ClassNodeResolver.java |  2 +-
 .../groovy/control/CompilerConfiguration.java      | 11 ++++--
 .../org/codehaus/groovy/vmplugin/VMPlugin.java     |  2 ++
 .../codehaus/groovy/vmplugin/VMPluginFactory.java  | 15 ++++----
 src/test/indy/perf/IndyPerfUtil.java               |  3 +-
 .../groovysh/util/SecurityManagerUtil.groovy       | 11 +++---
 8 files changed, 60 insertions(+), 28 deletions(-)

diff --git a/build.gradle b/build.gradle
index 3de27101c5..e6baa3c742 100644
--- a/build.gradle
+++ b/build.gradle
@@ -220,15 +220,6 @@ tasks.named('test') {
     dependsOn testExtensionModuleJar
 }
 
-if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
-    logger.lifecycle '''
-************************************* WARNING 
***********************************************
-****  You're running the build with an older JDK. NEVER try to release with an 
old JDK!  ****
-****  You must use a JDK 16+ in order to compile all features of the language. 
          ****
-*********************************************************************************************
-'''
-}
-
 apply from: 'gradle/licenses.gradle'
 
 // CC: This can probably be removed as the native IDEA import
@@ -266,3 +257,35 @@ tasks.named("dependencyUpdates")?.configure {
         !(it.currentVersion.toLowerCase() ==~ UNSTABLE) && 
it.candidate.version.toLowerCase() ==~ UNSTABLE
     }
 }
+
+def indyTests = [
+"IndyDirectTest",
+"IndyDoubleDispatchTest",
+"IndyPromotionTest",
+"RuntimeCallsiteGenTest",
+"SimpleReflectiveTest",
+"StaticCallsiteGenTest"]
+
+indyTests.each {name ->
+    tasks.register(name, JavaExec) {
+        javaLauncher = javaToolchains.launcherFor {
+            languageVersion = JavaLanguageVersion.of(23)
+        }
+        classpath = sourceSets.test.runtimeClasspath
+        mainClass = "indy.perf." + name
+    }
+}
+
+task('indyAll') {
+    dependsOn(indyTests)
+}
+
+tasks.register("main", JavaExec) {
+    javaLauncher = javaToolchains.launcherFor {
+        languageVersion = JavaLanguageVersion.of(23)
+    }
+    classpath = sourceSets.main.runtimeClasspath
+    mainClass = "groovy.ui.GroovyMain"
+    args("-d","t.groovy")
+    it.workingDir("/home/blackdrag/coding/releases")
+}
diff --git a/gradle.properties b/gradle.properties
index 0b143764f2..4e8c2cce02 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -49,3 +49,6 @@ org.gradle.java.compile-classpath-packaging=true
 
 # make dependency-verification lenient
 org.gradle.dependency.verification=lenient
+
+
+org.gradle.java.installations.paths=/opt/jdk-11_28,/opt/jdk-13.0.1,/opt/jdk-15.36,/opt/jdk-16.36,/opt/jdk-17.0.7,/opt/jdk-18.0.1.1,/opt/jdk-21_ea_26,/opt/jdk-23_ea_2
diff --git a/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java 
b/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
index 8be558d3e1..3a2fa62824 100644
--- a/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
+++ b/src/main/java/org/codehaus/groovy/control/ClassNodeResolver.java
@@ -257,7 +257,7 @@ public class ClassNodeResolver {
                     // this may happen under Windows because getResource is 
case-insensitive under that OS!
                     asmClass = null;
                 }
-            } catch (IOException e) {
+            } catch (Exception e) {
                 // fall through and attempt other search strategies
             }
         }
diff --git 
a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java 
b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 6d9522acd5..735e28e1d3 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -23,7 +23,6 @@ import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.control.customizers.CompilationCustomizer;
 import org.codehaus.groovy.control.io.NullWriter;
 import org.codehaus.groovy.control.messages.WarningMessage;
-import org.codehaus.groovy.vmplugin.VMPlugin;
 import org.objectweb.asm.Opcodes;
 
 import java.io.File;
@@ -643,6 +642,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 11+
      */
+    @Deprecated
     public static boolean isPostJDK11(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK11);
     }
@@ -653,6 +653,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 12+
      */
+    @Deprecated
     public static boolean isPostJDK12(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK12);
     }
@@ -663,6 +664,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 13+
      */
+    @Deprecated
     public static boolean isPostJDK13(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK13);
     }
@@ -673,6 +675,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 14+
      */
+    @Deprecated
     public static boolean isPostJDK14(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK14);
     }
@@ -683,6 +686,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 15+
      */
+    @Deprecated
     public static boolean isPostJDK15(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK15);
     }
@@ -693,6 +697,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 16+
      */
+    @Deprecated
     public static boolean isPostJDK16(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK16);
     }
@@ -703,6 +708,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 17+
      */
+    @Deprecated
     public static boolean isPostJDK17(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK17);
     }
@@ -713,6 +719,7 @@ public class CompilerConfiguration {
      * @param bytecodeVersion The parameter can take one of the values in 
{@link #ALLOWED_JDKS}.
      * @return true if the bytecode version is JDK 18+
      */
+    @Deprecated
     public static boolean isPostJDK18(final String bytecodeVersion) {
         return isAtLeast(bytecodeVersion, JDK18);
     }
@@ -1115,7 +1122,7 @@ public class CompilerConfiguration {
      * @since 4.0.0
      */
     private static String defaultTargetBytecode() {
-        final String javaVersion = VMPlugin.getJavaVersion();
+        String javaVersion = Integer.toString(Runtime.version().feature());
         if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(javaVersion)) {
             return javaVersion;
         }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java 
b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index 5c27d9bb8e..602b452bf6 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -76,7 +76,9 @@ public interface VMPlugin {
      *
      * @return java version
      * @since 4.0.0
+     * @deprecated
      */
+    @Deprecated
     static String getJavaVersion() {
         try {
             return System.getProperty("java.specification.version");
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java 
b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
index 978d8c5308..875a184c55 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
@@ -21,7 +21,6 @@ package org.codehaus.groovy.vmplugin;
 import org.apache.groovy.util.Maps;
 import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 
-import java.math.BigDecimal;
 import java.util.Map;
 
 /**
@@ -31,12 +30,10 @@ import java.util.Map;
  */
 public class VMPluginFactory {
 
-    private static final Map<BigDecimal,String> PLUGIN_MAP = Maps.of(
+    private static final Map<Integer,String> PLUGIN_MAP = Maps.of(
         // NOTE: Declare the vm plugin entries in *descending* order!
-        new BigDecimal( "16"), "org.codehaus.groovy.vmplugin.v16.Java16",
-        new BigDecimal( "10"), "org.codehaus.groovy.vmplugin.v10.Java10",
-        new BigDecimal(  "9"), "org.codehaus.groovy.vmplugin.v9.Java9",
-        new BigDecimal("1.8"), "org.codehaus.groovy.vmplugin.v8.Java8"
+        16, "org.codehaus.groovy.vmplugin.v16.Java16",
+        10, "org.codehaus.groovy.vmplugin.v10.Java10"
     );
 
     private static final VMPlugin PLUGIN = createPlugin();
@@ -44,9 +41,9 @@ public class VMPluginFactory {
     private static VMPlugin createPlugin() {
         return doPrivileged(() -> {
             ClassLoader loader = VMPluginFactory.class.getClassLoader();
-            BigDecimal specVer = new BigDecimal(VMPlugin.getJavaVersion());
-            for (Map.Entry<BigDecimal,String> entry : PLUGIN_MAP.entrySet()) {
-                if (DefaultGroovyMethods.isAtLeast(specVer, entry.getKey())) {
+            int specVer = Runtime.version().feature();
+            for (Map.Entry<Integer,String> entry : PLUGIN_MAP.entrySet()) {
+                if (specVer >= entry.getKey()) {
                     String fullName = entry.getValue();
                     try {
                         return (VMPlugin) 
loader.loadClass(fullName).getDeclaredConstructor().newInstance();
diff --git a/src/test/indy/perf/IndyPerfUtil.java 
b/src/test/indy/perf/IndyPerfUtil.java
index aa9bf02175..ba202d93a8 100644
--- a/src/test/indy/perf/IndyPerfUtil.java
+++ b/src/test/indy/perf/IndyPerfUtil.java
@@ -26,7 +26,7 @@ public class IndyPerfUtil {
     private static final int TEST_ITERATIONS = 10;
     private static final int HOT_LOOP_ITERATIONS = 100_000;
     public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
-    private static boolean WRITE_FILE = true;
+    private static boolean WRITE_FILE = false;
 
     private static long getTotal(long[] times, int length) {
         long t_diff = 0;
@@ -209,6 +209,7 @@ public class IndyPerfUtil {
     }
 
     public static void executeTests(Class<?> clazz) {
+        System.out.println("running on JDK "+ Runtime.version());
         try {
             final Object instance = 
clazz.getDeclaredConstructor().newInstance();
 
diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/util/SecurityManagerUtil.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/util/SecurityManagerUtil.groovy
index b16daa5088..026535c953 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/util/SecurityManagerUtil.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/util/SecurityManagerUtil.groovy
@@ -18,9 +18,6 @@
  */
 package org.apache.groovy.groovysh.util
 
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.vmplugin.VMPlugin
-
 class SecurityManagerUtil {
     private final SecurityManager saved
 
@@ -28,14 +25,16 @@ class SecurityManagerUtil {
         if (explicitlyEnabled() || autoEnabledUntilJDK17()) {
             saved = System.getSecurityManager()
             System.setSecurityManager(new NoExitSecurityManager())
+        } else {
+            saved = null;
         }
     }
 
-    private boolean autoEnabledUntilJDK17() {
-        !CompilerConfiguration.isPostJDK18(VMPlugin.getJavaVersion())
+    private static boolean autoEnabledUntilJDK17() {
+        return Runtime.version().feature() < 18;
     }
 
-    private boolean explicitlyEnabled() {
+    private static boolean explicitlyEnabled() {
         System.getProperty('java.security.manager', 'disallow') == 'allow'
     }
 

Reply via email to