1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <pthread.h>
18 
19 #include <cstdio>
20 #include <iostream>
21 #include <vector>
22 
23 #include "android-base/logging.h"
24 #include "jni.h"
25 #include "jvmti.h"
26 
27 #include "scoped_local_ref.h"
28 #include "scoped_primitive_array.h"
29 
30 // Test infrastructure
31 #include "jvmti_helper.h"
32 #include "test_env.h"
33 
34 namespace art {
35 namespace Test1927ExceptionEvent {
36 
ThrowNative(JNIEnv * env)37 static void ThrowNative(JNIEnv* env) {
38   ScopedLocalRef<jclass> exception(env, env->FindClass("art/Test1927$TestException"));
39   env->ThrowNew(exception.get(), "from native");
40 }
41 
CallMethod(JNIEnv * env,jclass test,const char * name)42 static void CallMethod(JNIEnv* env, jclass test, const char* name) {
43   jmethodID m = env->GetStaticMethodID(test, name, "()V");
44   env->CallStaticVoidMethod(test, m);
45 }
46 
ClearAndPrintException(JNIEnv * env,jclass test)47 static void ClearAndPrintException(JNIEnv* env, jclass test) {
48   jthrowable e = env->ExceptionOccurred();
49   env->ExceptionClear();
50   jmethodID m = env->GetStaticMethodID(test, "printException", "(Ljava/lang/Throwable;)V");
51   env->CallStaticVoidMethod(test, m, e);
52 }
53 
Java_art_Test1927_terminal_1N(JNIEnv * env,jclass)54 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_terminal_1N(JNIEnv* env, jclass) {
55   ThrowNative(env);
56 }
57 
Java_art_Test1927_test_1N(JNIEnv * env,jclass test)58 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N(JNIEnv* env, jclass test) {
59   ThrowNative(env);
60   ClearAndPrintException(env, test);
61 }
62 
Java_art_Test1927_test_1N_1J(JNIEnv * env,jclass test)63 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1J(JNIEnv* env, jclass test) {
64   CallMethod(env, test, "terminal_J");
65   ClearAndPrintException(env, test);
66 }
67 
Java_art_Test1927_test_1N_1N(JNIEnv * env,jclass test)68 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1N(JNIEnv* env, jclass test) {
69   CallMethod(env, test, "terminal_N");
70   ClearAndPrintException(env, test);
71 }
72 
Java_art_Test1927_intermediate_1N_1J(JNIEnv * env,jclass test)73 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_intermediate_1N_1J(JNIEnv* env, jclass test) {
74   CallMethod(env, test, "terminal_J");
75 }
76 
Java_art_Test1927_intermediate_1N_1N(JNIEnv * env,jclass test)77 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_intermediate_1N_1N(JNIEnv* env, jclass test) {
78   CallMethod(env, test, "terminal_N");
79 }
80 
Java_art_Test1927_test_1N_1J_1J(JNIEnv * env,jclass test)81 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1J_1J(JNIEnv* env, jclass test) {
82   CallMethod(env, test, "intermediate_J_J");
83   ClearAndPrintException(env, test);
84 }
85 
Java_art_Test1927_test_1N_1J_1N(JNIEnv * env,jclass test)86 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1J_1N(JNIEnv* env, jclass test) {
87   CallMethod(env, test, "intermediate_J_N");
88   ClearAndPrintException(env, test);
89 }
90 
Java_art_Test1927_test_1N_1N_1J(JNIEnv * env,jclass test)91 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1N_1J(JNIEnv* env, jclass test) {
92   CallMethod(env, test, "intermediate_N_J");
93   ClearAndPrintException(env, test);
94 }
95 
Java_art_Test1927_test_1N_1N_1N(JNIEnv * env,jclass test)96 extern "C" JNIEXPORT void JNICALL Java_art_Test1927_test_1N_1N_1N(JNIEnv* env, jclass test) {
97   CallMethod(env, test, "intermediate_N_N");
98   ClearAndPrintException(env, test);
99 }
100 
101 }  // namespace Test1927ExceptionEvent
102 }  // namespace art
103