Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Conditional Compilation and AspectJ

> but found after checking the bytecode that the compiler converted 
> the advice into a method even though it would never get executed.
> 
> Is there a reason for this? 

The advice "method" is generated during the source code compilation phase. 
During the weaving phase we do the pointcut matching and determine that a 
pointcut of the form if(false) could never match, and so do not weave an 
advice call at any join points. It would be an extra implementation step 
(though quite safe) to then go and prune the never-called advice method - 
but in reality the effort is not worth it as you would save only a few 
bytes compared to the overall program size

-- Adrian
Adrian_Colyer@xxxxxxxxxx



"Lendvai Attila" <Attila.Lendvai@xxxxxxxxxxx> 
Sent by: aspectj-users-admin@xxxxxxxxxxx
26/11/2004 09:56
Please respond to
aspectj-users@xxxxxxxxxxx


To
<aspectj-users@xxxxxxxxxxx>
cc

Subject
RE: [aspectj-users] Conditional Compilation and AspectJ






 
Even in the rules of plain old java, such an optimization would be valid 
if based on an expression only depending on private static final 
variables. But Java is not that language...
 
"It would be too complex for the masses" - IOW - "We know better what you 
need to be more efficient"
"Macro level (compile time execution) is only needed for buggy languages 
like c++"
"Dynamic reflection means slow code"
"Strict typing is The Holy Grail"
etc.etc.etc... :)
 
Unfortuantely I have to say that we should learn to live with it, or move 
on. Java is not that language...
 
But IMHO your example could work, and would be helpful nevertheless.
 
Just my 2 cents,
 
- 101
 

Hi all,

One of the features missing from the java language is a pre-processor to 
handle conditional compilation.  Many people will point out that this was 
only really needed in C++ to handle different platforms and that its 
possible to imitate #ifdef kind of constructs using static variables, 
which is how the guys at Philips reduce their preprocessing directives for 
their Koala component technology.

ie.

private final static boolean DEBUG = true;
 
..
 
        if(DEBUG)
        {
        ... some functionality
        }
 
whereby setting DEBUG  as a static variable would cause the compiler to 
include the code or not.
I've been wondering if it is possible to do the same thing in AspectJ on 
advice, whereby the compiler would know that the branches could not be 
reached so would not include them.
 
I put together a simple aspect as shown below
 
aspect X
 
{
    private final static boolean CHECK = false;
 
    pointcut something() : call (public void SomeClass.printMsg(String));
    pointcut check() : if(CHECK);
 
    before() :something() && check()
    {
        //.. some functionality
    }
}
 
but found after checking the bytecode that the compiler converted the 
advice into a method even though it would never get executed.
 
Is there a reason for this? 
 
Cheers
Neil
 
 
 



Back to the top