1 /*
2  * Copyright (C) 2013 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 <inttypes.h>
18 
19 #include <cstdio>
20 #include <memory>
21 
22 #include "android-base/logging.h"
23 #include "android-base/stringprintf.h"
24 
25 #include "jni.h"
26 #include "jvmti.h"
27 #include "scoped_local_ref.h"
28 
29 // Test infrastructure
30 #include "jni_binder.h"
31 #include "jni_helper.h"
32 #include "jvmti_helper.h"
33 #include "test_env.h"
34 #include "ti_macros.h"
35 
36 namespace art {
37 namespace Test993Breakpoints {
38 
39 extern "C" JNIEXPORT
Java_art_Test993_constructNative(JNIEnv * env,jclass klass ATTRIBUTE_UNUSED,jobject target,jclass clazz)40 jobject JNICALL Java_art_Test993_constructNative(JNIEnv* env,
41                                                  jclass klass ATTRIBUTE_UNUSED,
42                                                  jobject target,
43                                                  jclass clazz) {
44   jmethodID method = env->FromReflectedMethod(target);
45   if (env->ExceptionCheck()) {
46     return nullptr;
47   }
48   return env->NewObject(clazz, method);
49 }
50 
51 extern "C" JNIEXPORT
Java_art_Test993_invokeNativeObject(JNIEnv * env,jclass klass ATTRIBUTE_UNUSED,jobject target,jclass clazz,jobject thizz)52 void JNICALL Java_art_Test993_invokeNativeObject(JNIEnv* env,
53                                                  jclass klass ATTRIBUTE_UNUSED,
54                                                  jobject target,
55                                                  jclass clazz,
56                                                  jobject thizz) {
57   jmethodID method = env->FromReflectedMethod(target);
58   if (env->ExceptionCheck()) {
59     return;
60   }
61   if (thizz == nullptr) {
62     env->CallStaticObjectMethod(clazz, method);
63   } else {
64     env->CallObjectMethod(thizz, method);
65   }
66 }
67 
68 extern "C" JNIEXPORT
Java_art_Test993_invokeNativeBool(JNIEnv * env,jclass klass ATTRIBUTE_UNUSED,jobject target,jclass clazz,jobject thizz)69 void JNICALL Java_art_Test993_invokeNativeBool(JNIEnv* env,
70                                                jclass klass ATTRIBUTE_UNUSED,
71                                                jobject target,
72                                                jclass clazz,
73                                                jobject thizz) {
74   jmethodID method = env->FromReflectedMethod(target);
75   if (env->ExceptionCheck()) {
76     return;
77   }
78   if (thizz == nullptr) {
79     env->CallStaticBooleanMethod(clazz, method);
80   } else {
81     env->CallBooleanMethod(thizz, method);
82   }
83 }
84 
85 extern "C" JNIEXPORT
Java_art_Test993_invokeNativeLong(JNIEnv * env,jclass klass ATTRIBUTE_UNUSED,jobject target,jclass clazz,jobject thizz)86 void JNICALL Java_art_Test993_invokeNativeLong(JNIEnv* env,
87                                                jclass klass ATTRIBUTE_UNUSED,
88                                                jobject target,
89                                                jclass clazz,
90                                                jobject thizz) {
91   jmethodID method = env->FromReflectedMethod(target);
92   if (env->ExceptionCheck()) {
93     return;
94   }
95   if (thizz == nullptr) {
96     env->CallStaticLongMethod(clazz, method);
97   } else {
98     env->CallLongMethod(thizz, method);
99   }
100 }
101 
102 extern "C" JNIEXPORT
Java_art_Test993_invokeNative(JNIEnv * env,jclass klass ATTRIBUTE_UNUSED,jobject target,jclass clazz,jobject thizz)103 void JNICALL Java_art_Test993_invokeNative(JNIEnv* env,
104                                            jclass klass ATTRIBUTE_UNUSED,
105                                            jobject target,
106                                            jclass clazz,
107                                            jobject thizz) {
108   jmethodID method = env->FromReflectedMethod(target);
109   if (env->ExceptionCheck()) {
110     return;
111   }
112   if (thizz == nullptr) {
113     env->CallStaticVoidMethod(clazz, method);
114   } else {
115     env->CallVoidMethod(thizz, method);
116   }
117 }
118 
119 }  // namespace Test993Breakpoints
120 }  // namespace art
121 
122