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

[GR-41298] Introduce ParseOnceJIT concept and flag. #5061

Merged
merged 1 commit into from
Oct 1, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,36 @@
import com.oracle.svm.core.option.RuntimeOptionKey;
import com.oracle.svm.core.thread.VMOperationControl;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.VMError;

import jdk.internal.misc.Unsafe;

public class SubstrateOptions {

@Option(help = "When true, compiler graphs are parsed only once before static analysis. When false, compiler graphs are parsed for static analysis and again for AOT compilation.")//
public static final HostedOptionKey<Boolean> ParseOnce = new HostedOptionKey<>(true);
@Option(help = "When true, each compiler graph version (DeoptTarget, AOT, JIT) needed for runtime compilation will be separately analyzed during static analysis." +
"When false, only one version of the compiler graph (AOT) will be used in static analysis, and then three new versions will be parsed for compilation.")//
public static final HostedOptionKey<Boolean> ParseOnceJIT = new HostedOptionKey<>(false) {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
if (newValue) {
throw VMError.shouldNotReachHere("Enabling ParseOnceJIT is currently not supported");
}
super.onValueUpdate(values, oldValue, newValue);
}
};
@Option(help = "Preserve the local variable information for every Java source line to allow line-by-line stepping in the debugger. Allow the lookup of Java-level method information, e.g., in stack traces.")//
public static final HostedOptionKey<Boolean> SourceLevelDebug = new HostedOptionKey<>(false);
@Option(help = "Constrain debug info generation to the comma-separated list of package prefixes given to this option.")//
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> SourceLevelDebugFilter = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());

public static boolean parseOnce() {
/*
* Parsing all graphs before static analysis is work-in-progress, and not yet working for
* graphs parsed for deoptimization entry points and JIT compilation.
* Parsing all graphs before static analysis is work-in-progress and for JIT compilation is
* only enabled when ParseOnceJIT is set.
*/
return ParseOnce.getValue() && !DeoptimizationSupport.enabled();
return ParseOnce.getValue() && (ParseOnceJIT.getValue() || !DeoptimizationSupport.enabled());
}

@Option(help = "Module containing the class that contains the main entry point. Optional if --shared is used.", type = OptionType.User)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;

