summaryrefslogtreecommitdiff
path: root/compiler/jni/jni_compiler_test.cc
diff options
context:
space:
mode:
author Igor Murashkin <iam@google.com> 2016-07-29 09:51:58 -0700
committer Igor Murashkin <iam@google.com> 2016-08-16 20:19:36 +0000
commit9d4b6da934934c322536ee3309b63ce402740f49 (patch)
tree9e7ee5023d6036b98e0560411bb0527efdedca01 /compiler/jni/jni_compiler_test.cc
parent2af1aa066e3d20edd8fea5d5b6dbbbad73102d52 (diff)
jni: Fast path for @FastNative annotated java methods
Adds a faster path for java methods annotated with dalvik.annotation.optimization.FastNative . Intended to replace usage of fast JNI (registering with "!(FOO)BAR" descriptors). Performance Microbenchmark Results (Angler): * Regular JNI cost in nanoseconds: 115 * Fast JNI cost in nanoseconds: 60 * @FastNative cost in nanoseconds: 36 Summary: Up to 67% faster (vs fast jni) JNI transition cost Change-Id: Ic23823ae0f232270c068ec999fd89aa993894b0e
Diffstat (limited to 'compiler/jni/jni_compiler_test.cc')
-rw-r--r--compiler/jni/jni_compiler_test.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/compiler/jni/jni_compiler_test.cc b/compiler/jni/jni_compiler_test.cc
index c4c2399ccd..b83985a771 100644
--- a/compiler/jni/jni_compiler_test.cc
+++ b/compiler/jni/jni_compiler_test.cc
@@ -175,6 +175,9 @@ class JniCompilerTest : public CommonCompilerTest {
void StackArgsMixedImpl();
void StackArgsSignExtendedMips64Impl();
+ void NormalNativeImpl();
+ void FastNativeImpl();
+
JNIEnv* env_;
jstring library_search_path_;
jmethodID jmethod_;
@@ -1772,4 +1775,44 @@ void JniCompilerTest::StackArgsSignExtendedMips64Impl() {
JNI_TEST(StackArgsSignExtendedMips64)
+void Java_MyClassNatives_normalNative(JNIEnv*, jclass) {
+ // Intentionally left empty.
+}
+
+// Methods not annotated with anything are not considered "fast native"
+// -- Check that the annotation lookup does not find it.
+void JniCompilerTest::NormalNativeImpl() {
+ SetUpForTest(/* direct */ true,
+ "normalNative",
+ "()V",
+ reinterpret_cast<void*>(&Java_MyClassNatives_normalNative));
+
+ ScopedObjectAccess soa(Thread::Current());
+ ArtMethod* method = soa.DecodeMethod(jmethod_);
+ ASSERT_TRUE(method != nullptr);
+
+ EXPECT_FALSE(method->IsAnnotatedWithFastNative());
+}
+JNI_TEST(NormalNative)
+
+// Methods annotated with @FastNative are considered "fast native"
+// -- Check that the annotation lookup succeeds.
+void Java_MyClassNatives_fastNative(JNIEnv*, jclass) {
+ // Intentionally left empty.
+}
+
+void JniCompilerTest::FastNativeImpl() {
+ SetUpForTest(/* direct */ true,
+ "fastNative",
+ "()V",
+ reinterpret_cast<void*>(&Java_MyClassNatives_fastNative));
+
+ ScopedObjectAccess soa(Thread::Current());
+ ArtMethod* method = soa.DecodeMethod(jmethod_);
+ ASSERT_TRUE(method != nullptr);
+
+ EXPECT_TRUE(method->IsAnnotatedWithFastNative());
+}
+JNI_TEST(FastNative)
+
} // namespace art