Skip to content
This repository has been archived by the owner. It is now read-only.

8279930: Synthetic cast causes generation of store barriers when using heap segments #97

Closed

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Jan 12, 2022

When looking at larger benchmarks, I noted a discrepancy between the performance of off-heap segments and on-heap segments. Looking at the assembly for the MemorySegment::asSlice method I could see some additional barriers in the off-heap case, but could not initially make sense of them. Vlad pointed me at G1 (in fact no such barrier was emitted when using a different GC, such as the serial GC, or ZGC), and later Erik narrowed the problem down to a failure in a C2 optimization to remove barriers around initializing stores. This problem was caused by a synthetic cast added by javac to a value (the base object) that initialized the newly created memory segment slice. Because of that case, C2 missed the store as an "initializing" one, and inserted additional barriers. This patch should make performance of on-heap segments a lot more reliable, especially when slicing is involved.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8279930: Synthetic cast causes generation of store barriers when using heap segments

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk18 pull/97/head:pull/97
$ git checkout pull/97

Update a local copy of the PR:
$ git checkout pull/97
$ git pull https://git.openjdk.java.net/jdk18 pull/97/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 97

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk18/pull/97.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jan 12, 2022

👋 Welcome back mcimadamore! 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 openjdk bot added the rfr label Jan 12, 2022
@openjdk
Copy link

@openjdk openjdk bot commented Jan 12, 2022

@mcimadamore 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.

@openjdk openjdk bot added the core-libs label Jan 12, 2022
@mlbridge
Copy link

@mlbridge mlbridge bot commented Jan 12, 2022

Webrevs


OfByte(long offset, byte[] base, long length, int mask) {
OfByte(long offset, Object base, long length, int mask) {
Copy link
Member

@PaulSandoz PaulSandoz Jan 12, 2022

Choose a reason for hiding this comment

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

Is it possible to retain the array type for the constructor?

Copy link
Contributor Author

@mcimadamore mcimadamore Jan 12, 2022

Choose a reason for hiding this comment

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

yes, that should be harmless

Copy link
Contributor Author

@mcimadamore mcimadamore Jan 12, 2022

Choose a reason for hiding this comment

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

Actually, no, sorry. If I sharpen the type, then dup has to cast, so we go back to the original issue.

Copy link
Member

@PaulSandoz PaulSandoz Jan 12, 2022

Choose a reason for hiding this comment

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

Ah yes, i see. Maybe it's worth adding a general comment to the class doc of HeapMemorySegmentImpl briefly explaining the reasons for use of Object.

public void setup() {
scope = ResourceScope.newConfinedScope();
nativeSegment = MemorySegment.allocateNative(ALLOC_SIZE, scope);
heapSegment = MemorySegment.ofArray(new float[ELEM_SIZE]);
Copy link
Member

@PaulSandoz PaulSandoz Jan 13, 2022

Choose a reason for hiding this comment

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

The heap MemorySegment wraps float[] but is accessed as if int[], same bit size, but I suspect it was not intentional?

@openjdk
Copy link

@openjdk openjdk bot commented Jan 13, 2022

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

8279930: Synthetic cast causes generation of store barriers when using heap segments

Reviewed-by: psandoz

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

  • ff85659: 8279833: Loop optimization issue in String.encodeUTF8_UTF16
  • 14a90e5: 8279370: jdk.jpackage/share/native/applauncher/JvmLauncher.cpp fails to build with GCC 6.3.0
  • 3381479: 8274007: [REDO] VM Exit does not abort concurrent mark
  • 65eb066: 8279837: C2: assert(is_Loop()) failed: invalid node class: Region

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 added the ready label Jan 13, 2022
@mcimadamore
Copy link
Contributor Author

@mcimadamore mcimadamore commented Jan 14, 2022

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Jan 14, 2022

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

  • 45f2063: 8279597: [TESTBUG] ReturnBlobToWrongHeapTest.java fails with -XX:TieredStopAtLevel=1 on machines with many cores
  • 064ee6a: 8278434: timeouts in test java/time/test/java/time/format/TestZoneTextPrinterParser.java
  • ff85659: 8279833: Loop optimization issue in String.encodeUTF8_UTF16
  • 14a90e5: 8279370: jdk.jpackage/share/native/applauncher/JvmLauncher.cpp fails to build with GCC 6.3.0
  • 3381479: 8274007: [REDO] VM Exit does not abort concurrent mark
  • 65eb066: 8279837: C2: assert(is_Loop()) failed: invalid node class: Region

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated label Jan 14, 2022
@openjdk openjdk bot closed this Jan 14, 2022
@openjdk openjdk bot removed ready rfr labels Jan 14, 2022
@openjdk
Copy link

@openjdk openjdk bot commented Jan 14, 2022

@mcimadamore Pushed as commit c6b0275.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core-libs integrated
2 participants