Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Accessing JNI services

The Java Native Interface (JNI) provides many callable services that you can use when you develop applications that mix COBOL and Java. To facilitate access to these services, copy JNI.cpy into the LINKAGE SECTION of your COBOL program.

The JNI.cpy copybook contains these definitions:

You obtain the JNI environment structure by two levels of indirection from the JNI environment pointer, as the following illustration shows:

This figure shows the JNI environment structure: JNIEnvPtr points to a per-thread pointer that points to an array of JNI function pointers.

Use the special register JNIEnvPtr to reference the JNI environment pointer to obtain the address for the JNI environment structure. JNIEnvPtr is implicitly defined as USAGE POINTER; do not use it as a receiving data item. Before you reference the contents of the JNI environment structure, you must code the following statements to establish its addressability:

Linkage section.
COPY JNI
. . .
Procedure division.
    Set address of JNIEnv to JNIEnvPtr
    Set address of JNINativeInterface to JNIEnv
    . . .

The code above sets the addresses of the following items:

After you code the statements above, you can access the JNI callable services with CALL statements that reference the function pointers. You can pass the JNIEnvPtr special register as the first argument to the services that require the environment pointer, as shown in the following example:

01 InputArrayObj usage object reference jlongArray.
01 ArrayLen pic S9(9) comp-5.
. . .
    Call GetArrayLength using by value JNIEnvPtr InputArrayObj
      returning ArrayLen

Important: Pass all arguments to the JNI callable services by value.

Some JNI callable services require a Java class-object reference as an argument. To obtain a reference to the class object that is associated with a class, use one of the following JNI callable services:

Restriction: The JNI environment pointer is thread specific. Do not pass it from one thread to another.

related references  
JNI.cpy  
The Java Native Interface


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)