public abstract class JNIHelpers extends JNIGenericHelpers
JNIFunctions
Constructor and Description |
---|
JNIHelpers() |
Modifier and Type | Method and Description |
---|---|
private static Address |
getVarArgAddress(boolean skip4Args)
This method supports var args passed from C.
|
static Object |
invokeInitializer(Class<?> cls,
int methodID,
Address argAddress,
boolean isJvalue,
boolean isDotDotStyle)
Common code shared by the JNI functions NewObjectA, NewObjectV, NewObject
(object creation)
|
static Object |
invokeWithDotDotVarArg(int methodID,
TypeReference expectReturnType)
Common code shared by the JNI functions CallStatic<type>Method
(static method invocation)
|
static Object |
invokeWithDotDotVarArg(Object obj,
int methodID,
TypeReference expectReturnType,
boolean skip4Args)
Common code shared by the JNI functions Call<type>Method
(virtual method invocation)
|
static Object |
invokeWithVarArg(int methodID,
Address argAddress,
TypeReference expectReturnType)
Common code shared by the JNI functions CallStatic<type>MethodV
|
static Object |
invokeWithVarArg(Object obj,
int methodID,
Address argAddress,
TypeReference expectReturnType,
boolean skip4Args)
Common code shared by the JNI functions Call<type>MethodV
|
(package private) static Object[] |
packageParameterFromVarArg(MethodReference targetMethod,
Address argAddress)
Repackage the arguments passed as a variable argument list into an array of Object,
used by the JNI functions CallStatic<type>MethodV
|
callMethod, callMethodJValuePtr, createByteArrayFromC, createStringFromC, createUTFForCFromString, createUTFStringFromC, implementedInJava, packageParametersFromJValuePtr, strlen
public JNIHelpers()
public static Object invokeInitializer(Class<?> cls, int methodID, Address argAddress, boolean isJvalue, boolean isDotDotStyle) throws Exception
cls
- class whose constructor is to be invokedmethodID
- the method ID for a constructorargAddress
- where to find the arguments for the constructorisJvalue
- true
if parameters are passed as a jvalue arrayisDotDotStyle
- true
if the method uses varargsException
- when the reflective invocation of the constructor failspublic static Object invokeWithDotDotVarArg(int methodID, TypeReference expectReturnType) throws Exception
methodID
- the method IDexpectReturnType
- the return type of the method to be invokedException
- if the return type doesn't match the expected return typepublic static Object invokeWithDotDotVarArg(Object obj, int methodID, TypeReference expectReturnType, boolean skip4Args) throws Exception
obj
- the object instancemethodID
- the method IDexpectReturnType
- the return type for checking purposeskip4Args
- true if the calling JNI Function takes 4 args before the vararg
false if the calling JNI Function takes 3 args before the varargException
- if the return type doesn't match the expected return typeprivate static Address getVarArgAddress(boolean skip4Args)
In the Linux Intel C convention, the caller places the args immediately above the
saved return address, starting with the first arg.
For the JNI functions that takes var args, their prolog code will save the
var arg in the glue frame because the values in the register may be lost by
subsequent calls.
This method copies the var arg values that were saved earlier in glue frame into
the spill area of the original caller, thereby doing the work that the callee
normally performs in the AIX C convention.
NOTE: This method contains internal stack pointer.
For now we assume that the stack will not be relocatable while native code is running
because native code can hold an address into the stack, so this code is OK,
but this is an issue to be resolved later.
NOTE: this method assumes that it is immediately above the
invokeWithDotDotVarArg frame, the JNI frame, the glue frame and
the C caller frame in the respective order.
Therefore, this method will not work if called from anywhere else.
low address | fp | <- JNIEnvironment.getVarArgAddress | mid | | | | | |------| | fp | <- JNIEnvironment.invokeWithDotDotVarArg frame | mid | | ... | | | | | |------| | fp | <- JNI method frame | mid | | ... | | arg 0| args copied by JNI prolog (3 for static, nonvirtual, | arg 1| or 4 for virtual) | arg 2| | | | | |------| | fp | <- Native C caller frame |return| | arg 0| | arg 1| | arg 2| | arg 3| | arg 4| | arg 5| | arg 6| | arg 7| | arg 8| | arg 9| | | | | | | high address
skip4Args
- if true, the calling JNI function has 4 args before the vararg
if false, the calling JNI function has 3 args before the varargpublic static Object invokeWithVarArg(int methodID, Address argAddress, TypeReference expectReturnType) throws Exception
methodID
- the method IDargAddress
- a raw address for the variable argument listexpectReturnType
- the return type of the method to be invokedException
- if the return type doesn't match the expected return typepublic static Object invokeWithVarArg(Object obj, int methodID, Address argAddress, TypeReference expectReturnType, boolean skip4Args) throws Exception
obj
- the object instancemethodID
- the method IDargAddress
- a raw address for the variable argument listexpectReturnType
- the return type for checking purposeskip4Args
- received from the JNI function, passed on to Reflection.invoke()Exception
- if the return type doesn't match the expected return typestatic Object[] packageParameterFromVarArg(MethodReference targetMethod, Address argAddress)
targetMethod
- The target RVMMethod
argAddress
- an address into the C space for the array of jvalue unions;
each element is 2-word and holds the argument of the appropriate type