InOnIt.com
Cygwin/Java
FAQ
Calling C from Java
Starting a JVM from C
Overview
Building an import library
Creating a JVM from C
Invoking the class's main() method
Compiling and executing
MLS Playoff Odds
World Football Rankings & World Cup Odds
NCAA Basketball Ratings
Hearts
Personal Home Pages
David's Company

The Invocation API

The Invocation API allows a Java VM to be created inside a native process. (Note that only one JVM can be created in a single process.) [Details]

In order to build a program which uses the Invocation API using Cygwin tools, we need to create a Cygwin-style library against which our program can link. Our program will then load jvm.dll (in the Java 2 SDK) and invoke functions from it.

We can create a Java VM by invoking a function in jvm.dll (which also attaches the current native thread to the VM). Then we can start invoking arbitrary Java methods in that VM from within our native thread. In our example, we'll be invoking HelloWorld's main(java.lang.String[]) method (which is essentially what java.exe does). Each JVM in Sun's distribution (the "Classic" VM and the two HotSpot VMs) has its own jvm.dll, so we can control which one is used at runtime by choosing our jvm.dll at that time.

Continue (i.e., skip the footnotes)


Esoterica

* This limitation is listed as RFE #4525299 on Sun's Java Developer Connection. There's a comment from a Sun engineer on why this limitation exists under closed bug #4479303.)

If you need, or think you need, multiple JVMs for your native application, you might keep an eye on JSR-121, which will create the Java Application Isolation API. JSR-121 is in the JCP Public Review stage (as I write this December 25, 2002), and you can submit comments about it through the JCP if you are sufficiently motivated. This API allows multiple applications to run within a single JVM while remaining otherwise, um, isolated. (These "isolates" might also be implemented as heavyweight processes, and in fact are implemented that way in the reference implementation.)