Skip to content

Commit

Permalink
8284165: Add pid to process reaper thread name
Browse files Browse the repository at this point in the history
Reviewed-by: rriggs
  • Loading branch information
tstuefe committed Apr 5, 2022
1 parent 36b3bbc commit 9561b5e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
55 changes: 31 additions & 24 deletions src/java.base/share/classes/java/lang/ProcessHandleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,40 @@ static CompletableFuture<Integer> completion(long pid, boolean shouldReap) {
processReaperExecutor.execute(new Runnable() {
// Use inner class to avoid lambda stack overhead
public void run() {
int exitValue = waitForProcessExit0(pid, shouldReap);
if (exitValue == NOT_A_CHILD) {
// 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 origStart = startTime;
while (startTime >= 0) {
try {
Thread.sleep(Math.min(sleep, 5000L)); // no more than 5 sec
sleep += incr;
} catch (InterruptedException ie) {
// ignore and retry
}
startTime = isAlive0(pid); // recheck if it is alive
if (startTime > 0 && origStart > 0 && startTime != origStart) {
// start time changed (and is not zero), pid is not the same process
break;
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName("process reaper (pid " + pid + ")");
try {
int exitValue = waitForProcessExit0(pid, shouldReap);
if (exitValue == NOT_A_CHILD) {
// 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 origStart = startTime;
while (startTime >= 0) {
try {
Thread.sleep(Math.min(sleep, 5000L)); // no more than 5 sec
sleep += incr;
} catch (InterruptedException ie) {
// ignore and retry
}
startTime = isAlive0(pid); // recheck if it is alive
if (startTime > 0 && origStart > 0 && startTime != origStart) {
// start time changed (and is not zero), pid is not the same process
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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/java/lang/ProcessBuilder/ProcessReaperCCL.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void test() throws Exception {

// Verify all "Process Reaper" threads have a null CCL
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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/java/util/concurrent/Phaser/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ static void dumpTestThreads() {
if ("Finalizer".equals(name)
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue;
if ("process reaper".equals(name))
if (name.startsWith("process reaper"))
continue;
if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
continue;
Expand Down

5 comments on commit 9561b5e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@tstuefe
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 9561b5e Jan 10, 2023

Choose a reason for hiding this comment

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

@tstuefe Could not automatically backport 9561b5e0 to openjdk/jdk17u-dev due to conflicts in the following files:

  • test/jdk/java/lang/ProcessBuilder/ProcessReaperCCL.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b tstuefe-backport-9561b5e0

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk 9561b5e041c4cc70319e60953819c521c1e68d6c

# Backport the commit
$ git cherry-pick --no-commit 9561b5e041c4cc70319e60953819c521c1e68d6c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 9561b5e041c4cc70319e60953819c521c1e68d6c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 9561b5e041c4cc70319e60953819c521c1e68d6c.

@tstuefe
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 9561b5e Feb 14, 2023

Choose a reason for hiding this comment

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

@tstuefe Could not automatically backport 9561b5e0 to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/jdk/java/lang/ProcessBuilder/ProcessReaperCCL.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b tstuefe-backport-9561b5e0

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk 9561b5e041c4cc70319e60953819c521c1e68d6c

# Backport the commit
$ git cherry-pick --no-commit 9561b5e041c4cc70319e60953819c521c1e68d6c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 9561b5e041c4cc70319e60953819c521c1e68d6c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 9561b5e041c4cc70319e60953819c521c1e68d6c.

Please sign in to comment.