jni: Add @CriticalNative optimization to speed up JNI transitions
Change-Id: I963059ac3a72dd8e6a867596c356d7062deb6da7
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index b5bc2fb..daac7fb 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -616,17 +616,22 @@
/* referrer */ nullptr,
invoke_type);
- bool fast_native = false;
- if (LIKELY(method != nullptr)) {
- fast_native = method->IsAnnotatedWithFastNative();
- } else {
+ // Query any JNI optimization annotations such as @FastNative or @CriticalNative.
+ Compiler::JniOptimizationFlags optimization_flags = Compiler::kNone;
+ if (UNLIKELY(method == nullptr)) {
// Failed method resolutions happen very rarely, e.g. ancestor class cannot be resolved.
DCHECK(self->IsExceptionPending());
self->ClearException();
+ } else if (method->IsAnnotatedWithFastNative()) {
+ // TODO: Will no longer need this CHECK once we have verifier checking this.
+ CHECK(!method->IsAnnotatedWithCriticalNative());
+ optimization_flags = Compiler::kFastNative;
+ } else if (method->IsAnnotatedWithCriticalNative()) {
+ // TODO: Will no longer need this CHECK once we have verifier checking this.
+ CHECK(!method->IsAnnotatedWithFastNative());
+ optimization_flags = Compiler::kCriticalNative;
}
- Compiler::JniOptimizationFlags optimization_flags =
- fast_native ? Compiler::kFastNative : Compiler::kNone;
compiled_method = driver->GetCompiler()->JniCompile(access_flags,
method_idx,
dex_file,