From 2d4feeb67912d64b9e980e6687794826a5c22f9d Mon Sep 17 00:00:00 2001 From: Mythri Alle Date: Wed, 13 Oct 2021 15:39:37 +0000 Subject: Add support for calling entry / exit hooks directly from JIT code The idea of this CL is to avoid maintaining the instrumentation stack and manipulating the return addresses on the stack to call the entry / exit hooks. This Cl only addresses this for JITed code. In follow up CLs, we will extend this to others (native, nterp). Once we have everything in place we could remove the complexity of instrumentation stack. This CL introduces new nodes (HMethodEntry / HMethodExit(Void)) that generate code to call the trace entry / exit hooks when instrumentation_stubs are installed. Currently these are introduced for JITed code in debuggable mode. The entry / exit hooks roughly do the same this as instrumentation entry / exit points. We also extend the JITed frame slots by adding a ShouldDeoptimize slot. This will be used to force deoptimization of frames when requested by jvmti (for ex: structural re-definition). Test: art/testrunner.py Change-Id: Id4aa439731d214a8d2b820a67e75415ca1d5424e --- compiler/optimizing/nodes.h | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 06fb88e837..978e7c419e 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -21,6 +21,7 @@ #include #include +#include "art_method.h" #include "base/arena_allocator.h" #include "base/arena_bit_vector.h" #include "base/arena_containers.h" @@ -32,7 +33,6 @@ #include "base/quasi_atomic.h" #include "base/stl_util.h" #include "base/transform_array_ref.h" -#include "art_method.h" #include "block_namer.h" #include "class_root.h" #include "compilation_kind.h" @@ -680,7 +680,7 @@ class HGraph : public ArenaObject { } bool HasShouldDeoptimizeFlag() const { - return number_of_cha_guards_ != 0; + return number_of_cha_guards_ != 0 || debuggable_; } bool HasTryCatch() const { return has_try_catch_; } @@ -1530,6 +1530,8 @@ class HLoopInformationOutwardIterator : public ValueObject { M(LongConstant, Constant) \ M(Max, Instruction) \ M(MemoryBarrier, Instruction) \ + M(MethodEntryHook, Instruction) \ + M(MethodExitHook, Instruction) \ M(Min, BinaryOperation) \ M(MonitorOperation, Instruction) \ M(Mul, BinaryOperation) \ @@ -2991,6 +2993,38 @@ class HExpression<0> : public HInstruction { friend class SsaBuilder; }; +class HMethodEntryHook : public HExpression<0> { + public: + explicit HMethodEntryHook(uint32_t dex_pc) + : HExpression(kMethodEntryHook, SideEffects::All(), dex_pc) {} + + bool NeedsEnvironment() const override { + return true; + } + + DECLARE_INSTRUCTION(MethodEntryHook); + + protected: + DEFAULT_COPY_CONSTRUCTOR(MethodEntryHook); +}; + +class HMethodExitHook : public HExpression<1> { + public: + HMethodExitHook(HInstruction* value, uint32_t dex_pc) + : HExpression(kMethodExitHook, SideEffects::All(), dex_pc) { + SetRawInputAt(0, value); + } + + bool NeedsEnvironment() const override { + return true; + } + + DECLARE_INSTRUCTION(MethodExitHook); + + protected: + DEFAULT_COPY_CONSTRUCTOR(MethodExitHook); +}; + // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow // instruction that branches to the exit block. class HReturnVoid final : public HExpression<0> { -- cgit v1.2.3-59-g8ed1b