aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/src
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2020-08-14 10:56:10 -0700
committerAndy Clement <aclement@pivotal.io>2020-08-14 10:56:10 -0700
commitb0b2f50a27499227580852496964e037e9204f22 (patch)
treea3e327b7903c5edc7b0735399b20d6fe881d69e1 /weaver/src
parente5c41da8638f924a6ba5ed4acd2da45784412fa2 (diff)
downloadaspectj-b0b2f50a27499227580852496964e037e9204f22.tar.gz
aspectj-b0b2f50a27499227580852496964e037e9204f22.zip
Fix up tests and reduce verbosity on J11
Diffstat (limited to 'weaver/src')
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java150
1 files changed, 87 insertions, 63 deletions
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 8bd479332..bbad8ed6a 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
@@ -94,7 +94,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$";
+ private static final String SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX = "$SWITCH_TABLE$";
public static boolean weave(BcelWorld world, LazyClassGen clazz, List<ShadowMunger> shadowMungers,
List<ConcreteTypeMunger> typeMungers, List<ConcreteTypeMunger> lateTypeMungers, boolean inReweavableMode) {
@@ -783,7 +783,6 @@ class BcelClassWeaver implements IClassWeaver {
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<LazyMethodGen> methods = clazz.getMethodGens();
@@ -796,6 +795,7 @@ class BcelClassWeaver implements IClassWeaver {
methodsSet.add(sb.toString()); // e.g. "foo(Ljava/lang/String;)V"
}
+ List<BridgeMethodDescriptor> bridges = null;
// Now go through all the methods in this type
for (LazyMethodGen bridgeToCandidate : methods) {
// This is the local method that we *might* have to bridge to
@@ -835,9 +835,12 @@ class BcelClassWeaver implements IClassWeaver {
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:bridging to '" + overriddenMethod + "'");
}
- createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
+ if (bridges== null) {
+ bridges = new ArrayList<>();
+ }
+ bridges.add(new BridgeMethodDescriptor(bridgeToCandidate, overriddenMethod));
+ //createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
methodsSet.add(key);
- didSomething = true;
}
}
}
@@ -856,9 +859,12 @@ class BcelClassWeaver implements IClassWeaver {
String key = new StringBuffer().append(overriddenMethod.getName()).append(overriddenMethod.getSignatureErased()).toString(); // pr237419
boolean alreadyHaveABridgeMethod = methodsSet.contains(key);
if (!alreadyHaveABridgeMethod) {
- createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
+ if (bridges== null) {
+ bridges = new ArrayList<>();
+ }
+ bridges.add(new BridgeMethodDescriptor(bridgeToCandidate, overriddenMethod));
+ // createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
methodsSet.add(key);
- didSomething = true;
if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:bridging to " + overriddenMethod);
}
@@ -867,7 +873,25 @@ class BcelClassWeaver implements IClassWeaver {
}
}
- return didSomething;
+ if (bridges != null) {
+ for (BridgeMethodDescriptor bmDescriptor: bridges) {
+ createBridgeMethod(world, bmDescriptor.bridgeToCandidate, clazz, bmDescriptor.overriddenMethod);
+ }
+ }
+
+ return bridges!=null && !bridges.isEmpty();
+ }
+
+ static class BridgeMethodDescriptor {
+
+ final LazyMethodGen bridgeToCandidate;
+ final ResolvedMember overriddenMethod;
+
+ public BridgeMethodDescriptor(LazyMethodGen bridgeToCandidate, ResolvedMember overriddenMethod) {
+ this.bridgeToCandidate = bridgeToCandidate;
+ this.overriddenMethod = overriddenMethod;
+ }
+
}
// **************************** end of bridge method creation code *****************
@@ -909,9 +933,9 @@ class BcelClassWeaver implements IClassWeaver {
for (LazyMethodGen method: addedLazyMethodGens) {
// They have no resolvedmember of their own, conjure one up for matching purposes
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()));
+ new ResolvedMemberImpl(ResolvedMember.METHOD,method.getEnclosingClass().getType(),method.getAccessFlags(),
+ BcelWorld.fromBcel(method.getReturnType()),method.getName(),
+ BcelWorld.fromBcel(method.getArgumentTypes()),UnresolvedType.forNames(method.getDeclaredExceptions()));
resolvedmember.setAnnotationTypes(method.getAnnotationTypes());
resolvedmember.setAnnotations(method.getAnnotations());
@@ -1119,7 +1143,7 @@ class BcelClassWeaver implements IClassWeaver {
WeaveMessage.WEAVEMESSAGE_ANNOTATES,
new String[] { sig.toString(), loc.toString(), decaM.getAnnotationString(),
methodName.startsWith("<init>") ? "constructor" : "method", decaM.getAspect().toString(),
- Utility.beautifyLocation(decaM.getSourceLocation()) }));
+ Utility.beautifyLocation(decaM.getSourceLocation()) }));
}
}
@@ -1548,9 +1572,9 @@ class BcelClassWeaver implements IClassWeaver {
world.getMessageHandler().handleMessage(
WeaveMessage.constructWeavingMessage(
isRemove ? WeaveMessage.WEAVEMESSAGE_REMOVES_ANNOTATION : WeaveMessage.WEAVEMESSAGE_ANNOTATES,
- new String[] { theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(),
- clazz.getFileName(), decaf.getAnnotationString(), "field", decaf.getAspect().toString(),
- Utility.beautifyLocation(decaf.getSourceLocation()) }));
+ new String[] { theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(),
+ clazz.getFileName(), decaf.getAnnotationString(), "field", decaf.getAspect().toString(),
+ Utility.beautifyLocation(decaf.getSourceLocation()) }));
}
}
@@ -2214,53 +2238,53 @@ class BcelClassWeaver implements IClassWeaver {
cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg));
}
// May need to copy bootstrapmethods across too.
-// if (fresh instanceof InvokeDynamic) {
-// InvokeDynamic id = (InvokeDynamic)fresh;
-// ConstantInvokeDynamic cid = (ConstantInvokeDynamic)donorCpg.getConstant(src.getInstruction().getIndex());
-// int bmaIndex = cid.getBootstrapMethodAttrIndex();
-// if (bootstrapMethods == null) {
-// Collection<Attribute> attributes = donor.getEnclosingClass().getAttributes();
-// if (attributes != null) {
-// for (Attribute attribute: attributes) {
-// if (attribute instanceof BootstrapMethods) {
-// bootstrapMethods = (BootstrapMethods)attribute;
-// }
-// }
-// }
-// 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<bootstrapMethodArguments.length; a++) {
-// newMethodArguments[a] = recipientCpg.addConstant(donorCpg.getConstant(bootstrapMethodArguments[a]),donorCpg);
-// }
-// BootstrapMethods.BootstrapMethod newBootstrapMethod =
-// new BootstrapMethods.BootstrapMethod(newMethodHandleIndex,newMethodArguments);
-//
-// Collection<Attribute> newAttributes = recipient.getEnclosingClass().getAttributes();
-// BootstrapMethods newBootstrapMethods = null;
-// for (Attribute attr: newAttributes) {
-// if (attr instanceof BootstrapMethods) {
-// newBootstrapMethods = (BootstrapMethods)newBootstrapMethods;
-// }
-// }
-// if (newBootstrapMethods == null) {
-// newBootstrapMethods =
-// new BootstrapMethods(recipientCpg.addUtf8("BootstrapMethods"),
-// 2+newBootstrapMethod.getLength(),
-// new BootstrapMethods.BootstrapMethod[] {newBootstrapMethod},
-// recipientCpg);
-// recipient.getEnclosingClass().addAttribute(newBootstrapMethods);
-// }
-// TODO need to copy over lambda$0 support methods too...
-// }
-//
-// }
+ // if (fresh instanceof InvokeDynamic) {
+ // InvokeDynamic id = (InvokeDynamic)fresh;
+ // ConstantInvokeDynamic cid = (ConstantInvokeDynamic)donorCpg.getConstant(src.getInstruction().getIndex());
+ // int bmaIndex = cid.getBootstrapMethodAttrIndex();
+ // if (bootstrapMethods == null) {
+ // Collection<Attribute> attributes = donor.getEnclosingClass().getAttributes();
+ // if (attributes != null) {
+ // for (Attribute attribute: attributes) {
+ // if (attribute instanceof BootstrapMethods) {
+ // bootstrapMethods = (BootstrapMethods)attribute;
+ // }
+ // }
+ // }
+ // 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<bootstrapMethodArguments.length; a++) {
+ // newMethodArguments[a] = recipientCpg.addConstant(donorCpg.getConstant(bootstrapMethodArguments[a]),donorCpg);
+ // }
+ // BootstrapMethods.BootstrapMethod newBootstrapMethod =
+ // new BootstrapMethods.BootstrapMethod(newMethodHandleIndex,newMethodArguments);
+ //
+ // Collection<Attribute> newAttributes = recipient.getEnclosingClass().getAttributes();
+ // BootstrapMethods newBootstrapMethods = null;
+ // for (Attribute attr: newAttributes) {
+ // if (attr instanceof BootstrapMethods) {
+ // newBootstrapMethods = (BootstrapMethods)newBootstrapMethods;
+ // }
+ // }
+ // if (newBootstrapMethods == null) {
+ // newBootstrapMethods =
+ // new BootstrapMethods(recipientCpg.addUtf8("BootstrapMethods"),
+ // 2+newBootstrapMethod.getLength(),
+ // new BootstrapMethods.BootstrapMethod[] {newBootstrapMethod},
+ // recipientCpg);
+ // recipient.getEnclosingClass().addAttribute(newBootstrapMethods);
+ // }
+ // TODO need to copy over lambda$0 support methods too...
+ // }
+ //
+ // }
}
if (src.getInstruction() == Range.RANGEINSTRUCTION) {
dest = ret.append(Range.RANGEINSTRUCTION);
@@ -2653,7 +2677,7 @@ class BcelClassWeaver implements IClassWeaver {
return false;
}
if (mg.getName().startsWith(SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX)
- && Objects.equals(mg.getReturnType().getSignature(), "[I")) {
+ && Objects.equals(mg.getReturnType().getSignature(), "[I")) {
// this is a synthetic switch helper, should be skipped (since it's not 'declared')
return false;
}
@@ -3239,7 +3263,7 @@ class BcelClassWeaver implements IClassWeaver {
&& s.charAt(4) == 'a'
&& (s.equals("org.aspectj.runtime.internal.CFlowCounter")
|| s.equals("org.aspectj.runtime.internal.CFlowStack") || s
- .equals("org.aspectj.runtime.reflect.Factory"))) {
+ .equals("org.aspectj.runtime.reflect.Factory"))) {
proceed = false;
} else {
if (methodName.equals("aspectOf")) {