Skip to main content

Japex and Native Drivers

Posted by spericas on January 30, 2006 at 2:05 PM PST

Paul Sandoz and I have developed an extension to Japex to support native drivers. This allows a benchmark to compare the relative performance of a C-based XML parser vs. a Java-based XML parser, for example.

Every native driver is an instance of the class com.sun.japex.jdsl.JapexNativeDriver which defines a native method corresponding to each phase in Japex. An important requirement for this extension was for the inner loop of the benchmark to be carried out in native code to avoid crossing the JNI layer multiple times. The new native methods runLoopIterations and runLoopDuration were added for this purpose. These methods should be the same for all native drivers and can be copied from the sample provided in Japex. In the future, however, it is likely that they will be moved into their own library.

Each instance of com.sun.japex.jdsl.JapexNativeDriver must be compiled into a separate dynamic library and specified using the libraryName parameter as shown below:

    <driver name="JapexNativeDriverOne">
        <param name="japex.driverClass"
               value="com.sun.japex.jdsl.nativecode.JapexNativeDriver"/>
        <param name="description" value="Japex Native Driver One"/>
        <param name="libraryName" value="JapexNativeDriverOne"/>
    </driver>

    <driver name="JapexNativeDriverTwo">
        <param name="japex.driverClass"
               value="com.sun.japex.jdsl.nativecode.JapexNativeDriver"/>
        <param name="description" value="Japex Native Driver Two"/>
        <param name="libraryName" value="JapexNativeDriverTwo"/>
    </driver>

Note that the library name, such as JapexNativeDriverOne, should include neither prefixes nor suffixes, such as lib and .so, since these are added automatically by the JNI runtime.

Given that all native drivers are instances of the same class, it follows that every dynamic library will define a common subset of symbols. So how are these symbols loaded into the VM without producing any name clashes? Fortunately, Japex was designed to use a fresh class loader for each driver, which ensures that each dynamic library is loaded into a separate name space (actually, this was an issue in earlier versions of Java in which dynamic link errors did in fact occur).

The fact that a simple sample works, does not mean that this will actually be usable in practice. As we start developing more native drivers, I'm sure will learn the pluses and minuses of this interface and will hopefully be able to improve it. Please send your comments to users@japex.dev.java.net. Happy benchmarking!

Related Topics >>