aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/src
diff options
context:
space:
mode:
authorAndy Clement <aclement@gopivotal.com>2014-09-30 11:08:50 -0700
committerAndy Clement <aclement@gopivotal.com>2014-09-30 11:08:50 -0700
commit102173fc11fc6648ed8f2283d3c5ad535e412c73 (patch)
tree41f4d30666dcbaf76353d34e7f94d6e92c10da73 /weaver/src
parente26c781374ac7afeaf8859baf4fc55d7dfb7b3a7 (diff)
downloadaspectj-102173fc11fc6648ed8f2283d3c5ad535e412c73.tar.gz
aspectj-102173fc11fc6648ed8f2283d3c5ad535e412c73.zip
445395: invokedynamic in around advice
Diffstat (limited to 'weaver/src')
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java23
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java59
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java9
3 files changed, 87 insertions, 4 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
index ac30af5f9..668a0b2dc 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
@@ -19,12 +19,14 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
+import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.LocalVariable;
import org.aspectj.apache.bcel.classfile.LocalVariableTable;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InvokeDynamic;
import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
import org.aspectj.bridge.ISourceLocation;
@@ -69,7 +71,8 @@ class BcelAdvice extends Advice {
*/
private Test runtimeTest;
private ExposedState exposedState;
-
+ private int containsInvokedynamic = 0;// 0 = dontknow, 1=no, 2=yes
+
public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member adviceSignature, ResolvedType concreteAspect) {
super(attribute, pointcut, simplify(attribute.getKind(), adviceSignature));
this.concreteAspect = concreteAspect;
@@ -233,6 +236,24 @@ class BcelAdvice extends Advice {
// Could be a symptom that the aspect failed to build last build... return the default answer of false
return false;
}
+ // Need isJava8 check
+ // Does the advice contain invokedynamic...
+ if (boType.javaClass.getMajor() == Constants.MAJOR_1_8) {
+ if (containsInvokedynamic == 0) {
+ containsInvokedynamic = 1;
+ LazyMethodGen lmg = boType.getLazyClassGen().getLazyMethodGen(this.signature);
+ InstructionList ilist = lmg.getBody();
+ for (InstructionHandle src = ilist.getStart(); src != null; src = src.getNext()) {
+ if (src.getInstruction().opcode == Constants.INVOKEDYNAMIC) {
+ containsInvokedynamic = 2;
+ break;
+ }
+ }
+ }
+ }
+ if (containsInvokedynamic == 2) {
+ return false;
+ }
return boType.getLazyClassGen().isWoven();
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
index 2c352a258..a7b35a203 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
@@ -27,6 +27,11 @@ import java.util.Properties;
import java.util.Set;
import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.BootstrapMethods;
+import org.aspectj.apache.bcel.classfile.ConstantInvokeDynamic;
+import org.aspectj.apache.bcel.classfile.ConstantMethodHandle;
+import org.aspectj.apache.bcel.classfile.ConstantMethodref;
import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
@@ -42,6 +47,7 @@ import org.aspectj.apache.bcel.generic.InstructionLV;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.InstructionSelect;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
+import org.aspectj.apache.bcel.generic.InvokeDynamic;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
@@ -2204,7 +2210,7 @@ class BcelClassWeaver implements IClassWeaver {
ConstantPool recipientCpg = recipient.getEnclosingClass().getConstantPool();
boolean isAcrossClass = donorCpg != recipientCpg;
-
+ BootstrapMethods bootstrapMethods = null;
// first pass: copy the instructions directly, populate the srcToDest
// map,
// fix frame instructions
@@ -2214,13 +2220,60 @@ class BcelClassWeaver implements IClassWeaver {
// OPTIMIZE optimize this stuff?
if (fresh.isConstantPoolInstruction()) {
- // need to reset index to go to new constant pool. This is
- // totally
+ // need to reset index to go to new constant pool. This is totally
// a computation leak... we're testing this LOTS of times. Sigh.
if (isAcrossClass) {
InstructionCP cpi = (InstructionCP) fresh;
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 (src.getInstruction() == Range.RANGEINSTRUCTION) {
dest = ret.append(Range.RANGEINSTRUCTION);
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
index 62ebac92c..8e2b09867 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -1582,6 +1583,14 @@ public final class LazyClassGen {
public void addAttribute(AjAttribute attribute) {
myGen.addAttribute(Utility.bcelAttribute(attribute, getConstantPool()));
}
+
+ public void addAttribute(Attribute attribute) {
+ myGen.addAttribute(attribute);
+ }
+
+ public Collection<Attribute> getAttributes() {
+ return myGen.getAttributes();
+ }
// this test is like asking:
// if