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

8339113: AccessFlags can be u2 in metadata #22246

Closed
wants to merge 18 commits into from

Conversation

coleenp
Copy link
Contributor

@coleenp coleenp commented Nov 19, 2024

Please review this change that makes AccessFlags and modifier_flags u2 types and removes the last remnants of Hotspot adding internal access flags. This change moves AccessFlags and modifier_flags in Klass to alignment gaps saving 16 bytes. From pahole: so it's a bit better.

before:

        /* size: 216, cachelines: 4, members: 25, static members: 17 */
        /* sum members: 194, holes: 3, sum holes: 18 */

after:

        /* size: 200, cachelines: 4, members: 25, static members: 17 */
        /* sum members: 188, holes: 4, sum holes: 12 */

We may eventually move the modifiers to java.lang.Class but that's WIP.

Tested with tier1-7 on oracle platforms. Did test builds on other platforms (please try these changes ppc/arm32 and s390). Also requires minor Graal changes.


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-8339113: AccessFlags can be u2 in metadata (Enhancement - P4)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22246

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 19, 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 Nov 19, 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:

8339113: AccessFlags can be u2 in metadata

Co-authored-by: Amit Kumar <[email protected]>
Reviewed-by: sspitsyn, vlivanov, yzheng, dlong, dholmes

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

  • e413fc6: 8347127: CTW fails to build after JDK-8334733
  • 9702acc: 8175709: DateTimeFormatterBuilder.appendZoneId() has misleading JavaDoc
  • 030149f: 8334644: Automate javax/print/attribute/PageRangesException.java
  • c8a9dd3: 8346609: Improve MemorySegment.toString
  • 4d8fb80: 8347038: [JMH] jdk.incubator.vector.SpiltReplicate fails NoClassDefFoundError
  • cf3e48e: 8346965: Multiple compiler/ciReplay test fails with -XX:+SegmentedCodeCache
  • e5f0c19: 8345041: IGV: Free Placement Mode in IGV Layout
  • 8b22517: 8211851: (ch) java/nio/channels/AsynchronousSocketChannel/StressLoopback.java times out (aix)
  • 5e6cda4: 8347000: Bug in com/sun/net/httpserver/bugs/B6361557.java test
  • 3f7052e: 8346868: RISC-V: compiler/sharedstubs tests fail after JDK-8332689
  • ... and 57 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
Copy link

openjdk bot commented Nov 19, 2024

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

  • 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.

@coleenp coleenp marked this pull request as ready for review December 17, 2024 21:24
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 17, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 17, 2024

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 17, 2024

@coleenp This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@coleenp
Copy link
Contributor Author

coleenp commented Dec 18, 2024

No, bot, this is a new PR.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Okay in principle but use of as_int() is very confusing.

@coleenp
Copy link
Contributor Author

coleenp commented Dec 19, 2024

The as_int() was because we are using the AccessFlags as an integral value. I was trying to minimize the effects of the change and the code uses AccessFlags as an integral value. as_int() returns u2 so I guess that's confusing. I don't want AccessFlags::get_flags() because that's implies the return is AccessFlags. I could change the name to as_unsigned_short(). Would that be less confusing?

Thank you David for looking through this change.

…method, field and class modifiers into AccessFlags. Change ciFlags to use AccessFlags.
@dholmes-ora
Copy link
Member

I could change the name to as_unsigned_short(). Would that be less confusing?

How about as_u2() as that is what it is? (less typing :) ).

@coleenp
Copy link
Contributor Author

coleenp commented Dec 19, 2024

I didn't really like that name since it's the name of the type rather than more of a description of the type returned. I was able to reduce the number of these by adding some helper functions in AccessFlags.

@dholmes-ora
Copy link
Member

Things become somewhat clearer once one realizes/recalls that AccessFlags do not specifically pertain to access, but to all class/method modifiers as per the various JVMS ACC_XXX constants. We need to restore the leading comment in accessFlags.hpp to read

// AccessFlags is an abstraction over Java ACC flags.

