Skip to content

Conversation

@offamitkumar
Copy link
Member

@offamitkumar offamitkumar commented Sep 11, 2025

Fixes the SIGLL caused after JDK-8361376.

Issue was with cs instruction, which requires the address to be aligned. And after this change address at which operating was not aligned.

Wisdom from Principle of Z Operations:

Sytax: CS R1,R3,D2(B2)

Sytax: CSY R1,R3,D2(B2)

The second operand of COMPARE AND SWAP (CS, CSY) must be designated on a word boundary.

=> 0x3fffc3149ba <_ZN17BarrierSetNMethod15set_guard_valueEP7nmethodii+266>: cs %r1,%r4,0(%r3)
(gdb) i r r3
r3             0x3ffe500017a       4397593526650
(gdb) p ($r3 % 8) 
$5 = 2
(gdb) si 

Thread 16 "C1 CompilerThre" received signal SIGILL, Illegal instruction.
NativeMethodBarrier::set_guard_value (bit_mask=2147483647, value=1, this=0x3ffe5000166)
    at /home/amit/jdk/src/hotspot/cpu/s390/gc/shared/barrierSetNMethod_s390.cpp:74
74         if (v == old_value) break;

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8367325: [s390x] build failure due to JDK-8361376 (Bug - P1)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27213/head:pull/27213
$ git checkout pull/27213

Update a local copy of the PR:
$ git checkout pull/27213
$ git pull https://git.openjdk.org/jdk.git pull/27213/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27213

View PR using the GUI difftool:
$ git pr show -t 27213

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27213.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 11, 2025

👋 Welcome back amitkumar! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@offamitkumar This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8367325: [s390x] build failure due to JDK-8361376

Reviewed-by: mdoerr, dlong

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 111 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8367325 8367325: [s390x] build failure due to JDK-8361376 Sep 11, 2025
@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@offamitkumar The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Sep 11, 2025
@offamitkumar offamitkumar marked this pull request as ready for review September 11, 2025 10:12
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 11, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 11, 2025

Webrevs

@TheRealMDoerr
Copy link
Contributor

TheRealMDoerr commented Sep 11, 2025

I think align(4) would be sufficient.
The offset of the immediate field of cfi is 3*6+2 = 20 which is already a multiple of 4. Aligning the start of the sequence to 4 should be the right thing.
Please add a comment explaining that the immediate field of cfi needs to be 4-Byte aligned!


void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) {
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
__ align(8); // must align the following block which requires atomic updates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. Rather than aligning at the start, wouldn't it be more maintainable to do
__ align(4, offset() + 2);
before the z_cfi?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require much more changes. The barrier sequence is expected to have a fixed size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then how about we align the beginning using
__ align(4, offset() + 3*6 + 2);
to make it more self-documenting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better: define a constant for 3*6 + 2 and reuse it in class NativeMethodBarrier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code, please have a look now

OptoReg::Name opto_reg) const;
#endif // COMPILER2

static const int PATCHABLE_INSTRUCTION_OFFSET = 3 * 6 + 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better call it PATCHABLE_BARRIER_VALUE_OFFSET?
It's no longer the instruction start address.
Or even better: define 2 constants. The version without the +2 is still needed below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have given name as PATCHABLE_SEQ_START_OFFSET and PATCHABLE_BARRIER_VALUE_OFFSET. Please let me know if there is better option :)

#include "code/nativeInst.hpp"
#include "code/nmethod.hpp"
#include "gc/shared/barrierSetNMethod.hpp"
#include "gc/shared/barrierSetAssembler.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be sorted alphabetically.

address inst_addr = get_barrier_start_address() + PATCHABLE_INSTRUCTION_OFFSET;
address inst_addr = get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_INSTRUCTION_OFFSET;

