Skip to content

Commit 3c47b03

Browse files
committed
Anti-delta FJP update for now due to worker spinning
1 parent 7bfa146 commit 3c47b03

File tree

2 files changed

+27
-50
lines changed

2 files changed

+27
-50
lines changed

src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -792,25 +792,25 @@ static final class DefaultForkJoinWorkerThreadFactory
792792
private static final AccessControlContext ACC = contextWithPermissions(
793793
new RuntimePermission("getClassLoader"),
794794
new RuntimePermission("setContextClassLoader"));
795+
795796
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
796797
return AccessController.doPrivileged(
797798
new PrivilegedAction<>() {
798799
public ForkJoinWorkerThread run() {
799-
return new ForkJoinWorkerThread(null, pool, true, false);
800+
return new ForkJoinWorkerThread(null, pool, true, true);
800801
}},
801802
ACC);
802803
}
803804
}
804805

805806
/**
806-
* Factory for CommonPool unless overridded by System
807-
* property. Creates InnocuousForkJoinWorkerThreads if a security
808-
* manager is present at time of invocation. Support requires that
809-
* we break quite a lot of encapsulation (some via helper methods
810-
* in ThreadLocalRandom) to access and set Thread fields.
807+
* Factory for InnocuousForkJoinWorkerThread. Support requires
808+
* that we break quite a lot of encapsulation (some via helper
809+
* methods in ThreadLocalRandom) to access and set Thread fields.
811810
*/
812-
static final class DefaultCommonPoolForkJoinWorkerThreadFactory
811+
static final class InnocuousForkJoinWorkerThreadFactory
813812
implements ForkJoinWorkerThreadFactory {
813+
// ACC for access to the factory
814814
private static final AccessControlContext ACC = contextWithPermissions(
815815
modifyThreadPermission,
816816
new RuntimePermission("enableContextClassLoaderOverride"),
@@ -820,13 +820,11 @@ static final class DefaultCommonPoolForkJoinWorkerThreadFactory
820820

821821
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
822822
return AccessController.doPrivileged(
823-
new PrivilegedAction<>() {
824-
public ForkJoinWorkerThread run() {
825-
return System.getSecurityManager() == null ?
826-
new ForkJoinWorkerThread(null, pool, true, true):
827-
new ForkJoinWorkerThread.
828-
InnocuousForkJoinWorkerThread(pool); }},
829-
ACC);
823+
new PrivilegedAction<>() {
824+
public ForkJoinWorkerThread run() {
825+
return new ForkJoinWorkerThread.
826+
InnocuousForkJoinWorkerThread(pool); }},
827+
ACC);
830828
}
831829
}
832830

@@ -1712,19 +1710,11 @@ else if (deadline != 0L)
17121710
// Utilities used by ForkJoinTask
17131711

17141712
/**
1715-
* Returns true if all workers are busy, possibly creating one if allowed
1713+
* Returns true if all workers are busy
17161714
*/
17171715
final boolean isSaturated() {
1718-
int maxTotal = bounds >>> SWIDTH;
1719-
for (long c;;) {
1720-
if (((int)(c = ctl) & ~UNSIGNALLED) != 0)
1721-
return false;
1722-
if ((short)(c >>> TC_SHIFT) >= maxTotal)
1723-
return true;
1724-
long nc = ((c + TC_UNIT) & TC_MASK) | (c & ~TC_MASK);
1725-
if (compareAndSetCtl(c, nc))
1726-
return !createWorker();
1727-
}
1716+
long c;
1717+
return (int)((c = ctl) >> RC_SHIFT) >= 0 && ((int)c & ~UNSIGNALLED) == 0;
17281718
}
17291719

17301720
/**
@@ -1787,7 +1777,7 @@ private int tryCompensate(long c) {
17871777
}
17881778
return -1; // retry
17891779
}
1790-
else if (active - minActive > 1) { // reduce parallelism
1780+
else if (active > minActive) { // reduce parallelism
17911781
long nc = ((RC_MASK & (c - RC_UNIT)) | (~RC_MASK & c));
17921782
return compareAndSetCtl(c, nc) ? UNCOMPENSATE : -1;
17931783
}
@@ -2544,7 +2534,9 @@ private ForkJoinPool(byte forCommonPoolOnly) {
25442534
int p = this.mode = Math.min(Math.max(parallelism, 0), MAX_CAP);
25452535
int size = 1 << (33 - Integer.numberOfLeadingZeros(p > 0 ? p - 1 : 1));
25462536
this.factory = (fac != null) ? fac :
2547-
new DefaultCommonPoolForkJoinWorkerThreadFactory();
2537+
(System.getSecurityManager() == null ?
2538+
defaultForkJoinWorkerThreadFactory :
2539+
new InnocuousForkJoinWorkerThreadFactory());
25482540
this.ueh = handler;
25492541
this.keepAlive = DEFAULT_KEEPALIVE;
25502542
this.saturate = null;
@@ -2684,10 +2676,7 @@ public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
26842676
ForkJoinTask<T> f =
26852677
new ForkJoinTask.AdaptedInterruptibleCallable<T>(t);
26862678
futures.add(f);
2687-
if (isSaturated())
2688-
f.doExec();
2689-
else
2690-
externalSubmit(f);
2679+
externalSubmit(f);
26912680
}
26922681
for (int i = futures.size() - 1; i >= 0; --i)
26932682
((ForkJoinTask<?>)futures.get(i)).quietlyJoin();
@@ -2710,10 +2699,7 @@ public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
27102699
ForkJoinTask<T> f =
27112700
new ForkJoinTask.AdaptedInterruptibleCallable<T>(t);
27122701
futures.add(f);
2713-
if (isSaturated())
2714-
f.doExec();
2715-
else
2716-
externalSubmit(f);
2702+
externalSubmit(f);
27172703
}
27182704
long startTime = System.nanoTime(), ns = nanos;
27192705
boolean timedOut = (ns < 0L);
@@ -2749,22 +2735,14 @@ static final class InvokeAnyRoot<E> extends ForkJoinTask<E> {
27492735
final AtomicInteger count; // in case all throw
27502736
InvokeAnyRoot(int n) { count = new AtomicInteger(n); }
27512737
final void tryComplete(Callable<E> c) { // called by InvokeAnyTasks
2752-
Throwable ex = null;
2753-
boolean failed = false;
2754-
if (c != null) { // raciness OK
2755-
if (isCancelled())
2756-
failed = true;
2757-
else if (!isDone()) {
2758-
try {
2759-
complete(c.call());
2760-
} catch (Throwable tx) {
2761-
ex = tx;
2762-
failed = true;
2763-
}
2738+
if (c != null && !isDone()) { // raciness OK
2739+
try {
2740+
complete(c.call());
2741+
} catch (Throwable ex) {
2742+
if (count.getAndDecrement() <= 1)
2743+
trySetThrown(ex);
27642744
}
27652745
}
2766-
if (failed && count.getAndDecrement() <= 1)
2767-
trySetThrown(ex != null ? ex : new CancellationException());
27682746
}
27692747
public final boolean exec() { return false; } // never forked
27702748
public final E getRawResult() { return result; }

test/jdk/java/lang/Thread/virtual/WithDeadlineTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public Object[][] executors() {
6363
{ Executors.newCachedThreadPool() },
6464
{ Executors.newFixedThreadPool(1) },
6565
{ new ForkJoinPool() },
66-
{ new ForkJoinPool(1) },
6766
};
6867
}
6968

0 commit comments

Comments
 (0)