import com.oracle.svm.core.feature.InternalFeature;
import org.graalvm.collections.EconomicMap;
import org.graalvm.compiler.code.DisassemblerProvider;
import org.graalvm.compiler.core.GraalServiceThread;
Expand Down Expand Up @@ -121,6 +120,7 @@
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
import com.oracle.svm.core.graal.snippets.NodeLoweringProvider;
import com.oracle.svm.core.heap.GCCause;
Expand Down Expand Up @@ -195,7 +195,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {

@Override
public List<Class<? extends Feature>> getRequiredFeatures() {
return Arrays.asList(JNIFeature.class, RuntimeCompilationFeature.class, ReflectionFeature.class);
return List.of(JNIFeature.class, RuntimeCompilationFeature.getRuntimeCompilationFeature(), ReflectionFeature.class);
}

public static final class IsEnabled implements BooleanSupplier {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.graal.hosted;

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.util.VMError;

/**
* Marker for current strategy for supporting RuntimeCompilationFeature. Eventually will be
* supplanted by {@link ParseOnceRuntimeCompilationFeature}.
*/
public class LegacyRuntimeCompilationFeature extends RuntimeCompilationFeature {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
VMError.guarantee(!SubstrateOptions.ParseOnceJIT.getValue(), "This feature is only supported when ParseOnceJIT is not set");

ImageSingletons.add(RuntimeCompilationFeature.class, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.graal.hosted;

import com.oracle.svm.core.util.VMError;

/**
* Marker for runtime compilation strategy used when
* {@link com.oracle.svm.core.SubstrateOptions#ParseOnceJIT} is enabled.
*/
public class ParseOnceRuntimeCompilationFeature extends RuntimeCompilationFeature {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
throw VMError.unimplemented("ParseOnceRuntimeCompilationFeature is not currently supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
* image. Data that is prepared during image generation and used at run time is stored in
* {@link GraalSupport}.
*/
public final class RuntimeCompilationFeature implements Feature {
public abstract class RuntimeCompilationFeature implements Feature {

public static class Options {
@Option(help = "Print call tree of methods available for runtime compilation")//
Expand Down Expand Up @@ -180,7 +180,23 @@ public boolean getAsBoolean() {
public static final class IsEnabledAndNotLibgraal implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return ImageSingletons.contains(RuntimeCompilationFeature.class) && !SubstrateUtil.isBuildingLibgraal();
return isEnabledAndNotLibgraal();
}
}

public static boolean isEnabledAndNotLibgraal() {
return ImageSingletons.contains(RuntimeCompilationFeature.class) && !SubstrateUtil.isBuildingLibgraal();
}

public static RuntimeCompilationFeature singleton() {
return ImageSingletons.lookup(RuntimeCompilationFeature.class);
}

public static Class<? extends Feature> getRuntimeCompilationFeature() {
if (SubstrateOptions.ParseOnceJIT.getValue()) {
return ParseOnceRuntimeCompilationFeature.class;
} else {
return LegacyRuntimeCompilationFeature.class;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void registerInvocationPlugins(Providers providers, SnippetReflectionProv

@Override
public List<Class<? extends Feature>> getRequiredFeatures() {
return Arrays.asList(RuntimeCompilationFeature.class, TruffleBaseFeature.class);
return List.of(RuntimeCompilationFeature.getRuntimeCompilationFeature(), TruffleBaseFeature.class);
}

@Override
Expand Down Expand Up @@ -337,7 +337,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
// register thread local foreign poll as compiled otherwise the stub won't work
config.registerAsRoot((AnalysisMethod) SubstrateThreadLocalHandshake.FOREIGN_POLL.findMethod(config.getMetaAccess()), true);

RuntimeCompilationFeature runtimeCompilationFeature = ImageSingletons.lookup(RuntimeCompilationFeature.class);
RuntimeCompilationFeature runtimeCompilationFeature = RuntimeCompilationFeature.singleton();
SnippetReflectionProvider snippetReflection = runtimeCompilationFeature.getHostedProviders().getSnippetReflection();
SubstrateTruffleCompiler truffleCompiler = truffleRuntime.initTruffleCompiler();
truffleRuntime.initializeKnownMethods(config.getMetaAccess());
Expand Down Expand Up @@ -843,7 +843,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
runtimeCompiledMethods.addAll(Arrays.asList(config.getMetaAccess().lookupJavaType(CompilerDirectives.class).getDeclaredMethods()));
runtimeCompiledMethods.addAll(Arrays.asList(config.getMetaAccess().lookupJavaType(CompilerAsserts.class).getDeclaredMethods()));

for (CallTreeNode runtimeCompiledMethod : ImageSingletons.lookup(RuntimeCompilationFeature.class).getRuntimeCompiledMethods().values()) {
for (CallTreeNode runtimeCompiledMethod : RuntimeCompilationFeature.singleton().getRuntimeCompiledMethods().values()) {

runtimeCompiledMethods.add(runtimeCompiledMethod.getImplementationMethod());

Expand Down Expand Up @@ -874,7 +874,7 @@ private static void printStaticTruffleBoundaries() {
HashSet<ResolvedJavaMethod> foundBoundaries = new HashSet<>();
int callSiteCount = 0;
int calleeCount = 0;
for (CallTreeNode node : ImageSingletons.lookup(RuntimeCompilationFeature.class).getRuntimeCompiledMethods().values()) {
for (CallTreeNode node : RuntimeCompilationFeature.singleton().getRuntimeCompiledMethods().values()) {
StructuredGraph graph = node.getGraph();
for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public SubstrateTruffleCompiler createTruffleCompiler(SubstrateTruffleRuntime ru
}

protected static TruffleCompilerConfiguration createSubstrateTruffleCompilerConfig(SubstrateTruffleRuntime runtime, String compilerConfigurationName, Method optimizedCallTargetMethod) {
RuntimeCompilationFeature runtimeCompilationFeature = ImageSingletons.lookup(RuntimeCompilationFeature.class);
RuntimeCompilationFeature runtimeCompilationFeature = RuntimeCompilationFeature.singleton();
SubstrateKnownTruffleTypes knownTruffleTypes = new SubstrateKnownTruffleTypes(GraalSupport.getRuntimeConfig().getProviders().getMetaAccess());
SnippetReflectionProvider snippetReflectionProvider = runtimeCompilationFeature.getHostedProviders().getSnippetReflection();
final GraphBuilderConfiguration.Plugins graphBuilderPlugins = runtimeCompilationFeature.getHostedProviders().getGraphBuilderPlugins();
Expand Down