Skip to content

8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int' #22456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

offamitkumar
Copy link
Member

@offamitkumar offamitkumar commented Nov 29, 2024

fixes the issue reported by ubsan.


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-8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int' (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22456

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2024

👋 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 Nov 29, 2024

@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:

8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int'

Reviewed-by: lucy, 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 53 new commits pushed to the master branch:

  • 293323c: 8340141: C1: rework ciMethod::equals following 8338471
  • 76e874c: 8345319: Fix the tag type in PoolEntry and AnnotationValue
  • e9f6ba0: 8345293: Fix generational Shenandoah with compact headers
  • e1910f2: 8345397: Remove from g1HeapRegionRemSet.cpp
  • 3c60f0b: 8345296: AArch64: VM crashes with SIGILL when prctl is disallowed
  • 3eaa761: 8342086: FileInputStream.available() fails with "Incorrect function" for "nul" path (win)
  • 60bd73a: 8342089: Require --enable-native-access to be the same between CDS dump time and run time
  • 2be27e1: 8345393: ProblemList java/util/concurrent/locks/StampedLock/OOMEInStampedLock.java on generic-all JTREG_TEST_THREAD_FACTORY=Virtual
  • ba50939: 8341649: Regressions with large metaspace apps after 8338526
  • caf053b: 8337287: Update image in javax.swing.text.Document.insert
  • ... and 43 more: https://git.openjdk.org/jdk/compare/ac2fede165e0ecbfa51f5cc75a3218c51e3528be...master

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 8344304 8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int' Nov 29, 2024
@openjdk
Copy link

openjdk bot commented Nov 29, 2024

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

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label Nov 29, 2024
@offamitkumar offamitkumar marked this pull request as ready for review November 29, 2024 12:11
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 29, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 29, 2024

Webrevs

} else {
__ z_slfi(lreg, c);
}
break;

Choose a reason for hiding this comment

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

Would it be simpler to use java_negate(c) (from globalDefinitions.hpp)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure of that actually. I didn't even know that there exists such helper method. Thanks for making me aware.

I updated current solution in accordance with GCC compiler. So Z don't have a shi instruction which can handle 16-bit numbers, so GCC negates the number and adds it with ahi instruction. Then for number upto 32bits, slfi instruction is emitted for subtraction.

@RealLucy do you have other thoughts on this ?

Copy link
Member

Choose a reason for hiding this comment

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

I agree,
__ z_afi(lreg, java_negate(c));
reads better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you use add2reg_32() for the subtraction as well?

Comment on lines 1536 to 1540
if (Immediate::is_simm16(c)) {
__ z_ahi(lreg, c);
} else {
__ z_afi(lreg, c);
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems like it would be better to have code like this in a helper function, instead of making every call site repeat the pattern. Can you use add2reg() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

add2reg will emit z_aghi instruction which is for 64 bit (register) <- 16 bit (immediate). z_ahi and z_afi are both
32 bit (register) < - 16 bit (immediate), 32 bit (register) <- 32 bit (immediate). So I guess these are better here. Though we can move the logic to new method add2reg_32() method which will do the check and emit correct instruction.

} else {
__ z_slfi(lreg, c);
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you use add2reg_32() for the subtraction as well?

@@ -681,6 +681,17 @@ void MacroAssembler::add2reg(Register r1, int64_t imm, Register r2) {
z_agfi(r1, imm);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer this method to have the same interface as add2reg(). Of course, that implies a more complex method body. Your choice.

@@ -156,7 +156,9 @@ class MacroAssembler: public Assembler {
unsigned int mul_reg64_const16(Register rval, Register work, int cval);

// Generic operation r1 := r2 + imm.
void add2reg(Register r1, int64_t imm, Register r2 = noreg);
void add2reg (Register r1, int64_t imm, Register r2 = noreg);
void add2reg_32(Register r1, int64_t imm, Register r2 = noreg);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the difference between these two. For both, imm must be a simm_32. I don't think we need add2reg_32.

Copy link
Member Author

@offamitkumar offamitkumar Dec 3, 2024

Choose a reason for hiding this comment

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

for add2reg_32 the sum and the first operand, register in this case, are treated as 32 bits signed integers. But for add2reg, sum and operands will be treated as 64 bits signed integers. Immediate value in both case will be 32 bits only.

Copy link
Contributor

@RealLucy RealLucy left a comment

Choose a reason for hiding this comment

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

LGTM.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 3, 2024
@offamitkumar
Copy link
Member Author

Thanks for reviews & suggestions Lutz, Dean.
/integrate

@openjdk
Copy link

openjdk bot commented Dec 4, 2024

Going to push as commit 43b337e.
Since your change was applied there have been 65 commits pushed to the master branch:

  • 7ec36bb: 8343001: Adjust XSLT and XPath Extension Function Property
  • c143138: 8345351: RISC-V: Rename macro-assembler routine cmpxchg_weak to weak_cmpxchg
  • 4237897: 8345341: Fix incorrect log message in JDI stop002t test
  • 82e8aa6: 8345415: Rollback JDK-8301991 change on xmlsecurity_de.properties
  • 05ee562: 8343839: Detect patched modules and abort run-time image link early
  • 0664b51: 8344987: Test serviceability/sa/TestJhsdbJstackPrintVMLocks.java fails: NoClassDefFoundError: jdk/test/lib/Utils
  • 157a434: 8345389: Bump missed copyright years for JDK-8336768
  • a49f077: 8345221: Replace legacy with new Provider APIs in SunNativeGSS
  • 2be07b5: 8324491: Keyboard layout didn't keep its state if it was changed when dialog was active
  • f37f64d: 8343736: Test java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java failed: Choice can't be controlled by keyboard
  • ... and 55 more: https://git.openjdk.org/jdk/compare/ac2fede165e0ecbfa51f5cc75a3218c51e3528be...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 4, 2024

@offamitkumar Pushed as commit 43b337e.

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

@offamitkumar offamitkumar deleted the ubsan_new branch December 4, 2024 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants