Skip to content

Commit 5f2a45c

Browse files
Shruthi AcharyaPaul Hohensee
authored andcommitted
8317801: java/net/Socket/asyncClose/Race.java fails intermittently (aix)
Backport-of: 8f121a173ca2534c706682f6c68fbbb0b94ec057
1 parent 0f49f65 commit 5f2a45c

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/java.base/unix/classes/sun/nio/ch/NativeThread.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -78,6 +78,17 @@ static boolean isVirtualThread(long tid) {
7878
return (tid == VIRTUAL_THREAD_ID);
7979
}
8080

81+
/**
82+
* Return true if the operating system supports pending signals. If a signal is sent
83+
* to a thread but cannot be delivered immediately then it will be delivered when the
84+
* thread is in the appropriate state.
85+
*/
86+
static boolean supportPendingSignals() {
87+
return supportPendingSignals0();
88+
}
89+
90+
private static native boolean supportPendingSignals0();
91+
8192
// Returns an opaque token representing the native thread underlying the
8293
// invoking Java thread. On systems that do not require signalling, this
8394
// method always returns 0.

src/java.base/unix/classes/sun/nio/ch/UnixDispatcher.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,31 @@
2929
import java.io.IOException;
3030

3131
abstract class UnixDispatcher extends NativeDispatcher {
32+
private static final boolean SUPPORTS_PENDING_SIGNALS = NativeThread.supportPendingSignals();
3233

3334
@Override
3435
void close(FileDescriptor fd) throws IOException {
3536
close0(fd);
3637
}
3738

38-
@Override
39-
void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException {
40-
preClose0(fd);
39+
private void signalThreads(long reader, long writer) {
4140
if (NativeThread.isNativeThread(reader))
4241
NativeThread.signal(reader);
4342
if (NativeThread.isNativeThread(writer))
4443
NativeThread.signal(writer);
4544
}
4645

46+
@Override
47+
void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException {
48+
if (SUPPORTS_PENDING_SIGNALS) {
49+
signalThreads(reader, writer);
50+
}
51+
preClose0(fd);
52+
if (!SUPPORTS_PENDING_SIGNALS) {
53+
signalThreads(reader, writer);
54+
}
55+
}
56+
4757
private static native void close0(FileDescriptor fd) throws IOException;
4858

4959
private static native void preClose0(FileDescriptor fd) throws IOException;

src/java.base/unix/native/libnio/ch/NativeThread.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -88,3 +88,12 @@ Java_sun_nio_ch_NativeThread_signal0(JNIEnv *env, jclass cl, jlong thread)
8888
#endif
8989
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
9090
}
91+
92+
JNIEXPORT jboolean JNICALL
93+
Java_sun_nio_ch_NativeThread_supportPendingSignals0(JNIEnv *env, jclass cl) {
94+
#if defined(_AIX)
95+
return JNI_TRUE;
96+
#else
97+
return JNI_FALSE;
98+
#endif
99+
}

test/jdk/ProblemList.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,6 @@ java/net/MulticastSocket/SetLoopbackMode.java 7122846,8308807
592592
java/net/MulticastSocket/SetOutgoingIf.java 8308807 aix-ppc64
593593
java/net/MulticastSocket/Test.java 7145658,8308807 macosx-all,aix-ppc64
594594

595-
java/net/Socket/asyncClose/Race.java 8317801 aix-ppc64
596-
597595
############################################################################
598596

599597
# jdk_nio

0 commit comments

Comments
 (0)