RFR: 8262328: Templatize JVMFlag boilerplate access methods [v2]
Ioi Lam
iklam at openjdk.java.net
Tue Apr 6 04:18:27 UTC 2021
On Tue, 6 Apr 2021 02:20:54 GMT, David Holmes <dholmes at openjdk.org> wrote:
> Hi Ioi,
>
> In terms of readability and writeability I prefer <type>AtPut() over set<JVM_FLAG_TYPE(type)>(). Is there any way to push the JVM_FLAG_TYPE down a level so it doesn't shout at you when reading the code? set<type>() would look much much better.
>
> Thanks,
> David
I added the `JVMFlagAccess::set_<type>()` functions back (they are the same as the old `<type>AtPut` functions, but with a more consistent naming style).
Now I use the more low-level `set<JVM_FLAG_TYPE(type)>()` only in templates where the type is not statically known. E.g, `WriteableFlags::set_flag_impl()`.
* * *
A related note: in an [earlier version](https://webrevs.openjdk.java.net/?repo=jdk&pr=3318&range=00), I tried to get rid of the `<JVM_FLAG_TYPE(type)>` altogether, where the code is much cleaner with template type inference.
JVMFlag* flag = someSizetFlag;
size_t s = 0;
JVMFlagAccess::set(flag, &s, origin);
However, this may allow type mismatch like the following, on platforms that use the exact same type for `size_t` and `uint`:
JVMFlag* flag = someSizetFlag;
uint s = 0;
JVMFlagAccess::set(flag, &s, origin);
but you will get a runtime failure on platforms where `size_t` is not the same as `uint`. So I decided against this design due to non-portability.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3318
More information about the hotspot-dev
mailing list