Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8237388: serviceability/dcmd/framework/VMVersionTest.java fails with …
…connection refused error.

Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Alex Menkov committed Jun 8, 2021
1 parent c21cc93 commit b568e87
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 69 deletions.
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -61,13 +61,13 @@ public Process launch() {
Binder binder = new Binder(argHandler, log);
binder.prepareForPipeConnection(argHandler);

pipe = IOPipe.startDebuggerPipe(binder);

String cmd = prepareLaunch(java, argHandler.getPipePort());

Debugee debuggee = binder.startLocalDebugee(cmd);
debuggee.redirectOutput(log);

pipe = new IOPipe(debuggee);

String line = pipe.readln();
if (!"ready".equals(line)) {
System.out.println("Wrong reply received:" + line);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -48,7 +48,7 @@ public static void main(String argv[]) {
log("Waiting for the quit command from the test ...");
String cmd = pipe.readln();
int exitCode = PASSED;
if (cmd.equals("quit")) {
if ("quit".equals(cmd)) {
log("'quit' received");
} else {
log("Invalid command received " + cmd);
Expand Down
30 changes: 20 additions & 10 deletions test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java
Expand Up @@ -24,6 +24,7 @@
package nsk.share.jpda;

import nsk.share.*;
import nsk.share.jdi.Binder;

/**
* This class implements communicational channel between
Expand All @@ -42,8 +43,6 @@ public class IOPipe extends SocketIOPipe {

public static final String PIPE_LOG_PREFIX = "IOPipe> ";

private DebugeeProcess debugee;

/**
* Make <code>IOPipe</code> at debugee's side.
*
Expand All @@ -61,7 +60,9 @@ public IOPipe(DebugeeArgumentHandler argumentHandler, Log log) {
* Make <code>IOPipe</code> at debugger's side
* with given <code>Debugee</code> mirror.
*
* @deprecated Use Debugee.createIOPipe() instead.
* @deprecated Preferred way is to start IOPipe before launching debuggee process.
*
* @see #startDebuggerPipe
*/
@Deprecated
public IOPipe(DebugeeProcess debugee) {
Expand All @@ -70,8 +71,7 @@ public IOPipe(DebugeeProcess debugee) {
debugee.getArgumentHandler().getPipePortNumber(),
(long)debugee.getArgumentHandler().getWaitTime() * 60 * 1000,
true);

this.debugee = debugee;
setServerSocket(debugee.getPipeServerSocket());
}

/**
Expand All @@ -81,12 +81,22 @@ protected IOPipe(Log log, String host, int port, long timeout, boolean listening
super("IOPipe", log, PIPE_LOG_PREFIX, host, port, timeout, listening);
}

protected void connect() {
if (listening) {
setServerSocket(debugee.getPipeServerSocket());
setConnectingProcess(debugee.getProcess());
}
/**
* Creates and starts listening <code>IOPipe</code> at debugger side.
*/
public static IOPipe startDebuggerPipe(Binder binder) {
IOPipe ioPipe = new IOPipe(binder.getLog(),
binder.getArgumentHandler().getDebugeeHost(),
binder.getArgumentHandler().getPipePortNumber(),
(long)binder.getArgumentHandler().getWaitTime() * 60 * 1000,
true);
ioPipe.setServerSocket(binder.getPipeServerSocket());
ioPipe.startListening();
return ioPipe;
}


protected void connect() {
super.connect();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,8 +53,6 @@ class BasicSocketConnection {

protected OutputStream sout = null;

protected Process connectingProcess = null;

protected volatile boolean connected = false;

protected volatile boolean closed = false;
Expand Down Expand Up @@ -257,11 +255,6 @@ public void continueAttach(String host, int port, long timeout) {
} catch (ConnectException e) {
logger.display("Attempt #" + i + " to attach for " + name + " connection failed:\n\t" + e);
lastException = e;
// check if listening process still alive
if (!checkConnectingProcess()) {
shouldStop = true;
throw new Failure("Break attaching to " + name + " connection: " + "listening process exited");
}
// sleep between attempts
try {
Thread.sleep(DebugeeBinder.CONNECT_TRY_DELAY);
Expand Down Expand Up @@ -310,31 +303,6 @@ public Socket getSocket() {
return socket;
}

/**
* Return true if another connecting process is still alive.
*/
public boolean checkConnectingProcess() {
if (connectingProcess == null) {
// no process to check
return true;
}
try {
int exitCode = connectingProcess.exitValue();
} catch (IllegalThreadStateException e) {
// process is still alive
return true;
}
// process exited
return false;
}

/**
* Set another connecting process to control if it is still alive.
*/
public void setConnectingProcess(Process process) {
connectingProcess = process;
}

/**
* Check if connection is established.
*/
Expand Down
87 changes: 66 additions & 21 deletions test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -79,8 +79,6 @@ public class SocketIOPipe extends Log.Logger implements Finalizable {

protected volatile boolean shouldStop;

protected Process connectingProcess;

protected ServerSocket serverSocket;

protected String name;
Expand Down Expand Up @@ -160,10 +158,6 @@ public int getPort() {
return port;
}

protected void setConnectingProcess(Process connectingProcess) {
this.connectingProcess = connectingProcess;
}

protected void setServerSocket(ServerSocket serverSocket) {
this.serverSocket = serverSocket;
if (serverSocket != null)
Expand Down Expand Up @@ -207,6 +201,63 @@ public void close() {
}
}

protected class ListenerThread extends Thread {
private SocketConnection connection;
private RuntimeException error;

ListenerThread() {
super("PipeIO Listener Thread");
setDaemon(true);

connection = new SocketConnection(SocketIOPipe.this, getName());

if (serverSocket == null) {
connection.bind(port, timeout);
} else {
connection.setServerSocket(serverSocket);
}
}

@Override
public void run() {
synchronized (this) {
try {
connection.accept(timeout);
} catch (Throwable th) {
error = th instanceof RuntimeException
? (RuntimeException)th
: new RuntimeException(th);
}
notifyAll();
}
}

public SocketConnection getConnection() {
synchronized (this) {
while (!connection.isConnected() && error != null) {
try {
wait();
} catch (InterruptedException e) {
}
}
if (error != null) {
throw error;
}
return connection;
}
}
}

private ListenerThread listenerThread;

protected void startListening() {
if (listenerThread != null) {
throw new TestBug("already listening");
}
listenerThread = new ListenerThread();
listenerThread.start();
}

/**
* Establish <code>IOPipe</code> connection by attaching or accepting
* connection appropriately.
Expand All @@ -219,23 +270,17 @@ protected void connect() {
if (shouldStop)
return;

connection = new SocketConnection(this, getName());

if (listening) {
connection.setConnectingProcess(connectingProcess);
if (serverSocket == null) {
connection.bind(port, timeout);
} else {
connection.setServerSocket(serverSocket);
// listenerThread == null means the test is not updated yet
// to start IOPipe listening before launching debuggee.
if (listenerThread == null) {
// start listening and accept connection on the current thread
listenerThread = new ListenerThread();
listenerThread.run();
}

if (shouldStop)
return;

// wait for connection from remote host
connection.accept(timeout);

connection = listenerThread.getConnection();
} else {
connection = new SocketConnection(this, getName());
// attach from the debuggee's side
connection.continueAttach(host, port, timeout);
}
Expand Down

1 comment on commit b568e87

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.