RFR: 8271525: ResourceHashtableBase::iterate() should not declared as const

Coleen Phillimore coleenp at openjdk.java.net
Fri Jul 30 14:36:43 UTC 2021


On Fri, 30 Jul 2021 04:16:59 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> `ResourceHashtableBase::iterate()` is declared `const`, but it can actually change the contents of the table. The same is true for `ResourceHashtableBase::get()`, which returns a non-`const` pointer to the value, allowing the caller to modify it.
> 
> We should declare these two functions as non-`const`. This will also remove a lot of ugly `const_cast<>` code.
> 
> The `iterate()` API is tightened such that the `do_entry()` function can modify the `value` but not the `key`.

src/hotspot/share/utilities/resourceHash.hpp line 204:

> 202:       Node* node = *bucket;
> 203:       while (node != NULL) {
> 204:         bool cont = iter->do_entry(const_cast<K const&>(node->_key), node->_value);

It seems to me that iterate should be const because it doesn't change the table.  Whether or not it changes the pointers in the Nodes is not part of the contract, since they could have been declared non-const.

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

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


More information about the hotspot-dev mailing list