CallStatic<type>Method Routines - CallStaticLongMethod
CallStatic<type>MethodA Routines
CallStatic<type>MethodV Routines
NativeType CallStatic<type>Method
(JNIEnv *env, jclass clazz,
jmethodID methodID, ...);
NativeType CallStatic<type>MethodA
(JNIEnv *env, jclass clazz,
jmethodID methodID, jvalue *args);
NativeType CallStatic<type>MethodV
(JNIEnv *env, jclass clazz,
jmethodID methodID, va_list args);
(CallStaticLongMethod)This family of operations invokes a static method on a Java object, according to the specified method ID. The
methodID
argument must be obtained by calling GetStaticMethodID
()
.
The method ID must be derived from
clazz
, not from one of its superclasses.
(CallStaticLongMethod)
CallStatic<type>Method Routines
Programmers should place all arguments that are to be passed to the method immediately following the
methodID
argument. TheCallStatic<type>Method routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke. (CallStaticLongMethod)CallStatic<type>MethodA Routines
Programmers should place all arguments to the method in an
args
array of jvalues
that immediately follows the methodID
argument. The CallStaticMethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.CallStatic<type>MethodV Routines
Programmers should place all arguments to the method in an
args
argument of type va_list
that immediately follows the methodID
argument. The CallStaticMethodV routine accepts the arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
The following table describes each of the method calling routines according to their result types. You should replace type inCallStatic<type>Method with the Java type of the method, or one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-7a CallStatic<type>Method Calling Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-7b CallStatic<type>Method Calling Routines
PARAMETERS of CallStaticLongMethod
env
: the JNI interface pointer.clazz
: a Java class object.methodID
: a static method ID.Additional Parameter for CallStatic<type>Method Routines:
arguments to the static method.
Additional Parameter for CallStatic<type>MethodA Routines:
args
: an array of arguments.Additional Parameter for CallStatic<type>MethodV Routines:
args
: a va_list
of arguments.RETURNS:
Returns the result of calling the static Java method.
THROWS:
Exceptions raised during the execution of the Java method.
Example of
CallStaticLongMethod#include <jni.h> #define ARG1 ((jlong)10098374ll) #define RES1 ((jlong)ARG1) #define ARG22 ((jlong)150034513451ll) #define RES2 ((jlong)(ARG1 + ARG22)) #define ARG3_LENGTH 2 #define ARG31 ((jlong)-32755134541351ll) #define ARG32 ((jlong)1321113451345134ll) #define RES3 ((jlong)(ARG31 + ARG32)) #define ARG42_LENGTH 3 #define ARG421 ((jlong)881345134514513ll) #define ARG422 ((jlong)-1ll) #define ARG423 ((jlong)32756353151545143ll) #define RES4 ((jlong)((ARG31 + ARG32) + (ARG421 + ARG422 + ARG423))) #define ARG5 ((jlong)1002131454113145ll) #define RES5 ((jlong)ARG5) #define ARG62 ((jlong)-4800234123412341234ll) #define RES6 ((jlong)(ARG5 + ARG62)) /* * Method: org.apache.harmony.vts.test.vm.jni.static_methods.CallStaticLongMethodTest.nativeExecute(Lorg/apache/harmony/vts/test/vm/jni/static_methods/TestClass;Lorg/apache/harmony/vts/test/vm/jni/static_methods/NativeTestClass;)Z */ JNIEXPORT jboolean JNICALL Java_org_apache_harmony_vts_test_vm_jni_static_1methods_CallStaticLongMethodTest_nativeExecute (JNIEnv *env, jobject this_object, jobject tc, jobject ntc) { jclass jc, class1, class2; char *sig1 = "(J)J"; char *sig2 = "(JJ)J"; char *sig3 = "([J)J"; char *sig4 = "([J[J)J"; char *sig5 = "(Ljava/lang/Long;)J"; char *sig6 = "(Ljava/lang/Long;Ljava/lang/Long;)J"; jobject jo5, jo62; jlongArray ar3, ar42; jlong *elements3, *elements42; jlong result1, result2, result3, result4, result5, result6; jlong nresult1, nresult2, nresult3, nresult4, nresult5, nresult6; jmethodID m1, m2, m3, m4, m5, m6; jmethodID nm1, nm2, nm3, nm4, nm5, nm6; jmethodID long_init; ar3 = (*env)->NewLongArray(env, ARG3_LENGTH); ar42 = (*env)->NewLongArray(env, ARG42_LENGTH); if (NULL == ar3 || NULL == ar42) return JNI_FALSE; elements3 = (*env)->GetLongArrayElements(env, ar3, NULL); elements42 = (*env)->GetLongArrayElements(env, ar42, NULL); if (NULL == elements3 || NULL == elements42) return JNI_FALSE; elements3[0] = ARG31; elements3[1] = ARG32; elements42[0] = ARG421; elements42[1] = ARG422; elements42[2] = ARG423; (*env)->ReleaseLongArrayElements(env, ar3, elements3, 0); (*env)->ReleaseLongArrayElements(env, ar42, elements42, 0); jc = (*env)->FindClass(env, "java/lang/Long"); if (NULL == jc) return JNI_FALSE; long_init = (*env)->GetMethodID(env, jc, "<init>", "(J)V"); if (NULL == long_init) return JNI_FALSE; jo5 = (*env)->NewObject(env, jc, long_init, ARG5); jo62 = (*env)->NewObject(env, jc, long_init, ARG62); if (NULL == jo5 || NULL == jo62) return JNI_FALSE; class1 = (*env)->GetObjectClass(env, tc); class2 = (*env)->GetObjectClass(env, ntc); m1 = (*env)->GetStaticMethodID(env, class1, "method", sig1); m2 = (*env)->GetStaticMethodID(env, class1, "method", sig2); m3 = (*env)->GetStaticMethodID(env, class1, "method", sig3); m4 = (*env)->GetStaticMethodID(env, class1, "method", sig4); m5 = (*env)->GetStaticMethodID(env, class1, "method", sig5); m6 = (*env)->GetStaticMethodID(env, class1, "method", sig6); if (NULL == m1 || NULL == m2 || NULL == m3 || NULL == m4 || NULL == m5 || NULL == m6) return JNI_FALSE; nm1 = (*env)->GetStaticMethodID(env, class2, "method", sig1); nm2 = (*env)->GetStaticMethodID(env, class2, "method", sig2); nm3 = (*env)->GetStaticMethodID(env, class2, "method", sig3); nm4 = (*env)->GetStaticMethodID(env, class2, "method", sig4); nm5 = (*env)->GetStaticMethodID(env, class2, "method", sig5); nm6 = (*env)->GetStaticMethodID(env, class2, "method", sig6); if (NULL == nm1 || NULL == nm2 || NULL == nm3 || NULL == nm4 || NULL == nm5 || NULL == nm6) return JNI_FALSE; result1 = (*env)->CallStaticLongMethod(env, class1, m1, ARG1); result2 = (*env)->CallStaticLongMethod(env, class1, m2, ARG1, ARG22); result3 = (*env)->CallStaticLongMethod(env, class1, m3, ar3); result4 = (*env)->CallStaticLongMethod(env, class1, m4, ar3, ar42); result5 = (*env)->CallStaticLongMethod(env, class1, m5, jo5); result6 = (*env)->CallStaticLongMethod(env, class1, m6, jo5, jo62); nresult1 = (*env)->CallStaticLongMethod(env, class2, nm1, ARG1); nresult2 = (*env)->CallStaticLongMethod(env, class2, nm2, ARG1, ARG22); nresult3 = (*env)->CallStaticLongMethod(env, class2, nm3, ar3); nresult4 = (*env)->CallStaticLongMethod(env, class2, nm4, ar3, ar42); nresult5 = (*env)->CallStaticLongMethod(env, class2, nm5, jo5); nresult6 = (*env)->CallStaticLongMethod(env, class2, nm6, jo5, jo62); if (result1 != RES1 || nresult1 != RES1 || result2 != RES2 || nresult2 != RES2 || result3 != RES3 || nresult3 != RES3 || result4 != RES4 || nresult4 != RES4 || result5 != RES5 || nresult5 != RES5 || result6 != RES6 || nresult6 != RES6) return JNI_FALSE; else return JNI_TRUE; }