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 2018/03/01 06:57:04 UTC

groovy git commit: Cleanup code and reduce buffer size of java stub generator

Repository: groovy
Updated Branches:
  refs/heads/master 7491e98a8 -> bfa17ba0f


Cleanup code and reduce buffer size of java stub generator

The original buffer size is too big(64K), which will use heap quickly and increase the times of GC. In general, the size of Java stub source code is about 8K.


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

Branch: refs/heads/master
Commit: bfa17ba0fbdd1f9ffd1f6a8eb62ad0ef433f91d2
Parents: 7491e98
Author: sunlan <su...@apache.org>
Authored: Thu Mar 1 14:56:46 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Thu Mar 1 14:56:58 2018 +0800

----------------------------------------------------------------------
 .../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java      | 8 ++------
 .../org/codehaus/groovy/tools/javac/JavaStubGenerator.java   | 2 +-
 2 files changed, 3 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/bfa17ba0/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index ab45f9c..7f3b345 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -56,7 +56,6 @@ import java.util.stream.Collectors;
 
 import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_LAMBDA_TYPE;
 import static org.codehaus.groovy.transform.stc.StaticTypesMarker.PARAMETER_TYPE;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
 import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
 import static org.objectweb.asm.Opcodes.ACC_STATIC;
 import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
@@ -77,7 +76,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter {
     public static final String INIT = "<init>";
     public static final String IS_GENERATED_CONSTRUCTOR = "__IS_GENERATED_CONSTRUCTOR";
     public static final String LAMBDA_WRAPPER = "__lambda_wrapper";
-    public static final String SAM_NAME = "__SAM_NAME";
     private StaticTypesClosureWriter staticTypesClosureWriter;
     private WriterController controller;
     private WriterControllerFactory factory;
@@ -98,8 +96,8 @@ public class StaticTypesLambdaWriter extends LambdaWriter {
     public void writeLambda(LambdaExpression expression) {
         ClassNode lambdaType = getLambdaType(expression);
 
-        if (!ClassHelper.isFunctionalInterface(lambdaType.redirect())) {
-            // if the parameter type is not real FunctionInterface, generate the default bytecode, which is actually a closure
+        if (null == lambdaType || !ClassHelper.isFunctionalInterface(lambdaType.redirect())) {
+            // if the parameter type is not real FunctionInterface or failed to be inferred, generate the default bytecode, which is actually a closure
             super.writeLambda(expression);
             return;
         }
@@ -312,8 +310,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter {
             answer.setScriptBody(true);
         }
 
-        answer.addField(SAM_NAME, ACC_PUBLIC | ACC_STATIC | ACC_FINAL, ClassHelper.STRING_TYPE, new ConstantExpression(abstractMethodNode.getName()));
-
         MethodNode syntheticLambdaMethodNode = addSyntheticLambdaMethodNode(expression, answer, abstractMethodNode);
         Parameter[] localVariableParameters = syntheticLambdaMethodNode.getNodeMetaData(LAMBDA_SHARED_VARIABLES);
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/bfa17ba0/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 271195a..b6af6ab 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -96,7 +96,7 @@ public class JavaStubGenerator {
         dir.mkdirs();
     }
 
-    private static final int DEFAULT_BUFFER_SIZE = 64 * 1024; // 64K
+    private static final int DEFAULT_BUFFER_SIZE = 8 * 1024; // 8K
     public void generateClass(ClassNode classNode) throws FileNotFoundException {
         // Only attempt to render our self if our super-class is resolved, else wait for it
         if (requireSuperResolved && !classNode.getSuperClass().isResolved()) {