Skip to content
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

8346239: Improve memory efficiency of JimageDiffGenerator #22835

Closed
wants to merge 4 commits into from

Conversation

jerboaa
Copy link
Contributor

@jerboaa jerboaa commented Dec 19, 2024

Please review this fairly simple change to improve how the JimageDiffGenerator works. The original implementation is pretty naive and read all bytes into memory and then compared them. This improved version only reads bytes on a bound buffer into memory compares those bytes and if equal continues on to reading the next bytes (2k at most) at a time. Previously it was 2*N (where N is the file size of a file in bytes) part of the JDK. Ouch.

There is still the off-chance of reading a full file into memory when the generator detects a change, but this shouldn't happen for large files since the total diff should be around 600K as of today.

This also reverts changes from JDK-8344036 other than the /timeout change to the test, which is preserved as I think this bump is no longer needed.

Testing:

  • GHA
  • jlink tests on a fastdebug build with --with-native-debug-symbols=internal (so as to have a large libjvm.so).
  • Manual reproducer from the bug which fails with OOM before the patch and passes after

Thoughts?


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-8346239: Improve memory efficiency of JimageDiffGenerator (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22835

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 19, 2024

👋 Welcome back sgehwolf! 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 Dec 19, 2024

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

8346239: Improve memory efficiency of JimageDiffGenerator

Reviewed-by: mbaesken

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 57 new commits pushed to the master branch:

  • f119663: 8346573: Can't use custom default file system provider with custom system class loader
  • 379ac34: 8346838: RISC-V: runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java crash with debug VMs
  • 0285020: 8345676: [ubsan] ProcessImpl_md.c:561:40: runtime error: applying zero offset to null pointer on macOS aarch64
  • 0a81676: 8346881: [ubsan] logSelection.cpp:154:24 / logSelectionList.cpp:72:94 : runtime error: applying non-zero offset 1 to null pointer
  • 08debd3: 8346993: C2 SuperWord: refactor to make more vector nodes available in VectorNode::make
  • de02503: 8346832: runtime/CompressedOops/CompressedCPUSpecificClassSpaceReservation.java fails on RISC-V
  • 27646e5: 8344148: Add an explicit compiler phase for warning generation
  • 8d388cc: 8346457: AOT cache creation crashes with "assert(pair_at(i).match() < pair_at(i+1).match()) failed: unsorted table entries"
  • d723597: 8345432: (ch, fs) Replace anonymous Thread with InnocuousThread
  • 9c393a2: 8346953: Remove unnecessary @SuppressWarnings annotations (client, Make "can write" check work on Windows #2)
  • ... and 47 more: https://git.openjdk.org/jdk/compare/4d77dbad4e15c5392878e7bc91cd8eb7ce49a482...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 added the rfr Pull request is ready for review label Dec 19, 2024
@openjdk
Copy link

openjdk bot commented Dec 19, 2024

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

  • core-libs

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.

@jerboaa
Copy link
Contributor Author

jerboaa commented Dec 19, 2024

@MBaesken @RealFYang Could you please test this PR since you originally ran into JDK-8346239 (this bug) and JDK-8344036. Thanks!

@mlbridge
Copy link

mlbridge bot commented Dec 19, 2024

Webrevs

@RealFYang
Copy link
Member

@MBaesken @RealFYang Could you please test this PR since you originally ran into JDK-8346239 (this bug) and JDK-8344036. Thanks!

Yes, I can confirm that it works on my linux-aarch64 platform. Great! Thanks!

@MBaesken
Copy link
Member

Hi Severin, I added it to our build/test queue.

@jerboaa
Copy link
Contributor Author

jerboaa commented Dec 20, 2024

Yes, I can confirm that it works on my linux-aarch64 platform. Great! Thanks!

Thank you!

@jerboaa
Copy link
Contributor Author

jerboaa commented Dec 20, 2024

Hi Severin, I added it to our build/test queue.

Thanks, Matthias!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 30, 2024
@jerboaa
Copy link
Contributor Author

jerboaa commented Jan 7, 2025

Thanks for the review @MBaesken!

@jerboaa
Copy link
Contributor Author

jerboaa commented Jan 8, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Jan 8, 2025

Going to push as commit f696d9c.
Since your change was applied there have been 76 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 Jan 8, 2025
@openjdk openjdk bot closed this Jan 8, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 8, 2025
@openjdk
Copy link

openjdk bot commented Jan 8, 2025

@jerboaa Pushed as commit f696d9c.

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

@AlanBateman
Copy link
Contributor

@slowhog Would it be possible to do a pass over this too?

try {
try (is1; is2) {
while ((bytesRead1 = is1.read(buf1)) != -1 &&
(bytesRead2 = is2.read(buf2)) != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • what's the point to have second try block?
  • I think it's easier to read to while loop on is1, then read and check is2 within the loop instead of && on both.

try (is1; is2) {
while ((bytesRead1 = is1.read(buf1)) != -1 &&
(bytesRead2 = is2.read(buf2)) != -1) {
if (bytesRead1 != bytesRead2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test seems to assume there won't be any short reads. That might be true in practice, but for defensive programming reasons it would be safer to use readNBytes() instead of read().

if (bytesRead1 != bytesRead2) {
return false;
}
if (bytesRead1 == buf1.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified by using Arrays.equals(byte[],int,int,byte[],int,int) for both cases.

@archiecobbs
Copy link
Contributor

Sorry, I didn't realize this PR was already closed. You can treat my comments as "FYI".

@jerboaa
Copy link
Contributor Author

jerboaa commented Jan 9, 2025

Thanks for the reviews. I'll follow up with those comments/fixes in a separate PR.

@jerboaa
Copy link
Contributor Author

jerboaa commented Jan 9, 2025

@slowhog @AlanBateman @archiecobbs Clean ups done in #23014 PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants