On Fri, 30 Jul 2021 04:03:57 GMT, Kim Barrett <kbarr...@openjdk.org> wrote:

>> src/hotspot/share/services/nmtPreInit.hpp line 128:
>> 
>>> 126:   // Returns start of the user data area
>>> 127:   void* payload()             { return this + 1; }
>>> 128:   const void* payload() const { return this + 1; }
>> 
>> This is an odd looking overload (that I wouldn't have thought possible).  
>> Maybe one of these payloads can be renamed to why it's const.
>
> [Not a review, just a drive-by comment.]  This is a normal and idiomatic 
> overload on the const-ness of `this`.

To expand on Kim's answer. This is a way to solve const/nonconst problems like 
https://github.com/openjdk/jdk/pull/4938/files#r679639391. 

You get a const version (suitably returning a write-protected pointer) which 
the compiler chooses in const code, and a non-const version for non-const code, 
and no awkward const-casts are needed from the outside.

In this case the implementation is simple enough that I just duplicated it; 
were it more complex, I'd call one in terms of the other. We do this in other 
places too, see e.g. `ResourceHashTable::lookup_node`.

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

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

Reply via email to