NonStop Server for Java 5.1 Programmer's Reference
Calling Java Methods from C or C++
You can create your own C or C++ program and use the Invocation API to load the JVM into an arbitrary native
program. Be sure to follow these guidelines:
Compile code written in C++ by using the -Wversion2 or -Wversion3 compiler, and the
-WIEEE_float compiler command-line options.
●
The NonStop Server for Java 5.1 provides DLLs. Therefore, you can build an executable and link it with the
JVM DLL, libjvm.so. For more information, see the invocation_api demo provided
with the NonStop Server for Java 5.1 installation.
●
Do not set signal handlers for the following signals: SIGSEGV, SIGPIPE, SIGCHLD, SIGINT, SIGQUIT,
SIGTERM, and SIGHUP.
●
Set the executable to use IEEE floating point.●
NonStop Server for Java 5.1 does not support the signal-chaining facility implemented in some other vendors'
JVMs.
When a program uses the Invocation API to start a JVM, its function returns are parameters of type float or
double that are in IEEE floating-point format. Any parameters of type float or double that are passed to
NonStop Server for Java 5.1 must also be in IEEE floating-point format. If such a program wants to convert
between TNS floating-point format and IEEE floating-point format, the Guardian Procedure Calls Manual
documents a series of procedures with names beginning with NSK_FLOAT_ that can be used to convert float
and double data between the two formats.
To run the Invocation API demo, follow the instructions for the Invocation API demo in the README file in the
directory /usr/tandem/java/demo/invocation_api.
Linker and Compiler Options
Compiler Options
When you compile C++ source for use with NonStop Server for Java 5.1, you must use the following compiler
options to identify which dialect of the C++ compiler is to be used:
-Wversion2 or
-Wversion3
In addition, for a compilation unit containing JNI code that has any floating-point parameters being passed across
the JNI boundary and that is directly called by the JVM, you must use the compiler option:
-WIEEE_float
Any compilation units not called directly by the JVM can be compiled without the –WIEEE_float option;
however, the complications that can occur while using such mixed modes are beyond the scope of this document.
However, the javahjni demo shows an example of mixed modes. (For information on demos, see
Demonstration Programs.)