8292202: modules_do is called without Module_lock

Reviewed-by: iklam, coleenp
This commit is contained in:
Calvin Cheung 2022-09-22 03:37:23 +00:00
parent 742bc041ea
commit 47f233acec
2 changed files with 21 additions and 5 deletions
src/hotspot/share/classfile

@ -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) {

@ -694,6 +694,7 @@ 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);
}
@ -701,6 +702,7 @@ 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);
}