org.jikesrvm.jni.ia32
Class JNIHelpers

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

public abstract class JNIHelpers
extends JNIGenericHelpers

Platform dependent 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
JNIHelpers()
           
 
Method Summary
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 CallStaticMethod (static method invocation)
static Object invokeWithDotDotVarArg(Object obj, int methodID, TypeReference expectReturnType, boolean skip4Args)
          Common code shared by the JNI functions CallMethod (virtual method invocation)
static Object invokeWithJValue(int methodID, Address argAddress, TypeReference expectReturnType)
          Common code shared by the JNI functions CallStaticMethodA
static Object invokeWithJValue(Object obj, int methodID, Address argAddress, TypeReference expectReturnType, boolean skip4Args)
          Common code shared by the JNI functions CallMethodA
static Object invokeWithVarArg(int methodID, Address argAddress, TypeReference expectReturnType)
          Common code shared by the JNI functions CallStaticMethodV
static Object invokeWithVarArg(Object obj, int methodID, Address argAddress, TypeReference expectReturnType, boolean skip4Args)
          Common code shared by the JNI functions CallMethodV
(package private) static Object packageAndInvoke(Object obj, int methodID, Address argAddress, TypeReference expectReturnType, boolean skip4Args, boolean isVarArg)
          Common code shared by invokeWithJValue, invokeWithVarArg and invokeWithDotDotVarArg
(package private) static Object[] packageParameterFromJValue(RVMMethod targetMethod, Address argAddress)
          Repackage the arguments passed as an array of jvalue into an array of Object, used by the JNI functions CallStaticMethodA
(package private) static Object[] packageParameterFromVarArg(RVMMethod targetMethod, Address argAddress)
          Repackage the arguments passed as a variable argument list into an array of Object, used by the JNI functions CallStaticMethodV
 
Methods inherited from class org.jikesrvm.jni.JNIGenericHelpers
createByteArrayFromC, createStringFromC, createUTFForCFromString, createUTFStringFromC, strlen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JNIHelpers

public JNIHelpers()
Method Detail

invokeInitializer

public static Object invokeInitializer(Class<?> cls,
                                       int methodID,
                                       Address argAddress,
                                       boolean isJvalue,
                                       boolean isDotDotStyle)
                                throws Exception
Common code shared by the JNI functions NewObjectA, NewObjectV, NewObject (object creation)

Parameters:
methodID - the method ID for a constructor
Returns:
a new object created by the specified constructor
Throws:
Exception

invokeWithDotDotVarArg

public static Object invokeWithDotDotVarArg(int methodID,
                                            TypeReference expectReturnType)
                                     throws Exception
Common code shared by the JNI functions CallStaticMethod (static method invocation)

Parameters:
methodID - the method ID
expectReturnType - the return type of the method to be invoked
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

invokeWithDotDotVarArg

public static Object invokeWithDotDotVarArg(Object obj,
                                            int methodID,
                                            TypeReference expectReturnType,
                                            boolean skip4Args)
                                     throws Exception
Common code shared by the JNI functions CallMethod (virtual method invocation)

Parameters:
obj - the object instance
methodID - the method ID
expectReturnType - the return type for checking purpose
skip4Args - true if the calling JNI Function takes 4 args before the vararg false if the calling JNI Function takes 3 args before the vararg
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

getVarArgAddress

private static Address getVarArgAddress(boolean skip4Args)
This method supports var args passed from C.

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
 

Parameters:
skip4Args - if true, the calling JNI function has 4 args before the vararg if false, the calling JNI function has 3 args before the vararg
Returns:
the starting address of the vararg in the caller stack frame

invokeWithVarArg

public static Object invokeWithVarArg(int methodID,
                                      Address argAddress,
                                      TypeReference expectReturnType)
                               throws Exception
Common code shared by the JNI functions CallStaticMethodV

Parameters:
methodID - the method ID
argAddress - a raw address for the variable argument list
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

invokeWithVarArg

public static Object invokeWithVarArg(Object obj,
                                      int methodID,
                                      Address argAddress,
                                      TypeReference expectReturnType,
                                      boolean skip4Args)
                               throws Exception
Common code shared by the JNI functions CallMethodV

Parameters:
obj - the object instance
methodID - the method ID
argAddress - a raw address for the variable argument list
expectReturnType - the return type for checking purpose
skip4Args - received from the JNI function, passed on to Reflection.invoke()
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

invokeWithJValue

public static Object invokeWithJValue(int methodID,
                                      Address argAddress,
                                      TypeReference expectReturnType)
                               throws Exception
Common code shared by the JNI functions CallStaticMethodA

Parameters:
methodID - id of MemberReference
argAddress - a raw address for the argument array
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

invokeWithJValue

public static Object invokeWithJValue(Object obj,
                                      int methodID,
                                      Address argAddress,
                                      TypeReference expectReturnType,
                                      boolean skip4Args)
                               throws Exception
Common code shared by the JNI functions CallMethodA

Parameters:
obj - the object instance
methodID - id of MemberReference
argAddress - a raw address for the argument array
expectReturnType - the return type for checking purpose
skip4Args - received from the JNI function, passed on to Reflection.invoke()
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

packageAndInvoke

static Object packageAndInvoke(Object obj,
                               int methodID,
                               Address argAddress,
                               TypeReference expectReturnType,
                               boolean skip4Args,
                               boolean isVarArg)
                        throws Exception
Common code shared by invokeWithJValue, invokeWithVarArg and invokeWithDotDotVarArg

Parameters:
obj - the object instance
methodID - id of MemberReference
argAddress - a raw address for the argument array
expectReturnType - the return type for checking purpose
skip4Args - This flag is received from the JNI function and passed directly to Reflection.invoke(). It is true if the actual method is to be invoked, which could be from the superclass. It is false if the method from the real class of the object is to be invoked, which may not be the actual method specified by methodID
isVarArg - This flag describes whether the array of parameters is in var arg format or jvalue format
Returns:
an object that may be the return object or a wrapper for the primitive return value
Throws:
Exception

packageParameterFromVarArg

static Object[] packageParameterFromVarArg(RVMMethod targetMethod,
                                           Address argAddress)
Repackage the arguments passed as a variable argument list into an array of Object, used by the JNI functions CallStaticMethodV

Parameters:
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
Returns:
an Object array holding the arguments wrapped at Objects

packageParameterFromJValue

static Object[] packageParameterFromJValue(RVMMethod targetMethod,
                                           Address argAddress)
Repackage the arguments passed as an array of jvalue into an array of Object, used by the JNI functions CallStaticMethodA

Parameters:
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
Returns:
an Object array holding the arguments wrapped at Objects