Integrated: 8253640: Make MEMFLAGS an enum class
Stefan Karlsson
stefank at openjdk.java.net
Tue Sep 29 12:05:57 UTC 2020
On Mon, 28 Sep 2020 11:49:37 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: 3ed960ec
Author: Stefan Karlsson <stefank at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/3ed960ec
Stats: 51 lines in 8 files changed: 17 ins; 13 del; 21 mod
8253640: Make MEMFLAGS an enum class
Reviewed-by: stuefe, tschatzl
-------------
PR: https://git.openjdk.java.net/jdk/pull/378
More information about the hotspot-dev
mailing list