Skip to content

Commit ada79c0

Browse files
dougxcboris-spas
authored andcommitted
avoid ConcurrentModificationException in CompilationWatchDogTest (GR-42988)
1 parent a0e02d0 commit ada79c0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CompilationWatchDogTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@ public static int snippet(int value) {
6969
return value;
7070
}
7171

72+
/**
73+
* Access to this list is synchronized to avoid a ConcurrentModificationException.
74+
*/
7275
private List<String> events = new ArrayList<>();
7376

7477
private long firstEvent = System.currentTimeMillis();
7578

76-
private void event(String label) {
79+
private synchronized void event(String label) {
7780
long when = System.currentTimeMillis() - firstEvent;
7881
events.add(String.format("after %d ms: %s", when, label));
7982
}
8083

81-
private String eventLog() {
84+
private synchronized String eventLog() {
8285
return events.stream().collect(Collectors.joining(System.lineSeparator()));
8386
}
8487

@@ -138,10 +141,19 @@ public void onStuckCompilation(CompilationWatchDog watchDog, Thread watched, Com
138141
event("start compiling");
139142
return super.getCode(installedCodeOwner, graph, forceCompile, installAsDefault, options);
140143
} finally {
141-
Assert.assertTrue(eventLog(), !longCompilations.isEmpty());
142-
Assert.assertTrue(eventLog(), longCompilations.stream().allMatch(id -> id == compilation));
143-
Assert.assertTrue(eventLog(), !stuckCompilations.isEmpty());
144-
Assert.assertTrue(eventLog(), longCompilations.stream().allMatch(id -> id == compilation));
144+
check(!longCompilations.isEmpty());
145+
check(longCompilations.stream().allMatch(id -> id == compilation));
146+
check(!stuckCompilations.isEmpty());
147+
check(longCompilations.stream().allMatch(id -> id == compilation));
148+
}
149+
}
150+
151+
/**
152+
* Factored out to only fetch the event log if the condition fails.
153+
*/
154+
private void check(boolean condition) {
155+
if (!condition) {
156+
Assert.fail(eventLog());
145157
}
146158
}
147159
}

0 commit comments

Comments
 (0)