Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame^] | 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 "methods.h" |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include "base/macros.h" |
| 22 | #include "jni.h" |
| 23 | #include "openjdkjvmti/jvmti.h" |
| 24 | #include "ScopedLocalRef.h" |
| 25 | |
| 26 | #include "ti-agent/common_load.h" |
| 27 | |
| 28 | namespace art { |
| 29 | namespace Test910Methods { |
| 30 | |
| 31 | extern "C" JNIEXPORT jobjectArray JNICALL Java_Main_getMethodName( |
| 32 | JNIEnv* env, jclass klass ATTRIBUTE_UNUSED, jobject method) { |
| 33 | jmethodID id = env->FromReflectedMethod(method); |
| 34 | |
| 35 | char* name; |
| 36 | char* sig; |
| 37 | char* gen; |
| 38 | jvmtiError result = jvmti_env->GetMethodName(id, &name, &sig, &gen); |
| 39 | if (result != JVMTI_ERROR_NONE) { |
| 40 | char* err; |
| 41 | jvmti_env->GetErrorName(result, &err); |
| 42 | printf("Failure running GetMethodName: %s\n", err); |
| 43 | return nullptr; |
| 44 | } |
| 45 | |
| 46 | ScopedLocalRef<jclass> obj_class(env, env->FindClass("java/lang/String")); |
| 47 | if (obj_class.get() == nullptr) { |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | jobjectArray ret = env->NewObjectArray(3, obj_class.get(), nullptr); |
| 52 | if (ret == nullptr) { |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | ScopedLocalRef<jstring> name_str(env, name == nullptr ? nullptr : env->NewStringUTF(name)); |
| 57 | ScopedLocalRef<jstring> sig_str(env, sig == nullptr ? nullptr : env->NewStringUTF(sig)); |
| 58 | ScopedLocalRef<jstring> gen_str(env, gen == nullptr ? nullptr : env->NewStringUTF(gen)); |
| 59 | |
| 60 | env->SetObjectArrayElement(ret, 0, name_str.get()); |
| 61 | env->SetObjectArrayElement(ret, 1, sig_str.get()); |
| 62 | env->SetObjectArrayElement(ret, 2, gen_str.get()); |
| 63 | |
| 64 | // Need to deallocate the strings. |
| 65 | if (name != nullptr) { |
| 66 | jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(name)); |
| 67 | } |
| 68 | if (sig != nullptr) { |
| 69 | jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(sig)); |
| 70 | } |
| 71 | if (gen != nullptr) { |
| 72 | jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(gen)); |
| 73 | } |
| 74 | |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | // Don't do anything |
| 79 | jint OnLoad(JavaVM* vm, |
| 80 | char* options ATTRIBUTE_UNUSED, |
| 81 | void* reserved ATTRIBUTE_UNUSED) { |
| 82 | if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) { |
| 83 | printf("Unable to get jvmti env!\n"); |
| 84 | return 1; |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | } // namespace Test910Methods |
| 90 | } // namespace art |