8203766: Add some instrumentation to jdk/java/nio/channels/Selector/RacyDeregister.java
Reviewed-by: alanb
This commit is contained in:
parent
ea1e68ff5d
commit
18d880bad8
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -34,17 +34,24 @@ import java.nio.channels.SocketChannel;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6429204
|
* @bug 6429204 8203766
|
||||||
* @summary SelectionKey.interestOps does not update interest set on Windows.
|
* @summary SelectionKey.interestOps does not update interest set on Windows.
|
||||||
* @author Frank Ding
|
* @author Frank Ding
|
||||||
|
* @run main/timeout=1200 RacyDeregister
|
||||||
*/
|
*/
|
||||||
public class RacyDeregister {
|
public class RacyDeregister {
|
||||||
|
|
||||||
// FIXME: numOuterLoopIterations should be reverted to the hard-coded value
|
// FIXME: NUM_OUTER_LOOP_ITERATIONS should be reverted to the hard-coded
|
||||||
// 15 when JDK-8161083 is resolved as either a bug or a non-issue.
|
// value 15 when JDK-8161083 is resolved as either a bug or a non-issue.
|
||||||
static final int numOuterLoopIterations =
|
static final int NUM_OUTER_LOOP_ITERATIONS =
|
||||||
System.getProperty("os.name").startsWith("Windows") ? 150 : 15;
|
System.getProperty("os.name").startsWith("Windows") ? 150 : 15;
|
||||||
|
|
||||||
|
// 90% of 1200 second timeout as milliseconds
|
||||||
|
static final int TIMEOUT_THRESHOLD_MILLIS = 1200*900;
|
||||||
|
|
||||||
|
// Time at start of main().
|
||||||
|
static long t0;
|
||||||
|
|
||||||
static boolean notified;
|
static boolean notified;
|
||||||
static final Object selectorLock = new Object();
|
static final Object selectorLock = new Object();
|
||||||
static final Object notifyLock = new Object();
|
static final Object notifyLock = new Object();
|
||||||
@ -56,6 +63,8 @@ public class RacyDeregister {
|
|||||||
static volatile Boolean succTermination = null;
|
static volatile Boolean succTermination = null;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
t0 = System.currentTimeMillis();
|
||||||
|
|
||||||
InetAddress addr = InetAddress.getByName(null);
|
InetAddress addr = InetAddress.getByName(null);
|
||||||
ServerSocketChannel sc = ServerSocketChannel.open();
|
ServerSocketChannel sc = ServerSocketChannel.open();
|
||||||
sc.socket().bind(new InetSocketAddress(addr, 0));
|
sc.socket().bind(new InetSocketAddress(addr, 0));
|
||||||
@ -76,13 +85,12 @@ public class RacyDeregister {
|
|||||||
final SelectionKey[] key = new SelectionKey[]{
|
final SelectionKey[] key = new SelectionKey[]{
|
||||||
accepted.register(sel, SelectionKey.OP_READ)};
|
accepted.register(sel, SelectionKey.OP_READ)};
|
||||||
|
|
||||||
|
|
||||||
// thread that will be changing key[0].interestOps to OP_READ | OP_WRITE
|
// thread that will be changing key[0].interestOps to OP_READ | OP_WRITE
|
||||||
new Thread() {
|
new Thread() {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
for (int k = 0; k < numOuterLoopIterations; k++) {
|
for (int k = 0; k < NUM_OUTER_LOOP_ITERATIONS; k++) {
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
synchronized (notifyLock) {
|
synchronized (notifyLock) {
|
||||||
synchronized (selectorLock) {
|
synchronized (selectorLock) {
|
||||||
@ -104,7 +112,7 @@ public class RacyDeregister {
|
|||||||
if (notified) {
|
if (notified) {
|
||||||
long t =
|
long t =
|
||||||
System.currentTimeMillis();
|
System.currentTimeMillis();
|
||||||
System.out.printf
|
System.err.printf
|
||||||
("Notified after %d ms%n",
|
("Notified after %d ms%n",
|
||||||
t - beginTime);
|
t - beginTime);
|
||||||
break;
|
break;
|
||||||
@ -118,6 +126,15 @@ public class RacyDeregister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
if (t - t0 > TIMEOUT_THRESHOLD_MILLIS) {
|
||||||
|
System.err.format
|
||||||
|
("Timeout after %d outer loop iterations%n", k);
|
||||||
|
succTermination = false;
|
||||||
|
// wake up main thread doing select()
|
||||||
|
sel.wakeup();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
succTermination = true;
|
succTermination = true;
|
||||||
// wake up main thread doing select()
|
// wake up main thread doing select()
|
||||||
@ -140,7 +157,7 @@ public class RacyDeregister {
|
|||||||
sc.close();
|
sc.close();
|
||||||
break;
|
break;
|
||||||
} else if (Boolean.FALSE.equals(succTermination)) {
|
} else if (Boolean.FALSE.equals(succTermination)) {
|
||||||
System.out.println("Failed to pass the test");
|
System.err.println("Failed to pass the test");
|
||||||
sel.close();
|
sel.close();
|
||||||
sc.close();
|
sc.close();
|
||||||
throw new RuntimeException("Failed to pass the test");
|
throw new RuntimeException("Failed to pass the test");
|
||||||
|
Loading…
Reference in New Issue
Block a user