RFR: 8253640: Make MEMFLAGS an enum class

Stefan Karlsson stefank at openjdk.java.net
Mon Sep 28 12:24:55 UTC 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.

-------------

Commit messages:
 - 8253640: Make MEMFLAGS an enum class

Changes: https://git.openjdk.java.net/jdk/pull/378/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=378&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8253640
  Stats: 51 lines in 8 files changed: 17 ins; 13 del; 21 mod
  Patch: https://git.openjdk.java.net/jdk/pull/378.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/378/head:pull/378

PR: https://git.openjdk.java.net/jdk/pull/378


More information about the hotspot-dev mailing list