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 }
|
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 ValueObjectMethods now to avoid using the smaller stack
91 // of the processReaper threads.
92 ThreadLocalRandom.current();
93 try {
94 Class.forName("java.lang.runtime.ValueObjectMethods$MethodHandleBuilder", true, null);
95 } catch (ClassNotFoundException cnfe) {
96 throw new InternalError("unable to initialize ValueObjectMethodds", cnfe);
97 }
98 // For a debug build, the stack shadow zone is larger;
99 // Increase the total stack size to avoid potential stack overflow.
100 int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096);
101 final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
102 ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
103
104 ThreadFactory threadFactory = grimReaper -> {
105 Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
106 stackSize, Thread.MAX_PRIORITY);
107 t.setDaemon(true);
108 return t;
109 };
110
111 return Executors.newCachedThreadPool(threadFactory);
112 }
113
114 private static class ExitCompletion extends CompletableFuture<Integer> {
115 final boolean isReaping;
116
117 ExitCompletion(boolean isReaping) {
118 this.isReaping = isReaping;
119 }
120 }
|