IT Management

The Java Native Interface on z/OS

4 Pages

The code in Figure 1 calls into the pre-initialization routine to create the HLL environment. The variables used in the call are:

  • INITSUB: The value 3 indicates this is a request to initialize the environment to execute subroutines multiple times.
  • ADRPITBL: This contains the address of a table that contains the name of the glue code load module.
  • ADRSRTNS: This contains the address of the service routine vector. A zero value indicates there’s no service routine vector.
  • RTOPTS: This is a fixed-length field containing the run-time options.
  • TOKEN: This value is used to represent the newly created environment. It’s used in subsequent calls.

The table that contains the name of the glue code module, known as the preinit table, is created using three macros. The operands on the CEEXPITY macro are the name of the glue code module and its entry point. A zero value says the module is to be dynamically loaded. The first entry in the table has an index of 0. A second entry would have an index of 1. The sequence of index numbers continues as you’d expect. This index value is used in subsequent calls.

The code in Figure 2 calls into the C module to create the JVM. The variables used in the call are:

  • CALLSUB is a call to invoke a subroutine, as indicated by the value 4.
  • PITBLIDX is the index into the preinit table for the module that’s called.
  • TOKEN is the value used to represent the run-time environment and was initialized by the INITSUB call.
  • PARMPTR is a pointer to a parameter list.
  • PARMSTR contains character test data.
  • PARMNMBR contains the function code used by the C module.
  • RETCODE is the subroutine return code.
  • REASCODE is the subroutine reason code.
  • FDBKCODE is feedback information when the environment ends. The information here is useful in determining the cause of an unexpected termination.

The PARMVCTR variable has the address of a string. This is followed by the address of the C module function code, PARMNMBR. The PARMVCTR address is placed into the PARMPTR variable. This is the standard OS linkage in the mainframe environment. The parameter list is a list of addresses.

The code in Figure 3 terminates the HLL environment. The variables used in the call are:

  • TERM is a request to terminate the environment, as indicated by the value 5.
  • TOKEN is a value used to represent the existing environment that’s to be terminated.
  • RETCODE is the subroutine return code.

 

The C Code

This is a simple module that highlights particular points about the JNI. It creates the JVM, gets handles to the Java class and its methods, calls those methods, and destroys the JVM:

#pragma linkage(PRODC2J, fetchable)

4 Pages