Skip to content

Commit

Permalink
[Wisp] Fix initialization problem between JavaNetSocketAccess and its…
Browse files Browse the repository at this point in the history
… usage

Summary: JavaNetSocketAccess is used in WispServerSocketImpl.java, but the former one's initialization is in Socket.java. This underlying problem shall be fixed.

Test Plan: ServerSocketConnectionTest.java

Reviewed-by: D-D-H, yuleil

Issue: #437
  • Loading branch information
zhengxiaolinX committed Nov 16, 2022
1 parent c720c95 commit cdbee46
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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());
}
Expand Down
28 changes: 28 additions & 0 deletions jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,44 @@
* @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;


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();
throw new RuntimeException("Test Failed!");
} finally {
if (ss != null) {
ss.close();
}
}
}

private static void testIsConnectedAfterClosing() throws Exception {
ServerSocket ss = null;
Socket s1 = null;
Expand Down Expand Up @@ -105,6 +132,7 @@ private static void testIsConnectedAfterAcception() throws Exception {
}

public static void main(String args[]) throws Exception {
testJavaNetSocketAccessInitialization();
testIsConnectedAfterClosing();
testIsConnectedAfterConnectionFailure();
testIsConnectedAfterAcception();
Expand Down
14 changes: 14 additions & 0 deletions jdk/test/com/alibaba/wisp/io/SimpleClient.java
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit cdbee46

Please sign in to comment.