upload android base code part3

This commit is contained in:
August 2018-08-08 16:48:17 +08:00
parent 71b83c22f1
commit b9e30e05b1
15122 changed files with 2089659 additions and 0 deletions

View file

@ -0,0 +1,72 @@
//
// 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.
//
art_cc_library {
name: "libartbenchmark",
host_supported: true,
defaults: ["art_defaults" ],
srcs: [
"jni_loader.cc",
"jobject-benchmark/jobject_benchmark.cc",
"jni-perf/perf_jni.cc",
"micro-native/micro_native.cc",
"scoped-primitive-array/scoped_primitive_array.cc",
],
shared_libs: [
"libart",
"libbacktrace",
"libbase",
"libnativehelper",
],
clang: true,
target: {
android: {
shared_libs: ["libdl"],
},
host: {
host_ldlibs: ["-ldl", "-lpthread"],
},
},
cflags: [
"-Wno-frame-larger-than=",
],
}
art_cc_library {
name: "libartbenchmark-micronative-host",
host_supported: true,
device_supported: false,
defaults: ["art_debug_defaults", "art_defaults" ],
srcs: [
"jni_loader.cc",
"micro-native/micro_native.cc",
],
shared_libs: [
],
static_libs: [
],
header_libs: ["jni_headers"],
stl: "libc++_static",
clang: true,
target: {
host: {
host_ldlibs: ["-ldl", "-lpthread"],
},
},
cflags: [
"-Wno-frame-larger-than=",
],
}

View file

@ -0,0 +1 @@
Benchmarks for repeating const-class instructions in a loop.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
Benchmarks for repeating const-string instructions in a loop.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
Tests for measuring performance of JNI state changes.

View file

@ -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.
*/
#include <assert.h>
#include "jni.h"
#include "scoped_thread_state_change-inl.h"
#include "thread.h"
namespace art {
namespace {
extern "C" JNIEXPORT void JNICALL Java_JniPerfBenchmark_perfJniEmptyCall(JNIEnv*, jobject) {}
extern "C" JNIEXPORT void JNICALL Java_JniPerfBenchmark_perfSOACall(JNIEnv* env, jobject) {
ScopedObjectAccess soa(env);
}
extern "C" JNIEXPORT void JNICALL Java_JniPerfBenchmark_perfSOAUncheckedCall(JNIEnv*, jobject) {
ScopedObjectAccessUnchecked soa(Thread::Current());
}
} // namespace
} // namespace art

View file

@ -0,0 +1,52 @@
/*
* 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.
*/
public class JniPerfBenchmark {
private static final String MSG = "ABCDE";
native void perfJniEmptyCall();
native void perfSOACall();
native void perfSOAUncheckedCall();
public void timeFastJNI(int N) {
// TODO: This might be an intrinsic.
for (long i = 0; i < N; i++) {
char c = MSG.charAt(2);
}
}
public void timeEmptyCall(int N) {
for (long i = 0; i < N; i++) {
perfJniEmptyCall();
}
}
public void timeSOACall(int N) {
for (long i = 0; i < N; i++) {
perfSOACall();
}
}
public void timeSOAUncheckedCall(int N) {
for (long i = 0; i < N; i++) {
perfSOAUncheckedCall();
}
}
{
System.loadLibrary("artbenchmark");
}
}

View file

@ -0,0 +1,32 @@
/*
* 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>
extern void register_micro_native_methods(JNIEnv* env);
jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) {
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return -1;
}
// List of functions to call to register methods explicitly.
// Otherwise we use the regular JNI naming conventions to register implicitly.
register_micro_native_methods(env);
return JNI_VERSION_1_6;
}

View file

@ -0,0 +1,7 @@
Benchmark for jobject functions
Measures performance of:
Add/RemoveLocalRef
Add/RemoveGlobalRef
Add/RemoveWeakGlobalRef
Decoding local, weak, global, handle scope jobjects.

View file

@ -0,0 +1,104 @@
/*
* 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 "java_vm_ext.h"
#include "mirror/class-inl.h"
#include "scoped_thread_state_change-inl.h"
namespace art {
namespace {
extern "C" JNIEXPORT void JNICALL Java_JObjectBenchmark_timeAddRemoveLocal(
JNIEnv* env, jobject jobj, jint reps) {
ScopedObjectAccess soa(env);
ObjPtr<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);
ObjPtr<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);
ObjPtr<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);
ObjPtr<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);
ObjPtr<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);
ObjPtr<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

View file

@ -0,0 +1,37 @@
/*
* 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.
*/
public class JObjectBenchmark {
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);
}

