blob: 886dd0e67325c7323155f88722e48aec7b1490da [file] [log] [blame]
Andreas Gampe50a4e492017-01-06 18:00:20 -08001/*
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 "objects.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_helper.h"
27#include "ti-agent/common_load.h"
28
29namespace art {
30namespace Test920Objects {
31
32extern "C" JNIEXPORT jlong JNICALL Java_Main_getObjectSize(
33 JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
34 jlong size;
35
36 jvmtiError result = jvmti_env->GetObjectSize(object, &size);
37 if (result != JVMTI_ERROR_NONE) {
38 char* err;
39 jvmti_env->GetErrorName(result, &err);
40 printf("Failure running GetObjectSize: %s\n", err);
41 jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
42 return -1;
43 }
44
45 return size;
46}
47
48extern "C" JNIEXPORT jint JNICALL Java_Main_getObjectHashCode(
49 JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
50 jint hash;
51
52 jvmtiError result = jvmti_env->GetObjectHashCode(object, &hash);
53 if (result != JVMTI_ERROR_NONE) {
54 char* err;
55 jvmti_env->GetErrorName(result, &err);
56 printf("Failure running GetObjectHashCode: %s\n", err);
57 jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
58 return -1;
59 }
60
61 return hash;
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 SetAllCapabilities(jvmti_env);
73 return 0;
74}
75
76} // namespace Test920Objects
77} // namespace art