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,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);
}