From ae31d0fb148b971b6b407ed325f72ce03c2a50b7 Mon Sep 17 00:00:00 2001 From: Chad Rakoczy Date: Thu, 19 Jun 2025 20:11:54 +0000 Subject: [PATCH 1/2] 8358655: AArch64: Simplify Interpreter::profile_taken_branch --- .../cpu/aarch64/interp_masm_aarch64.cpp | 23 ++++--------------- .../cpu/aarch64/interp_masm_aarch64.hpp | 2 +- .../cpu/aarch64/templateTable_aarch64.cpp | 3 +-- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp index 35d6ebfae4b7c..e14829b7c898d 100644 --- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp @@ -1016,31 +1016,16 @@ void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { } -void InterpreterMacroAssembler::profile_taken_branch(Register mdp, - Register bumped_count) { +void InterpreterMacroAssembler::profile_taken_branch(Register mdp) { if (ProfileInterpreter) { Label profile_continue; // If no method data exists, go to profile_continue. - // Otherwise, assign to mdp test_method_data_pointer(mdp, profile_continue); // We are taking a branch. Increment the taken count. - // We inline increment_mdp_data_at to return bumped_count in a register - //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); - Address data(mdp, in_bytes(JumpData::taken_offset())); - ldr(bumped_count, data); - assert(DataLayout::counter_increment == 1, - "flow-free idiom only works with 1"); - // Intel does this to catch overflow - // addptr(bumped_count, DataLayout::counter_increment); - // sbbptr(bumped_count, 0); - // so we do this - adds(bumped_count, bumped_count, DataLayout::counter_increment); - Label L; - br(Assembler::CS, L); // skip store if counter overflow - str(bumped_count, data); - bind(L); + increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); + // The method data pointer needs to be updated to reflect the new target. update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); bind(profile_continue); @@ -1055,7 +1040,7 @@ void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { // If no method data exists, go to profile_continue. test_method_data_pointer(mdp, profile_continue); - // We are taking a branch. Increment the not taken count. + // We are not taking a branch. Increment the not taken count. increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); // The method data pointer needs to be updated to correspond to diff --git a/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp b/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp index 447d4f8244ea9..e896a2a943041 100644 --- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp @@ -276,7 +276,7 @@ class InterpreterMacroAssembler: public MacroAssembler { // narrow int return value void narrow(Register result); - void profile_taken_branch(Register mdp, Register bumped_count); + void profile_taken_branch(Register mdp); void profile_not_taken_branch(Register mdp); void profile_call(Register mdp); void profile_final_call(Register mdp); diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp index fcfe153a9a5b4..04d5f295fdf6b 100644 --- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp @@ -1759,7 +1759,7 @@ void TemplateTable::float_cmp(bool is_float, int unordered_result) void TemplateTable::branch(bool is_jsr, bool is_wide) { - __ profile_taken_branch(r0, r1); + __ profile_taken_branch(r0); const ByteSize be_offset = MethodCounters::backedge_counter_offset() + InvocationCounter::counter_offset(); const ByteSize inv_offset = MethodCounters::invocation_counter_offset() + @@ -1809,7 +1809,6 @@ void TemplateTable::branch(bool is_jsr, bool is_wide) if (UseLoopCounter) { // increment backedge counter for backward branches // r0: MDO - // w1: MDO bumped taken-count // r2: target offset __ cmp(r2, zr); __ br(Assembler::GT, dispatch); // count only if backward branch From c2d5ef37676c27784d93b8483392e7c11a2bafdc Mon Sep 17 00:00:00 2001 From: Chad Rakoczy Date: Fri, 20 Jun 2025 21:50:44 +0000 Subject: [PATCH 2/2] Remove r1 save --- src/hotspot/cpu/aarch64/templateTable_aarch64.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp index 04d5f295fdf6b..2ccde98d98d16 100644 --- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp @@ -1819,12 +1819,10 @@ void TemplateTable::branch(bool is_jsr, bool is_wide) __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset())); __ cbnz(rscratch1, has_counters); __ push(r0); - __ push(r1); __ push(r2); __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), rmethod); __ pop(r2); - __ pop(r1); __ pop(r0); __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset())); __ cbz(rscratch1, dispatch); // No MethodCounters allocated, OutOfMemory