1 /*
2 * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
70 /**
71 * Map of pids to ExitCompletions.
72 */
73 private static final ConcurrentMap<Long, ExitCompletion>
74 completions = new ConcurrentHashMap<>();
75
76 static {
77 initNative();
78 long pid = getCurrentPid0();
79 current = new ProcessHandleImpl(pid, isAlive0(pid));
80 }
81
82 private static native void initNative();
83
84 /**
85 * The thread pool of "process reaper" daemon threads.
86 */
87 private static final Executor processReaperExecutor = initReaper();
88
89 private static Executor initReaper() {
90 // Initialize ThreadLocalRandom now to avoid using the smaller stack
91 // of the processReaper threads.
92 ThreadLocalRandom.current();
93
94 // For a debug build, the stack shadow zone is larger;
95 // Increase the total stack size to avoid potential stack overflow.
96 int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4 * 4096);
97 final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
98 ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
99
100 ThreadFactory threadFactory = grimReaper -> {
101 Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
102 stackSize, Thread.MAX_PRIORITY);
103 t.setDaemon(true);
104 return t;
105 };
106
107 return Executors.newCachedThreadPool(threadFactory);
108 }
109
110 private static class ExitCompletion extends CompletableFuture<Integer> {
111 final boolean isReaping;
112
113 ExitCompletion(boolean isReaping) {
114 this.isReaping = isReaping;
115 }
116 }
|
1 /*
2 * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
70 /**
71 * Map of pids to ExitCompletions.
72 */
73 private static final ConcurrentMap<Long, ExitCompletion>
74 completions = new ConcurrentHashMap<>();
75
76 static {
77 initNative();
78 long pid = getCurrentPid0();
79 current = new ProcessHandleImpl(pid, isAlive0(pid));
80 }
81
82 private static native void initNative();
83
84 /**
85 * The thread pool of "process reaper" daemon threads.
86 */
87 private static final Executor processReaperExecutor = initReaper();
88
89 private static Executor initReaper() {
90 // Initialize ThreadLocalRandom and now to avoid using the smaller stack
91 // of the processReaper threads.
92 ThreadLocalRandom.current();
93 // For a debug build, the stack shadow zone is larger;
94 // Increase the total stack size to avoid potential stack overflow.
95 int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096);
96 final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
97 ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
98
99 ThreadFactory threadFactory = grimReaper -> {
100 Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
101 stackSize, Thread.MAX_PRIORITY);
102 t.setDaemon(true);
103 return t;
104 };
105
106 return Executors.newCachedThreadPool(threadFactory);
107 }
108
109 private static class ExitCompletion extends CompletableFuture<Integer> {
110 final boolean isReaping;
111
112 ExitCompletion(boolean isReaping) {
113 this.isReaping = isReaping;
114 }
115 }
|