From 1dbaabdc7824b69d4251788b8a80ee6a5d8ff5ea Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Wed, 22 Jan 2014 09:36:11 +0000 Subject: [PATCH 1/2] 7133499: (fc) FileChannel.read not preempted by asynchronous close on OS X Reviewed-by: chegar --- .../classes/sun/nio/ch/FileChannelImpl.java | 2 +- .../classes/sun/nio/ch/NativeThreadSet.java | 22 ++++----- .../ch/SimpleAsynchronousFileChannelImpl.java | 1 - .../solaris/native/sun/nio/ch/NativeThread.c | 45 +++++++++++-------- jdk/test/ProblemList.txt | 5 --- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java index 3c4ddaacd6d..2fcd0c89fe0 100644 --- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java @@ -110,7 +110,7 @@ public class FileChannelImpl } } - nd.preClose(fd); + // signal any threads blocked on this channel threads.signalAndWait(); if (parent != null) { diff --git a/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java b/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java index d6d4c5c9aef..5eb90af879e 100644 --- a/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java +++ b/jdk/src/share/classes/sun/nio/ch/NativeThreadSet.java @@ -82,8 +82,9 @@ class NativeThreadSet { // Signals all threads in this set. // - void signalAndWait() { - synchronized (this) { + synchronized void signalAndWait() { + boolean interrupted = false; + while (used > 0) { int u = used; int n = elts.length; for (int i = 0; i < n; i++) { @@ -96,16 +97,15 @@ class NativeThreadSet { break; } waitingToEmpty = true; - boolean interrupted = false; - while (used > 0) { - try { - wait(); - } catch (InterruptedException e) { - interrupted = true; - } + try { + wait(50); + } catch (InterruptedException e) { + interrupted = true; + } finally { + waitingToEmpty = false; } - if (interrupted) - Thread.currentThread().interrupt(); } + if (interrupted) + Thread.currentThread().interrupt(); } } diff --git a/jdk/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java index 741abf733fd..8d891b6ec34 100644 --- a/jdk/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java @@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl invalidateAllLocks(); // signal any threads blocked on this channel - nd.preClose(fdObj); threads.signalAndWait(); // wait until all async I/O operations have completely gracefully diff --git a/jdk/src/solaris/native/sun/nio/ch/NativeThread.c b/jdk/src/solaris/native/sun/nio/ch/NativeThread.c index 79a91a068ac..5e2a78b7af3 100644 --- a/jdk/src/solaris/native/sun/nio/ch/NativeThread.c +++ b/jdk/src/solaris/native/sun/nio/ch/NativeThread.c @@ -32,27 +32,32 @@ #include "sun_nio_ch_NativeThread.h" #include "nio_util.h" - #ifdef __linux__ -#include -#include - -/* Also defined in src/solaris/native/java/net/linux_close.c */ -#define INTERRUPT_SIGNAL (__SIGRTMAX - 2) + #include + #include + /* Also defined in net/linux_close.c */ + #define INTERRUPT_SIGNAL (__SIGRTMAX - 2) +#elif __solaris__ + #include + #include + #define INTERRUPT_SIGNAL (SIGRTMAX - 2) +#elif _ALLBSD_SOURCE + #include + #include + /* Also defined in net/bsd_close.c */ + #define INTERRUPT_SIGNAL SIGIO +#else + #error "missing platform-specific definition here" +#endif static void nullHandler(int sig) { } -#endif - - JNIEXPORT void JNICALL Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) { -#ifdef __linux__ - /* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the * handler previously installed by java/net/linux_close.c, but that's okay * since neither handler actually does anything. We install our own @@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) sigemptyset(&sa.sa_mask); if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0) JNU_ThrowIOExceptionWithLastError(env, "sigaction"); - -#endif } JNIEXPORT jlong JNICALL Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl) { -#ifdef __linux__ - return (long)pthread_self(); +#ifdef __solaris__ + return (jlong)thr_self(); #else - return -1; + return (jlong)pthread_self(); #endif } JNIEXPORT void JNICALL Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread) { -#ifdef __linux__ - if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL)) - JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed"); + int ret; +#ifdef __solaris__ + ret = thr_kill((thread_t)thread, INTERRUPT_SIGNAL); +#else + ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL); #endif + if (ret != 0) + JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed"); } diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt index 2a90ff98b67..95b6038e6e2 100644 --- a/jdk/test/ProblemList.txt +++ b/jdk/test/ProblemList.txt @@ -173,11 +173,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all # 6963118 java/nio/channels/Selector/Wakeup.java windows-all -# 7133499, 7133497 -java/nio/channels/AsyncCloseAndInterrupt.java macosx-all -java/nio/channels/AsynchronousFileChannel/Lock.java macosx-all -java/nio/channels/FileChannel/Transfer.java macosx-all - # 7141822 java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all From dc4d716d02913a4db3209fd1eee0297bc959e0d9 Mon Sep 17 00:00:00 2001 From: Mattias Tobiasson Date: Tue, 21 Jan 2014 08:36:12 +0100 Subject: [PATCH 2/2] 6545321: [TESTBUG] jstatLineCounts4.sh has to be resilient to unexpected output Keep check for specific lines. Remove check for total number of lines. Reviewed-by: sla --- jdk/test/sun/tools/jstat/classOutput1.awk | 2 +- jdk/test/sun/tools/jstat/classloadOutput1.awk | 2 +- jdk/test/sun/tools/jstat/compilerOutput1.awk | 2 +- jdk/test/sun/tools/jstat/fileURITest1.awk | 2 +- jdk/test/sun/tools/jstat/gcCapacityOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcCauseOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcMetaCapacityOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcNewCapacityOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcOldCapacityOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcOldOutput1.awk | 2 +- jdk/test/sun/tools/jstat/gcOutput1.awk | 2 +- jdk/test/sun/tools/jstat/lineCounts1.awk | 2 +- jdk/test/sun/tools/jstat/lineCounts2.awk | 2 +- jdk/test/sun/tools/jstat/lineCounts3.awk | 2 +- jdk/test/sun/tools/jstat/lineCounts4.awk | 2 +- jdk/test/sun/tools/jstat/printCompilationOutput1.awk | 2 +- jdk/test/sun/tools/jstat/timeStamp1.awk | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/jdk/test/sun/tools/jstat/classOutput1.awk b/jdk/test/sun/tools/jstat/classOutput1.awk index d31118bf0ec..6213899e72b 100644 --- a/jdk/test/sun/tools/jstat/classOutput1.awk +++ b/jdk/test/sun/tools/jstat/classOutput1.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/classloadOutput1.awk b/jdk/test/sun/tools/jstat/classloadOutput1.awk index 66e2b5dcd18..0a3d1e945b5 100644 --- a/jdk/test/sun/tools/jstat/classloadOutput1.awk +++ b/jdk/test/sun/tools/jstat/classloadOutput1.awk @@ -22,7 +22,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/compilerOutput1.awk b/jdk/test/sun/tools/jstat/compilerOutput1.awk index 4a9f89e9fde..09b920ab0e4 100644 --- a/jdk/test/sun/tools/jstat/compilerOutput1.awk +++ b/jdk/test/sun/tools/jstat/compilerOutput1.awk @@ -30,7 +30,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/fileURITest1.awk b/jdk/test/sun/tools/jstat/fileURITest1.awk index 51e31846501..8b56e89ca31 100644 --- a/jdk/test/sun/tools/jstat/fileURITest1.awk +++ b/jdk/test/sun/tools/jstat/fileURITest1.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcCapacityOutput1.awk b/jdk/test/sun/tools/jstat/gcCapacityOutput1.awk index ab630d143b6..ec7a737d55c 100644 --- a/jdk/test/sun/tools/jstat/gcCapacityOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcCapacityOutput1.awk @@ -22,7 +22,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcCauseOutput1.awk b/jdk/test/sun/tools/jstat/gcCauseOutput1.awk index 3041291ac3d..005e791043a 100644 --- a/jdk/test/sun/tools/jstat/gcCauseOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcCauseOutput1.awk @@ -30,7 +30,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcMetaCapacityOutput1.awk b/jdk/test/sun/tools/jstat/gcMetaCapacityOutput1.awk index 12d9544542a..352e02d6cbc 100644 --- a/jdk/test/sun/tools/jstat/gcMetaCapacityOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcMetaCapacityOutput1.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcNewCapacityOutput1.awk b/jdk/test/sun/tools/jstat/gcNewCapacityOutput1.awk index 0491fa52076..f4473dc37e4 100644 --- a/jdk/test/sun/tools/jstat/gcNewCapacityOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcNewCapacityOutput1.awk @@ -22,7 +22,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcOldCapacityOutput1.awk b/jdk/test/sun/tools/jstat/gcOldCapacityOutput1.awk index 7fb4575163a..cbf88756060 100644 --- a/jdk/test/sun/tools/jstat/gcOldCapacityOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcOldCapacityOutput1.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcOldOutput1.awk b/jdk/test/sun/tools/jstat/gcOldOutput1.awk index c007f66b3be..319f707d273 100644 --- a/jdk/test/sun/tools/jstat/gcOldOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcOldOutput1.awk @@ -22,7 +22,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/gcOutput1.awk b/jdk/test/sun/tools/jstat/gcOutput1.awk index d1d90a281e2..5bd59fe0d8e 100644 --- a/jdk/test/sun/tools/jstat/gcOutput1.awk +++ b/jdk/test/sun/tools/jstat/gcOutput1.awk @@ -22,7 +22,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/lineCounts1.awk b/jdk/test/sun/tools/jstat/lineCounts1.awk index dd6d5f8fbf5..cc974104b99 100644 --- a/jdk/test/sun/tools/jstat/lineCounts1.awk +++ b/jdk/test/sun/tools/jstat/lineCounts1.awk @@ -25,7 +25,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 5) && (totallines == 6)) { + if ((headerlines == 1) && (datalines == 5)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/lineCounts2.awk b/jdk/test/sun/tools/jstat/lineCounts2.awk index adecd0a0572..ac2009d2e0b 100644 --- a/jdk/test/sun/tools/jstat/lineCounts2.awk +++ b/jdk/test/sun/tools/jstat/lineCounts2.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/lineCounts3.awk b/jdk/test/sun/tools/jstat/lineCounts3.awk index 24788b429e0..9b6d3ecec59 100644 --- a/jdk/test/sun/tools/jstat/lineCounts3.awk +++ b/jdk/test/sun/tools/jstat/lineCounts3.awk @@ -30,7 +30,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 10) && (totallines == 11)) { + if ((headerlines == 1) && (datalines == 10)) { exit 0 } else { exit 1 diff --git a/jdk/test/sun/tools/jstat/lineCounts4.awk b/jdk/test/sun/tools/jstat/lineCounts4.awk index c4ea918fdd2..db40ad355c6 100644 --- a/jdk/test/sun/tools/jstat/lineCounts4.awk +++ b/jdk/test/sun/tools/jstat/lineCounts4.awk @@ -36,7 +36,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 2) && (datalines == 11) && (totallines == 13) && (datalines2 == 1)) { + if ((headerlines == 2) && (datalines == 11) && (datalines2 == 1)) { exit 0 } else { exit 1 diff --git a/jdk/test/sun/tools/jstat/printCompilationOutput1.awk b/jdk/test/sun/tools/jstat/printCompilationOutput1.awk index f2e26213975..d165e4d997e 100644 --- a/jdk/test/sun/tools/jstat/printCompilationOutput1.awk +++ b/jdk/test/sun/tools/jstat/printCompilationOutput1.awk @@ -25,7 +25,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else { diff --git a/jdk/test/sun/tools/jstat/timeStamp1.awk b/jdk/test/sun/tools/jstat/timeStamp1.awk index cce381ce41d..908f4230419 100644 --- a/jdk/test/sun/tools/jstat/timeStamp1.awk +++ b/jdk/test/sun/tools/jstat/timeStamp1.awk @@ -21,7 +21,7 @@ BEGIN { { totallines++; print $0 } END { - if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + if ((headerlines == 1) && (datalines == 1)) { exit 0 } else {