diff options
author | 2020-01-07 17:05:42 +0000 | |
---|---|---|
committer | 2020-01-07 19:55:17 +0000 | |
commit | 93be70effba70b78596fc4bda6b583615c3b6d0c (patch) | |
tree | da679b13dee39a03f4854c53c0edcff4dddea0e9 | |
parent | 55d6fa4c352a1fadbd21b8d8e0929833e547b9e5 (diff) |
Revert^2 "Make tests 1995, 2001, & 2005 less likely to OOME."
Test 2005 works by starting a bunch of threads, collecting all threads
using the thread-group, suspending them and then performing
redefinition work. Unfortunately due to the API there is a race
between figuring out how many threads their are and getting them with
enumerate. In cases where enumerate is called with a larger array then
needed, due to some threads finishing ('run' returning) the enumerate
doesn't fill in some of the array. This meant we called
SuspendThreadList with 'null', which is interpreted as meaning the
current thread. This leads to a deadlock.
This reverts commit 01a09bfd3839401c32d537b9a03b7991c4ffd20c.
Bug: 147190668
Bug: 147278184
Test: ./test.py --host
Reason for revert: Fixed issue causing occasional deadlock in test
2005
Change-Id: I01fb9f38c4516730821106ac291836eb61534a73
3 files changed, 17 insertions, 6 deletions
diff --git a/test/1995-final-virtual-structural-multithread/src/art/Test1995.java b/test/1995-final-virtual-structural-multithread/src/art/Test1995.java index 1ffee60a06..70734943a0 100644 --- a/test/1995-final-virtual-structural-multithread/src/art/Test1995.java +++ b/test/1995-final-virtual-structural-multithread/src/art/Test1995.java @@ -22,6 +22,8 @@ import java.util.Base64; import java.util.concurrent.CountDownLatch; public class Test1995 { private static final int NUM_THREADS = 20; + // Don't perform more than this many repeats per thread to prevent OOMEs + private static final int TASK_COUNT_LIMIT = 1000; public static final class Transform { public String greetingEnglish; @@ -107,14 +109,14 @@ public class Test1995 { public MyThread(CountDownLatch delay, int id) { super("Thread: " + id); this.thr_id = id; - this.results = new ArrayList<>(1000); + this.results = new ArrayList<>(TASK_COUNT_LIMIT); this.finish = false; this.delay = delay; } public void run() { delay.countDown(); - while (!finish) { + while (!finish && results.size() < TASK_COUNT_LIMIT) { Transform t = new Transform(); results.add(t.sayHi()); } diff --git a/test/2001-virtual-structural-multithread/src-art/art/Test2001.java b/test/2001-virtual-structural-multithread/src-art/art/Test2001.java index e6ee0ceaec..40972db643 100644 --- a/test/2001-virtual-structural-multithread/src-art/art/Test2001.java +++ b/test/2001-virtual-structural-multithread/src-art/art/Test2001.java @@ -25,6 +25,8 @@ import java.util.function.Supplier; public class Test2001 { private static final int NUM_THREADS = 20; + // Don't perform more than this many repeats per thread to prevent OOMEs + private static final int TASK_COUNT_LIMIT = 1000; public static class Transform { public String greetingEnglish; @@ -167,14 +169,14 @@ public class Test2001 { public MyThread(CountDownLatch delay, int id) { super("Thread: " + id); this.thr_id = id; - this.results = new ArrayList<>(1000); + this.results = new ArrayList<>(TASK_COUNT_LIMIT); this.finish = false; this.delay = delay; } public void run() { delay.countDown(); - while (!finish) { + while (!finish && results.size() < TASK_COUNT_LIMIT) { Supplier<String> t = mkTransform(); results.add(t.get()); } diff --git a/test/2005-pause-all-redefine-multithreaded/src/art/Test2005.java b/test/2005-pause-all-redefine-multithreaded/src/art/Test2005.java index 6fdadb7a0a..e805a5f555 100644 --- a/test/2005-pause-all-redefine-multithreaded/src/art/Test2005.java +++ b/test/2005-pause-all-redefine-multithreaded/src/art/Test2005.java @@ -22,6 +22,8 @@ import java.util.concurrent.CountDownLatch; public class Test2005 { private static final int NUM_THREADS = 20; private static final String DEFAULT_VAL = "DEFAULT_VALUE"; + // Don't perform more than this many repeats per thread to prevent OOMEs + private static final int TASK_COUNT_LIMIT = 1000; public static final class Transform { public String greetingEnglish; @@ -108,14 +110,14 @@ public class Test2005 { public MyThread(CountDownLatch delay, int id) { super("Thread: " + id); this.thr_id = id; - this.results = new ArrayList<>(1000); + this.results = new ArrayList<>(TASK_COUNT_LIMIT); this.finish = false; this.delay = delay; } public void run() { delay.countDown(); - while (!finish) { + while (!finish && results.size() < TASK_COUNT_LIMIT) { Transform t = new Transform(); results.add(t.sayHi()); } @@ -171,7 +173,12 @@ public class Test2005 { Thread[] all_threads = new Thread[mytg.activeCount()]; mytg.enumerate(all_threads); Set<Thread> thread_set = new HashSet<>(Arrays.asList(all_threads)); + // We don't want to suspend ourself, that would cause a deadlock. thread_set.remove(Thread.currentThread()); + // If some of the other threads finished between calling mytg.activeCount and enumerate we will + // have nulls. These nulls are interpreted as currentThread by SuspendThreadList so we want to + // get rid of them. + thread_set.remove(null); // Suspend them. Suspension.suspendList(thread_set.toArray(new Thread[0])); // Actual redefine. |