Skip to content

Commit d70f103

Browse files
committed
synchronize on module entry
1 parent 2808f36 commit d70f103

File tree

1 file changed

+11
-5
lines changed
  • espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime

1 file changed

+11
-5
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/JavaAgents.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,18 @@ public boolean shouldEnableRedefinition() {
412412
return false;
413413
}
414414

415-
public synchronized void grantReadAccessToUnnamedModules(ModuleTable.ModuleEntry module) {
415+
public void grantReadAccessToUnnamedModules(ModuleTable.ModuleEntry module) {
416416
if (module != null && module.isNamed() && !module.hasDefaultReads()) {
417-
getContext().getMeta().jdk_internal_module_Modules_transformedByAgent.invokeDirect(module.module());
418-
// no reason to call into guest for a module more than once,
419-
// so flip the hasDefaultReads flag
420-
module.setHasDefaultReads();
417+
synchronized (module) {
418+
if (module.hasDefaultReads()) {
419+
// we lost the race, so nothing to do
420+
return;
421+
}
422+
getContext().getMeta().jdk_internal_module_Modules_transformedByAgent.invokeDirect(module.module());
423+
// no reason to call into guest for a module more than once,
424+
// so flip the hasDefaultReads flag
425+
module.setHasDefaultReads();
426+
}
421427
}
422428
}
423429

0 commit comments

Comments
 (0)