Re: Fwd: [abc-users] codeGen dynamic code

From: Amjad Nusayr <anusayr_at_cs.nmsu.edu>
Date: Tue, 15 Sep 2009 13:35:08 -0600

Thanks Eric,
I will assume that we have only concrete aspects (not abstract). And yes
my intension is to create one counter per each aspect not for all aspect
instances. That is, if I have two pointcut expressions that use the
afterN PCD, then I will have one counter associated with each expression.
My problem is not with the methodology. It is with the implementation.
I'm struggling with two things. The first is knowing where should I
write the code that is responsible for creating a counter for each
pointcut expression. The second thing is that I lack the knowledge for
writing the dynamic residue (jimple soot).

My first attempt was a failure as I created a local each time the
codeGen was invoked. When I looked at the jimple file (IR file) I had a
bunch of locals. Not only this is not correct. I don't think that they
represent a local for each pointcut expression!!!

Amjad

Eric Bodden wrote:
> Sorry for the late response. I already sent this on the 29th but my
> response got discarded by the list server.
>
> Eric
>
>
> ---------- Forwarded message ----------
> From: Eric Bodden <bodden_at_st.informatik.tu-darmstadt.de>
> Date: 2009/8/29
> Subject: Re: [abc-users] codeGen dynamic code
> To: abc-users_at_comlab.ox.ac.uk
>
>
> Hi Amjad.
>
> I agree with the steps that you outlined. My personal opinion is that
> the easiest way would be to implement this in two different chunks of
> code, where the first one is concerned with...
>
>
>> For each pointcut expression that has AfterN
>> - create a local counter for that expression (lets call it n) and initialize
>> it // again a local counter for the expression not the underlying method or
>> class
>>
>
> ... and the second one with ...
>
>> - check if n>cutpoint
>> - if true apply the advise
>> - if false dont not apply the adivse
>> - increment n each time the we need to apply the advise
>>
>
> Regarding problem 1, generating and initializing the counters I would
> suggest to simply create the counter as a field in the aspect that
> holds the pointcut. You will have to keep in mind, though that there
> may be abstract aspects, and think about what happens in that case.
> Also you will have to make up your mind whether the counter should be
> an instance field or a static field. Be reminded that aspects can have
> multiple instances, i.e. if you have a per-target aspect. In that case
> do you want one counter per aspect or just one counter for all aspect
> instances? Genrating the counters should not be hard: simply analyze
> each pointcut to extract its AfterN sub-pointcuts and for each
> pointcut that you encounter generate a new field. There's no need to
> initialize the field because the JVM will set it to 0 automatically
> anyway. Store a mapping that maps from every afterN pointcut to its
> unique counter.
>
> Then regarding problem 2, this code should all go within your
> AfterNDResidue. The important thing there is the codeGen method, which
> takes the following arguments:
>
> SootMethod method - the method that is woven into
> LocalGeneratorEx localgen - allows you to create fresh local variables
> in the method"s body
> Chain units - the list of Jimple statements of that method
> Stmt begin - the "current" statement
> Stmt fail - the statement to jump to if the dynamic check fails
> boolean sense - If this is false, inverts the meaning of failure and
> success for the residue
> WeavingContext wc - the weaving context; you probaby won"t be needing that one
>
> So you have to insert, into "chain", just after "begin", code that
> fetches the right counter (the residue should hence have a reference
> to that counter) and if the counter-check fails then the code should
> jump to fail. The exception is when "sense" is false (happens when you
> use the pointcut under negation): then you jump to "fail" when the
> check *succeeds*.
>
> Hope that helps,
> Eric
>
> --
> Eric Bodden
> Software Technology Group
> Technical University Darmstadt, Germany
>
>
>
>
Received on Tue Sep 15 2009 - 20:35:20 BST

This archive was generated by hypermail 2.2.0 : Sun Sep 20 2009 - 11:00:10 BST