blob: fbf32595f84a4515c9669711630c7f995fd5e0ea [file] [log] [blame]
Andreas Gampee492ae32016-10-28 19:34:57 -07001/*
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
Andreas Gampe336c3c32016-11-08 17:02:19 -080026#include "ti-agent/common_helper.h"
Andreas Gampee492ae32016-10-28 19:34:57 -070027#include "ti-agent/common_load.h"
28
29namespace art {
30namespace Test912Classes {
31
32extern "C" JNIEXPORT jobjectArray JNICALL Java_Main_getClassSignature(
33 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jclass klass) {
34 char* sig;
35 char* gen;
36 jvmtiError result = jvmti_env->GetClassSignature(klass, &sig, &gen);
37 if (result != JVMTI_ERROR_NONE) {
38 char* err;
39 jvmti_env->GetErrorName(result, &err);
40 printf("Failure running GetClassSignature: %s\n", err);
41 return nullptr;
42 }
43
Andreas Gampe336c3c32016-11-08 17:02:19 -080044 auto callback = [&](jint i) {
45 if (i == 0) {
46 return sig == nullptr ? nullptr : env->NewStringUTF(sig);
47 } else {
48 return gen == nullptr ? nullptr : env->NewStringUTF(gen);
49 }
50 };
51 jobjectArray ret = CreateObjectArray(env, 2, "java/lang/String", callback);
Andreas Gampee492ae32016-10-28 19:34:57 -070052
53 // Need to deallocate the strings.
54 if (sig != nullptr) {
55 jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(sig));
56 }
57 if (gen != nullptr) {
58 jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(gen));
59 }
60
61 return ret;
62}
63
64// Don't do anything
65jint OnLoad(JavaVM* vm,
66 char* options ATTRIBUTE_UNUSED,
67 void* reserved ATTRIBUTE_UNUSED) {
68 if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) {
69 printf("Unable to get jvmti env!\n");
70 return 1;
71 }
72 return 0;
73}
74
75} // namespace Test912Classes
76} // namespace art