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

8248186: Move CDS C++ vtable code to cppVtables.cpp #136

Closed
wants to merge 2 commits into from

Conversation

iklam
Copy link
Member

@iklam iklam commented Sep 11, 2020

I moved the code that supports C++ vtables in the CDS archive from metaspaceShared.cpp to a new file, cppVtables.cpp. To keep the refactoring straightforward, the code is moved verbatim, except for:

  • Methods are renamed from MetaspaceShared::xx to CppVtables::xx
  • Access to _mc_region is changed to the inline function mc_region()

Progress

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

Issue

  • JDK-8248186: Move CDS C++ vtable code to cppVtables.cpp

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/136/head:pull/136
$ git checkout pull/136

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 11, 2020

👋 Welcome back iklam! 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, 2020

@iklam The following labels will be automatically applied to this pull request: build hotspot.

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 (add|remove) "label" command.

@iklam
Copy link
Member Author

iklam commented Sep 11, 2020

/label remove build,hotspot

@openjdk
Copy link

openjdk bot commented Sep 11, 2020

@iklam
The build label was successfully removed.

The hotspot label was successfully removed.

@iklam
Copy link
Member Author

iklam commented Sep 11, 2020

/label add hotspot-runtime

@openjdk
Copy link

openjdk bot commented Sep 11, 2020

@iklam
The hotspot-runtime label was successfully added.

@iklam iklam marked this pull request as ready for review September 11, 2020 22:14
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 11, 2020
@mlbridge
Copy link

mlbridge bot commented Sep 11, 2020

Webrevs

#include "oops/instanceClassLoaderKlass.hpp"
#include "oops/instanceMirrorKlass.hpp"
#include "oops/instanceRefKlass.hpp"
#include "oops/methodData.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you check that you needed all of these #include files?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I started with no headers and kept adding until gcc stopped complaining. I was using a non-PCH build.

@openjdk
Copy link

openjdk bot commented Sep 11, 2020

@iklam This change now passes all automated pre-integration checks. In addition to the automated checks, the change must also fulfill all project specific requirements

After integration, the commit message will be:

8248186: Move CDS C++ vtable code to cppVtables.cpp

Reviewed-by: coleenp
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /issue command.

There are currently no new commits on the master branch since the last update of the source branch of this PR. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you would like to avoid potential automatic rebasing, specify the current head hash when integrating, like this: /integrate 03a4df0acd103702e52dcd01c3f03fda4d7b04f5.

➡️ 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 Sep 11, 2020
@iklam
Copy link
Member Author

iklam commented Sep 13, 2020

/integrate

@openjdk openjdk bot closed this Sep 13, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 13, 2020
@openjdk
Copy link

openjdk bot commented Sep 13, 2020

@iklam Pushed as commit c5e63b6.

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

robehn pushed a commit to robehn/jdk that referenced this pull request Nov 13, 2023
fg1417 added a commit to fg1417/jdk that referenced this pull request Jul 12, 2024
…g to pointer

In the cases like:
```
  UNSAFE.putLong(address + off1 + 1030, lseed);
  UNSAFE.putLong(address + 1023, lseed);
  UNSAFE.putLong(address + off2 + 1001, lseed);
```

Unsafe intrinsifies direct memory access using a long as
the base address, generating a `CastX2P` node converting
long to pointer in C2. Then we get optoassembly code like:
```
  ldr  R10, [R15, openjdk#120]    # int ! Field: address
  ldr  R11, [R16, openjdk#136]    # int ! Field: off1
  ldr  R12, [R16, openjdk#144]    # int ! Field: off2
  add  R11, R11, R10
  mov R11, R11    # long -> ptr
  add  R12, R12, R10
  mov R10, R10    # long -> ptr
  add R11, R11, openjdk#1030    # ptr
  str  R17, [R11]    # int
  add R10, R10, openjdk#1023    # ptr
  str  R17, [R10]    # int
  mov R10, R12    # long -> ptr
  add R10, R10, openjdk#1001    # ptr
  str  R17, [R10]    # int
```

In aarch64, the conversion from long to pointer could be
a nop but C2 doesn't know it. On the existing code, we
do nothing for `mov dst src` only when `dst` == `src` [1],
then we have assembly:
```
  ldr    x10, [x15,openjdk#120]
  ldp    x11, x12, [x16,openjdk#136]
  add    x11, x11, x10
  add    x12, x12, x10
  add    x11, x11, #0x406
  str    x17, [x11]
  add    x10, x10, #0x3ff
  str    x17, [x10]
  mov    x10, x12  <--- extra register copy
  add    x10, x10, #0x3e9
  str    x17, [x10]
```

There is still one extra register copy, which we're trying
to remove in this patch.

This patch folds `CastX2P` into memory operands by introducing
`indirectX2P` and `indOffX2P`. We also create a new opclass
`iRegPorL2P` to remove extra copies from `CastX2P` in pointer
addition.

Tier 1~3 passed on aarch64. No obvious change in size
of libjvm.so

[1] https://github.com/openjdk/jdk/blob/5c612c230b0a852aed5fd36e58b82ebf2e1838af/src/hotspot/cpu/aarch64/aarch64.ad#L7906
fg1417 added a commit to fg1417/jdk that referenced this pull request Jul 12, 2024
This patch forces `CastX2P` to be a two-address instruction,
so that C2 could allocate the same register for dst and
src. Then we can remove the instruction completely in the
assembly.

The motivation comes from some cast operations like `castPP`.
The difference for ADLC between `castPP` and `CastX2P` lies in
that `CastX2P` always has different types for dst and src.
We can force ADLC to generate an extra `two_adr()` for `CastX2P`
like it does automatically for `castPP`, which could tell register
allocator that the instruction needs the same register for dst
and src.

However, sometimes, RA and GCM in C2 can't work as we expected.

For example, we have Assembly on the existing code:
```
  ldp    x10, x11, [x17,openjdk#136]
  add    x10, x10, x15
  add    x11, x11, x10
  ldr    x12, [x17,openjdk#152]
  str    x16, [x10]
  add    x10, x12, x15
  str    x16, [x11]
  str    x16, [x10]
```

After applying the patch, the assembly is:
```
  ldr    x10, [x16,openjdk#136]  <--- 1
  add    x10, x10, x15
  ldr    x11, [x16,openjdk#144]  <--- 2
  mov    x13, x10         <--- 3
  str    x17, [x13]
  ldr    x12, [x16,openjdk#152]
  add    x10, x11, x10
  str    x17, [x10]
  add    x10, x12, x15
  str    x17, [x10]
```

C2 generate a totally extra mov, see 3, and we even lost the chance
to merge load pair, see 1 and 2. That's terrible.

Although this scenario would disappear after combining with
openjdk#20157, I'm
still not sure if this patch is worthwhile.
pfirmstone added a commit to pfirmstone/jdk-with-authorization that referenced this pull request Nov 18, 2024
pfirmstone added a commit to pfirmstone/jdk-with-authorization that referenced this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants