Skip to content

Latest commit

 

History

History

README.md

JNet.Runtime

We need your help! Can you help us to document this?

JNet.Runtime is a wrapper library around the JVM (Java Native Interface - JNI) library. This is the base runtime to JNet.

You must understand the JNI approach before use this wrapper library. Read below documentation first:

How to operate on virtual machine

To operante on virtual machine environment you needs a JNetRuntime instance. Three classes are very important for using the JNet.Runtime:

Class Usage
JNetVirtualMachine Initializes the virtual machine; Attach/Detach threads to virtual machine; Gets the runtime instances.
JNetConfiguration Configures the virtual machine initialization.
JNetRuntime Calls the JNI operations on virtual machine enviroment.

There are the steps to operate on virtual machine environment:

  • Start the virtual machine in your process by calling JNetVirtualMachine.Initialize method. It must returns the JNetVirtualMachine instance.
  • Attach the current thread to virtual machine by calling JNetVirtualMachine.AttachCurrentThread. It must returns the JNetRuntime instance.
  • Operate on JNetRuntime instance (it must be done on the same thread that is attached)...
  • Dettach the thread to release virtual machine environment objects references by calling JNetVirtualMachine.DettachCurrentThread (it is very important to collect unused references on virtual machine environment).
  • Destroy the virtual machine - if you don't need more in your process - by calling JNetVirtualMachine.Destroy.

How to initialize the virtual machine

To start using the JNet Runtime the program must initializes a the virtual machine by calling the JNetVirtualMachine.Initialize method.

As of JDK/JRE 1.2, creation of multiple virtual machines in a single process is not supported. Support for creating only a single virtual machine within a single job or process follows the standards of the Oracle America, Inc. reference implementation of Java.

Virtual machine configuration

Pass an JNetConfiguration instance to JNetVirtualMachine.Initialize to configure the virtual machine.

Property Type Intialize's method default behavior
JavaRuntimePath string Infer from JAVA_HOME environment variable.
Classpath IEnumerable<string> No classpath.
Bootstrap IJNetBootstrap No bootstrap.
JNIVersion JNIVersion JNIVersion.Version10
EnableDiagnostics bool false
LoggerCallback JNetConfiguration.Logger Default JNI logger.

Hosting the JNet Runtime usage

Managing the JNetRuntime instances by AttachCurrentThread and DettachCurrentThread can be complicated in your project. To simplify this, we recommend you to implement a host to handle the runtime operations.

JNet.Hosting is a library that implements a host to manage the JNetRuntime instances. It is a wrapper library around the JNet.Runtime library.