Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of ForkJoinPool #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -209,6 +210,13 @@ public Builder extension(TinyRemapper.Extension extension) {
extension.attach(this);
return this;
}

public Builder useForkJoinPool() {
ForkJoinPool pool = ForkJoinPool.commonPool();
this.threadCount = pool.getParallelism();
this.service = pool;
return this;
}

public TinyRemapper build() {
TinyRemapper remapper = new TinyRemapper(mappingProviders, ignoreFieldDesc, threadCount,
Expand All @@ -218,7 +226,7 @@ public TinyRemapper build() {
removeFrames, ignoreConflicts, resolveMissing, checkPackageAccess || fixPackageAccess, fixPackageAccess,
rebuildSourceFilenames, skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex,
analyzeVisitors, stateProcessors, preApplyVisitors, postApplyVisitors,
extraRemapper);
extraRemapper, service);

return remapper;
}
Expand Down Expand Up @@ -246,6 +254,7 @@ public TinyRemapper build() {
private final List<ApplyVisitorProvider> preApplyVisitors = new ArrayList<>();
private final List<ApplyVisitorProvider> postApplyVisitors = new ArrayList<>();
private Remapper extraRemapper;
private ExecutorService service;
}

public interface Extension {
Expand Down Expand Up @@ -279,12 +288,12 @@ private TinyRemapper(Collection<IMappingProvider> mappingProviders, boolean igno
boolean renameInvalidLocals, Pattern invalidLvNamePattern, boolean inferNameFromSameLvIndex,
List<AnalyzeVisitorProvider> analyzeVisitors, List<StateProcessor> stateProcessors,
List<ApplyVisitorProvider> preApplyVisitors, List<ApplyVisitorProvider> postApplyVisitors,
Remapper extraRemapper) {
Remapper extraRemapper, ExecutorService service) {
this.mappingProviders = mappingProviders;
this.ignoreFieldDesc = ignoreFieldDesc;
this.threadCount = threadCount > 0 ? threadCount : Math.max(Runtime.getRuntime().availableProcessors(), 2);
this.keepInputData = keepInputData;
this.threadPool = Executors.newFixedThreadPool(this.threadCount);
this.threadPool = service == null ? Executors.newFixedThreadPool(this.threadCount) : service;
this.forcePropagation = forcePropagation;
this.propagatePrivate = propagatePrivate;
this.propagateBridges = propagateBridges;
Expand All @@ -311,12 +320,16 @@ public static Builder newRemapper() {
}

public void finish() {
threadPool.shutdown();

try {
threadPool.awaitTermination(20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
if(threadPool == ForkJoinPool.commonPool()) {
((ForkJoinPool)threadPool).awaitQuiescence(20, TimeUnit.SECONDS);
} else {
threadPool.shutdown();

try {
threadPool.awaitTermination(20, TimeUnit.SECONDS);
} catch(InterruptedException e) {
e.printStackTrace();
}
}

outputBuffer = null;
Expand Down