--- old/src/hotspot/share/utilities/hashtable.hpp 2020-07-31 23:33:56.568134877 -0700 +++ new/src/hotspot/share/utilities/hashtable.hpp 2020-07-31 23:33:56.376127650 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -301,13 +301,14 @@ public: KVHashtable(int table_size) : BasicHashtable(table_size, sizeof(KVHashtableEntry)) {} - void add(K key, V value) { + V* add(K key, V value) { unsigned int hash = HASH(key); KVHashtableEntry* entry = new_entry(hash, key, value); BasicHashtable::add_entry(BasicHashtable::hash_to_index(hash), entry); + return &(entry->_value); } - V* lookup(K key) { + V* lookup(K key) const { unsigned int hash = HASH(key); int index = BasicHashtable::hash_to_index(hash); for (KVHashtableEntry* e = bucket(index); e != NULL; e = e->next()) { @@ -317,6 +318,23 @@ } return NULL; } + + int table_size() const { + return BasicHashtable::table_size(); + } + + // ITER contains bool do_entry(K, V const&), which will be + // called for each entry in the table. If do_entry() returns false, + // the iteration is cancelled. + template + void iterate(ITER* iter) const { + for (int index = 0; index < table_size(); index++) { + for (KVHashtableEntry* e = bucket(index); e != NULL; e = e->next()) { + bool cont = iter->do_entry(e->_key, &e->_value); + if (!cont) { return; } + } + } + } };