Enhancement For Java
db4o enhancement framework relies on the following jars:
bloat-1.0
|
Third-party bytecode instrumentation library
|
db4o-x.x-instrumentation
|
Instrumentation library on top of bloat
|
db4o-x.x-tools
|
Enhancement and other utilities
|
In addition
- for TA
/TP instrumentation enhancement db4o-x.x-taj.jar should be used (contains TA
/TP instrumentation classes);
- for
NQ optimization db4o-x.x-nqopt.jar is used (provides instrumentation
functionality for NQ).
The basic steps required to enhance classes are:
- Create
ClassFilter instance to select the classes for enhancement. ClassFilter is
an interface in db4oinstrumentation project and is implemented by several
classes, like AcceptAllClassesFilter, ByNameClassFilter and others (see
ClassFilter hierarchy for a list of all implementations).
- Create
BloatClassEdit array of classes capable of editing class bytecode.
BloatClassEdit is an interface in db4oinstrumentation project. Among its
implementations are TranslateNQToSODAEdit (implements NQ optimization) and
InjectTransparentActivationEdit (injects TA/TP awareness). Filter can be used
in some of the edit classes (InjectTransparentActivationEdit).
- For
load-time instrumentation the edit classes created above are passed to
Db4oInstrumentationLauncher together with the application entry point
class. Db4oInstrumentationLauncher is a public class in db4oinctrumentation project, which creates a special instrumenting classloader and uses it to
load the application's main class.
- For
build time instrumentation Db4oFileEnhancerAntTask is used to create an
enhancer task in Ant, which must call the class edit classes inside.
Db4oFileEnhancerAntTask is a class extending Ant task in db4oinstrumentation project. It loads and instruments the classes using class edits supplied
as parameters to the enhancer task and copies the resulted classes to the
output directory. It can also work on Jars instead of classes.
The examples below shows how enhancer works at load and
build time: