Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def contents(self):
'-Dorg.graalvm.version={}'.format(_suite.release_version()),
]
if _debug_images():
build_args += ['-ea', '-H:-AOTInline', '-H:+PreserveFramePointer', '-H:-DeleteLocalSymbols']
build_args += ['-ea', '-O0', '-H:+PreserveFramePointer', '-H:-DeleteLocalSymbols']
if _get_svm_support().is_debug_supported():
build_args += ['-g']
if getattr(image_config, 'link_at_build_time', True):
Expand Down Expand Up @@ -3303,7 +3303,7 @@ def graalvm_vendor_version(graalvm_dist):
mx.add_argument('--disable-polyglot', action='store_true', help='Disable the \'polyglot\' launcher project.')
mx.add_argument('--disable-installables', action='store', help='Disable the \'installable\' distributions for gu.'
'This can be a comma-separated list of disabled components short names or `true` to disable all installables.', default=None)
mx.add_argument('--debug-images', action='store_true', help='Build native images in debug mode: \'-H:-AOTInline\' and with \'-ea\'.')
mx.add_argument('--debug-images', action='store_true', help='Build native images in debug mode: \'-O0\' and with \'-ea\'.')
mx.add_argument('--native-images', action='store', help='Comma-separated list of launchers and libraries (syntax: lib:polyglot) to build with Native Image.')
mx.add_argument('--force-bash-launchers', action='store', help='Force the use of bash launchers instead of native images.'
'This can be a comma-separated list of disabled launchers or `true` to disable all native launchers.', default=None)
Expand Down
1 change: 1 addition & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
"jdk.internal.vm.annotation",
"jdk.internal.org.objectweb.asm",
"sun.reflect.annotation",
"sun.security.jca",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.oracle.graal.pointsto.util.TimerCollection;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.debug.DebugContext;
Expand All @@ -57,6 +56,7 @@
import com.oracle.graal.pointsto.util.CompletionExecutor;
import com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable;
import com.oracle.graal.pointsto.util.Timer.StopTimer;
import com.oracle.graal.pointsto.util.TimerCollection;
import com.oracle.objectfile.ObjectFile;
import com.oracle.objectfile.ObjectFile.Element;
import com.oracle.objectfile.SectionName;
Expand All @@ -73,6 +73,7 @@
import com.oracle.svm.core.heap.SubstrateReferenceMap;
import com.oracle.svm.core.jdk.UninterruptibleUtils.AtomicInteger;
import com.oracle.svm.core.meta.MethodPointer;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.image.NativeImage.NativeTextSectionImpl;
import com.oracle.svm.hosted.image.NativeImageCodeCache;
import com.oracle.svm.hosted.image.NativeImageHeap;
Expand Down Expand Up @@ -270,7 +271,7 @@ private void llvmCompile(DebugContext debug, String outputPath, String inputPath
args.add("--trap-unreachable");
args.add("-march=" + LLVMTargetSpecific.get().getLLVMArchName());
args.addAll(LLVMTargetSpecific.get().getLLCAdditionalOptions());
args.add("-O" + SubstrateOptions.optimizationLevel());
args.add("-O" + optimizationLevel());
args.add("-filetype=obj");
args.add("-o");
args.add(outputPath);
Expand All @@ -284,6 +285,20 @@ private void llvmCompile(DebugContext debug, String outputPath, String inputPath
}
}

private static int optimizationLevel() {
switch (SubstrateOptions.optimizationLevel()) {
case O0:
case BUILD_TIME:
return 0;
case O1:
return 1;
case O2:
return 2;
default:
throw VMError.shouldNotReachHere();
}
}

private void llvmLink(DebugContext debug, String outputPath, List<String> inputPaths) {
List<String> args = new ArrayList<>();
args.add("-o");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,42 +151,64 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
public static final String IMAGE_CLASSPATH_PREFIX = "-imagecp";
public static final String IMAGE_MODULEPATH_PREFIX = "-imagemp";
public static final String WATCHPID_PREFIX = "-watchpid";
private static ValueUpdateHandler optimizeValueUpdateHandler;
private static ValueUpdateHandler debugInfoValueUpdateHandler = SubstrateOptions::defaultDebugInfoValueUpdateHandler;
private static ValueUpdateHandler<OptimizationLevel> optimizeValueUpdateHandler;
private static ValueUpdateHandler<Integer> debugInfoValueUpdateHandler = SubstrateOptions::defaultDebugInfoValueUpdateHandler;

/**
* The currently supported optimization levels. See the option description of {@link #Optimize}
* for a description of the levels.
*/
public enum OptimizationLevel {
O0,
O1,
O2,
BUILD_TIME
}

@Option(help = "Control native-image code optimizations: b - optimize for shortest build time, 0 - no optimizations, 1 - basic optimizations, 2 - aggressive optimizations.", type = OptionType.User)//
public static final HostedOptionKey<String> Optimize = new HostedOptionKey<>("2") {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String oldValue, String newValue) {
Integer oldLevel = parseOptimizationLevel(oldValue);
Integer newLevel = parseOptimizationLevel(newValue);
SubstrateOptions.IncludeNodeSourcePositions.update(values, newLevel < 1);
SubstrateOptions.AOTInline.update(values, newLevel > 0);
SubstrateOptions.AOTTrivialInline.update(values, newLevel > 0);
OptimizationLevel newLevel = parseOptimizationLevel(newValue);
SubstrateOptions.IncludeNodeSourcePositions.update(values, newLevel == OptimizationLevel.O0);
SubstrateOptions.AOTTrivialInline.update(values, newLevel != OptimizationLevel.O0);
if (optimizeValueUpdateHandler != null) {
optimizeValueUpdateHandler.onValueUpdate(values, oldLevel, newLevel);
optimizeValueUpdateHandler.onValueUpdate(values, newLevel);
}
}
};

