src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java Fri Jul 7 09:31:49 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java Fri Jul 7 09:31:49 2017
*** 21,38 ****
--- 21,42 ----
* questions.
*/
package org.graalvm.compiler.replacements;
import static org.graalvm.compiler.core.common.GraalOptions.UseSnippetGraphCache;
+ import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
import static org.graalvm.compiler.java.BytecodeParserOptions.InlineIntrinsicsDuringParsing;
import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createIntrinsicInlineInfo;
import static org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING;
import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required;
+ import java.util.Collections;
+ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+ import java.util.concurrent.atomic.AtomicInteger;
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.compiler.api.replacements.MethodSubstitution;
import org.graalvm.compiler.api.replacements.Snippet;
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
*** 40,54 ****
--- 44,59 ----
import org.graalvm.compiler.bytecode.Bytecode;
import org.graalvm.compiler.bytecode.BytecodeProvider;
import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
import org.graalvm.compiler.core.common.GraalOptions;
import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
import org.graalvm.compiler.debug.Debug;
import org.graalvm.compiler.debug.Debug.Scope;
import org.graalvm.compiler.debug.DebugCloseable;
! import org.graalvm.compiler.debug.DebugTimer;
! import org.graalvm.compiler.debug.DebugHandlersFactory;
+ import org.graalvm.compiler.debug.DebugContext;
+ import org.graalvm.compiler.debug.DebugContext.Description;
import org.graalvm.compiler.debug.GraalError;
+ import org.graalvm.compiler.debug.TimerKey;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
import org.graalvm.compiler.java.GraphBuilderPhase;
import org.graalvm.compiler.java.GraphBuilderPhase.Instance;
import org.graalvm.compiler.nodes.CallTargetNode;
*** 90,99 ****
--- 95,105 ----
protected final OptionValues options;
public final Providers providers;
public final SnippetReflectionProvider snippetReflection;
public final TargetDescription target;
private GraphBuilderConfiguration.Plugins graphBuilderPlugins;
+ private final DebugHandlersFactory debugHandlersFactory;
@Override
public OptionValues getOptions() {
return options;
}
*** 178,218 ****
--- 184,238 ----
// This map is key'ed by a class name instead of a Class object so that
// it is stable across VM executions (in support of replay compilation).
private final EconomicMap<String, SnippetTemplateCache> snippetTemplateCache;
! public ReplacementsImpl(OptionValues options, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider, TargetDescription target) {
! public ReplacementsImpl(OptionValues options, DebugHandlersFactory debugHandlersFactory, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider,
+ TargetDescription target) {
this.options = options;
this.providers = providers.copyWith(this);
this.snippetReflection = snippetReflection;
this.target = target;
this.graphs = new ConcurrentHashMap<>();
this.snippetTemplateCache = EconomicMap.create(Equivalence.DEFAULT);
this.defaultBytecodeProvider = bytecodeProvider;
+ this.debugHandlersFactory = debugHandlersFactory;
+
}
! private static final DebugTimer SnippetPreparationTime = Debug.timer("SnippetPreparationTime");
! private static final TimerKey SnippetPreparationTime = DebugContext.timer("SnippetPreparationTime");
@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args) {
return getSnippet(method, null, args);
}
+ private static final AtomicInteger nextDebugContextId = new AtomicInteger();
+
+ protected DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) {
+ DebugContext outer = DebugContext.forCurrentThread();
+ Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet());
+ List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory);
+ return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories);
+ }
+
@Override
@SuppressWarnings("try")
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args) {
assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
assert method.hasBytecodes() : "Snippet must not be abstract or native";
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
if (graph == null) {
! try (DebugCloseable a = SnippetPreparationTime.start()) {
StructuredGraph newGraph = makeGraph(defaultBytecodeProvider, method, args, recursiveEntry);
! Debug.counter("SnippetNodeCount[%#s]", method).add(newGraph.getNodeCount());
! try (DebugContext debug = openDebugContext("Snippet_", method);
+ DebugCloseable a = SnippetPreparationTime.start(debug)) {
! StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry);
+ DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount());
if (!UseSnippetGraphCache.getValue(options) || args != null) {
return newGraph;
}
+ newGraph.freeze();
graphs.putIfAbsent(method, newGraph);
graph = graphs.get(method);
}
}
return graph;
*** 254,276 ****
--- 274,300 ----
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
StructuredGraph graph = graphs.get(substitute);
if (graph == null) {
graph = makeGraph(msPlugin.getBytecodeProvider(), substitute, null, method);
+ try (DebugContext debug = openDebugContext("Substitution_", method)) {
+ graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method);
graph.freeze();
graphs.putIfAbsent(substitute, graph);
graph = graphs.get(substitute);
}
+ }
assert graph.isFrozen();
result = graph;
} else {
Bytecode code = new ResolvedJavaMethodBytecode(method);
ConstantReflectionProvider constantReflection = providers.getConstantReflection();
ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
StampProvider stampProvider = providers.getStampProvider();
result = new IntrinsicGraphBuilder(options, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
+ try (DebugContext debug = openDebugContext("Substitution_", method)) {
+ result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
+ }
}
} else {
result = null;
}
return result;
*** 283,294 ****
--- 307,318 ----
* @param method the snippet or method substitution for which a graph will be created
* @param args
* @param original the original method if {@code method} is a {@linkplain MethodSubstitution
* substitution} otherwise null
*/
! public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original) {
! return createGraphMaker(method, original).makeGraph(bytecodeProvider, args);
! return createGraphMaker(method, original).makeGraph(debug, bytecodeProvider, args);
}
/**
* Can be overridden to return an object that specializes various parts of graph preprocessing.
*/
*** 321,342 ****
--- 345,366 ----
this.method = substitute;
this.substitutedMethod = substitutedMethod;
}
@SuppressWarnings("try")
! public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, Object[] args) {
! try (Scope s = Debug.scope("BuildSnippetGraph", method)) {
! try (DebugContext.Scope s = debug.scope("BuildSnippetGraph", method)) {
assert method.hasBytecodes() : method;
! StructuredGraph graph = buildInitialGraph(debug, bytecodeProvider, method, args);
finalizeGraph(graph);
! Debug.dump(Debug.INFO_LEVEL, graph, "%s: Final", method.getName());
! debug.dump(DebugContext.INFO_LEVEL, graph, "%s: Final", method.getName());
return graph;
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
}
/**
* Does final processing of a snippet graph.
*** 388,407 ****
--- 412,431 ----
/**
* Builds the initial graph for a replacement.
*/
@SuppressWarnings("try")
! protected StructuredGraph buildInitialGraph(DebugContext debug, BytecodeProvider bytecodeProvider, final ResolvedJavaMethod methodToParse, Object[] args) {
// Replacements cannot have optimistic assumptions since they have
// to be valid for the entire run of the VM.
+ final StructuredGraph graph = new StructuredGraph.Builder(replacements.options, debug).method(methodToParse).build();
final StructuredGraph graph = new StructuredGraph.Builder(replacements.options).method(methodToParse).build();
// They are not user code so they do not participate in unsafe access tracking
+ // Replacements are not user code so they do not participate in unsafe access
+ // tracking
graph.disableUnsafeAccessTracking();
! try (Scope s = Debug.scope("buildInitialGraph", graph)) {
! try (DebugContext.Scope s = debug.scope("buildInitialGraph", graph)) {
MetaAccessProvider metaAccess = replacements.providers.getMetaAccess();
Plugins plugins = new Plugins(replacements.graphBuilderPlugins);
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
if (args != null) {
*** 421,431 ****
--- 445,455 ----
createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), replacements.providers.getConstantFieldProvider(), config,
OptimisticOptimizations.NONE, initialIntrinsicContext).apply(graph);
new CanonicalizerPhase().apply(graph, new PhaseContext(replacements.providers));
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
return graph;
}
protected Instance createGraphBuilder(MetaAccessProvider metaAccess, StampProvider stampProvider, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider,
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File