RFR: 8271506: Add ResourceHashtable support for deleting selected entries [v2]

Thomas Stuefe stuefe at openjdk.java.net
Mon Aug 2 18:49:35 UTC 2021


On Fri, 30 Jul 2021 13:42:53 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.
>
> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Make unlink non-const because it's not.

Hi Coleen, 

looks good to me. One minor remark, but I leave it up to you, this is good as it is.

Thanks, Thomas

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

> 228:         Node* node = *ptr;
> 229:         // do_entry must clean up the key and value in Node.
> 230:         bool clean = iter->do_entry(node->_key, node->_value);

Unless I miss it, you don't enforce the constness here, no? So, nothing prevents the called hook from modifying key or value. You may do what Ioi did in https://github.com/openjdk/jdk/pull/4942 and const-cast the parameters for the call.

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

Marked as reviewed by stuefe (Reviewer).

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


More information about the hotspot-dev mailing list