Bug 51230 - Optimization of if pointcut
Summary: Optimization of if pointcut
Status: REOPENED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-05 06:32 EST by knizhnik CLA
Modified: 2009-08-30 02:50 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description knizhnik CLA 2004-02-05 06:32:12 EST
It wwill be nice if AspectJ can avoid generation of runtime check for if 
primitive pointcut if expression can be eveluated at compile time.
The most important example is deecting access to self fields. 
Such optimization is very important for persistence and remoting aspects.
If we access field of "foreign" object, then object has to be loaded first.
If we access field of this object (most common case), then no extra checks are 
needed. Pleas notice that exact check is not needed. For example:

MyObject o = this;
o.foo = 1;

It is not critical that here access to "foo" will be not be treated as "this"
access.

In AspectJ poincut for matching access to non-this fields can be written in 
the following way:

nonSelfGet(Peristent self, Persistent dst): get(* Persistent.*) && target(dst) 
&& this(self) && if(dst != self);

Unfortunatelly this pointcut requires runtime check, which makes this 
optimization completely useless. Instead of two byye code instructions
ApsectJ inserts 20 instruction, which cause increase of byte code about 10 
times and about 3 times decrease speed:

   0:   aload_0
   1:   getfield        #27; //Field x:I
--------
   0:   aload_0
   1:   astore_1
   2:   aload_0
   3:   aload_1
   4:   invokestatic    #110; //Method DynamicTest$CheckFieldAccess.ajc$if_0:
(LDynamicTest;LDynamicTest;)Z
   7:   ifeq    19
   10:  invokestatic    #102; //Method DynamicTest$CheckFieldAccess.aspectOf:()
LDynamicTest$CheckFieldAccess;
   13:  aload_0
   14:  aload_1
   15:  invokevirtual   #106; //Method 
DynamicTest$CheckFieldAccess.ajc$before$DynamicTest$CheckFieldAccess$543:
(LDynamicTest;LDynamicTest;)V
   18:  aload_1
   19:  getfield        #27; //Field x:I

But in most cases it is possible to calculate this condtion during compile 
time! For all "this" accesses (in terms of Java fields access without 
specifying base object, in terms of byte code - fields of instance method 
which targt is loaded using aload_0 instruction), specified if condition is 
always false. So no runtime check needs to be inserted.

Also it may be possible to calculate at compile time some other kinds of if 
conditions, for example instanceof checks. Certainly it is not so important, 
because most of such checks can be rewritten using other pointcuts which do 
not require runtime checks. May be there are other useful conditions which
can not be expressed in other way and which can be calculated at compile time.

So I wonder if this change request will be consiidered to be useful and can be 
easily implemented.
Comment 1 Jim Hugunin CLA 2004-03-18 13:07:49 EST
This is a useful optimization idea, but it is unlikely to be implemented any 
time soon without a patch contributed that implements it.  The only reason not 
to do this optimization is the time required to implement and test it 
carefully; however, that's a powerful reason not to do it without a 
contribution.
Comment 2 Adrian Colyer CLA 2005-08-17 14:14:48 EDT
Still a perfectly valid enhancement request, but we have no immediate plans to implement this in the near 
future so moving to "LATER" status for consideration in future planning activities.
Comment 3 Eclipse Webmaster CLA 2009-08-30 02:50:46 EDT
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.