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/04/19 08:22:47 UTC

[groovy] branch GROOVY-9513 updated (b0e4095 -> 5965af4)

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

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


    from b0e4095  Remove indy flags thoroughly
     new b8757a0  Revert "Remove indy flags thoroughly"
     new 5965af4  Tweak docs

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:
 .../java/org/codehaus/groovy/classgen/asm/WriterController.java   | 3 ++-
 .../java/org/codehaus/groovy/control/CompilerConfiguration.java   | 8 +++++++-
 src/test/groovy/bugs/Groovy9271.groovy                            | 4 +++-
 .../src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy | 3 +++
 4 files changed, 15 insertions(+), 3 deletions(-)


[groovy] 02/02: Tweak docs

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

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

commit 5965af4ccdf89a869f7693dbbbb859d21200a813
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Apr 19 16:22:16 2020 +0800

    Tweak docs
---
 README.adoc                                              | 12 ------------
 src/spec/doc/tools-groovy.adoc                           |  1 -
 src/spec/doc/tools-groovyc.adoc                          |  1 -
 subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc |  1 -
 4 files changed, 15 deletions(-)

diff --git a/README.adoc b/README.adoc
index 293932c..13d6690 100644
--- a/README.adoc
+++ b/README.adoc
@@ -174,18 +174,6 @@ All code samples of the documentation guide are pulled from actual test cases. T
 
 (Note the omission of package name: class is `semantics.PowerAssertTest` but only `PowerAssertTest` is added to `testSingle`.)
 
-== InvokeDynamic support
-
-The Groovy build supports the JVM instruction `invokedynamic`. If you want to build Groovy with invokedynamic, you can use the project property `indy`:
-
-    gradlew -Pindy=true clean test
-
-Please note that the following Gradle tasks generate both indy and non indy variants of the jars, so you don't need to use the system property:
-
-* dist
-* install
-* uploadArchives
-
 == Continuous Integration Server
 
 The official CI server runs {groovy-ci}[here] and is sponsored by http://www.jetbrains.com[JetBrains].
diff --git a/src/spec/doc/tools-groovy.adoc b/src/spec/doc/tools-groovy.adoc
index caf202c..2e865cc 100644
--- a/src/spec/doc/tools-groovy.adoc
+++ b/src/spec/doc/tools-groovy.adoc
@@ -54,7 +54,6 @@ int (disable any int based optimizations) |
 | -e <script> | | specify an inline command line script | groovy -e "println new Date()"
 | -h | --help | Displays usage information for the command line groovy command | groovy --help
 | -i <extension> | | modify files in place; create backup if extension is given (e.g. '.bak') |
-| | --indy | Enables invokedynamic support. Requires Java 7+ | groovy --indy Person.groovy
 | -l <port> | | listen on a port and process inbound lines (default: 1960) |
 | -n | | process files line by line using implicit 'line' variable |
 | -p | | process files line by line and print result (see also -n) |
diff --git a/src/spec/doc/tools-groovyc.adoc b/src/spec/doc/tools-groovyc.adoc
index 6193db6..3d48d1d 100644
--- a/src/spec/doc/tools-groovyc.adoc
+++ b/src/spec/doc/tools-groovyc.adoc
@@ -47,7 +47,6 @@ a number of command line switches:
 | -e | --exception | Displays the stack trace in case of compilation error | groovyc -e script.groovy
 | -j | --jointCompilation* | Enables joint compilation | groovyc -j A.groovy B.java
 | -b | --basescript | Base class name for scripts (must derive from Script)|
-| -indy | --indy | Enables invokedynamic support. Requires Java 7+ | groovyc --indy Person.groovy
 | | --configscript | Advanced compiler configuration script | groovyc --configscript config/config.groovy src/Person.groovy
 | -Jproperty=value | | Properties to be passed to `javac` if joint compilation is enabled | groovyc -j -Jtarget=1.6 -Jsource=1.6 A.groovy B.java
 | -Fflag | | Flags to be passed to `javac` if joint compilation is enabled | groovyc -j -Fnowarn A.groovy B.java
diff --git a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
index cea3333..6057f70 100644
--- a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
+++ b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
@@ -118,7 +118,6 @@ You might need to use the _contextClassLoader_ attribute (see below) if any of y
 |append|If enabled and output is to a file, append to existing file rather than overwrite. Defaults to false.|No
 |fork|If enabled the script will be executed in a forked JVM process (disabled by default).|No
 |scriptBaseClass|The name of the base class for scripts.|No
-|indy|If enabled the script will be executed with `invokedynamic` (disabled by default).|No
 |parameters|Generates metadata for reflection on method parameter names on JDK 8 and above. Defaults to false. |No
 |useGroovyShell|If enabled a new GroovyShell is used to run the script. Special variables won't be available but you don't need Ant in the classpath. Defaults to false. |No
 |includeAntRuntime|If enabled the system classpath will be included on the classpath when forking. Defaults to true. |No


