RFR: 8358696: Assert with extreme values for -XX:BciProfileWidth [v8]
Martin Doerr
mdoerr at openjdk.org
Tue Aug 19 14:04:02 UTC 2025
On Wed, 13 Aug 2025 09:35:08 GMT, Saranya Natarajan <snatarajan at openjdk.org> wrote:
>> **Issue**
>> Extreme values for BciProfileWidth flag such as `java -XX:BciProfileWidth=-1 -version` and `java -XX:BciProfileWidth=100000 -version `results in assert failure `assert(allocates2(pc)) failed: not in CodeBuffer memory: 0x0000772b63a7a3a0 <= 0x0000772b63b75159 <= 0x0000772b63b75158 `. This is observed in a x86 machine.
>>
>> **Analysis**
>> On debugging the issue, I found that increasing the size of the interpreter using the `InterpreterCodeSize` variable in `src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp` prevented the above mentioned assert from failing for large values of BciProfileWidth.
>>
>> **Proposal**
>> Considering the fact that larger BciProfileWidth results in slower profiling, I have proposed a range between 0 to 5000 to restrict the value for BciProfileWidth for x86 machines. This maximum value is based on modifying the `InterpreterCodeSize` variable in `src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp` using the smallest `InterpreterCodeSize` for all the architectures. As for the lower bound, a value of -1 would be the same as 0, as this simply means no return bci's will be recorded in ret profile.
>>
>> **Issue in AArch64**
>> Additionally running the command `java -XX:BciProfileWidth= 10000 -version` (or larger values) results in a different failure `assert(offset_ok_for_immed(offset(), size)) failed: must be, was: 32768, 3` on an AArch64 machine.This is an issue of maximum offset for `ldr/str` in AArch64 which can be fixed using `form_address` as mentioned in [JDK-8342736](https://bugs.openjdk.org/browse/JDK-8342736). In my preliminary fix using `form_address` on AArch64 machine. I had to modify 3 `ldr` and 1 `str` instruction (in file `src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp` at line number 926, 983, and 997). With this fix using `form_address`, `BciProfileWidth` works for maximum of 5000 after which it crashes with`assert(allocates2(pc)) failed: not in CodeBuffer memory: 0x0000772b63a7a3a0 <= 0x0000772b63b75159 <= 0x0000772b63b75158 `. Without this fix `BciProfileWidth` works for a maximum value of 1300. Currently, I have suggested to restrict the upper bound on AArch64 to 1000 instead
of fixing it with `form_address`.
>>
>> **Question to reviewers**
>> Do you think this is a reasonable fix ? For AArch64 do you suggest fixing using `form_address` ? If yes, do I fix it under this PR or create another one ?
>>
>> **Request to port maintainers**
>> @dafedafe suggested that we keep the upper boun...
>
> Saranya Natarajan has updated the pull request incrementally with one additional commit since the last revision:
>
> additions for linux-riscv64
Can you add this patch, please?
diff --git a/src/hotspot/cpu/ppc/interp_masm_ppc.hpp b/src/hotspot/cpu/ppc/interp_masm_ppc.hpp
index d3969427db3..ac3825d152f 100644
--- a/src/hotspot/cpu/ppc/interp_masm_ppc.hpp
+++ b/src/hotspot/cpu/ppc/interp_masm_ppc.hpp
@@ -228,7 +228,7 @@ class InterpreterMacroAssembler: public MacroAssembler {
// Interpreter profiling operations
void set_method_data_pointer_for_bcp();
- void test_method_data_pointer(Label& zero_continue);
+ void test_method_data_pointer(Label& zero_continue, bool may_be_far = false);
void verify_method_data_pointer();
void set_mdp_data_at(int constant, Register value);
diff --git a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
index 29fb54250c2..7557709653a 100644
--- a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
+++ b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
@@ -1249,10 +1249,14 @@ void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
}
// Test ImethodDataPtr. If it is null, continue at the specified label.
-void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {
+void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue, bool may_be_far) {
assert(ProfileInterpreter, "must be profiling interpreter");
cmpdi(CR0, R28_mdx, 0);
- beq(CR0, zero_continue);
+ if (may_be_far) {
+ bc_far_optimized(Assembler::bcondCRbiIs1, bi0(CR0, Assembler::equal), zero_continue);
+ } else {
+ beq(CR0, zero_continue);
+ }
}
void InterpreterMacroAssembler::verify_method_data_pointer() {
@@ -1555,7 +1559,7 @@ void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci,
uint row;
// If no method data exists, go to profile_continue.
- test_method_data_pointer(profile_continue);
+ test_method_data_pointer(profile_continue, true);
// Update the total ret count.
increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 );
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26139#issuecomment-3200895865
More information about the hotspot-compiler-dev
mailing list