Table of Contents

Interface IJavaObjectBase

Namespace
MASES.JCOBridge.C2JBridge.JVMInterop
Assembly
C2JBridge.dll

Base interface for all objects allocated from JVM

public interface IJavaObjectBase : IDisposable
Inherited Members
Extension Methods

Properties

IsGlobal

Returns true if this Pointer was set to be a Global reference

bool IsGlobal { get; }

Property Value

bool

IsNull

Returns true if this IJavaObjectBase is a null object within the JVM

bool IsNull { get; }

Property Value

bool

JVMType

IJavaType JVMType { get; }

Property Value

IJavaType

JniClassName

The JNI class name of this IJavaObjectBase

string JniClassName { get; }

Property Value

string

Pointer

The native pointer of the object

IntPtr Pointer { get; }

Property Value

IntPtr

Remarks

For advanced use only. Do not use this value in user code unless you have a thorough understanding of the underlying native memory model. Improper use may result in undefined behavior, memory corruption or application crashes.

ReferenceObject

The IJavaObject referenced from the instance of IJavaObjectBase, maybe it is null in many conditions

IJavaObjectBase ReferenceObject { get; }

Property Value

IJavaObjectBase

Remarks

Use this value with caution and do not store it: the referenced object may be invalidated when the owning IJavaObjectBase is disposed or garbage collected by the JVM.

Methods

Equals(IJavaObjectBase)

Checks for the equality between this instance and other

bool Equals(IJavaObjectBase other)

Parameters

other IJavaObjectBase

The IJavaObjectBase instance to be checked

Returns

bool

true if this instance and other are equal, otherwise false

HashCode()

Returns the int value of JVM hashCode

int HashCode()

Returns

int

int representing the JVM hashCode

MonitorEnter()

Enters the monitor associated with the underlying with this IJavaObjectBase

void MonitorEnter()

Remarks

Each Java object has a monitor associated with it. If the current thread already owns the monitor associated with IJavaObjectBase, the JVM increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with IJavaObjectBase is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1. If another thread already owns the monitor associated with obj, the current thread waits until the monitor is released, then tries again to gain ownership.

 A monitor entered through a <xref href="MASES.JCOBridge.C2JBridge.JVMInterop.IJavaObjectBase.MonitorEnter" data-throw-if-not-resolved="false"></xref> function call cannot be exited using the monitorexit Java virtual machine instruction or a synchronized method return.
 A <xref href="MASES.JCOBridge.C2JBridge.JVMInterop.IJavaObjectBase.MonitorEnter" data-throw-if-not-resolved="false"></xref> function call and a monitorenter Java virtual machine instruction may race to enter the monitor associated with the same object.
 To avoid deadlocks, a monitor entered through a <xref href="MASES.JCOBridge.C2JBridge.JVMInterop.IJavaObjectBase.MonitorEnter" data-throw-if-not-resolved="false"></xref> function call must be exited using the <xref href="MASES.JCOBridge.C2JBridge.JVMInterop.IJavaObjectBase.MonitorExit" data-throw-if-not-resolved="false"></xref> call, unless the DetachCurrentThread call is used to implicitly release JNI monitors.

MonitorExit()

Exits the monitor associated with the underlying with this IJavaObjectBase

void MonitorExit()

Remarks

The current thread must be the owner of the monitor associated with the underlying Java object referred to by IJavaObjectBase. The thread decrements the counter indicating the number of times it has entered this monitor. If the value of the counter becomes zero, the current thread releases the monitor. Native code must not use MonitorExit() to exit a monitor entered through a synchronized method or a monitorenter Java virtual machine instruction. Failing to call MonitorExit() after MonitorEnter() will result in a deadlock. Always use a try/finally block to guarantee the monitor is released.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

void Notify()

NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

void NotifyAll()

ToArray()

Returns a .NET array containing a copy of the JVM object data.

When called on an IJavaObject instance that represents a JVM array, the returned object is an IJavaArray wrapping the underlying JVM array. When called on an IJavaArray instance, the returned object is a typed .NET array whose element type depends on the underlying JVM primitive or reference type, as described in the returns section below.

object ToArray()

Returns

object

A .NET array containing a copy of the JVM object data. The exact element type depends on the underlying JVM type:

  • Primitive arrays (e.g. byte[], int[], double[]) are returned as the corresponding .NET primitive array.
  • String arrays are returned as string[].
  • Object arrays are returned as object[], where each element is an IJavaObject wrapping the corresponding JVM object. If an element itself represents a JVM array, ToArray() can be called on it recursively to retrieve its content.

ToPrimitive()

Converts this IJavaObjectBase to a primitive value.

object ToPrimitive()

Returns

object

When called on an IJavaObject instance, returns the underlying JVM primitive value as a .NET object. When called on an IJavaArray instance, returns the array contents converted to the corresponding .NET representation (native arrays, object arrays, etc.).

Exceptions

InvalidOperationException

Thrown by IJavaObject implementations when the underlying JVM type is not convertible to a primitive value.

ToPrimitive<TReturn>()

Converts this IJavaObjectBase to a primitive value.

TReturn ToPrimitive<TReturn>()

Returns

TReturn

This instance converted to TReturn.

Type Parameters

TReturn

The primitive type to be returned.

Exceptions

InvalidOperationException

Thrown by IJavaObject implementations when the underlying JVM type is not convertible to TReturn. Not meaningful when called on an IJavaArray instance.

ToString()

Returns the string representation of this instance

string ToString()

Returns

string

string representing the managed JVM object

Wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

void Wait()

Wait(long)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

void Wait(long timeoutMillis)

Parameters

timeoutMillis long

The maximum time to wait, in milliseconds

Wait(long, int)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

void Wait(long timeoutMillis, int nanos)

Parameters

timeoutMillis long

The maximum time to wait, in milliseconds

nanos int

Additional time, in nanoseconds, in the range range 0-999999 inclusive