This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push: new d6d0ef2ff7 Revert "GROOVY-11415: Tweak bytecode for identity" d6d0ef2ff7 is described below commit d6d0ef2ff735967e85f387730656d06c43f24c2b Author: Daniel Sun <sun...@apache.org> AuthorDate: Fri Aug 30 22:11:27 2024 +0800 Revert "GROOVY-11415: Tweak bytecode for identity" (cherry picked from commit a425cc241fc2a884bdc94539979f7482d7111410) --- .../classgen/asm/BinaryExpressionHelper.java | 45 ++---------------- src/test/groovy/bugs/Groovy11415.groovy | 53 ---------------------- 2 files changed, 4 insertions(+), 94 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java index 2e02c16902..cdbe93f73d 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java @@ -109,11 +109,12 @@ import static org.objectweb.asm.Opcodes.GOTO; import static org.objectweb.asm.Opcodes.IFEQ; import static org.objectweb.asm.Opcodes.IFNE; import static org.objectweb.asm.Opcodes.IF_ACMPEQ; -import static org.objectweb.asm.Opcodes.IF_ACMPNE; import static org.objectweb.asm.Opcodes.INSTANCEOF; public class BinaryExpressionHelper { // compare + private static final MethodCaller compareIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareIdentical"); + private static final MethodCaller compareNotIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotIdentical"); private static final MethodCaller compareEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareEqual"); private static final MethodCaller compareNotEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotEqual"); private static final MethodCaller compareToMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareTo"); @@ -329,11 +330,11 @@ public class BinaryExpressionHelper { break; case COMPARE_IDENTICAL: - evaluateIdentity(expression, true); + evaluateCompareExpression(compareIdenticalMethod, expression); break; case COMPARE_NOT_IDENTICAL: - evaluateIdentity(expression, false); + evaluateCompareExpression(compareNotIdenticalMethod, expression); break; default: @@ -341,44 +342,6 @@ public class BinaryExpressionHelper { } } - private void evaluateIdentity(BinaryExpression expression, boolean identical) { - AsmClassGenerator acg = controller.getAcg(); - MethodVisitor mv = controller.getMethodVisitor(); - OperandStack operandStack = controller.getOperandStack(); - TypeChooser typeChooser = controller.getTypeChooser(); - - Expression lhs = expression.getLeftExpression(); - ClassNode leftType = typeChooser.resolveType(lhs, controller.getClassNode()); - - Expression rhs = expression.getRightExpression(); - ClassNode rightType = typeChooser.resolveType(rhs, controller.getClassNode()); - - boolean leftPrimitive = ClassHelper.isPrimitiveType(leftType); - boolean rightPrimitive = ClassHelper.isPrimitiveType(rightType); - if (leftPrimitive && rightPrimitive) { - BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(controller); - boolean done = helper.doPrimitiveCompare(leftType, rightType, expression); - if (done) return; - } - - lhs.visit(acg); - if (leftPrimitive) operandStack.box(); - - rhs.visit(acg); - if (rightPrimitive) operandStack.box(); - - Label trueCase = operandStack.jump(identical ? IF_ACMPEQ : IF_ACMPNE); - ConstantExpression.PRIM_FALSE.visit(acg); - Label end = new Label(); - mv.visitJumpInsn(GOTO, end); - - mv.visitLabel(trueCase); - ConstantExpression.PRIM_TRUE.visit(acg); - - mv.visitLabel(end); - operandStack.replace(ClassHelper.boolean_TYPE, 3); - } - @Deprecated protected void assignToArray(final Expression parent, final Expression receiver, final Expression index, final Expression rhsValueLoader) { assignToArray(parent, receiver, index, rhsValueLoader, false); diff --git a/src/test/groovy/bugs/Groovy11415.groovy b/src/test/groovy/bugs/Groovy11415.groovy deleted file mode 100644 index 47864b3166..0000000000 --- a/src/test/groovy/bugs/Groovy11415.groovy +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package bugs - -import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase - -import static groovy.test.GroovyAssert.isAtLeastJdk - -final class Groovy11415 extends AbstractBytecodeTestCase { - void testIdentity() { - assert compile(method: 'isIdentical', ''' - def isIdentical (Object obj) { - if (obj === 'abc') return true - return false - } - ''').hasSequence([ - 'LDC "abc"', - 'IF_ACMPEQ L1', - 'ICONST_0', - 'GOTO L2' - ]) - } - - void testNotIdentity() { - assert compile(method: 'isNotIdentical', ''' - def isNotIdentical (Object obj) { - if (obj !== 'abc') return true - return false - } - ''').hasSequence([ - 'LDC "abc"', - 'IF_ACMPNE L1', - 'ICONST_0', - 'GOTO L2' - ]) - } -}