org.jikesrvm.jni
Class JNIGenericHelpers

java.lang.Object
  extended by org.jikesrvm.jni.JNIGenericHelpers
Direct Known Subclasses:
JNIHelpers

public abstract class JNIGenericHelpers
extends Object

Platform independent utility functions called from JNIFunctions (cannot be placed in JNIFunctions because methods there are specially compiled to be called from native).

See Also:
JNIFunctions

Constructor Summary
JNIGenericHelpers()
           
 
Method Summary
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)
          Create a string from the given charset decoder and bytebuffer
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)
          Convert a String into a a malloced region
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.
(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)
          Compute the length of the given null-terminated string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JNIGenericHelpers

public JNIGenericHelpers()
Method Detail

strlen

public static int strlen(Address ptr)
Compute the length of the given null-terminated string

Parameters:
ptr - address of string in memory
Returns:
the length of the string in bytes

createByteArrayFromC

public 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.

Parameters:
stringAddress - an address in C space for a string
Returns:
a new Java byte[]

createString

private static String createString(CharsetDecoder csd,
                                   ByteBuffer bbuf)
                            throws CharacterCodingException
Create a string from the given charset decoder and bytebuffer

Throws:
CharacterCodingException

createStringFromC

public 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.

Parameters:
stringAddress - an address in C space for a string
Returns:
a new Java String

createUTFStringFromC

public 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.

Parameters:
stringAddress - an address in C space for a string
Returns:
a new Java String

createUTFForCFromString

public static void createUTFForCFromString(String str,
                                           Address copyBuffer,
                                           int len)
Convert a String into a a malloced region


setBoolStar

static void setBoolStar(Address boolPtr,
                        boolean val)
A JNI helper function, to set the value pointed to by a C pointer of type (jboolean *).

Parameters:
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)