[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] writing an aspect to check for Swing Thread Safety

>  Now I am attempting to add a new aspect to
> help check for Swing Thread Safety. 

This is an interesting application.  If you get it to
work, it would be nice to see the solution on the list.

> I would like to put a
> pointcut on all executions to javax.swing code 

One factor to consider, from the Programming Guide 
appendix C, "implementation limitations":

  execution join points can be advised only if 
  ajc controls the code for the method or 
  constructor body in question

So you can advise only the swing subclasses passed as 
source to the AspectJ compiler.  It will not advise
libraries on the classpath.  It should advise any 
such subclasses in your sources.  I suspect you know
this, but thought it worth mentioning.

Another factor is the pointcut:  

>     pointcut restrictedExecution(): execution(*
> javax.swing+.*(..))
>                                  ||
> execution(javax.swing+.new());

+ works on types, not packages.  Try this (untested):

  from: execution(* javax.swing+.*(..))
    to: execution(* javax.swing..*+.*(..))
    or: target(javax.swing..*+) && execution(* *(..))

tip: for staticly-determinable pointcuts like the method 
execution PCD, you can debug it at compile time using
declare warning:

   pointcut testme() : 
       execution(* javax.swing..*.*(..));
  
   declare warning() : testme() : "testme";

You can also use the IDE's (Ajbrowser, et al) to see
what code is affected by particular advice (once
they are working with 1.1?  No response to Nick's
question on point yet).

Wes

> Jim Piersol wrote:
> 
> Hi,
> 
> Absolute AspectJ newbie here.  Been through the docs and a
> few examples.  Now I am attempting to add a new aspect to
> help check for Swing Thread Safety.  I would like to put a
> pointcut on all executions to javax.swing code to check
> the SwingUtilities.isEventDispatchThread() method and
> report a message if the call was made outside the
> EventThread.  This would be used as a development tool to
> find any BAD code that could cause GUI anomalies, i.e.
> deadlocks, painting problems...
> 
> Here is what I am trying so far.  It doesn't seem to do
> what I want though.  It finds calls to things like
> javax.swing.AbstractAction but I purposely added a
> background Thread in a GUI class to instantiate and
> operate on a JTextField, and it nevers reports on it.
> 
> **************************************
> package strata.aspect;
> 
> import javax.swing.*;
> public aspect TraceMyClasses {
> 
>     pointcut restrictedExecution(): execution(*
> javax.swing+.*(..))
>                                  ||
> execution(javax.swing+.new());
> 
> 
>     before(): restrictedExecution() {
>         if (!SwingUtilities.isEventDispatchThread()) {
>            System.out.println("\n-->FOUND NON SAFE SWING
> CALL....."
>                     + "\n--> " +
> thisJoinPointStaticPart.getSignature()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getFileName()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getLine()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getWithinType());
>         }
>     }
> }
> 
> ****************************************************************************************************
> 
> Any help or ideas would be appreciated.  I will be sure to
> post any final results I receive from this thread.
> 
> Thanks,
> Jim
> 
>     Jim Piersol
> Senior Software Engineer
> Sun Certified Java Developer
> Strata Group, Inc.
> jrp@xxxxxxxxxxxxxxxx
>