From c8c2bb6784d70cdc6e3a75a24fc9d09970a574e4 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 15 Oct 2021 09:33:09 +0100 Subject: JNI compiler: Rewrite exception polling. Make the slow path explicit in the JNI compiler. Fix the CFI data for the exceptional path of synchronized methods. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 172332525 Change-Id: If64965eef15c063e36b78dd8bb6cba5af34ab4fa --- compiler/jni/quick/jni_compiler.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'compiler/jni/quick/jni_compiler.cc') diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc index 25eb919c53..5752c7562a 100644 --- a/compiler/jni/quick/jni_compiler.cc +++ b/compiler/jni/quick/jni_compiler.cc @@ -288,6 +288,8 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp // 5. Call into appropriate JniMethodStart passing Thread* so that transition out of Runnable // can occur. We abuse the JNI calling convention here, that is guaranteed to support passing // two pointer arguments. + std::unique_ptr monitor_enter_exception_slow_path = + UNLIKELY(is_synchronized) ? __ CreateLabel() : nullptr; if (LIKELY(!is_critical_native)) { // Skip this for @CriticalNative methods. They do not call JniMethodStart. ThreadOffset jni_start = @@ -328,7 +330,7 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp } method_register = ManagedRegister::NoRegister(); // Method register is clobbered. if (is_synchronized) { // Check for exceptions from monitor enter. - __ ExceptionPoll(main_out_arg_size); + __ ExceptionPoll(monitor_enter_exception_slow_path.get()); } } @@ -602,8 +604,10 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp // 17. Process pending exceptions from JNI call or monitor exit. // @CriticalNative methods do not need exception poll in the stub. + std::unique_ptr exception_slow_path = + LIKELY(!is_critical_native) ? __ CreateLabel() : nullptr; if (LIKELY(!is_critical_native)) { - __ ExceptionPoll(/* stack_adjust= */ 0); + __ ExceptionPoll(exception_slow_path.get()); } // 18. Remove activation - need to restore callee save registers since the GC may have changed @@ -673,7 +677,21 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp } } - // 20. Finalize code generation + // 20. Emit exception poll slow paths. + if (LIKELY(!is_critical_native)) { + if (UNLIKELY(is_synchronized)) { + __ Bind(monitor_enter_exception_slow_path.get()); + if (main_out_arg_size != 0) { + jni_asm->cfi().AdjustCFAOffset(main_out_arg_size); + __ DecreaseFrameSize(main_out_arg_size); + } + } + DCHECK_EQ(jni_asm->cfi().GetCurrentCFAOffset(), static_cast(current_frame_size)); + __ Bind(exception_slow_path.get()); + __ DeliverPendingException(); + } + + // 21. Finalize code generation __ FinalizeCode(); size_t cs = __ CodeSize(); std::vector managed_code(cs); -- cgit v1.2.3-59-g8ed1b