Skip to content

Conversation

@coleenp
Copy link
Contributor

@coleenp coleenp commented Dec 9, 2024

The Class.getModifiers() method is implemented as a native method in java.lang.Class to access a field that we've calculated when creating the mirror. The field is final after that point. The VM doesn't need it anymore, so there's no real need for the jdk code to call into the VM to get it. This moves the field to Java and removes the intrinsic code. I promoted the compute_modifiers() functions to return int since that's how java.lang.Class uses the value. It should really be an unsigned short though.

There's a couple of JMH benchmarks added with this change. One does show that for array classes for non-bootstrap class loader, this results in one extra load which in a long loop of just that, is observable. I don't think this is real life code. The other benchmarks added show no regression.

Tested with tier1-8.


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-8346567: Make Class.getModifiers() non-native (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22652

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 9, 2024

👋 Welcome back coleenp! 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 9, 2024

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

8346567: Make Class.getModifiers() non-native

Reviewed-by: alanb, vlivanov, yzheng, 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 98 new commits pushed to the master branch:

  • 8f6ccde: 8349554: [UBSAN] os::attempt_reserve_memory_between reported applying non-zero offset to non-null pointer produced null pointer
  • 7d52f1e: 8349525: RBTree: provide leftmost, rightmost, and a simple way to print trees
  • e9278de: 8348411: C2: Remove the control input of LoadKlassNode and LoadNKlassNode
  • 5395ffa: 8327378: XMLStreamReader throws EOFException instead of XMLStreamException
  • 1ed9ef1: 8349559: Compiler interface doesn't need to store protection domain
  • f0ea38b: 8349509: [macos] Clean up macOS dead code in jpackage
  • 7f6c687: 8349374: [JVMCI] concurrent use of HotSpotSpeculationLog can crash
  • bd9b24c: 8349512: Duplicate PermittedSubclasses entries with doclint enabled
  • b40f8ee: 8337251: C1: Improve Class.isInstance intrinsic
  • 88a8483: 8349121: SSLParameters.setApplicationProtocols() ALPN example could be clarified
  • ... and 88 more: https://git.openjdk.org/jdk/compare/f05c53c2c4adec4c4e875d8b84ec7682bbe356f8...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
Copy link

openjdk bot commented Dec 9, 2024

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

  • core-libs
  • graal
  • hotspot
  • serviceability

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 graal graal-dev@openjdk.org serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Dec 9, 2024
Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

The change to java.lang.Class looks good.

@openjdk
Copy link

openjdk bot commented Dec 16, 2024

@coleenp this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout modifiers2
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed merge-conflict Pull request has merge conflict with target branch labels Dec 16, 2024
@coleenp coleenp changed the title 8345678: Make Class.getModifiers() non-native. 8346567: Make Class.getModifiers() non-native Dec 18, 2024
@coleenp coleenp marked this pull request as ready for review February 3, 2025 17:41
@coleenp
Copy link
Contributor Author

coleenp commented Feb 3, 2025

/assign @iwanowww

@liach
Copy link
Member

liach commented Feb 3, 2025

Looking at #23396, we might need to filter this field too.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 3, 2025
@openjdk
Copy link

openjdk bot commented Feb 3, 2025

@coleenp Unknown command assign - for a list of valid commands use /help.

@coleenp
Copy link
Contributor Author

coleenp commented Feb 3, 2025

Looking at #23396, we might need to filter this field too.

Yes, I agree. This patch is a follow on to that one, so I'll add it to the same places when that one is merged in here.

@mlbridge
Copy link

mlbridge bot commented Feb 3, 2025

Copy link
Member

@dean-long dean-long left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Please ask @iwanowww to review compiler changes.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 5, 2025
Copy link
Contributor Author

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

Thank you for the detailed comments.

writer->write(mark_symbol(klass, leakp));
writer->write(package_id(klass, leakp));
writer->write(klass->modifier_flags());
writer->write(klass->compute_modifier_flags());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying not to add a Klass::modifier_flags function, but now I have.

print(" unloaded='1'");
} else {
print(" flags='%d'", klass->modifier_flags());
print(" flags='%d'", klass->access_flags());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I wanted to remove the one use of ciKlass::modifier_flags() and the field with this change, but I'll add it back since I added a Klass::modifier_flags() function.

@Benchmark
public int getAppArrayModifiers() {
return clazzArray.getClass().getModifiers();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Yes it does.

Co-authored-by: Dean Long <17332032+dean-long@users.noreply.github.com>
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 6, 2025
Copy link
Contributor

@iwanowww iwanowww 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. (Except a left-over ??? in a comment.)

I very much like this cleanup. Migrating from Klass to Class simplifies compiler logic since there's no need to care about primitives at runtime anymore.

Speaking of missing optimization opportunities (demonstrated by one microbenchmark), it looks like a corner case and can be addressed later.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 6, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 6, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Feb 6, 2025

Thank you Vladimir for encouraging me to continue this change. I removed the ??? and hid the modifiers field for reflection as suggested in this PR.

@coleenp
Copy link
Contributor Author

coleenp commented Feb 7, 2025

I added some code to hide the Class.modifiers field and fixed the JVMCI test. Please re-review.

Also @iwanowww I think the intrinsic for isInterface can be removed and just be Java code like:

public boolean isInterface()  {
  return getModifiers().isInterface();
}

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 7, 2025
@iwanowww
Copy link
Contributor

iwanowww commented Feb 7, 2025

I think the intrinsic for isInterface can be removed

Good point. Moreover, it seems most of intrinsics on Class queries can be replaced with a flag bit check on the mirror. (Do we have 16 unused bits in Class::modifiers after this change?)

@coleenp
Copy link
Contributor Author

coleenp commented Feb 7, 2025

Good point. Moreover, it seems most of intrinsics on Class queries can be replaced with a flag bit check on the mirror. (Do we have 16 unused bits in Class::modifiers after this change?)

Yes, I think so. isArray and isPrimitive definitely. We could first change the modifiers field to "char" because that's its size and then have a booleans for each of these.

@liach
Copy link
Member

liach commented Feb 7, 2025

Making isArray and isPrimitive Java-based is going to be helpful for the interpreter performance of these methods in early bootstrap. 👍

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

No more comments from me.

Copy link
Contributor

@mur47x111 mur47x111 left a comment

Choose a reason for hiding this comment

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

JVMCI change looks good to me

@coleenp
Copy link
Contributor Author

coleenp commented Feb 10, 2025

Thank you for the reviews Yudi, Alan, Chen, Vladimir and Dean, and the help and comments with the various pieces of this.
/integrate

@openjdk
Copy link

openjdk bot commented Feb 10, 2025

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

  • 5589892: 8343074: test/jdk/com/sun/net/httpserver/docs/test1/largefile.txt could be generated
  • d104deb: 8349556: RISC-V: improve the performance when -COH and -AvoidUnalignedAccesses for UL and LU string comparison
  • 4a83ca1: 8349666: RISC-V: enable superwords tests for vector reductions
  • 8f6ccde: 8349554: [UBSAN] os::attempt_reserve_memory_between reported applying non-zero offset to non-null pointer produced null pointer
  • 7d52f1e: 8349525: RBTree: provide leftmost, rightmost, and a simple way to print trees
  • e9278de: 8348411: C2: Remove the control input of LoadKlassNode and LoadNKlassNode
  • 5395ffa: 8327378: XMLStreamReader throws EOFException instead of XMLStreamException
  • 1ed9ef1: 8349559: Compiler interface doesn't need to store protection domain
  • f0ea38b: 8349509: [macos] Clean up macOS dead code in jpackage
  • 7f6c687: 8349374: [JVMCI] concurrent use of HotSpotSpeculationLog can crash
  • ... and 91 more: https://git.openjdk.org/jdk/compare/f05c53c2c4adec4c4e875d8b84ec7682bbe356f8...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 10, 2025

@coleenp Pushed as commit c9cadbd.

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

@coleenp coleenp deleted the modifiers2 branch February 10, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

9 participants