From aa4e441fca78dfc36f6a78c0f7b922718f352b04 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 11 Sep 2019 08:35:17 -0700 Subject: [PATCH] Moved tests around for avoiding weaving switch infrastructure method --- tests/bugs195/switch/Azpect.java | 5 + .../bugs195/switch}/HelloWorldEnumSwitch.java | 1 + .../systemtest/ajc195/Ajc195Tests.java | 4 + .../org/aspectj/systemtest/ajc195/ajc195.xml | 57 +++++++++++ .../aspectj/weaver/bcel/BcelClassWeaver.java | 93 +++++++++--------- .../aspectj/weaver/bcel/WeaveTestCase.java | 22 ++--- .../bin/HelloWorldEnumSwitch$TestEnum.class | Bin 1094 -> 0 bytes .../testdata/bin/HelloWorldEnumSwitch.class | Bin 1117 -> 0 bytes 8 files changed, 124 insertions(+), 58 deletions(-) create mode 100644 tests/bugs195/switch/Azpect.java rename {weaver/testinputdata/org/aspectj/weaver/test => tests/bugs195/switch}/HelloWorldEnumSwitch.java (99%) delete mode 100644 weaver/testdata/bin/HelloWorldEnumSwitch$TestEnum.class delete mode 100644 weaver/testdata/bin/HelloWorldEnumSwitch.class diff --git a/tests/bugs195/switch/Azpect.java b/tests/bugs195/switch/Azpect.java new file mode 100644 index 000000000..4e5c62e4a --- /dev/null +++ b/tests/bugs195/switch/Azpect.java @@ -0,0 +1,5 @@ +aspect Azpect { + before(): within(HelloWorldEnumSwitch) { + System.out.println(">"+thisJoinPointStaticPart.getSourceLocation().getLine()); + } +} diff --git a/weaver/testinputdata/org/aspectj/weaver/test/HelloWorldEnumSwitch.java b/tests/bugs195/switch/HelloWorldEnumSwitch.java similarity index 99% rename from weaver/testinputdata/org/aspectj/weaver/test/HelloWorldEnumSwitch.java rename to tests/bugs195/switch/HelloWorldEnumSwitch.java index f0d3cb03a..59c2f58c1 100644 --- a/weaver/testinputdata/org/aspectj/weaver/test/HelloWorldEnumSwitch.java +++ b/tests/bugs195/switch/HelloWorldEnumSwitch.java @@ -19,3 +19,4 @@ public class HelloWorldEnumSwitch { } } } + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc195/Ajc195Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc195/Ajc195Tests.java index 7c6034a3e..71219a5d2 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc195/Ajc195Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc195/Ajc195Tests.java @@ -16,6 +16,10 @@ import junit.framework.Test; */ public class Ajc195Tests extends XMLBasedAjcTestCase { + public void testAvoidWeavingSwitchInfrastructure() { + runTest("avoid weaving switch infrastructure"); + } + public void testFinallyBlocksAndUnlinkingAndExceptions() { runTest("around finally blocks and unlinking"); } diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc195/ajc195.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc195/ajc195.xml index 10d1a0156..c21529061 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc195/ajc195.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc195/ajc195.xml @@ -15,5 +15,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java index 80d704891..66ccfd0ce 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -1,15 +1,14 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; @@ -22,9 +21,9 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.Set; -import java.util.Objects; import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.classfile.BootstrapMethods; @@ -94,6 +93,7 @@ class BcelClassWeaver implements IClassWeaver { private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelClassWeaver.class); + // Name of helper method generated by JDT compiler. Javac uses a separate inner class. private static final String SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX = "$SWITCH_TABLE$"; public static boolean weave(BcelWorld world, LazyClassGen clazz, List shadowMungers, @@ -399,7 +399,7 @@ class BcelClassWeaver implements IClassWeaver { /** * Weave a class and indicate through the return value whether the class was modified. - * + * * @return true if the class was modified */ public boolean weave() { @@ -569,7 +569,7 @@ class BcelClassWeaver implements IClassWeaver { // FIXASC refactor into ResolvedType or even ResolvedMember? /** * Check if a particular method is overriding another - refactored into this helper so it can be used from multiple places. - * @return method that is overriding if it + * @return method that is overriding if it */ private static ResolvedMember isOverriding(ResolvedType typeToCheck, ResolvedMember methodThatMightBeGettingOverridden, String mname, String mrettype, int mmods, boolean inSamePackage, UnresolvedType[] methodParamsArray) { @@ -670,7 +670,7 @@ class BcelClassWeaver implements IClassWeaver { /** * Looks at the visibility modifiers between two methods, and knows whether they are from classes in the same package, and * decides whether one overrides the other. - * + * * @return true if there is an overrides rather than a 'hides' relationship */ static boolean isVisibilityOverride(int methodMods, ResolvedMember inheritedMethod, boolean inSamePackage) { @@ -697,7 +697,7 @@ class BcelClassWeaver implements IClassWeaver { /** * This method recurses up a specified type looking for a method that overrides the one passed in. - * + * * @return the method being overridden or null if none is found */ public static void checkForOverride(ResolvedType typeToCheck, String mname, String mparams, String mrettype, @@ -709,7 +709,7 @@ class BcelClassWeaver implements IClassWeaver { if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature) { return; // we just can't tell ! } - + if (typeToCheck.getWorld().forDEBUG_bridgingCode) { System.err.println(" Bridging:checking for override of " + mname + " in " + typeToCheck); @@ -720,12 +720,12 @@ class BcelClassWeaver implements IClassWeaver { packageName = ""; } // used when looking at visibility rules - boolean inSamePackage = packageName.equals(mpkg); + boolean inSamePackage = packageName.equals(mpkg); ResolvedMember[] methods = typeToCheck.getDeclaredMethods(); for (int ii = 0; ii < methods.length; ii++) { // the method we are going to check - ResolvedMember methodThatMightBeGettingOverridden = methods[ii]; + ResolvedMember methodThatMightBeGettingOverridden = methods[ii]; ResolvedMember isOverriding = isOverriding(typeToCheck, methodThatMightBeGettingOverridden, mname, mrettype, mmods, inSamePackage, methodParamsArray); if (isOverriding != null) { @@ -761,7 +761,7 @@ class BcelClassWeaver implements IClassWeaver { ResolvedType superclass = typeToCheck.getSuperclass(); checkForOverride(superclass, mname, mparams, mrettype, mmods, mpkg, methodParamsArray,overriddenMethodsCollector); - + ResolvedType[] interfaces = typeToCheck.getDeclaredInterfaces(); for (int i = 0; i < interfaces.length; i++) { ResolvedType anInterface = interfaces[i]; @@ -773,19 +773,19 @@ class BcelClassWeaver implements IClassWeaver { * We need to determine if any methods in this type require bridge methods - this method should only be called if necessary to * do this calculation, i.e. we are on a 1.5 VM (where covariance/generics exist) and the type hierarchy for the specified class * has changed (via decp/itd). - * + * * See pr108101 */ public static boolean calculateAnyRequiredBridgeMethods(BcelWorld world, LazyClassGen clazz) { world.ensureAdvancedConfigurationProcessed(); - + if (!world.isInJava5Mode()) { return false; // just double check... the caller should have already } if (clazz.isInterface()) { return false; // dont bother if we are an interface } - + boolean didSomething = false; // set if we build any bridge methods // So what methods do we have right now in this class? List methods = clazz.getMethodGens(); @@ -903,7 +903,7 @@ class BcelClassWeaver implements IClassWeaver { if (decaMs.isEmpty()) { return false; // nothing to do } - + Set unusedDecams = new HashSet(); unusedDecams.addAll(decaMs); @@ -913,7 +913,7 @@ class BcelClassWeaver implements IClassWeaver { if (addedLazyMethodGens!=null) { for (LazyMethodGen method: addedLazyMethodGens) { // They have no resolvedmember of their own, conjure one up for matching purposes - ResolvedMember resolvedmember = + ResolvedMember resolvedmember = new ResolvedMemberImpl(ResolvedMember.METHOD,method.getEnclosingClass().getType(),method.getAccessFlags(), BcelWorld.fromBcel(method.getReturnType()),method.getName(), BcelWorld.fromBcel(method.getArgumentTypes()),UnresolvedType.forNames(method.getDeclaredExceptions())); @@ -944,7 +944,7 @@ class BcelClassWeaver implements IClassWeaver { unusedDecams.remove(decam); } else if (!decam.isStarredAnnotationPattern()) { // an annotation is specified that might be put on by a subsequent decaf - worthRetrying.add(decam); + worthRetrying.add(decam); } } @@ -979,8 +979,8 @@ class BcelClassWeaver implements IClassWeaver { } } } - - + + // deal with all the other methods... List members = clazz.getMethodGens(); if (!members.isEmpty()) { @@ -1193,7 +1193,7 @@ class BcelClassWeaver implements IClassWeaver { /** * Applies some set of declare @field constructs (List) to some bunch of ITDfields (List. It * will iterate over the fields repeatedly until everything has been applied. - * + * */ private boolean weaveAtFieldRepeatedly(List decaFs, List itdFields, List reportedErrors) { @@ -1373,7 +1373,7 @@ class BcelClassWeaver implements IClassWeaver { // skip it for now /** * Weave any declare @field statements into the fields of the supplied class. This will attempt to apply them to the ITDs too. - * + * * Interesting case relating to public ITDd fields. The annotations are really stored against the interfieldinit method in the * aspect, but the public field is placed in the target type and then is processed in the 2nd pass over fields that occurs. I * think it would be more expensive to avoid putting the annotation on that inserted public field than just to have it put there @@ -1677,7 +1677,7 @@ class BcelClassWeaver implements IClassWeaver { /** * inline a particular call in bytecode. - * + * * @param donor the method we want to inline * @param recipient the method containing the call we want to inline * @param call the instructionHandle in recipient's body holding the call we want to inline. @@ -1687,11 +1687,11 @@ class BcelClassWeaver implements IClassWeaver { /* * Implementation notes: - * + * * We allocate two slots for every tempvar so we don't screw up longs and doubles which may share space. This could be * conservatively avoided (no reference to a long/double instruction, don't do it) or packed later. Right now we don't * bother to pack. - * + * * Allocate a new var for each formal param of the inlined. Fill with stack contents. Then copy the inlined instructions in * with the appropriate remap table. Any framelocs used by locals in inlined are reallocated to top of frame, */ @@ -1721,10 +1721,10 @@ class BcelClassWeaver implements IClassWeaver { /** * Input method is a synchronized method, we remove the bit flag for synchronized and then insert a try..finally block - * + * * Some jumping through firey hoops required - depending on the input code level (1.5 or not) we may or may not be able to use * the LDC instruction that takes a class literal (doesnt on <1.5). - * + * * FIXME asc Before promoting -Xjoinpoints:synchronization to be a standard option, this needs a bunch of tidying up - there is * some duplication that can be removed. */ @@ -2190,7 +2190,7 @@ class BcelClassWeaver implements IClassWeaver { /** * generate the instructions to be inlined. - * + * * @param donor the method from which we will copy (and adjust frame and jumps) instructions. * @param recipient the method the instructions will go into. Used to get the frame size so we can allocate new frame locations * for locals in donor. @@ -2240,21 +2240,21 @@ class BcelClassWeaver implements IClassWeaver { // } // } // } -// BootstrapMethods.BootstrapMethod bootstrapMethod = +// BootstrapMethods.BootstrapMethod bootstrapMethod = // bootstrapMethods.getBootstrapMethods()[bmaIndex]; // ConstantMethodHandle methodhandle = (ConstantMethodHandle)donorCpg.getConstant(bootstrapMethod.getBootstrapMethodRef()); // int bootstrapMethodArguments[] = bootstrapMethod.getBootstrapArguments(); -// +// // // Finally have all we need to build the new one... -// +// // int newMethodHandleIndex = recipientCpg.addConstant(methodhandle, donorCpg); // int[] newMethodArguments = new int[bootstrapMethodArguments.length]; // for (int a=0; a newAttributes = recipient.getEnclosingClass().getAttributes(); // BootstrapMethods newBootstrapMethods = null; // for (Attribute attr: newAttributes) { @@ -2263,7 +2263,7 @@ class BcelClassWeaver implements IClassWeaver { // } // } // if (newBootstrapMethods == null) { -// newBootstrapMethods = +// newBootstrapMethods = // new BootstrapMethods(recipientCpg.addUtf8("BootstrapMethods"), // 2+newBootstrapMethod.getLength(), // new BootstrapMethods.BootstrapMethod[] {newBootstrapMethod}, @@ -2272,7 +2272,7 @@ class BcelClassWeaver implements IClassWeaver { // } // TODO need to copy over lambda$0 support methods too... // } -// +// // } } if (src.getInstruction() == Range.RANGEINSTRUCTION) { @@ -2540,7 +2540,7 @@ class BcelClassWeaver implements IClassWeaver { /** * generate the argument stores in preparation for inlining. - * + * * @param donor the method we will inline from. Used to get the signature. * @param recipient the method we will inline into. Used to get the frame size so we can allocate fresh locations. * @param frameEnv an empty environment we populate with a map from donor frame to recipient frame. @@ -2572,7 +2572,7 @@ class BcelClassWeaver implements IClassWeaver { /** * get a called method: Assumes the called method is in this class, and the reference to it is exact (a la INVOKESPECIAL). - * + * * @param ih The InvokeInstruction instructionHandle pointing to the called method. */ private LazyMethodGen getCalledMethod(InstructionHandle ih) { @@ -3052,7 +3052,7 @@ class BcelClassWeaver implements IClassWeaver { /** * Find the specified member in the specified type. - * + * * @param type the type to search for the member * @param methodName the name of the method to find * @param params the method parameters that the discovered method should have @@ -3098,7 +3098,7 @@ class BcelClassWeaver implements IClassWeaver { * For a given resolvedmember, this will discover the real annotations for it. Should only be used when the resolvedmember is * the contents of an effective signature attribute, as thats the only time when the annotations aren't stored directly in the * resolvedMember - * + * * @param rm the sig we want it to pretend to be 'int A.m()' or somesuch ITD like thing * @param declaredSig the real sig 'blah.ajc$xxx' */ @@ -3133,7 +3133,7 @@ class BcelClassWeaver implements IClassWeaver { * For a given resolvedmember, this will discover the real annotations for it. Should only be used when the resolvedmember is * the contents of an effective signature attribute, as thats the only time when the annotations aren't stored directly in the * resolvedMember - * + * * @param rm the sig we want it to pretend to be 'int A.m()' or somesuch ITD like thing * @param declaredSig the real sig 'blah.ajc$xxx' */ @@ -3269,7 +3269,6 @@ class BcelClassWeaver implements IClassWeaver { } if (methodName.startsWith(SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX)) { - // we shouldn't process calls to synthetic methods (since they're not 'declared') proceed = false; } diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java index 4bab41bfa..d336b580c 100644 --- a/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java @@ -1,13 +1,13 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation * ******************************************************************/ package org.aspectj.weaver.bcel; @@ -29,8 +29,8 @@ import org.aspectj.testing.util.TestUtil; import org.aspectj.util.FileUtil; import org.aspectj.util.LangUtil; import org.aspectj.weaver.Advice; -import org.aspectj.weaver.WeaverTestCase; import org.aspectj.weaver.ShadowMunger; +import org.aspectj.weaver.WeaverTestCase; import org.aspectj.weaver.patterns.FormalBinding; import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; @@ -133,7 +133,7 @@ public abstract class WeaveTestCase extends TestCase { throw e; } } - + public String findMostRelevantFile(String name) { double version = LangUtil.getVmVersion(); while (version > 0) { @@ -267,7 +267,7 @@ public abstract class WeaveTestCase extends TestCase { // ---- public String[] getStandardTargets() { - return new String[] { "HelloWorld", "FancyHelloWorld", "HelloWorldEnumSwitch" }; + return new String[] { "HelloWorld", "FancyHelloWorld" }; } public String getTraceJar() { diff --git a/weaver/testdata/bin/HelloWorldEnumSwitch$TestEnum.class b/weaver/testdata/bin/HelloWorldEnumSwitch$TestEnum.class deleted file mode 100644 index 6f912ffbdd7a06312bb40c56336eda38a1e9b78c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1094 zcmah{-%}D%7(JhhEUc>%DTY4+l?u=xDtm!(Foz~4)Q43Xrl$orTxVIDWwGJEDt*wY z$?3U2s_DBM%05^yv)ujeJ?DJq?00|t{&o%EC7#QeAgsJKEUWvz>sZGXyWi11n{MkQ zb!hZlQOXDqW={1pJ#XoDJ1_PKv_nYL{!1(}>NR1ivVXLfs_)c}DjFgAVJsU2Srrl7BLquBNGx3&dDC3SwA;mMrXFVOeHD`kh9HX~rb0$g zygg76LYSp$rfux^J59qm)SH$;h}OC--Ky)3DQa(1frMGM;GUR0?s}$MeS=@t(wT8V z6eO`GW0er`865OnqoZOSDMDCx9DUI0ei{(6{ul?%Q={b;tG;A6TO5rbdo~U}5?=Ue z!}OUkUsyy+t9XPAVaw0owe()E=xcf_I0_)9&x2L8Zr^DcZ%pyo;&)wxoZxUq&1~Dc z+jkgO@JS1u(io%L+(@n3w&8frjGl~Vgt@!A5kfcjwOrsCOMJbha$L+G;FU)YL>9&1 z`6R%rf+@zST-CW2zub3FBRVZzV&(!-ub2yX#r)(CK9bH6)f$0w%xf1|_{xk4#QA^5 z>z2ecRV5{CWvs8uJQ#0$r* zrZ*?xPiHm-0!z-Wp~8=+#^pNfi%}QIO^kjp6={&@hTI_B@nH7D1R zN)Y}*Rf&eFbX~#t(3pvz&oH_59f8yG1*R^)scWN6P=SpT1j;m?5n-@tY<4Y8@~ AJpcdz -- 2.39.5