RFR: 8253640: Make MEMFLAGS an enum class [v2]
Stefan Karlsson
stefank at openjdk.java.net
Mon Sep 28 13:00:10 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.
Stefan Karlsson has updated the pull request incrementally with one additional commit since the last revision:
Review 1
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/378/files
- new: https://git.openjdk.java.net/jdk/pull/378/files/24cb2fb8..3f225acd
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=378&range=01
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=378&range=00-01
Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 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