Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: RE: using AspectJ with rt.jar

Classes from rt.jar are special citizens in Java. Given that you are
using an execution pointcut, this means that possible join point
shadow do belong to the code in java.lang.Object class itslef ie
inside rt.jar

Obviously unless you compile the JDK with AJC, you cannot use source
weaving (compile time weaving). You can use it on your own
application, but the java.lang.Object will never be encountered.

Lets now assume you are using load time weaving.
In this case, obviously the java.lang.Object as a very special citizen
will be loaded very early by the VM. AspectJ load time needs it (as
100% of Java applications) just to perform the actual weaving. That
means that we need this java.lang.Object among others to weave... this
java.lang.Object class. That can' t be done, and instead of blowing in
sort of infinite recursion, the java.lang.Object is just not expsoed
to load time weaving.

Last option is to use post compile time weaving ie AJC on the compiled
version of java.lang.Object that stands in your JDK rt.jar.
This can be done.
Issue may arise when you will want to run with this modified version
(skipping legal / licensing issues debate here). First you need to
make sure the VM will take your version and not the JDK version.
Wether change your rt.jar file (and possibly corrupt your whole instal
of the JDK), or use -Xbootclasspath/p:pathToYour_rt.jar (the /p is
very important , refer to Sun documentation for that option).
When done, obviously the weaved java.lang.Object will trigger calls to
possible aspects, to org.aspectj.lang.* classes from aspectjrt.jar
etc. This means that all those dependencies also needs to stand in the
bootclasspath.

To sum up it is certainly possible using post compile weaving.
That said you are strongly encourage to use call pointcut to classes
to rt.jar instead, which will happen in your own applications that you
fully control (thus AJC compiled, post compiled, or load time weaved),
without requiring any special considerations in your configuration
except the one that we covers in the docs.

What is the use case for what you are trying to do by the way?

Alex



On 10/27/05, Joanne (sent by Nabble.com) <lists@xxxxxxxxxx> wrote:
>  I defined a pointcut at the execution of a method in rt.jar:
>     pointcut execToString() : execution(* *..Object.toString(..));
>
> I applied a "before" advice on this pointcut:
>     before() : execToString()
>     {
>         System.out.println("Instrumenting toString in Object class");
>     }
>
> Of course I have a method that does the following:
>     Object obj = new Object();
>     obj.toString();
>
> I tried compile-time weaving, post-compile weaving and load-time weaving, I
> was not getting the message printed at all, and I think the
> Object.toString() method was not applied with aspect.
> However if I change "execution" to "call" in the pointcut definition, I see
> the message get printed.  I have a feeling that aspectJ can only apply
> aspects on my own application classes, not the classes in rt.jar.
>
> Can you please carify this for me please?  If we can actually apply aspects
> on classes in rt.jar, how can I do that?  I'd really appreciate this.
> Thanks a lot.
>
> Joanne
> ________________________________
>  Sent from the AspectJ - users forum at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>


Back to the top