8285008: JFR: jdk/jfr/jmx/streaming/TestClose.java failed with "Exception: Expected repository to be empty"

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2022-05-28 17:22:10 +00:00
parent 2c461acfeb
commit a6e2e223ea
2 changed files with 11 additions and 29 deletions

View File

@ -33,6 +33,8 @@ import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
@ -44,7 +46,6 @@ import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.PlatformRecording;
import jdk.jfr.internal.SecuritySupport;
/*
@ -54,7 +55,7 @@ import jdk.jfr.internal.SecuritySupport;
public abstract class AbstractEventStream implements EventStream {
private static final AtomicLong counter = new AtomicLong();
private final Object terminated = new Object();
private final CountDownLatch terminated = new CountDownLatch(1);
private final Runnable flushOperation = () -> dispatcher().runFlushActions();
@SuppressWarnings("removal")
private final AccessControlContext accessControllerContext;
@ -178,33 +179,16 @@ public abstract class AbstractEventStream implements EventStream {
throw new IllegalArgumentException("timeout value is negative");
}
long base = System.currentTimeMillis();
long now = 0;
long millis;
long nanos;
try {
millis = Math.multiplyExact(timeout.getSeconds(), 1000);
nanos = timeout.toNanos();
} catch (ArithmeticException a) {
millis = Long.MAX_VALUE;
nanos = Long.MAX_VALUE;
}
int nanos = timeout.toNanosPart();
if (nanos == 0 && millis == 0) {
synchronized (terminated) {
while (!isClosed()) {
terminated.wait(0);
}
}
if (nanos == 0) {
terminated.await();
} else {
while (!isClosed()) {
long delay = millis - now;
if (delay <= 0) {
break;
}
synchronized (terminated) {
terminated.wait(delay, nanos);
}
now = System.currentTimeMillis() - base;
}
terminated.await(nanos, TimeUnit.NANOSECONDS);
}
}
@ -275,9 +259,7 @@ public abstract class AbstractEventStream implements EventStream {
try {
close();
} finally {
synchronized (terminated) {
terminated.notifyAll();
}
terminated.countDown();
}
}
}

View File

@ -38,7 +38,7 @@ import jdk.management.jfr.RemoteRecordingStream;
* @summary Tests that a RemoteRecordingStream can be closed
* @requires vm.hasJFR
* @library /test/lib /test/jdk
* @run main/othervm jdk.jfr.jmx.streaming.TestClose
* @run main/othervm -Xlog:jfr=debug jdk.jfr.jmx.streaming.TestClose
*/
public class TestClose {