Skip to content

Commit 927f343

Browse files
committed
Make newMethodsVersion() thread-safe
* So it's correct if another Thread concurrently inserts an InternalMethod with a different CallTarget.
1 parent 0bdcaed commit 927f343

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/org/truffleruby/core/module/ModuleFields.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,16 @@ public void newHierarchyVersion() {
737737

738738
public void newMethodsVersion(List<String> methodsToInvalidate) {
739739
for (String entryToInvalidate : methodsToInvalidate) {
740-
MethodEntry methodEntry = methods.get(entryToInvalidate);
741-
if (methodEntry != null) {
742-
methodEntry.invalidate(SharedMethodInfo.moduleAndMethodName(rubyModule, entryToInvalidate));
743-
methods.put(entryToInvalidate, methodEntry.withNewAssumption());
740+
while (true) {
741+
final MethodEntry methodEntry = methods.get(entryToInvalidate);
742+
if (methodEntry == null) {
743+
break;
744+
} else {
745+
methodEntry.invalidate(SharedMethodInfo.moduleAndMethodName(rubyModule, entryToInvalidate));
746+
if (methods.replace(entryToInvalidate, methodEntry, methodEntry.withNewAssumption())) {
747+
break;
748+
}
749+
}
744750
}
745751
}
746752
}

0 commit comments

Comments
 (0)