diff --git a/src/hotspot/share/cds/lambdaProxyClassDictionary.cpp b/src/hotspot/share/cds/lambdaProxyClassDictionary.cpp index 62b1b8c05f133..f6da1a34af377 100644 --- a/src/hotspot/share/cds/lambdaProxyClassDictionary.cpp +++ b/src/hotspot/share/cds/lambdaProxyClassDictionary.cpp @@ -518,7 +518,7 @@ void LambdaProxyClassDictionary::print_on(const char* prefix, if (!dictionary->empty()) { st->print_cr("%sShared Lambda Dictionary", prefix); SharedLambdaDictionaryPrinter ldp(st, start_index); - dictionary->iterate(&ldp); + dictionary->iterate_all(&ldp); } } diff --git a/src/hotspot/share/classfile/compactHashtable.hpp b/src/hotspot/share/classfile/compactHashtable.hpp index 402c8f197fa93..944fb876521ce 100644 --- a/src/hotspot/share/classfile/compactHashtable.hpp +++ b/src/hotspot/share/classfile/compactHashtable.hpp @@ -294,6 +294,7 @@ class CompactHashtable : public SimpleCompactHashtable { return nullptr; } + // Iterate through the values in the table, stopping when do_value() returns false. template inline void iterate(ITER* iter) const { iterate([&](V v) { iter->do_value(v); }); } @@ -302,6 +303,7 @@ class CompactHashtable : public SimpleCompactHashtable { iterate(const_cast(function)); } + // Iterate through the values in the table, stopping when the lambda returns false. template inline void iterate(Function& function) const { // lambda enabled API for (u4 i = 0; i < _bucket_count; i++) { @@ -311,17 +313,35 @@ class CompactHashtable : public SimpleCompactHashtable { u4* entry = _entries + bucket_offset; if (bucket_type == VALUE_ONLY_BUCKET_TYPE) { - function(decode(entry[0])); + if (!function(decode(entry[0]))) { + return; + } } else { u4* entry_max = _entries + BUCKET_OFFSET(_buckets[i + 1]); while (entry < entry_max) { - function(decode(entry[1])); + if (!function(decode(entry[1]))) { + return; + } entry += 2; } } } } + // Unconditionally iterate through all the values in the table + template + inline void iterate_all(ITER* iter) const { iterate_all([&](V v) { iter->do_value(v); }); } + + // Unconditionally iterate through all the values in the table using lambda + template + void iterate_all(Function function) const { // lambda enabled API + auto wrapper = [&] (V v) { + function(v); + return true; + }; + iterate(wrapper); + } + void print_table_statistics(outputStream* st, const char* name) { st->print_cr("%s statistics:", name); int total_entries = 0; diff --git a/src/hotspot/share/classfile/stringTable.cpp b/src/hotspot/share/classfile/stringTable.cpp index c6c1c7a31bdca..be41631a732cd 100644 --- a/src/hotspot/share/classfile/stringTable.cpp +++ b/src/hotspot/share/classfile/stringTable.cpp @@ -909,7 +909,7 @@ void StringTable::dump(outputStream* st, bool verbose) { st->print_cr("# Shared strings:"); st->print_cr("#----------------"); PrintSharedString pss(thr, st); - _shared_table.iterate(&pss); + _shared_table.iterate_all(&pss); } #endif } diff --git a/src/hotspot/share/classfile/symbolTable.cpp b/src/hotspot/share/classfile/symbolTable.cpp index 13320a30872f2..ec639a2b4d39d 100644 --- a/src/hotspot/share/classfile/symbolTable.cpp +++ b/src/hotspot/share/classfile/symbolTable.cpp @@ -272,9 +272,7 @@ class SharedSymbolIterator { void SymbolTable::symbols_do(SymbolClosure *cl) { assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint"); // all symbols from shared table - SharedSymbolIterator iter(cl); - _shared_table.iterate(&iter); - _dynamic_shared_table.iterate(&iter); + shared_symbols_do(cl); // all symbols from the dynamic table SymbolsDo sd(cl); @@ -284,8 +282,8 @@ void SymbolTable::symbols_do(SymbolClosure *cl) { // Call function for all symbols in shared table. Used by -XX:+PrintSharedArchiveAndExit void SymbolTable::shared_symbols_do(SymbolClosure *cl) { SharedSymbolIterator iter(cl); - _shared_table.iterate(&iter); - _dynamic_shared_table.iterate(&iter); + _shared_table.iterate_all(&iter); + _dynamic_shared_table.iterate_all(&iter); } Symbol* SymbolTable::lookup_dynamic(const char* name, @@ -669,14 +667,14 @@ void SymbolTable::dump(outputStream* st, bool verbose) { st->print_cr("# Shared symbols:"); st->print_cr("#----------------"); DumpSharedSymbol dss(st); - _shared_table.iterate(&dss); + _shared_table.iterate_all(&dss); } if (!_dynamic_shared_table.empty()) { st->print_cr("#------------------------"); st->print_cr("# Dynamic shared symbols:"); st->print_cr("#------------------------"); DumpSharedSymbol dss(st); - _dynamic_shared_table.iterate(&dss); + _dynamic_shared_table.iterate_all(&dss); } } } diff --git a/src/hotspot/share/classfile/systemDictionaryShared.cpp b/src/hotspot/share/classfile/systemDictionaryShared.cpp index cb2ae96348ead..afc190c36cf20 100644 --- a/src/hotspot/share/classfile/systemDictionaryShared.cpp +++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp @@ -1431,11 +1431,11 @@ const char* SystemDictionaryShared::loader_type_for_shared_class(Klass* k) { } void SystemDictionaryShared::get_all_archived_classes(bool is_static_archive, GrowableArray* classes) { - get_archive(is_static_archive)->_builtin_dictionary.iterate([&] (const RunTimeClassInfo* record) { + get_archive(is_static_archive)->_builtin_dictionary.iterate_all([&] (const RunTimeClassInfo* record) { classes->append(record->klass()); }); - get_archive(is_static_archive)->_unregistered_dictionary.iterate([&] (const RunTimeClassInfo* record) { + get_archive(is_static_archive)->_unregistered_dictionary.iterate_all([&] (const RunTimeClassInfo* record) { classes->append(record->klass()); }); } @@ -1464,9 +1464,9 @@ void SystemDictionaryShared::ArchiveInfo::print_on(const char* prefix, st->print_cr("%sShared Dictionary", prefix); SharedDictionaryPrinter p(st); st->print_cr("%sShared Builtin Dictionary", prefix); - _builtin_dictionary.iterate(&p); + _builtin_dictionary.iterate_all(&p); st->print_cr("%sShared Unregistered Dictionary", prefix); - _unregistered_dictionary.iterate(&p); + _unregistered_dictionary.iterate_all(&p); LambdaProxyClassDictionary::print_on(prefix, st, p.index(), is_static_archive); } diff --git a/src/hotspot/share/oops/trainingData.cpp b/src/hotspot/share/oops/trainingData.cpp index 27ae3404f4184..1a16fd70e446d 100644 --- a/src/hotspot/share/oops/trainingData.cpp +++ b/src/hotspot/share/oops/trainingData.cpp @@ -83,7 +83,7 @@ static void verify_archived_entry(TrainingData* td, const TrainingData::Key* k) void TrainingData::verify() { if (TrainingData::have_data() && !TrainingData::assembling_data()) { - archived_training_data_dictionary()->iterate([&](TrainingData* td) { + archived_training_data_dictionary()->iterate_all([&](TrainingData* td) { if (td->is_KlassTrainingData()) { KlassTrainingData* ktd = td->as_KlassTrainingData(); if (ktd->has_holder() && ktd->holder()->is_loaded()) { @@ -466,7 +466,7 @@ void TrainingData::init_dumptime_table(TRAPS) { precond((!assembling_data() && !need_data()) || need_data() != assembling_data()); if (assembling_data()) { _dumptime_training_data_dictionary = new DumptimeTrainingDataDictionary(); - _archived_training_data_dictionary.iterate([&](TrainingData* record) { + _archived_training_data_dictionary.iterate_all([&](TrainingData* record) { _dumptime_training_data_dictionary->append(record); }); } @@ -692,7 +692,7 @@ void TrainingData::print_archived_training_data_on(outputStream* st) { st->print_cr("Archived TrainingData Dictionary"); TrainingDataPrinter tdp(st); TrainingDataLocker::initialize(); - _archived_training_data_dictionary.iterate(&tdp); + _archived_training_data_dictionary.iterate_all(&tdp); } void TrainingData::Key::metaspace_pointers_do(MetaspaceClosure *iter) { diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index 8ede4d1082af1..835bbc0ae2f78 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -3036,7 +3036,7 @@ void AdapterHandlerLibrary::link_aot_adapters() { * result in collision of adapter ids between AOT stored handlers and runtime generated handlers. * To avoid such situation, initialize the _id_counter with the largest adapter id among the AOT stored handlers. */ - _aot_adapter_handler_table.iterate([&](AdapterHandlerEntry* entry) { + _aot_adapter_handler_table.iterate_all([&](AdapterHandlerEntry* entry) { assert(!entry->is_linked(), "AdapterHandlerEntry is already linked!"); entry->link(); max_id = MAX2(max_id, entry->id()); @@ -3388,19 +3388,37 @@ JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) ) FREE_C_HEAP_ARRAY(intptr_t, buf); JRT_END +const char* AdapterHandlerLibrary::name(AdapterHandlerEntry* handler) { + return handler->fingerprint()->as_basic_args_string(); +} + +uint32_t AdapterHandlerLibrary::id(AdapterHandlerEntry* handler) { + return handler->id(); +} + bool AdapterHandlerLibrary::contains(const CodeBlob* b) { bool found = false; #if INCLUDE_CDS if (AOTCodeCache::is_using_adapter()) { auto findblob_archived_table = [&] (AdapterHandlerEntry* handler) { - return (found = (b == CodeCache::find_blob(handler->get_i2c_entry()))); + if (b == CodeCache::find_blob(handler->get_i2c_entry())) { + found = true; + return false; // abort iteration + } else { + return true; // keep looking + } }; _aot_adapter_handler_table.iterate(findblob_archived_table); } #endif // INCLUDE_CDS if (!found) { - auto findblob_runtime_table = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) { - return (found = (b == CodeCache::find_blob(a->get_i2c_entry()))); + auto findblob_runtime_table = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* handler) { + if (b == CodeCache::find_blob(handler->get_i2c_entry())) { + found = true; + return false; // abort iteration + } else { + return true; // keep looking + } }; assert_locked_or_safepoint(AdapterHandlerLibrary_lock); _adapter_handler_table->iterate(findblob_runtime_table); @@ -3408,14 +3426,6 @@ bool AdapterHandlerLibrary::contains(const CodeBlob* b) { return found; } -const char* AdapterHandlerLibrary::name(AdapterHandlerEntry* handler) { - return handler->fingerprint()->as_basic_args_string(); -} - -uint32_t AdapterHandlerLibrary::id(AdapterHandlerEntry* handler) { - return handler->id(); -} - void AdapterHandlerLibrary::print_handler_on(outputStream* st, const CodeBlob* b) { bool found = false; #if INCLUDE_CDS @@ -3425,23 +3435,23 @@ void AdapterHandlerLibrary::print_handler_on(outputStream* st, const CodeBlob* b found = true; st->print("Adapter for signature: "); handler->print_adapter_on(st); - return true; + return false; // abort iteration } else { - return false; // keep looking + return true; // keep looking } }; _aot_adapter_handler_table.iterate(findblob_archived_table); } #endif // INCLUDE_CDS if (!found) { - auto findblob_runtime_table = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* a) { - if (b == CodeCache::find_blob(a->get_i2c_entry())) { + auto findblob_runtime_table = [&] (AdapterFingerPrint* key, AdapterHandlerEntry* handler) { + if (b == CodeCache::find_blob(handler->get_i2c_entry())) { found = true; st->print("Adapter for signature: "); - a->print_adapter_on(st); - return true; + handler->print_adapter_on(st); + return false; // abort iteration } else { - return false; // keep looking + return true; // keep looking } }; assert_locked_or_safepoint(AdapterHandlerLibrary_lock);