Tags:
not added yet
OMS JNI ArchitectureThis document serves as a reference for all JNI related issues of OMS components. Supported ScenarioA native source (maybe some subrouting/function out of an existing model) already exists and it should be used as a component. The Java Component can be derived from the Fortran/C source.Calling sequenceIn order to use native code, there need to be three files in total:
Java Component <=> C++ Bridge <=> Fortran/C The Fortran source exists at the beginning, the Java Component is derived/generated from the Fortran/C source, and the C++ Bridge is generated from the Java Component. Compilation & LinkingThe Java source gets compiled into a class file, the other files make it into a dynamic loadable library Component C++ Bridge Fortran/C (Comp.java) (Comp_Bridge.C) (comp.for) | | | Compilation | V V | Comp_Bridge.o comp.o | | | Linking | + ----------+--------------+ | | V V Comp.class libComp.dll Executable Compiler/Linker SettingsCompiler and Linker options for several compiler need to be choosen to ensure the following requirements:
GNU/GCCFortran Compiler Flags to be used:
CCompiler flags to be used: Digital Fortran/MSVCFortran Compiler Flags to be used:
Intel C/FortranTBD<oms.h>The file <oms.h> gets included in a Bridge file. The structure of this file results out of the following strategies:
/** * OMS JNI Support. DO NOT EDIT UNLESS YOU ARE KNOW WHAT YOU ARE DOING! * Jnisupport Version : 1.0 * @author Olaf David * @author Ian Schneider */ #ifdef __CYGWIN__ #define JNIEXPORT __declspec(dllexport) #define JNIIMPORT __declspec(dllimport) #define JNICALL __stdcall typedef long jint; typedef long long jlong; typedef signed char jbyte; #define _JAVASOFT_JNI_MD_H_ #endif #include <jni.h> #if defined(DEBUG) #define GETATTR(TYPE, NAME) \ TYPE __ ## NAME ## __ = (TYPE) GetDebugBuffer(env, NAME, #NAME);\ if (!__ ## NAME ## __) return; #define PRECALL(NAME) { puts("leaving to : #NAME"); fflush(stdout);} #define POSTCALL(NAME) { puts("returning from : #NAME"); fflush(stdout); } #elif defined(FAST) #define GETATTR(TYPE, NAME) \ TYPE __ ## NAME ## __ = (TYPE)GetFastBuffer(env, NAME); #define PRECALL(NAME) #define POSTCALL(NAME) #else #define GETATTR(TYPE, NAME) \ TYPE __ ## NAME ## __ = (TYPE)GetSafeBuffer(env, NAME, #NAME);\ if (!__ ## NAME ## __) return; #define PRECALL(NAME) #define POSTCALL(NAME) #endif /** JNI 1.4 is required to support direct buffers */ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_4; } /** GetSafeBuffer decodes the memory buffer of a Java NIO Buffer object * with checking for exeptions */ void* GetSafeBuffer(JNIEnv *env, jobject buffer, const char* name) { if (!buffer) { env->ThrowNew(env->FindClass("java/lang/NullPointerException"), name); return NULL; } void *nat_buffer = env->GetDirectBufferAddress(buffer); if (!nat_buffer) env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), name); return nat_buffer; } /** GetSafeBuffer decodes the memory buffer of a Java NIO Buffer object * with checking for exeptions */ void* GetDebugBuffer(JNIEnv *env, jobject buffer, const char* name) { if (!buffer) { env->ThrowNew(env->FindClass("java/lang/NullPointerException"), name); return NULL; } void *nat_buffer = env->GetDirectBufferAddress(buffer); puts("Getting Attrbute "); puts(name); if (!nat_buffer) env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), name); return nat_buffer; } /** GetFastBuffer decodes the memory buffer of a Java NIO Buffer object * without checking anything */ static inline void* GetFastBuffer(JNIEnv *env, jobject buffer) { return env->GetDirectBufferAddress(buffer); } The Bridge FileThe Bridge file is usually generated from the component file. The it should be not modified manually. The build system (build.properties) should be used to set definesSupported 'defines'
JNI Component ExampleFortran Source Test.forSUBROUTINE SLOSS(IPLANE,LOAD,TCEND,WIDTH,RSPACE,EFFDRN,THETA, 1 SLPLEN,IRDGDX,QSOUT,DSLOST,AVSOLE,NPLANE,QOUT) C IMPLICIT NONE REAL LOAD(101), TCEND, WIDTH(10), RSPACE(10), EFFDRN(10) REAL THETA, SLPLEN(10) REAL IRDGDX(10), QSOUT, DSLOST(10,100) REAL AVSOLE, QOUT INTEGER IPLANE, NPLANE ..... END C++ Bridge Test_Bridge.C/******************************************************************************* OMS jnisupport generated bridge - DO NOT EDIT (unless you are me) Java Component : gov.test.Test Creation Date : 2/1/05 4:57 PM Jnisupport Version : 1.0 *******************************************************************************/ #include <oms.h> // External (Native) Call Prototype extern "C" void SLOSS( int*, // IPLANE double*, // LOAD double*, // TCEND double*, // WIDTH double*, // RSPACE double*, // EFFDRN double*, // THETA double*, // SLPLEN double*, // IRDGDX double*, // QSOUT double*, // DSLOST double*, // AVSOLE int*, // NPLANE double* // QOUT ); // JNI Dispatcher extern "C" JNIEXPORT void JNICALL Java_gov_test_Test_SLOSS ( JNIEnv *env, jobject obj, jobject IPLANE, jobject LOAD, jobject TCEND, jobject WIDTH, jobject RSPACE, jobject EFFDRN, jobject THETA, jobject SLPLEN, jobject IRDGDX, jobject QSOUT, jobject DSLOST, jobject AVSOLE, jobject NPLANE, jobject QOUT ) { GETATTR(int*, IPLANE) GETATTR(double*, LOAD) GETATTR(double*, TCEND) GETATTR(double*, WIDTH) GETATTR(double*, RSPACE) GETATTR(double*, EFFDRN) GETATTR(double*, THETA) GETATTR(double*, SLPLEN) GETATTR(double*, IRDGDX) GETATTR(double*, QSOUT) GETATTR(double*, DSLOST) GETATTR(double*, AVSOLE) GETATTR(int*, NPLANE) GETATTR(double*, QOUT) PRECALL(SLOSS) SLOSS( __IPLANE__, // IPLANE __LOAD__, // LOAD __TCEND__, // TCEND __WIDTH__, // WIDTH __RSPACE__, // RSPACE __EFFDRN__, // EFFDRN __THETA__, // THETA __SLPLEN__, // SLPLEN __IRDGDX__, // IRDGDX __QSOUT__, // QSOUT __DSLOST__, // DSLOST __AVSOLE__, // AVSOLE __NPLANE__, // NPLANE __QOUT__ // QOUT ); POSTCALL(SLOSS) return; } // Reloadable dispatcher extern "C" JNIEXPORT void JNICALL Java_gov_test_Test_SLOSSdispatch ( JNIEnv * env, jobject obj, jobject * args) { Java_gov_test_Test_SLOSS( env,obj,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13] ); return; }; |
Navigation Bar for Object Modeling System
Resources:
Downloads You must login to see this link. Register now, if you have no user account yet. OMS API Javadoc Publications & Presentations Annotation Reference DSL Reference Handbook 3.0 (Draft) Frequently Asked Questions (FAQ) OMS License (LGPL 2.1) New Users: 1. Get an ALM account 2. Join the OMS project Contact Us: Jack Carlson Coordinator, OMS Laboratory OMS Laboratory Jack.Carlson@colostate.edu (970) 492-7323 Olaf David Director, OMS Laboratory odavid (at) colostate.edu (970) 491-8026 |