blob: 2f38b78eaf4ad2bf68f0a8b2131320d4d9f791a6 [file] [log] [blame]
Mathieu Chartier14f8b132015-09-22 18:14:29 -07001/*
2 * Copyright (C) 2015 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 "jni.h"
18
Vladimir Marko3e61dc02018-05-04 10:06:38 +010019#include "jni/java_vm_ext.h"
Mathieu Chartier14f8b132015-09-22 18:14:29 -070020#include "mirror/class-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070021#include "scoped_thread_state_change-inl.h"
Mathieu Chartier14f8b132015-09-22 18:14:29 -070022
23namespace art {
24namespace {
25
26extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveLocal(
27 JNIEnv* env, jobject jobj, jint reps) {
28 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070029 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070030 CHECK(obj != nullptr);
31 for (jint i = 0; i < reps; ++i) {
Mathieu Chartier8778c522016-10-04 19:06:30 -070032 jobject ref = soa.Env()->AddLocalReference<jobject>(obj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070033 soa.Env()->DeleteLocalRef(ref);
34 }
35}
36
37extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeLocal(
38 JNIEnv* env, jobject jobj, jint reps) {
39 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070040 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070041 CHECK(obj != nullptr);
Mathieu Chartier8778c522016-10-04 19:06:30 -070042 jobject ref = soa.Env()->AddLocalReference<jobject>(obj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070043 for (jint i = 0; i < reps; ++i) {
Mathieu Chartier0795f232016-09-27 18:43:30 -070044 CHECK_EQ(soa.Decode<mirror::Object>(ref), obj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070045 }
46 soa.Env()->DeleteLocalRef(ref);
47}
48
49extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveGlobal(
50 JNIEnv* env, jobject jobj, jint reps) {
51 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070052 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070053 CHECK(obj != nullptr);
54 for (jint i = 0; i < reps; ++i) {
55 jobject ref = soa.Vm()->AddGlobalRef(soa.Self(), obj);
56 soa.Vm()->DeleteGlobalRef(soa.Self(), ref);
57 }
58}
59
60extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeGlobal(
61 JNIEnv* env, jobject jobj, jint reps) {
62 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070063 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070064 CHECK(obj != nullptr);
65 jobject ref = soa.Vm()->AddGlobalRef(soa.Self(), obj);
66 for (jint i = 0; i < reps; ++i) {
Mathieu Chartier0795f232016-09-27 18:43:30 -070067 CHECK_EQ(soa.Decode<mirror::Object>(ref), obj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070068 }
69 soa.Vm()->DeleteGlobalRef(soa.Self(), ref);
70}
71
72extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveWeakGlobal(
73 JNIEnv* env, jobject jobj, jint reps) {
74 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070075 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070076 CHECK(obj != nullptr);
77 for (jint i = 0; i < reps; ++i) {
78 jobject ref = soa.Vm()->AddWeakGlobalRef(soa.Self(), obj);
79 soa.Vm()->DeleteWeakGlobalRef(soa.Self(), ref);
80 }
81}
82
83extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeWeakGlobal(
84 JNIEnv* env, jobject jobj, jint reps) {
85 ScopedObjectAccess soa(env);
Mathieu Chartier0795f232016-09-27 18:43:30 -070086 ObjPtr<mirror::Object> obj = soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070087 CHECK(obj != nullptr);
88 jobject ref = soa.Vm()->AddWeakGlobalRef(soa.Self(), obj);
89 for (jint i = 0; i < reps; ++i) {
Mathieu Chartier0795f232016-09-27 18:43:30 -070090 CHECK_EQ(soa.Decode<mirror::Object>(ref), obj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -070091 }
92 soa.Vm()->DeleteWeakGlobalRef(soa.Self(), ref);
93}
94
95extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeHandleScopeRef(
96 JNIEnv* env, jobject jobj, jint reps) {
97 ScopedObjectAccess soa(env);
98 for (jint i = 0; i < reps; ++i) {
Mathieu Chartier0795f232016-09-27 18:43:30 -070099 soa.Decode<mirror::Object>(jobj);
Mathieu Chartier14f8b132015-09-22 18:14:29 -0700100 }
101}
102
103} // namespace
104} // namespace art