JNIEXPORT jintArray JNICALL Java_org_apache_harmony_test_stress_jni_stack_StackTest5_nativeMethod(JNIEnv* env, jclass c, jintArray intArray, jint len, jint cnt, jint threadId){ jint* arr; jintArray res, res2 = NULL; jint* calc_res; StackTest_alloc_arrays(env, len, &arr, &calc_res, NULL); if (arr == NULL || calc_res == NULL) { printf("Native code (thread %d): Cannot allocate jint* arrays\n", (int)threadId); return NULL; } (*env)->GetIntArrayRegion(env, intArray, 0, len, arr); if((*env)->ExceptionCheck(env)) { printf("Native code (thread %d): Cannot get array elements\n", (int)threadId); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } StackTest_do_calc(arr, calc_res, len); res = (*env)->NewIntArray(env, len); if (res == NULL) { StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } (*env)->SetIntArrayRegion(env, res, 0, len, calc_res); if ((*env)->ExceptionCheck(env)) { printf("Native code (thread %d): Cannot set array elements\n", (int)threadId); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } if (cnt < maxCnt) { res2 = (*env)->CallStaticObjectMethod(env, clazz, mid, res, len, cnt + 1, threadId); if ((*env)->ExceptionCheck(env)) { StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } } StackTest_free_arrays(env, arr, calc_res, NULL); return res2; }
JNIEXPORT jintArray JNICALL Java_org_apache_harmony_test_stress_jni_stack_StackTest9_nativeMethod(JNIEnv* env, jobject thisObject, jintArray intArray, jint len, jint cnt){ jint* arr; jintArray res, res2 = NULL; jint* calc_res; StackTest_alloc_arrays(env, len, &arr, &calc_res, NULL); if (arr == NULL || calc_res == NULL) { printf("Native code: Cannot allocate jint* arrays\n"); return NULL; } (*env)->GetIntArrayRegion(env, intArray, 0, len, arr); if ((*env)->ExceptionCheck(env)) { printf("Native code: Cannot get array elements\n"); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } StackTest_do_calc(arr, calc_res, len); res2 = res = (*env)->NewIntArray(env, len); if (res == NULL) { printf("Native code: Cannot create an array\n"); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } (*env)->SetIntArrayRegion(env, res, 0, len, calc_res); if ((*env)->ExceptionCheck(env)) { printf("Native code: Cannot set array elements\n"); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } if (cnt < maxCnt) { res2 = (*env)->CallObjectMethod(env, thisObject, mid, res, cnt + 1); if((*env)->ExceptionCheck(env)) { printf("Native code: exception in caught in native method\n"); StackTest_free_arrays(env, arr, calc_res, NULL); return NULL; } } StackTest_free_arrays(env, arr, calc_res, NULL); return res2; }