Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -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 "classes.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 Test912Classes { |
| 30 | |
| 31 | extern "C" JNIEXPORT jobjectArray JNICALL Java_Main_getClassSignature( |
| 32 | JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jclass klass) { |
| 33 | char* sig; |
| 34 | char* gen; |
| 35 | jvmtiError result = jvmti_env->GetClassSignature(klass, &sig, &gen); |
| 36 | if (result != JVMTI_ERROR_NONE) { |
| 37 | char* err; |
| 38 | jvmti_env->GetErrorName(result, &err); |
| 39 | printf("Failure running GetClassSignature: %s\n", err); |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
| 43 | ScopedLocalRef<jclass> obj_class(env, env->FindClass("java/lang/String")); |
| 44 | if (obj_class.get() == nullptr) { |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
| 48 | jobjectArray ret = env->NewObjectArray(2, obj_class.get(), nullptr); |
| 49 | if (ret == nullptr) { |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | ScopedLocalRef<jstring> sig_str(env, sig == nullptr ? nullptr : env->NewStringUTF(sig)); |
| 54 | ScopedLocalRef<jstring> gen_str(env, gen == nullptr ? nullptr : env->NewStringUTF(gen)); |
| 55 | |
| 56 | env->SetObjectArrayElement(ret, 0, sig_str.get()); |
| 57 | env->SetObjectArrayElement(ret, 1, gen_str.get()); |
| 58 | |
| 59 | // Need to deallocate the strings. |
| 60 | if (sig != nullptr) { |
| 61 | jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(sig)); |
| 62 | } |
| 63 | if (gen != nullptr) { |
| 64 | jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(gen)); |
| 65 | } |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | // Don't do anything |
| 71 | jint OnLoad(JavaVM* vm, |
| 72 | char* options ATTRIBUTE_UNUSED, |
| 73 | void* reserved ATTRIBUTE_UNUSED) { |
| 74 | if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) { |
| 75 | printf("Unable to get jvmti env!\n"); |
| 76 | return 1; |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | } // namespace Test912Classes |
| 82 | } // namespace art |