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 <stdio.h>
18 
19 #include "android-base/macros.h"
20 #include "jni.h"
21 #include "jvmti.h"
22 #include "scoped_local_ref.h"
23 
24 // Test infrastructure
25 #include "test_env.h"
26 
27 namespace art {
28 namespace Test920Objects {
29 
Java_art_Test920_getObjectSize(JNIEnv * env ATTRIBUTE_UNUSED,jclass klass ATTRIBUTE_UNUSED,jobject object)30 extern "C" JNIEXPORT jlong JNICALL Java_art_Test920_getObjectSize(
31     JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
32   jlong size;
33 
34   jvmtiError result = jvmti_env->GetObjectSize(object, &size);
35   if (result != JVMTI_ERROR_NONE) {
36     char* err;
37     jvmti_env->GetErrorName(result, &err);
38     printf("Failure running GetObjectSize: %s\n", err);
39     jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
40     return -1;
41   }
42 
43   return size;
44 }
45 
Java_art_Test920_getObjectHashCode(JNIEnv * env ATTRIBUTE_UNUSED,jclass klass ATTRIBUTE_UNUSED,jobject object)46 extern "C" JNIEXPORT jint JNICALL Java_art_Test920_getObjectHashCode(
47     JNIEnv* env ATTRIBUTE_UNUSED, jclass klass ATTRIBUTE_UNUSED, jobject object) {
48   jint hash;
49 
50   jvmtiError result = jvmti_env->GetObjectHashCode(object, &hash);
51   if (result != JVMTI_ERROR_NONE) {
52     char* err;
53     jvmti_env->GetErrorName(result, &err);
54     printf("Failure running GetObjectHashCode: %s\n", err);
55     jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(err));
56     return -1;
57   }
58 
59   return hash;
60 }
61 
62 }  // namespace Test920Objects
63 }  // namespace art
64