java-bridge-0.9: Bindings to the JNI and a high level interface generator.

Portabilityportable (Haskell2010)
Stabilitystable
Maintainerjulian.fleischer@fu-berlin.de
Safe HaskellNone

Foreign.Java.JNI.Unsafe

Contents

Description

Low level interface to the Java Virtual Machine. This module is a very thin wrapper over the Java Native Interface.

Note that all functions that return references (of type Ptr JObjectRef) return global references which you will need to free manually.

This module contains unsafe bindings, see also Foreign.Java.JNI.Safe.

Read the The Java Native Interface - Programmer's Guide and Specification for further information on the Java Native Interface (available at http://www.soi.city.ac.uk/~kloukin/IN2P3/material/jni.pdf, and http://192.9.162.55/docs/books/jni/).

Synopsis

Controlling the virtual machine

data JVM Source

createVM'Source

Arguments

:: Word32

The number of arguments (like argc)

-> Ptr CString

A char** to the arguments (like argv)

-> IO (Ptr JVM)

Returns a Ptr to the newly running JVM

Discovering classes

Object creation

Array creation

Method access

Static method invocation

Method invocation

Field access

Static getters

Static setters

Member getters

Member setters

Argument passing

data JArg whereSource

Constructors

BooleanA :: Bool -> JArg 
CharA :: Word16 -> JArg 
ByteA :: Int8 -> JArg 
ShortA :: Int16 -> JArg 
IntA :: Int32 -> JArg 
LongA :: Int64 -> JArg 
FloatA :: Float -> JArg 
DoubleA :: Double -> JArg 
StringA :: String -> JArg 
ObjectA :: Maybe JObject -> JArg 
ArrayA :: Maybe (JArray e) -> JArg 

mkJValues :: Ptr JVM -> [JArg] -> IO (Ptr JValues)Source

Create a JValues Array which can be used for argument passing to a multi parameter method. You need to free the Ptr object manually using free.

This method is implemented using calloc internally. See the native implementation of newJValues.

Releasing resources

release :: ReleaseGlobalReference a => FunPtr (Ptr a -> IO ())Source

release is a special function which can be used to create a ForeignPtr. A ForeignPtr does not carry a reference to a virtual machine (no Ptr JVM), thus this function will lookup the current virtual machine or do nothing if it can not find one. It is realised as a FunPtr as this is what newForeignPtr expects.

Special data types

String handling

Array handling

Reflection

Exception handling

exceptionCheck :: Ptr JVM -> IO BoolSource

Checks whether an exception has occured in the virtual machine or not.

exceptionOccurred :: Ptr JVM -> IO (Ptr JThrowableRef)Source

Checks whether an exception occured and return that exception. If no exception occured, the returned pointer will be the nullPtr. This method will return a local reference only, so beware that the obtained Ptr will not be valid for too long.

exceptionOccurredClear :: Ptr JVM -> IO (Ptr JThrowableRef)Source

Checks whether an exception occured and return that exception. If no exception occured, the returned pointer will be the nullPtr. This method will also call exceptionClear which means that it can not be called twice. This method will return a global reference - as opposed to exceptionOccurred, which will return a local reference only.

Debugging

libjvm initialization

getLibjvmPath :: IO CStringSource

Returns the path to libjvm that is used by this library. Note that this will return the nullPtr if the library has not yet been initialized. The library is lazily initialized the first time that runJava' is used. runJava is implemented in terms of runJava, as is initJava.

You are not allowed to invoke free on the returned cstring.

getCompiledLibjvmPath :: IO CStringSource

Returns the path to libjvm with which this library has been compiled. This is guaranteed to never return nullPtr.

You are not allowed to invoke free on the returned cstring.

setLibjvmPath :: CString -> IO ()Source

Sets the path to libjvm. Note that this will only have an effect if the library has not yet been initialized, that is before any of the following functions is used: runJava, runJava', and initJava.

Do not invoke free on the cstring passed to this function, as this function will not set a copy but the object given. It is only ever used once during the lifecycle of your application.

Primitive types

data Z Source

Constructors

Z 

data C Source

Constructors

C 

data B Source

Constructors

B 

data S Source

Constructors

S 

data I Source

Constructors

I 

data J Source

Constructors

J 

data D Source

Constructors

D 

data F Source

Constructors

F 

data L Source

Constructors

L String 

Instances

Show L 
JavaArray L (Maybe JObject) 
JavaObject (JArray L)

Every JArray is a JavaObject.

data V Source

Constructors

V 

Instances

data A x Source

Constructors

A x 

Instances

Show x => Show (A x) 
JavaArray (A e) (Maybe (JArray e)) 

data X Source

Constructors

X 

Instances

Workarounds for certain platforms