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
diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc
index c8be993..d520daa 100644
--- a/compiler/jni/quick/jni_compiler.cc
+++ b/compiler/jni/quick/jni_compiler.cc
@@ -246,7 +246,7 @@
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 @@
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 b34b613..2cc367f 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -1169,8 +1169,10 @@
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 8cea5f9..2a9bc39 100644
--- a/compiler/optimizing/code_generator_arm_vixl.cc
+++ b/compiler/optimizing/code_generator_arm_vixl.cc
@@ -2166,9 +2166,11 @@
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 04373c5..a14ea8b 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -1197,8 +1197,10 @@
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 40a1cd2..3d0f35d 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -1561,8 +1561,10 @@
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 b232422..634b0d2 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -200,7 +200,7 @@
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 @@
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 4407e0c..89a3578 100644
--- a/tools/cpp-define-generator/runtime.def
+++ b/tools/cpp-define-generator/runtime.def
@@ -31,8 +31,6 @@
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())