[groovy] 01/02: Revert "Remove indy flags thoroughly"

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

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

commit b8757a0f8c45b88f7d53da7b69c2bcf734a9c932
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Apr 19 16:20:11 2020 +0800

    Revert "Remove indy flags thoroughly"
    
    This reverts commit b0e4095a
---
 README.adoc                                                  | 12 ++++++++++++
 .../org/codehaus/groovy/classgen/asm/WriterController.java   |  3 ++-
 .../org/codehaus/groovy/control/CompilerConfiguration.java   |  8 +++++++-
 src/spec/doc/tools-groovy.adoc                               |  1 +
 src/spec/doc/tools-groovyc.adoc                              |  1 +
 src/test/groovy/bugs/Groovy9271.groovy                       |  4 +++-
 subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc     |  1 +
 .../groovy/groovy/console/SwingBuilderConsoleTest.groovy     |  3 +++
 8 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/README.adoc b/README.adoc
index 13d6690..293932c 100644
--- a/README.adoc
+++ b/README.adoc
@@ -174,6 +174,18 @@ All code samples of the documentation guide are pulled from actual test cases. T
 
 (Note the omission of package name: class is `semantics.PowerAssertTest` but only `PowerAssertTest` is added to `testSingle`.)
 
+== InvokeDynamic support
+
+The Groovy build supports the JVM instruction `invokedynamic`. If you want to build Groovy with invokedynamic, you can use the project property `indy`:
+
+    gradlew -Pindy=true clean test
+
+Please note that the following Gradle tasks generate both indy and non indy variants of the jars, so you don't need to use the system property:
+
+* dist
+* install
+* uploadArchives
+
 == Continuous Integration Server
 
 The official CI server runs {groovy-ci}[here] and is sponsored by http://www.jetbrains.com[JetBrains].
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 38fc9ba..fe8dc41 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -80,13 +80,14 @@ 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();
-        final boolean invokedynamic = true;
+        boolean invokedynamic = false;
         if (optOptions.isEmpty()) {
             // IGNORE
         } else if (Boolean.FALSE.equals(optOptions.get("all"))) {
             this.optimizeForInt = false;
             // set other optimizations options to false here
         } else {
+            if (Boolean.TRUE.equals(optOptions.get(CompilerConfiguration.INVOKEDYNAMIC))) invokedynamic = true;
             if (Boolean.FALSE.equals(optOptions.get("int"))) this.optimizeForInt = false;
             if (invokedynamic) this.optimizeForInt = false;
             // set other optimizations options to false here
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 9fc0cc3..6422184 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -48,6 +48,9 @@ import static org.codehaus.groovy.runtime.StringGroovyMethods.isAtLeast;
  */
 public class CompilerConfiguration {
 
+    /** Optimization Option for enabling <code>invokedynamic</code> compilation. */
+    public static final String INVOKEDYNAMIC = "indy";
+
     /** Optimization Option for enabling attaching groovydoc as AST node metadata. */
     public static final String GROOVYDOC = "groovydoc";
 
@@ -412,6 +415,7 @@ public class CompilerConfiguration {
      * <blockquote>
      * <table summary="Groovy Compiler Optimization Options Configuration Properties">
      *   <tr><th>Property Key</th><th>Related Property Getter</th></tr>
+     *   <tr><td><code>groovy.target.indy</code></td><td>{@link #getOptimizationOptions}</td></tr>
      *   <tr><td><code>groovy.attach.groovydoc</code></td><td>{@link #getOptimizationOptions}</td></tr>
      *   <tr><td><code>groovy.attach.runtime.groovydoc</code></td><td>{@link #getOptimizationOptions}</td></tr>
      * </table>
@@ -432,6 +436,7 @@ public class CompilerConfiguration {
         defaultScriptExtension = getSystemPropertySafe("groovy.default.scriptExtension", ".groovy");
 
         optimizationOptions = new HashMap<>(4);
+        handleOptimizationOption(optimizationOptions, INVOKEDYNAMIC, "groovy.target.indy", "true");
         handleOptimizationOption(optimizationOptions, GROOVYDOC, "groovy.attach.groovydoc");
         handleOptimizationOption(optimizationOptions, RUNTIME_GROOVYDOC, "groovy.attach.runtime.groovydoc");
     }
@@ -1060,7 +1065,8 @@ public class CompilerConfiguration {
      * Checks if invoke dynamic is enabled.
      */
     public boolean isIndyEnabled() {
-        return true;
+        Boolean indyEnabled = getOptimizationOptions().get(INVOKEDYNAMIC);
+        return Optional.ofNullable(indyEnabled).orElse(Boolean.FALSE);
     }
 
     /**
diff --git a/src/spec/doc/tools-groovy.adoc b/src/spec/doc/tools-groovy.adoc
index 2e865cc..caf202c 100644
--- a/src/spec/doc/tools-groovy.adoc
+++ b/src/spec/doc/tools-groovy.adoc
@@ -54,6 +54,7 @@ int (disable any int based optimizations) |
 | -e <script> | | specify an inline command line script | groovy -e "println new Date()"
 | -h | --help | Displays usage information for the command line groovy command | groovy --help
 | -i <extension> | | modify files in place; create backup if extension is given (e.g. '.bak') |
+| | --indy | Enables invokedynamic support. Requires Java 7+ | groovy --indy Person.groovy
 | -l <port> | | listen on a port and process inbound lines (default: 1960) |
 | -n | | process files line by line using implicit 'line' variable |
 | -p | | process files line by line and print result (see also -n) |
diff --git a/src/spec/doc/tools-groovyc.adoc b/src/spec/doc/tools-groovyc.adoc
index 3d48d1d..6193db6 100644
--- a/src/spec/doc/tools-groovyc.adoc
+++ b/src/spec/doc/tools-groovyc.adoc
@@ -47,6 +47,7 @@ a number of command line switches:
 | -e | --exception | Displays the stack trace in case of compilation error | groovyc -e script.groovy
 | -j | --jointCompilation* | Enables joint compilation | groovyc -j A.groovy B.java
 | -b | --basescript | Base class name for scripts (must derive from Script)|
+| -indy | --indy | Enables invokedynamic support. Requires Java 7+ | groovyc --indy Person.groovy
 | | --configscript | Advanced compiler configuration script | groovyc --configscript config/config.groovy src/Person.groovy
 | -Jproperty=value | | Properties to be passed to `javac` if joint compilation is enabled | groovyc -j -Jtarget=1.6 -Jsource=1.6 A.groovy B.java
 | -Fflag | | Flags to be passed to `javac` if joint compilation is enabled | groovyc -j -Fnowarn A.groovy B.java
diff --git a/src/test/groovy/bugs/Groovy9271.groovy b/src/test/groovy/bugs/Groovy9271.groovy
index f9b8298..9ab9124 100644
--- a/src/test/groovy/bugs/Groovy9271.groovy
+++ b/src/test/groovy/bugs/Groovy9271.groovy
@@ -19,6 +19,7 @@
 package groovy.bugs
 
 import groovy.transform.CompileStatic
+import org.codehaus.groovy.control.CompilerConfiguration
 import org.junit.Test
 
 @CompileStatic
@@ -26,7 +27,8 @@ final class Groovy9271 {
 
     @Test
     void testBracketsInMethodNameWithIndy() {
-        new GroovyShell().evaluate '''
+        def config = new CompilerConfiguration(optimizationOptions: [indy: true])
+        new GroovyShell(config).evaluate '''
             class Bar {
                 private char letter = 'o'
                 int 'foo$()bar'() {
diff --git a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
index 6057f70..cea3333 100644
--- a/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
+++ b/subprojects/groovy-ant/src/spec/doc/groovy-ant-task.adoc
@@ -118,6 +118,7 @@ You might need to use the _contextClassLoader_ attribute (see below) if any of y
 |append|If enabled and output is to a file, append to existing file rather than overwrite. Defaults to false.|No
 |fork|If enabled the script will be executed in a forked JVM process (disabled by default).|No
 |scriptBaseClass|The name of the base class for scripts.|No
+|indy|If enabled the script will be executed with `invokedynamic` (disabled by default).|No
 |parameters|Generates metadata for reflection on method parameter names on JDK 8 and above. Defaults to false. |No
 |useGroovyShell|If enabled a new GroovyShell is used to run the script. Special variables won't be available but you don't need Ant in the classpath. Defaults to false. |No
 |includeAntRuntime|If enabled the system classpath will be included on the classpath when forking. Defaults to true. |No
diff --git a/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy b/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
index 30ae0da..6d57206 100644
--- a/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
+++ b/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
@@ -24,6 +24,7 @@ import groovy.console.ui.view.BasicMenuBar
 import groovy.console.ui.view.MacOSXMenuBar
 import groovy.swing.GroovySwingTestCase
 import groovy.swing.SwingBuilder
+import org.codehaus.groovy.control.CompilerConfiguration
 import org.junit.rules.TemporaryFolder
 
 import javax.swing.JTextPane
@@ -590,10 +591,12 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
                 console.inputEditor.textEditor.text = scriptSource
 
                 console.runScript(new EventObject([:]))
+                assert console.config.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
                 assert outputDocument.getText(0, outputDocument.length) == 'Result: foobar'
 
                 console.outputArea.text = ''
                 console.runScript(new EventObject([:]))
+                assert console.config.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
                 assert outputDocument.getText(0, outputDocument.length) == 'Result: foobar'
             } finally {
                 GroovySystem.metaClassRegistry.removeMetaClass(Thread)