You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/05/07 04:56:51 UTC

[1/2] groovy git commit: Clarify documentation around indy (closes #530)

Repository: groovy
Updated Branches:
  refs/heads/master 323155c5e -> 6b70bbc94


Clarify documentation around indy (closes #530)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6edd6141
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6edd6141
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6edd6141

Branch: refs/heads/master
Commit: 6edd61410e75f5bb03497b7c08e949779889f40b
Parents: 323155c
Author: John Wagenleitner <jw...@apache.org>
Authored: Sun Apr 30 11:07:34 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 6 20:43:34 2017 -0700

----------------------------------------------------------------------
 src/spec/doc/invokedynamic-support.adoc | 31 ++++++++++++++++++----------
 1 file changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6edd6141/src/spec/doc/invokedynamic-support.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/invokedynamic-support.adoc b/src/spec/doc/invokedynamic-support.adoc
index 944d938..9b0bc70 100644
--- a/src/spec/doc/invokedynamic-support.adoc
+++ b/src/spec/doc/invokedynamic-support.adoc
@@ -24,11 +24,10 @@
 
 == Foreword
 
-Since Groovy 2.0, we added support for the JVM http://docs.oracle.com/javase/7/docs/technotes/guides/vm/multiple-language-support.html#invokedynamic[invokedynamic] instruction. This instruction is supported since Java 7 and is a new bytecode instruction in the JVM that allows easier implementation of dynamic languages. This instruction will also be used internally, by the JVM, for the lambda support in Java 8.
+Since Groovy 2.0, support was added for the JVM http://docs.oracle.com/javase/7/docs/technotes/guides/vm/multiple-language-support.html#invokedynamic[invokedynamic] instruction. This instruction is supported since Java 7 and is a new bytecode instruction in the JVM that allows easier implementation of dynamic languages. This instruction will also be used internally, by the JVM, for the lambda support in Java 8.
 
 This means that unlike APIs, AST transformations or syntactic sugar, this feature is **not visible** to the developer or the end user. It is a compilation and runtime feature only. This means that given two programs written in Groovy, you have the choice to compile it with or without invokedynamic support. Whatever you choose, it comes with pros and cons:
 
-- call site caching, as implemented in "normal" Groovy is replaced with invokedynamic since Groovy 2.1
 - it is possible to mix classes compiled with and without invokedynamic in the same project, as long as you run JDK 1.7+
 - depending on the JVM (even different minor versions of the JVM), you can target close to Java performance for dynamic Groovy with invokedynamic support activated
 
@@ -38,15 +37,20 @@ This means that unlike APIs, AST transformations or syntactic sugar, this featur
 
 The Groovy distribution comes with **two** jars:
 
-- groovy-x.y.z.jar : makes use of call site caching
-- groovy-x-y-z-indy.jar : has invokedynamic support bundled, old call site caching still possible
+- groovy-x.y.z.jar : contains Groovy sources compiled with call site caching
+- groovy-x-y-z-indy.jar : contains Groovy sources compiled with invokedynamic instructions
 
-The first jar is Groovy compiled without invokedynamic support, while the second one has invokedynamic support bundled. As Groovy core and the groovy modules are sometimes written in Groovy, we currently have no choice but issuing two distinct versions of Groovy. This means that if you pick the "normal" jar, the groovy classes of groovy itself are compiled with call site caching (1.5+), while if you use the "indy" jar, the groovy classes of groovy itself are compiled using invokedynamic. This means that the invokedynamic version of Groovy doesn't make use of the old call site caching mechanism.
+As Groovy core and the Groovy modules are sometimes written in Groovy, we currently have no choice but to distribute two
+distinct versions of Groovy. This means that if you pick the "normal" jar, the Groovy classes of Groovy itself are
+compiled with call site caching (1.6+), while if you use the "indy" jar, the Groovy classes of Groovy itself are
+compiled using invokedynamic.
 
-Both jars contain a fully working groovy implementation. They are mutually exclusive (don't put both on classpath).
+Both jars contain a fully working Groovy implementation that is capable of compiling user supplied Groovy sources using either
+invokedynamic or call site caching. The sets of jars are mutually exclusive (don't put both on classpath) and the key difference between
+them has to do with how the Groovy source files that make up Groovy itself are compiled.
 
 === Command-line and indy
-If you download the distribution and that you use the command line, it's always the "normal" version of Groovy which is picked up in classpath. This means that whatever command you use (`groovy`, `groovyc`, `groovysh` or `groovyConsole`), invokedynamic support is not available out of the box. To use the invokedynamic version, you have to switch the jars manually. The distribution makes use of the jars in the ++lib++ directory, while the indy jars are available in the ++indy++ directory. You have three things to do:
+If you download the distribution and use the command line, it's always the "normal" version of Groovy which is picked up in classpath. This means that whatever command you use (`groovy`, `groovyc`, `groovysh` or `groovyConsole`), invokedynamic support is not available out of the box. To use a Groovy distribution that was compiled with invokedynamic for its Groovy sources you have to switch the jars manually. The distribution makes use of the jars in the ++lib++ directory, while the indy jars are available in the ++indy++ directory. You have three things to do:
 
 - remove or rename the groovy-*.jar files in the lib directory
 - replace them with the indy version from the indy directory
@@ -59,9 +63,14 @@ Here's a bash script that would do it all at once:
 $ for f in `ls lib/groovy*.jar | cut -d/ -f2`;do k=`basename $f .jar`; mv lib/$k.jar lib/$k.jar.old; cp indy/$k-indy.jar lib/$k.jar ; done
 ----
 
+== Running groovy script from command line
+
+The usual way to run a script from the command line is by `groovy foo.groovy`, where `foo.groovy` is the Groovy program
+in source form. To use indy for this you have to use the indy compilation flag, `groovy --indy foo.groovy`.
+
 == The compilation flag
 
-Independently of the jar version that you use (and after having exchanged the jars as described), invokedynamic support requires a specific compilation flag (__indy__). If you want to compile your classes with invokedynamic support, this flag must be set at compile time. The following tables show you what happens with user compiled classes and groovy core classes depending on the jar you use and the compilation flag:
+Independently of the jar version that you use (and after having exchanged the jars as described), invokedynamic support requires a specific compilation flag (__indy__). If you want to compile your classes with invokedynamic support, this flag must be set at compile time. The following tables show you what happens with user compiled classes and Groovy core classes depending on the jar you use and the compilation flag:
 
 [cols="1,1,1" options="header"]
 .user compiled classes
@@ -72,7 +81,7 @@ Independently of the jar version that you use (and after having exchanged the ja
 
 |normal jar
 |call site caching
-|N/A
+|invokedynamic
 
 |indy jar
 |call site caching
@@ -80,7 +89,7 @@ Independently of the jar version that you use (and after having exchanged the ja
 |===
 
 [cols="1,1,1" options="header"]
-.core groovy classes
+.core Groovy classes
 |===
 |indy flag
 |**off**
@@ -88,7 +97,7 @@ Independently of the jar version that you use (and after having exchanged the ja
 
 |normal jar
 |call site caching
-|N/A
+|call site caching
 
 |indy jar
 |invokedynamic


[2/2] groovy git commit: GROOVY-8135: SecureASTCustomizer whitelist does not work (closes #538)

Posted by jw...@apache.org.
GROOVY-8135: SecureASTCustomizer whitelist does not work (closes #538)

For arrays we should get componentType instead of type


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6b70bbc9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6b70bbc9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6b70bbc9

Branch: refs/heads/master
Commit: 6b70bbc940d2cf021877f6a3ef0b5cf5fb974ff3
Parents: 6edd614
Author: Sargis Harutyunyan <sa...@webbfontaine.com>
Authored: Sat May 6 23:34:42 2017 +0400
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 6 20:48:05 2017 -0700

----------------------------------------------------------------------
 .../customizers/SecureASTCustomizer.java        |  7 ++++++-
 .../customizers/SecureASTCustomizerTest.groovy  | 21 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6b70bbc9/src/main/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java b/src/main/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
index b3d39f7..79b5455 100644
--- a/src/main/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
+++ b/src/main/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
@@ -698,7 +698,8 @@ public class SecureASTCustomizer extends CompilationCustomizer {
                         assertImportIsAllowed(expression.getType().getName());
                     } else if (expression instanceof MethodCallExpression) {
                         MethodCallExpression expr = (MethodCallExpression) expression;
-                        final String typename = expr.getObjectExpression().getType().getName();
+                        ClassNode objectExpressionType = expr.getObjectExpression().getType();
+                        final String typename = getExpressionType(objectExpressionType).getName();
                         assertImportIsAllowed(typename);
                         assertStaticImportIsAllowed(expr.getMethodAsString(), typename);
                     } else if (expression instanceof StaticMethodCallExpression) {
@@ -718,6 +719,10 @@ public class SecureASTCustomizer extends CompilationCustomizer {
             }
         }
 
+        private ClassNode getExpressionType(ClassNode objectExpressionType) {
+            return objectExpressionType.isArray() ? getExpressionType(objectExpressionType.getComponentType()) : objectExpressionType;
+        }
+
         /**
          * Checks that a given token is either in the whitelist or not in the blacklist.
          *

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b70bbc9/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
index 56832ce..35ce09a 100644
--- a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
+++ b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
@@ -459,4 +459,25 @@ class SecureASTCustomizerTest extends GroovyTestCase {
             '''
         }
     }
+
+    // GROOVY-8135
+    void testStarImportsWhiteListWithIndirectImportCheckEnabled() {
+        SecureASTCustomizer customizer = new SecureASTCustomizer()
+        customizer.setIndirectImportCheckEnabled(true)
+
+        List<String> starImportsWhitelist = new ArrayList<String>()
+        starImportsWhitelist.add("java.lang")
+        customizer.setStarImportsWhitelist(starImportsWhitelist)
+
+        CompilerConfiguration cc = new CompilerConfiguration()
+        cc.addCompilationCustomizers(customizer)
+
+        ClassLoader parent = getClass().getClassLoader()
+        GroovyClassLoader loader = new GroovyClassLoader(parent, cc)
+        loader.parseClass("Object object = new Object()")
+        loader.parseClass("Object object = new Object(); object.hashCode()")
+        loader.parseClass("Object[] array = new Object[0]; array.size()")
+        loader.parseClass("Object[][] array = new Object[0][0]; array.size()")
+    }
+
 }