Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » How many methods does a pointcut add?(It seems instead of weaving, AJDT is adding a bunch of methods and increasing code size)
How many methods does a pointcut add? [message #1690213] Wed, 25 March 2015 17:15 Go to next message
Ori Lentz is currently offline Ori LentzFriend
Messages: 2
Registered: March 2015
Junior Member
Hey all,

I hope someone might be help me (and thanks in advance to anyone who tries).

I am using AJDT (download.eclipse.org/tools/ajdt/43/update) with eclipse. When testing to see how it operates, I see that it simply adds about 2 methods (beyond the pointcut itself) for each pointcut.

Example code:

package com.mytest.aspects;

public class HelloWorld {

	public static void main(String[] args) {
        	foo();
	}

        private static void foo() {
        	System.out.println("Hello world");
       }

}


Example aspect:

package com.mytest.aspects;

public aspect HelloAspect {

	pointcut foo() : call (void com.mytest.aspects.HelloWorld.foo(..));
	void around() : foo() {
		System.out.println("weaving foo...");
		proceed();
	}
}


When i decompile (using JD-Gui), I see that the aspect class has been added 3 methods (AspectOf, hasAspect and a static constructor), and that the pointcut is not implemented by injecting a code, rather by overwriting the call to a new pointcut:

package com.mytest.aspects;

import java.io.PrintStream;
import org.aspectj.runtime.internal.AroundClosure;

public class HelloWorld
{
  private static final int foo_aroundBody0()
  {
    foo();
  }
  
  public static void main(String[] args)
  {
    foo_aroundBody1$advice(HelloAspect.aspectOf(), null) == 2);
  }
  
  private static final int foo_aroundBody1$advice(HelloAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure)
  {
    System.out.println("weaving foo...");
      AroundClosure localAroundClosure = ajc$aroundClosure;
    foo2_aroundBody0();
  }
  
  private static void foo()
  {
    System.out.println("Hello World");
  }

}


Am I perhaps missing something? Is this the proper way AspectJ works?

Moreover, for a call pointcut, it seems 2 methods are added for each call to a method, even if both done in the same class.

I am trying to avoid adding so many methods to my code, since my aspiration is to use this for an Android application and earlier versions of android cannot have more 65,536 methods (and using various jars, it is easy to reach that number, especially if the aspects add so many methods).

Any know if this is right or is there something else I should be doing?
Re: How many methods does a pointcut add? [message #1690331 is a reply to message #1690213] Thu, 26 March 2015 16:07 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
Yes, this is the way that AspectJ works. AspectJ is implemented using bytecode manipulation to instrument your class files. This is the way that AspectJ is implemented and there is not much you can do to get around that.

My only suggestion is to be intelligent about how and where your Aspects get woven into the code. Try to limit it and try not to weave into third party libraries.
Re: How many methods does a pointcut add? [message #1690354 is a reply to message #1690331] Thu, 26 March 2015 19:11 Go to previous message
Ori Lentz is currently offline Ori LentzFriend
Messages: 2
Registered: March 2015
Junior Member
Thanks for your answer.

I'm afraid I'm using AspectJ in order to log some aspects (no pun intended) of my application, including in third party libraries.

Does anyone know perhaps of some other way to achieve something much more similar to injection, or preferably that adds less methods (as the call pointcut)? Is there some other tool or compiler out there which can inject / crosscut java code?

Thanks.
Previous Topic:AspectJ Maven and AjcClosure classes
Next Topic:SVN checkout not working in Eclipse
Goto Forum:
  


Current Time: Wed Dec 13 11:28:30 GMT 2017

Powered by FUDForum. Page generated in 0.01787 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software