8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
Add more diagnostic to attach code Reviewed-by: dholmes, alanb
This commit is contained in:
parent
a283244f86
commit
b022343185
jdk/src/jdk.attach
aix/classes/sun/tools/attach
linux/classes/sun/tools/attach
macosx
share/classes/sun/tools/attach
solaris/classes/sun/tools/attach
@ -76,20 +76,29 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
sendQuitTo(pid);
|
||||
|
||||
// give the target VM time to start the attach mechanism
|
||||
int i = 0;
|
||||
long delay = 200;
|
||||
int retries = (int)(attachTimeout() / delay);
|
||||
final int delay_step = 100;
|
||||
final long timeout = attachTimeout();
|
||||
long time_spend = 0;
|
||||
long delay = 0;
|
||||
do {
|
||||
// Increase timeout on each attempt to reduce polling
|
||||
delay += delay_step;
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException x) { }
|
||||
path = findSocketFile(pid);
|
||||
i++;
|
||||
} while (i <= retries && path == null);
|
||||
|
||||
time_spend += delay;
|
||||
if (time_spend > timeout/2 && path == null) {
|
||||
// Send QUIT again to give target VM the last chance to react
|
||||
sendQuitTo(pid);
|
||||
}
|
||||
} while (time_spend <= timeout && path == null);
|
||||
if (path == null) {
|
||||
throw new AttachNotSupportedException(
|
||||
"Unable to open socket file: target process not responding " +
|
||||
"or HotSpot VM not loaded");
|
||||
String.format("Unable to open socket file %s: " +
|
||||
"target process %d doesn't respond within %dms " +
|
||||
"or HotSpot VM not loaded", f.getPath(), pid, time_spend));
|
||||
}
|
||||
} finally {
|
||||
f.delete();
|
||||
|
@ -44,9 +44,6 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
// Any changes to this needs to be synchronized with HotSpot.
|
||||
private static final String tmpdir = "/tmp";
|
||||
|
||||
// Indicates if this machine uses the old LinuxThreads
|
||||
static boolean isLinuxThreads;
|
||||
|
||||
// The patch to the socket file created by the target VM
|
||||
String path;
|
||||
|
||||
@ -73,44 +70,37 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
if (path == null) {
|
||||
File f = createAttachFile(pid);
|
||||
try {
|
||||
// On LinuxThreads each thread is a process and we don't have the
|
||||
// pid of the VMThread which has SIGQUIT unblocked. To workaround
|
||||
// this we get the pid of the "manager thread" that is created
|
||||
// by the first call to pthread_create. This is parent of all
|
||||
// threads (except the initial thread).
|
||||
if (isLinuxThreads) {
|
||||
int mpid;
|
||||
try {
|
||||
mpid = getLinuxThreadsManager(pid);
|
||||
} catch (IOException x) {
|
||||
throw new AttachNotSupportedException(x.getMessage());
|
||||
}
|
||||
assert(mpid >= 1);
|
||||
sendQuitToChildrenOf(mpid);
|
||||
} else {
|
||||
sendQuitTo(pid);
|
||||
}
|
||||
sendQuitTo(pid);
|
||||
|
||||
// give the target VM time to start the attach mechanism
|
||||
int i = 0;
|
||||
long delay = 200;
|
||||
int retries = (int)(attachTimeout() / delay);
|
||||
final int delay_step = 100;
|
||||
final long timeout = attachTimeout();
|
||||
long time_spend = 0;
|
||||
long delay = 0;
|
||||
do {
|
||||
// Increase timeout on each attempt to reduce polling
|
||||
delay += delay_step;
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException x) { }
|
||||
path = findSocketFile(pid);
|
||||
i++;
|
||||
} while (i <= retries && path == null);
|
||||
|
||||
time_spend += delay;
|
||||
if (time_spend > timeout/2 && path == null) {
|
||||
// Send QUIT again to give target VM the last chance to react
|
||||
sendQuitTo(pid);
|
||||
}
|
||||
} while (time_spend <= timeout && path == null);
|
||||
if (path == null) {
|
||||
throw new AttachNotSupportedException(
|
||||
"Unable to open socket file: target process not responding " +
|
||||
"or HotSpot VM not loaded");
|
||||
String.format("Unable to open socket file %s: " +
|
||||
"target process %d doesn't respond within %dms " +
|
||||
"or HotSpot VM not loaded", f.getPath(), pid, time_spend));
|
||||
}
|
||||
} finally {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the file owner/permission to avoid attaching to
|
||||
// bogus process
|
||||
@ -340,6 +330,5 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
|
||||
static {
|
||||
System.loadLibrary("attach");
|
||||
isLinuxThreads = isLinuxThreads();
|
||||
}
|
||||
}
|
||||
|
@ -70,26 +70,34 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
// Then we attempt to find the socket file again.
|
||||
path = findSocketFile(pid);
|
||||
if (path == null) {
|
||||
File f = new File(tmpdir, ".attach_pid" + pid);
|
||||
createAttachFile(f.getPath());
|
||||
File f = createAttachFile(pid);
|
||||
try {
|
||||
sendQuitTo(pid);
|
||||
|
||||
// give the target VM time to start the attach mechanism
|
||||
int i = 0;
|
||||
long delay = 200;
|
||||
int retries = (int)(attachTimeout() / delay);
|
||||
final int delay_step = 100;
|
||||
final long timeout = attachTimeout();
|
||||
long time_spend = 0;
|
||||
long delay = 0;
|
||||
do {
|
||||
// Increase timeout on each attempt to reduce polling
|
||||
delay += delay_step;
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException x) { }
|
||||
path = findSocketFile(pid);
|
||||
i++;
|
||||
} while (i <= retries && path == null);
|
||||
|
||||
time_spend += delay;
|
||||
if (time_spend > timeout/2 && path == null) {
|
||||
// Send QUIT again to give target VM the last chance to react
|
||||
sendQuitTo(pid);
|
||||
}
|
||||
} while (time_spend <= timeout && path == null);
|
||||
if (path == null) {
|
||||
throw new AttachNotSupportedException(
|
||||
"Unable to open socket file: target process not responding " +
|
||||
"or HotSpot VM not loaded");
|
||||
String.format("Unable to open socket file %s: " +
|
||||
"target process %d doesn't respond within %dms " +
|
||||
"or HotSpot VM not loaded", f.getPath(), pid, time_spend));
|
||||
}
|
||||
} finally {
|
||||
f.delete();
|
||||
@ -282,6 +290,12 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
write(fd, b, 0, 1);
|
||||
}
|
||||
|
||||
private File createAttachFile(int pid) throws IOException {
|
||||
String fn = ".attach_pid" + pid;
|
||||
File f = new File(tmpdir, fn);
|
||||
createAttachFile0(f.getPath());
|
||||
return f;
|
||||
}
|
||||
|
||||
//-- native methods
|
||||
|
||||
@ -299,7 +313,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
|
||||
static native void write(int fd, byte buf[], int off, int bufLen) throws IOException;
|
||||
|
||||
static native void createAttachFile(String path);
|
||||
static native void createAttachFile0(String path);
|
||||
|
||||
static native String getTempDir();
|
||||
|
||||
|
@ -270,7 +270,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_write
|
||||
* Method: createAttachFile
|
||||
* Signature: (Ljava.lang.String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_createAttachFile(JNIEnv *env, jclass cls, jstring path)
|
||||
JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_createAttachFile0(JNIEnv *env, jclass cls, jstring path)
|
||||
{
|
||||
const char* _path;
|
||||
jboolean isCopy;
|
||||
|
@ -319,7 +319,7 @@ public abstract class HotSpotVirtualMachine extends VirtualMachine {
|
||||
|
||||
// -- attach timeout support
|
||||
|
||||
private static long defaultAttachTimeout = 5000;
|
||||
private static long defaultAttachTimeout = 10000;
|
||||
private volatile long attachTimeout;
|
||||
|
||||
/*
|
||||
|
@ -71,27 +71,36 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
|
||||
} catch (FileNotFoundException fnf1) {
|
||||
File f = createAttachFile(pid);
|
||||
try {
|
||||
// kill -QUIT will tickle target VM to check for the
|
||||
// attach file.
|
||||
sigquit(pid);
|
||||
|
||||
// give the target VM time to start the attach mechanism
|
||||
int i = 0;
|
||||
long delay = 200;
|
||||
int retries = (int)(attachTimeout() / delay);
|
||||
final int delay_step = 100;
|
||||
final long timeout = attachTimeout();
|
||||
long time_spend = 0;
|
||||
long delay = 0;
|
||||
do {
|
||||
// Increase timeout on each attempt to reduce polling
|
||||
delay += delay_step;
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException x) { }
|
||||
try {
|
||||
fd = openDoor(pid);
|
||||
} catch (FileNotFoundException fnf2) { }
|
||||
i++;
|
||||
} while (i <= retries && fd == -1);
|
||||
if (fd == -1) {
|
||||
} catch (FileNotFoundException fnf2) {
|
||||
// pass
|
||||
}
|
||||
|
||||
time_spend += delay;
|
||||
if (time_spend > timeout/2 && fd == -1) {
|
||||
// Send QUIT again to give target VM the last chance to react
|
||||
sigquit(pid);
|
||||
}
|
||||
} while (time_spend <= timeout && fd == -1);
|
||||
if (fd == -1) {
|
||||
throw new AttachNotSupportedException(
|
||||
"Unable to open door: target process not responding or " +
|
||||
"HotSpot VM not loaded");
|
||||
String.format("Unable to open door %s: " +
|
||||
"target process %d doesn't respond within %dms " +
|
||||
"or HotSpot VM not loaded", f.getPath(), pid, time_spend));
|
||||
}
|
||||
} finally {
|
||||
f.delete();
|
||||
|
Loading…
x
Reference in New Issue
Block a user