View file

@ -0,0 +1,146 @@
/*
* 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 <stdio.h>
#include <jni.h>
#ifndef NATIVE_METHOD
#define NATIVE_METHOD(className, functionName, signature) \
{ #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) }
#endif
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
#define GLUE4(a, b, c, d) a ## b ## c ## d
#define GLUE4_(a, b, c, d) GLUE4(a, b, c, d)
#define CLASS_NAME "benchmarks/MicroNative/java/NativeMethods"
#define CLASS_INFIX benchmarks_MicroNative_java_NativeMethods
#define NAME_NORMAL_JNI_METHOD(name) GLUE4_(Java_, CLASS_INFIX, _, name)
#define NAME_CRITICAL_JNI_METHOD(name) GLUE4_(JavaCritical_, CLASS_INFIX, _, name)
#define DEFINE_NORMAL_JNI_METHOD(ret, name) extern "C" JNIEXPORT ret JNICALL GLUE4_(Java_, CLASS_INFIX, _, name)
#define DEFINE_CRITICAL_JNI_METHOD(ret, name) extern "C" JNIEXPORT ret JNICALL GLUE4_(JavaCritical_, CLASS_INFIX, _, name)
static void NativeMethods_emptyJniStaticSynchronizedMethod0(JNIEnv*, jclass) { }
static void NativeMethods_emptyJniSynchronizedMethod0(JNIEnv*, jclass) { }
static JNINativeMethod gMethods_NormalOnly[] = {
NATIVE_METHOD(NativeMethods, emptyJniStaticSynchronizedMethod0, "()V"),
NATIVE_METHOD(NativeMethods, emptyJniSynchronizedMethod0, "()V"),
};
static void NativeMethods_emptyJniMethod0(JNIEnv*, jobject) { }
static void NativeMethods_emptyJniMethod6(JNIEnv*, jobject, int, int, int, int, int, int) { }
static void NativeMethods_emptyJniMethod6L(JNIEnv*, jobject, jobject, jarray, jarray, jobject,
jarray, jarray) { }
static void NativeMethods_emptyJniStaticMethod6L(JNIEnv*, jclass, jobject, jarray, jarray, jobject,
jarray, jarray) { }
static void NativeMethods_emptyJniStaticMethod0(JNIEnv*, jclass) { }
static void NativeMethods_emptyJniStaticMethod6(JNIEnv*, jclass, int, int, int, int, int, int) { }
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeMethods, emptyJniMethod0, "()V"),
NATIVE_METHOD(NativeMethods, emptyJniMethod6, "(IIIIII)V"),
NATIVE_METHOD(NativeMethods, emptyJniMethod6L, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6L, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod0, "()V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6, "(IIIIII)V"),
};
static void NativeMethods_emptyJniMethod0_Fast(JNIEnv*, jobject) { }
static void NativeMethods_emptyJniMethod6_Fast(JNIEnv*, jobject, int, int, int, int, int, int) { }
static void NativeMethods_emptyJniMethod6L_Fast(JNIEnv*, jobject, jobject, jarray, jarray, jobject,
jarray, jarray) { }
static void NativeMethods_emptyJniStaticMethod6L_Fast(JNIEnv*, jclass, jobject, jarray, jarray,
jobject, jarray, jarray) { }
static void NativeMethods_emptyJniStaticMethod0_Fast(JNIEnv*, jclass) { }
static void NativeMethods_emptyJniStaticMethod6_Fast(JNIEnv*, jclass, int, int, int, int, int, int) { }
static JNINativeMethod gMethods_Fast[] = {
NATIVE_METHOD(NativeMethods, emptyJniMethod0_Fast, "()V"),
NATIVE_METHOD(NativeMethods, emptyJniMethod6_Fast, "(IIIIII)V"),
NATIVE_METHOD(NativeMethods, emptyJniMethod6L_Fast, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6L_Fast, "(Ljava/lang/String;[Ljava/lang/String;[[ILjava/lang/Object;[Ljava/lang/Object;[[[[Ljava/lang/Object;)V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod0_Fast, "()V"),
NATIVE_METHOD(NativeMethods, emptyJniStaticMethod6_Fast, "(IIIIII)V"),
};
// Have both a Java_ and a JavaCritical_ version of the same empty method.
// The runtime automatically selects the right one when doing a dlsym-based native lookup.
DEFINE_NORMAL_JNI_METHOD(void, emptyJniStaticMethod0_1Critical)(JNIEnv*, jclass) { }
DEFINE_CRITICAL_JNI_METHOD(void, emptyJniStaticMethod0_1Critical)() { }
DEFINE_NORMAL_JNI_METHOD(void, emptyJniStaticMethod6_1Critical)(JNIEnv*, jclass, int, int, int, int, int, int) { }
DEFINE_CRITICAL_JNI_METHOD(void, emptyJniStaticMethod6_1Critical)(int, int, int, int, int, int) { }
static JNINativeMethod gMethods_Critical[] = {
// Don't use NATIVE_METHOD because the name is mangled differently.
{ "emptyJniStaticMethod0_Critical", "()V",
reinterpret_cast<void*>(NAME_CRITICAL_JNI_METHOD(emptyJniStaticMethod0_1Critical)) },
{ "emptyJniStaticMethod6_Critical", "(IIIIII)V",
reinterpret_cast<void*>(NAME_CRITICAL_JNI_METHOD(emptyJniStaticMethod6_1Critical)) }
};
void jniRegisterNativeMethods(JNIEnv* env,
const char* className,
const JNINativeMethod* methods,
int numMethods) {
jclass c = env->FindClass(className);
if (c == nullptr) {
char* tmp;
const char* msg;
if (asprintf(&tmp,
"Native registration unable to find class '%s'; aborting...",
className) == -1) {
// Allocation failed, print default warning.
msg = "Native registration unable to find class; aborting...";
} else {
msg = tmp;
}
env->FatalError(msg);
}
if (env->RegisterNatives(c, methods, numMethods) < 0) {
char* tmp;
const char* msg;
if (asprintf(&tmp, "RegisterNatives failed for '%s'; aborting...", className) == -1) {
// Allocation failed, print default warning.
msg = "RegisterNatives failed; aborting...";
} else {
msg = tmp;
}
env->FatalError(msg);
}
}
void register_micro_native_methods(JNIEnv* env) {
jniRegisterNativeMethods(env, CLASS_NAME, gMethods_NormalOnly, NELEM(gMethods_NormalOnly));
jniRegisterNativeMethods(env, CLASS_NAME, gMethods, NELEM(gMethods));
jniRegisterNativeMethods(env, CLASS_NAME, gMethods_Fast, NELEM(gMethods_Fast));
if (env->FindClass("dalvik/annotation/optimization/CriticalNative") != nullptr) {
// Only register them explicitly if the annotation is present.
jniRegisterNativeMethods(env, CLASS_NAME, gMethods_Critical, NELEM(gMethods_Critical));
} else {
if (env->ExceptionCheck()) {
// It will throw NoClassDefFoundError
env->ExceptionClear();
}
}
// else let them be registered implicitly.
}

View file

@ -0,0 +1 @@
Tests for measuring performance of ScopedPrimitiveArray.

View file

@ -0,0 +1,58 @@
/*
* 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 "nativehelper/ScopedPrimitiveArray.h"
extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureByteArray(
JNIEnv* env, jclass, int reps, jbyteArray arr) {
jlong ret = 0;
for (jint i = 0; i < reps; ++i) {
ScopedByteArrayRO sc(env, arr);
ret += sc[0] + sc[sc.size() - 1];
}
return ret;
}
extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureShortArray(
JNIEnv* env, jclass, int reps, jshortArray arr) {
jlong ret = 0;
for (jint i = 0; i < reps; ++i) {
ScopedShortArrayRO sc(env, arr);
ret += sc[0] + sc[sc.size() - 1];
}
return ret;
}
extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureIntArray(
JNIEnv* env, jclass, int reps, jintArray arr) {
jlong ret = 0;
for (jint i = 0; i < reps; ++i) {
ScopedIntArrayRO sc(env, arr);
ret += sc[0] + sc[sc.size() - 1];
}
return ret;
}
extern "C" JNIEXPORT jlong JNICALL Java_ScopedPrimitiveArrayBenchmark_measureLongArray(
JNIEnv* env, jclass, int reps, jlongArray arr) {
jlong ret = 0;
for (jint i = 0; i < reps; ++i) {
ScopedLongArrayRO sc(env, arr);
ret += sc[0] + sc[sc.size() - 1];
}
return ret;
}

View file

@ -0,0 +1,91 @@
/*
* 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.
*/
public class ScopedPrimitiveArrayBenchmark {
// Measure adds the first and last element of the array by using ScopedPrimitiveArray.
static native long measureByteArray(int reps, byte[] arr);
static native long measureShortArray(int reps, short[] arr);
static native long measureIntArray(int reps, int[] arr);
static native long measureLongArray(int reps, long[] arr);
static final int smallLength = 16;
static final int mediumLength = 256;
static final int largeLength = 8096;
static byte[] smallBytes = new byte[smallLength];
static byte[] mediumBytes = new byte[mediumLength];
static byte[] largeBytes = new byte[largeLength];
static short[] smallShorts = new short[smallLength];
static short[] mediumShorts = new short[mediumLength];
static short[] largeShorts = new short[largeLength];
static int[] smallInts = new int[smallLength];
static int[] mediumInts = new int[mediumLength];
static int[] largeInts = new int[largeLength];
static long[] smallLongs = new long[smallLength];
static long[] mediumLongs = new long[mediumLength];
static long[] largeLongs = new long[largeLength];
public void timeSmallBytes(int reps) {
measureByteArray(reps, smallBytes);
}
public void timeMediumBytes(int reps) {
measureByteArray(reps, mediumBytes);
}
public void timeLargeBytes(int reps) {
measureByteArray(reps, largeBytes);
}
public void timeSmallShorts(int reps) {
measureShortArray(reps, smallShorts);
}
public void timeMediumShorts(int reps) {
measureShortArray(reps, mediumShorts);
}
public void timeLargeShorts(int reps) {
measureShortArray(reps, largeShorts);
}
public void timeSmallInts(int reps) {
measureIntArray(reps, smallInts);
}
public void timeMediumInts(int reps) {
measureIntArray(reps, mediumInts);
}
public void timeLargeInts(int reps) {
measureIntArray(reps, largeInts);
}
public void timeSmallLongs(int reps) {
measureLongArray(reps, smallLongs);
}
public void timeMediumLongs(int reps) {
measureLongArray(reps, mediumLongs);
}
public void timeLargeLongs(int reps) {
measureLongArray(reps, largeLongs);
}
{
System.loadLibrary("artbenchmark");
}
}

View file

@ -0,0 +1 @@
Benchmarks for repeating String.indexOf() instructions in a loop.

View file

@ -0,0 +1,122 @@
/*
* 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.
*/
public class StringIndexOfBenchmark {
public static final String string36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // length = 36
public void timeIndexOf0(int count) {
final char c = '0';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf1(int count) {
final char c = '1';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf2(int count) {
final char c = '2';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf3(int count) {
final char c = '3';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf4(int count) {
final char c = '4';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf7(int count) {
final char c = '7';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf8(int count) {
final char c = '8';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOfF(int count) {
final char c = 'F';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOfG(int count) {
final char c = 'G';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOfV(int count) {
final char c = 'V';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOfW(int count) {
final char c = 'W';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
public void timeIndexOf_(int count) {
final char c = '_';
String s = string36;
for (int i = 0; i < count; ++i) {
$noinline$indexOf(s, c);
}
}
static int $noinline$indexOf(String s, char c) {
if (doThrow) { throw new Error(); }
return s.indexOf(c);
}
public static boolean doThrow = false;
}