as it originally did.

@offamitkumar
Copy link
Member

Thanks for adding the patch Coleen :-)

I did another test-run and s390x looks fine now.

Copy link
Contributor

@sspitsyn sspitsyn 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 update with this an unification!
I've posted a couple of comments with similar nits.

return TypeInt::make(klass->modifier_flags());
}
if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
// The field is Klass::_access_flags. Return its (constant) value.
// (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
assert(this->Opcode() == Op_LoadI, "must load an int from _access_flags");
assert(this->Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This can be unified with line 1979 and also get rid of this->.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1979 and 1985 are in different branches of an if statement (address of modifier flags vs access flags) so needs to be repeated. But I did remove the this->

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

I can't say that I really understand which API's are fine with flags-as-int and which need to care about the actual flag storage size. but I'll leave it at that. I will tick approve for the shared code portion of the change.

Thanks

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

coleenp commented Jan 7, 2025

Thanks David. I'm hoping @iwanowww or @dean-long can review the compiler parts.

@dean-long
Copy link
Member

Sure, I'll try to take a look at it tomorrow.

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 7, 2025
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 changes look good to me!

Copy link
Contributor

@sspitsyn sspitsyn 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 one more unification update! Looks good.

@@ -36,31 +36,31 @@
#include "utilities/tribool.hpp"

// These are flag-matching functions:
inline bool match_F_R(jshort flags) {
inline bool match_F_R(u2 flags) {
Copy link
Member

Choose a reason for hiding this comment

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

I wish more code could be size-agnostic. So instead of using u2 here, there could be a typedef in accessFlags.hpp that we could use that hides the size. However, it's not a big deal, because it seems unlikely this type will change much in the future without a JVM spec change. I'm tempted to suggesting using AccessFlags here, but it's a class. Since this is an end-point "consumer" of the type that doesn't store it or pass it along, we could even use something like uint here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like a good idea if this weren't so limited. I did chat with DanH. to see if access flags will ever grow in size from u2 and he was doubtful that would ever happen. uint would work here too, but this small use might prevent some future -Wconversion warnings and doesn't hurt anything.
Thank you for reviewing.

@coleenp
Copy link
Contributor Author

coleenp commented Jan 7, 2025

IMO you could just call as_int() here. All other usages of ciFlags::as_int() are in printing code.
Ideally, ciField::print() could use ciFlags::print(), but such cleanup can be done separately.

This does seem like a good future cleanup. Thanks for reviewing Vladimir.

@coleenp
Copy link
Contributor Author

coleenp commented Jan 7, 2025

Thanks for reviewing David, Yudi and Serguei. I reran tiers 1-7 on this change.
/integrate

@openjdk
Copy link

openjdk bot commented Jan 7, 2025

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

  • e413fc6: 8347127: CTW fails to build after JDK-8334733
  • 9702acc: 8175709: DateTimeFormatterBuilder.appendZoneId() has misleading JavaDoc
  • 030149f: 8334644: Automate javax/print/attribute/PageRangesException.java
  • c8a9dd3: 8346609: Improve MemorySegment.toString
  • 4d8fb80: 8347038: [JMH] jdk.incubator.vector.SpiltReplicate fails NoClassDefFoundError
  • cf3e48e: 8346965: Multiple compiler/ciReplay test fails with -XX:+SegmentedCodeCache
  • e5f0c19: 8345041: IGV: Free Placement Mode in IGV Layout
  • 8b22517: 8211851: (ch) java/nio/channels/AsynchronousSocketChannel/StressLoopback.java times out (aix)
  • 5e6cda4: 8347000: Bug in com/sun/net/httpserver/bugs/B6361557.java test
  • 3f7052e: 8346868: RISC-V: compiler/sharedstubs tests fail after JDK-8332689
  • ... and 57 more: https://git.openjdk.org/jdk/compare/4d77dbad4e15c5392878e7bc91cd8eb7ce49a482...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 7, 2025

@coleenp Pushed as commit 098afc8.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

9 participants