Represents a jni JavaVM

Introduced properties

fun attach_current_thread: JniEnv

jvm :: JavaVM :: attach_current_thread

Attach the calling thread to the JVM and return its JniEnv
fun destroy

jvm :: JavaVM :: destroy

Unload the Java VM when the calling thread is the only remaining non-daemon attached user thread
fun detach_current_thread

jvm :: JavaVM :: detach_current_thread

Detach the calling thread from this JVM
fun env: JniEnv

jvm :: JavaVM :: env

JniEnv attached to the calling thread

Redefined properties

redef type SELF: JavaVM

jvm $ JavaVM :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun address_is_null: Bool

core :: Pointer :: address_is_null

Is the address behind this Object at NULL?
fun attach_current_thread: JniEnv

jvm :: JavaVM :: attach_current_thread

Attach the calling thread to the JVM and return its JniEnv
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun destroy

jvm :: JavaVM :: destroy

Unload the Java VM when the calling thread is the only remaining non-daemon attached user thread
fun detach_current_thread

jvm :: JavaVM :: detach_current_thread

Detach the calling thread from this JVM
fun env: JniEnv

jvm :: JavaVM :: env

JniEnv attached to the calling thread
fun free

core :: Pointer :: free

Free the memory pointed by this pointer
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
init nul: Pointer

core :: Pointer :: nul

C NULL pointer
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram jvm::JavaVM JavaVM core::Pointer Pointer jvm::JavaVM->core::Pointer core::Object Object core::Pointer->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

extern class Pointer

core :: Pointer

Pointer classes are used to manipulate extern C structures.

Class definitions

jvm $ JavaVM
# Represents a jni JavaVM
extern class JavaVM `{JavaVM *`}
	# Create the JVM
	#
	# The corresponding `JniEnv` can be obtained by calling `env`.
	#
	# Unavailable on some platforms, including Android where you cannot instanciate a new JVM.
	private new(args: JavaVMInitArgs) import jni_error `{

	#ifdef ANDROID
		JavaVM_jni_error(NULL, "JVM creation not supported on Android", 0);
		return NULL;
	#endif

		JavaVM *jvm;
		JNIEnv *env;
		jint res;

		res = JNI_CreateJavaVM(&jvm, (void**)&env, args);

		if (res != JNI_OK) {
			JavaVM_jni_error(NULL, "Could not create Java VM", res);
			return NULL;
		}

		return jvm;
	`}

	private fun jni_error(msg: CString, v: Int)
	do
		print "JNI Error: {msg} ({v})"
		abort
	end

	# Unload the Java VM when the calling thread is the only remaining non-daemon attached user thread
	fun destroy `{
		(*self)->DestroyJavaVM(self);
	`}

	# `JniEnv` attached to the calling thread
	#
	# A null pointer is returned if the calling thread is not attached to the JVM.
	fun env: JniEnv import jni_error `{
		JNIEnv *env;
		int res = (*self)->GetEnv(self, (void **)&env, JNI_VERSION_1_6);
		if (res == JNI_EDETACHED) {
			JavaVM_jni_error(NULL, "Requesting JNIEnv from an unattached thread", res);
			return NULL;
		}
		else if (res != JNI_OK) {
			JavaVM_jni_error(NULL, "Could not get JNIEnv from Java VM", res);
			return NULL;
		}
		return env;
	`}

	# Attach the calling thread to the JVM and return its `JniEnv`
	fun attach_current_thread: JniEnv import jni_error `{
		JNIEnv *env;
	#ifdef ANDROID
		// the signature is different (better actually) on Android
		int res = (*self)->AttachCurrentThread(self, &env, NULL);
	#else
		int res = (*self)->AttachCurrentThread(self, (void**)&env, NULL);
	#endif
		if (res != JNI_OK) {
			JavaVM_jni_error(NULL, "Could not attach current thread to Java VM", res);
			return NULL;
		}
		return env;
	`}

	# Detach the calling thread from this JVM
	fun detach_current_thread import jni_error `{
		int res = (*self)->DetachCurrentThread(self);
		if (res != JNI_OK) {
			JavaVM_jni_error(NULL, "Could not detach current thread to Java VM", res);
		}
	`}
end
lib/jvm/jvm.nit:132,1--211,3