Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/share/cds/lambdaProxyClassDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
24 changes: 22 additions & 2 deletions src/hotspot/share/classfile/compactHashtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class CompactHashtable : public SimpleCompactHashtable {
return nullptr;
}

// Iterate through the values in the table, stopping when do_value() return false.
template <class ITER>
inline void iterate(ITER* iter) const { iterate([&](V v) { iter->do_value(v); }); }

Expand All @@ -302,6 +303,7 @@ class CompactHashtable : public SimpleCompactHashtable {
iterate(const_cast<Function&>(function));
}

// Iterate through the values in the table, stopping when the lambda return false.
template<typename Function>
inline void iterate(Function& function) const { // lambda enabled API
for (u4 i = 0; i < _bucket_count; i++) {
Expand All @@ -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 <class ITER>
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<typename Function>
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;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/stringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 5 additions & 7 deletions src/hotspot/share/classfile/symbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/classfile/systemDictionaryShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Klass*>* 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());
});
}
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/oops/trainingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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) {
Expand Down
48 changes: 29 additions & 19 deletions src/hotspot/share/runtime/sharedRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -3388,34 +3388,44 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pass AdapterFingerPrint* key argument which is not used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the function passed to HashTable::iterate is called with both key and value:

bool cont = function(node->_key, node->_value);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this.

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);
}
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
Expand All @@ -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);
Expand Down