diff --git a/jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java b/jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java index 505044159eb..e0b342502af 100644 --- a/jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java +++ b/jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java @@ -30,6 +30,7 @@ import java.dyn.CoroutineExitException; import java.dyn.CoroutineSupport; import java.io.IOException; +import java.net.Socket; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.util.*; @@ -148,6 +149,7 @@ private static void initializeClasses() { Class.forName(ShutdownEngine.class.getName()); Class.forName(AbstractShutdownTask.class.getName()); Class.forName(ShutdownControlGroup.class.getName()); + Class.forName(Socket.class.getName()); if (WispConfiguration.WISP_PROFILE) { Class.forName(WispPerfCounterMonitor.class.getName()); } diff --git a/jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java b/jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java index 4873fcea45b..0de2bb892b5 100644 --- a/jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java +++ b/jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java @@ -24,17 +24,43 @@ * @summary Test ServerSocket isConnected() method * @requires os.family == "linux" * @library /lib/testlibrary + * @build SimpleClient * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableCoroutine -XX:+UseWispMonitor -Dcom.alibaba.wisp.transparentWispSwitch=true ServerSocketConnectionTest */ import java.io.IOException; import java.net.*; -import static jdk.testlibrary.Asserts.assertTrue; -import static jdk.testlibrary.Asserts.assertFalse; + +import static jdk.testlibrary.Asserts.*; public class ServerSocketConnectionTest { + private static final String CLIENT = "SimpleClient"; + private static final String PORT = "4039"; + + public static void testJavaNetSocketAccessInitialization() throws Exception { + ServerSocket ss = null; + try { + ss = new ServerSocket(Integer.parseInt(PORT)); + // We should avoid using the Socket class here to reproduce this issue. + // So we use another process here. + ProcessBuilder pb = jdk.testlibrary.ProcessTools.createJavaProcessBuilder( + CLIENT, + PORT // port + ); + pb.start(); + ss.accept(); + } catch (Exception e) { + e.printStackTrace(); + fail("Test Failed!"); + } finally { + if (ss != null) { + ss.close(); + } + } + } + private static void testIsConnectedAfterClosing() throws Exception { ServerSocket ss = null; Socket s1 = null; @@ -48,7 +74,7 @@ private static void testIsConnectedAfterClosing() throws Exception { s1.connect(isa); } catch (Exception e) { e.printStackTrace(); - throw new RuntimeException("Test Failed!"); + fail("Test Failed!"); } finally { // close this socket if (s1 != null) { @@ -74,7 +100,7 @@ private static void testIsConnectedAfterConnectionFailure() throws Exception { s1.connect(isa, -1); // exception here } catch (IOException e) { e.printStackTrace(); - throw new RuntimeException("Test Failed!"); + fail("Test Failed!"); } catch (IllegalArgumentException e) { // we shall go here. assertFalse(s1.isConnected()); @@ -93,7 +119,7 @@ private static void testIsConnectedAfterAcception() throws Exception { s1 = ss.accept(); } catch (Exception e) { e.printStackTrace(); - throw new RuntimeException("Test Failed!"); + fail("Test Failed!"); } finally { if (s1 != null) { assertTrue(s1.isConnected()); @@ -105,6 +131,7 @@ private static void testIsConnectedAfterAcception() throws Exception { } public static void main(String args[]) throws Exception { + testJavaNetSocketAccessInitialization(); testIsConnectedAfterClosing(); testIsConnectedAfterConnectionFailure(); testIsConnectedAfterAcception(); diff --git a/jdk/test/com/alibaba/wisp/io/SimpleClient.java b/jdk/test/com/alibaba/wisp/io/SimpleClient.java new file mode 100644 index 00000000000..7871fa23c42 --- /dev/null +++ b/jdk/test/com/alibaba/wisp/io/SimpleClient.java @@ -0,0 +1,14 @@ +import java.io.IOException; +import java.net.ServerSocket; +import java.net.*; +import java.net.Socket; + +public class SimpleClient { + + public static void main(String[] args) throws Exception { + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(InetAddress.getLocalHost(), Integer.parseInt(args[0]))); + System.out.println(socket.getRemoteSocketAddress()); + } + +}