Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [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 | |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 17 | #include <stdio.h> |
| 18 | |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 19 | #include "android-base/macros.h" |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 20 | #include "jni.h" |
Andreas Gampe | 5e03a30 | 2017-03-13 13:10:00 -0700 | [diff] [blame] | 21 | #include "jvmti.h" |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 22 | #include "scoped_local_ref.h" |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 23 | |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 24 | // Test infrastructure |
| 25 | #include "test_env.h" |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | namespace Test920Objects { |
| 29 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 30 | extern "C" JNIEXPORT jlong JNICALL Java_art_Test920_getObjectSize( |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 46 | extern "C" JNIEXPORT jint JNICALL Java_art_Test920_getObjectHashCode( |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 62 | } // namespace Test920Objects |
| 63 | } // namespace art |