Skip to content
Fabien DUMINY edited this page Aug 23, 2015 · 4 revisions

Classlib developers guide

Important : This is a work in progress with informations gathered from many sources, like http://www.jnode.org/node/2973

The JNode class library (Classlib) can be seen as the "JDK for JNode". It's compound of classes from OpenJDK, IcedTea and GNU Classpath. It also contains JNode specific classes and tools.

Native binding

In JNode, each method marked native must have its java implementation.

Let say we have the following class :

package my.pkg;
public class MyClass {
    private int aPrivateValue;

    private native int aNativeMethod(char c);

    private static native String aStaticNativeMethod(char c);
}

The Classlib developer must add the following class :

package my.pkg;
public class NativeMyClass {
    private static int aNativeMethod(MyClass myClass, char c) {
        // implementation of the native method for JNode
        return myClass.aPrivateValue;
    }

    private static String aStaticNativeMethod(char c) {
        // implementation of the native method for JNode
        return c + " ";
    }
}

The key points are :

  • Create a class in the same package.
  • Prepend Native to the class name (even if it already starts with Native) to get the new class name.
  • In the new class, copy each method marked as native and modify its signature :
    • Remove the native keyword
    • If the method is not static, add the static keyword and add an extra argument at the first place : the type of this argument must be the source class
    • If the method is static, there is no more modification to do

The above work is (almost) completely done by NativeStubGenerator class.

Clone this wiki locally