diff options
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java | 20 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelMethod.java | 9 | ||||
-rw-r--r-- | weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt | 8 | ||||
-rw-r--r-- | weaver/testdata/AroundAllAndOthersHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/BeforeFancyHelloWorld.txt | 8 | ||||
-rw-r--r-- | weaver/testdata/BeforeHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/CflowStateResidueDynamicHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/FieldSet.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/StaticTjpBeforeHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/TjpBeforeHelloWorld.txt | 4 | ||||
-rw-r--r-- | weaver/testdata/TraceJarHello.txt | 2 |
12 files changed, 51 insertions, 24 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index ab61031f6..2fcd25e6d 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -24,6 +24,7 @@ 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.LineNumberTag; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.Message; import org.aspectj.weaver.Advice; @@ -424,7 +425,24 @@ public class BcelAdvice extends Advice { il.append(getNonTestAdviceInstructions(shadow)); InstructionHandle ifYesAdvice = il.getStart(); - il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice)); + il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice)); + + // If inserting instructions at the start of a method, we need a nice line number for this entry + // in the stack trace + if (shadow.getKind()==Shadow.MethodExecution && getKind()==AdviceKind.Before) { + int lineNumber=0; + // Uncomment this code if you think we should use the method decl line number when it exists... +// // If the advised join point is in a class built by AspectJ, we can use the declaration line number +// boolean b = shadow.getEnclosingMethod().getMemberView().hasDeclarationLineNumberInfo(); +// if (b) { +// lineNumber = shadow.getEnclosingMethod().getMemberView().getDeclarationLineNumber(); +// } else { // If it wasn't, the best we can do is the line number of the first instruction in the method + lineNumber = shadow.getEnclosingMethod().getMemberView().getLineNumberOfFirstInstruction(); +// } + if (lineNumber>0) il.getStart().addTargeter(new LineNumberTag(lineNumber)); + } + + return il; } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index 2bc6e9734..13839f41a 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -23,6 +23,8 @@ import org.aspectj.apache.bcel.classfile.Attribute; import org.aspectj.apache.bcel.classfile.ExceptionTable; import org.aspectj.apache.bcel.classfile.GenericSignatureParser; import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.LineNumber; +import org.aspectj.apache.bcel.classfile.LineNumberTable; import org.aspectj.apache.bcel.classfile.LocalVariable; import org.aspectj.apache.bcel.classfile.LocalVariableTable; import org.aspectj.apache.bcel.classfile.Method; @@ -102,6 +104,13 @@ public final class BcelMethod extends ResolvedMemberImpl { return super.getParameterNames(); } + public int getLineNumberOfFirstInstruction() { + LineNumberTable lnt = method.getLineNumberTable(); + if (lnt==null) return -1; + LineNumber[] lns = lnt.getLineNumberTable(); + if (lns==null || lns.length==0) return -1; + return lns[0].getLineNumber(); + } public void determineParameterNames() { if (parameterNamesInitialized) return; diff --git a/weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt b/weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt index 789b9d37e..dea1d2c63 100644 --- a/weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt +++ b/weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt @@ -25,7 +25,7 @@ public abstract class FancyHelloWorld extends java.lang.Object: ALOAD_0 ASTORE 19 method-execution(void FancyHelloWorld.main(java.lang.String[])) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9) | BIPUSH 1 | ANEWARRAY java.lang.Object | ASTORE 21 @@ -45,7 +45,7 @@ public abstract class FancyHelloWorld extends java.lang.Object: public static String getName(): method-execution(java.lang.String FancyHelloWorld.getName()) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20) | BIPUSH 0 | ANEWARRAY java.lang.Object | ASTORE 15 @@ -292,7 +292,7 @@ public abstract class FancyHelloWorld extends java.lang.Object: end static final void main_aroundBody20(String[]) static final void main_aroundBody22(String[]): - INVOKESTATIC Aspect.ajc_before_method_execution ()V + INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9) BIPUSH 1 ANEWARRAY java.lang.Object ASTORE_1 @@ -500,7 +500,7 @@ public abstract class FancyHelloWorld extends java.lang.Object: end static final String getName_aroundBody40() static final String getName_aroundBody42(): - INVOKESTATIC Aspect.ajc_before_method_execution ()V + INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20) BIPUSH 0 ANEWARRAY java.lang.Object ASTORE_0 diff --git a/weaver/testdata/AroundAllAndOthersHelloWorld.txt b/weaver/testdata/AroundAllAndOthersHelloWorld.txt index 2175e03c6..b3d0b28fb 100644 --- a/weaver/testdata/AroundAllAndOthersHelloWorld.txt +++ b/weaver/testdata/AroundAllAndOthersHelloWorld.txt @@ -25,7 +25,7 @@ public class HelloWorld extends java.lang.Object: ALOAD_0 ASTORE 7 method-execution(void HelloWorld.main(java.lang.String[])) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8) | BIPUSH 1 | ANEWARRAY java.lang.Object | ASTORE 9 @@ -153,7 +153,7 @@ public class HelloWorld extends java.lang.Object: end static final void main_aroundBody12(String[]) static final void main_aroundBody14(String[]): - INVOKESTATIC Aspect.ajc_before_method_execution ()V + INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8) BIPUSH 1 ANEWARRAY java.lang.Object ASTORE_1 diff --git a/weaver/testdata/BeforeFancyHelloWorld.txt b/weaver/testdata/BeforeFancyHelloWorld.txt index bc2ef49ba..69ee446b2 100644 --- a/weaver/testdata/BeforeFancyHelloWorld.txt +++ b/weaver/testdata/BeforeFancyHelloWorld.txt @@ -10,10 +10,10 @@ public abstract class FancyHelloWorld extends java.lang.Object: public static void main(String[]): method-execution(void FancyHelloWorld.main(java.lang.String[])) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9) | field-get(java.io.PrintStream java.lang.System.out) | | INVOKESTATIC Aspect.ajc_before_field_get ()V - | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 9) + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; | field-get(java.io.PrintStream java.lang.System.out) | ASTORE_1 | finally -> E1 @@ -55,8 +55,8 @@ public abstract class FancyHelloWorld extends java.lang.Object: public static String getName(): method-execution(java.lang.String FancyHelloWorld.getName()) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V - | ICONST_0 (line 20) + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20) + | ICONST_0 | ISTORE_0 | ILOAD_0 // int x (line 21) | LDC "name" diff --git a/weaver/testdata/BeforeHelloWorld.txt b/weaver/testdata/BeforeHelloWorld.txt index d89b5acd9..13dab828c 100644 --- a/weaver/testdata/BeforeHelloWorld.txt +++ b/weaver/testdata/BeforeHelloWorld.txt @@ -10,10 +10,10 @@ public class HelloWorld extends java.lang.Object: public static void main(String[]): method-execution(void HelloWorld.main(java.lang.String[])) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8) | field-get(java.io.PrintStream java.lang.System.out) | | INVOKESTATIC Aspect.ajc_before_field_get ()V - | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8) + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; | field-get(java.io.PrintStream java.lang.System.out) | LDC "hello world" (line 9) | method-call(void java.io.PrintStream.println(java.lang.String)) diff --git a/weaver/testdata/CflowStateResidueDynamicHelloWorld.txt b/weaver/testdata/CflowStateResidueDynamicHelloWorld.txt index 4745c2af0..4d3b2775d 100644 --- a/weaver/testdata/CflowStateResidueDynamicHelloWorld.txt +++ b/weaver/testdata/CflowStateResidueDynamicHelloWorld.txt @@ -9,7 +9,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria public static void main(String[]): method-execution(void DynamicHelloWorld.main(java.lang.String[])) - | GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack; + | GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack; (line 12) | INVOKEVIRTUAL org.aspectj.runtime.internal.CFlowStack.isValid ()Z | IFEQ L0 | GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack; @@ -18,7 +18,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria | CHECKCAST java.util.ArrayList | INVOKESTATIC Aspect.ajc_before_0 (Ljava/util/ArrayList;)V | catch java.lang.UnsupportedOperationException -> E0 - | | L0: NEW DynamicHelloWorld (line 12) + | | L0: NEW DynamicHelloWorld | | DUP | | INVOKESPECIAL DynamicHelloWorld.<init> ()V | | LDC "hello" diff --git a/weaver/testdata/FieldSet.txt b/weaver/testdata/FieldSet.txt index a32fad0f7..f5704a576 100644 --- a/weaver/testdata/FieldSet.txt +++ b/weaver/testdata/FieldSet.txt @@ -19,10 +19,10 @@ public class FieldyHelloWorld extends java.lang.Object: public static void main(String[]): method-execution(void FieldyHelloWorld.main(java.lang.String[])) - | INVOKESTATIC Aspect.ajc_before_method_execution ()V + | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 6) | field-get(java.lang.String FieldyHelloWorld.str) | | INVOKESTATIC Aspect.ajc_before_field_get ()V - | | GETSTATIC FieldyHelloWorld.str Ljava/lang/String; (line 6) + | | GETSTATIC FieldyHelloWorld.str Ljava/lang/String; | field-get(java.lang.String FieldyHelloWorld.str) | method-call(java.lang.String java.lang.String.valueOf(java.lang.Object)) | | INVOKESTATIC Aspect.ajc_before_method_call ()V diff --git a/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt b/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt index fc806f810..fed62e3c7 100644 --- a/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt +++ b/weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt @@ -13,12 +13,12 @@ public class HelloWorld extends java.lang.Object: public static void main(String[]): method-execution(void HelloWorld.main(java.lang.String[])) - | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart; + | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart; (line 8) | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V | field-get(java.io.PrintStream java.lang.System.out) | | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart; | | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V - | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8) + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; | field-get(java.io.PrintStream java.lang.System.out) | LDC "hello world" (line 9) | method-call(void java.io.PrintStream.println(java.lang.String)) diff --git a/weaver/testdata/StaticTjpBeforeHelloWorld.txt b/weaver/testdata/StaticTjpBeforeHelloWorld.txt index 6bc961dab..dcb25de15 100644 --- a/weaver/testdata/StaticTjpBeforeHelloWorld.txt +++ b/weaver/testdata/StaticTjpBeforeHelloWorld.txt @@ -15,12 +15,12 @@ public class HelloWorld extends java.lang.Object: public static void main(String[]): method-execution(void HelloWorld.main(java.lang.String[])) - | GETSTATIC HelloWorld.ajc$tjp_3 Lorg/aspectj/lang/JoinPoint$StaticPart; + | GETSTATIC HelloWorld.ajc$tjp_3 Lorg/aspectj/lang/JoinPoint$StaticPart; (line 8) | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V | field-get(java.io.PrintStream java.lang.System.out) | | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$StaticPart; | | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V - | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8) + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; | field-get(java.io.PrintStream java.lang.System.out) | LDC "hello world" (line 9) | method-call(void java.io.PrintStream.println(java.lang.String)) diff --git a/weaver/testdata/TjpBeforeHelloWorld.txt b/weaver/testdata/TjpBeforeHelloWorld.txt index 910465ee1..cf1eb20f8 100644 --- a/weaver/testdata/TjpBeforeHelloWorld.txt +++ b/weaver/testdata/TjpBeforeHelloWorld.txt @@ -28,7 +28,7 @@ public class HelloWorld extends java.lang.Object: INVOKESTATIC org.aspectj.runtime.reflect.Factory.makeJP (Lorg/aspectj/lang/JoinPoint$StaticPart;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/aspectj/lang/JoinPoint; ASTORE 5 method-execution(void HelloWorld.main(java.lang.String[])) - | ALOAD 5 + | ALOAD 5 (line 8) | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint;)V | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$StaticPart; | ACONST_NULL @@ -38,7 +38,7 @@ public class HelloWorld extends java.lang.Object: | field-get(java.io.PrintStream java.lang.System.out) | | ALOAD_1 | | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint;)V - | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8) + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; | field-get(java.io.PrintStream java.lang.System.out) | LDC "hello world" (line 9) | ASTORE_3 diff --git a/weaver/testdata/TraceJarHello.txt b/weaver/testdata/TraceJarHello.txt index 95a629d12..7e313b911 100644 --- a/weaver/testdata/TraceJarHello.txt +++ b/weaver/testdata/TraceJarHello.txt @@ -42,7 +42,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria ALOAD_2 ASTORE 4 method-execution(java.lang.String DynamicHelloWorld.doit(java.lang.String, java.util.List)) - | INVOKESTATIC MyTrace.aspectOf ()LMyTrace; + | INVOKESTATIC MyTrace.aspectOf ()LMyTrace; (line 21) | ALOAD_0 | INVOKEVIRTUAL Trace.ajc$before$Trace$1$26352be2 (Ljava/lang/Object;)V | INVOKESTATIC MyTrace.aspectOf ()LMyTrace; |