private static Integer parseOptimizationLevel(String value) {
if (value == null) {
return null;
}
// Only allow 'b' or numeric optimization levels,
// throw a user error otherwise.
/**
* Only allows 'b' or positive numeric optimization levels, throws a user error otherwise.
*/
private static OptimizationLevel parseOptimizationLevel(String value) {
if (value.equals("b")) {
return 0;
return OptimizationLevel.BUILD_TIME;
}

int intLevel;
try {
return Integer.parseInt(value);
intLevel = Integer.parseInt(value);
} catch (NumberFormatException nfe) {
throw UserError.abort("Invalid value '%s' provided for option Optimize (expected 'b' or numeric value)", value);
intLevel = -1;
}

if (intLevel == 0) {
return OptimizationLevel.O0;
} else if (intLevel == 1) {
return OptimizationLevel.O1;
} else if (intLevel >= 2) {
/*
* We allow all positive numbers, and treat that as our current highest supported level.
*/
return OptimizationLevel.O2;
} else {
throw UserError.abort("Invalid value '%s' provided for option Optimize (expected 'b' or numeric value >= 0)", value);
}
}

@Fold
public static Integer optimizationLevel() {
public static OptimizationLevel optimizationLevel() {
return parseOptimizationLevel(Optimize.getValue());
}

Expand All @@ -199,15 +221,15 @@ public static boolean useEconomyCompilerConfig() {
return useEconomyCompilerConfig(HostedOptionValues.singleton());
}

public interface ValueUpdateHandler {
void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer oldValue, Integer newValue);
public interface ValueUpdateHandler<T> {
void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, T newValue);
}

public static void setOptimizeValueUpdateHandler(ValueUpdateHandler updateHandler) {
public static void setOptimizeValueUpdateHandler(ValueUpdateHandler<OptimizationLevel> updateHandler) {
SubstrateOptions.optimizeValueUpdateHandler = updateHandler;
}

public static void setDebugInfoValueUpdateHandler(ValueUpdateHandler updateHandler) {
public static void setDebugInfoValueUpdateHandler(ValueUpdateHandler<Integer> updateHandler) {
SubstrateOptions.debugInfoValueUpdateHandler = updateHandler;
}

Expand Down Expand Up @@ -409,8 +431,8 @@ public static final long getTearDownFailureNanos() {
@Option(help = "Enable wildcard expansion in command line arguments on Windows.")//
public static final HostedOptionKey<Boolean> EnableWildcardExpansion = new HostedOptionKey<>(true);

@Option(help = "Perform method inlining in the AOT compiled native image")//
public static final HostedOptionKey<Boolean> AOTInline = new HostedOptionKey<>(true);
@Option(help = "Deprecated", deprecated = true)//
static final HostedOptionKey<Boolean> AOTInline = new HostedOptionKey<>(true);

@Option(help = "Perform trivial method inlining in the AOT compiled native image")//
public static final HostedOptionKey<Boolean> AOTTrivialInline = new HostedOptionKey<>(true);
Expand Down Expand Up @@ -537,11 +559,11 @@ public static int codeAlignment() {
public static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0) {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer oldValue, Integer newValue) {
debugInfoValueUpdateHandler.onValueUpdate(values, oldValue, newValue);
debugInfoValueUpdateHandler.onValueUpdate(values, newValue);
}
};

public static void defaultDebugInfoValueUpdateHandler(EconomicMap<OptionKey<?>, Object> values, @SuppressWarnings("unused") Integer oldValue, Integer newValue) {
public static void defaultDebugInfoValueUpdateHandler(EconomicMap<OptionKey<?>, Object> values, Integer newValue) {
/* Force update of TrackNodeSourcePosition */
TrackNodeSourcePosition.update(values, newValue > 0);
if (OS.WINDOWS.isCurrent()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,6 @@ private void setupNativeImage(String imageName, OptionValues options, Map<Method
}

if (SubstrateOptions.useEconomyCompilerConfig()) {
HostedConfiguration.setInstanceIfEmpty(new EconomyHostedConfiguration());
GraalConfiguration.setHostedInstanceIfEmpty(new EconomyGraalConfiguration());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,6 @@ public void closeAction() {
};
}

public void printInliningSkipped() {
stagePrinter.skipped(BuildStage.INLINING);
}

public ReporterClosable printCompiling() {
Timer timer = getTimer(TimerCollection.Registry.COMPILE);
timer.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import com.oracle.svm.core.BuildPhaseProvider;
import com.oracle.svm.core.RuntimeAssertionsSupport;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateOptions.OptimizationLevel;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.annotate.NeverInline;
import com.oracle.svm.core.annotate.UnknownClass;
Expand Down Expand Up @@ -307,7 +308,7 @@ private boolean retainLocalVariables() {
* TODO: ParseOnce does not support deoptimization targets yet, this needs to be added
* later.
*/
return SubstrateOptions.optimizationLevel() <= 0;
return SubstrateOptions.optimizationLevel() == OptimizationLevel.O0;

} else {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
import com.oracle.graal.pointsto.util.CompletionExecutor;
import com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateOptions.OptimizationLevel;
import com.oracle.svm.core.annotate.AlwaysInlineAllCallees;
import com.oracle.svm.core.annotate.AlwaysInlineSelectCallees;
import com.oracle.svm.core.annotate.DeoptTest;
Expand Down Expand Up @@ -222,6 +223,7 @@ public interface CompileFunction {
private volatile boolean inliningProgress;

private final boolean printMethodHistogram = NativeImageOptions.PrintMethodHistogram.getValue();
private final boolean optionAOTTrivialInline = SubstrateOptions.AOTTrivialInline.getValue();

public abstract static class CompileReason {
/**
Expand Down Expand Up @@ -423,12 +425,8 @@ public void finish(DebugContext debug) {
method.wrapped.setAnalyzedGraph(null);
}

if (SubstrateOptions.AOTInline.getValue() && SubstrateOptions.AOTTrivialInline.getValue()) {
try (ProgressReporter.ReporterClosable ac = reporter.printInlining()) {
inlineTrivialMethods(debug);
}
} else {
reporter.printInliningSkipped();
try (ProgressReporter.ReporterClosable ac = reporter.printInlining()) {
inlineTrivialMethods(debug);
}

assert suitesNotCreated();
Expand Down Expand Up @@ -625,7 +623,6 @@ private void ensureParsedForDeoptTesting(HostedMethod method) {
protected void checkTrivial(HostedMethod method) {
if (!method.compilationInfo.isTrivialMethod() && method.canBeInlined() && InliningUtilities.isTrivialMethod(method.compilationInfo.getGraph())) {
method.compilationInfo.setTrivialMethod(true);
inliningProgress = true;
}
}

Expand Down Expand Up @@ -710,7 +707,7 @@ private void doInlineTrivial(DebugContext debug, final HostedMethod method) {
}
}

private static boolean tryInlineTrivial(StructuredGraph graph, Invoke invoke, boolean firstInline) {
private boolean tryInlineTrivial(StructuredGraph graph, Invoke invoke, boolean firstInline) {
if (invoke.getInvokeKind().isDirect()) {
HostedMethod singleCallee = (HostedMethod) invoke.callTarget().targetMethod();
if (makeInlineDecision(invoke, singleCallee) && InliningUtilities.recursionDepth(invoke, singleCallee) == 0) {
Expand All @@ -726,14 +723,14 @@ private static boolean tryInlineTrivial(StructuredGraph graph, Invoke invoke, bo
return false;
}

private static boolean makeInlineDecision(Invoke invoke, HostedMethod callee) {
private boolean makeInlineDecision(Invoke invoke, HostedMethod callee) {
if (!callee.canBeInlined() || callee.getAnnotation(NeverInlineTrivial.class) != null) {
return false;
}
if (callee.shouldBeInlined() || callerAnnotatedWith(invoke, AlwaysInlineAllCallees.class)) {
return true;
}
if (callee.compilationInfo.isTrivialMethod()) {
if (optionAOTTrivialInline && callee.compilationInfo.isTrivialMethod()) {
return true;
}
AlwaysInlineSelectCallees selectCallees = getCallerAnnotation(invoke, AlwaysInlineSelectCallees.class);
Expand Down Expand Up @@ -1179,7 +1176,7 @@ protected OptionValues getCustomizedOptions(DebugContext debug) {
protected GraphBuilderConfiguration createHostedGraphBuilderConfiguration(HostedProviders providers, HostedMethod method) {
GraphBuilderConfiguration gbConf = GraphBuilderConfiguration.getDefault(providers.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.CheckAll);

if (SubstrateOptions.optimizationLevel() <= 0 && !method.isDeoptTarget()) {
if (SubstrateOptions.optimizationLevel() == OptimizationLevel.O0 && !method.isDeoptTarget()) {
/*
* Disabling liveness analysis preserves the values of local variables beyond the
* bytecode-liveness. This greatly helps debugging. When local variable numbers are
Expand Down
Loading