RFR: 8271506: Add ResourceHashtable support for deleting selected entries

Ioi Lam iklam at openjdk.java.net
Fri Jul 30 04:32:30 UTC 2021


On Thu, 29 Jul 2021 21:00:06 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

> The ResourceHashtable doesn't have a way to delete selected entries based on things like their class has been unloaded, which is needed to replace Hashtable with ResourceHashtable.
> The Nodes of the ResourceHashtable has a Key and Value of  template types.
> template<typename K, typename V>
> class ResourceHashtableNode : public ResourceObj {
> public:
>   unsigned _hash;
>   K _key;
>   V _value;
> ...
> But there's no destructor so that ~K and ~V are not called (if I understand C++ correctly).
> 
> When instantiated with a value that's not a pointer, calling code does this:
> 
>   SourceObjInfo src_info(ref, read_only, follow_mode);
>   bool created;
>   SourceObjInfo* p = _src_obj_table.put_if_absent(src_obj, src_info, &created);
> 
> So if SourceObjInfo has a destructor, it'll have to have a careful assignment operator so that the value copied into the hashtable doesn't get deleted.
> 
> In this patch, I assign the responsibility of deleting the Key and Value of the hashtable to the do_entry function, because it's simple.  If we want to use more advanced unreadable C++ code, someone will have to suggest an alternate set of changes, because my C++ is not up to this.
> 
> Tested with tier1-3, gtest, and upcoming patch for JDK-8048190.

Changes requested by iklam (Reviewer).

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

> 217:   // the entry is deleted.
> 218:   template<class ITER>
> 219:   void unlink(ITER* iter) const {

`unlink()` shouldn't be `const` as it modifies the table. However, you probably needed to declare it as such because it calls `bucket_at()`, which is `const`. And the reason that  `bucket_at()` is `const` is because it's called by `iterate()`, which is `const`.

The use of `const` and `const_cast` in this class is getting a bit out of whack. I have created [JDK-8271525](https://bugs.openjdk.java.net/browse/JDK-8271525) with a preliminary fix here: https://github.com/openjdk/jdk/pull/4942

Maybe we should do that before this PR? it will also make the `const_cast` unnecessary for `decrement_entries()`.

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

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


More information about the hotspot-dev mailing list