diff options
author | 2022-10-21 15:07:44 +0000 | |
---|---|---|
committer | 2022-10-24 14:13:04 +0000 | |
commit | 5b263aefb705fb19b627b5cf2e0db35223b8ea01 (patch) | |
tree | 5d3180b86a823f0d294eb3b414cc24ad3cea3d4c | |
parent | aa08e26515f2ba7713bdda45704ce853233d6ebc (diff) |
Call method entry hooks only when we have method entry listeners
We don't need to anything when there are no method entry listeners on
method entry. So tighten the check so we call method entry hook only
when method entry listeners are installed. Earlier, we used to call
whenever the stack is instrumented or instrumentation stubs are
installed.
Drive by fix: remove unused constant from runtime.def
Bug: 253232638
Test: art/test.py
Change-Id: I6bdb4207804fd9c79fd7f21500c00b47e12beef3
-rw-r--r-- | compiler/jni/quick/jni_compiler.cc | 4 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm64.cc | 6 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm_vixl.cc | 6 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86.cc | 6 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86_64.cc | 6 | ||||
-rw-r--r-- | runtime/instrumentation.h | 11 | ||||
-rw-r--r-- | tools/cpp-define-generator/runtime.def | 4 |
7 files changed, 29 insertions, 14 deletions
diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc index c8be993f5d..d520daa439 100644 --- a/compiler/jni/quick/jni_compiler.cc +++ b/compiler/jni/quick/jni_compiler.cc @@ -246,7 +246,7 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp std::unique_ptr<JNIMacroLabel> method_entry_hook_return; if (UNLIKELY(needs_entry_exit_hooks)) { uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); + int offset = instrumentation::Instrumentation::HaveMethodEntryListenersOffset().Int32Value(); method_entry_hook_slow_path = __ CreateLabel(); method_entry_hook_return = __ CreateLabel(); __ TestByteAndJumpIfNotZero(address + offset, method_entry_hook_slow_path.get()); @@ -570,7 +570,7 @@ static JniCompiledMethod ArtJniCompileMethodInternal(const CompilerOptions& comp std::unique_ptr<JNIMacroLabel> method_exit_hook_return; if (UNLIKELY(needs_entry_exit_hooks)) { uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); + int offset = instrumentation::Instrumentation::NeedsExitHooksOffset().Int32Value(); method_exit_hook_slow_path = __ CreateLabel(); method_exit_hook_return = __ CreateLabel(); __ TestByteAndJumpIfNotZero(address + offset, method_exit_hook_slow_path.get()); diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc index b34b613849..2cc367f0b2 100644 --- a/compiler/optimizing/code_generator_arm64.cc +++ b/compiler/optimizing/code_generator_arm64.cc @@ -1169,8 +1169,10 @@ void InstructionCodeGeneratorARM64::GenerateMethodEntryExitHook(HInstruction* in codegen_->AddSlowPath(slow_path); uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); - __ Mov(temp, address + offset); + MemberOffset offset = instruction->IsMethodExitHook() ? + instrumentation::Instrumentation::NeedsExitHooksOffset() : + instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); + __ Mov(temp, address + offset.Int32Value()); __ Ldrb(value, MemOperand(temp, 0)); __ Cbnz(value, slow_path->GetEntryLabel()); __ Bind(slow_path->GetExitLabel()); diff --git a/compiler/optimizing/code_generator_arm_vixl.cc b/compiler/optimizing/code_generator_arm_vixl.cc index 8cea5f98cf..2a9bc398ac 100644 --- a/compiler/optimizing/code_generator_arm_vixl.cc +++ b/compiler/optimizing/code_generator_arm_vixl.cc @@ -2166,9 +2166,11 @@ void InstructionCodeGeneratorARMVIXL::GenerateMethodEntryExitHook(HInstruction* new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathARMVIXL(instruction); codegen_->AddSlowPath(slow_path); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); + MemberOffset offset = instruction->IsMethodExitHook() ? + instrumentation::Instrumentation::NeedsExitHooksOffset() : + instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); uint32_t address = reinterpret_cast32<uint32_t>(Runtime::Current()->GetInstrumentation()); - __ Mov(temp, address + offset); + __ Mov(temp, address + offset.Int32Value()); __ Ldrb(temp, MemOperand(temp, 0)); __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); __ Bind(slow_path->GetExitLabel()); diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 04373c5600..a14ea8b3bf 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -1197,8 +1197,10 @@ void InstructionCodeGeneratorX86::GenerateMethodEntryExitHook(HInstruction* inst codegen_->AddSlowPath(slow_path); uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); - __ cmpb(Address::Absolute(address + offset), Immediate(0)); + MemberOffset offset = instruction->IsMethodExitHook() ? + instrumentation::Instrumentation::NeedsExitHooksOffset() : + instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); + __ cmpb(Address::Absolute(address + offset.Int32Value()), Immediate(0)); __ j(kNotEqual, slow_path->GetEntryLabel()); __ Bind(slow_path->GetExitLabel()); } diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index 40a1cd2293..3d0f35df63 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -1561,8 +1561,10 @@ void InstructionCodeGeneratorX86_64::GenerateMethodEntryExitHook(HInstruction* i codegen_->AddSlowPath(slow_path); uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); - int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); - __ movq(CpuRegister(TMP), Immediate(address + offset)); + MemberOffset offset = instruction->IsMethodExitHook() ? + instrumentation::Instrumentation::NeedsExitHooksOffset() + : instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); + __ movq(CpuRegister(TMP), Immediate(address + offset.Int32Value())); __ cmpb(Address(CpuRegister(TMP), 0), Immediate(0)); __ j(kNotEqual, slow_path->GetEntryLabel()); __ Bind(slow_path->GetExitLabel()); diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h index b232422449..634b0d2b73 100644 --- a/runtime/instrumentation.h +++ b/runtime/instrumentation.h @@ -200,7 +200,7 @@ class Instrumentation { Instrumentation(); - static constexpr MemberOffset NeedsEntryExitHooksOffset() { + static constexpr MemberOffset NeedsExitHooksOffset() { // Assert that instrumentation_stubs_installed_ is 8bits wide. If the size changes // update the compare instructions in the code generator when generating checks for // MethodEntryExitHooks. @@ -209,6 +209,15 @@ class Instrumentation { return MemberOffset(OFFSETOF_MEMBER(Instrumentation, instrumentation_stubs_installed_)); } + static constexpr MemberOffset HaveMethodEntryListenersOffset() { + // Assert that have_method_entry_listeners_ is 8bits wide. If the size changes + // update the compare instructions in the code generator when generating checks for + // MethodEntryExitHooks. + static_assert(sizeof(have_method_entry_listeners_) == 1, + "have_method_entry_listeners_ isn't expected size"); + return MemberOffset(OFFSETOF_MEMBER(Instrumentation, have_method_entry_listeners_)); + } + // Add a listener to be notified of the masked together sent of instrumentation events. This // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy // for saying you should have suspended all threads (installing stubs while threads are running diff --git a/tools/cpp-define-generator/runtime.def b/tools/cpp-define-generator/runtime.def index 4407e0c2b6..89a35782bb 100644 --- a/tools/cpp-define-generator/runtime.def +++ b/tools/cpp-define-generator/runtime.def @@ -31,8 +31,6 @@ ASM_DEFINE(RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET, ASM_DEFINE(RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET, art::Runtime::GetCalleeSaveMethodOffset(art::CalleeSaveType::kSaveRefsOnly)) ASM_DEFINE(RUNTIME_INSTRUMENTATION_OFFSET, art::Runtime::GetInstrumentationOffset().Int32Value()) -ASM_DEFINE(INSTRUMENTATION_STUBS_INSTALLED_OFFSET, - art::instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value()) ASM_DEFINE(INSTRUMENTATION_STUBS_INSTALLED_OFFSET_FROM_RUNTIME_INSTANCE, art::Runtime::GetInstrumentationOffset().Int32Value() + - art::instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value()) + art::instrumentation::Instrumentation::NeedsExitHooksOffset().Int32Value()) |