Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Compile-time errors

Title: Message
As Elizabeth says, you are talking about a dynamic condition, and the static declare error/warn mechanism can't handle it.
 
Also as Elizabeth says, one possibility is to just switch to use AspectJ to add/remove the listeners.  If you pay attention to getting the pointcuts involved really clean, that should make your add/remove policy clear, and the new code won't have the current problem.
 
But there are two other approaches worth bringing up.  These are of interest if, for some reason, you are just using development aspects, and are not yet in a position where you can use AspectJ in actual shipping code.
 
 
Approach 1: Dynamic Debugging Aspects
 
One approach would be to write some debugging aspects that would help find this problem.  For example, something like:
 
  before(Listener l): call(void add(Listener)) && args(l) {
     record(l, thisJoinPoint);
  }
 
This might help you figure out which subset of your listeners isn't being freed properly.
 
 
Approach 2: Use AspectJ as a Design Tool
 
Another idea would be to temporarily, just in your own development tree, use AspectJ to implement the add/remove.  You could either comment out all the old add/removes, or use AspectJ to render them null.  If, as mentioned at the top of this message, you worked to get the pointcuts that describe when to add/remove really clean, then those pointcuts will effectively represent your design for what the add/remove invariants should be.
 
Once you have that clean design, you can go manually weave that back into the real production sources.  At each site you weave it in, you can put the pointcut as a comment to explain what is going on.
 
 
Both of these approaches are just specific examples of standard ways to get maximum value out of AspectJ if you are still working in a period where you aren't yet ready to run your actual shipping code through the AspectJ compiler.
 
-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Echlin Harmer, Elizabeth
Sent: Thursday, April 10, 2003 8:48 AM
To: 'aspectj-users@xxxxxxxxxxx'
Subject: RE: [aspectj-users] Compile-time errors

Hi Hugo
I don't know of any way to make a compile time aspect that will do what you want (very interested to know if one of the experts knows of a way!). Without knowing the control flow of your application, I don't see how any static compile time view would work, I mean methods A, B and C could all add listeners, with no remove, but be ok if the control flow always comes back to method D which removes the listeners. Likewise method Q could have calls to both add and remove but depending on context (ordering and conditional execution) could add a listener that never gets removed.

Can you come up with a pointcut that defines "when it is appropriate" to remove the listener? Then just have the aspect define advice to remove any dangling listeners at that point. If you don't want the aspect in your production code, you could use the aspects you defined below to dynamically keep track of who added and removed listeners, and have the "appropriate" pointcut generate logging/debugging info to identify the culprits who added the listeners that didn't get removed.

Good luck!
Elizabeth

-----Original Message-----
From: Hugo Magalhães [mailto:Hugo.Magalhaes@xxxxxxxxxxx]
Sent: Thursday April 10, 2003 11:14 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Compile-time errors


Good afternoon.

It's possible to create an compile time Aspect to see if each listener added to a model is also removed from the model when appropried? The reason for this is that our application has memory leaks due to the fact that not all of our listeners are removed when appropried, and because it's an application with a considerable amount of code, this type of Aspect could be a great help in finding those lost listeners.

I´ve created an Aspect with two pointcuts that catch all methods that add listeners to a model and all that remove listeners but they work independently. Is there any way to put them to work together?

The code is the following:

----------------------------------------------

- Aspect:

1.  public aspect EventCallListener {
2.                             
3.  pointcut addListenerCall(Object model, java.util.EventListener listener)
4.       : call(void *.add*Listener(java.util.EventListener+))
5.       && target(model) && args(listener);
6.             
7.  pointcut removeListenerCall(Object model, java.util.EventListener listener)
8.       : call(void *.remove*Listener(java.util.EventListener+))
9.       && target(model) && args(listener);
10.            
11. declare error: addListenerCall(Object, java.util.EventListener)
12.      : "Listener added";
13.            
14. declare error: removeListenerCall(Object, java.util.EventListener)
15.      : "Listener removed";
16                     
17. }

-----------------------------------------------

Thanks in advance,
Hugo Magalhães



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top