Portability | portable (Haskell2010) |
---|---|
Stability | stable |
Maintainer | julian.fleischer@fu-berlin.de |
Safe Haskell | None |
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 safe bindings, see also Foreign.Java.JNI.Unsafe.
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/).
- data JVM
- createVM :: IO (Ptr JVM)
- createVM' :: Word32 -> Ptr CString -> IO (Ptr JVM)
- destroyVM :: Ptr JVM -> IO ()
- persistVM :: Ptr JVM -> IO ()
- data JClassRef
- findClass :: Ptr JVM -> CString -> IO (Ptr JClassRef)
- data JConstructorID
- data JObjectRef
- getConstructorID :: Ptr JVM -> Ptr JClassRef -> CString -> IO (Ptr JConstructorID)
- newObject :: Ptr JVM -> Ptr JClassRef -> Ptr JConstructorID -> Ptr JValues -> IO (Ptr JObjectRef)
- data JStaticMethodID
- data JMethodID
- getStaticMethodID :: Ptr JVM -> Ptr JClassRef -> CString -> CString -> IO (Ptr JStaticMethodID)
- getMethodID :: Ptr JVM -> Ptr JClassRef -> CString -> CString -> IO (Ptr JMethodID)
- callStaticVoidMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO ()
- callStaticBooleanMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Bool
- callStaticCharMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Word16
- callStaticByteMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int8
- callStaticShortMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int16
- callStaticIntMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int32
- callStaticLongMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int64
- callStaticFloatMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CFloat
- callStaticDoubleMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CDouble
- callStaticObjectMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO (Ptr JObjectRef)
- callStaticStringMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CString
- callVoidMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO ()
- callBooleanMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Bool
- callCharMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Word16
- callByteMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Int8
- callShortMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Int16
- callIntMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Int32
- callLongMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO Int64
- callFloatMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO CFloat
- callDoubleMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO CDouble
- callObjectMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO (Ptr JObjectRef)
- callStringMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO CString
- data JFieldID
- data JStaticFieldID
- getFieldID :: Ptr JVM -> Ptr JClassRef -> CString -> CString -> IO (Ptr JFieldID)
- getStaticFieldID :: Ptr JVM -> Ptr JClassRef -> CString -> CString -> IO (Ptr JStaticFieldID)
- getStaticBooleanField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Bool
- getStaticCharField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Word16
- getStaticByteField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int8
- getStaticShortField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int16
- getStaticIntField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int32
- getStaticLongField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int64
- getStaticFloatField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CFloat
- getStaticDoubleField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CDouble
- getStaticObjectField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO (Ptr JObjectRef)
- getStaticStringField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CString
- setStaticBooleanField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Bool -> IO ()
- setStaticCharField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Word16 -> IO ()
- setStaticByteField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int8 -> IO ()
- setStaticShortField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int16 -> IO ()
- setStaticIntField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int32 -> IO ()
- setStaticLongField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int64 -> IO ()
- setStaticFloatField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CFloat -> IO ()
- setStaticDoubleField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CDouble -> IO ()
- setStaticObjectField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Ptr JObjectRef -> IO ()
- setStaticStringField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CString -> IO ()
- getBooleanField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Bool
- getCharField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Word16
- getByteField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int8
- getShortField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int16
- getIntField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int32
- getLongField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int64
- getFloatField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CFloat
- getDoubleField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CDouble
- getObjectField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO (Ptr JObjectRef)
- getStringField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CString
- setBooleanField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Bool -> IO ()
- setCharField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Word16 -> IO ()
- setByteField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int8 -> IO ()
- setShortField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int16 -> IO ()
- setIntField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int32 -> IO ()
- setLongField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int64 -> IO ()
- setFloatField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CFloat -> IO ()
- setDoubleField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CDouble -> IO ()
- setObjectField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Ptr JObjectRef -> IO ()
- setStringField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CString -> IO ()
- data JValues
- data JArg where
- mkJValues :: Ptr JVM -> [JArg] -> IO (Ptr JValues)
- newJValues :: CInt -> IO (Ptr JValues)
- setJValueByte :: Ptr JValues -> CInt -> Int8 -> IO ()
- setJValueShort :: Ptr JValues -> CInt -> Int16 -> IO ()
- setJValueInt :: Ptr JValues -> CInt -> Int32 -> IO ()
- setJValueLong :: Ptr JValues -> CInt -> Int64 -> IO ()
- setJValueFloat :: Ptr JValues -> CInt -> CFloat -> IO ()
- setJValueDouble :: Ptr JValues -> CInt -> CDouble -> IO ()
- setJValueObject :: Ptr JValues -> CInt -> Ptr JObjectRef -> IO ()
- setJValueString :: Ptr JVM -> Ptr JValues -> CInt -> CString -> IO ()
- releaseJObjectRef :: Ptr JVM -> Ptr JObjectRef -> IO ()
- releaseJClassRef :: Ptr JVM -> Ptr JClassRef -> IO ()
- releaseJThrowableRef :: Ptr JVM -> Ptr JThrowableRef -> IO ()
- release :: ReleaseGlobalReference a => FunPtr (Ptr a -> IO ())
- data JChars
- data JBytes
- newJString :: Ptr JVM -> CString -> IO (Ptr JObjectRef)
- charsFromJString :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JChars)
- bytesFromJString :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JBytes)
- releaseJChars :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()
- releaseJBytes :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()
- jStringToCString :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()
- getArrayLength :: Ptr JVM -> Ptr JObjectRef -> IO Int32
- getObjectClass :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JClassRef)
- isInstanceOf :: Ptr JVM -> Ptr JObjectRef -> Ptr JClassRef -> IO Bool
- data JThrowableRef
- exceptionCheck :: Ptr JVM -> IO Bool
- exceptionOccurred :: Ptr JVM -> IO (Ptr JThrowableRef)
- exceptionOccurredClear :: Ptr JVM -> IO (Ptr JThrowableRef)
- exceptionClear :: Ptr JVM -> IO ()
- exceptionDescribe :: Ptr JVM -> IO ()
- getDebugStatus :: IO Bool
- setDebugStatus :: Bool -> IO ()
- getLibjvmPath :: IO CString
- getCompiledLibjvmPath :: IO CString
- setLibjvmPath :: CString -> IO ()
- registerCallbacks :: Ptr JVM -> Ptr JClassRef -> IO Bool
- runCocoaMain :: IO ()
Controlling the virtual machine
Discovering classes
Object creation
data JConstructorID Source
data JObjectRef Source
getConstructorID :: Ptr JVM -> Ptr JClassRef -> CString -> IO (Ptr JConstructorID)Source
newObject :: Ptr JVM -> Ptr JClassRef -> Ptr JConstructorID -> Ptr JValues -> IO (Ptr JObjectRef)Source
Method access
data JStaticMethodID Source
getStaticMethodID :: Ptr JVM -> Ptr JClassRef -> CString -> CString -> IO (Ptr JStaticMethodID)Source
Static method invocation
callStaticVoidMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO ()Source
callStaticBooleanMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO BoolSource
callStaticCharMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Word16Source
callStaticByteMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int8Source
callStaticShortMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int16Source
callStaticIntMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int32Source
callStaticLongMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO Int64Source
callStaticFloatMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CFloatSource
callStaticDoubleMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CDoubleSource
callStaticObjectMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO (Ptr JObjectRef)Source
callStaticStringMethod :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticMethodID -> Ptr JValues -> IO CStringSource
Method invocation
callObjectMethod :: Ptr JVM -> Ptr JObjectRef -> Ptr JMethodID -> Ptr JValues -> IO (Ptr JObjectRef)Source
Field access
data JStaticFieldID Source
Static getters
getStaticBooleanField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO BoolSource
getStaticCharField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Word16Source
getStaticByteField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int8Source
getStaticShortField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int16Source
getStaticIntField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int32Source
getStaticLongField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO Int64Source
getStaticFloatField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CFloatSource
getStaticDoubleField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CDoubleSource
getStaticObjectField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO (Ptr JObjectRef)Source
getStaticStringField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> IO CStringSource
Static setters
setStaticBooleanField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Bool -> IO ()Source
setStaticCharField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Word16 -> IO ()Source
setStaticByteField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int8 -> IO ()Source
setStaticShortField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int16 -> IO ()Source
setStaticIntField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int32 -> IO ()Source
setStaticLongField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Int64 -> IO ()Source
setStaticFloatField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CFloat -> IO ()Source
setStaticDoubleField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CDouble -> IO ()Source
setStaticObjectField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> Ptr JObjectRef -> IO ()Source
setStaticStringField :: Ptr JVM -> Ptr JClassRef -> Ptr JStaticFieldID -> CString -> IO ()Source
Member getters
getBooleanField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO BoolSource
getCharField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Word16Source
getByteField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int8Source
getShortField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int16Source
getIntField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int32Source
getLongField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO Int64Source
getFloatField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CFloatSource
getDoubleField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CDoubleSource
getObjectField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO (Ptr JObjectRef)Source
getStringField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> IO CStringSource
Member setters
setBooleanField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Bool -> IO ()Source
setCharField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Word16 -> IO ()Source
setByteField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int8 -> IO ()Source
setShortField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int16 -> IO ()Source
setIntField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int32 -> IO ()Source
setLongField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Int64 -> IO ()Source
setFloatField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CFloat -> IO ()Source
setDoubleField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CDouble -> IO ()Source
setObjectField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> Ptr JObjectRef -> IO ()Source
setStringField :: Ptr JVM -> Ptr JObjectRef -> Ptr JFieldID -> CString -> IO ()Source
Argument passing
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
.
setJValueObject :: Ptr JValues -> CInt -> Ptr JObjectRef -> IO ()Source
Releasing resources
releaseJObjectRef :: Ptr JVM -> Ptr JObjectRef -> IO ()Source
releaseJThrowableRef :: Ptr JVM -> Ptr JThrowableRef -> IO ()Source
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
newJString :: Ptr JVM -> CString -> IO (Ptr JObjectRef)Source
charsFromJString :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JChars)Source
bytesFromJString :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JBytes)Source
releaseJChars :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()Source
releaseJBytes :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()Source
jStringToCString :: Ptr JVM -> Ptr JObjectRef -> CString -> IO ()Source
Array handling
getArrayLength :: Ptr JVM -> Ptr JObjectRef -> IO Int32Source
Reflection
getObjectClass :: Ptr JVM -> Ptr JObjectRef -> IO (Ptr JClassRef)Source
isInstanceOf :: Ptr JVM -> Ptr JObjectRef -> Ptr JClassRef -> IO BoolSource
Exception handling
data JThrowableRef Source
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.
exceptionClear :: Ptr JVM -> IO ()Source
exceptionDescribe :: Ptr JVM -> IO ()Source
Debugging
setDebugStatus :: Bool -> IO ()Source
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.
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.
Workarounds for certain platforms
runCocoaMain :: IO ()Source