summaryrefslogtreecommitdiff
path: root/test/2005-pause-all-redefine-multithreaded
diff options
context:
space:
mode:
Diffstat (limited to 'test/2005-pause-all-redefine-multithreaded')
-rw-r--r--test/2005-pause-all-redefine-multithreaded/src/art/Test2005.java11
1 files changed, 9 insertions, 2 deletions
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.