1
2 /*
3 * Copyright (C) 2019 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include <cstdio>
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23
24 #include "android-base/logging.h"
25 #include "android-base/macros.h"
26 #include "android-base/stringprintf.h"
27 #include "jni.h"
28 #include "jvmti.h"
29 #include "scoped_local_ref.h"
30 #include "scoped_utf_chars.h"
31
32 // Test infrastructure
33 #include "jni_helper.h"
34 #include "jvmti_helper.h"
35 #include "test_env.h"
36 #include "ti_macros.h"
37
38 namespace art {
39 namespace Test1976StructuralTransformMethods {
40
Java_art_Test1976_callNativeMethods(JNIEnv * env,jclass k,jclass m_class,jlongArray m)41 extern "C" JNIEXPORT void JNICALL Java_art_Test1976_callNativeMethods(JNIEnv* env,
42 jclass k,
43 jclass m_class,
44 jlongArray m) {
45 jint len = env->GetArrayLength(m);
46 for (jint i = 0; i < len; i++) {
47 jlong mid_val;
48 env->GetLongArrayRegion(m, i, 1, &mid_val);
49 jmethodID mid = reinterpret_cast<jmethodID>(static_cast<intptr_t>(mid_val));
50 // For this test everything is objects and static.
51 env->CallStaticVoidMethod(
52 k,
53 env->GetStaticMethodID(
54 k, "printRun", "(JLjava/lang/reflect/Method;)V"),
55 mid_val,
56 env->ToReflectedMethod(m_class, mid, true));
57 env->CallStaticVoidMethod(m_class, mid);
58 }
59 }
60
Java_art_Test1976_getMethodIds(JNIEnv * env,jclass,jobjectArray m)61 extern "C" JNIEXPORT jlongArray JNICALL Java_art_Test1976_getMethodIds(JNIEnv* env,
62 jclass,
63 jobjectArray m) {
64 jint len = env->GetArrayLength(m);
65 jlongArray arr = env->NewLongArray(len);
66 for (jint i = 0; i < len; i++) {
67 env->PushLocalFrame(1);
68 jmethodID fid = env->FromReflectedMethod(env->GetObjectArrayElement(m, i));
69 jlong lmid = static_cast<jlong>(reinterpret_cast<intptr_t>(fid));
70 env->SetLongArrayRegion(arr, i, 1, &lmid);
71 env->PopLocalFrame(nullptr);
72 }
73 return arr;
74 }
75
76 } // namespace Test1976StructuralTransformMethods
77 } // namespace art
78