Bug 193065 - Improve the extensibility of AspectJ weaver to support PointcutDoctor
Summary: Improve the extensibility of AspectJ weaver to support PointcutDoctor
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 enhancement (vote)
Target Milestone: 1.5.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-18 02:29 EDT by Linton Ye CLA
Modified: 2012-04-03 15:32 EDT (History)
2 users (show)

See Also:


Attachments
Preliminary Implementation (5.18 KB, patch)
2007-10-26 11:31 EDT, Linton Ye CLA
no flags Details | Diff
2nd Impl (9.71 KB, text/plain)
2007-11-26 14:07 EST, Linton Ye CLA
no flags Details
Test case and javadoc (10.01 KB, patch)
2007-12-07 03:21 EST, Linton Ye CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Linton Ye CLA 2007-06-18 02:29:53 EDT
As seen at AOSD 2007, PointcutDoctor (http://pointcutdoctor.cs.ubc.ca) 
is a natual extension of AJDT that helps developers write correct 
pointcuts.  It shows *almost matched* join points for a pointcut, and 
explains *why* a pointcut doesn't match (or does match) a given join 
point. 

The goal of this request is to improve the extensibility of AspectJ 
weaver so that tools like PointcutDoctor are able to augment the weaving
process, and thus, run on top of unmodified AspectJ compiler.  

The key of this improvement is to allow an extender to add customized 
ShadowMungers (i.e. subclasses of ShadowMunger) that run in parallel 
to other ShadowMungers such as Advice. That is, as an Advice, these 
additional ShadowMungers will go through each Shadow produced in the 
weaving process and perform operations defined by the extender.

We've overseen the following changes to the current weaver:
- add hooks so that customized shadow mungers can be added into the list 
  of shadow mungers for each ResolvedType:
  -- in class Ajde or AspectJBuildManager (or other better places?),
     add related methods to set/get a CustomShadowMungerFactory
  -- in method addOrReplaceAspect of class CrosscuttingMemeber (or other
     better places?), add calls to CustomShadowMungerFactory to 
     produce customized ShadowMungers and add them to the list.
- add a flag in class Ajde or AspectJBuildManager (or other better places?) 
  to turn on/off this whole extension feature.  The purpose of this is to 
  avoid any performance overhead when the extender tools are not running.

We are more than happy to implement these changes and release them as a 
patch.  We greatly appreciate your comments!
Comment 1 Eric Bodden CLA 2007-06-30 03:33:20 EDT
Sounds like an aspect to me :-)
Comment 2 Andrew Clement CLA 2007-10-26 08:12:53 EDT
have you started on this Linton?
Comment 3 Linton Ye CLA 2007-10-26 11:31:47 EDT
Created attachment 81273 [details]
Preliminary Implementation
Comment 4 Linton Ye CLA 2007-10-26 11:33:24 EDT
Yes, I have started on this earlier.  Please see the attached patch for a preliminary implementation.  

What I have done include:
- Converted weaver project into an AspectJ project, in order to better modularize my change.  
- Added an aspect "CustomMungerExtension", which weaves into CrosscuttingMemberSet  to enable the extension.  It also has a flag to turn on/off the extension.
- Added an interface "CustomMungerFactory", which can be implemented by extenders to create actual mungers.

Now I am refactoring the code of PointcutDoctor to test the validity of this approach.  I have planned to do the following hopefully this weekend and the following week:
- Add custom shadow functionality into "CustomMungerExtension".  This is to support the virtual join point shadow in PointcutDoctor.
- Write tests for extensions added in weaver in weaver/testsrc
- Adjust and write more tests for PointcutDoctor

I would greatly appreciate your comments, Andy.  Especially for my change of converting weaver to AspectJ project, I am not sure if it's an acceptable change but it does enable a nice encapsulation of the extension code.  
Comment 5 Linton Ye CLA 2007-11-26 14:05:33 EST
Please see the updated implementation in the attachment.
There are some major changes in this patch:
- Leave "weaver" as a Java project, rather than an AspectJ project in the preliminary implementation
- According to the new interface of AspectJ compiler, associated a CustomMungerFactory with a AJCompiler.  

If a user wants to turn on this extension, he can just write an implementation of CustomMungerFactory interface and call AjCompiler.setCustomMungerFactory(CustomMungerFactory) when initializing their compiler.

If a user needs to turn off this extension, call AjCompiler.setCustomMungerFactory(null).

By default, the extension is off.

I would greatly appreciate your comments and suggestions on this implementation.  Hope this can be included into the next release of AspectJ.

