Merge "Add int[] JNI benchmarks"
This commit is contained in:
@@ -12,8 +12,11 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
|
||||
LOCAL_PACKAGE_NAME := CorePerfTests
|
||||
|
||||
LOCAL_JNI_SHARED_LIBRARIES := libperftestscore_jni
|
||||
|
||||
# Use google-fonts/dancing-script for the performance metrics
|
||||
LOCAL_ASSET_DIR := $(TOP)/external/google-fonts/dancing-script
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
include $(call all-makefiles-under, $(LOCAL_PATH))
|
||||
|
||||
17
apct-tests/perftests/core/jni/Android.mk
Normal file
17
apct-tests/perftests/core/jni/Android.mk
Normal file
@@ -0,0 +1,17 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SDK_VERSION := 21
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
SystemPerfTest.cpp \
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(JNI_H_INCLUDE)
|
||||
|
||||
LOCAL_MODULE := libperftestscore_jni
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
82
apct-tests/perftests/core/jni/SystemPerfTest.cpp
Normal file
82
apct-tests/perftests/core/jni/SystemPerfTest.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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>
|
||||
|
||||
#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
|
||||
|
||||
static void jintarrayArgumentNoop(JNIEnv*, jclass, jintArray, jint) {
|
||||
}
|
||||
|
||||
static jint jintarrayGetLength(JNIEnv* env, jclass, jintArray jarray) {
|
||||
const jsize len = env->GetArrayLength(jarray);
|
||||
return static_cast<jint>(len);
|
||||
}
|
||||
|
||||
static jint jintarrayCriticalAccess(JNIEnv* env, jclass, jintArray jarray, jint index) {
|
||||
const jsize len = env->GetArrayLength(jarray);
|
||||
if (index < 0 || index >= len) {
|
||||
return -1;
|
||||
}
|
||||
jint* data = (jint*) env->GetPrimitiveArrayCritical(jarray, 0);
|
||||
jint ret = data[index];
|
||||
env->ReleasePrimitiveArrayCritical(jarray, data, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static jint jintarrayBasicAccess(JNIEnv* env, jclass, jintArray jarray, jint index) {
|
||||
const jsize len = env->GetArrayLength(jarray);
|
||||
if (index < 0 || index >= len) {
|
||||
return -1;
|
||||
}
|
||||
jint* data = env->GetIntArrayElements(jarray, 0);
|
||||
jint ret = data[index];
|
||||
env->ReleaseIntArrayElements(jarray, data, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const JNINativeMethod sMethods[] = {
|
||||
{"jintarrayArgumentNoop", "([II)V", (void *) jintarrayArgumentNoop},
|
||||
{"jintarrayGetLength", "([I)I", (void *) jintarrayGetLength},
|
||||
{"jintarrayCriticalAccess", "([II)I", (void *) jintarrayCriticalAccess},
|
||||
{"jintarrayBasicAccess", "([II)I", (void *) jintarrayBasicAccess},
|
||||
};
|
||||
|
||||
static int registerNativeMethods(JNIEnv* env, const char* className,
|
||||
const JNINativeMethod* gMethods, int numMethods) {
|
||||
jclass clazz = env->FindClass(className);
|
||||
if (clazz == NULL) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jint JNI_OnLoad(JavaVM* jvm, void*) {
|
||||
JNIEnv *env = NULL;
|
||||
if (jvm->GetEnv((void**) &env, JNI_VERSION_1_6)) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
if (registerNativeMethods(env, "java/lang/perftests/SystemPerfTest",
|
||||
sMethods, NELEM(sMethods)) == -1) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
@@ -20,6 +20,9 @@ import android.perftests.utils.BenchmarkState;
|
||||
import android.perftests.utils.PerfStatusReporter;
|
||||
import android.support.test.filters.LargeTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import dalvik.annotation.optimization.FastNative;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -29,6 +32,11 @@ import java.util.concurrent.TimeUnit;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class SystemPerfTest {
|
||||
|
||||
static {
|
||||
System.loadLibrary("perftestscore_jni");
|
||||
}
|
||||
|
||||
@Rule
|
||||
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
|
||||
|
||||
@@ -60,4 +68,49 @@ public class SystemPerfTest {
|
||||
state.resumeTiming();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJniArrayNoop() {
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
final int[] data = new int[450];
|
||||
while (state.keepRunning()) {
|
||||
jintarrayArgumentNoop(data, data.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJniArrayGetLength() {
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
final int[] data = new int[450];
|
||||
while (state.keepRunning()) {
|
||||
jintarrayGetLength(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJniArrayCriticalAccess() {
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
final int[] data = new int[450];
|
||||
while (state.keepRunning()) {
|
||||
jintarrayCriticalAccess(data, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJniArrayBasicAccess() {
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
final int[] data = new int[450];
|
||||
while (state.keepRunning()) {
|
||||
jintarrayBasicAccess(data, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@FastNative
|
||||
private static native void jintarrayArgumentNoop(int[] array, int length);
|
||||
@FastNative
|
||||
private static native int jintarrayGetLength(int[] array);
|
||||
@FastNative
|
||||
private static native int jintarrayCriticalAccess(int[] array, int index);
|
||||
@FastNative
|
||||
private static native int jintarrayBasicAccess(int[] array, int index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user