Skip to content

Commit cdbee46

Browse files
committed
[Wisp] Fix initialization problem between JavaNetSocketAccess and its 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
1 parent c720c95 commit cdbee46

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

jdk/src/linux/classes/com/alibaba/wisp/engine/WispEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.dyn.CoroutineExitException;
3131
import java.dyn.CoroutineSupport;
3232
import java.io.IOException;
33+
import java.net.Socket;
3334
import java.nio.channels.SelectableChannel;
3435
import java.nio.channels.SelectionKey;
3536
import java.util.*;
@@ -148,6 +149,7 @@ private static void initializeClasses() {
148149
Class.forName(ShutdownEngine.class.getName());
149150
Class.forName(AbstractShutdownTask.class.getName());
150151
Class.forName(ShutdownControlGroup.class.getName());
152+
Class.forName(Socket.class.getName());
151153
if (WispConfiguration.WISP_PROFILE) {
152154
Class.forName(WispPerfCounterMonitor.class.getName());
153155
}

jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,44 @@
2424
* @summary Test ServerSocket isConnected() method
2525
* @requires os.family == "linux"
2626
* @library /lib/testlibrary
27+
* @build SimpleClient
2728
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableCoroutine -XX:+UseWispMonitor -Dcom.alibaba.wisp.transparentWispSwitch=true ServerSocketConnectionTest
2829
*/
2930

3031
import java.io.IOException;
3132
import java.net.*;
33+
3234
import static jdk.testlibrary.Asserts.assertTrue;
3335
import static jdk.testlibrary.Asserts.assertFalse;
3436

3537

3638
public class ServerSocketConnectionTest {
3739

40+
private static final String CLIENT = "SimpleClient";
41+
private static final String PORT = "4039";
42+
43+
public static void testJavaNetSocketAccessInitialization() throws Exception {
44+
ServerSocket ss = null;
45+
try {
46+
ss = new ServerSocket(Integer.parseInt(PORT));
47+
// We should avoid using the Socket class here to reproduce this issue.
48+
// So we use another process here.
49+
ProcessBuilder pb = jdk.testlibrary.ProcessTools.createJavaProcessBuilder(
50+
CLIENT,
51+
PORT // port
52+
);
53+
pb.start();
54+
ss.accept();
55+
} catch (Exception e) {
56+
e.printStackTrace();
57+
throw new RuntimeException("Test Failed!");
58+
} finally {
59+
if (ss != null) {
60+
ss.close();
61+
}
62+
}
63+
}
64+
3865
private static void testIsConnectedAfterClosing() throws Exception {
3966
ServerSocket ss = null;
4067
Socket s1 = null;
@@ -105,6 +132,7 @@ private static void testIsConnectedAfterAcception() throws Exception {
105132
}
106133

107134
public static void main(String args[]) throws Exception {
135+
testJavaNetSocketAccessInitialization();
108136
testIsConnectedAfterClosing();
109137
testIsConnectedAfterConnectionFailure();
110138
testIsConnectedAfterAcception();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.io.IOException;
2+
import java.net.ServerSocket;
3+
import java.net.*;
4+
import java.net.Socket;
5+
6+
public class SimpleClient {
7+
8+
public static void main(String[] args) throws Exception {
9+
Socket socket = new Socket();
10+
socket.connect(new InetSocketAddress(InetAddress.getLocalHost(), Integer.parseInt(args[0])));
11+
System.out.println(socket.getRemoteSocketAddress());
12+
}
13+
14+
}

0 commit comments

Comments
 (0)