public abstract class JNIGenericHelpers extends Object
JNIFunctions
Modifier and Type | Field and Description |
---|---|
private static boolean |
ALLOW_READS_OF_UNDEFINED_MEMORY
Whether to allow reads of undefined memory when computing strlen(..).
|
Constructor and Description |
---|
JNIGenericHelpers() |
Modifier and Type | Method and Description |
---|---|
protected static Object |
callMethod(Object obj,
MethodReference mr,
Object[] args,
TypeReference expectedReturnType,
boolean nonVirtual)
Dispatch method call
|
protected static Object |
callMethodJValuePtr(JNIEnvironment env,
int objJREF,
int methodID,
Address argAddress,
TypeReference expectedReturnType,
boolean nonVirtual)
Dispatch method call, arguments in jvalue*
|
static byte[] |
createByteArrayFromC(Address stringAddress)
Given an address in C that points to a null-terminated string,
create a new Java byte[] with a copy of the string.
|
private static String |
createString(CharsetDecoder csd,
ByteBuffer bbuf) |
static String |
createStringFromC(Address stringAddress)
Given an address in C that points to a null-terminated string,
create a new Java String with a copy of the string.
|
static void |
createUTFForCFromString(String str,
Address copyBuffer,
int len)
Converts a String into a a malloced regions.
|
static String |
createUTFStringFromC(Address stringAddress)
Given an address in C that points to a null-terminated string,
create a new UTF encoded Java String with a copy of the string.
|
static boolean |
implementedInJava(int functionTableIndex) |
protected static Object[] |
packageParametersFromJValuePtr(MethodReference targetMethod,
Address argAddress)
Repackage the arguments passed as an array of jvalue into an array of Object,
used by the JNI functions CallStatic<type>MethodA
|
(package private) static void |
setBoolStar(Address boolPtr,
boolean val)
A JNI helper function, to set the value pointed to by a C pointer
of type (jboolean *).
|
static int |
strlen(Address ptr)
Computes the length of the given null-terminated string.
|
private static final boolean ALLOW_READS_OF_UNDEFINED_MEMORY
public JNIGenericHelpers()
public static int strlen(Address ptr)
NOTE: This method may read undefined memory if ALLOW_READS_OF_UNDEFINED_MEMORY
is true. However, the behaviour of this method is always well-defined.
ptr
- address of string in memorypublic static byte[] createByteArrayFromC(Address stringAddress)
stringAddress
- an address in C space for a stringprivate static String createString(CharsetDecoder csd, ByteBuffer bbuf) throws CharacterCodingException
CharacterCodingException
public static String createStringFromC(Address stringAddress)
stringAddress
- an address in C space for a stringpublic static String createUTFStringFromC(Address stringAddress)
stringAddress
- an address in C space for a stringpublic static void createUTFForCFromString(String str, Address copyBuffer, int len)
str
- the string to convertcopyBuffer
- start address for a newly allocated bufferlen
- length of the bufferstatic void setBoolStar(Address boolPtr, boolean val)
boolPtr
- Native pointer to a jboolean variable to be set. May be
the NULL pointer, in which case we do nothing.val
- Value to set it to (usually TRUE)protected static Object callMethod(Object obj, MethodReference mr, Object[] args, TypeReference expectedReturnType, boolean nonVirtual) throws InvocationTargetException
obj
- this pointer for method to be invoked, or null if method is staticmr
- reference to method to be invokedargs
- argument arrayexpectedReturnType
- a type reference for the expected return typenonVirtual
- should invocation be of the given method or should we use virtual dispatch on the object?InvocationTargetException
- when the reflective method call failsprotected static Object callMethodJValuePtr(JNIEnvironment env, int objJREF, int methodID, Address argAddress, TypeReference expectedReturnType, boolean nonVirtual) throws InvocationTargetException
env
- the JNI environemnt for the threadobjJREF
- a JREF index for the objectmethodID
- id of a MethodReferenceargAddress
- address of an array of jvalues (jvalue*)expectedReturnType
- a type reference for the expected return typenonVirtual
- should invocation be of the given method or should we use virtual dispatch on the object?InvocationTargetException
- when reflective invocation failsprotected static Object[] packageParametersFromJValuePtr(MethodReference targetMethod, Address argAddress)
targetMethod
- the target MethodReference
argAddress
- an address into the C space for the array of jvalue unionspublic static boolean implementedInJava(int functionTableIndex)
functionTableIndex
- slot in the JNI function tabletrue
if the function is implemented in Java (i.e.
its code is in org.jikesrvm.jni.JNIFunctions) and false
if the function is implemented in C (i.e. its code is in the
bootloader)