[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] detecting non-this field access

Hello all,

Sorry if this question was already discussed in this mailing list.
I am new user of AspectJ (although I have interested in AOP a long
time ago and even have implemented interface to my OODBMS GOODS using
AOP).
It seems to me that one of the most important aspects
(except tracing and debugging) are persistence and remoting aspects.
I.e. aspects providing transparent access to persistent and remote
objects. In both cases it is very important to distinguish
access to self field from access to "foreign" object. Or in other
words this and non-this access. When we access self field there is
no need in any pre/post processing - this object is already loaded.
But if we access field of a foreign object, we should first load this
object.

I know only one way how to write pointcut detecting non-this access:

nonThisGet(Object self, Object dst):  get(!transient !static * *.*)
&& this(self) && target(dst) && if(self != dst)

But this pointcut is translated in runtime check before access to each
field! AspectJ inserts invocation of method which checks if this is
really equal to target. So instead of optimization (removing extra
requests to check presence of the objects), we get even worse code!

I wonder if I missed something in AspectJ documentation and there is
really a way to distinguish this and non-this access at compile time?
Actually here it is not so important that "target != this".
If programmer write something like this:

   MyClass o = this;
   o.foo = 1;

then it is no so critical that access to "foo" field will be treated
as non-this access.

But it is very important (from performance point of view) to be able
to avoid extra code for each access to self instance variable.

Efficient implementation of persistence aspect can be do in the
following way:

1. Insert at the beginning of each method of persistent capable class
code responsible for loading object.

2. Detect all non-this accesses to the fields and insert before them
object loading code.

3. Detect all assignments to fields of persistent capable objects and
insert before them code which will mark target object as dirty.
As optimization it will be nice to avoid generation of such code in
constructors (except assignment to fields of other objects - once again
non-this access detection is needed). And the smartest AOP tool will allow
to specify some action once per basic block (to avoid extra invocations
of dirty() method for subsequent assignments).

1) can be easily implemented with AspectJ. 3) - partly.
And 3) - only by runtime check which makes such optimization useless.


So I wonder if AspectJ developers though about described above
scenario? Or is it something wrong with it?
Once again sorry if such functionality is provided by AspectJ and
I just was not able to locate it.

-- 
Thanks in advance,
 Konstantin                          mailto:knizhnik@xxxxxxxxx