DEBUG_ONLY(Assembler::is_z_cfi(*((long*)inst_addr)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cfi check needs an adjustment to point to the instruction start, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now It is pointing to z_cfi:

(gdb) x/i inst_addr 
   0x3ffe500017a:	cfi	%r0,0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks broken (already before this PR). Shouldn't it be something like assert(Assembler::is_z_cfi...)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be good to do something like this and get rid of PATCHABLE_SEQ_START_OFFSET ?:

diff --git a/src/hotspot/cpu/s390/gc/shared/barrierSetNMethod_s390.cpp b/src/hotspot/cpu/s390/gc/shared/barrierSetNMethod_s390.cpp
index 4dc50232c17..807d3cdd899 100644
--- a/src/hotspot/cpu/s390/gc/shared/barrierSetNMethod_s390.cpp
+++ b/src/hotspot/cpu/s390/gc/shared/barrierSetNMethod_s390.cpp
@@ -38,10 +38,11 @@ class NativeMethodBarrier: public NativeInstruction {
     }
 
     address get_patchable_data_address() const {
+#ifdef ASSERT
       address inst_addr = get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_SEQ_START_OFFSET;
-
-      DEBUG_ONLY(Assembler::is_z_cfi(*((long*)inst_addr)));
-      return inst_addr + 2;
+      assert(Assembler::is_z_cfi(*((long*)inst_addr)), "should be");
+#endif // ASSERT
+      return get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_BARRIER_VALUE_OFFSET;
     }
 
   public:


public:
static const int BARRIER_TOTAL_LENGTH = PATCHABLE_INSTRUCTION_OFFSET + 2*6 + 2; // bytes
static const int BARRIER_TOTAL_LENGTH = BarrierSetAssembler::PATCHABLE_INSTRUCTION_OFFSET + 2*6; // bytes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


public:
static const int BARRIER_TOTAL_LENGTH = PATCHABLE_INSTRUCTION_OFFSET + 2*6 + 2; // bytes
static const int BARRIER_TOTAL_LENGTH = BarrierSetAssembler::PATCHABLE_BARRIER_VALUE_OFFSET + 2*6; // bytes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very confusing. There are 2 instructions with 6 Bytes and one instruction with 2 Bytes after PATCHABLE_SEQ_START_OFFSET.

address inst_addr = get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_SEQ_START_OFFSET;

DEBUG_ONLY(Assembler::is_z_cfi(*((long*)inst_addr)));
return inst_addr + 2;
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_BARRIER_VALUE_OFFSET? inst_addr could be removed.

address inst_addr = get_barrier_start_address() + PATCHABLE_INSTRUCTION_OFFSET;
address inst_addr = get_barrier_start_address() + BarrierSetAssembler::PATCHABLE_INSTRUCTION_OFFSET;

DEBUG_ONLY(Assembler::is_z_cfi(*((long*)inst_addr)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks broken (already before this PR). Shouldn't it be something like assert(Assembler::is_z_cfi...)?

void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) {
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
__ align(4, __ offset() + PATCHABLE_BARRIER_VALUE_OFFSET); // must align the following block which requires atomic updates
__ align(4, __ offset() + BARRIER_TOTAL_LENGTH); // must align the following block which requires atomic updates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, this is confusing. We don't want to align the end of the barrier. We need to align the patchable field which is the immediate field of the cfi instruction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find out better way to keep the main code free from magic numbers, so now there are three constants:

  1. holding offset to the instruction (cfi)
  2. holding the offset the the patchable data
  3. total barrier length.

I guess explanation in .hpp is enough to explain the usecase.

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me. I only have some minor comments.


// first 2 bytes are for cfi instruction opcode and next 4 bytes will be the value/data to be patched,
// so we are skipping first 2 bytes and returning the address of value/data field
static const int OFFSET_TO_PATCHABLE_DATA = 6 + 6 + 6 + 2; // iihf(6) + iilf(6) + lg(6) + CFI_OPCODE(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OFFSET_TO_PATCHABLE_DATA_INSTRUCTION could be used, here.


public:
static const int BARRIER_TOTAL_LENGTH = PATCHABLE_INSTRUCTION_OFFSET + 2*6 + 2; // bytes
static const int BARRIER_TOTAL_LENGTH = BarrierSetAssembler::BARRIER_TOTAL_LENGTH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to replicate it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being used with NativeMethodBarrier, yes I can change it and technically it wouldn't affect anything, but just to keep code change bit shorter, I left it as it is.

offset += Assembler::instr_len(&start[offset]);

Assembler::is_z_cfi(*((long*)(start + offset)));
// it will be assignment operation, So it doesn't matter what value is already present in instr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean by "it will be assignment operation".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just a assignment being done in that method, i.e. instr variable will be just overwritten straightly. So currently whatever value instr holds, it wouldn't not affect the returned-value.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 18, 2025
@offamitkumar
Copy link
Member Author

@dean-long would it be possible for you to have another look at the latest changes ?
Thanks

Copy link
Member

@dean-long dean-long left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

@offamitkumar
Copy link
Member Author

thank you so much for the reviews.
/integrate

@openjdk
Copy link

openjdk bot commented Sep 19, 2025

Going to push as commit 898fcff.
Since your change was applied there have been 115 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 19, 2025
@openjdk openjdk bot closed this Sep 19, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 19, 2025
@openjdk
Copy link

openjdk bot commented Sep 19, 2025

@offamitkumar Pushed as commit 898fcff.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@offamitkumar offamitkumar deleted the alignment_fix branch September 19, 2025 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants