From 367f3dd32454858b8b25d87feb8f6599d3b4c9dd Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Thu, 1 Sep 2016 17:00:24 -0700 Subject: jni: Add @CriticalNative optimization to speed up JNI transitions Change-Id: I963059ac3a72dd8e6a867596c356d7062deb6da7 --- compiler/driver/compiler_driver.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'compiler/driver/compiler_driver.cc') diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index b5bc2fb116..daac7fbb96 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -616,17 +616,22 @@ static void CompileMethod(Thread* self, /* 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, -- cgit v1.2.3-59-g8ed1b