Skip to content

Commit

Permalink
8241456: ThreadRunner shouldn't use Wicket for threads starting synch…
Browse files Browse the repository at this point in the history
…ronization

Reviewed-by: dholmes, iignatyev
  • Loading branch information
lmesnik committed Apr 3, 2020
1 parent cf22d44 commit a76f0f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 6 additions & 5 deletions test/hotspot/jtreg/vmTestbase/nsk/share/Wicket.java
Expand Up @@ -116,8 +116,8 @@ public Wicket(int count) {
public void waitFor() {
long id = System.currentTimeMillis();

lock.lock();
try {
lock.lock();
++waiters;
if (debugOutput != null) {
debugOutput.printf("Wicket %d %s: waitFor(). There are %d waiters totally now.\n", id, name, waiters);
Expand Down Expand Up @@ -172,8 +172,8 @@ public int waitFor(long timeout) {

long id = System.currentTimeMillis();

lock.lock();
try {
lock.lock();
++waiters;
if (debugOutput != null) {
debugOutput.printf("Wicket %d %s: waitFor(). There are %d waiters totally now.\n", id, name, waiters);
Expand Down Expand Up @@ -209,8 +209,8 @@ public int waitFor(long timeout) {
*/
public void unlock() {

lock.lock();
try {
lock.lock();
if (count == 0)
throw new IllegalStateException("locks are already open");

Expand Down Expand Up @@ -241,8 +241,8 @@ public void unlockAll() {
debugOutput.printf("Wicket %s: unlockAll()\n", name);
}

lock.lock();
try {
lock.lock();
count = 0;
condition.signalAll();
} finally {
Expand All @@ -257,8 +257,9 @@ public void unlockAll() {
* @return number of waiters
*/
public int getWaiters() {

lock.lock();
try {
lock.lock();
if (debugOutput != null) {
debugOutput.printf("Wicket %s: getWaiters()\n", name);
}
Expand Down
Expand Up @@ -22,7 +22,6 @@
*/
package nsk.share.runner;

import nsk.share.Wicket;
import nsk.share.gc.OOMStress;
import nsk.share.log.*;
import nsk.share.test.Stresser;
Expand All @@ -45,7 +44,7 @@ public class ThreadsRunner implements MultiRunner, LogAware, RunParamsAware {
private RunParams runParams;
private List<Runnable> runnables = new ArrayList<Runnable>();
private List<ManagedThread> threads = new ArrayList<ManagedThread>();
private Wicket wicket = new Wicket();
private AtomicInteger notStarted;
private AtomicInteger finished;
private boolean started = false;
private boolean successful = true;
Expand Down Expand Up @@ -97,7 +96,10 @@ public ManagedThread(ManagedThreadFactory threadFactory, Runnable test, int num)

@Override
public void run() {
wicket.waitFor();
notStarted.decrementAndGet();
while (notStarted.get() != 0) {
Thread.onSpinWait();
}
try {
stresser.start(runParams.getIterations());
while (!this.thread.isInterrupted() && stresser.iteration()) {
Expand Down Expand Up @@ -187,6 +189,7 @@ private void prepare() {

private void create() {
int threadCount = runnables.size();
notStarted = new AtomicInteger(threadCount);
finished = new AtomicInteger(threadCount);
ManagedThreadFactory factory = ManagedThreadFactory.createFactory(runParams);
for (int i = 0; i < threadCount; ++i) {
Expand All @@ -208,7 +211,6 @@ public void start() {
log.debug("Starting " + t);
t.start();
}
wicket.unlock();
started = true;
}

Expand Down

0 comments on commit a76f0f7

Please sign in to comment.