Browse Source

Fix 548785: Check level is >=1.8 when looking to skip inlining around advice lambdas

tags/V1_9_5
Andy Clement 4 years ago
parent
commit
08861eb882

+ 7
- 7
weaver/src/main/java/org/aspectj/weaver/bcel/BcelAdvice.java View File



/** /**
* Advice implemented for BCEL * Advice implemented for BCEL
*
*
* @author Erik Hilsdale * @author Erik Hilsdale
* @author Jim Hugunin * @author Jim Hugunin
* @author Andy Clement * @author Andy Clement
private Test runtimeTest; private Test runtimeTest;
private ExposedState exposedState; private ExposedState exposedState;
private int containsInvokedynamic = 0;// 0 = dontknow, 1=no, 2=yes private int containsInvokedynamic = 0;// 0 = dontknow, 1=no, 2=yes
public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member adviceSignature, ResolvedType concreteAspect) { public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member adviceSignature, ResolvedType concreteAspect) {
super(attribute, pointcut, simplify(attribute.getKind(), adviceSignature)); super(attribute, pointcut, simplify(attribute.getKind(), adviceSignature));
this.concreteAspect = concreteAspect; this.concreteAspect = concreteAspect;
} }
public boolean bindsProceedingJoinPoint() { public boolean bindsProceedingJoinPoint() {
UnresolvedType[] parameterTypes = signature.getParameterTypes(); UnresolvedType[] parameterTypes = signature.getParameterTypes();
for (int i=0;i<parameterTypes.length;i++) { for (int i=0;i<parameterTypes.length;i++) {
} }
return false; return false;
} }
/** /**
* A heavyweight BcelMethod object is only required for around advice that will be inlined. For other kinds of advice it is * A heavyweight BcelMethod object is only required for around advice that will be inlined. For other kinds of advice it is
* possible to save some space. * possible to save some space.
} }
// Need isJava8 check // Need isJava8 check
// Does the advice contain invokedynamic... // Does the advice contain invokedynamic...
if (boType.javaClass.getMajor() == Constants.MAJOR_1_8) {
if (boType.javaClass.getMajor() >= Constants.MAJOR_1_8) {
if (containsInvokedynamic == 0) { if (containsInvokedynamic == 0) {
containsInvokedynamic = 1; containsInvokedynamic = 1;
LazyMethodGen lmg = boType.getLazyClassGen().getLazyMethodGen(this.signature.getName(), this.signature.getSignature(), true); LazyMethodGen lmg = boType.getLazyClassGen().getLazyMethodGen(this.signature.getName(), this.signature.getSignature(), true);
/** /**
* The munger must not check for the advice exceptions to be declared by the shadow in the case of @AJ aspects so that around * The munger must not check for the advice exceptions to be declared by the shadow in the case of @AJ aspects so that around
* can throws Throwable * can throws Throwable
*
*
* @return * @return
*/ */
@Override @Override
/** /**
* get the instruction list for the really simple version of this advice. Is broken apart for other advice, but if you want it * get the instruction list for the really simple version of this advice. Is broken apart for other advice, but if you want it
* in one block, this is the method to call. * in one block, this is the method to call.
*
*
* @param s The shadow around which these instructions will eventually live. * @param s The shadow around which these instructions will eventually live.
* @param extraArgVar The var that will hold the return value or thrown exception for afterX advice * @param extraArgVar The var that will hold the return value or thrown exception for afterX advice
* @param ifNoAdvice The instructionHandle to jump to if the dynamic tests for this munger fails. * @param ifNoAdvice The instructionHandle to jump to if the dynamic tests for this munger fails.

+ 8
- 7
weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java View File

* Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data and then a reader/writer * Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data and then a reader/writer
* process it. The writer is wired into the world so that types can be resolved and getCommonSuperClass() can be implemented without * process it. The writer is wired into the world so that types can be resolved and getCommonSuperClass() can be implemented without
* class loading using the context class loader. * class loading using the context class loader.
*
*
* It is important that the constant pool is preserved here and asm does not try to remove unused entries. That is because some * It is important that the constant pool is preserved here and asm does not try to remove unused entries. That is because some
* entries are refered to from classfile attributes. Asm cannot see into these attributes so does not realise the constant pool * entries are refered to from classfile attributes. Asm cannot see into these attributes so does not realise the constant pool
* entries are in use. In order to ensure the copying of cp occurs, we use the variant super constructor call in AspectJConnectClassWriter * entries are in use. In order to ensure the copying of cp occurs, we use the variant super constructor call in AspectJConnectClassWriter
* that passes in the classreader. However, ordinarily that change causes a further optimization: that if a classreader sees * that passes in the classreader. However, ordinarily that change causes a further optimization: that if a classreader sees
* a methodvisitor that has been created by a ClassWriter then it just copies the data across without changing it (and so it * a methodvisitor that has been created by a ClassWriter then it just copies the data across without changing it (and so it
* fails to attach the stackmapattribute). In order to avoid this further optimization we use our own minimal MethodVisitor. * fails to attach the stackmapattribute). In order to avoid this further optimization we use our own minimal MethodVisitor.
*
*
* @author Andy Clement * @author Andy Clement
*/ */
public class StackMapAdder { public class StackMapAdder {
return cw.toByteArray(); return cw.toByteArray();
} catch (Throwable t) { } catch (Throwable t) {
System.err.println("AspectJ Internal Error: unable to add stackmap attributes. " + t.getMessage()); System.err.println("AspectJ Internal Error: unable to add stackmap attributes. " + t.getMessage());
t.printStackTrace();
AsmDetector.isAsmAround = false; AsmDetector.isAsmAround = false;
return data; return data;
} }
} }
private static class AspectJClassVisitor extends ClassVisitor { private static class AspectJClassVisitor extends ClassVisitor {


public AspectJClassVisitor(ClassVisitor classwriter) { public AspectJClassVisitor(ClassVisitor classwriter) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
return new AJMethodVisitor(mv); return new AJMethodVisitor(mv);
} }
// Minimal pass through MethodVisitor just so that the ClassReader doesn't see one that has been directly // Minimal pass through MethodVisitor just so that the ClassReader doesn't see one that has been directly
// created by a ClassWriter (see top level class comment) // created by a ClassWriter (see top level class comment)
static class AJMethodVisitor extends MethodVisitor { static class AJMethodVisitor extends MethodVisitor {
super(Opcodes.ASM7,mv); super(Opcodes.ASM7,mv);
} }
} }
} }


