Skip to content

Commit fe2bdb1

Browse files
committed
[GR-48230] Use common pool for class loading, analysis, and compilation.
PullRequest: graal/15762
2 parents 8b67e3f + 72876c8 commit fe2bdb1

File tree

34 files changed

+285
-491
lines changed

34 files changed

+285
-491
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/options/OptionKey.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,26 @@ public final void setDescriptor(OptionDescriptor descriptor) {
5050

5151
/**
5252
* Returns the descriptor for this option, if it has been set by
53-
* {@link #setDescriptor(OptionDescriptor)}.
53+
* {@link #setDescriptor(OptionDescriptor)}. As descriptors are loaded lazily, this method will
54+
* return {@code null} if the descriptors have not been loaded. Use {@link #loadDescriptor}
55+
* instead to ensure a non-null descriptor is returned if available.
5456
*/
5557
public final OptionDescriptor getDescriptor() {
5658
return descriptor;
5759
}
5860

61+
/**
62+
* Returns the descriptor for this option, triggering loading of descriptors if this descriptor
63+
* is null. Note that it's still possible for this method to return null if this option does not
64+
* have a descriptor created by a service loader.
65+
*/
66+
public final OptionDescriptor loadDescriptor() {
67+
if (descriptor == null) {
68+
Lazy.init();
69+
}
70+
return descriptor;
71+
}
72+
5973
/**
6074
* Checks that a descriptor exists for this key after triggering loading of descriptors.
6175
*/

docs/reference-manual/native-image/BuildOutput.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ By default, the build process tries to only use free memory (to avoid memory pre
137137
If less than 8GB of memory are free, the build process falls back to use 85% of total memory.
138138
Therefore, consider freeing up memory if your machine is slow during a build, for example, by closing applications that you do not need.
139139
140-
By default, the build process uses all available CPU cores to maximize speed.
140+
By default, the build process uses all available processors to maximize speed, but not more than 32 threads.
141141
Use the `--parallelism` option to set the number of threads explicitly (for example, `--parallelism=4`).
142142
Use fewer threads to reduce load on your system as well as memory consumption (at the cost of a slower build process).
143143

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.nio.file.Paths;
3838
import java.util.ArrayList;
3939
import java.util.List;
40-
import java.util.concurrent.ForkJoinPool;
4140

4241
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
4342
import jdk.graal.compiler.debug.DebugContext;
@@ -52,7 +51,6 @@
5251

5352
import com.oracle.graal.pointsto.AnalysisObjectScanningObserver;
5453
import com.oracle.graal.pointsto.AnalysisPolicy;
55-
import com.oracle.graal.pointsto.PointsToAnalysis;
5654
import com.oracle.graal.pointsto.api.PointstoOptions;
5755
import com.oracle.graal.pointsto.flow.context.bytecode.BytecodeSensitiveAnalysisPolicy;
5856
import com.oracle.graal.pointsto.heap.HeapSnapshotVerifier;
@@ -135,7 +133,6 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
135133
SnippetReflectionProvider snippetReflection = originalProviders.getSnippetReflection();
136134
MetaAccessProvider originalMetaAccess = originalProviders.getMetaAccess();
137135
debugContext = new DebugContext.Builder(options, new GraalDebugHandlersFactory(snippetReflection)).build();
138-
ForkJoinPool executor = PointsToAnalysis.createExecutor(debugContext, Math.min(Runtime.getRuntime().availableProcessors(), 32));
139136
StandaloneHost standaloneHost = new StandaloneHost(options, analysisClassLoader);
140137
int wordSize = getWordSize();
141138
AnalysisPolicy analysisPolicy = PointstoOptions.AllocationSiteSensitiveHeap.getValue(options) ? new BytecodeSensitiveAnalysisPolicy(options)
@@ -154,7 +151,8 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
154151
originalProviders.getPlatformConfigurationProvider(), aMetaAccessExtensionProvider, originalProviders.getLoopsDataProvider());
155152
standaloneHost.initializeProviders(aProviders);
156153
analysisName = getAnalysisName(mainEntryClass);
157-
bigbang = new StandalonePointsToAnalysis(options, aUniverse, standaloneHost, aMetaAccess, snippetReflection, aConstantReflection, aProviders.getWordTypes(), executor, new TimerCollection());
154+
bigbang = new StandalonePointsToAnalysis(options, aUniverse, standaloneHost, aMetaAccess, snippetReflection, aConstantReflection, aProviders.getWordTypes(), debugContext,
155+
new TimerCollection());
158156
standaloneHost.setImageName(analysisName);
159157
aUniverse.setBigBang(bigbang);
160158
ImageHeap heap = new ImageHeap();

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/StandalonePointsToAnalysis.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828

2929
import java.util.Set;
3030
import java.util.concurrent.ConcurrentHashMap;
31-
import java.util.concurrent.ForkJoinPool;
32-
33-
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
34-
import jdk.graal.compiler.options.OptionValues;
35-
import jdk.graal.compiler.word.WordTypes;
3631

3732
import com.oracle.graal.pointsto.PointsToAnalysis;
3833
import com.oracle.graal.pointsto.api.HostVM;
@@ -43,17 +38,18 @@
4338
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
4439
import com.oracle.graal.pointsto.util.TimerCollection;
4540

41+
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
42+
import jdk.graal.compiler.debug.DebugContext;
43+
import jdk.graal.compiler.options.OptionValues;
44+
import jdk.graal.compiler.word.WordTypes;
4645
import jdk.vm.ci.meta.ConstantReflectionProvider;
4746

4847
public class StandalonePointsToAnalysis extends PointsToAnalysis {
4948
private final Set<AnalysisMethod> addedClinits = ConcurrentHashMap.newKeySet();
5049

51-
public StandalonePointsToAnalysis(OptionValues options, AnalysisUniverse universe, HostVM hostVM,
52-
AnalysisMetaAccess metaAccess, SnippetReflectionProvider snippetReflectionProvider,
53-
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes,
54-
ForkJoinPool executorService, TimerCollection timerCollection) {
55-
super(options, universe, hostVM, metaAccess, snippetReflectionProvider, constantReflectionProvider, wordTypes, executorService, new UnsupportedFeatures(), timerCollection,
56-
true);
50+
public StandalonePointsToAnalysis(OptionValues options, AnalysisUniverse universe, HostVM hostVM, AnalysisMetaAccess metaAccess, SnippetReflectionProvider snippetReflectionProvider,
51+
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes, DebugContext debugContext, TimerCollection timerCollection) {
52+
super(options, universe, hostVM, metaAccess, snippetReflectionProvider, constantReflectionProvider, wordTypes, new UnsupportedFeatures(), debugContext, timerCollection, true);
5753
}
5854

5955
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/AbstractAnalysisEngine.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.PrintWriter;
2828
import java.util.Collections;
2929
import java.util.List;
30-
import java.util.concurrent.ForkJoinPool;
3130
import java.util.function.Function;
3231

3332
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
@@ -101,7 +100,7 @@ public abstract class AbstractAnalysisEngine implements BigBang {
101100

102101
@SuppressWarnings("this-escape")
103102
public AbstractAnalysisEngine(OptionValues options, AnalysisUniverse universe, HostVM hostVM, AnalysisMetaAccess metaAccess, SnippetReflectionProvider snippetReflectionProvider,
104-
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes, ForkJoinPool executorService, UnsupportedFeatures unsupportedFeatures,
103+
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes, UnsupportedFeatures unsupportedFeatures, DebugContext debugContext,
105104
TimerCollection timerCollection) {
106105
this.options = options;
107106
this.universe = universe;
@@ -110,7 +109,7 @@ public AbstractAnalysisEngine(OptionValues options, AnalysisUniverse universe, H
110109
this.metaAccess = metaAccess;
111110
this.analysisPolicy = universe.analysisPolicy();
112111
this.hostVM = hostVM;
113-
this.executor = new CompletionExecutor(this, executorService);
112+
this.executor = new CompletionExecutor(debugContext, this);
114113
this.unsupportedFeatures = unsupportedFeatures;
115114

116115
this.processFeaturesTimer = timerCollection.get(TimerCollection.Registry.FEATURES);

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/PointsToAnalysis.java

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,11 @@
3737
import java.util.Map;
3838
import java.util.concurrent.ConcurrentHashMap;
3939
import java.util.concurrent.ConcurrentMap;
40-
import java.util.concurrent.ForkJoinPool;
41-
import java.util.concurrent.ForkJoinWorkerThread;
4240
import java.util.concurrent.atomic.AtomicLong;
4341
import java.util.concurrent.atomic.AtomicLongArray;
4442
import java.util.function.Consumer;
4543
import java.util.stream.StreamSupport;
4644

47-
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
48-
import jdk.graal.compiler.core.common.SuppressFBWarnings;
49-
import jdk.graal.compiler.debug.DebugContext;
50-
import jdk.graal.compiler.debug.Indent;
51-
import jdk.graal.compiler.graph.Node;
52-
import jdk.graal.compiler.graph.NodeList;
53-
import jdk.graal.compiler.options.OptionValues;
54-
import jdk.graal.compiler.word.WordTypes;
55-
5645
import com.oracle.graal.pointsto.api.HostVM;
5746
import com.oracle.graal.pointsto.api.PointstoOptions;
5847
import com.oracle.graal.pointsto.constraints.UnsupportedFeatures;
@@ -84,8 +73,14 @@
8473
import com.oracle.graal.pointsto.util.TimerCollection;
8574
import com.oracle.svm.common.meta.MultiMethod;
8675
import com.oracle.svm.util.ClassUtil;
87-
import com.oracle.svm.util.ImageGeneratorThreadMarker;
8876

77+
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
78+
import jdk.graal.compiler.debug.DebugContext;
79+
import jdk.graal.compiler.debug.Indent;
80+
import jdk.graal.compiler.graph.Node;
81+
import jdk.graal.compiler.graph.NodeList;
82+
import jdk.graal.compiler.options.OptionValues;
83+
import jdk.graal.compiler.word.WordTypes;
8984
import jdk.vm.ci.meta.ConstantReflectionProvider;
9085
import jdk.vm.ci.meta.JavaKind;
9186
import jdk.vm.ci.meta.JavaType;
@@ -111,9 +106,9 @@ public abstract class PointsToAnalysis extends AbstractAnalysisEngine {
111106

112107
@SuppressWarnings("this-escape")
113108
public PointsToAnalysis(OptionValues options, AnalysisUniverse universe, HostVM hostVM, AnalysisMetaAccess metaAccess, SnippetReflectionProvider snippetReflectionProvider,
114-
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes, ForkJoinPool executorService, UnsupportedFeatures unsupportedFeatures, TimerCollection timerCollection,
109+
ConstantReflectionProvider constantReflectionProvider, WordTypes wordTypes, UnsupportedFeatures unsupportedFeatures, DebugContext debugContext, TimerCollection timerCollection,
115110
boolean strengthenGraalGraphs) {
116-
super(options, universe, hostVM, metaAccess, snippetReflectionProvider, constantReflectionProvider, wordTypes, executorService, unsupportedFeatures, timerCollection);
111+
super(options, universe, hostVM, metaAccess, snippetReflectionProvider, constantReflectionProvider, wordTypes, unsupportedFeatures, debugContext, timerCollection);
117112
this.typeFlowTimer = timerCollection.createTimer("(typeflow)");
118113

119114
this.strengthenGraalGraphs = strengthenGraalGraphs;
@@ -537,16 +532,6 @@ public boolean doTypeflow() throws InterruptedException {
537532
return didSomeWork;
538533
}
539534

540-
@SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "ForkJoinPool does support null for the exception handler.")
541-
public static ForkJoinPool createExecutor(DebugContext debug, int numberOfThreads) {
542-
ForkJoinPool.ForkJoinWorkerThreadFactory factory = debugThreadFactory(debug.areScopesEnabled() || debug.areMetricsEnabled() ? debug : null);
543-
return new ForkJoinPool(numberOfThreads, factory, null, false);
544-
}
545-
546-
private static ForkJoinPool.ForkJoinWorkerThreadFactory debugThreadFactory(DebugContext debug) {
547-
return pool -> new SubstrateWorkerThread(pool, debug);
548-
}
549-
550535
@Override
551536
public void onTypeInstantiated(AnalysisType type, AnalysisType.UsageKind usageKind) {
552537
/* Register the type as instantiated with all its super types. */
@@ -735,21 +720,4 @@ public void print() {
735720
System.out.println();
736721
}
737722
}
738-
739-
private static class SubstrateWorkerThread extends ForkJoinWorkerThread
740-
implements ImageGeneratorThreadMarker {
741-
private final DebugContext debug;
742-
743-
SubstrateWorkerThread(ForkJoinPool pool, DebugContext debug) {
744-
super(pool);
745-
this.debug = debug;
746-
}
747-
748-
@Override
749-
protected void onTermination(Throwable exception) {
750-
if (debug != null) {
751-
debug.closeDumpHandlers(true);
752-
}
753-
}
754-
}
755723
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@
2727
import static com.oracle.graal.pointsto.ObjectScanner.ScanReason;
2828

2929
import java.util.Objects;
30-
import java.util.concurrent.ForkJoinPool;
3130
import java.util.function.Consumer;
3231

33-
import jdk.graal.compiler.options.Option;
34-
import jdk.graal.compiler.options.OptionKey;
35-
import jdk.graal.compiler.options.OptionType;
36-
3732
import com.oracle.graal.pointsto.BigBang;
3833
import com.oracle.graal.pointsto.ObjectScanner;
3934
import com.oracle.graal.pointsto.ObjectScanner.ReusableSet;
@@ -46,6 +41,10 @@
4641
import com.oracle.graal.pointsto.util.CompletionExecutor;
4742
import com.oracle.svm.util.LogUtils;
4843

44+
import jdk.graal.compiler.debug.DebugContext;
45+
import jdk.graal.compiler.options.Option;
46+
import jdk.graal.compiler.options.OptionKey;
47+
import jdk.graal.compiler.options.OptionType;
4948
import jdk.vm.ci.meta.JavaConstant;
5049

5150
public class HeapSnapshotVerifier {
@@ -74,8 +73,8 @@ public HeapSnapshotVerifier(BigBang bb, ImageHeap imageHeap, ImageHeapScanner sc
7473
verbosity = Options.HeapVerifierVerbosity.getValue(bb.getOptions());
7574
}
7675

77-
public boolean checkHeapSnapshot(UniverseMetaAccess metaAccess, ForkJoinPool threadPool, String stage) {
78-
CompletionExecutor executor = new CompletionExecutor(bb, threadPool);
76+
public boolean checkHeapSnapshot(DebugContext debug, UniverseMetaAccess metaAccess, String stage) {
77+
CompletionExecutor executor = new CompletionExecutor(debug, bb);
7978
executor.init();
8079
return checkHeapSnapshot(metaAccess, executor, stage, false);
8180
}

0 commit comments

Comments
 (0)