Re: [abc-users] Obtaining SootMethods from PerSetupAdvice

From: Nathan Weston <npweston_at_gmail.com>
Date: Wed, 14 May 2008 16:07:31 +0100

Hi Eric,

That unfortunately doesn't work - I just get a RuntimeException saying
the method couldn't be found, regardless of the classes in question.
If it helps, I'm analysing the Spacewar example distributed with
AspectJ - the final GameSynchronisation.jimple file certainly does
have a abc$perThisBind method, but when I use this technique, it only
finds three methods in the GameSynchronisation class - <init>,
aspectOf and hasAspect.

I added the setApplicationClass() and loadClass methods at your
previous suggestion ;) Without them I get a
polyglot.util.InternalCompilerError exception: "Anonymous classes
cannot have names" when I try and convert an AbcClass to a SootClass.
Here's the snippet of code I'm using:

  List<SootMethod> methods = new ArrayList<SootMethod>();
  Iterator<AbcClass> classes =
abc.main.Main.v().getAbcExtension().getGlobalAspectInfo().getWeavableClasses().iterator();

  while (classes.hasNext()) {
    AbcClass abccl = classes.next();
    SootClass scl = abccl.getSootClass();

    scl.setApplicationClass();
    Scene.v().loadClass(scl.getName(), SootClass.BODIES);

    Iterator<SootMethod> methodsit =
Scene.v().getSootClass(scl.getName()).getMethods().iterator();

    // Previously using this:
    // Iterator<SootMethod> methodsit = scl.getMethods().iterator();

    while (methodsit.hasNext()) { ... etc.

Thanks again for your help,
Nathan

On Wed, May 14, 2008 at 3:19 PM, Eric Bodden <eric.bodden_at_mail.mcgill.ca> wrote:
> Normally, something like this should work:
>
> Scene.v().getSootClass("NameOfTheAspect").getMethodByName("abc$perThisBind");
>
> Setting classes as application classes and using "loadClass" should
> normally be superflous anyway. abc already does that for you.
>
> Eric
>
>
> 2008/5/14 Nathan Weston <npweston_at_gmail.com>:
>> Hi Eric,
>>
>> Thanks for your reply! My problem is that I'm not sure how to access
>> this method pre-weave (I'm performing this analysis as a compiler pass
>> after JIMPLIFY_DONE). Currently I use:
>>
>> abc.main.Main.v().getAbcExtension().getGlobalAspectInfo().getWeavableClasses();
>>
>> to find SootClasses, set them as ApplicationClasses and call
>> Scene.v().loadClass so I can get access to the methods they define.
>> However, using this technique, no methods called abc$perThisBind are
>> visible to analyse.
>>
>> Thanks again,
>> Nath
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Wed, May 14, 2008 at 3:00 PM, Eric Bodden <eric.bodden_at_mail.mcgill.ca> wrote:
>> > Nathan, can you not just attach your tags to the method
>> > abc$perThisBind in this case?
>> >
>> > The fact that you have multiple aspect instances at runtime should not
>> > really matter because there's still only *one* such method. There are
>> > just multiple *calls* to this method inserted by PetThisSetup.
>> >
>> > Eric
>> >
>> > 2008/5/14 Nathan Weston <npweston_at_gmail.com>:
>> >> Thanks Eric! The difficulty is that I'm doing pre-analysis of advices
>> >> and attaching the results to SootMethods as tags, which I then retrieve
>> >> after weaving. This is possible with AdviceDecls, but I guess it's more
>> >> difficult when the advice applies perThis as the instances of the advice
>> >> are different?
>> >>
>> >> Nathan
>> >>
>> >>
>> >>
>> >>
>> >> Eric Bodden wrote:
>> >>
>> >> > Or another way you could look at it is that the advice body will
>> >> > always be called "abc$perThisBind', as this is the method for which a
>> >> > call is being inserted at the shadow.
>> >> >
>> >> > Eric
>> >> >
>> >> > 2008/5/13 Eric Bodden <eric.bodden_at_mail.mcgill.ca>:
>> >> >
>> >> > > Hi Nathan.
>> >> > >
>> >> > > Looking at the code I believe that the reason for not providing this
>> >> > > method is that there is no method being generated for PerThisSetup. If
>> >> > > I am not mistaken, all the functionality is implemented within
>> >> > > makeAdviceExecutionStmts, which just adds a bunch of statements to the
>> >> > > shadow (and no method call to an advice body).
>> >> > >
>> >> > > Eric
>> >> > >
>> >> > > 2008/5/13 Nathan Weston <npweston_at_gmail.com>:
>> >> > >
>> >> > >
>> >> > >
>> >> > > > Hello all,
>> >> > > >
>> >> > > >
>> >> > > > Is it possible to obtain the SootMethod implementation of a
>> >> PerSetupAdvice,
>> >> > > > especially a PerThisSetup? I mean in a similar method to
>> >> > > > getImpl().getSootMethod() for an AdviceDecl.
>> >> > > >
>> >> > > > Thanks for any help!
>> >> > > > Nathan
>> >> > > >
>> >> > > >
>> >> > >
>> >> > >
>> >> > >
>> >> > > --
>> >> > > Eric Bodden
>> >> > > Sable Research Group
>> >> > > McGill University, Montréal, Canada
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Eric Bodden
>> > Sable Research Group
>> > McGill University, Montréal, Canada
>> >
>> >
>>
>>
>
>
>
> --
> Eric Bodden
> Sable Research Group
> McGill University, Montréal, Canada
>
>
Received on Wed May 14 2008 - 16:07:36 BST

This archive was generated by hypermail 2.2.0 : Wed May 14 2008 - 16:20:11 BST