Skip to content

8253640: Make MEMFLAGS an enum class #378

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

Conversation

stefank
Copy link
Member

@stefank stefank commented Sep 28, 2020

I'd like to propose that we make MEMFLAGS an enum class, to prevent them from being implicitly converted to integers.

I've been refactoring code that uses MEMFLAGS and have found that the functions often take integers and/or use default values. Because of this the compiler won't always tell you if you mess up the order. If we make the MEMFLAGS more type safe, the compiler will complain immediately if you send in the arguments in the wrong order.

Changes in the patch:

  1. G1 is the only code that uses MemoryType instead of the MEMFLAGS typedef. I changed those to make the code base uniform w.r.t. this.
  2. Added some code generation so that we still can use mtGC, and don't have to write MEMFLAGS::mtGC.
  3. Some stricter checks around the values stored in MEMFLAGS variables. There was a masking of 0xFF that I removed in favor of an assert. Need to run some more extensive testing see if there was a need for this masking.
  4. Removed unused by_index

Notes:

  1. I didn't specify the underlying type of the enum, but it's clear for its usage that code will start to break if the value range is larger than 8 bits. Maybe something to clean up in a separate patch?
  2. The code sometimes talks about "flags" and sometimes about "memory type", it's quite clear that the name changed, but the comments and names didn't get cleaned up accordingly.

Progress

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

Issue

Reviewers

Download

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 28, 2020

👋 Welcome back stefank! 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 Pull request is ready for review label Sep 28, 2020
@openjdk
Copy link

openjdk bot commented Sep 28, 2020

@stefank The following label will be automatically applied to this pull request:

  • hotspot

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 hotspot hotspot-dev@openjdk.org label Sep 28, 2020
@mlbridge
Copy link

mlbridge bot commented Sep 28, 2020

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Hi Stefan,

I was just looking this morning at this enum and wished it were a class. This will make reworking the reservation APIs less error prone.

Found some small nits, but leave it up to you if you change anything.

(For some reason I always believed that using enum class would prevent us from using sentinel values but for the life of me I cannot remember why I thought this...)

Thanks, Thomas

return index >= 0 && index < mt_number_of_types;
}

// Check if flag value is a valid MEMFLAGS enum value
Copy link
Member

Choose a reason for hiding this comment

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

Small nit, can you please clarify that this includes "mtNone"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

@@ -151,14 +151,20 @@ class AllocatedObj {
/*
* Memory types
*/
enum MemoryType {
enum class MEMFLAGS {
Copy link
Member

Choose a reason for hiding this comment

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

Remark (possible for a later change): As you wrote, I think using uint8 would be okay and safer here.

@openjdk
Copy link

openjdk bot commented Sep 28, 2020

@stefank 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 more details.

After integration, the commit message for the final commit will be:

8253640: Make MEMFLAGS an enum class

Reviewed-by: stuefe, tschatzl

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

  • 16b8c39: 8253053: Javadoc clean up in Authenticator and BasicAuthenicator
  • 840aa2b: 8253424: Add support for running pre-submit testing using GitHub Actions
  • 8e87d46: 8252857: AArch64: Shenandoah C1 CAS is not sequentially consistent
  • c2692f8: 8225329: -XX:+PrintBiasedLockingStatistics causes crash during initia…
  • e9c1782: 8252752: Clear card table for old regions during scan in G1

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 Pull request is ready to be integrated label Sep 28, 2020
Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

lgtm

@stefank
Copy link
Member Author

stefank commented Sep 28, 2020

Thanks!

Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

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

Lgtm.

@stefank
Copy link
Member Author

stefank commented Sep 29, 2020

Thanks, Thomas!

@stefank
Copy link
Member Author

stefank commented Sep 29, 2020

/integrate

@openjdk openjdk bot closed this Sep 29, 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 29, 2020
@openjdk
Copy link

openjdk bot commented Sep 29, 2020

@stefank Since your change was applied there have been 24 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit 3ed960e.

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

@stefank stefank deleted the 8253640_make_memflags_an_enum_class branch September 29, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants