Use a synchronization barrier to fix flakes.
test: test-art-host gcstress
Change-Id: I8ded9ec6efb48729bdfecaf9dc8daea164c6f519
diff --git a/test/952-invoke-custom/generator/TestInvokeCustomWithConcurrentThreads.java b/test/952-invoke-custom/generator/TestInvokeCustomWithConcurrentThreads.java
index 5d5cae4..9c0645b 100644
--- a/test/952-invoke-custom/generator/TestInvokeCustomWithConcurrentThreads.java
+++ b/test/952-invoke-custom/generator/TestInvokeCustomWithConcurrentThreads.java
@@ -28,6 +28,7 @@
import java.lang.Thread;
import java.lang.ThreadLocal;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.CyclicBarrier;
public class TestInvokeCustomWithConcurrentThreads extends Thread {
private static final int NUMBER_OF_THREADS = 16;
@@ -43,13 +44,16 @@
};
// Array of call sites instantiated, one per thread
- private static CallSite[] instantiated = new CallSite[NUMBER_OF_THREADS];
+ private static final CallSite[] instantiated = new CallSite[NUMBER_OF_THREADS];
// Array of counters for how many times each instantiated call site is called
- private static AtomicInteger[] called = new AtomicInteger[NUMBER_OF_THREADS];
+ private static final AtomicInteger[] called = new AtomicInteger[NUMBER_OF_THREADS];
// Array of call site indicies of which call site a thread invoked
- private static AtomicInteger[] targetted = new AtomicInteger[NUMBER_OF_THREADS];
+ private static final AtomicInteger[] targetted = new AtomicInteger[NUMBER_OF_THREADS];
+
+ // Synchronization barrier all threads will wait on in the bootstrap method.
+ private static final CyclicBarrier barrier = new CyclicBarrier(NUMBER_OF_THREADS);
private TestInvokeCustomWithConcurrentThreads() {}
@@ -95,10 +99,10 @@
assertEquals(mh.type().parameterCount(), 1);
assertEquals(methodType, mh.type());
- // Sleep to try to get concurrent executions of this
- // method. Multiple call sites should be created, but only one
+ // Wait for all threads to be in this method.
+ // Multiple call sites should be created, but only one
// invoked.
- Thread.sleep(125);
+ barrier.await();
instantiated[getThreadIndex()] = new ConstantCallSite(mh);
return instantiated[getThreadIndex()];