test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI03/ji03t003/ji03t003.cpp
changeset 52642 9cfc8b0c45fd
parent 51729 1ebe04845112
child 52952 837f1b8442be
equal deleted inserted replaced
52641:09a3f379b927 52642:9cfc8b0c45fd
   101 void doRedirect(JNIEnv *env) {
   101 void doRedirect(JNIEnv *env) {
   102     jvmtiError err;
   102     jvmtiError err;
   103 
   103 
   104     if (verbose)
   104     if (verbose)
   105         printf("\ndoRedirect: obtaining the JNI function table ...\n");
   105         printf("\ndoRedirect: obtaining the JNI function table ...\n");
   106     if ((err = jvmti->GetJNIFunctionTable(&orig_jni_functions)) !=
   106     err = jvmti->GetJNIFunctionTable(&orig_jni_functions);
   107             JVMTI_ERROR_NONE) {
   107     if (err != JVMTI_ERROR_NONE) {
   108         result = STATUS_FAILED;
   108         result = STATUS_FAILED;
   109         printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n",
   109         printf("(%s,%d): TEST FAILED: failed to get original JNI function table: %s\n",
   110             __FILE__, __LINE__, TranslateError(err));
   110             __FILE__, __LINE__, TranslateError(err));
   111         env->FatalError("failed to get original JNI function table");
   111         env->FatalError("failed to get original JNI function table");
   112     }
   112     }
   113     if ((err = jvmti->GetJNIFunctionTable(&redir_jni_functions)) !=
   113     err = jvmti->GetJNIFunctionTable(&redir_jni_functions);
   114             JVMTI_ERROR_NONE) {
   114     if (err != JVMTI_ERROR_NONE) {
   115         result = STATUS_FAILED;
   115         result = STATUS_FAILED;
   116         printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n",
   116         printf("(%s,%d): TEST FAILED: failed to get redirected JNI function table: %s\n",
   117             __FILE__, __LINE__, TranslateError(err));
   117             __FILE__, __LINE__, TranslateError(err));
   118         env->FatalError("failed to get redirected JNI function table");
   118         env->FatalError("failed to get redirected JNI function table");
   119     }
   119     }
   124         printf("\ndoRedirect: overwriting the functions Throw,ThrowNew,ExceptionOccured ...\n");
   124         printf("\ndoRedirect: overwriting the functions Throw,ThrowNew,ExceptionOccured ...\n");
   125     redir_jni_functions->Throw = MyThrow;
   125     redir_jni_functions->Throw = MyThrow;
   126     redir_jni_functions->ThrowNew = MyThrowNew;
   126     redir_jni_functions->ThrowNew = MyThrowNew;
   127     redir_jni_functions->ExceptionOccurred = MyExceptionOccurred;
   127     redir_jni_functions->ExceptionOccurred = MyExceptionOccurred;
   128 
   128 
   129     if ((err = jvmti->SetJNIFunctionTable(redir_jni_functions)) !=
   129     err = jvmti->SetJNIFunctionTable(redir_jni_functions);
   130             JVMTI_ERROR_NONE) {
   130     if (err != JVMTI_ERROR_NONE) {
   131         result = STATUS_FAILED;
   131         result = STATUS_FAILED;
   132         printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n",
   132         printf("(%s,%d): TEST FAILED: failed to set new JNI function table: %s\n",
   133             __FILE__, __LINE__, TranslateError(err));
   133             __FILE__, __LINE__, TranslateError(err));
   134         env->FatalError("failed to set new JNI function table");
   134         env->FatalError("failed to set new JNI function table");
   135     }
   135     }
   141 void doRestore(JNIEnv *env) {
   141 void doRestore(JNIEnv *env) {
   142     jvmtiError err;
   142     jvmtiError err;
   143 
   143 
   144     if (verbose)
   144     if (verbose)
   145         printf("\ndoRestore: restoring the original JNI function table ...\n");
   145         printf("\ndoRestore: restoring the original JNI function table ...\n");
   146     if ((err = jvmti->SetJNIFunctionTable(orig_jni_functions)) !=
   146     err = jvmti->SetJNIFunctionTable(orig_jni_functions);
   147             JVMTI_ERROR_NONE) {
   147     if (err != JVMTI_ERROR_NONE) {
   148         result = STATUS_FAILED;
   148         result = STATUS_FAILED;
   149         printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n",
   149         printf("(%s,%d): TEST FAILED: failed to restore original JNI function table: %s\n",
   150             __FILE__, __LINE__, TranslateError(err));
   150             __FILE__, __LINE__, TranslateError(err));
   151         env->FatalError("failed to restore original JNI function table");
   151         env->FatalError("failed to restore original JNI function table");
   152     }
   152     }
   155 }
   155 }
   156 
   156 
   157 void doExc(JNIEnv *env, jthrowable thrw, jclass thrCls, const char *msg) {
   157 void doExc(JNIEnv *env, jthrowable thrw, jclass thrCls, const char *msg) {
   158     jint res;
   158     jint res;
   159 
   159 
   160     if ((res = env->ThrowNew(thrCls, msg)) != 0) {
   160     res = env->ThrowNew(thrCls, msg);
       
   161     if (res != 0) {
   161         result = STATUS_FAILED;
   162         result = STATUS_FAILED;
   162         printf("(%s,%d): TEST FAILED: failed to throw new exception\n",
   163         printf("(%s,%d): TEST FAILED: failed to throw new exception\n",
   163             __FILE__, __LINE__);
   164             __FILE__, __LINE__);
   164         env->FatalError("failed to failed to throw new exception");
   165         env->FatalError("failed to failed to throw new exception");
   165     }
   166     }
   174         result = STATUS_FAILED;
   175         result = STATUS_FAILED;
   175         printf("(%s,%d): TEST FAILED: exception %s thrown by ThrowNew()\n\tis not detected by ExceptionOccurred()\n",
   176         printf("(%s,%d): TEST FAILED: exception %s thrown by ThrowNew()\n\tis not detected by ExceptionOccurred()\n",
   176             __FILE__, __LINE__, msg);
   177             __FILE__, __LINE__, msg);
   177     }
   178     }
   178 
   179 
   179     if ((res = env->Throw(thrw)) != 0) {
   180     res = env->Throw(thrw);
       
   181     if (res != 0) {
   180         result = STATUS_FAILED;
   182         result = STATUS_FAILED;
   181         printf("(%s,%d): TEST FAILED: failed to throw exception\n",
   183         printf("(%s,%d): TEST FAILED: failed to throw exception\n",
   182             __FILE__, __LINE__);
   184             __FILE__, __LINE__);
   183         env->FatalError("failed to failed to throw new exception");
   185         env->FatalError("failed to failed to throw new exception");
   184     }
   186     }
   262     objCls = env->GetObjectClass(obj);
   264     objCls = env->GetObjectClass(obj);
   263 
   265 
   264     if (verbose)
   266     if (verbose)
   265        printf("\ncheck: obtaining field ID for \"name=%s signature=%s\"...\n",
   267        printf("\ncheck: obtaining field ID for \"name=%s signature=%s\"...\n",
   266            javaField, excClassSig);
   268            javaField, excClassSig);
   267     if ((fid = env->GetFieldID(objCls, javaField, excClassSig)) == 0) {
   269     fid = env->GetFieldID(objCls, javaField, excClassSig);
       
   270     if (fid == 0) {
   268         result = STATUS_FAILED;
   271         result = STATUS_FAILED;
   269         printf("(%s,%d): TEST FAILED: failed to get ID for the field \"%s\"\n",
   272         printf("(%s,%d): TEST FAILED: failed to get ID for the field \"%s\"\n",
   270             __FILE__, __LINE__, javaField);
   273             __FILE__, __LINE__, javaField);
   271         return result;
   274         return result;
   272     }
   275     }