|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, 2019, 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 |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package com.oracle.svm.core.jdk; |
| 26 | + |
| 27 | +import java.util.Collection; |
| 28 | +import java.util.List; |
| 29 | +import java.util.concurrent.Callable; |
| 30 | +import java.util.concurrent.ExecutionException; |
| 31 | +import java.util.concurrent.ForkJoinPool; |
| 32 | +import java.util.concurrent.ForkJoinTask; |
| 33 | +import java.util.concurrent.ForkJoinWorkerThread; |
| 34 | +import java.util.concurrent.Future; |
| 35 | +import java.util.concurrent.TimeUnit; |
| 36 | +import java.util.concurrent.TimeoutException; |
| 37 | + |
| 38 | +/** |
| 39 | + * Pure delegate implementation to ForkJoinPool.commonPool(). |
| 40 | + */ |
| 41 | +public final class DeferredCommonPool extends ForkJoinPool { |
| 42 | + |
| 43 | + public DeferredCommonPool() { |
| 44 | + super(1, new DisallowingForkJoinWorkerThreadFactory(), null, false); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public <T> T invoke(ForkJoinTask<T> task) { |
| 49 | + return ForkJoinPool.commonPool().invoke(task); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void execute(ForkJoinTask<?> task) { |
| 54 | + ForkJoinPool.commonPool().execute(task); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void execute(Runnable task) { |
| 59 | + ForkJoinPool.commonPool().execute(task); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public <T> ForkJoinTask<T> submit(ForkJoinTask<T> task) { |
| 64 | + return ForkJoinPool.commonPool().submit(task); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public <T> ForkJoinTask<T> submit(Callable<T> task) { |
| 69 | + return ForkJoinPool.commonPool().submit(task); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public <T> ForkJoinTask<T> submit(Runnable task, T result) { |
| 74 | + return ForkJoinPool.commonPool().submit(task, result); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public ForkJoinTask<?> submit(Runnable task) { |
| 79 | + return ForkJoinPool.commonPool().submit(task); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { |
| 84 | + return ForkJoinPool.commonPool().invokeAll(tasks); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public ForkJoinWorkerThreadFactory getFactory() { |
| 89 | + return ForkJoinPool.commonPool().getFactory(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() { |
| 94 | + return ForkJoinPool.commonPool().getUncaughtExceptionHandler(); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public int getParallelism() { |
| 99 | + return ForkJoinPool.commonPool().getParallelism(); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public int getPoolSize() { |
| 104 | + return ForkJoinPool.commonPool().getPoolSize(); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public boolean getAsyncMode() { |
| 109 | + return ForkJoinPool.commonPool().getAsyncMode(); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public int getRunningThreadCount() { |
| 114 | + return ForkJoinPool.commonPool().getRunningThreadCount(); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public int getActiveThreadCount() { |
| 119 | + return ForkJoinPool.commonPool().getActiveThreadCount(); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public boolean isQuiescent() { |
| 124 | + return ForkJoinPool.commonPool().isQuiescent(); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public long getStealCount() { |
| 129 | + return ForkJoinPool.commonPool().getStealCount(); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public long getQueuedTaskCount() { |
| 134 | + return ForkJoinPool.commonPool().getQueuedTaskCount(); |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public int getQueuedSubmissionCount() { |
| 139 | + return ForkJoinPool.commonPool().getQueuedSubmissionCount(); |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public boolean hasQueuedSubmissions() { |
| 144 | + return ForkJoinPool.commonPool().hasQueuedSubmissions(); |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public String toString() { |
| 149 | + return ForkJoinPool.commonPool().toString(); |
| 150 | + } |
| 151 | + |
| 152 | + @Override |
| 153 | + public void shutdown() { |
| 154 | + ForkJoinPool.commonPool().shutdown(); |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public List<Runnable> shutdownNow() { |
| 159 | + return ForkJoinPool.commonPool().shutdownNow(); |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public boolean isTerminated() { |
| 164 | + return ForkJoinPool.commonPool().isTerminated(); |
| 165 | + } |
| 166 | + |
| 167 | + @Override |
| 168 | + public boolean isTerminating() { |
| 169 | + return ForkJoinPool.commonPool().isTerminating(); |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public boolean isShutdown() { |
| 174 | + return ForkJoinPool.commonPool().isShutdown(); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { |
| 179 | + return ForkJoinPool.commonPool().awaitTermination(timeout, unit); |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public boolean awaitQuiescence(long timeout, TimeUnit unit) { |
| 184 | + return ForkJoinPool.commonPool().awaitQuiescence(timeout, unit); |
| 185 | + } |
| 186 | + |
| 187 | + @Override |
| 188 | + public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { |
| 189 | + return ForkJoinPool.commonPool().invokeAny(tasks); |
| 190 | + } |
| 191 | + |
| 192 | + @Override |
| 193 | + public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { |
| 194 | + return ForkJoinPool.commonPool().invokeAny(tasks, timeout, unit); |
| 195 | + } |
| 196 | + |
| 197 | + @Override |
| 198 | + public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { |
| 199 | + return ForkJoinPool.commonPool().invokeAll(tasks, timeout, unit); |
| 200 | + } |
| 201 | + |
| 202 | + static class DisallowingForkJoinWorkerThreadFactory implements ForkJoinWorkerThreadFactory { |
| 203 | + @Override |
| 204 | + public ForkJoinWorkerThread newThread(ForkJoinPool pool) { |
| 205 | + throw new Error("Deferred ForkJoin.commonPool() delegate should not start its own threads."); |
| 206 | + } |
| 207 | + } |
| 208 | +} |
0 commit comments