[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Oddity with @Around and proceed arguments
|
Matthew,
The version is:
AspectJ Compiler 1.5.0 built on Tuesday Dec 20, 2005 at 12:05:54 GMT
=Ron=
Matthew Webster wrote On 01/27/06 08:47,:
>
> Ron,
>
> Which version of _AspectJ_ are you using?
>
> Matthew Webster
> AOSD Project
> Java Technology Centre, MP146
> IBM Hursley Park, Winchester, SO21 2JN, England
> Telephone: +44 196 2816139 (external) 246139 (internal)
> Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> http://w3.hursley.ibm.com/~websterm/
>
> Sent by: Ron.Mann@xxxxxxx
>
> To: Matthew Webster/UK/IBM@IBMGB
> cc:
> Subject: Re: [aspectj-users] Oddity with @Around and proceed
> arguments
>
>
> Matthew,
>
> Originally I was using build 1.5.0-b64. As a result of your mail I
> switched to build 1.5.0_06-b05. I did a little more work that I'm at a
> loss to explain.
>
> First, I tried the new Java install and had the same effect. Second, I
> tried the -XnoInline option and everything worked fine no matter which
> style I used!?!
>
> So I decide to change the A.java code to include both proceeds in the
> same code just as a sanity check:
>
> @Around("fooOfC( i )")
> public void foo2( ProceedingJoinPoint pjp, int i) {
> pjp.proceed( new Object[] { pjp.getTarget(), i } );
> pjp.proceed( new Object[] { i } );
> }
>
> and with noInline it worked in both cases.
>
> runit
> 42
> 42
>
>
> I removed all the classes, recompiled with the -XnoInline argument
> removed as well :
>
> runit
> 42
> Exception in thread "main" java.lang.ClassCastException:
> java.lang.Integer
> at ron.interfacetest.M.bar_aroundBody1$advice(M.java:120)
> at ron.interfacetest.M.main(M.java:10)
>
> Must say I'm getting a bit beyond my depth here. I've enclosed the
> javap output from both tests (inline.out being the failure case and
> noinline.out being the success (i guess) case. Perhaps this might give
> you a clue as to whats up. Thanks again very much for the assistence!
>
> =Ron=
>
>
>
>
>
> Matthew Webster wrote On 01/27/06 06:02,:
>
> >
> > Ron,
> >
> > Which version of the compiler are you using and which JDK? I have no
> > problem using either AJDT or ajc with JDK 1.5.0_05 to build your code:
> >
> > C:\workspaces\temp\Test\src>c:\aspectj1.5\bin\ajc -version
> > AspectJ Compiler 1.5.0 built on Tuesday Dec 20, 2005 at 12:05:54 GMT
> >
> >
> > C:\workspaces\temp\Test\src>c:\aspectj1.5\bin\ajc -d c:\temp\test -1.5
> > -showWeaveInfo -verbose -referenceInfo -argfile ..\files.lst
> > zipfile classpath entry does not exist: C:\jdk1.5.0_05\jre\lib\i18n.jar
> >
> > zipfile classpath entry does not exist:
> > C:\jdk1.5.0_05\jre\lib\sunrsasign.jar
> >
> > directory classpath entry does not exist: C:\jdk1.5.0_05\jre\classes
> >
> > compiling C:\workspaces\temp\Test\src\A.java
> >
> > compiling C:\workspaces\temp\Test\src\C.java
> >
> > compiling C:\workspaces\temp\Test\src\M.java
> >
> > weaver operating in reweavable mode. Need to verify any required
> > types exist.
> >
> > Join point 'method-call(void C.bar(int))' in Type 'M' (M.java:4)
> > advised by around advice from 'A' (A.java:13)
> >
> > Matthew Webster
> > AOSD Project
> > Java Technology Centre, MP146
> > IBM Hursley Park, Winchester, SO21 2JN, England
> > Telephone: +44 196 2816139 (external) 246139 (internal)
> > Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> > http://w3.hursley.ibm.com/~websterm/
> >
> > Please respond to aspectj-users@xxxxxxxxxxx
> >
> > Sent by: aspectj-users-bounces@xxxxxxxxxxx
> >
> > To: aspectj-users@xxxxxxxxxxx
> > cc:
> > Subject: Re: [aspectj-users] Oddity with @Around and proceed
> > arguments
> >
> >
> > Hi Matthew!
> >
> > I haven't yet explored runtime weaving yet. At the moment I'm using
> > 1.5.0 and doing static weaving. I was running ajc via a script which
> > looks like this:
> >
> > #! /bin/sh
> > build=.
> >
> > ajc -1.5\
> > -cp $build:/files0/AOP/AspectJ/aspectj1.5/lib/aspectjrt.jar \
> > -verbose \
> > -showWeaveInfo \
> > -referenceInfo \
> > -d . -argfile files.lst
> >
> > with a list file containing:
> > A.java
> > C.java
> > M.java
> >
> > and getting the following exception when run:
> > Exception in thread "main" java.lang.ClassCastException:
> java.lang.Integer
> > at ron.interfacetest.M.bar_aroundBody1$advice(M.java:119)
> > at ron.interfacetest.M.main(M.java:10)
> >
> > A javap -c -private ron.interfacetest.M shows where for some reason
> > there seems to be expected a push of two arguments, not one, and on the
> > first there is a checkcast (on type C):
> >
> > 0: aload 4
> > 2: iconst_1
> > 3: anewarray #4; //class java/lang/Object
> > 6: dup
> > 7: iconst_0
> > 8: iload 5
> > 10: invokestatic #53; //Method
> > java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
> > 13: aastore
> > 14: astore 6
> > 16: astore 7
> > 18: aload 6
> > 20: bipush 0
> > 22: aaload
> > 23: checkcast #18; //class ron/interfacetest/C
> > 26: aload 6
> > 28: bipush 1
> > 30: aaload
> > 31: invokestatic #73; //Method
> > org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
> > 34: aload 7
> > 36: invokestatic #75; //Method
> > bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
> > 39: aconst_null
> > 40: pop
> > 41: return
> >
> > When I add in the pjp.getTarget() back I get the following which
> > executes properly:
> >
> > 0: aload 4
> > 2: iconst_2
> > 3: anewarray #4; //class java/lang/Object
> > 6: dup
> > 7: iconst_0
> > 8: aload 4
> > 10: invokeinterface #53, 1; //InterfaceMethod
> > org/aspectj/lang/ProceedingJoinPoint.getTarget:()Ljava/lang/Object;
> > 15: aastore
> > 16: dup
> > 17: iconst_1
> > 18: iload 5
> > 20: invokestatic #59; //Method
> > java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
> > 23: aastore
> > 24: astore 6
> > 26: astore 7
> > 28: aload 6
> > 30: bipush 0
> > 32: aaload
> > 33: checkcast #18; //class ron/interfacetest/C
> > 36: aload 6
> > 38: bipush 1
> > 40: aaload
> > 41: invokestatic #77; //Method
> > org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
> > 44: aload 7
> > 46: invokestatic #79; //Method
> > bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
> > 49: aconst_null
> > 50: pop
> > 51: return
> >
> > Hopefully this is helpful.
> >
> > =Ron=
> >
> >
> > Matthew Webster wrote On 01/26/06 10:06,:
> >
> > >
> > > Ron,
> > >
> > > How are you building and running the application? Which version of
> > > AspectJ are you using? It works for me using a hand-coded aop.xml file
> > > and load-time weaving support. I had to change the aspect a little to
> > > cope with the fact that the "proceed()" method throws Throwable but
> > > this is what I got:
> > >
> > > _Console_
> > > 84
> > > info AspectJ Weaver Version DEVELOPMENT built on Friday Jan 20, 2006
> > > at 10:29:42 GMT
> > > info register classloader
> > > org.aspectj.weaver.loadtime.WeavingURLClassLoader
> > > info using /C:/workspaces/temp/Test/bin/META-INF/aop.xml
> > > info register aspect A
> > > info weaving 'M'
> > > info generating class 'M$AjcClosure1'
> > > info weaving 'C'
> > > info weaving 'A'
> > >
> > > _A.java_
> > > import org.aspectj.lang.ProceedingJoinPoint;
> > > import org.aspectj.lang.annotation.Around;
> > > import org.aspectj.lang.annotation.Aspect;
> > > import org.aspectj.lang.annotation.Pointcut;
> > >
> > > @Aspect
> > > public class A {
> > >
> > > @Pointcut( "call(void C.bar( int )) && args( i ) " )
> > > void fooOfC( int i ) {}
> > >
> > > @Around("fooOfC( i )")
> > > public void foo2( ProceedingJoinPoint pjp, int i) throws
> Throwable {
> > > // pjp.proceed( new Object[] { pjp.getTarget(), i } );
> > > pjp.proceed( new Object[] { i*2 } );
> > > }
> > > }
> > >
> > > _aop.xml_
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <aspectj>
> > > <aspects>
> > > <aspect name="A"/>
> > > </aspects>
> > > <weaver options="-verbose"/>
> > > </aspectj>
> > >
> > > Cheers
> > >
> > > Matthew Webster
> > > AOSD Project
> > > Java Technology Centre, MP146
> > > IBM Hursley Park, Winchester, SO21 2JN, England
> > > Telephone: +44 196 2816139 (external) 246139 (internal)
> > > Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> > > http://w3.hursley.ibm.com/~websterm/
> > >
> > > Please respond to aspectj-users@xxxxxxxxxxx
> > >
> > > Sent by: aspectj-users-bounces@xxxxxxxxxxx
> > >
> > > To: aspectj-users@xxxxxxxxxxx
> > > cc:
> > > Subject: [aspectj-users] Oddity with @Around and proceed
> > arguments
> > >
> > >
> > > Hi experts!
> > >
> > > I'm a newcomer to this technology, so forgive me if I've missed the
> > > obvious. For various reasons, the project I'm working on is
> interesting
> > > in incorporating the annotation style for aspect declaration. I've
> > > encountered an oddity which I'm unsure about. In essense I have
> > > duplicated the @Around example in chapter 9 of the developers notebook
> > >
> >
> (http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html)
> > > where each of the following classes are in a separate .java file:
> > >
> > > public class M {
> > > public static void main( String[] args ) {
> > > C c = new C();
> > > c.bar(42);
> > > }
> > > }
> > >
> > > public class C {
> > > public void bar(int i) {
> > > System.out.println( i );
> > > }
> > > }
> > >
> > > @Aspect
> > > public class A {
> > >
> > > @Pointcut( "call(void C.bar( int )) && args( i ) " )
> > > void fooOfC( int i ) {}
> > >
> > > @Around("fooOfC( i )")
> > > public void foo2( ProceedingJoinPoint pjp, int i) {
> > > pjp.proceed( new Object[] { pjp.getTarget(), i } );
> > > /* Doc doesn't show this ---^^^^^^^^^^^^^^^
> > > * Via the doc I should have passed just the int reference
> > > thus:
> > > * pjp.proceed( new Object[] { i } );
> > > */
> > > }
> > > }
> > >
> > > When I followed the example by only including the int in the Object
> > > array, I was getting a ClassCastException which after javap'ing
> the file
> > > indicated that the weaver appeared to be expecting two arguments
> rather
> > > than one. The first (and missing arg) appearing to be the instance of
> > > object to proceed to. By getting the target from the pjp
> reference and
> > > adding it to the array of objects passed, the problem seems to be
> solved
> > > and everything worked fine. So, I'd just like to have confidence that
> > > what I'm doing is in fact the correct methodology and that this is a
> > > documentation oversight or alternately, that my limited understanding
> > > has resulted in me completely bolluxing everything up and things
> should
> > > be specified in a different way.
> > >
> > > Thanks for your help!!!
> > >
> > > =Ron=
> > >
> > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> >
> >------------------------------------------------------------------------
> > >
> > >_______________________________________________
> > >aspectj-users mailing list
> > >aspectj-users@xxxxxxxxxxx
> > >https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> > >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >aspectj-users mailing list
> >aspectj-users@xxxxxxxxxxx
> >https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> Compiled from "M.java"
> public class ron.interfacetest.M extends java.lang.Object{
> private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0;
>
> public ron.interfacetest.M();
> Code:
> 0: aload_0
> 1: invokespecial #9; //Method
> java/lang/Object."<init>":()V
> 4: return
>
> public static void main(java.lang.String[]);
> Code:
> 0: new #18; //class ron/interfacetest/C
> 3: dup
> 4: invokespecial #19; //Method
> ron/interfacetest/C."<init>":()V
> 7: astore_1
> 8: aload_1
> 9: bipush 42
> 11: istore_2
> 12: astore_3
> 13: getstatic #33; //Field
> ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;
> 16: aconst_null
> 17: aload_3
> 18: iload_2
> 19: invokestatic #39; //Method
> org/aspectj/runtime/internal/Conversions.intObject:(I)Ljava/lang/Object;
> 22: invokestatic #45; //Method
> org/aspectj/runtime/reflect/Factory.makeJP:(Lorg/aspectj/lang/JoinPoint$StaticPart;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/aspectj/lang/JoinPoint;
> 25: astore 4
> 27: invokestatic #64; //Method
> ron/interfacetest/A.aspectOf:()Lron/interfacetest/A;
> 30: bipush 3
> 32: anewarray #4; //class
> java/lang/Object
> 35: astore 5
> 37: aload 5
> 39: bipush 0
> 41: aload_3
> 42: aastore
> 43: aload 5
> 45: bipush 1
> 47: iload_2
> 48: invokestatic #39; //Method
> org/aspectj/runtime/internal/Conversions.intObject:(I)Ljava/lang/Object;
> 51: aastore
> 52: aload 5
> 54: bipush 2
> 56: aload 4
> 58: aastore
> 59: new #49; //class
> ron/interfacetest/M$AjcClosure1
> 62: dup
> 63: aload 5
> 65: invokespecial #52; //Method
> ron/interfacetest/M$AjcClosure1."<init>":([Ljava/lang/Object;)V
> 68: invokevirtual #58; //Method
> org/aspectj/runtime/internal/AroundClosure.linkClosureAndJoinPoint:()Lorg/aspectj/lang/ProceedingJoinPoint;
> 71: iload_2
> 72: invokevirtual #68; //Method
> ron/interfacetest/A.foo2:(Lorg/aspectj/lang/ProceedingJoinPoint;I)V
> 75: return
>
> static {};
> Code:
> 0: new #44; //class
> org/aspectj/runtime/reflect/Factory
> 3: dup
> 4: ldc #71; //String M.java
> 6: ldc #73; //String ron.interfacetest.M
> 8: invokestatic #79; //Method
> java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
> 11: invokespecial #82; //Method
> org/aspectj/runtime/reflect/Factory."<init>":(Ljava/lang/String;Ljava/lang/Class;)V
> 14: astore_0
> 15: aload_0
> 16: ldc #84; //String method-call
> 18: aload_0
> 19: ldc #86; //String 1
> 21: ldc #87; //String bar
> 23: ldc #89; //String
> ron.interfacetest.C
> 25: ldc #91; //String int:
> 27: ldc #93; //String i:
> 29: ldc #95; //String
> 31: ldc #97; //String void
> 33: invokevirtual #101; //Method
> org/aspectj/runtime/reflect/Factory.makeMethodSig:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/aspectj/lang/reflect/MethodSignature;
> 36: bipush 10
> 38: invokevirtual #105; //Method
> org/aspectj/runtime/reflect/Factory.makeSJP:(Ljava/lang/String;Lorg/aspectj/lang/Signature;I)Lorg/aspectj/lang/JoinPoint$StaticPart;
> 41: putstatic #33; //Field
> ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;
> 44: return
>
> static final void bar_aroundBody0(ron.interfacetest.C, int,
> org.aspectj.lang.JoinPoint);
> Code:
> 0: aload_0
> 1: iload_1
> 2: invokevirtual #23; //Method
> ron/interfacetest/C.bar:(I)V
> 5: return
>
> }
>
> Compiled from "M.java"
> public class ron.interfacetest.M extends java.lang.Object{
> private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0;
>
> public ron.interfacetest.M();
> Code:
> 0: aload_0
> 1: invokespecial #9; //Method
> java/lang/Object."<init>":()V
> 4: return
>
> public static void main(java.lang.String[]);
> Code:
> 0: new #18; //class ron/interfacetest/C
> 3: dup
> 4: invokespecial #19; //Method
> ron/interfacetest/C."<init>":()V
> 7: astore_1
> 8: aload_1
> 9: bipush 42
> 11: istore_2
> 12: astore_3
> 13: getstatic #33; //Field
> ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;
> 16: aconst_null
> 17: aload_3
> 18: iload_2
> 19: invokestatic #39; //Method
> org/aspectj/runtime/internal/Conversions.intObject:(I)Ljava/lang/Object;
> 22: invokestatic #45; //Method
> org/aspectj/runtime/reflect/Factory.makeJP:(Lorg/aspectj/lang/JoinPoint$StaticPart;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/aspectj/lang/JoinPoint;
> 25: astore 4
> 27: aload_3
> 28: iload_2
> 29: aload 4
> 31: invokestatic #69; //Method
> ron/interfacetest/A.aspectOf:()Lron/interfacetest/A;
> 34: aload 4
> 36: iload_2
> 37: invokestatic #73; //Method
> bar_aroundBody1$advice:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;Lron/interfacetest/A;Lorg/aspectj/lang/ProceedingJoinPoint;I)V
> 40: return
>
> static {};
> Code:
> 0: new #44; //class
> org/aspectj/runtime/reflect/Factory
> 3: dup
> 4: ldc #82; //String M.java
> 6: ldc #84; //String ron.interfacetest.M
> 8: invokestatic #90; //Method
> java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
> 11: invokespecial #93; //Method
> org/aspectj/runtime/reflect/Factory."<init>":(Ljava/lang/String;Ljava/lang/Class;)V
> 14: astore_0
> 15: aload_0
> 16: ldc #95; //String method-call
> 18: aload_0
> 19: ldc #97; //String 1
> 21: ldc #98; //String bar
> 23: ldc #100; //String
> ron.interfacetest.C
> 25: ldc #102; //String int:
> 27: ldc #104; //String i:
> 29: ldc #106; //String
> 31: ldc #108; //String void
> 33: invokevirtual #112; //Method
> org/aspectj/runtime/reflect/Factory.makeMethodSig:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/aspectj/lang/reflect/MethodSignature;
> 36: bipush 10
> 38: invokevirtual #116; //Method
> org/aspectj/runtime/reflect/Factory.makeSJP:(Ljava/lang/String;Lorg/aspectj/lang/Signature;I)Lorg/aspectj/lang/JoinPoint$StaticPart;
> 41: putstatic #33; //Field
> ajc$tjp_0:Lorg/aspectj/lang/JoinPoint$StaticPart;
> 44: return
>
> private static final void bar_aroundBody0(ron.interfacetest.C, int,
> org.aspectj.lang.JoinPoint);
> Code:
> 0: aload_0
> 1: iload_1
> 2: invokevirtual #23; //Method
> ron/interfacetest/C.bar:(I)V
> 5: return
>
> private static final void bar_aroundBody1$advice(ron.interfacetest.C,
> int, org.aspectj.lang.JoinPoint, ron.interfacetest.A,
> org.aspectj.lang.ProceedingJoinPoint, int);
> Code:
> 0: aload 4
> 2: iconst_2
> 3: anewarray #4; //class
> java/lang/Object
> 6: dup
> 7: iconst_0
> 8: aload 4
> 10: invokeinterface #53, 1;
> //InterfaceMethod
> org/aspectj/lang/ProceedingJoinPoint.getTarget:()Ljava/lang/Object;
> 15: aastore
> 16: dup
> 17: iconst_1
> 18: iload 5
> 20: invokestatic #59; //Method
> java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
> 23: aastore
> 24: astore 6
> 26: astore 7
> 28: aload 6
> 30: bipush 0
> 32: aaload
> 33: checkcast #18; //class
> ron/interfacetest/C
> 36: aload 6
> 38: bipush 1
> 40: aaload
> 41: invokestatic #77; //Method
> org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
> 44: aload 7
> 46: invokestatic #79; //Method
> bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
> 49: aconst_null
> 50: pop
> 51: aload 4
> 53: iconst_1
> 54: anewarray #4; //class
> java/lang/Object
> 57: dup
> 58: iconst_0
> 59: iload 5
> 61: invokestatic #59; //Method
> java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
> 64: aastore
> 65: astore 8
> 67: astore 9
> 69: aload 8
> 71: bipush 0
> 73: aaload
> 74: checkcast #18; //class
> ron/interfacetest/C
> 77: aload 8
> 79: bipush 1
> 81: aaload
> 82: invokestatic #77; //Method
> org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
> 85: aload 9
> 87: invokestatic #79; //Method
> bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
> 90: aconst_null
> 91: pop
> 92: return
>
> }
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>