Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8292202: modules_do is called without Module_lock
Reviewed-by: iklam, coleenp
  • Loading branch information
calvinccheung committed Sep 22, 2022
1 parent 742bc04 commit 47f233a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/hotspot/share/classfile/classLoaderExt.cpp
Expand Up @@ -82,20 +82,34 @@ void ClassLoaderExt::setup_app_search_path(JavaThread* current) {

void ClassLoaderExt::process_module_table(JavaThread* current, ModuleEntryTable* met) {
ResourceMark rm(current);
class Process : public ModuleClosure {
GrowableArray<char*>* module_paths = new GrowableArray<char*>(5);

class ModulePathsGatherer : public ModuleClosure {
JavaThread* _current;
GrowableArray<char*>* _module_paths;
public:
Process(JavaThread* current) : _current(current) {}
ModulePathsGatherer(JavaThread* current, GrowableArray<char*>* module_paths) :
_current(current), _module_paths(module_paths) {}
void do_module(ModuleEntry* m) {
char* path = m->location()->as_C_string();
if (strncmp(path, "file:", 5) == 0) {
path = ClassLoader::skip_uri_protocol(path);
ClassLoader::setup_module_search_path(_current, path);
char* path_copy = NEW_RESOURCE_ARRAY(char, strlen(path) + 1);
strcpy(path_copy, path);
_module_paths->append(path_copy);
}
}
};
Process process(current);
met->modules_do(&process);

ModulePathsGatherer gatherer(current, module_paths);
{
MutexLocker ml(Module_lock);
met->modules_do(&gatherer);
}

for (int i = 0; i < module_paths->length(); i++) {
ClassLoader::setup_module_search_path(current, module_paths->at(i));
}
}

void ClassLoaderExt::setup_module_paths(JavaThread* current) {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/moduleEntry.cpp
Expand Up @@ -694,13 +694,15 @@ void ModuleEntryTable::modules_do(void f(ModuleEntry*)) {
auto do_f = [&] (const SymbolHandle& key, ModuleEntry*& entry) {
f(entry);
};
assert_lock_strong(Module_lock);
_table.iterate_all(do_f);
}

void ModuleEntryTable::modules_do(ModuleClosure* closure) {
auto do_f = [&] (const SymbolHandle& key, ModuleEntry*& entry) {
closure->do_module(entry);
};
assert_lock_strong(Module_lock);
_table.iterate_all(do_f);
}

Expand Down

0 comments on commit 47f233a

Please sign in to comment.