8284165: Add pid to process reaper thread name

Reviewed-by: rriggs
This commit is contained in:
Thomas Stuefe 2022-04-05 03:39:39 +00:00
parent 36b3bbc53d
commit 9561b5e041
3 changed files with 32 additions and 25 deletions

View file

@ -140,33 +140,40 @@ final class ProcessHandleImpl implements ProcessHandle {
processReaperExecutor.execute(new Runnable() { processReaperExecutor.execute(new Runnable() {
// Use inner class to avoid lambda stack overhead // Use inner class to avoid lambda stack overhead
public void run() { public void run() {
int exitValue = waitForProcessExit0(pid, shouldReap); String threadName = Thread.currentThread().getName();
if (exitValue == NOT_A_CHILD) { Thread.currentThread().setName("process reaper (pid " + pid + ")");
// pid not alive or not a child of this process try {
// If it is alive wait for it to terminate int exitValue = waitForProcessExit0(pid, shouldReap);
long sleep = 300; // initial milliseconds to sleep if (exitValue == NOT_A_CHILD) {
int incr = 30; // increment to the sleep time // pid not alive or not a child of this process
// If it is alive wait for it to terminate
long sleep = 300; // initial milliseconds to sleep
int incr = 30; // increment to the sleep time
long startTime = isAlive0(pid); long startTime = isAlive0(pid);
long origStart = startTime; long origStart = startTime;
while (startTime >= 0) { while (startTime >= 0) {
try { try {
Thread.sleep(Math.min(sleep, 5000L)); // no more than 5 sec Thread.sleep(Math.min(sleep, 5000L)); // no more than 5 sec
sleep += incr; sleep += incr;
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
// ignore and retry // ignore and retry
} }
startTime = isAlive0(pid); // recheck if it is alive startTime = isAlive0(pid); // recheck if it is alive
if (startTime > 0 && origStart > 0 && startTime != origStart) { if (startTime > 0 && origStart > 0 && startTime != origStart) {
// start time changed (and is not zero), pid is not the same process // start time changed (and is not zero), pid is not the same process
break; break;
}
} }
exitValue = 0;
} }
exitValue = 0; newCompletion.complete(exitValue);
// remove from cache afterwards
completions.remove(pid, newCompletion);
} finally {
// Restore thread name
Thread.currentThread().setName(threadName);
} }
newCompletion.complete(exitValue);
// remove from cache afterwards
completions.remove(pid, newCompletion);
} }
}); });
} }

View file

@ -57,7 +57,7 @@ public class ProcessReaperCCL {
// Verify all "Process Reaper" threads have a null CCL // Verify all "Process Reaper" threads have a null CCL
for (Thread th : Thread.getAllStackTraces().keySet()) { for (Thread th : Thread.getAllStackTraces().keySet()) {
if ("process reaper".equals(th.getName())) { if (th.getName().startsWith("process reaper")) {
Assert.assertEquals(th.getContextClassLoader(), null, "CCL not null"); Assert.assertEquals(th.getContextClassLoader(), null, "CCL not null");
} }
} }

View file

@ -440,7 +440,7 @@ public class Basic {
if ("Finalizer".equals(name) if ("Finalizer".equals(name)
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue; continue;
if ("process reaper".equals(name)) if (name.startsWith("process reaper"))
continue; continue;
if (name != null && name.startsWith("ForkJoinPool.commonPool-worker")) if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
continue; continue;