Fwd: [abc-users] codeGen dynamic code

From: Eric Bodden <bodden_at_st.informatik.tu-darmstadt.de>
Date: Mon, 14 Sep 2009 23:08:28 +0200

Sorry for the late response. I already sent this on the 29th but my
response got discarded by the list server.


---------- 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 Bodden
Software Technology Group
Technical University Darmstadt, Germany
Eric Bodden
Software Technology Group, Technische Universität Darmstadt, Germany
Tel: +49 6151 16-5478    Fax: +49 6151 16-5410
Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt
Received on Mon Sep 14 2009 - 22:08:51 BST

This archive was generated by hypermail 2.2.0 : Tue Sep 15 2009 - 20:40:12 BST