changeset 17703:2f3d9ed99e66

8173817: StackOverflowError in "process reaper" thread Summary: Switch to inner class to avoid lambda stack overhead in ProcessReaper Reviewed-by: dholmes, martin
author rriggs
date Tue, 22 Aug 2017 09:41:58 -0400
parents f049b1fd90c3
children fe799975105c
files src/java.base/share/classes/java/lang/ProcessHandleImpl.java
diffstat 1 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/ProcessHandleImpl.java	Tue Aug 22 13:08:15 2017 +0200
+++ b/src/java.base/share/classes/java/lang/ProcessHandleImpl.java	Tue Aug 22 09:41:58 2017 -0400
@@ -132,34 +132,37 @@
                 // newCompletion has just been installed successfully
                 completion = newCompletion;
                 // spawn a thread to wait for and deliver the exit value
-                processReaperExecutor.execute(() -> {
-                    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
+                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
+                            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 is alive
+                                if (origStart > 0 && startTime != origStart) {
+                                    // start time changed, pid is not the same process
+                                    break;
+                                }
                             }
-                            startTime = isAlive0(pid);  // recheck if is alive
-                            if (origStart > 0 && startTime != origStart) {
-                                // start time changed, pid is not the same process
-                                break;
-                            }
+                            exitValue = 0;
                         }
-                        exitValue = 0;
+                        newCompletion.complete(exitValue);
+                        // remove from cache afterwards
+                        completions.remove(pid, newCompletion);
                     }
-                    newCompletion.complete(exitValue);
-                    // remove from cache afterwards
-                    completions.remove(pid, newCompletion);
                 });
             }
         }