Skip to content

8300235: Use VarHandle access in Image(Input | Output)StreamImpl classes #12204

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

minborg
Copy link
Contributor

@minborg minborg commented Jan 25, 2023

This PR suggests improving performance by using the newly introduced class jdk.internal.util.ByteArray to improve packing/unpacking operations.

The PR also proposes adding a ByteArrayLittleEndian class for support for little endian packing/unpacking.


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-8300235: Use VarHandle access in Image(Input | Output)StreamImpl classes

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12204

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 25, 2023

👋 Welcome back pminborg! 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 Jan 25, 2023

@minborg The following labels will be automatically applied to this pull request:

  • client
  • core-libs

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

@openjdk openjdk bot added client client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jan 25, 2023
@@ -272,6 +272,8 @@
jdk.jfr;
exports jdk.internal.util.random to
jdk.random;
exports jdk.internal.util to
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added coupling I am afraid.

@minborg minborg marked this pull request as ready for review January 25, 2023 19:00
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 25, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 25, 2023

Webrevs

@bplb
Copy link
Member

bplb commented Jan 25, 2023

Looks good overall. Did you measure any performance changes in the image streams? (Note that this PR and its corresponding issue are missing "Stream" in the title.)

@minborg minborg changed the title 8300235: Use VarHandle access in Image(Input | Output)Impl classes 8300235: Use VarHandle access in Image(Input | Output)StreamImpl classes Jan 26, 2023
@minborg
Copy link
Contributor Author

minborg commented Jan 26, 2023

Here are some performance figures (TLDR: about 2% performance increase):

Baseline (J21 master)

     [java] All test results:
     [java] Test(imageio.input.stream.tests.readFully(int[])) averaged 2.0089243986475606E9 bytes/sec
     [java]     with 250x250, photo, byteArray, !useCache
     [java] Test(imageio.input.stream.tests.readLong) averaged 6.087925258517034E8 bytes/sec
     [java]     with 250x250, photo, byteArray, !useCache

Patch

     [java] All test results:
     [java] Test(imageio.input.stream.tests.readFully(int[]) averaged 2.0537614726652384E9 bytes/sec
     [java]     with 250x250, photo, byteArray, !useCache
     [java] Test(imageio.input.stream.tests.readLong) averaged 6.227265050569915E8 bytes/sec
     [java]     with 250x250, photo, byteArray, !useCache

the readFully(int[]) is a custom benchmark:

                iis.mark();
                int[] array = new int[8];
                do {
                    if (pos + 4*8 > length) {
                        iis.reset();
                        iis.mark();
                        pos = 0;
                    }
                    iis.readFully(array, 0, 8);
                    pos += 4*8;
                } while (--numReps >= 0);

Tests were run on a Mac M1 aarch64 machine.

@minborg
Copy link
Contributor Author

minborg commented Jan 26, 2023

Given the way the benchmarks are written, I suspect the actual performance gains are higher than indicated by the figures above. The benchmark likely spends more time in preparing for the call (e.g. checking, looping) than in the actual target method.

@RogerRiggs
Copy link
Contributor

Can the benchmark be moved to the JMH framework; it deals with the setup and measurements in a more predictable way.
See test/micro/org/openjdk/bench/jajva/nio/... for examples.

@minborg
Copy link
Contributor Author

minborg commented Feb 2, 2023

Here are some benchmarks:

Baseline (JDK21, master (called Java 20 below))
Benchmark                       Mode  Cnt  Score   Error  Units
ImageInputStreamBench.readInt   avgt   15  1.289 ± 0.029  ns/op
ImageInputStreamBench.readLong  avgt   15  1.308 ± 0.017  ns/op

Patch (called Java 21 below)
Benchmark                       Mode  Cnt  Score   Error  Units
ImageInputStreamBench.readInt   avgt   15  0.946 ± 0.046  ns/op
ImageInputStreamBench.readLong  avgt   15  0.954 ± 0.010  ns/op

image

Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Looks good.
Thanks for the JMH benchmarks.

DOUBLE.set(array, offset, value);
}

private static VarHandle create(Class<?> viewArrayClass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming the method to createLittleEndian would make the static assignments at the top unambiguous.

@openjdk
Copy link

openjdk bot commented Feb 2, 2023

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

8300235: Use VarHandle access in Image(Input | Output)StreamImpl classes

Reviewed-by: rriggs

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

  • f696785: 8300869: Make use of the Double.toString(double) algorithm in java.util.Formatter
  • cf6b9eb: 8301637: ThreadLocalRandom.current().doubles().parallel() contention
  • c647ae6: 8301149: Parallel: Refactor MutableNUMASpace::update_layout
  • de57733: 8301644: com/sun/jdi/JdbStopThreadTest.java fails after JDK-8300811
  • 930ec00: 8301636: Minor cleanup in CommentHelper and DocPretty
  • 725d57b: 8301659: Resolve initialization reordering issues on Windows for libawt and libsaproc
  • 2d50c7d: 8298979: Remove duplicated serviceability/jvmti/thread/GetAllThreads/allthr01/allthr01.java
  • 59b7fb1: 8300273: [IR framework] Handle message instead of bailing out
  • 5b1584b: 8298880: VectorLogicalOpIdentityTest.java IR test incorrectly use avx3 instead of avx512
  • 21c1afb: 8301612: OopLoadProxy constructor should be explicit
  • ... and 146 more: https://git.openjdk.org/jdk/compare/f279c751a5b2132c11aa3a31084ee37f1a349150...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 ready Pull request is ready to be integrated label Feb 2, 2023
@minborg
Copy link
Contributor Author

minborg commented Feb 3, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Feb 3, 2023

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

  • 406021a: 8300929: Avoid unnecessary array fill after creation in java.awt.image
  • 7f313b0: 8180266: Convert sun/security/provider/KeyStore/DKSTest.sh to Java Jtreg Test
  • 3ad6aef: 8301313: RISC-V: C2: assert(false) failed: bad AD file due to missing match rule
  • 4c9de87: 8301655: Problemlist jdk/jdk/nio/zipfs/TestLocOffsetFromZip64EF.java on Linux
  • 04278e6: 8301564: Non-C-heap allocated ResourceHashtable keys and values must have trivial destructor
  • b00b70c: 8286907: keytool should warn about weak PBE algorithms
  • ee0f5b5: 8301392: Port fdlibm log1p to Java
  • f696785: 8300869: Make use of the Double.toString(double) algorithm in java.util.Formatter
  • cf6b9eb: 8301637: ThreadLocalRandom.current().doubles().parallel() contention
  • c647ae6: 8301149: Parallel: Refactor MutableNUMASpace::update_layout
  • ... and 153 more: https://git.openjdk.org/jdk/compare/f279c751a5b2132c11aa3a31084ee37f1a349150...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 3, 2023

@minborg Pushed as commit b504c94.

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

@AlanBateman
Copy link
Contributor

Do I read this correctly that the proposal is to have ByteArray and ByteArrayLittleEndian?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants