summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2015-09-22 18:14:29 -0700
committer Mathieu Chartier <mathieuc@google.com> 2015-09-22 18:20:10 -0700
commit14f8b13d2593770b7f5387a33f6a8400c20aaa8e (patch)
tree5d4c8b1fac7738ae4541dd572d3f678dd3acf79b
parent6a0e05aff612118d45b87473829fd69a595003ba (diff)
Add benchmark for jobject functions
Measures performance of: Add/RemoveLocalRef Add/RemoveGlobalRef Add/RemoveWeakGlobalRef Decoding local, weak, global, handle scope jobjects. N5 results: benchmark ns linear runtime AddRemoveGlobal 476.7 =========================== AddRemoveLocal 42.0 == AddRemoveWeakGlobal 519.7 ============================== DecodeGlobal 69.9 ==== DecodeHandleScopeRef 38.9 == DecodeLocal 70.7 ==== DecodeWeakGlobal 119.7 ====== Change-Id: Iba014a9993909ee45fd52ae48d6dea8428a86bf2
-rw-r--r--benchmark/Android.mk1
-rw-r--r--benchmark/jobject-benchmark/info.txt7
-rw-r--r--benchmark/jobject-benchmark/jobject_benchmark.cc103
-rw-r--r--benchmark/jobject-benchmark/src/JObjectBenchmark.java39
4 files changed, 150 insertions, 0 deletions
diff --git a/benchmark/Android.mk b/benchmark/Android.mk
index 09aca98337..a4a603ad04 100644
--- a/benchmark/Android.mk
+++ b/benchmark/Android.mk
@@ -19,6 +19,7 @@ LOCAL_PATH := $(call my-dir)
include art/build/Android.common_build.mk
LIBARTBENCHMARK_COMMON_SRC_FILES := \
+ jobject-benchmark/jobject_benchmark.cc \
jni-perf/perf_jni.cc \
scoped-primitive-array/scoped_primitive_array.cc
diff --git a/benchmark/jobject-benchmark/info.txt b/benchmark/jobject-benchmark/info.txt
new file mode 100644
index 0000000000..f2a256a3e6
--- /dev/null
+++ b/benchmark/jobject-benchmark/info.txt
@@ -0,0 +1,7 @@
+Benchmark for jobject functions
+
+Measures performance of:
+Add/RemoveLocalRef
+Add/RemoveGlobalRef
+Add/RemoveWeakGlobalRef
+Decoding local, weak, global, handle scope jobjects.
diff --git a/benchmark/jobject-benchmark/jobject_benchmark.cc b/benchmark/jobject-benchmark/jobject_benchmark.cc
new file mode 100644
index 0000000000..e7ca9ebc1e
--- /dev/null
+++ b/benchmark/jobject-benchmark/jobject_benchmark.cc
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jni.h"
+
+#include "mirror/class-inl.h"
+#include "scoped_thread_state_change.h"
+
+namespace art {
+namespace {
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveLocal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ for (jint i = 0; i < reps; ++i) {
+ jobject ref = soa.Env()->AddLocalReference<jobject>(obj);
+ soa.Env()->DeleteLocalRef(ref);
+ }
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeLocal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ jobject ref = soa.Env()->AddLocalReference<jobject>(obj);
+ for (jint i = 0; i < reps; ++i) {
+ CHECK_EQ(soa.Decode<mirror::Object*>(ref), obj);
+ }
+ soa.Env()->DeleteLocalRef(ref);
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveGlobal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ for (jint i = 0; i < reps; ++i) {
+ jobject ref = soa.Vm()->AddGlobalRef(soa.Self(), obj);
+ soa.Vm()->DeleteGlobalRef(soa.Self(), ref);
+ }
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeGlobal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ jobject ref = soa.Vm()->AddGlobalRef(soa.Self(), obj);
+ for (jint i = 0; i < reps; ++i) {
+ CHECK_EQ(soa.Decode<mirror::Object*>(ref), obj);
+ }
+ soa.Vm()->DeleteGlobalRef(soa.Self(), ref);
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveWeakGlobal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ for (jint i = 0; i < reps; ++i) {
+ jobject ref = soa.Vm()->AddWeakGlobalRef(soa.Self(), obj);
+ soa.Vm()->DeleteWeakGlobalRef(soa.Self(), ref);
+ }
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeWeakGlobal(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ mirror::Object* obj = soa.Decode<mirror::Object*>(jobj);
+ CHECK(obj != nullptr);
+ jobject ref = soa.Vm()->AddWeakGlobalRef(soa.Self(), obj);
+ for (jint i = 0; i < reps; ++i) {
+ CHECK_EQ(soa.Decode<mirror::Object*>(ref), obj);
+ }
+ soa.Vm()->DeleteWeakGlobalRef(soa.Self(), ref);
+}
+
+extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeDecodeHandleScopeRef(
+ JNIEnv* env, jobject jobj, jint reps) {
+ ScopedObjectAccess soa(env);
+ for (jint i = 0; i < reps; ++i) {
+ soa.Decode<mirror::Object*>(jobj);
+ }
+}
+
+} // namespace
+} // namespace art
diff --git a/benchmark/jobject-benchmark/src/JObjectBenchmark.java b/benchmark/jobject-benchmark/src/JObjectBenchmark.java
new file mode 100644
index 0000000000..f4c059c58b
--- /dev/null
+++ b/benchmark/jobject-benchmark/src/JObjectBenchmark.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.google.caliper.SimpleBenchmark;
+
+public class JObjectBenchmark extends SimpleBenchmark {
+ public JObjectBenchmark() {
+ // Make sure to link methods before benchmark starts.
+ System.loadLibrary("artbenchmark");
+ timeAddRemoveLocal(1);
+ timeDecodeLocal(1);
+ timeAddRemoveGlobal(1);
+ timeDecodeGlobal(1);
+ timeAddRemoveWeakGlobal(1);
+ timeDecodeWeakGlobal(1);
+ timeDecodeHandleScopeRef(1);
+ }
+
+ public native void timeAddRemoveLocal(int reps);
+ public native void timeDecodeLocal(int reps);
+ public native void timeAddRemoveGlobal(int reps);
+ public native void timeDecodeGlobal(int reps);
+ public native void timeAddRemoveWeakGlobal(int reps);
+ public native void timeDecodeWeakGlobal(int reps);
+ public native void timeDecodeHandleScopeRef(int reps);
+}