private static class AspectJConnectClassWriter extends ClassWriter { private static class AspectJConnectClassWriter extends ClassWriter {
super(cr, ClassWriter.COMPUTE_FRAMES); // passing in cr is necessary so cpool isnt modified (see 2.2.4 of asm doc) super(cr, ClassWriter.COMPUTE_FRAMES); // passing in cr is necessary so cpool isnt modified (see 2.2.4 of asm doc)
this.world = w; this.world = w;
} }


// Implementation of getCommonSuperClass() that avoids Class.forName() // Implementation of getCommonSuperClass() that avoids Class.forName()
@Override @Override
do { do {
resolvedType1 = resolvedType1.getSuperclass(); resolvedType1 = resolvedType1.getSuperclass();
if (resolvedType1 == null) { if (resolvedType1 == null) {
// This happens if some types are missing, the getSuperclass() call on
// This happens if some types are missing, the getSuperclass() call on
// MissingResolvedTypeWithKnownSignature will return the Missing type which // MissingResolvedTypeWithKnownSignature will return the Missing type which
// in turn returns a superclass of null. By returning Object here it // in turn returns a superclass of null. By returning Object here it
// should surface the cantFindType message raised in the first problematic // should surface the cantFindType message raised in the first problematic

Loading…
Cancel
Save