ASM/C Interfaces - Natives
SNI - Simple Native Interface
SNI is a standardized library API registered to the ESR Consortium (ESR012).
It allows to interface Java and C code by providing calls and
data sharing. SNI focuses on both simplicity
and performance /
memory footprints (zero-copy buffers).
Java to C call Example
- Java code:
package examples; public class Hello{ public static void main(String[] args){ int i = printHelloNbTimes(3); } public static native int printHelloNbTimes(int times); }- C code:
#include "sni.h" #include "stdio.h" jint Java_examples_Hello_printHelloNbTimes(jint times){ while (--times){ printf(“Hello world!\n”) ; } return 0 ; }
C to Java call Example
- Java code:
package examples; public class Hello{ public static void printHelloNbTimes(int times){ while (--times){ System.out.println(“Hello world!”) ; } } }- C code:
#include "sni.h" void main(){ SNI_callJavaVoidMethod(Java_examples_Hello_printHelloNbTimes, 3) ; }
SP - Shilded Plug
The Shielded Plug, SP, provides a secured means to interface Java and C. While SNI allows to call directly C functions from Java, SP reduce the interfae to data messaging based on a publish / subscribe interface type.
SP provides segregation of the processes, which can be written either in C or in Java. It allows the certification of each individual part individually. The data sharing between processes uses the concept of shared memory blocks, with introspection on those blocks. Facilities provided include: notification when the content changes, re-initialization of the block, testing the presence of data in the data block, and a mechanism for serialization and de-serialization.
SP allows the creation of several data stores. These can be defined entirely statically, or increase in number during the execution of a program. Reading and writing in the shared memory are operations with predictable performance characteristics.

