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/02/06 00:32:39 UTC
groovy git commit: Update the comment on the workaround
Repository: groovy
Updated Branches:
refs/heads/native-lambda dffe45b54 -> 005aa6c05
Update the comment on the workaround
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/005aa6c0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/005aa6c0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/005aa6c0
Branch: refs/heads/native-lambda
Commit: 005aa6c0594ccacc6d0322f6633d74ee54ad18eb
Parents: dffe45b
Author: sunlan <su...@apache.org>
Authored: Tue Feb 6 08:32:22 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Feb 6 08:32:35 2018 +0800
----------------------------------------------------------------------
.../asm/sc/StaticTypesLambdaWriter.java | 53 ++++++++------------
1 file changed, 21 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/005aa6c0/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 ab9d0f3..ab45f9c 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
@@ -130,53 +130,42 @@ public class StaticTypesLambdaWriter extends LambdaWriter {
if (null != expression.getNodeMetaData(INFERRED_LAMBDA_TYPE)) {
// FIXME declaring variable whose initial value is a lambda, e.g. `Function<Integer, String> f = (Integer e) -> 'a' + e`
- // Groovy will `POP` multiple times...(expecting `POP` only once), as a hack, `DUP` to duplicate the element of operand stack:
+ // Groovy will `POP` automatically, use `DUP` to duplicate the element of operand stack:
/*
- L2
- ASTORE 0
- ALOAD 0
- ACONST_NULL
INVOKEDYNAMIC apply(LTest1$_p_lambda1;LTest1;)Ljava/util/function/Function; [
// handle kind 0x6 : INVOKESTATIC
java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
// arguments:
(Ljava/lang/Object;)Ljava/lang/Object;,
// handle kind 0x5 : INVOKEVIRTUAL
- Test1$_p_lambda1.doCall(LTest1;Ljava/lang/Integer;)Ljava/lang/Object;,
- (Ljava/lang/Integer;)Ljava/lang/Object;
+ Test1$_p_lambda1.doCall(LTest1;Ljava/lang/Integer;)Ljava/lang/String;,
+ (Ljava/lang/Integer;)Ljava/lang/String;
]
- DUP <-------------- FIXME ADDED ON PURPOSE, WE SHOULD REMOVE IT AFTER FIND BETTER SOLUTION
- DUP
+ DUP <-------------- FIXME ADDED ON PURPOSE, WE SHOULD REMOVE IT AFTER FIND BETTER SOLUTION
+ ASTORE 0
+ L2
ALOAD 0
- SWAP
- INVOKEVIRTUAL groovy/lang/Lambda.setLambdaObject (Ljava/lang/Object;)V
- LDC Ljava/util/function/Function;.class
- INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
- CHECKCAST java/util/function/Function
- ASTORE 1
- L3
- ALOAD 1
- POP
+ POP <-------------- Since operand stack is not empty, the `POP`s are issued by `controller.getOperandStack().popDownTo(mark);` in the method `org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement`, but when we try to `operandStack.pop();` instead of `mv.visitInsn(DUP);`, we will get AIOOBE...
POP
*/
mv.visitInsn(DUP);
/*
-org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
-General error during class generation: size==0
-
-java.lang.ArrayIndexOutOfBoundsException: size==0
- at org.codehaus.groovy.classgen.asm.OperandStack.getTopOperand(OperandStack.java:693)
- at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateEqual(BinaryExpressionHelper.java:397)
- at org.codehaus.groovy.classgen.asm.sc.StaticTypesBinaryExpressionMultiTypeDispatcher.evaluateEqual(StaticTypesBinaryExpressionMultiTypeDispatcher.java:179)
- at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:694)
- at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:89)
- at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:633)
- at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:681)
- at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
- */
-// operandStack.pop();
+ org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
+ General error during class generation: size==0
+
+ java.lang.ArrayIndexOutOfBoundsException: size==0
+ at org.codehaus.groovy.classgen.asm.OperandStack.getTopOperand(OperandStack.java:693)
+ at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateEqual(BinaryExpressionHelper.java:397)
+ at org.codehaus.groovy.classgen.asm.sc.StaticTypesBinaryExpressionMultiTypeDispatcher.evaluateEqual(StaticTypesBinaryExpressionMultiTypeDispatcher.java:179)
+ at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:694)
+ at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:89)
+ at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:633)
+ at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:681)
+ at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
+ */
+ // operandStack.pop();
}
}