Thank you very much!
Comment 6 Linton Ye CLA 2007-11-26 14:07:22 EST
Created attachment 83799 [details]
2nd Impl
Comment 7 Andrew Clement CLA 2007-11-26 16:20:18 EST
thanks Linton - i will get to this, I promise.  I'm just drowning in some complexities around moving to Java6 at the mo.
Comment 8 Andrew Clement CLA 2007-12-02 06:42:43 EST
A few comments:

- i've removed the generics from your patch, we do not use Java5 internally at the moment.
- i've removed use of the new for loop, same reason
- could do with some javadoc on the interface you are adding
- could do with a couple of test cases (which would also demonstrate how to use the new CustomMunger support).  This would be in your interest to add since I may accidentally break it when refactoring the codebase if there are no tests for it.

So I've committed your - but it would be nice if you at least did another patch containing javadoc.

thanks!

keyword: iplog (reminds me I have a non-committer patch in the codebase)
Comment 9 Linton Ye CLA 2007-12-02 14:49:29 EST
Thanks Andy!  I will write some unit tests and javadoc and submit a new patch soon.

I noticed that you have checked in the changes for project "weaver".  What about the other two projects "ajde.core" and "org.aspectj.ajdt.core"?  Those changes allow PointcutDoctor set the CustomMungerFactory through a AjCompiler, since it seems the weaver is not directly visible to compiler users.  Does this make sense?
Comment 10 Andrew Clement CLA 2007-12-02 17:37:25 EST
all changes in, my synchronize didnt behave itself so i missed committing the changes in the other projects.
Comment 11 Andrew Clement CLA 2007-12-03 12:43:03 EST
I had to remove your changes from ajde.core, the dependency that introduces from ajde.core to weaver causes chaos on the build machine.  I need a clean build so will get back to this when i can and try and work out a better way to do it.
Comment 12 Linton Ye CLA 2007-12-04 01:52:03 EST
I see.  Would it be possible to expose the AjBuildManager in AjCompiler?  That way I could call the setCustomMungerFactory method in AjBuildManager without requiring that dependency.

something like:  compiler.getAjBuildManager().setCustomMungerFactory(factory)

One concern is that AjBuildManager is in an internal package though.
Comment 13 Linton Ye CLA 2007-12-04 02:14:59 EST
Andy, I just noticed your recent change in cvs.  But I need to access the instance of the factory assigned to the weaver.

Another alternative is to change the signature of the method to:
void AjCompiler.setCustomMungerFactory(Object)
Object AjCompiler.getCustomMungerFactory()
and 
void AjdeCoreBuildManager.setCustomMungerFactory(Object)
Object AjdeCoreBuildManager.getCustomMungerFactory()

Compared to previous approaches, which one works better?
Comment 14 Andrew Clement CLA 2007-12-04 03:17:11 EST
I thought about Object signatures but I dont like that either - but if you need the instance it may be what I do for now.  I wish I had more time to think it through properly.
Comment 15 Linton Ye CLA 2007-12-07 03:19:13 EST
hi Andy, I am attaching a new patch, which consists of a test case and some javadoc comments.  I am not sure where to put the test class (and test data), so it is in tests/org.aspectj.systemtest.ajc154 for now.

Please let me know if there is any problem.  I appreciate your help!
Comment 16 Linton Ye CLA 2007-12-07 03:21:39 EST
Created attachment 84711 [details]
Test case and javadoc
Comment 17 Andrew Clement CLA 2007-12-07 08:49:58 EST
thanks Linton, all committed.  I still haven't integrated the single test into the  entire suite because when I tried that it failed. (It runs fine standalone).  I dont think it plays nicely when run from a different project - possibly it is abusing the sandbox dir.



iplog.
Comment 18 Linton Ye CLA 2007-12-12 12:38:54 EST
(In reply to comment #17)
> thanks Linton, all committed.  I still haven't integrated the single test into
> the  entire suite because when I tried that it failed. (It runs fine
> standalone).  I dont think it plays nicely when run from a different project -
> possibly it is abusing the sandbox dir.
> 
> 
> 
> iplog.
> 

I just got time to look at this.  I didn't know that the test will be run from a different project.  

Would the following "less abusing" update work?  It works on my machine at least.  Could you give me some suggestions if it doesn't work well?
<code>
class CustomMungerExtensionTest {
...
	File oldSandBoxDir;
	protected void setUp() throws Exception {
		super.setUp();
		oldSandBoxDir = sandboxDir;
		sandboxDir = new File("../tests");
	}
	
	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
		sandboxDir = oldSandBoxDir;
	}
}
</code>