We give two simple code examples, followed by a more complex one.
1. Recovery aspect
This first example aspect checks whether a critical SQL query (call to _iqcftch) has been
interrupted by a database error. If the particular error which popped up is recoverable, the aspect
tries to fix the error up to a maximum number of attempts. If the error still persists, an
error-specific message is prompted. This example works for Aspicere1 and Aspicere2, but with a slightly
different syntax.
Of course, the notion of "a critical SQL query" is subject to interpretation. Developers can annotate
queries, or use Prolog facts and rules for this. Here, we use the latter approach:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
:-load_library('KnowledgeLibrary').sql_code(-666,'The statement cannot be executed, because a time limit was exceeded.').sql_code(-910,'The object cannot be used, because an operation is pending.').sql_code(-542,'Invalid SQL code.').sql_code(-357,'The file server is currently not available.').sql_redo(-666,2).sql_redo(-357,3).sql_redo(-542,0).critical_method('monthlyPayment').critical_call(Jp):-enclosingMethod(Jp,EncMethod),execution(EncMethod,Name),critical_method(Name),print('CRITICAL call found!!!'),nl.
2. Optimizer aspect
In this example, we optimize an SQL-query by modifying the argument of the call to _iqcprep.
The /*@halting()*/-annotation means that we want to stop the
execution of procedure f if the call to g returns zero (which is always true
here for the sake of simplicity). In other words, printf("C") must NOT be executed. For
this, we need the following advice:
This advice does the following: if the return value of a /*@halting()*/-annotated call equals zero, the delimited continuation
(i.e. the remaining execution within procedure f after the call to g)
is skipped (not proceeded). Otherwise, the remaining execution is resumed (proceeded). In other words,
we get "ABD" as output.
How do we define the halting_invocation/2 predicate? For this, we need to attach a join point property to procedure f in order to
temporarily store the return value of /*@halting()*/-annotated
calls:
Basically, there is a check whether JpCall is a call annotated with a /*@halting()*/ annotation. If so, the current value of the return_var property attached to the calling execution join point
property is returned.
In this paper, we apply delimited continuation join points to extract an
idiom-based exception handling idiom into aspects.
Releases
There are two implementations of Aspicere. Aspicere2 fully implements Aspicere,
whereas Aspicere1 only provides a small subset.
Aspicere1
Beta 1 is the aspect weaver we used in the Kava casestudy. This means
that it is able to weave in K&R- as well as in ANSI C-code.
Unfortunately, in the former case, there are times when method prototypes don't declare the types of
their arguments. Aspicere1 infers these types from a procedure's call site, but does not support all
possible C types. In those cases, our weaver merely "skips" the
relevant join points without halting the full weaving process. The weaver shows statistics about the
relative percentage of "skipped" join points.
Aspicere1 has the following limitations:
only supports call join points
(with GCC 4.x on non-OSX platforms) modifying captured arguments of advised procedures gives a
compilation error
does not advize function pointers
multiple advices on the same join point are allowed, but advice on advice is not possible yet
As a manual workaround for the GCC 4.x bug, one can do the following:
open the file which refuses to compile
regexp-replace all "# .*" (mind the space) by ""
retry the offended GCC command and note down the erring line numbers
reopen the file which refuses to compile
go to the relevant lines and replace the casts like (char*)voidptr=charptr; by
voidptr=(void*)charptr;
recompile the corrected file
Aspicere1 is covered under a Tri License scheme: MPL/LGLP/GPL.
It depends on Yerna Lindale and Lillambi, but these are included in the
download. Furthermore, you need a Java 1.4-compatible VM, a C compiler, Perl interpreter and Bash shell.
The included INSTALL file contains detailed installation instructions for Aspicere1.
Aspicere2
Aspicere2 is also covered under a Tri License scheme: MPL/LGLP/GPL. It has the following dependencies:
This is the most recent version of Aspicere2, used inmultiplepapers.
The best documentation can be found here. The included INSTALL
file contains installation instructions for all of these and for Aspicere2 itself.
Publications
Michael Haupt, Bram Adams, Stijn Timbermont, Celina Gibbs, Yvonne Coady and Robert Hirschfeld (2009). Disentangling Virtual Machine Architecture, IET Software (Special Issue on Domain-specific Aspect Languages), 3(3), p. 201-218.
Bram Adams, Wolfgang De Meuter, Herman Tromp and Ahmed E. Hassan (2009). Can we Refactor Conditional Compilation into Aspects?, in Proceedings of the 8th international conference on Aspect-oriented Software Development (AOSD) (Charlottesville, VA, US), p. 243-254, ACM. (Acceptance ratio: 19/86=22%) (Most Influential Paper Award)
Bram Adams, Charlotte Herzeel and Kris Gybels (2008). cHALO, Stateful Aspects in C, in Proceedings of the 7th Workshop on Aspects, Components, and Patterns for Infrastructure Software (ACP4IS) (Brussels, Belgium), p. 1-6, ACM.
Kris De Schutter and Bram Adams (2007). Aspect-orientation For Revitalising Legacy Business Software, in Proceedings of the ERCIM Working Group on Software Evolution, Electronic Notes in Theoretical Computer Science (ENTCS) (06-07 April 2006, Lille, France), 166(1), p. 63-80, Elsevier.