Home | About | Partners | Contact Us
SourceForge Logo

Quick Links

Home
News
Thoughts and Rants
License
SourceForge Info
Download
Browse CVS
Mailing Lists

Thin Tools Examples...

Symbolic Differentiation
Constant folding
Execution Tracer
Contracts in Java
Removing useless code

Understanding...

Concept programming
Moka
XL
Thin Tools
Active Libraries
Refactoring
Optimizations
Coda
Notes

More Info

Contributors
Related Ideas
Some history
Applications
Other links
The GNU Project

Tracer Thin Tool

Concept programming relies on the addition of arbitrary concepts to programs. In general, creating new abstraction degrades the debuggability of programs: error messages tend to get worse, and debugging tools don't know anything about the new abstraction. For instance, a debugger generally won't know how to print the contents of a List class.

Concept programming let you add debugging capabilities as concepts. Therefore, it becomes possible to create the debugging tools that go along with the new concepts. The tracer thin tool illustrates this, by automating the generation of tracing code. This is arguably a simplistic example, but it illustrates a dimension that classic "software components" cannot even address.

Tracing Java code

To insert tracing code in a program, you simply need to invoke the tracer plug-in, and to define methods BeenThere and DoneThat. The method BeenThere is called at the beginning of each method, the method DoneThat is called at the end. The plug-in is invoked from Moka by the +tracer option.

% moka tests/example11.java +tracer -out

The plug-in identifies the methods in the following code:

public interface Colorable
{  
   void setColor(byte r,
      byte g,
      byte b)
;
}
class Point
{  
   int xy;
}

class ColoredPoint extends Point implements Colorable
{  
   byte rgb;
   
   
public void setColor(byte rv,
      byte gv,
      byte bv)
   {  
      r = rv;
      g = gv;
      b = bv;
   }

}

class Test
{  
   public static void main(String[] args)
   {  
      Point p = new Point ();
      ColoredPoint cp = new ColoredPoint ();
      p = cp;
      Colorable c = cp;
   }

}

The plug-in then inserts the calls to BeenThere and DoneThat, wrapped in a try/finally clause, so that the DoneThat calls are always invoked on exit, even in the case of exception termination.

public interface Colorable
{  
   void setColor(byte r,
      byte g,
      byte b)
;
}
class Point
{  
   int xy;
}

class ColoredPoint extends Point implements Colorable
{  
   byte rgb;
   
   
public void setColor(byte rv,
      byte gv,
      byte bv)
   {  
      try
      {  
         BeenThere ("setColor"0);
         r = rv;
         g = gv;
         b = bv;
      }
      finally
      {  
         DoneThat ("setColor"0);
      }
   }

}

class Test
{  
   public static void main(String[] args)
   {  
      try
      {  
         BeenThere ("main"1);
         Point p = new Point ();
         ColoredPoint cp = new ColoredPoint ();
         p = cp;
         Colorable c = cp;
      }
      finally
      {  
         DoneThat ("main"1);
      }
   }

}

Other uses

The plug-in is not really useful as is, but it is designed as a really small and simple basis (less than 100 lines of code) on which you can build many more useful tools: counting how many times each method is invoked, slowing down a program for testing, validating program invariants (although the assert plug-in might be a better choice for that)...


Copyright Christophe de Dinechin
First published Feb 17, 2000
Version 1.4 (updated 2004/01/20 06:16:14)