mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 17:44:40 +02:00
8183991: Update Graal
Reviewed-by: kvn
This commit is contained in:
parent
5bd24e0c25
commit
b7629460d2
418 changed files with 10369 additions and 10463 deletions
|
@ -27,8 +27,7 @@ import java.util.ListIterator;
|
||||||
|
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.core.GraalCompiler;
|
import org.graalvm.compiler.core.GraalCompiler;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
||||||
import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
|
import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
|
||||||
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
|
||||||
|
@ -82,6 +81,10 @@ public class AOTBackend {
|
||||||
return backend;
|
return backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HotSpotProviders getProviders() {
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
|
||||||
private Suites getSuites() {
|
private Suites getSuites() {
|
||||||
// create suites every time, as we modify options for the compiler
|
// create suites every time, as we modify options for the compiler
|
||||||
return backend.getSuites().getDefaultSuites(graalOptions);
|
return backend.getSuites().getDefaultSuites(graalOptions);
|
||||||
|
@ -93,10 +96,10 @@ public class AOTBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod) {
|
public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod, DebugContext debug) {
|
||||||
StructuredGraph graph = buildStructuredGraph(resolvedMethod);
|
StructuredGraph graph = buildStructuredGraph(resolvedMethod, debug);
|
||||||
if (graph != null) {
|
if (graph != null) {
|
||||||
return compileGraph(resolvedMethod, graph);
|
return compileGraph(resolvedMethod, graph, debug);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -105,12 +108,13 @@ public class AOTBackend {
|
||||||
* Build a structured graph for the member.
|
* Build a structured graph for the member.
|
||||||
*
|
*
|
||||||
* @param javaMethod method for whose code the graph is to be created
|
* @param javaMethod method for whose code the graph is to be created
|
||||||
|
* @param debug
|
||||||
* @return structured graph
|
* @return structured graph
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod) {
|
private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod, DebugContext debug) {
|
||||||
try (Scope s = Debug.scope("AOTParseMethod")) {
|
try (DebugContext.Scope s = debug.scope("AOTParseMethod")) {
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(graalOptions).method(javaMethod).useProfilingInfo(false).build();
|
StructuredGraph graph = new StructuredGraph.Builder(graalOptions, debug).method(javaMethod).useProfilingInfo(false).build();
|
||||||
graphBuilderSuite.apply(graph, highTierContext);
|
graphBuilderSuite.apply(graph, highTierContext);
|
||||||
return graph;
|
return graph;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -120,8 +124,8 @@ public class AOTBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private CompilationResult compileGraph(ResolvedJavaMethod resolvedMethod, StructuredGraph graph) {
|
private CompilationResult compileGraph(ResolvedJavaMethod resolvedMethod, StructuredGraph graph, DebugContext debug) {
|
||||||
try (Scope s = Debug.scope("AOTCompileMethod")) {
|
try (DebugContext.Scope s = debug.scope("AOTCompileMethod")) {
|
||||||
ProfilingInfo profilingInfo = DefaultProfilingInfo.get(TriState.FALSE);
|
ProfilingInfo profilingInfo = DefaultProfilingInfo.get(TriState.FALSE);
|
||||||
|
|
||||||
final boolean isImmutablePIC = true;
|
final boolean isImmutablePIC = true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -26,14 +26,15 @@ package jdk.tools.jaotc;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.core.GraalCompilerOptions;
|
import org.graalvm.compiler.core.GraalCompilerOptions;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.DebugEnvironment;
|
|
||||||
import org.graalvm.compiler.debug.Management;
|
import org.graalvm.compiler.debug.Management;
|
||||||
import org.graalvm.compiler.debug.TTY;
|
import org.graalvm.compiler.debug.TTY;
|
||||||
import org.graalvm.compiler.debug.internal.DebugScope;
|
import org.graalvm.compiler.debug.DebugContext.Activation;
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
|
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
|
||||||
|
|
||||||
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
|
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
|
||||||
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
|
||||||
|
@ -88,15 +89,12 @@ public class AOTCompilationTask implements Runnable, Comparable<Object> {
|
||||||
/**
|
/**
|
||||||
* Compile a method or a constructor.
|
* Compile a method or a constructor.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("try")
|
||||||
public void run() {
|
public void run() {
|
||||||
// Ensure a JVMCI runtime is initialized prior to Debug being initialized as the former
|
// Ensure a JVMCI runtime is initialized prior to Debug being initialized as the former
|
||||||
// may include processing command line options used by the latter.
|
// may include processing command line options used by the latter.
|
||||||
HotSpotJVMCIRuntime.runtime();
|
HotSpotJVMCIRuntime.runtime();
|
||||||
|
|
||||||
// Ensure a debug configuration for this thread is initialized
|
|
||||||
if (Debug.isEnabled() && DebugScope.getConfig() == null) {
|
|
||||||
DebugEnvironment.ensureInitialized(graalOptions);
|
|
||||||
}
|
|
||||||
AOTCompiler.logCompilation(MiscUtils.uniqueMethodName(method), "Compiling");
|
AOTCompiler.logCompilation(MiscUtils.uniqueMethodName(method), "Compiling");
|
||||||
|
|
||||||
final long threadId = Thread.currentThread().getId();
|
final long threadId = Thread.currentThread().getId();
|
||||||
|
@ -117,8 +115,12 @@ public class AOTCompilationTask implements Runnable, Comparable<Object> {
|
||||||
allocatedBytesBefore = 0L;
|
allocatedBytesBefore = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompilationResult compResult = null;
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
CompilationResult compResult = aotBackend.compileMethod(method);
|
SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection();
|
||||||
|
try (DebugContext debug = DebugContext.create(graalOptions, new GraalDebugHandlersFactory(snippetReflection)); Activation a = debug.activate()) {
|
||||||
|
compResult = aotBackend.compileMethod(method, debug);
|
||||||
|
}
|
||||||
final long endTime = System.currentTimeMillis();
|
final long endTime = System.currentTimeMillis();
|
||||||
|
|
||||||
if (printAfterCompilation || printCompilation) {
|
if (printAfterCompilation || printCompilation) {
|
||||||
|
|
|
@ -33,8 +33,7 @@ import jdk.tools.jaotc.binformat.ByteContainer;
|
||||||
import jdk.tools.jaotc.binformat.HeaderContainer;
|
import jdk.tools.jaotc.binformat.HeaderContainer;
|
||||||
import jdk.tools.jaotc.utils.Timer;
|
import jdk.tools.jaotc.utils.Timer;
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.hotspot.HotSpotHostBackend;
|
import org.graalvm.compiler.hotspot.HotSpotHostBackend;
|
||||||
import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
|
import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
|
||||||
import org.graalvm.compiler.hotspot.stubs.Stub;
|
import org.graalvm.compiler.hotspot.stubs.Stub;
|
||||||
|
@ -124,10 +123,12 @@ class DataBuilder {
|
||||||
/**
|
/**
|
||||||
* Prepare data with all compiled classes and stubs.
|
* Prepare data with all compiled classes and stubs.
|
||||||
*
|
*
|
||||||
|
* @param debug
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public void prepareData() throws Exception {
|
public void prepareData(DebugContext debug) throws Exception {
|
||||||
try (Timer t = new Timer(main, "Parsing compiled code")) {
|
try (Timer t = new Timer(main, "Parsing compiled code")) {
|
||||||
/*
|
/*
|
||||||
* Copy compiled code into code section container and calls stubs (PLT trampoline).
|
* Copy compiled code into code section container and calls stubs (PLT trampoline).
|
||||||
|
@ -142,7 +143,7 @@ class DataBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AOTCompiledClass stubCompiledCode = retrieveStubCode();
|
AOTCompiledClass stubCompiledCode = retrieveStubCode(debug);
|
||||||
|
|
||||||
// Free memory!
|
// Free memory!
|
||||||
try (Timer t = main.options.verbose ? new Timer(main, "Freeing memory") : null) {
|
try (Timer t = main.options.verbose ? new Timer(main, "Freeing memory") : null) {
|
||||||
|
@ -177,18 +178,20 @@ class DataBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all stubs from Graal and add them to the code section.
|
* Get all stubs from Graal and add them to the code section.
|
||||||
|
*
|
||||||
|
* @param debug
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private AOTCompiledClass retrieveStubCode() {
|
private AOTCompiledClass retrieveStubCode(DebugContext debug) {
|
||||||
ArrayList<CompiledMethodInfo> stubs = new ArrayList<>();
|
ArrayList<CompiledMethodInfo> stubs = new ArrayList<>();
|
||||||
HotSpotForeignCallsProvider foreignCallsProvider = backend.getProviders().getForeignCalls();
|
HotSpotForeignCallsProvider foreignCallsProvider = backend.getProviders().getForeignCalls();
|
||||||
for (Stub stub : foreignCallsProvider.getStubs()) {
|
for (Stub stub : foreignCallsProvider.getStubs()) {
|
||||||
try (Scope scope = Debug.scope("CompileStubs")) {
|
try (DebugContext.Scope scope = debug.scope("CompileStubs")) {
|
||||||
CompilationResult result = stub.getCompilationResult(backend);
|
CompilationResult result = stub.getCompilationResult(debug, backend);
|
||||||
CompiledMethodInfo cm = new CompiledMethodInfo(result, new AOTStub(stub, backend));
|
CompiledMethodInfo cm = new CompiledMethodInfo(result, new AOTStub(stub, backend));
|
||||||
stubs.add(cm);
|
stubs.add(cm);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AOTCompiledClass stubCompiledCode = new AOTCompiledClass(stubs);
|
AOTCompiledClass stubCompiledCode = new AOTCompiledClass(stubs);
|
||||||
|
|
|
@ -59,7 +59,10 @@ import jdk.tools.jaotc.collect.jar.JarSourceProvider;
|
||||||
import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
|
import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
|
||||||
import jdk.tools.jaotc.utils.Timer;
|
import jdk.tools.jaotc.utils.Timer;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
|
||||||
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
|
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext.Activation;
|
||||||
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
|
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
|
||||||
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
||||||
import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
|
import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
|
||||||
|
@ -72,6 +75,7 @@ import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.BasePhase;
|
import org.graalvm.compiler.phases.BasePhase;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
|
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
|
@ -467,6 +471,7 @@ public class Main implements LogPrinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, filters);
|
AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, filters);
|
||||||
|
SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection();
|
||||||
AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads);
|
AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads);
|
||||||
classes = compiler.compileClasses(classes);
|
classes = compiler.compileClasses(classes);
|
||||||
|
|
||||||
|
@ -485,7 +490,10 @@ public class Main implements LogPrinter {
|
||||||
|
|
||||||
BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
|
BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
|
||||||
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
|
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
|
||||||
dataBuilder.prepareData();
|
|
||||||
|
try (DebugContext debug = DebugContext.create(graalOptions, new GraalDebugHandlersFactory(snippetReflection)); Activation a = debug.activate()) {
|
||||||
|
dataBuilder.prepareData(debug);
|
||||||
|
}
|
||||||
|
|
||||||
// Print information about section sizes
|
// Print information about section sizes
|
||||||
printContainerInfo(binaryContainer.getHeaderContainer().getContainer());
|
printContainerInfo(binaryContainer.getHeaderContainer().getContainer());
|
||||||
|
|
|
@ -70,15 +70,15 @@ suite = {
|
||||||
"exports" : [
|
"exports" : [
|
||||||
"<package-info>", # exports all packages containing package-info.java
|
"<package-info>", # exports all packages containing package-info.java
|
||||||
],
|
],
|
||||||
"checkstyle" : "org.graalvm.api.word",
|
"checkstyle" : "org.graalvm.word",
|
||||||
"javaCompliance" : "1.8",
|
"javaCompliance" : "1.8",
|
||||||
"workingSets" : "API,SDK",
|
"workingSets" : "API,SDK",
|
||||||
},
|
},
|
||||||
"org.graalvm.api.word" : {
|
"org.graalvm.word" : {
|
||||||
"subDir" : "share/classes",
|
"subDir" : "share/classes",
|
||||||
"sourceDirs" : ["src"],
|
"sourceDirs" : ["src"],
|
||||||
"dependencies" : [],
|
"dependencies" : [],
|
||||||
"checkstyle" : "org.graalvm.api.word",
|
"checkstyle" : "org.graalvm.word",
|
||||||
"javaCompliance" : "1.8",
|
"javaCompliance" : "1.8",
|
||||||
"workingSets" : "API,SDK",
|
"workingSets" : "API,SDK",
|
||||||
},
|
},
|
||||||
|
@ -142,8 +142,7 @@ suite = {
|
||||||
"sourceDirs" : ["src"],
|
"sourceDirs" : ["src"],
|
||||||
"checkstyle" : "org.graalvm.compiler.graph",
|
"checkstyle" : "org.graalvm.compiler.graph",
|
||||||
"uses" : [
|
"uses" : [
|
||||||
"org.graalvm.compiler.debug.DebugConfigCustomizer",
|
"org.graalvm.compiler.debug.DebugHandlersFactory",
|
||||||
"org.graalvm.compiler.debug.DebugInitializationParticipant",
|
|
||||||
"org.graalvm.compiler.debug.TTYStreamProvider",
|
"org.graalvm.compiler.debug.TTYStreamProvider",
|
||||||
],
|
],
|
||||||
"dependencies" : [
|
"dependencies" : [
|
||||||
|
@ -792,6 +791,36 @@ suite = {
|
||||||
"workingSets" : "Graal,Phases",
|
"workingSets" : "Graal,Phases",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"org.graalvm.compiler.virtual.bench" : {
|
||||||
|
"subDir" : "share/classes",
|
||||||
|
"sourceDirs" : ["src"],
|
||||||
|
"dependencies" : ["mx:JMH_1_18", "org.graalvm.compiler.microbenchmarks"],
|
||||||
|
"checkstyle" : "org.graalvm.compiler.graph",
|
||||||
|
"javaCompliance" : "1.8",
|
||||||
|
"annotationProcessors" : ["mx:JMH_1_18"],
|
||||||
|
"findbugsIgnoresGenerated" : True,
|
||||||
|
"workingSets" : "Graal,Bench",
|
||||||
|
"isTestProject" : True,
|
||||||
|
},
|
||||||
|
|
||||||
|
"org.graalvm.compiler.microbenchmarks" : {
|
||||||
|
"subDir" : "share/classes",
|
||||||
|
"sourceDirs" : ["src"],
|
||||||
|
"dependencies" : [
|
||||||
|
"mx:JMH_1_18",
|
||||||
|
"org.graalvm.compiler.api.test",
|
||||||
|
"org.graalvm.compiler.java",
|
||||||
|
"org.graalvm.compiler.runtime",
|
||||||
|
],
|
||||||
|
"checkstyle" : "org.graalvm.compiler.graph",
|
||||||
|
"javaCompliance" : "1.8",
|
||||||
|
"checkPackagePrefix" : "false",
|
||||||
|
"annotationProcessors" : ["mx:JMH_1_18"],
|
||||||
|
"findbugsIgnoresGenerated" : True,
|
||||||
|
"workingSets" : "Graal,Bench",
|
||||||
|
"isTestProject" : True,
|
||||||
|
},
|
||||||
|
|
||||||
"org.graalvm.compiler.loop" : {
|
"org.graalvm.compiler.loop" : {
|
||||||
"subDir" : "share/classes",
|
"subDir" : "share/classes",
|
||||||
"sourceDirs" : ["src"],
|
"sourceDirs" : ["src"],
|
||||||
|
@ -970,7 +999,7 @@ suite = {
|
||||||
"sourceDirs" : ["src"],
|
"sourceDirs" : ["src"],
|
||||||
"dependencies" : [
|
"dependencies" : [
|
||||||
"org.graalvm.compiler.debug",
|
"org.graalvm.compiler.debug",
|
||||||
"org.graalvm.api.word",
|
"org.graalvm.word",
|
||||||
],
|
],
|
||||||
"annotationProcessors" : ["GRAAL_OPTIONS_PROCESSOR"],
|
"annotationProcessors" : ["GRAAL_OPTIONS_PROCESSOR"],
|
||||||
"checkstyle" : "org.graalvm.compiler.graph",
|
"checkstyle" : "org.graalvm.compiler.graph",
|
||||||
|
@ -998,6 +1027,7 @@ suite = {
|
||||||
"subDir" : "share/classes",
|
"subDir" : "share/classes",
|
||||||
"sourceDirs" : ["src"],
|
"sourceDirs" : ["src"],
|
||||||
"dependencies" : [
|
"dependencies" : [
|
||||||
|
"org.graalvm.compiler.debug",
|
||||||
"org.graalvm.util",
|
"org.graalvm.util",
|
||||||
"mx:JUNIT",
|
"mx:JUNIT",
|
||||||
],
|
],
|
||||||
|
|
|
@ -32,8 +32,6 @@ module jdk.internal.vm.compiler {
|
||||||
|
|
||||||
uses org.graalvm.compiler.code.DisassemblerProvider;
|
uses org.graalvm.compiler.code.DisassemblerProvider;
|
||||||
uses org.graalvm.compiler.core.match.MatchStatementSet;
|
uses org.graalvm.compiler.core.match.MatchStatementSet;
|
||||||
uses org.graalvm.compiler.debug.DebugConfigCustomizer;
|
|
||||||
uses org.graalvm.compiler.debug.DebugInitializationParticipant;
|
|
||||||
uses org.graalvm.compiler.debug.TTYStreamProvider;
|
uses org.graalvm.compiler.debug.TTYStreamProvider;
|
||||||
uses org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
|
uses org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
|
||||||
uses org.graalvm.compiler.hotspot.HotSpotBackendFactory;
|
uses org.graalvm.compiler.hotspot.HotSpotBackendFactory;
|
||||||
|
@ -51,7 +49,6 @@ module jdk.internal.vm.compiler {
|
||||||
exports org.graalvm.compiler.core.common to jdk.aot;
|
exports org.graalvm.compiler.core.common to jdk.aot;
|
||||||
exports org.graalvm.compiler.core.target to jdk.aot;
|
exports org.graalvm.compiler.core.target to jdk.aot;
|
||||||
exports org.graalvm.compiler.debug to jdk.aot;
|
exports org.graalvm.compiler.debug to jdk.aot;
|
||||||
exports org.graalvm.compiler.debug.internal to jdk.aot;
|
|
||||||
exports org.graalvm.compiler.graph to jdk.aot;
|
exports org.graalvm.compiler.graph to jdk.aot;
|
||||||
exports org.graalvm.compiler.hotspot to jdk.aot;
|
exports org.graalvm.compiler.hotspot to jdk.aot;
|
||||||
exports org.graalvm.compiler.hotspot.meta to jdk.aot;
|
exports org.graalvm.compiler.hotspot.meta to jdk.aot;
|
||||||
|
@ -66,6 +63,7 @@ module jdk.internal.vm.compiler {
|
||||||
exports org.graalvm.compiler.options to jdk.aot;
|
exports org.graalvm.compiler.options to jdk.aot;
|
||||||
exports org.graalvm.compiler.phases to jdk.aot;
|
exports org.graalvm.compiler.phases to jdk.aot;
|
||||||
exports org.graalvm.compiler.phases.tiers to jdk.aot;
|
exports org.graalvm.compiler.phases.tiers to jdk.aot;
|
||||||
|
exports org.graalvm.compiler.printer to jdk.aot;
|
||||||
exports org.graalvm.compiler.runtime to jdk.aot;
|
exports org.graalvm.compiler.runtime to jdk.aot;
|
||||||
exports org.graalvm.compiler.replacements to jdk.aot;
|
exports org.graalvm.compiler.replacements to jdk.aot;
|
||||||
exports org.graalvm.compiler.word to jdk.aot;
|
exports org.graalvm.compiler.word to jdk.aot;
|
||||||
|
|
|
@ -220,7 +220,7 @@ public class ControlFlowAnchorDirectiveTest extends GraalCompilerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testClone() {
|
public void testClone() {
|
||||||
StructuredGraph g = parseEager("preventPeelSnippet", AllowAssumptions.NO);
|
StructuredGraph g = parseEager("preventPeelSnippet", AllowAssumptions.NO);
|
||||||
g.copy();
|
g.copy(g.getDebug());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<NodeCount> getNodeCountAnnotations(StructuredGraph graph) {
|
private static List<NodeCount> getNodeCountAnnotations(StructuredGraph graph) {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.asm.aarch64;
|
package org.graalvm.compiler.asm.aarch64;
|
||||||
|
|
||||||
|
import static jdk.vm.ci.aarch64.AArch64.cpuRegisters;
|
||||||
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADD;
|
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADD;
|
||||||
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADDS;
|
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADDS;
|
||||||
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADR;
|
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADR;
|
||||||
|
@ -1010,6 +1011,100 @@ public abstract class AArch64Assembler extends Assembler {
|
||||||
loadStoreInstruction(LDRS, rt, address, generalFromSize(targetSize), transferSize);
|
loadStoreInstruction(LDRS, rt, address, generalFromSize(targetSize), transferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum PrefetchMode {
|
||||||
|
PLDL1KEEP(0b00000),
|
||||||
|
PLDL1STRM(0b00001),
|
||||||
|
PLDL2KEEP(0b00010),
|
||||||
|
PLDL2STRM(0b00011),
|
||||||
|
PLDL3KEEP(0b00100),
|
||||||
|
PLDL3STRM(0b00101),
|
||||||
|
|
||||||
|
PLIL1KEEP(0b01000),
|
||||||
|
PLIL1STRM(0b01001),
|
||||||
|
PLIL2KEEP(0b01010),
|
||||||
|
PLIL2STRM(0b01011),
|
||||||
|
PLIL3KEEP(0b01100),
|
||||||
|
PLIL3STRM(0b01101),
|
||||||
|
|
||||||
|
PSTL1KEEP(0b10000),
|
||||||
|
PSTL1STRM(0b10001),
|
||||||
|
PSTL2KEEP(0b10010),
|
||||||
|
PSTL2STRM(0b10011),
|
||||||
|
PSTL3KEEP(0b10100),
|
||||||
|
PSTL3STRM(0b10101);
|
||||||
|
|
||||||
|
private final int encoding;
|
||||||
|
|
||||||
|
PrefetchMode(int encoding) {
|
||||||
|
this.encoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrefetchMode[] modes = {
|
||||||
|
PLDL1KEEP,
|
||||||
|
PLDL1STRM,
|
||||||
|
PLDL2KEEP,
|
||||||
|
PLDL2STRM,
|
||||||
|
PLDL3KEEP,
|
||||||
|
PLDL3STRM,
|
||||||
|
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
|
||||||
|
PLIL1KEEP,
|
||||||
|
PLIL1STRM,
|
||||||
|
PLIL2KEEP,
|
||||||
|
PLIL2STRM,
|
||||||
|
PLIL3KEEP,
|
||||||
|
PLIL3STRM,
|
||||||
|
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
|
||||||
|
PSTL1KEEP,
|
||||||
|
PSTL1STRM,
|
||||||
|
PSTL2KEEP,
|
||||||
|
PSTL2STRM,
|
||||||
|
PSTL3KEEP,
|
||||||
|
PSTL3STRM
|
||||||
|
};
|
||||||
|
|
||||||
|
public static PrefetchMode lookup(int enc) {
|
||||||
|
assert enc >= 00 && enc < modes.length;
|
||||||
|
return modes[enc];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Register toRegister() {
|
||||||
|
return cpuRegisters.get(encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* implements a prefetch at a 64-bit aligned address using a scaled 12 bit or unscaled 9 bit
|
||||||
|
* displacement addressing mode
|
||||||
|
*
|
||||||
|
* @param rt general purpose register. May not be null, zr or stackpointer.
|
||||||
|
*
|
||||||
|
* @param address only displacement addressing modes allowed. May not be null.
|
||||||
|
*/
|
||||||
|
public void prfm(AArch64Address address, PrefetchMode mode) {
|
||||||
|
assert (address.getAddressingMode() == AddressingMode.IMMEDIATE_SCALED ||
|
||||||
|
address.getAddressingMode() == AddressingMode.IMMEDIATE_UNSCALED ||
|
||||||
|
address.getAddressingMode() == AddressingMode.REGISTER_OFFSET);
|
||||||
|
assert mode != null;
|
||||||
|
final int srcSize = 64;
|
||||||
|
final int transferSize = NumUtil.log2Ceil(srcSize / 8);
|
||||||
|
final Register rt = mode.toRegister();
|
||||||
|
// this looks weird but that's because loadStoreInstruction is weird
|
||||||
|
// instruction select fields are size [31:30], v [26] and opc [25:24]
|
||||||
|
// prfm requires size == 0b11, v == 0b0 and opc == 0b11
|
||||||
|
// passing LDRS ensures opc[1] == 0b1
|
||||||
|
// (n.b. passing LDR/STR makes no difference to opc[1:0]!!)
|
||||||
|
// passing General64 ensures opc[0] == 0b1 and v = 0b0
|
||||||
|
// (n.b. passing General32 ensures opc[0] == 0b0 and v = 0b0)
|
||||||
|
// srcSize 64 ensures size == 0b11
|
||||||
|
loadStoreInstruction(LDRS, rt, address, General64, transferSize);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores register rt into memory pointed by address.
|
* Stores register rt into memory pointed by address.
|
||||||
*
|
*
|
||||||
|
|
|
@ -146,10 +146,10 @@ public class AArch64MacroAssembler extends AArch64Assembler {
|
||||||
return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
|
return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (NumUtil.isSignedNbit(9, displacement)) {
|
if (displacementScalable && NumUtil.isUnsignedNbit(12, scaledDisplacement)) {
|
||||||
return new AddressGenerationPlan(NO_WORK, IMMEDIATE_UNSCALED, false);
|
|
||||||
} else if (displacementScalable && NumUtil.isUnsignedNbit(12, scaledDisplacement)) {
|
|
||||||
return new AddressGenerationPlan(NO_WORK, IMMEDIATE_SCALED, false);
|
return new AddressGenerationPlan(NO_WORK, IMMEDIATE_SCALED, false);
|
||||||
|
} else if (NumUtil.isSignedNbit(9, displacement)) {
|
||||||
|
return new AddressGenerationPlan(NO_WORK, IMMEDIATE_UNSCALED, false);
|
||||||
} else {
|
} else {
|
||||||
boolean needsScratch = !isArithmeticImmediate(displacement);
|
boolean needsScratch = !isArithmeticImmediate(displacement);
|
||||||
return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
|
return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
|
||||||
|
|
|
@ -31,8 +31,7 @@ import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.code.DisassemblerProvider;
|
import org.graalvm.compiler.code.DisassemblerProvider;
|
||||||
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
||||||
import org.graalvm.compiler.core.target.Backend;
|
import org.graalvm.compiler.core.target.Backend;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
@ -83,10 +82,12 @@ public abstract class AssemblerTest extends GraalTest {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
|
protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
|
||||||
ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
|
ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
|
||||||
try (Scope s = Debug.scope("assembleMethod", method, codeCache)) {
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = getDebugContext(options);
|
||||||
|
try (DebugContext.Scope s = debug.scope("assembleMethod", method, codeCache)) {
|
||||||
RegisterConfig registerConfig = codeCache.getRegisterConfig();
|
RegisterConfig registerConfig = codeCache.getRegisterConfig();
|
||||||
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
|
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).compilationId(compilationId).build();
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
|
||||||
CallingConvention cc = backend.newLIRGenerationResult(compilationId, null, null, graph, null).getCallingConvention();
|
CallingConvention cc = backend.newLIRGenerationResult(compilationId, null, null, graph, null).getCallingConvention();
|
||||||
|
|
||||||
CompilationResult compResult = new CompilationResult();
|
CompilationResult compResult = new CompilationResult();
|
||||||
|
@ -95,7 +96,7 @@ public abstract class AssemblerTest extends GraalTest {
|
||||||
compResult.setTotalFrameSize(0);
|
compResult.setTotalFrameSize(0);
|
||||||
compResult.close();
|
compResult.close();
|
||||||
|
|
||||||
InstalledCode code = backend.addInstalledCode(method, asCompilationRequest(compilationId), compResult);
|
InstalledCode code = backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compResult);
|
||||||
|
|
||||||
for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
|
for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
|
||||||
String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
|
String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
|
||||||
|
@ -105,7 +106,7 @@ public abstract class AssemblerTest extends GraalTest {
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class BytecodeDisassembler {
|
||||||
stream.next();
|
stream.next();
|
||||||
opcode = stream.currentBC();
|
opcode = stream.currentBC();
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(String.format("Error disassembling %s%nPartial disassembly:%n%s", method.format("%H.%n(%p)"), buf.toString()), e);
|
throw new RuntimeException(String.format("Error disassembling %s%nPartial disassembly:%n%s", method.format("%H.%n(%p)"), buf.toString()), e);
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import jdk.vm.ci.meta.JavaConstant;
|
||||||
import org.graalvm.compiler.core.common.NumUtil;
|
import org.graalvm.compiler.core.common.NumUtil;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
|
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
|
||||||
import org.graalvm.compiler.core.common.type.IntegerStamp;
|
import org.graalvm.compiler.core.common.type.IntegerStamp;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.nodes.ValueNode;
|
import org.graalvm.compiler.nodes.ValueNode;
|
||||||
import org.graalvm.compiler.nodes.calc.AddNode;
|
import org.graalvm.compiler.nodes.calc.AddNode;
|
||||||
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
|
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
|
||||||
|
@ -47,12 +48,15 @@ public class AMD64AddressLowering extends AddressLowering {
|
||||||
AMD64AddressNode ret = new AMD64AddressNode(base, offset);
|
AMD64AddressNode ret = new AMD64AddressNode(base, offset);
|
||||||
boolean changed;
|
boolean changed;
|
||||||
do {
|
do {
|
||||||
changed = improve(ret);
|
changed = improve(base.getDebug(), ret);
|
||||||
} while (changed);
|
} while (changed);
|
||||||
return base.graph().unique(ret);
|
return base.graph().unique(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean improve(AMD64AddressNode ret) {
|
/**
|
||||||
|
* @param debug
|
||||||
|
*/
|
||||||
|
protected boolean improve(DebugContext debug, AMD64AddressNode ret) {
|
||||||
ValueNode newBase = improveInput(ret, ret.getBase(), 0);
|
ValueNode newBase = improveInput(ret, ret.getBase(), 0);
|
||||||
if (newBase != ret.getBase()) {
|
if (newBase != ret.getBase()) {
|
||||||
ret.setBase(newBase);
|
ret.setBase(newBase);
|
||||||
|
|
|
@ -26,10 +26,16 @@ package org.graalvm.compiler.core.amd64;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
|
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
|
||||||
import org.graalvm.compiler.core.common.LIRKind;
|
import org.graalvm.compiler.core.common.LIRKind;
|
||||||
import org.graalvm.compiler.graph.NodeClass;
|
import org.graalvm.compiler.graph.NodeClass;
|
||||||
|
import org.graalvm.compiler.graph.spi.Simplifiable;
|
||||||
|
import org.graalvm.compiler.graph.spi.SimplifierTool;
|
||||||
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
|
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
|
||||||
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
||||||
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
||||||
|
import org.graalvm.compiler.nodes.ConstantNode;
|
||||||
|
import org.graalvm.compiler.nodes.LoopBeginNode;
|
||||||
|
import org.graalvm.compiler.nodes.PhiNode;
|
||||||
import org.graalvm.compiler.nodes.ValueNode;
|
import org.graalvm.compiler.nodes.ValueNode;
|
||||||
|
import org.graalvm.compiler.nodes.calc.AddNode;
|
||||||
import org.graalvm.compiler.nodes.memory.address.AddressNode;
|
import org.graalvm.compiler.nodes.memory.address.AddressNode;
|
||||||
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
||||||
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
||||||
|
@ -42,7 +48,7 @@ import jdk.vm.ci.meta.Value;
|
||||||
* optional.
|
* optional.
|
||||||
*/
|
*/
|
||||||
@NodeInfo
|
@NodeInfo
|
||||||
public class AMD64AddressNode extends AddressNode implements LIRLowerable {
|
public class AMD64AddressNode extends AddressNode implements Simplifiable, LIRLowerable {
|
||||||
|
|
||||||
public static final NodeClass<AMD64AddressNode> TYPE = NodeClass.create(AMD64AddressNode.class);
|
public static final NodeClass<AMD64AddressNode> TYPE = NodeClass.create(AMD64AddressNode.class);
|
||||||
|
|
||||||
|
@ -64,6 +70,28 @@ public class AMD64AddressNode extends AddressNode implements LIRLowerable {
|
||||||
this.scale = Scale.Times1;
|
this.scale = Scale.Times1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void canonicalizeIndex(SimplifierTool tool) {
|
||||||
|
if (index instanceof AddNode) {
|
||||||
|
AddNode add = (AddNode) index;
|
||||||
|
ValueNode valX = add.getX();
|
||||||
|
if (valX instanceof PhiNode) {
|
||||||
|
PhiNode phi = (PhiNode) valX;
|
||||||
|
if (phi.merge() instanceof LoopBeginNode) {
|
||||||
|
LoopBeginNode loopNode = (LoopBeginNode) phi.merge();
|
||||||
|
if (!loopNode.isSimpleLoop()) {
|
||||||
|
ValueNode valY = add.getY();
|
||||||
|
if (valY instanceof ConstantNode) {
|
||||||
|
int addBy = valY.asJavaConstant().asInt();
|
||||||
|
displacement = displacement + scale.value * addBy;
|
||||||
|
replaceFirstInput(index, phi);
|
||||||
|
tool.addToWorkList(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generate(NodeLIRBuilderTool gen) {
|
public void generate(NodeLIRBuilderTool gen) {
|
||||||
LIRGeneratorTool tool = gen.getLIRGeneratorTool();
|
LIRGeneratorTool tool = gen.getLIRGeneratorTool();
|
||||||
|
@ -135,4 +163,9 @@ public class AMD64AddressNode extends AddressNode implements LIRLowerable {
|
||||||
public long getMaxConstantDisplacement() {
|
public long getMaxConstantDisplacement() {
|
||||||
return displacement;
|
return displacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void simplify(SimplifierTool tool) {
|
||||||
|
canonicalizeIndex(tool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.QWORD;
|
||||||
import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD;
|
import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD;
|
||||||
import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SS;
|
import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SS;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.NumUtil;
|
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp;
|
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp;
|
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp;
|
import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp;
|
||||||
|
@ -44,12 +43,12 @@ import org.graalvm.compiler.asm.amd64.AMD64Assembler.AVXOp;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize;
|
import org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize;
|
||||||
import org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp;
|
import org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp;
|
||||||
import org.graalvm.compiler.core.common.LIRKind;
|
import org.graalvm.compiler.core.common.LIRKind;
|
||||||
|
import org.graalvm.compiler.core.common.NumUtil;
|
||||||
import org.graalvm.compiler.core.common.calc.Condition;
|
import org.graalvm.compiler.core.common.calc.Condition;
|
||||||
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
||||||
import org.graalvm.compiler.core.gen.NodeMatchRules;
|
import org.graalvm.compiler.core.gen.NodeMatchRules;
|
||||||
import org.graalvm.compiler.core.match.ComplexMatchResult;
|
import org.graalvm.compiler.core.match.ComplexMatchResult;
|
||||||
import org.graalvm.compiler.core.match.MatchRule;
|
import org.graalvm.compiler.core.match.MatchRule;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.lir.LIRFrameState;
|
import org.graalvm.compiler.lir.LIRFrameState;
|
||||||
import org.graalvm.compiler.lir.LIRValueUtil;
|
import org.graalvm.compiler.lir.LIRValueUtil;
|
||||||
|
@ -147,7 +146,7 @@ public class AMD64NodeMatchRules extends NodeMatchRules {
|
||||||
matchedAsConstant = true;
|
matchedAsConstant = true;
|
||||||
}
|
}
|
||||||
if (kind.isXMM()) {
|
if (kind.isXMM()) {
|
||||||
Debug.log("Skipping constant compares for float kinds");
|
ifNode.getDebug().log("Skipping constant compares for float kinds");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ package org.graalvm.compiler.core.common;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Assertions;
|
import org.graalvm.compiler.debug.Assertions;
|
||||||
import org.graalvm.compiler.options.Option;
|
import org.graalvm.compiler.options.Option;
|
||||||
import org.graalvm.compiler.options.OptionType;
|
|
||||||
import org.graalvm.compiler.options.OptionKey;
|
import org.graalvm.compiler.options.OptionKey;
|
||||||
|
import org.graalvm.compiler.options.OptionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class encapsulates options that control the behavior of the Graal compiler.
|
* This class encapsulates options that control the behavior of the Graal compiler.
|
||||||
|
@ -109,6 +109,9 @@ public final class GraalOptions {
|
||||||
@Option(help = "", type = OptionType.Debug)
|
@Option(help = "", type = OptionType.Debug)
|
||||||
public static final OptionKey<Boolean> LoopUnswitch = new OptionKey<>(true);
|
public static final OptionKey<Boolean> LoopUnswitch = new OptionKey<>(true);
|
||||||
|
|
||||||
|
@Option(help = "", type = OptionType.Debug)
|
||||||
|
public static final OptionKey<Boolean> PartialUnroll = new OptionKey<>(true);
|
||||||
|
|
||||||
@Option(help = "", type = OptionType.Expert)
|
@Option(help = "", type = OptionType.Expert)
|
||||||
public static final OptionKey<Float> MinimumPeelProbability = new OptionKey<>(0.35f);
|
public static final OptionKey<Float> MinimumPeelProbability = new OptionKey<>(0.35f);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.util.Deque;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Indent;
|
import org.graalvm.compiler.debug.Indent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,8 +40,8 @@ import org.graalvm.compiler.debug.Indent;
|
||||||
*/
|
*/
|
||||||
public final class BiDirectionalTraceBuilder {
|
public final class BiDirectionalTraceBuilder {
|
||||||
|
|
||||||
public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
return new BiDirectionalTraceBuilder(blocks).build(startBlock, blocks, pred);
|
return new BiDirectionalTraceBuilder(blocks).build(debug, startBlock, blocks, pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Deque<AbstractBlockBase<?>> worklist;
|
private final Deque<AbstractBlockBase<?>> worklist;
|
||||||
|
@ -69,22 +69,22 @@ public final class BiDirectionalTraceBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private TraceBuilderResult build(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
private TraceBuilderResult build(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
try (Indent indent = Debug.logAndIndent("BiDirectionalTraceBuilder: start trace building")) {
|
try (Indent indent = debug.logAndIndent("BiDirectionalTraceBuilder: start trace building")) {
|
||||||
ArrayList<Trace> traces = buildTraces();
|
ArrayList<Trace> traces = buildTraces(debug);
|
||||||
assert traces.get(0).getBlocks()[0].equals(startBlock) : "The first traces always contains the start block";
|
assert traces.get(0).getBlocks()[0].equals(startBlock) : "The first traces always contains the start block";
|
||||||
return TraceBuilderResult.create(blocks, traces, blockToTrace, pred);
|
return TraceBuilderResult.create(debug, blocks, traces, blockToTrace, pred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<Trace> buildTraces() {
|
protected ArrayList<Trace> buildTraces(DebugContext debug) {
|
||||||
ArrayList<Trace> traces = new ArrayList<>();
|
ArrayList<Trace> traces = new ArrayList<>();
|
||||||
// process worklist
|
// process worklist
|
||||||
while (!worklist.isEmpty()) {
|
while (!worklist.isEmpty()) {
|
||||||
AbstractBlockBase<?> block = worklist.pollFirst();
|
AbstractBlockBase<?> block = worklist.pollFirst();
|
||||||
assert block != null;
|
assert block != null;
|
||||||
if (!processed(block)) {
|
if (!processed(block)) {
|
||||||
Trace trace = new Trace(startTrace(block));
|
Trace trace = new Trace(startTrace(debug, block));
|
||||||
for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
|
for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
|
||||||
blockToTrace[traceBlock.getId()] = trace;
|
blockToTrace[traceBlock.getId()] = trace;
|
||||||
}
|
}
|
||||||
|
@ -97,14 +97,16 @@ public final class BiDirectionalTraceBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new trace starting at {@code block}.
|
* Build a new trace starting at {@code block}.
|
||||||
|
*
|
||||||
|
* @param debug
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private Collection<AbstractBlockBase<?>> startTrace(AbstractBlockBase<?> block) {
|
private Collection<AbstractBlockBase<?>> startTrace(DebugContext debug, AbstractBlockBase<?> block) {
|
||||||
ArrayDeque<AbstractBlockBase<?>> trace = new ArrayDeque<>();
|
ArrayDeque<AbstractBlockBase<?>> trace = new ArrayDeque<>();
|
||||||
try (Indent i = Debug.logAndIndent("StartTrace: %s", block)) {
|
try (Indent i = debug.logAndIndent("StartTrace: %s", block)) {
|
||||||
try (Indent indentFront = Debug.logAndIndent("Head:")) {
|
try (Indent indentFront = debug.logAndIndent("Head:")) {
|
||||||
for (AbstractBlockBase<?> currentBlock = block; currentBlock != null; currentBlock = selectPredecessor(currentBlock)) {
|
for (AbstractBlockBase<?> currentBlock = block; currentBlock != null; currentBlock = selectPredecessor(currentBlock)) {
|
||||||
addBlockToTrace(currentBlock);
|
addBlockToTrace(debug, currentBlock);
|
||||||
trace.addFirst(currentBlock);
|
trace.addFirst(currentBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,21 +116,21 @@ public final class BiDirectionalTraceBuilder {
|
||||||
b.setLinearScanNumber(blockNr++);
|
b.setLinearScanNumber(blockNr++);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Indent indentBack = Debug.logAndIndent("Tail:")) {
|
try (Indent indentBack = debug.logAndIndent("Tail:")) {
|
||||||
for (AbstractBlockBase<?> currentBlock = selectSuccessor(block); currentBlock != null; currentBlock = selectSuccessor(currentBlock)) {
|
for (AbstractBlockBase<?> currentBlock = selectSuccessor(block); currentBlock != null; currentBlock = selectSuccessor(currentBlock)) {
|
||||||
addBlockToTrace(currentBlock);
|
addBlockToTrace(debug, currentBlock);
|
||||||
trace.addLast(currentBlock);
|
trace.addLast(currentBlock);
|
||||||
/* This time we can number the blocks immediately as we go forwards. */
|
/* This time we can number the blocks immediately as we go forwards. */
|
||||||
currentBlock.setLinearScanNumber(blockNr++);
|
currentBlock.setLinearScanNumber(blockNr++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.log("Trace: %s", trace);
|
debug.log("Trace: %s", trace);
|
||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBlockToTrace(AbstractBlockBase<?> currentBlock) {
|
private void addBlockToTrace(DebugContext debug, AbstractBlockBase<?> currentBlock) {
|
||||||
Debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
|
debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
|
||||||
processed.set(currentBlock.getId());
|
processed.set(currentBlock.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,17 +26,18 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds traces consisting of a single basic block.
|
* Builds traces consisting of a single basic block.
|
||||||
*/
|
*/
|
||||||
public final class SingleBlockTraceBuilder {
|
public final class SingleBlockTraceBuilder {
|
||||||
|
|
||||||
public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
return build(startBlock, blocks, pred);
|
return build(debug, startBlock, blocks, pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TraceBuilderResult build(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
private static TraceBuilderResult build(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
Trace[] blockToTrace = new Trace[blocks.length];
|
Trace[] blockToTrace = new Trace[blocks.length];
|
||||||
ArrayList<Trace> traces = new ArrayList<>(blocks.length);
|
ArrayList<Trace> traces = new ArrayList<>(blocks.length);
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ public final class SingleBlockTraceBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert traces.get(0).getBlocks()[0].equals(startBlock) : "The first traces always contains the start block";
|
assert traces.get(0).getBlocks()[0].equals(startBlock) : "The first traces always contains the start block";
|
||||||
return TraceBuilderResult.create(blocks, traces, blockToTrace, pred);
|
return TraceBuilderResult.create(debug, blocks, traces, blockToTrace, pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Indent;
|
import org.graalvm.compiler.debug.Indent;
|
||||||
|
|
||||||
public final class TraceBuilderResult {
|
public final class TraceBuilderResult {
|
||||||
|
@ -39,9 +39,9 @@ public final class TraceBuilderResult {
|
||||||
private final ArrayList<Trace> traces;
|
private final ArrayList<Trace> traces;
|
||||||
private final Trace[] blockToTrace;
|
private final Trace[] blockToTrace;
|
||||||
|
|
||||||
static TraceBuilderResult create(AbstractBlockBase<?>[] blocks, ArrayList<Trace> traces, Trace[] blockToTrace, TrivialTracePredicate pred) {
|
static TraceBuilderResult create(DebugContext debug, AbstractBlockBase<?>[] blocks, ArrayList<Trace> traces, Trace[] blockToTrace, TrivialTracePredicate pred) {
|
||||||
connect(traces, blockToTrace);
|
connect(traces, blockToTrace);
|
||||||
ArrayList<Trace> newTraces = reorderTraces(traces, pred);
|
ArrayList<Trace> newTraces = reorderTraces(debug, traces, pred);
|
||||||
TraceBuilderResult traceBuilderResult = new TraceBuilderResult(newTraces, blockToTrace);
|
TraceBuilderResult traceBuilderResult = new TraceBuilderResult(newTraces, blockToTrace);
|
||||||
traceBuilderResult.numberTraces();
|
traceBuilderResult.numberTraces();
|
||||||
assert verify(traceBuilderResult, blocks.length);
|
assert verify(traceBuilderResult, blocks.length);
|
||||||
|
@ -157,11 +157,11 @@ public final class TraceBuilderResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private static ArrayList<Trace> reorderTraces(ArrayList<Trace> oldTraces, TrivialTracePredicate pred) {
|
private static ArrayList<Trace> reorderTraces(DebugContext debug, ArrayList<Trace> oldTraces, TrivialTracePredicate pred) {
|
||||||
if (pred == null) {
|
if (pred == null) {
|
||||||
return oldTraces;
|
return oldTraces;
|
||||||
}
|
}
|
||||||
try (Indent indent = Debug.logAndIndent("ReorderTrace")) {
|
try (Indent indent = debug.logAndIndent("ReorderTrace")) {
|
||||||
ArrayList<Trace> newTraces = new ArrayList<>(oldTraces.size());
|
ArrayList<Trace> newTraces = new ArrayList<>(oldTraces.size());
|
||||||
for (int oldTraceIdx = 0; oldTraceIdx < oldTraces.size(); oldTraceIdx++) {
|
for (int oldTraceIdx = 0; oldTraceIdx < oldTraces.size(); oldTraceIdx++) {
|
||||||
Trace currentTrace = oldTraces.get(oldTraceIdx);
|
Trace currentTrace = oldTraces.get(oldTraceIdx);
|
||||||
|
@ -171,7 +171,7 @@ public final class TraceBuilderResult {
|
||||||
addTrace(newTraces, currentTrace);
|
addTrace(newTraces, currentTrace);
|
||||||
for (Trace succTrace : currentTrace.getSuccessors()) {
|
for (Trace succTrace : currentTrace.getSuccessors()) {
|
||||||
if (pred.isTrivialTrace(succTrace) && !alreadyProcessed(newTraces, succTrace)) {
|
if (pred.isTrivialTrace(succTrace) && !alreadyProcessed(newTraces, succTrace)) {
|
||||||
Debug.log("Moving trivial trace from %d to %d", succTrace.getId(), newTraces.size());
|
debug.log("Moving trivial trace from %d to %d", succTrace.getId(), newTraces.size());
|
||||||
// add trivial successor trace
|
// add trivial successor trace
|
||||||
addTrace(newTraces, succTrace);
|
addTrace(newTraces, succTrace);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,33 +25,32 @@ package org.graalvm.compiler.core.common.alloc;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.Indent;
|
import org.graalvm.compiler.debug.Indent;
|
||||||
|
|
||||||
public final class TraceStatisticsPrinter {
|
public final class TraceStatisticsPrinter {
|
||||||
private static final String SEP = ";";
|
private static final String SEP = ";";
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public static void printTraceStatistics(TraceBuilderResult result, String compilationUnitName) {
|
public static void printTraceStatistics(DebugContext debug, TraceBuilderResult result, String compilationUnitName) {
|
||||||
try (Scope s = Debug.scope("DumpTraceStatistics")) {
|
try (DebugContext.Scope s = debug.scope("DumpTraceStatistics")) {
|
||||||
if (Debug.isLogEnabled(Debug.VERBOSE_LEVEL)) {
|
if (debug.isLogEnabled(DebugContext.VERBOSE_LEVEL)) {
|
||||||
print(result, compilationUnitName);
|
print(debug, result, compilationUnitName);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Debug.handle(e);
|
debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected static void print(TraceBuilderResult result, String compilationUnitName) {
|
protected static void print(DebugContext debug, TraceBuilderResult result, String compilationUnitName) {
|
||||||
List<Trace> traces = result.getTraces();
|
List<Trace> traces = result.getTraces();
|
||||||
int numTraces = traces.size();
|
int numTraces = traces.size();
|
||||||
|
|
||||||
try (Indent indent0 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<tracestatistics>")) {
|
try (Indent indent0 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<tracestatistics>")) {
|
||||||
Debug.log(Debug.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
|
debug.log(DebugContext.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
|
||||||
try (Indent indent1 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<traces>")) {
|
try (Indent indent1 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<traces>")) {
|
||||||
printRawLine("tracenumber", "total", "min", "max", "numBlocks");
|
printRawLine(debug, "tracenumber", "total", "min", "max", "numBlocks");
|
||||||
for (int i = 0; i < numTraces; i++) {
|
for (int i = 0; i < numTraces; i++) {
|
||||||
AbstractBlockBase<?>[] t = traces.get(i).getBlocks();
|
AbstractBlockBase<?>[] t = traces.get(i).getBlocks();
|
||||||
double total = 0;
|
double total = 0;
|
||||||
|
@ -67,20 +66,20 @@ public final class TraceStatisticsPrinter {
|
||||||
max = probability;
|
max = probability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printLine(i, total, min, max, t.length);
|
printLine(debug, i, total, min, max, t.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.log(Debug.VERBOSE_LEVEL, "</traces>");
|
debug.log(DebugContext.VERBOSE_LEVEL, "</traces>");
|
||||||
}
|
}
|
||||||
Debug.log(Debug.VERBOSE_LEVEL, "</tracestatistics>");
|
debug.log(DebugContext.VERBOSE_LEVEL, "</tracestatistics>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printRawLine(Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) {
|
private static void printRawLine(DebugContext debug, Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) {
|
||||||
Debug.log(Debug.VERBOSE_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString()));
|
debug.log(DebugContext.VERBOSE_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printLine(int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) {
|
private static void printLine(DebugContext debug, int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) {
|
||||||
printRawLine(tracenr, totalTime, minProb, maxProb, numBlocks);
|
printRawLine(debug, tracenr, totalTime, minProb, maxProb, numBlocks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.PriorityQueue;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Indent;
|
import org.graalvm.compiler.debug.Indent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,8 +37,8 @@ import org.graalvm.compiler.debug.Indent;
|
||||||
*/
|
*/
|
||||||
public final class UniDirectionalTraceBuilder {
|
public final class UniDirectionalTraceBuilder {
|
||||||
|
|
||||||
public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
return new UniDirectionalTraceBuilder(blocks).build(startBlock, blocks, pred);
|
return new UniDirectionalTraceBuilder(blocks).build(debug, startBlock, blocks, pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final PriorityQueue<AbstractBlockBase<?>> worklist;
|
private final PriorityQueue<AbstractBlockBase<?>> worklist;
|
||||||
|
@ -71,14 +71,14 @@ public final class UniDirectionalTraceBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private TraceBuilderResult build(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
private TraceBuilderResult build(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
|
||||||
try (Indent indent = Debug.logAndIndent("UniDirectionalTraceBuilder: start trace building: %s", startBlock)) {
|
try (Indent indent = debug.logAndIndent("UniDirectionalTraceBuilder: start trace building: %s", startBlock)) {
|
||||||
ArrayList<Trace> traces = buildTraces(startBlock);
|
ArrayList<Trace> traces = buildTraces(debug, startBlock);
|
||||||
return TraceBuilderResult.create(blocks, traces, blockToTrace, pred);
|
return TraceBuilderResult.create(debug, blocks, traces, blockToTrace, pred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<Trace> buildTraces(AbstractBlockBase<?> startBlock) {
|
protected ArrayList<Trace> buildTraces(DebugContext debug, AbstractBlockBase<?> startBlock) {
|
||||||
ArrayList<Trace> traces = new ArrayList<>();
|
ArrayList<Trace> traces = new ArrayList<>();
|
||||||
// add start block
|
// add start block
|
||||||
worklist.add(startBlock);
|
worklist.add(startBlock);
|
||||||
|
@ -87,7 +87,7 @@ public final class UniDirectionalTraceBuilder {
|
||||||
AbstractBlockBase<?> block = worklist.poll();
|
AbstractBlockBase<?> block = worklist.poll();
|
||||||
assert block != null;
|
assert block != null;
|
||||||
if (!processed(block)) {
|
if (!processed(block)) {
|
||||||
Trace trace = new Trace(startTrace(block));
|
Trace trace = new Trace(startTrace(debug, block));
|
||||||
for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
|
for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
|
||||||
blockToTrace[traceBlock.getId()] = trace;
|
blockToTrace[traceBlock.getId()] = trace;
|
||||||
}
|
}
|
||||||
|
@ -102,13 +102,13 @@ public final class UniDirectionalTraceBuilder {
|
||||||
* Build a new trace starting at {@code block}.
|
* Build a new trace starting at {@code block}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private List<AbstractBlockBase<?>> startTrace(AbstractBlockBase<?> block) {
|
private List<AbstractBlockBase<?>> startTrace(DebugContext debug, AbstractBlockBase<?> block) {
|
||||||
assert checkPredecessorsProcessed(block);
|
assert checkPredecessorsProcessed(block);
|
||||||
ArrayList<AbstractBlockBase<?>> trace = new ArrayList<>();
|
ArrayList<AbstractBlockBase<?>> trace = new ArrayList<>();
|
||||||
int blockNumber = 0;
|
int blockNumber = 0;
|
||||||
try (Indent i = Debug.logAndIndent("StartTrace: %s", block)) {
|
try (Indent i = debug.logAndIndent("StartTrace: %s", block)) {
|
||||||
for (AbstractBlockBase<?> currentBlock = block; currentBlock != null; currentBlock = selectNext(currentBlock)) {
|
for (AbstractBlockBase<?> currentBlock = block; currentBlock != null; currentBlock = selectNext(currentBlock)) {
|
||||||
Debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
|
debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
|
||||||
processed.set(currentBlock.getId());
|
processed.set(currentBlock.getId());
|
||||||
trace.add(currentBlock);
|
trace.add(currentBlock);
|
||||||
unblock(currentBlock);
|
unblock(currentBlock);
|
||||||
|
|
|
@ -87,6 +87,10 @@ public abstract class Loop<T extends AbstractBlockBase<T>> {
|
||||||
return exits;
|
return exits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addExit(T t) {
|
||||||
|
exits.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if one loop is a transitive parent of another loop.
|
* Determines if one loop is a transitive parent of another loop.
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -48,14 +46,11 @@ import org.graalvm.compiler.api.replacements.Snippet.VarargsParameter;
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
import org.graalvm.compiler.bytecode.BridgeMethodUtils;
|
import org.graalvm.compiler.bytecode.BridgeMethodUtils;
|
||||||
import org.graalvm.compiler.core.CompilerThreadFactory;
|
import org.graalvm.compiler.core.CompilerThreadFactory;
|
||||||
import org.graalvm.compiler.core.CompilerThreadFactory.DebugConfigAccess;
|
|
||||||
import org.graalvm.compiler.core.common.LIRKind;
|
import org.graalvm.compiler.core.common.LIRKind;
|
||||||
import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
|
import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
import org.graalvm.compiler.debug.DebugEnvironment;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.DelegatingDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.NodeClass;
|
import org.graalvm.compiler.graph.NodeClass;
|
||||||
|
@ -203,12 +198,7 @@ public class CheckGraalInvariants extends GraalCompilerTest {
|
||||||
String[] filters = property == null ? null : property.split(",");
|
String[] filters = property == null ? null : property.split(",");
|
||||||
|
|
||||||
OptionValues options = getInitialOptions();
|
OptionValues options = getInitialOptions();
|
||||||
CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread", new DebugConfigAccess() {
|
CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread");
|
||||||
@Override
|
|
||||||
public GraalDebugConfig getDebugConfig() {
|
|
||||||
return DebugEnvironment.ensureInitialized(options);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
int availableProcessors = Runtime.getRuntime().availableProcessors();
|
int availableProcessors = Runtime.getRuntime().availableProcessors();
|
||||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);
|
ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);
|
||||||
|
|
||||||
|
@ -216,17 +206,19 @@ public class CheckGraalInvariants extends GraalCompilerTest {
|
||||||
|
|
||||||
for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) {
|
for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) {
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(options, AllowAssumptions.YES).method(method).build();
|
try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
|
||||||
try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("CheckingGraph", graph, method)) {
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build();
|
||||||
graphBuilderSuite.apply(graph, context);
|
try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
|
||||||
// update phi stamps
|
graphBuilderSuite.apply(graph, context);
|
||||||
graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
|
// update phi stamps
|
||||||
checkGraph(context, graph);
|
graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
|
||||||
errors.add(String.format("Expected error while checking %s", m));
|
checkGraph(context, graph);
|
||||||
} catch (VerificationError e) {
|
errors.add(String.format("Expected error while checking %s", m));
|
||||||
// expected!
|
} catch (VerificationError e) {
|
||||||
} catch (Throwable e) {
|
// expected!
|
||||||
errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
|
} catch (Throwable e) {
|
||||||
|
errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errors.isEmpty()) {
|
if (errors.isEmpty()) {
|
||||||
|
@ -251,26 +243,29 @@ public class CheckGraalInvariants extends GraalCompilerTest {
|
||||||
String methodName = className + "." + m.getName();
|
String methodName = className + "." + m.getName();
|
||||||
if (matches(filters, methodName)) {
|
if (matches(filters, methodName)) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(options).method(method).build();
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("CheckingGraph", graph, method)) {
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
checkMethod(method);
|
try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
|
||||||
graphBuilderSuite.apply(graph, context);
|
checkMethod(method);
|
||||||
// update phi stamps
|
graphBuilderSuite.apply(graph, context);
|
||||||
graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
|
// update phi stamps
|
||||||
checkGraph(context, graph);
|
graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
|
||||||
} catch (VerificationError e) {
|
checkGraph(context, graph);
|
||||||
errors.add(e.getMessage());
|
} catch (VerificationError e) {
|
||||||
} catch (LinkageError e) {
|
errors.add(e.getMessage());
|
||||||
// suppress linkages errors resulting from eager resolution
|
} catch (LinkageError e) {
|
||||||
} catch (BailoutException e) {
|
// suppress linkages errors resulting from eager resolution
|
||||||
// Graal bail outs on certain patterns in Java bytecode (e.g.,
|
} catch (BailoutException e) {
|
||||||
// unbalanced monitors introduced by jacoco).
|
// Graal bail outs on certain patterns in Java bytecode
|
||||||
} catch (Throwable e) {
|
// (e.g.,
|
||||||
try {
|
// unbalanced monitors introduced by jacoco).
|
||||||
tool.handleParsingException(e);
|
} catch (Throwable e) {
|
||||||
} catch (Throwable t) {
|
try {
|
||||||
errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
|
tool.handleParsingException(e);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.ValueNode;
|
import org.graalvm.compiler.nodes.ValueNode;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
||||||
|
@ -310,7 +310,8 @@ public class ConditionalEliminationTest13 extends ConditionalEliminationTestBase
|
||||||
super.prepareGraph(graph, canonicalizer, context, applyLowering);
|
super.prepareGraph(graph, canonicalizer, context, applyLowering);
|
||||||
graph.clearAllStateAfter();
|
graph.clearAllStateAfter();
|
||||||
graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
|
graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After preparation");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After preparation");
|
||||||
canonicalizer.apply(graph, context);
|
canonicalizer.apply(graph, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,16 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.nodes.ProxyNode;
|
import org.graalvm.compiler.nodes.ProxyNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
|
import org.graalvm.compiler.phases.common.ConditionalEliminationPhase;
|
||||||
import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
|
import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
|
||||||
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
|
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.common.ConditionalEliminationPhase;
|
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -52,21 +52,22 @@ public class ConditionalEliminationTestBase extends GraalCompilerTest {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
|
protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
PhaseContext context = new PhaseContext(getProviders());
|
PhaseContext context = new PhaseContext(getProviders());
|
||||||
CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
|
CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
|
||||||
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
||||||
try (Debug.Scope scope = Debug.scope("ConditionalEliminationTest", graph)) {
|
try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) {
|
||||||
prepareGraph(graph, canonicalizer1, context, applyLowering);
|
prepareGraph(graph, canonicalizer1, context, applyLowering);
|
||||||
new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
|
new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
|
||||||
canonicalizer.apply(graph, context);
|
canonicalizer.apply(graph, context);
|
||||||
canonicalizer.apply(graph, context);
|
canonicalizer.apply(graph, context);
|
||||||
new ConvertDeoptimizeToGuardPhase().apply(graph, context);
|
new ConvertDeoptimizeToGuardPhase().apply(graph, context);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Debug.handle(t);
|
debug.handle(t);
|
||||||
}
|
}
|
||||||
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
|
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
|
||||||
try (Debug.Scope scope = Debug.scope("ConditionalEliminationTest.ReferenceGraph", referenceGraph)) {
|
try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest.ReferenceGraph", referenceGraph)) {
|
||||||
prepareGraph(referenceGraph, canonicalizer, context, applyLowering);
|
prepareGraph(referenceGraph, canonicalizer, context, applyLowering);
|
||||||
if (applyConditionalEliminationOnReference) {
|
if (applyConditionalEliminationOnReference) {
|
||||||
new ConditionalEliminationPhase(true).apply(referenceGraph, context);
|
new ConditionalEliminationPhase(true).apply(referenceGraph, context);
|
||||||
|
@ -75,7 +76,7 @@ public class ConditionalEliminationTestBase extends GraalCompilerTest {
|
||||||
canonicalizer.apply(referenceGraph, context);
|
canonicalizer.apply(referenceGraph, context);
|
||||||
new ConvertDeoptimizeToGuardPhase().apply(graph, context);
|
new ConvertDeoptimizeToGuardPhase().apply(graph, context);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Debug.handle(t);
|
debug.handle(t);
|
||||||
}
|
}
|
||||||
assertEquals(referenceGraph, graph);
|
assertEquals(referenceGraph, graph);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,14 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the following tests, the usages of local variable "a" are replaced with the integer constant
|
* In the following tests, the usages of local variable "a" are replaced with the integer constant
|
||||||
|
@ -81,17 +79,18 @@ public class DegeneratedLoopsTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
try (Scope s = Debug.scope("DegeneratedLoopsTest", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("DegeneratedLoopsTest", new DebugDumpScope(snippet))) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
HighTierContext context = getDefaultHighTierContext();
|
HighTierContext context = getDefaultHighTierContext();
|
||||||
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
||||||
new CanonicalizerPhase().apply(graph, context);
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
|
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, referenceGraph, "ReferenceGraph");
|
debug.dump(DebugContext.BASIC_LEVEL, referenceGraph, "ReferenceGraph");
|
||||||
assertEquals(referenceGraph, graph);
|
assertEquals(referenceGraph, graph);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.core.phases.HighTier;
|
import org.graalvm.compiler.core.phases.HighTier;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
|
@ -72,7 +73,8 @@ public final class DontReuseArgumentSpaceTest extends GraalCompilerTest {
|
||||||
ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
|
ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
|
||||||
StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
|
||||||
CompilationResult compilationResult = compile(javaMethod, graph);
|
CompilationResult compilationResult = compile(javaMethod, graph);
|
||||||
getBackend().createDefaultInstalledCode(javaMethod, compilationResult);
|
DebugContext debug = getDebugContext();
|
||||||
|
getBackend().createDefaultInstalledCode(debug, javaMethod, compilationResult);
|
||||||
|
|
||||||
test("callTwice", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
test("callTwice", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,25 +28,25 @@ import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.Assumptions;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import jdk.vm.ci.meta.Assumptions.Assumption;
|
|
||||||
import jdk.vm.ci.meta.Assumptions.LeafType;
|
|
||||||
import jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass;
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
|
import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import jdk.vm.ci.meta.Assumptions;
|
||||||
|
import jdk.vm.ci.meta.Assumptions.Assumption;
|
||||||
|
import jdk.vm.ci.meta.Assumptions.LeafType;
|
||||||
|
import jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
|
||||||
public class FinalizableSubclassTest extends GraalCompilerTest {
|
public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
Constructor<?>[] constructors = cl.getConstructors();
|
Constructor<?>[] constructors = cl.getConstructors();
|
||||||
Assert.assertTrue(constructors.length == 1);
|
Assert.assertTrue(constructors.length == 1);
|
||||||
final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(constructors[0]);
|
final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(constructors[0]);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions(), allowAssumptions).method(javaMethod).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options), allowAssumptions).method(javaMethod).build();
|
||||||
|
|
||||||
GraphBuilderConfiguration conf = GraphBuilderConfiguration.getSnippetDefault(getDefaultGraphBuilderPlugins());
|
GraphBuilderConfiguration conf = GraphBuilderConfiguration.getSnippetDefault(getDefaultGraphBuilderPlugins());
|
||||||
new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getProviders().getConstantReflection(), getProviders().getConstantFieldProvider(), conf,
|
new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getProviders().getConstantReflection(), getProviders().getConstantFieldProvider(), conf,
|
||||||
|
@ -107,8 +108,9 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test1() throws ClassNotFoundException {
|
public void test1() throws ClassNotFoundException {
|
||||||
|
DebugContext debug = getDebugContext();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
ClassTemplateLoader loader = new ClassTemplateLoader();
|
ClassTemplateLoader loader = new ClassTemplateLoader(debug);
|
||||||
checkForRegisterFinalizeNode(loader.findClass("NoFinalizerEverAAAA"), true, AllowAssumptions.NO);
|
checkForRegisterFinalizeNode(loader.findClass("NoFinalizerEverAAAA"), true, AllowAssumptions.NO);
|
||||||
checkForRegisterFinalizeNode(loader.findClass("NoFinalizerEverAAAA"), false, AllowAssumptions.YES);
|
checkForRegisterFinalizeNode(loader.findClass("NoFinalizerEverAAAA"), false, AllowAssumptions.YES);
|
||||||
|
|
||||||
|
@ -126,8 +128,11 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
private final String replaceTo;
|
private final String replaceTo;
|
||||||
private HashMap<String, Class<?>> cache = new HashMap<>();
|
private HashMap<String, Class<?>> cache = new HashMap<>();
|
||||||
|
|
||||||
ClassTemplateLoader() {
|
private final DebugContext debug;
|
||||||
|
|
||||||
|
ClassTemplateLoader(DebugContext debug) {
|
||||||
loaderInstance++;
|
loaderInstance++;
|
||||||
|
this.debug = debug;
|
||||||
replaceTo = String.format("%04d", loaderInstance);
|
replaceTo = String.format("%04d", loaderInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,14 +160,15 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assert.fail("can't access class: " + name);
|
Assert.fail("can't access class: " + name);
|
||||||
}
|
}
|
||||||
dumpStringsInByteArray(classData);
|
|
||||||
|
dumpStringsInByteArray(debug, classData);
|
||||||
|
|
||||||
// replace all occurrences of "AAAA" in classfile
|
// replace all occurrences of "AAAA" in classfile
|
||||||
int index = -1;
|
int index = -1;
|
||||||
while ((index = indexOfAAAA(classData, index + 1)) != -1) {
|
while ((index = indexOfAAAA(classData, index + 1)) != -1) {
|
||||||
replaceAAAA(classData, index, replaceTo);
|
replaceAAAA(classData, index, replaceTo);
|
||||||
}
|
}
|
||||||
dumpStringsInByteArray(classData);
|
dumpStringsInByteArray(debug, classData);
|
||||||
|
|
||||||
Class<?> c = defineClass(null, classData, 0, classData.length);
|
Class<?> c = defineClass(null, classData, 0, classData.length);
|
||||||
cache.put(nameReplaced, c);
|
cache.put(nameReplaced, c);
|
||||||
|
@ -192,14 +198,14 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dumpStringsInByteArray(byte[] b) {
|
private static void dumpStringsInByteArray(DebugContext debug, byte[] b) {
|
||||||
boolean wasChar = true;
|
boolean wasChar = true;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Byte x : b) {
|
for (Byte x : b) {
|
||||||
// check for [a-zA-Z0-9]
|
// check for [a-zA-Z0-9]
|
||||||
if ((x >= 0x41 && x <= 0x7a) || (x >= 0x30 && x <= 0x39)) {
|
if ((x >= 0x41 && x <= 0x7a) || (x >= 0x30 && x <= 0x39)) {
|
||||||
if (!wasChar) {
|
if (!wasChar) {
|
||||||
Debug.log(sb + "");
|
debug.log(sb + "");
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
}
|
}
|
||||||
sb.append(String.format("%c", x));
|
sb.append(String.format("%c", x));
|
||||||
|
@ -208,7 +214,7 @@ public class FinalizableSubclassTest extends GraalCompilerTest {
|
||||||
wasChar = false;
|
wasChar = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.log(sb + "");
|
debug.log(sb + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,18 +22,16 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.Assumptions.AssumptionResult;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import jdk.vm.ci.meta.Assumptions.AssumptionResult;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test illustrates problems and limitations with class hierarchy analysis when default methods
|
* This test illustrates problems and limitations with class hierarchy analysis when default methods
|
||||||
|
@ -139,13 +137,14 @@ public class FindUniqueDefaultMethodTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected StructuredGraph buildGraph(final String snippet) {
|
protected StructuredGraph buildGraph(final String snippet) {
|
||||||
try (Scope s = Debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
|
DebugContext debug = getDebugContext();
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
try (DebugContext.Scope s = debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
|
||||||
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
|
||||||
compile(graph.method(), graph);
|
compile(graph.method(), graph);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, snippet);
|
debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
|
||||||
return graph;
|
return graph;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
|
@ -39,6 +35,8 @@ import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class FloatingReadTest extends GraphScheduleTest {
|
public class FloatingReadTest extends GraphScheduleTest {
|
||||||
|
|
||||||
|
@ -63,7 +61,8 @@ public class FloatingReadTest extends GraphScheduleTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
try (Scope s = Debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
|
||||||
|
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
PhaseContext context = new PhaseContext(getProviders());
|
PhaseContext context = new PhaseContext(getProviders());
|
||||||
|
@ -82,7 +81,7 @@ public class FloatingReadTest extends GraphScheduleTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After lowering");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After lowering");
|
||||||
|
|
||||||
Assert.assertNotNull(returnNode);
|
Assert.assertNotNull(returnNode);
|
||||||
Assert.assertNotNull(monitorexit);
|
Assert.assertNotNull(monitorexit);
|
||||||
|
@ -92,7 +91,7 @@ public class FloatingReadTest extends GraphScheduleTest {
|
||||||
|
|
||||||
assertOrderedAfterSchedule(graph, read, (Node) monitorexit);
|
assertOrderedAfterSchedule(graph, read, (Node) monitorexit);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public abstract class GraalCompilerAssumptionsTest extends GraalCompilerTest {
|
||||||
checkGraph(expectedAssumption, graph);
|
checkGraph(expectedAssumption, graph);
|
||||||
|
|
||||||
CompilationResult compilationResult = compile(javaMethod, graph);
|
CompilationResult compilationResult = compile(javaMethod, graph);
|
||||||
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(javaMethod, compilationResult);
|
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
|
||||||
assertTrue(installedCode.isValid());
|
assertTrue(installedCode.isValid());
|
||||||
if (classToLoad != null) {
|
if (classToLoad != null) {
|
||||||
String fullName = getClass().getName() + "$" + classToLoad;
|
String fullName = getClass().getName() + "$" + classToLoad;
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -55,10 +56,10 @@ import org.graalvm.compiler.core.GraalCompiler.Request;
|
||||||
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
||||||
import org.graalvm.compiler.core.common.type.StampFactory;
|
import org.graalvm.compiler.core.common.type.StampFactory;
|
||||||
import org.graalvm.compiler.core.target.Backend;
|
import org.graalvm.compiler.core.target.Backend;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
import org.graalvm.compiler.debug.DebugDumpHandler;
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.debug.DebugEnvironment;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.debug.TTY;
|
import org.graalvm.compiler.debug.TTY;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
|
@ -85,6 +86,7 @@ import org.graalvm.compiler.nodes.ProxyNode;
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
|
import org.graalvm.compiler.nodes.StructuredGraph.Builder;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
|
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
|
||||||
import org.graalvm.compiler.nodes.ValueNode;
|
import org.graalvm.compiler.nodes.ValueNode;
|
||||||
import org.graalvm.compiler.nodes.cfg.Block;
|
import org.graalvm.compiler.nodes.cfg.Block;
|
||||||
|
@ -111,13 +113,13 @@ import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.Suites;
|
import org.graalvm.compiler.phases.tiers.Suites;
|
||||||
import org.graalvm.compiler.phases.tiers.TargetProvider;
|
import org.graalvm.compiler.phases.tiers.TargetProvider;
|
||||||
import org.graalvm.compiler.phases.util.Providers;
|
import org.graalvm.compiler.phases.util.Providers;
|
||||||
|
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
import org.graalvm.compiler.test.AddExports;
|
import org.graalvm.compiler.test.AddExports;
|
||||||
import org.graalvm.compiler.test.GraalTest;
|
import org.graalvm.compiler.test.GraalTest;
|
||||||
import org.graalvm.compiler.test.JLModule;
|
import org.graalvm.compiler.test.JLModule;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.internal.AssumptionViolatedException;
|
import org.junit.internal.AssumptionViolatedException;
|
||||||
|
|
||||||
|
@ -364,14 +366,7 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
this.providers = backend.getProviders();
|
this.providers = backend.getProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Scope debugScope;
|
@Override
|
||||||
|
|
||||||
@Before
|
|
||||||
public void beforeTest() {
|
|
||||||
assert debugScope == null;
|
|
||||||
debugScope = Debug.scope(getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterTest() {
|
public void afterTest() {
|
||||||
if (invocationPluginExtensions != null) {
|
if (invocationPluginExtensions != null) {
|
||||||
|
@ -383,10 +378,21 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (debugScope != null) {
|
super.afterTest();
|
||||||
debugScope.close();
|
}
|
||||||
}
|
|
||||||
debugScope = null;
|
/**
|
||||||
|
* Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
|
||||||
|
* none currently exists. Debug contexts created by this method will have their
|
||||||
|
* {@link DebugDumpHandler}s closed in {@link #afterTest()}.
|
||||||
|
*/
|
||||||
|
protected DebugContext getDebugContext() {
|
||||||
|
return getDebugContext(getInitialOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
|
||||||
|
return Collections.singletonList(new GraalDebugHandlersFactory(getSnippetReflection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
|
protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
|
||||||
|
@ -413,13 +419,13 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
String mismatchString = compareGraphStrings(expected, expectedString, graph, actualString);
|
String mismatchString = compareGraphStrings(expected, expectedString, graph, actualString);
|
||||||
|
|
||||||
if (!excludeVirtual && getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
|
if (!excludeVirtual && getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, expected, "Node count not matching - expected");
|
expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "Node count not matching - expected");
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Node count not matching - actual");
|
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Node count not matching - actual");
|
||||||
Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount() + "\n" + mismatchString);
|
Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount() + "\n" + mismatchString);
|
||||||
}
|
}
|
||||||
if (!expectedString.equals(actualString)) {
|
if (!expectedString.equals(actualString)) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, expected, "mismatching graphs - expected");
|
expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "mismatching graphs - expected");
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "mismatching graphs - actual");
|
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "mismatching graphs - actual");
|
||||||
Assert.fail(mismatchString);
|
Assert.fail(mismatchString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -932,24 +938,27 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
|
final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
|
||||||
|
|
||||||
InstalledCode installedCode = null;
|
InstalledCode installedCode = null;
|
||||||
try (AllocSpy spy = AllocSpy.open(installedCodeOwner); Scope ds = Debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
|
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
|
||||||
|
DebugContext debug = graphToCompile.getDebug();
|
||||||
|
try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
|
||||||
final boolean printCompilation = PrintCompilation.getValue(options) && !TTY.isSuppressed();
|
final boolean printCompilation = PrintCompilation.getValue(options) && !TTY.isSuppressed();
|
||||||
if (printCompilation) {
|
if (printCompilation) {
|
||||||
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s ...", id, installedCodeOwner.getDeclaringClass().getName(), installedCodeOwner.getName(),
|
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s ...", id, installedCodeOwner.getDeclaringClass().getName(), installedCodeOwner.getName(),
|
||||||
installedCodeOwner.getSignature()));
|
installedCodeOwner.getSignature()));
|
||||||
}
|
}
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
CompilationResult compResult = compile(installedCodeOwner, graph, new CompilationResult(), id, options);
|
CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
|
||||||
if (printCompilation) {
|
if (printCompilation) {
|
||||||
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize()));
|
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Scope s = Debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult)) {
|
try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
|
||||||
|
DebugContext.Activation a = debug.activate()) {
|
||||||
try {
|
try {
|
||||||
if (installAsDefault) {
|
if (installAsDefault) {
|
||||||
installedCode = addDefaultMethod(installedCodeOwner, compResult);
|
installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
|
||||||
} else {
|
} else {
|
||||||
installedCode = addMethod(installedCodeOwner, compResult);
|
installedCode = addMethod(debug, installedCodeOwner, compResult);
|
||||||
}
|
}
|
||||||
if (installedCode == null) {
|
if (installedCode == null) {
|
||||||
throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
|
throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
|
||||||
|
@ -963,10 +972,10 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!forceCompile) {
|
if (!forceCompile) {
|
||||||
|
@ -988,6 +997,10 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), options);
|
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final StructuredGraph parseForCompile(ResolvedJavaMethod method, DebugContext debug) {
|
||||||
|
return parseEager(method, AllowAssumptions.YES, debug);
|
||||||
|
}
|
||||||
|
|
||||||
protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) {
|
protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) {
|
||||||
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
|
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
|
||||||
}
|
}
|
||||||
|
@ -1032,13 +1045,14 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
|
protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
|
||||||
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
|
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
|
||||||
lastCompiledGraph = graphToCompile;
|
lastCompiledGraph = graphToCompile;
|
||||||
try (Scope s = Debug.scope("Compile", graphToCompile)) {
|
DebugContext debug = graphToCompile.getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
|
||||||
assert options != null;
|
assert options != null;
|
||||||
Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
|
Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
|
||||||
graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
|
graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
|
||||||
return GraalCompiler.compile(request);
|
return GraalCompiler.compile(request);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,12 +1062,12 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compilationResult) {
|
protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
|
||||||
return backend.addInstalledCode(method, null, compilationResult);
|
return backend.addInstalledCode(debug, method, null, compilationResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InstalledCode addDefaultMethod(final ResolvedJavaMethod method, final CompilationResult compilationResult) {
|
protected InstalledCode addDefaultMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
|
||||||
return backend.createDefaultInstalledCode(method, compilationResult);
|
return backend.createDefaultInstalledCode(debug, method, compilationResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<ResolvedJavaMethod, Executable> methodMap = new HashMap<>();
|
private final Map<ResolvedJavaMethod, Executable> methodMap = new HashMap<>();
|
||||||
|
@ -1108,7 +1122,8 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseProfiled(String methodName, AllowAssumptions allowAssumptions) {
|
protected final StructuredGraph parseProfiled(String methodName, AllowAssumptions allowAssumptions) {
|
||||||
return parseProfiled(getResolvedJavaMethod(methodName), allowAssumptions);
|
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
|
||||||
|
return parse(builder(method, allowAssumptions), getDefaultGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1119,7 +1134,7 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseProfiled(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
protected final StructuredGraph parseProfiled(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
||||||
return parse1(method, getDefaultGraphBuilderSuite(), allowAssumptions, getCompilationId(method), getInitialOptions());
|
return parse(builder(method, allowAssumptions), getDefaultGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1130,7 +1145,8 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions) {
|
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions) {
|
||||||
return parseEager(getResolvedJavaMethod(methodName), allowAssumptions, getInitialOptions());
|
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
|
||||||
|
return parse(builder(method, allowAssumptions), getEagerGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1142,7 +1158,13 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param options the option values to be used when compiling the graph
|
* @param options the option values to be used when compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions, OptionValues options) {
|
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions, OptionValues options) {
|
||||||
return parseEager(getResolvedJavaMethod(methodName), allowAssumptions, options);
|
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
|
||||||
|
return parse(builder(method, allowAssumptions, options), getEagerGraphBuilderSuite());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions, DebugContext debug) {
|
||||||
|
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
|
||||||
|
return parse(builder(method, allowAssumptions, debug), getEagerGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1153,7 +1175,11 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
||||||
return parseEager(method, allowAssumptions, getCompilationId(method), getInitialOptions());
|
return parse(builder(method, allowAssumptions), getEagerGraphBuilderSuite());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
|
||||||
|
return parse(builder(method, allowAssumptions, debug), getEagerGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1165,7 +1191,7 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param options the option values to be used when compiling the graph
|
* @param options the option values to be used when compiling the graph
|
||||||
*/
|
*/
|
||||||
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
|
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
|
||||||
return parseEager(method, allowAssumptions, getCompilationId(method), options);
|
return parse(builder(method, allowAssumptions, options), getEagerGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1177,43 +1203,53 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
* @param compilationId the compilation identifier to be associated with the graph
|
* @param compilationId the compilation identifier to be associated with the graph
|
||||||
* @param options the option values to be used when compiling the graph
|
* @param options the option values to be used when compiling the graph
|
||||||
*/
|
*/
|
||||||
protected StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
|
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
|
||||||
return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true)), allowAssumptions, compilationId, options);
|
return parse(builder(method, allowAssumptions, compilationId, options), getEagerGraphBuilderSuite());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
|
||||||
* Parses a Java method using {@linkplain GraphBuilderConfiguration#withFullInfopoints(boolean)
|
OptionValues options = debug.getOptions();
|
||||||
* full debug} set to true to produce a graph.
|
return new Builder(options, debug, allowAssumptions).method(method).compilationId(getCompilationId(method));
|
||||||
*
|
}
|
||||||
* @param method the method to be parsed
|
|
||||||
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
|
protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
||||||
*/
|
OptionValues options = getInitialOptions();
|
||||||
protected StructuredGraph parseDebug(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
|
return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
|
||||||
return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)), allowAssumptions, getCompilationId(method),
|
}
|
||||||
getInitialOptions());
|
|
||||||
|
protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
|
||||||
|
return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(compilationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
|
||||||
|
return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PhaseSuite<HighTierContext> getDebugGraphBuilderSuite() {
|
||||||
|
return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId,
|
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
|
||||||
OptionValues options) {
|
ResolvedJavaMethod javaMethod = builder.getMethod();
|
||||||
|
if (builder.getCancellable() == null) {
|
||||||
|
builder.cancellable(getCancellable(javaMethod));
|
||||||
|
}
|
||||||
assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod;
|
assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod;
|
||||||
// @formatter:off
|
StructuredGraph graph = builder.build();
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(options, allowAssumptions).
|
DebugContext debug = graph.getDebug();
|
||||||
method(javaMethod).
|
try (DebugContext.Scope ds = debug.scope("Parsing", javaMethod, graph)) {
|
||||||
speculationLog(getSpeculationLog()).
|
|
||||||
useProfilingInfo(true).
|
|
||||||
compilationId(compilationId).
|
|
||||||
cancellable(getCancellable(javaMethod)).
|
|
||||||
build();
|
|
||||||
// @formatter:on
|
|
||||||
try (Scope ds = Debug.scope("Parsing", javaMethod, graph)) {
|
|
||||||
graphBuilderSuite.apply(graph, getDefaultHighTierContext());
|
graphBuilderSuite.apply(graph, getDefaultHighTierContext());
|
||||||
return graph;
|
return graph;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PhaseSuite<HighTierContext> getEagerGraphBuilderSuite() {
|
||||||
|
return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cancellable that should be associated with a graph being created by any of the
|
* Gets the cancellable that should be associated with a graph being created by any of the
|
||||||
* {@code parse...()} methods.
|
* {@code parse...()} methods.
|
||||||
|
@ -1385,6 +1421,6 @@ public abstract class GraalCompilerTest extends GraalTest {
|
||||||
public static void initializeForTimeout() {
|
public static void initializeForTimeout() {
|
||||||
// timeout tests run in a separate thread which needs the DebugEnvironment to be
|
// timeout tests run in a separate thread which needs the DebugEnvironment to be
|
||||||
// initialized
|
// initialized
|
||||||
DebugEnvironment.ensureInitialized(getInitialOptions());
|
// DebugEnvironment.ensureInitialized(getInitialOptions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.
|
||||||
|
*
|
||||||
|
* 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 org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.test.AddExports;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@AddExports("jdk.internal.vm.compiler/org.graalvm.compiler.printer")
|
||||||
|
public class GraalDebugHandlersFactoryTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createUniqueTest() throws Exception {
|
||||||
|
Field maxFileNameLengthField = GraalDebugHandlersFactory.class.getDeclaredField("MAX_FILE_NAME_LENGTH");
|
||||||
|
maxFileNameLengthField.setAccessible(true);
|
||||||
|
int maxFileNameLength = maxFileNameLengthField.getInt(null);
|
||||||
|
Method createUniqueMethod = GraalDebugHandlersFactory.class.getDeclaredMethod("createUnique", Path.class, String.class, String.class, String.class, boolean.class);
|
||||||
|
createUniqueMethod.setAccessible(true);
|
||||||
|
Path tmpDir = Files.createTempDirectory(Paths.get("."), "createUniqueTest");
|
||||||
|
try {
|
||||||
|
for (boolean createDirectory : new boolean[]{true, false}) {
|
||||||
|
for (String ext : new String[]{"", ".bgv", ".graph-strings"}) {
|
||||||
|
for (int i = 0; i < maxFileNameLength + 5; i++) {
|
||||||
|
String id = new String(new char[i]).replace('\0', 'i');
|
||||||
|
String label = "";
|
||||||
|
createUniqueMethod.invoke(null, tmpDir, id, label, ext, createDirectory);
|
||||||
|
|
||||||
|
id = "";
|
||||||
|
label = new String(new char[i]).replace('\0', 'l');
|
||||||
|
createUniqueMethod.invoke(null, tmpDir, id, label, ext, createDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
deleteTree(tmpDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteTree(Path root) throws IOException {
|
||||||
|
Files.walk(root).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||||
|
}
|
||||||
|
}
|
|
@ -112,7 +112,7 @@ public class GuardedIntrinsicTest extends GraalCompilerTest {
|
||||||
@Override
|
@Override
|
||||||
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
|
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
|
||||||
graph = super.parseForCompile(method, compilationId, options);
|
graph = super.parseForCompile(method, compilationId, options);
|
||||||
parsedForCompile = (StructuredGraph) graph.copy();
|
parsedForCompile = (StructuredGraph) graph.copy(graph.getDebug());
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.ConstantNode;
|
import org.graalvm.compiler.nodes.ConstantNode;
|
||||||
import org.graalvm.compiler.nodes.FrameState;
|
import org.graalvm.compiler.nodes.FrameState;
|
||||||
|
@ -40,6 +38,7 @@ import org.graalvm.compiler.phases.common.GuardLoweringPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the following tests, the usages of local variable "a" are replaced with the integer constant
|
* In the following tests, the usages of local variable "a" are replaced with the integer constant
|
||||||
|
@ -237,6 +236,7 @@ public class IfCanonicalizerTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private void test(String snippet) {
|
private void test(String snippet) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
|
ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
|
||||||
ConstantNode constant = ConstantNode.forInt(0, graph);
|
ConstantNode constant = ConstantNode.forInt(0, graph);
|
||||||
for (Node n : param.usages().snapshot()) {
|
for (Node n : param.usages().snapshot()) {
|
||||||
|
@ -244,7 +244,7 @@ public class IfCanonicalizerTest extends GraalCompilerTest {
|
||||||
n.replaceFirstInput(param, constant);
|
n.replaceFirstInput(param, constant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
|
for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
|
||||||
fs.replaceFirstInput(param, null);
|
fs.replaceFirstInput(param, null);
|
||||||
|
|
|
@ -22,13 +22,8 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.directives.GraalDirectives;
|
import org.graalvm.compiler.api.directives.GraalDirectives;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.nodes.DeoptimizeNode;
|
import org.graalvm.compiler.nodes.DeoptimizeNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
|
@ -42,6 +37,9 @@ import org.graalvm.compiler.phases.common.GuardLoweringPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the hub access and the null check are folded.
|
* Tests that the hub access and the null check are folded.
|
||||||
|
@ -68,8 +66,9 @@ public class ImplicitNullCheckTest extends GraphScheduleTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
try (Scope s = Debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
|
||||||
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
|
||||||
PhaseContext context = new PhaseContext(getProviders());
|
PhaseContext context = new PhaseContext(getProviders());
|
||||||
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
|
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
|
||||||
new FloatingReadPhase().apply(graph);
|
new FloatingReadPhase().apply(graph);
|
||||||
|
@ -80,7 +79,7 @@ public class ImplicitNullCheckTest extends GraphScheduleTest {
|
||||||
Assert.assertTrue(graph.getNodes().filter(ReadNode.class).first().canNullCheck());
|
Assert.assertTrue(graph.getNodes().filter(ReadNode.class).first().canNullCheck());
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class InfopointReasonTest extends GraalCompilerTest {
|
||||||
@Test
|
@Test
|
||||||
public void lineInfopoints() {
|
public void lineInfopoints() {
|
||||||
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
|
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
|
||||||
final StructuredGraph graph = parseDebug(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions())));
|
final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
|
||||||
int graphLineSPs = 0;
|
int graphLineSPs = 0;
|
||||||
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
|
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
|
||||||
if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
|
if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
|
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.test.ExportingClassLoader;
|
import org.graalvm.compiler.test.ExportingClassLoader;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
@ -104,12 +105,12 @@ public final class InterfaceMethodHandleTest extends GraalCompilerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
|
protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
|
||||||
if (method.getDeclaringClass().equals(getMetaAccess().lookupJavaType(M2Thrower.class))) {
|
if (method.getDeclaringClass().equals(getMetaAccess().lookupJavaType(M2Thrower.class))) {
|
||||||
// Make sure M2Thrower.m2 is invoked from normal code
|
// Make sure M2Thrower.m2 is invoked from normal code
|
||||||
return getBackend().createDefaultInstalledCode(method, compResult);
|
return getBackend().createDefaultInstalledCode(debug, method, compResult);
|
||||||
}
|
}
|
||||||
return super.addMethod(method, compResult);
|
return super.addMethod(debug, method, compResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,13 +26,15 @@ import jdk.vm.ci.meta.JavaConstant;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.nodes.ConstantNode;
|
import org.graalvm.compiler.nodes.ConstantNode;
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.ValueNode;
|
import org.graalvm.compiler.nodes.ValueNode;
|
||||||
import org.graalvm.compiler.nodes.calc.AddNode;
|
import org.graalvm.compiler.nodes.calc.AddNode;
|
||||||
import org.graalvm.compiler.nodes.debug.OpaqueNode;
|
import org.graalvm.compiler.nodes.debug.OpaqueNode;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
||||||
|
@ -52,7 +54,8 @@ public class LongNodeChainTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private void longAddChain(boolean reverse) {
|
private void longAddChain(boolean reverse) {
|
||||||
HighTierContext context = getDefaultHighTierContext();
|
HighTierContext context = getDefaultHighTierContext();
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
|
||||||
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
|
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
|
||||||
ValueNode value = null;
|
ValueNode value = null;
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
||||||
import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
|
import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
|
||||||
|
@ -83,15 +82,16 @@ public class LoopFullUnrollTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(String snippet, int loopCount) {
|
private void test(String snippet, int loopCount) {
|
||||||
try (Scope s = Debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
try (DebugContext.Scope s = debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
|
||||||
|
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
|
||||||
|
|
||||||
PhaseContext context = new PhaseContext(getProviders());
|
PhaseContext context = new PhaseContext(getProviders());
|
||||||
new LoopFullUnrollPhase(new CanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context);
|
new LoopFullUnrollPhase(new CanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context);
|
||||||
|
|
||||||
assertTrue(graph.getNodes().filter(LoopBeginNode.class).count() == loopCount);
|
assertTrue(graph.getNodes().filter(LoopBeginNode.class).count() == loopCount);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
||||||
import org.graalvm.compiler.loop.phases.LoopUnswitchingPhase;
|
import org.graalvm.compiler.loop.phases.LoopUnswitchingPhase;
|
||||||
|
@ -33,6 +30,7 @@ import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class LoopUnswitchTest extends GraalCompilerTest {
|
public class LoopUnswitchTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -124,6 +122,7 @@ public class LoopUnswitchTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(String snippet, String referenceSnippet) {
|
private void test(String snippet, String referenceSnippet) {
|
||||||
|
DebugContext debug = getDebugContext();
|
||||||
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
||||||
final StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
|
final StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
|
||||||
|
|
||||||
|
@ -135,10 +134,10 @@ public class LoopUnswitchTest extends GraalCompilerTest {
|
||||||
|
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
|
||||||
try (Scope s = Debug.scope("Test", new DebugDumpScope("Test:" + snippet))) {
|
try (DebugContext.Scope s = debug.scope("Test", new DebugDumpScope("Test:" + snippet))) {
|
||||||
assertEquals(referenceGraph, graph);
|
assertEquals(referenceGraph, graph);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.
|
||||||
|
*
|
||||||
|
* 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 org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
|
import org.graalvm.compiler.nodes.memory.WriteNode;
|
||||||
|
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
||||||
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
|
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
||||||
|
import org.graalvm.compiler.phases.common.IncrementalCanonicalizerPhase;
|
||||||
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class MemoryGraphCanonicalizeTest extends GraalCompilerTest {
|
||||||
|
static class TestObject {
|
||||||
|
Object object;
|
||||||
|
Integer integer;
|
||||||
|
int value;
|
||||||
|
volatile boolean written;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void simpleElimination(TestObject object) {
|
||||||
|
object.object = object;
|
||||||
|
object.value = object.integer;
|
||||||
|
object.value = object.integer + 2;
|
||||||
|
object.value = object.integer + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSimpleElimination() {
|
||||||
|
testGraph("simpleElimination", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void complexElimination(TestObject object) {
|
||||||
|
object.object = object;
|
||||||
|
object.value = object.integer;
|
||||||
|
object.value = object.integer + 2;
|
||||||
|
if (object.object == null) {
|
||||||
|
object.value = object.integer + 3;
|
||||||
|
} else {
|
||||||
|
object.object = new Object();
|
||||||
|
}
|
||||||
|
object.written = true;
|
||||||
|
object.value = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testComplexElimination() {
|
||||||
|
testGraph("complexElimination", 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGraph(String name, int expectedWrites) {
|
||||||
|
StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
|
||||||
|
HighTierContext context = getDefaultHighTierContext();
|
||||||
|
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
||||||
|
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
|
||||||
|
new IncrementalCanonicalizerPhase<>(canonicalizer, new FloatingReadPhase()).apply(graph, context);
|
||||||
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
|
int writes = graph.getNodes().filter(WriteNode.class).count();
|
||||||
|
assertTrue(writes == expectedWrites, "Expected %d writes, found %d", expectedWrites, writes);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,12 +31,8 @@ import static org.junit.Assert.assertThat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.directives.GraalDirectives;
|
import org.graalvm.compiler.api.directives.GraalDirectives;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.iterators.NodeIterable;
|
import org.graalvm.compiler.graph.iterators.NodeIterable;
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
|
@ -60,6 +56,8 @@ import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In these test the FrameStates are explicitly cleared out, so that the scheduling of
|
* In these test the FrameStates are explicitly cleared out, so that the scheduling of
|
||||||
|
@ -706,7 +704,8 @@ public class MemoryScheduleTest extends GraphScheduleTest {
|
||||||
private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
|
private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
|
||||||
OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
|
OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
|
||||||
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
|
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
|
||||||
try (Scope d = Debug.scope("FloatingReadTest", graph)) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope d = debug.scope("FloatingReadTest", graph)) {
|
||||||
HighTierContext context = getDefaultHighTierContext();
|
HighTierContext context = getDefaultHighTierContext();
|
||||||
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
||||||
canonicalizer.apply(graph, context);
|
canonicalizer.apply(graph, context);
|
||||||
|
@ -717,7 +716,7 @@ public class MemoryScheduleTest extends GraphScheduleTest {
|
||||||
if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
|
if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
|
||||||
graph.clearAllStateAfter();
|
graph.clearAllStateAfter();
|
||||||
}
|
}
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "after removal of framestates");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "after removal of framestates");
|
||||||
|
|
||||||
new FloatingReadPhase().apply(graph);
|
new FloatingReadPhase().apply(graph);
|
||||||
new RemoveValueProxyPhase().apply(graph);
|
new RemoveValueProxyPhase().apply(graph);
|
||||||
|
@ -732,7 +731,7 @@ public class MemoryScheduleTest extends GraphScheduleTest {
|
||||||
assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
|
assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
|
||||||
return graph.getLastSchedule();
|
return graph.getLastSchedule();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,13 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MergeCanonicalizerTest extends GraalCompilerTest {
|
public class MergeCanonicalizerTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public class MergeCanonicalizerTest extends GraalCompilerTest {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
assertDeepEquals(returnCount, graph.getNodes(ReturnNode.TYPE).count());
|
assertDeepEquals(returnCount, graph.getNodes(ReturnNode.TYPE).count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,8 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.Loop;
|
import org.graalvm.compiler.core.common.cfg.Loop;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.Invoke;
|
import org.graalvm.compiler.nodes.Invoke;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
|
@ -34,6 +31,8 @@ import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.cfg.Block;
|
import org.graalvm.compiler.nodes.cfg.Block;
|
||||||
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
||||||
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class NestedLoopTest extends GraalCompilerTest {
|
public class NestedLoopTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -142,7 +141,8 @@ public class NestedLoopTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
|
private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
|
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
|
||||||
|
|
||||||
Assert.assertEquals(3, cfg.getLoops().size());
|
Assert.assertEquals(3, cfg.getLoops().size());
|
||||||
|
@ -162,7 +162,7 @@ public class NestedLoopTest extends GraalCompilerTest {
|
||||||
Assert.assertEquals(rootExits, rootLoop.getExits().size());
|
Assert.assertEquals(rootExits, rootLoop.getExits().size());
|
||||||
Assert.assertEquals(nestedExits, nestedLoop.getExits().size());
|
Assert.assertEquals(nestedExits, nestedLoop.getExits().size());
|
||||||
Assert.assertEquals(innerExits, innerMostLoop.getExits().size());
|
Assert.assertEquals(innerExits, innerMostLoop.getExits().size());
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean contains(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
|
private static boolean contains(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.graalvm.compiler.api.directives.GraalDirectives;
|
import org.graalvm.compiler.api.directives.GraalDirectives;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.iterators.NodeIterable;
|
import org.graalvm.compiler.graph.iterators.NodeIterable;
|
||||||
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
import org.graalvm.compiler.graph.spi.Canonicalizable;
|
||||||
|
@ -196,7 +195,7 @@ public class NodePropertiesTest extends GraalCompilerTest {
|
||||||
GraphCostPhase gc2 = new GraphCostPhase();
|
GraphCostPhase gc2 = new GraphCostPhase();
|
||||||
gc1.apply(g1, htc);
|
gc1.apply(g1, htc);
|
||||||
gc2.apply(g2, htc);
|
gc2.apply(g2, htc);
|
||||||
Debug.log("Test testDifferentLoopFaster --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
g1.getDebug().log("Test testDifferentLoopFaster --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
||||||
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
||||||
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
||||||
}
|
}
|
||||||
|
@ -214,7 +213,7 @@ public class NodePropertiesTest extends GraalCompilerTest {
|
||||||
GraphCostPhase gc2 = new GraphCostPhase();
|
GraphCostPhase gc2 = new GraphCostPhase();
|
||||||
gc1.apply(g1, htc);
|
gc1.apply(g1, htc);
|
||||||
gc2.apply(g2, htc);
|
gc2.apply(g2, htc);
|
||||||
Debug.log("Test testSameLoopMoreIterationsCostlier --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
g1.getDebug().log("Test testSameLoopMoreIterationsCostlier --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
||||||
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
||||||
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +230,7 @@ public class NodePropertiesTest extends GraalCompilerTest {
|
||||||
GraphCostPhase gc2 = new GraphCostPhase();
|
GraphCostPhase gc2 = new GraphCostPhase();
|
||||||
gc1.apply(g1, htc);
|
gc1.apply(g1, htc);
|
||||||
gc2.apply(g2, htc);
|
gc2.apply(g2, htc);
|
||||||
Debug.log("Test testDifferentLoopsInnerOuter --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
g1.getDebug().log("Test testDifferentLoopsInnerOuter --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
|
||||||
Assert.assertTrue(gc2.finalSize > gc1.finalSize);
|
Assert.assertTrue(gc2.finalSize > gc1.finalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +245,7 @@ public class NodePropertiesTest extends GraalCompilerTest {
|
||||||
GraphCostPhase gc2 = new GraphCostPhase();
|
GraphCostPhase gc2 = new GraphCostPhase();
|
||||||
gc1.apply(g1, htc);
|
gc1.apply(g1, htc);
|
||||||
gc2.apply(g2, htc);
|
gc2.apply(g2, htc);
|
||||||
Debug.log("Test Graph Cost --> 1.Graph cost:%f vs. 2.Graph cost:%f\n", gc1.finalCycles, gc2.finalCycles);
|
g1.getDebug().log("Test Graph Cost --> 1.Graph cost:%f vs. 2.Graph cost:%f\n", gc1.finalCycles, gc2.finalCycles);
|
||||||
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
|
||||||
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
Assert.assertTrue(gc2.finalSize == gc1.finalSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.ValuePhiNode;
|
import org.graalvm.compiler.nodes.ValuePhiNode;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the following tests, the correct removal of redundant phis during graph building is tested.
|
* In the following tests, the correct removal of redundant phis during graph building is tested.
|
||||||
|
@ -70,7 +69,8 @@ public class PhiCreationTests extends GraalCompilerTest {
|
||||||
@Test
|
@Test
|
||||||
public void test3() {
|
public void test3() {
|
||||||
StructuredGraph graph = parseEager("test3Snippet", AllowAssumptions.YES);
|
StructuredGraph graph = parseEager("test3Snippet", AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext());
|
Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,8 @@ public class PhiCreationTests extends GraalCompilerTest {
|
||||||
@Test
|
@Test
|
||||||
public void test4() {
|
public void test4() {
|
||||||
StructuredGraph graph = parseEager("test4Snippet", AllowAssumptions.YES);
|
StructuredGraph graph = parseEager("test4Snippet", AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext());
|
Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaField;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.nodes.ParameterNode;
|
import org.graalvm.compiler.nodes.ParameterNode;
|
||||||
import org.graalvm.compiler.nodes.PiNode;
|
import org.graalvm.compiler.nodes.PiNode;
|
||||||
|
@ -44,6 +36,12 @@ import org.graalvm.compiler.nodes.type.StampTool;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaField;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaType;
|
||||||
|
|
||||||
public class PushNodesThroughPiTest extends GraalCompilerTest {
|
public class PushNodesThroughPiTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -77,7 +75,8 @@ public class PushNodesThroughPiTest extends GraalCompilerTest {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public void test1() {
|
public void test1() {
|
||||||
final String snippet = "test1Snippet";
|
final String snippet = "test1Snippet";
|
||||||
try (Scope s = Debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
|
||||||
StructuredGraph graph = compileTestSnippet(snippet);
|
StructuredGraph graph = compileTestSnippet(snippet);
|
||||||
for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
|
for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
|
||||||
OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
|
OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
|
||||||
|
@ -96,7 +95,7 @@ public class PushNodesThroughPiTest extends GraalCompilerTest {
|
||||||
|
|
||||||
Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
|
Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,14 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.FrameState;
|
import org.graalvm.compiler.nodes.FrameState;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.util.GraphUtil;
|
import org.graalvm.compiler.nodes.util.GraphUtil;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PushThroughIfTest extends GraalCompilerTest {
|
public class PushThroughIfTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -59,7 +58,8 @@ public class PushThroughIfTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private void test(String snippet, String reference) {
|
private void test(String snippet, String reference) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
|
for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
|
||||||
fs.replaceAtUsages(null);
|
fs.replaceAtUsages(null);
|
||||||
GraphUtil.killWithUnusedFloatingInputs(fs);
|
GraphUtil.killWithUnusedFloatingInputs(fs);
|
||||||
|
|
|
@ -22,11 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.nodes.ParameterNode;
|
import org.graalvm.compiler.nodes.ParameterNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
|
@ -37,6 +33,8 @@ import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
||||||
import org.graalvm.compiler.phases.common.LoweringPhase;
|
import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/* consider
|
/* consider
|
||||||
* B b = (B) a;
|
* B b = (B) a;
|
||||||
|
@ -84,7 +82,8 @@ public class ReadAfterCheckCastTest extends GraphScheduleTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
try (Scope s = Debug.scope("ReadAfterCheckCastTest", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("ReadAfterCheckCastTest", new DebugDumpScope(snippet))) {
|
||||||
// check shape of graph, with lots of assumptions. will probably fail if graph
|
// check shape of graph, with lots of assumptions. will probably fail if graph
|
||||||
// structure changes significantly
|
// structure changes significantly
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
|
@ -94,7 +93,7 @@ public class ReadAfterCheckCastTest extends GraphScheduleTest {
|
||||||
new FloatingReadPhase().apply(graph);
|
new FloatingReadPhase().apply(graph);
|
||||||
canonicalizer.apply(graph, context);
|
canonicalizer.apply(graph, context);
|
||||||
|
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After lowering");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After lowering");
|
||||||
|
|
||||||
for (FloatingReadNode node : graph.getNodes(ParameterNode.TYPE).first().usages().filter(FloatingReadNode.class)) {
|
for (FloatingReadNode node : graph.getNodes(ParameterNode.TYPE).first().usages().filter(FloatingReadNode.class)) {
|
||||||
// Checking that the parameter a is not directly used for the access to field
|
// Checking that the parameter a is not directly used for the access to field
|
||||||
|
@ -102,7 +101,7 @@ public class ReadAfterCheckCastTest extends GraphScheduleTest {
|
||||||
Assert.assertTrue(node.getLocationIdentity().isImmutable());
|
Assert.assertTrue(node.getLocationIdentity().isImmutable());
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the following tests, the scalar type system of the compiler should be complete enough to see
|
* In the following tests, the scalar type system of the compiler should be complete enough to see
|
||||||
|
@ -131,7 +130,7 @@ public class ScalarTypeSystemTest extends GraalCompilerTest {
|
||||||
private void test(final String snippet, final String referenceSnippet) {
|
private void test(final String snippet, final String referenceSnippet) {
|
||||||
// No debug scope to reduce console noise for @Test(expected = ...) tests
|
// No debug scope to reduce console noise for @Test(expected = ...) tests
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
PhaseContext context = new PhaseContext(getProviders());
|
PhaseContext context = new PhaseContext(getProviders());
|
||||||
new CanonicalizerPhase().apply(graph, context);
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
|
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
|
||||||
|
|
|
@ -24,10 +24,8 @@ package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.BlockMap;
|
import org.graalvm.compiler.core.common.cfg.BlockMap;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.NodeMap;
|
import org.graalvm.compiler.graph.NodeMap;
|
||||||
import org.graalvm.compiler.nodes.BeginNode;
|
import org.graalvm.compiler.nodes.BeginNode;
|
||||||
|
@ -51,6 +49,7 @@ import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
||||||
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SchedulingTest2 extends GraphScheduleTest {
|
public class SchedulingTest2 extends GraphScheduleTest {
|
||||||
|
|
||||||
|
@ -65,11 +64,12 @@ public class SchedulingTest2 extends GraphScheduleTest {
|
||||||
@Test
|
@Test
|
||||||
public void testValueProxyInputs() {
|
public void testValueProxyInputs() {
|
||||||
StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
|
StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
|
ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
|
||||||
BeginNode beginNode = graph.add(new BeginNode());
|
BeginNode beginNode = graph.add(new BeginNode());
|
||||||
returnNode.replaceAtPredecessor(beginNode);
|
returnNode.replaceAtPredecessor(beginNode);
|
||||||
beginNode.setNext(returnNode);
|
beginNode.setNext(returnNode);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST);
|
SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST);
|
||||||
schedulePhase.apply(graph);
|
schedulePhase.apply(graph);
|
||||||
ScheduleResult schedule = graph.getLastSchedule();
|
ScheduleResult schedule = graph.getLastSchedule();
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.AbstractBeginNode;
|
import org.graalvm.compiler.nodes.AbstractBeginNode;
|
||||||
import org.graalvm.compiler.nodes.AbstractMergeNode;
|
import org.graalvm.compiler.nodes.AbstractMergeNode;
|
||||||
import org.graalvm.compiler.nodes.BeginNode;
|
import org.graalvm.compiler.nodes.BeginNode;
|
||||||
|
@ -37,16 +34,23 @@ import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.cfg.Block;
|
import org.graalvm.compiler.nodes.cfg.Block;
|
||||||
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
|
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SimpleCFGTest extends GraalCompilerTest {
|
public class SimpleCFGTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private static void dumpGraph(final StructuredGraph graph) {
|
private static void dumpGraph(final StructuredGraph graph) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplies() {
|
public void testImplies() {
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.YES).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(getSnippetReflection()));
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
|
||||||
|
|
||||||
EndNode trueEnd = graph.add(new EndNode());
|
EndNode trueEnd = graph.add(new EndNode());
|
||||||
EndNode falseEnd = graph.add(new EndNode());
|
EndNode falseEnd = graph.add(new EndNode());
|
||||||
|
|
|
@ -23,19 +23,19 @@
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
|
import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
|
||||||
import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
import org.graalvm.compiler.debug.DelegatingDebugConfig;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
import org.graalvm.compiler.phases.VerifyPhase;
|
import org.graalvm.compiler.phases.VerifyPhase;
|
||||||
|
@ -90,11 +90,13 @@ public class StaticInterfaceFieldTest extends GraalTest {
|
||||||
|
|
||||||
final Method m = getMethod(clazz, methodName);
|
final Method m = getMethod(clazz, methodName);
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
OptionValues options = getInitialOptions();
|
||||||
try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("GraphBuilding", graph, method)) {
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
|
try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("GraphBuilding", graph, method)) {
|
||||||
graphBuilderSuite.apply(graph, context);
|
graphBuilderSuite.apply(graph, context);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test;
|
package org.graalvm.compiler.core.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class StraighteningTest extends GraalCompilerTest {
|
public class StraighteningTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -88,7 +87,8 @@ public class StraighteningTest extends GraalCompilerTest {
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
// No debug scope to reduce console noise for @Test(expected = ...) tests
|
// No debug scope to reduce console noise for @Test(expected = ...) tests
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
|
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
|
||||||
assertEquals(referenceGraph, graph);
|
assertEquals(referenceGraph, graph);
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.TTY;
|
import org.graalvm.compiler.debug.TTY;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodeinfo.Verbosity;
|
import org.graalvm.compiler.nodeinfo.Verbosity;
|
||||||
|
@ -179,7 +179,8 @@ public class TypeSystemTest extends GraalCompilerTest {
|
||||||
|
|
||||||
private void test(String snippet, String referenceSnippet) {
|
private void test(String snippet, String referenceSnippet) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
/*
|
/*
|
||||||
* When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase,
|
* When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase,
|
||||||
* tail-duplication gets activated thus resulting in a graph with more nodes than the
|
* tail-duplication gets activated thus resulting in a graph with more nodes than the
|
||||||
|
@ -198,9 +199,10 @@ public class TypeSystemTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
|
protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
if (getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
|
if (getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, expected, "expected (node count)");
|
debug.dump(DebugContext.BASIC_LEVEL, expected, "expected (node count)");
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "graph (node count)");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "graph (node count)");
|
||||||
Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount());
|
Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,7 +245,8 @@ public class TypeSystemTest extends GraalCompilerTest {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph " + snippet);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph " + snippet);
|
||||||
Assert.assertFalse("shouldn't have nodes of type " + clazz, graph.getNodes().filter(clazz).iterator().hasNext());
|
Assert.assertFalse("shouldn't have nodes of type " + clazz, graph.getNodes().filter(clazz).iterator().hasNext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
@ -85,7 +86,8 @@ public class UnbalancedMonitorsTest extends GraalCompilerTest {
|
||||||
private void checkForBailout(String name) throws ClassNotFoundException {
|
private void checkForBailout(String name) throws ClassNotFoundException {
|
||||||
ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
|
ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
|
||||||
try {
|
try {
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options)).method(method).build();
|
||||||
Plugins plugins = new Plugins(new InvocationPlugins());
|
Plugins plugins = new Plugins(new InvocationPlugins());
|
||||||
GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
||||||
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
|
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
|
||||||
|
|
|
@ -27,19 +27,19 @@ import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
import org.graalvm.compiler.core.common.PermanentBailoutException;
|
import org.graalvm.compiler.core.common.PermanentBailoutException;
|
||||||
import org.graalvm.compiler.core.common.RetryableBailoutException;
|
import org.graalvm.compiler.core.common.RetryableBailoutException;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.Phase;
|
import org.graalvm.compiler.phases.Phase;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
|
@ -48,6 +48,7 @@ import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.util.Providers;
|
import org.graalvm.compiler.phases.util.Providers;
|
||||||
import org.graalvm.compiler.phases.verify.VerifyBailoutUsage;
|
import org.graalvm.compiler.phases.verify.VerifyBailoutUsage;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import jdk.vm.ci.code.BailoutException;
|
import jdk.vm.ci.code.BailoutException;
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
|
@ -125,12 +126,14 @@ public class VerifyBailoutUsageTest {
|
||||||
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
||||||
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
||||||
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
||||||
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
for (Method m : c.getDeclaredMethods()) {
|
for (Method m : c.getDeclaredMethods()) {
|
||||||
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
graphBuilderSuite.apply(graph, context);
|
graphBuilderSuite.apply(graph, context);
|
||||||
try (DebugConfigScope s = Debug.disableIntercept()) {
|
try (DebugCloseable s = debug.disableIntercept()) {
|
||||||
new VerifyBailoutUsage().apply(graph, context);
|
new VerifyBailoutUsage().apply(graph, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,10 @@ import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.debug.Indent;
|
import org.graalvm.compiler.debug.Indent;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
|
@ -40,6 +39,7 @@ import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.Phase;
|
import org.graalvm.compiler.phases.Phase;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
|
@ -48,6 +48,7 @@ import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.util.Providers;
|
import org.graalvm.compiler.phases.util.Providers;
|
||||||
import org.graalvm.compiler.phases.verify.VerifyDebugUsage;
|
import org.graalvm.compiler.phases.verify.VerifyDebugUsage;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
@ -58,8 +59,9 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("%s", n.toString());
|
debug.log("%s", n.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +72,10 @@ public class VerifyDebugUsageTest {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
try (Indent i = Debug.logAndIndent("%s", graph.toString())) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (Indent i = debug.logAndIndent("%s", graph.toString())) {
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("%s", n);
|
debug.log("%s", n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "%s", graph.toString());
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "%s", graph.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +95,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.dump(Debug.VERY_DETAILED_LEVEL + 1, graph, "%s", graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.VERY_DETAILED_LEVEL + 1, graph, "%s", graph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +104,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.dump(getLevel(), graph, "%s", graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(getLevel(), graph, "%s", graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLevel() {
|
int getLevel() {
|
||||||
|
@ -111,7 +117,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.verify(graph, "%s", graph.toString());
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.verify(graph, "%s", graph.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,8 +127,9 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("error " + n);
|
debug.log("error " + n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +140,10 @@ public class VerifyDebugUsageTest {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
try (Indent i = Debug.logAndIndent("error " + graph)) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (Indent i = debug.logAndIndent("error " + graph)) {
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("%s", n);
|
debug.log("%s", n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +154,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "error " + graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "error " + graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -154,7 +164,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.verify(graph, "error " + graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.verify(graph, "error " + graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -163,8 +174,9 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("%s", n);
|
debug.log("%s", n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +187,10 @@ public class VerifyDebugUsageTest {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
try (Indent i = Debug.logAndIndent("%s", graph)) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (Indent i = debug.logAndIndent("%s", graph)) {
|
||||||
for (Node n : graph.getNodes()) {
|
for (Node n : graph.getNodes()) {
|
||||||
Debug.log("%s", n);
|
debug.log("%s", n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +201,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "%s", graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "%s", graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -197,7 +211,8 @@ public class VerifyDebugUsageTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(StructuredGraph graph) {
|
protected void run(StructuredGraph graph) {
|
||||||
Debug.verify(graph, "%s", graph);
|
DebugContext debug = graph.getDebug();
|
||||||
|
debug.verify(graph, "%s", graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -332,12 +347,14 @@ public class VerifyDebugUsageTest {
|
||||||
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
||||||
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
||||||
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
||||||
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
for (Method m : c.getDeclaredMethods()) {
|
for (Method m : c.getDeclaredMethods()) {
|
||||||
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
graphBuilderSuite.apply(graph, context);
|
graphBuilderSuite.apply(graph, context);
|
||||||
try (DebugConfigScope s = Debug.disableIntercept()) {
|
try (DebugCloseable s = debug.disableIntercept()) {
|
||||||
new VerifyDebugUsage().apply(graph, context);
|
new VerifyDebugUsage().apply(graph, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,11 @@ import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
import org.graalvm.compiler.core.common.type.StampFactory;
|
import org.graalvm.compiler.core.common.type.StampFactory;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.NodeClass;
|
import org.graalvm.compiler.graph.NodeClass;
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
||||||
|
@ -47,6 +46,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
||||||
import org.graalvm.compiler.nodes.java.ArrayLengthNode;
|
import org.graalvm.compiler.nodes.java.ArrayLengthNode;
|
||||||
import org.graalvm.compiler.nodes.spi.Virtualizable;
|
import org.graalvm.compiler.nodes.spi.Virtualizable;
|
||||||
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
|
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
import org.graalvm.compiler.phases.VerifyPhase.VerificationError;
|
import org.graalvm.compiler.phases.VerifyPhase.VerificationError;
|
||||||
|
@ -54,6 +54,7 @@ import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.util.Providers;
|
import org.graalvm.compiler.phases.util.Providers;
|
||||||
import org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage;
|
import org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
@ -270,12 +271,14 @@ public class VerifyVirtualizableTest {
|
||||||
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
||||||
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
||||||
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
||||||
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
for (Method m : c.getDeclaredMethods()) {
|
for (Method m : c.getDeclaredMethods()) {
|
||||||
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
graphBuilderSuite.apply(graph, context);
|
graphBuilderSuite.apply(graph, context);
|
||||||
try (DebugConfigScope s = Debug.disableIntercept()) {
|
try (DebugCloseable s = debug.disableIntercept()) {
|
||||||
new VerifyVirtualizableUsage().apply(graph, context);
|
new VerifyVirtualizableUsage().apply(graph, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,8 @@ package org.graalvm.compiler.core.test.backend;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import jdk.vm.ci.code.Register;
|
|
||||||
import jdk.vm.ci.code.ValueUtil;
|
|
||||||
import jdk.vm.ci.meta.Value;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.lir.LIR;
|
import org.graalvm.compiler.lir.LIR;
|
||||||
import org.graalvm.compiler.lir.LIRInstruction;
|
import org.graalvm.compiler.lir.LIRInstruction;
|
||||||
import org.graalvm.compiler.lir.LIRValueUtil;
|
import org.graalvm.compiler.lir.LIRValueUtil;
|
||||||
|
@ -40,23 +33,29 @@ import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
|
||||||
import org.graalvm.compiler.lir.ValueProcedure;
|
import org.graalvm.compiler.lir.ValueProcedure;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import jdk.vm.ci.code.Register;
|
||||||
|
import jdk.vm.ci.code.ValueUtil;
|
||||||
|
import jdk.vm.ci.meta.Value;
|
||||||
|
|
||||||
public class AllocatorTest extends BackendTest {
|
public class AllocatorTest extends BackendTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
|
protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
|
||||||
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
|
||||||
try (Scope s = Debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {
|
||||||
final RegisterStats stats = new RegisterStats(getLIRGenerationResult(graph).getLIR());
|
final RegisterStats stats = new RegisterStats(getLIRGenerationResult(graph).getLIR());
|
||||||
try (Scope s2 = Debug.scope("Assertions", stats.lir)) {
|
try (DebugContext.Scope s2 = debug.scope("Assertions", stats.lir)) {
|
||||||
Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
|
Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
|
||||||
Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
|
Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
|
||||||
Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
|
Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,16 +22,15 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test.backend;
|
package org.graalvm.compiler.core.test.backend;
|
||||||
|
|
||||||
import jdk.vm.ci.code.Architecture;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.GraalCompiler;
|
import org.graalvm.compiler.core.GraalCompiler;
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
|
|
||||||
|
import jdk.vm.ci.code.Architecture;
|
||||||
|
|
||||||
public abstract class BackendTest extends GraalCompilerTest {
|
public abstract class BackendTest extends GraalCompilerTest {
|
||||||
|
|
||||||
public BackendTest() {
|
public BackendTest() {
|
||||||
|
@ -44,10 +43,11 @@ public abstract class BackendTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected LIRGenerationResult getLIRGenerationResult(final StructuredGraph graph) {
|
protected LIRGenerationResult getLIRGenerationResult(final StructuredGraph graph) {
|
||||||
try (Scope s = Debug.scope("FrontEnd")) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("FrontEnd")) {
|
||||||
GraalCompiler.emitFrontEnd(getProviders(), getBackend(), graph, getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, graph.getProfilingInfo(), createSuites(graph.getOptions()));
|
GraalCompiler.emitFrontEnd(getProviders(), getBackend(), graph, getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, graph.getProfilingInfo(), createSuites(graph.getOptions()));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
LIRGenerationResult lirGen = GraalCompiler.emitLIR(getBackend(), graph, null, null, createLIRSuites(graph.getOptions()));
|
LIRGenerationResult lirGen = GraalCompiler.emitLIR(getBackend(), graph, null, null, createLIRSuites(graph.getOptions()));
|
||||||
|
|
|
@ -1,371 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.graalvm.compiler.core.common.util.Util;
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugCloseable;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpHandler;
|
|
||||||
import org.graalvm.compiler.debug.DebugMethodMetrics;
|
|
||||||
import org.graalvm.compiler.debug.DebugTimer;
|
|
||||||
import org.graalvm.compiler.debug.DebugVerifyHandler;
|
|
||||||
import org.graalvm.compiler.debug.DelegatingDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.DelegatingDebugConfig.Feature;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.internal.DebugScope;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl.CompilationData;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsInlineeScopeInfo;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsPrinter;
|
|
||||||
import org.graalvm.compiler.nodes.InvokeNode;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
||||||
import org.graalvm.compiler.nodes.calc.BinaryNode;
|
|
||||||
import org.graalvm.compiler.nodes.calc.FixedBinaryNode;
|
|
||||||
import org.graalvm.compiler.nodes.calc.MulNode;
|
|
||||||
import org.graalvm.compiler.nodes.calc.ShiftNode;
|
|
||||||
import org.graalvm.compiler.nodes.calc.SignedDivNode;
|
|
||||||
import org.graalvm.compiler.nodes.calc.SubNode;
|
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
|
||||||
import org.graalvm.compiler.phases.BasePhase;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
|
||||||
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
|
||||||
import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
|
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
|
||||||
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
|
||||||
import org.graalvm.compiler.phases.tiers.Suites;
|
|
||||||
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
public abstract class MethodMetricsTest extends GraalCompilerTest {
|
|
||||||
static class TestApplication {
|
|
||||||
public static int m01(int x, int y) {
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m02(int x, int y) {
|
|
||||||
return x * y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m03(int x, int y) {
|
|
||||||
return x ^ y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m04(int x, int y) {
|
|
||||||
return x >> y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m05(int x, int y) {
|
|
||||||
return x >>> y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m06(int x, int y) {
|
|
||||||
return x << y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m07(int x, int y) {
|
|
||||||
return x > y ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m08(int x, int y) {
|
|
||||||
return x % y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m09(int x, int y) {
|
|
||||||
return x / y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int m10(int x, int y) {
|
|
||||||
return x - y;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Class<?>[] testSignature = new Class<?>[]{int.class, int.class};
|
|
||||||
public static final Object[] testArgs = new Object[]{10, 10};
|
|
||||||
|
|
||||||
static class MethodMetricPhases {
|
|
||||||
static class CountingAddPhase extends Phase {
|
|
||||||
|
|
||||||
// typically those global metrics would be static final, but we need new timers every
|
|
||||||
// invocation if we override the debugvaluefactory
|
|
||||||
private final DebugCounter globalCounter = Debug.counter("GlobalMetric");
|
|
||||||
private final DebugTimer globalTimer = Debug.timer("GlobalTimer");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
try (DebugCloseable d = globalTimer.start()) {
|
|
||||||
ResolvedJavaMethod method = graph.method();
|
|
||||||
DebugMethodMetrics mm = Debug.methodMetrics(method);
|
|
||||||
mm.addToMetric(graph.getNodes().filter(InvokeNode.class).count(), "Invokes");
|
|
||||||
mm.incrementMetric("PhaseRunsOnMethod");
|
|
||||||
globalCounter.increment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountingShiftPhase extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
Debug.methodMetrics(graph.method()).addToMetric(graph.getNodes().filter(ShiftNode.class).count(), "Shifts");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountingMulPhase extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
Debug.methodMetrics(graph.method()).addToMetric(graph.getNodes().filter(MulNode.class).count(), "Muls");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountingSubPhase extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
Debug.methodMetrics(graph.method()).addToMetric(graph.getNodes().filter(SubNode.class).count(), "Subs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountingDivPhase extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
Debug.methodMetrics(graph.method()).addToMetric(graph.getNodes().filter(SignedDivNode.class).count(), "Divs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CountingBinOpPhase extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
Debug.methodMetrics(graph.method()).addToMetric(graph.getNodes().filter(x -> x instanceof BinaryNode || x instanceof FixedBinaryNode).count(), "BinOps");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ScopeTestPhase extends Phase {
|
|
||||||
// typically those global metrics would be static final, but we need new timers every
|
|
||||||
// invocation if we override the debugvaluefactory
|
|
||||||
private final DebugTimer timer = Debug.timer("GlobalTimer1");
|
|
||||||
private final DebugTimer scopedTimer = Debug.timer("GlobalTimer2");
|
|
||||||
private final DebugTimer scopedScopedTimer = Debug.timer("GlobalTimer3");
|
|
||||||
private final DebugTimer scopedScopedScopeTimer = Debug.timer("GlobalTimer4");
|
|
||||||
|
|
||||||
private final DebugTimer timer1 = Debug.timer("GlobalTimer1_WithoutInlineEnhancement");
|
|
||||||
private final DebugTimer scopedTimer1 = Debug.timer("GlobalTimer2_WithoutInlineEnhancement");
|
|
||||||
private final DebugTimer scopedScopedTimer1 = Debug.timer("GlobalTimer3_WithoutInlineEnhancement");
|
|
||||||
private final DebugTimer scopedScopedScopeTimer1 = Debug.timer("GlobalTimer4_WithoutInlineEnhancement");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
// we are in an enhanced debug scope from graal compiler
|
|
||||||
// now we open multiple inlining scopes, record their time
|
|
||||||
try (DebugCloseable c1 = timer.start()) {
|
|
||||||
try (DebugCloseable c2 = scopedTimer.start()) {
|
|
||||||
try (DebugCloseable c3 = scopedScopedTimer.start()) {
|
|
||||||
// do sth unnecessary long allocating many inlinee scopes
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
try (Debug.Scope s1 = Debug.methodMetricsScope("InlineEnhancement1", MethodMetricsInlineeScopeInfo.create(graph.method()), false)) {
|
|
||||||
try (DebugCloseable c4 = scopedScopedScopeTimer.start()) {
|
|
||||||
new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS).apply(graph);
|
|
||||||
// double scoped inlinee scopes should not make problems
|
|
||||||
// with the data
|
|
||||||
try (Debug.Scope s2 = Debug.methodMetricsScope("InlineEnhancement2", MethodMetricsInlineeScopeInfo.create(graph.method()),
|
|
||||||
false)) {
|
|
||||||
new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS).apply(graph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now lets try different counters without the inline enhancement
|
|
||||||
try (DebugCloseable c1 = timer1.start()) {
|
|
||||||
try (DebugCloseable c2 = scopedTimer1.start()) {
|
|
||||||
try (DebugCloseable c3 = scopedScopedTimer1.start()) {
|
|
||||||
// do sth unnecessary long allocating many inlinee scopes
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
try (DebugCloseable c4 = scopedScopedScopeTimer1.start()) {
|
|
||||||
new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS).apply(graph);
|
|
||||||
new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS).apply(graph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static DebugConfig overrideGraalDebugConfig(PrintStream log, String methodFilter, String methodMeter) {
|
|
||||||
List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
|
|
||||||
List<DebugVerifyHandler> verifyHandlers = new ArrayList<>();
|
|
||||||
OptionValues options = getInitialOptions();
|
|
||||||
GraalDebugConfig debugConfig = new GraalDebugConfig(
|
|
||||||
options,
|
|
||||||
GraalDebugConfig.Options.Log.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Count.getValue(options),
|
|
||||||
GraalDebugConfig.Options.TrackMemUse.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Time.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Dump.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Verify.getValue(options),
|
|
||||||
methodFilter,
|
|
||||||
methodMeter,
|
|
||||||
log, dumpHandlers, verifyHandlers);
|
|
||||||
return debugConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract Phase additionalPhase();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Suites createSuites(OptionValues options) {
|
|
||||||
Suites ret = super.createSuites(options);
|
|
||||||
ListIterator<BasePhase<? super HighTierContext>> iter = ret.getHighTier().findPhase(ConvertDeoptimizeToGuardPhase.class, true);
|
|
||||||
PhaseSuite.findNextPhase(iter, CanonicalizerPhase.class);
|
|
||||||
iter.add(additionalPhase());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
public void test() throws Throwable {
|
|
||||||
try (DebugConfigScope s = Debug.setConfig(getConfig())) {
|
|
||||||
executeMethod(TestApplication.class.getMethod("m01", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m02", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m03", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m04", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m05", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m06", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m07", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m08", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m09", testSignature), null, testArgs);
|
|
||||||
executeMethod(TestApplication.class.getMethod("m10", testSignature), null, testArgs);
|
|
||||||
assertValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void executeMethod(Method m, Object receiver, Object... args) {
|
|
||||||
OptionValues options = new OptionValues(getInitialOptions(), MethodMetricsPrinter.Options.MethodMeterPrintAscii, true);
|
|
||||||
test(options, asResolvedJavaMethod(m), receiver, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void rememberScopeId() {
|
|
||||||
scopeIdBeforeAccess = DebugScope.getCurrentGlobalScopeId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void clearMMCache() {
|
|
||||||
MethodMetricsImpl.clearMM();
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract DebugConfig getConfig();
|
|
||||||
|
|
||||||
abstract void assertValues() throws Throwable;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static Map<ResolvedJavaMethod, CompilationData> readMethodMetricsImplData() {
|
|
||||||
Map<ResolvedJavaMethod, CompilationData> threadLocalMap = null;
|
|
||||||
for (Field f : MethodMetricsImpl.class.getDeclaredFields()) {
|
|
||||||
if (f.getName().equals("threadEntries")) {
|
|
||||||
Util.setAccessible(f, true);
|
|
||||||
Object map;
|
|
||||||
try {
|
|
||||||
map = ((ThreadLocal<?>) f.get(null)).get();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new RuntimeException(t);
|
|
||||||
}
|
|
||||||
threadLocalMap = (Map<ResolvedJavaMethod, CompilationData>) map;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return threadLocalMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long scopeIdBeforeAccess;
|
|
||||||
private long scopeIdAfterAccess;
|
|
||||||
|
|
||||||
protected long readValFromCurrThread(ResolvedJavaMethod method, String metricName) {
|
|
||||||
|
|
||||||
Map<ResolvedJavaMethod, CompilationData> threadLocalMap = readMethodMetricsImplData();
|
|
||||||
assert threadLocalMap != null;
|
|
||||||
CompilationData compilationData = threadLocalMap.get(method);
|
|
||||||
assert compilationData != null;
|
|
||||||
Map<Long, Map<String, Long>> compilations = compilationData.getCompilations();
|
|
||||||
List<Map<String, Long>> compilationEntries = new ArrayList<>();
|
|
||||||
compilations.forEach((x, y) -> {
|
|
||||||
if (x >= scopeIdBeforeAccess && x <= scopeIdAfterAccess) {
|
|
||||||
compilationEntries.add(y);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
List<Map<String, Long>> listView = compilationEntries.stream().filter(x -> x.size() > 0).collect(Collectors.toList());
|
|
||||||
assert listView.size() <= 1 : "There must be at most one none empty compilation data point present:" + listView.size();
|
|
||||||
/*
|
|
||||||
* NOTE: Using the pre-generation of compilation entries for a method has the disadvantage
|
|
||||||
* that during testing we have different points in time when we request the metric. First,
|
|
||||||
* properly, when we use it and then when we want to know the result, but when we check the
|
|
||||||
* result the debug context no longer holds a correct scope with the unique id, so we return
|
|
||||||
* the first compilation entry that is not empty.
|
|
||||||
*/
|
|
||||||
Map<String, Long> entries = listView.size() > 0 ? listView.get(0) : null;
|
|
||||||
Long res = entries != null ? entries.get(metricName) : null;
|
|
||||||
return res != null ? res : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
void assertValues(String metricName, long[] vals) {
|
|
||||||
scopeIdAfterAccess = DebugScope.getCurrentGlobalScopeId();
|
|
||||||
try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().enable(Feature.METHOD_METRICS))) {
|
|
||||||
Assert.assertEquals(vals[0], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m01", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[1], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m02", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[2], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m03", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[3], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m04", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[4], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m05", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[5], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m06", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[6], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m07", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[7], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m08", testSignature)), metricName));
|
|
||||||
Assert.assertEquals(vals[8], readValFromCurrThread(asResolvedJavaMethod(TestApplication.class.getMethod("m09", testSignature)), metricName));
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new RuntimeException(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
public class MethodMetricsTest1 extends MethodMetricsTest {
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingAddPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingAddPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("PhaseRunsOnMethod", new long[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Test
|
|
||||||
public void test() throws Throwable {
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
public class MethodMetricsTest2 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingShiftPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingShiftPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("Shifts", new long[]{0, 0, 0, 1, 1, 1, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Override
|
|
||||||
public void test() throws Throwable {
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
public class MethodMetricsTest3 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingMulPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingMulPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("Muls", new long[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Test
|
|
||||||
public void test() throws Throwable {
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
public class MethodMetricsTest4 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingSubPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingSubPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("Subs", new long[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Test
|
|
||||||
public void test() throws Throwable {
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
public class MethodMetricsTest6 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingBinOpPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingBinOpPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("BinOps", new long[]{1, 1, 1, 1, 1, 1, 0, 1, 1, 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Test
|
|
||||||
public void test() throws Throwable {
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,119 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpHandler;
|
|
||||||
import org.graalvm.compiler.debug.DebugMemUseTracker;
|
|
||||||
import org.graalvm.compiler.debug.DebugMethodMetrics;
|
|
||||||
import org.graalvm.compiler.debug.DebugTimer;
|
|
||||||
import org.graalvm.compiler.debug.DebugValueFactory;
|
|
||||||
import org.graalvm.compiler.debug.DebugVerifyHandler;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.internal.CounterImpl;
|
|
||||||
import org.graalvm.compiler.debug.internal.MemUseTrackerImpl;
|
|
||||||
import org.graalvm.compiler.debug.internal.TimerImpl;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl;
|
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
// intercepting metrics
|
|
||||||
public class MethodMetricsTestInterception01 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.CountingAddPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
|
|
||||||
List<DebugVerifyHandler> verifyHandlers = new ArrayList<>();
|
|
||||||
OptionValues options = getInitialOptions();
|
|
||||||
GraalDebugConfig debugConfig = new GraalDebugConfig(
|
|
||||||
options,
|
|
||||||
GraalDebugConfig.Options.Log.getValue(options),
|
|
||||||
"CountingAddPhase",
|
|
||||||
GraalDebugConfig.Options.TrackMemUse.getValue(options),
|
|
||||||
"CountingAddPhase",
|
|
||||||
GraalDebugConfig.Options.Dump.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Verify.getValue(options),
|
|
||||||
"MethodMetricsTest$TestApplication.*",
|
|
||||||
"CountingAddPhase",
|
|
||||||
System.out, dumpHandlers, verifyHandlers);
|
|
||||||
return debugConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DebugValueFactory factory;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
public void test() throws Throwable {
|
|
||||||
factory = Debug.getDebugValueFactory();
|
|
||||||
Debug.setDebugValueFactory(new DebugValueFactory() {
|
|
||||||
@Override
|
|
||||||
public DebugTimer createTimer(String name, boolean conditional) {
|
|
||||||
return new TimerImpl(name, conditional, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugCounter createCounter(String name, boolean conditional) {
|
|
||||||
return CounterImpl.create(name, conditional, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugMethodMetrics createMethodMetrics(ResolvedJavaMethod method) {
|
|
||||||
return MethodMetricsImpl.getMethodMetrics(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugMemUseTracker createMemUseTracker(String name, boolean conditional) {
|
|
||||||
return new MemUseTrackerImpl(name, conditional, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
super.test();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTest() {
|
|
||||||
super.afterTest();
|
|
||||||
Debug.setDebugValueFactory(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("GlobalMetric", new long[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,164 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugCloseable;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpHandler;
|
|
||||||
import org.graalvm.compiler.debug.DebugMemUseTracker;
|
|
||||||
import org.graalvm.compiler.debug.DebugMethodMetrics;
|
|
||||||
import org.graalvm.compiler.debug.DebugTimer;
|
|
||||||
import org.graalvm.compiler.debug.DebugValueFactory;
|
|
||||||
import org.graalvm.compiler.debug.DebugVerifyHandler;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl;
|
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
// intercepting metrics
|
|
||||||
public class MethodMetricsTestInterception02 extends MethodMetricsTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Phase additionalPhase() {
|
|
||||||
return new MethodMetricPhases.ScopeTestPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
private DebugValueFactory factory;
|
|
||||||
|
|
||||||
public void setFactory() {
|
|
||||||
/*
|
|
||||||
* setting a custom debug value factory creating a constant timer for checking scope
|
|
||||||
* creation and inlining scopes with metric intercepting works
|
|
||||||
*/
|
|
||||||
factory = Debug.getDebugValueFactory();
|
|
||||||
Debug.setDebugValueFactory(new DebugValueFactory() {
|
|
||||||
@Override
|
|
||||||
public DebugTimer createTimer(String name, boolean conditional) {
|
|
||||||
// can still use together with real timer
|
|
||||||
// TimerImpl realTimer = new TimerImpl(name, conditional, true);
|
|
||||||
return new DebugTimer() {
|
|
||||||
int runs = 0;
|
|
||||||
|
|
||||||
// private DebugCloseable t;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugCloseable start() {
|
|
||||||
// t = realTimer.start();
|
|
||||||
return new DebugCloseable() {
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
// t.close();
|
|
||||||
runs++;
|
|
||||||
MethodMetricsImpl.addToCurrentScopeMethodMetrics(name, 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConditional(boolean flag) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConditional() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TimeUnit getTimeUnit() {
|
|
||||||
return TimeUnit.MILLISECONDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getCurrentValue() {
|
|
||||||
return runs;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugCounter createCounter(String name, boolean conditional) {
|
|
||||||
return factory.createCounter(name, conditional);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugMethodMetrics createMethodMetrics(ResolvedJavaMethod method) {
|
|
||||||
return factory.createMethodMetrics(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DebugMemUseTracker createMemUseTracker(String name, boolean conditional) {
|
|
||||||
return factory.createMemUseTracker(name, conditional);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Override
|
|
||||||
public void test() throws Throwable {
|
|
||||||
setFactory();
|
|
||||||
super.test();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTest() {
|
|
||||||
super.afterTest();
|
|
||||||
Debug.setDebugValueFactory(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
DebugConfig getConfig() {
|
|
||||||
List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
|
|
||||||
List<DebugVerifyHandler> verifyHandlers = new ArrayList<>();
|
|
||||||
OptionValues options = getInitialOptions();
|
|
||||||
GraalDebugConfig debugConfig = new GraalDebugConfig(
|
|
||||||
options,
|
|
||||||
GraalDebugConfig.Options.Log.getValue(options),
|
|
||||||
""/* unscoped meter */,
|
|
||||||
GraalDebugConfig.Options.TrackMemUse.getValue(options),
|
|
||||||
""/* unscoped time */,
|
|
||||||
GraalDebugConfig.Options.Dump.getValue(options),
|
|
||||||
GraalDebugConfig.Options.Verify.getValue(options),
|
|
||||||
null /* no method filter */,
|
|
||||||
"" /* unscoped method metering */,
|
|
||||||
System.out, dumpHandlers, verifyHandlers);
|
|
||||||
return debugConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
void assertValues() throws Throwable {
|
|
||||||
assertValues("GlobalTimer4_WithoutInlineEnhancement", new long[]{50, 50, 50, 50, 50, 50, 50, 50, 50, 50});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,265 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 2016, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core.test.debug;
|
|
||||||
|
|
||||||
import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
|
||||||
import org.graalvm.compiler.debug.DebugMethodMetrics;
|
|
||||||
import org.graalvm.compiler.graph.Node;
|
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
|
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
|
||||||
import org.graalvm.compiler.phases.Phase;
|
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
|
||||||
import org.graalvm.compiler.phases.VerifyPhase.VerificationError;
|
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
|
||||||
import org.graalvm.compiler.phases.util.Providers;
|
|
||||||
import org.graalvm.compiler.phases.verify.VerifyDebugUsage;
|
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Tests to verify that the usage of method metrics does not generate compile time overhead through
|
|
||||||
* eager evaluation of arguments.
|
|
||||||
*/
|
|
||||||
public class VerifyMethodMetricsTest {
|
|
||||||
|
|
||||||
private static class InvalidCCP_ToString01Inc extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.incrementMetric(n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_Concat01Inc extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.incrementMetric("a" + n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_ToString02Inc extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.incrementMetric("%s", n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_Concat02Inc extends Phase {
|
|
||||||
private final String s = this.getClass().toGenericString();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.incrementMetric("%s%s", "a" + s, n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ValidCCP_ToStringInc extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "%s", n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ValidCCP_ConcatInc extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.incrementMetric("%s%s", "a", n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_ToString01Add extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_Concat01Add extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "a" + n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_ToString02Add extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "%s", n.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InvalidCCP_Concat02Add extends Phase {
|
|
||||||
private final String s = this.getClass().toGenericString();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "%s%s", "a" + s, n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ValidCCP_ToStringAdd extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "%s", n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ValidCCP_ConcatAdd extends Phase {
|
|
||||||
@Override
|
|
||||||
protected void run(StructuredGraph graph) {
|
|
||||||
DebugMethodMetrics m = Debug.methodMetrics(graph.method());
|
|
||||||
for (Node n : graph.getNodes()) {
|
|
||||||
m.addToMetric(1, "%s%s", "a", n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidToString01Add() {
|
|
||||||
testDebugUsageClass(InvalidCCP_ToString01Add.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidConcat01Add() {
|
|
||||||
testDebugUsageClass(InvalidCCP_Concat01Add.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidToString02Add() {
|
|
||||||
testDebugUsageClass(InvalidCCP_ToString02Add.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidConcat02Add() {
|
|
||||||
testDebugUsageClass(InvalidCCP_Concat02Add.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogValidToStringAdd() {
|
|
||||||
testDebugUsageClass(ValidCCP_ToStringAdd.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogValidConcatAdd() {
|
|
||||||
testDebugUsageClass(ValidCCP_ConcatAdd.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidToString01Inc() {
|
|
||||||
testDebugUsageClass(InvalidCCP_ToString01Inc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidConcat01Inc() {
|
|
||||||
testDebugUsageClass(InvalidCCP_Concat01Inc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidToString02Inc() {
|
|
||||||
testDebugUsageClass(InvalidCCP_ToString02Inc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = VerificationError.class)
|
|
||||||
public void testLogInvalidConcat02Inc() {
|
|
||||||
testDebugUsageClass(InvalidCCP_Concat02Inc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogValidToStringInc() {
|
|
||||||
testDebugUsageClass(ValidCCP_ToStringInc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogValidConcatInc() {
|
|
||||||
testDebugUsageClass(ValidCCP_ConcatInc.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
private static void testDebugUsageClass(Class<?> c) {
|
|
||||||
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
|
|
||||||
Providers providers = rt.getHostBackend().getProviders();
|
|
||||||
MetaAccessProvider metaAccess = providers.getMetaAccess();
|
|
||||||
PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
|
|
||||||
Plugins plugins = new Plugins(new InvocationPlugins());
|
|
||||||
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
|
||||||
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
|
|
||||||
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
|
|
||||||
for (Method m : c.getDeclaredMethods()) {
|
|
||||||
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
|
|
||||||
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
|
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
|
||||||
graphBuilderSuite.apply(graph, context);
|
|
||||||
try (DebugConfigScope s = Debug.disableIntercept()) {
|
|
||||||
new VerifyDebugUsage().apply(graph, context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -189,7 +189,7 @@ public final class MonitorDeoptTest extends GraalCompilerTest {
|
||||||
removeLoopSafepoint(graph);
|
removeLoopSafepoint(graph);
|
||||||
|
|
||||||
CompilationResult compilationResult = compile(javaMethod, graph);
|
CompilationResult compilationResult = compile(javaMethod, graph);
|
||||||
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(javaMethod, compilationResult);
|
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
|
||||||
|
|
||||||
final Monitor monitor = new Monitor();
|
final Monitor monitor = new Monitor();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test.deopt;
|
package org.graalvm.compiler.core.test.deopt;
|
||||||
|
|
||||||
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
|
@ -44,6 +45,9 @@ public class SynchronizedMethodDeoptimizationTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test1() {
|
public void test1() {
|
||||||
|
// https://bugs.openjdk.java.net/browse/JDK-8182755
|
||||||
|
Assume.assumeTrue(Java8OrEarlier);
|
||||||
|
|
||||||
test("testMethodSynchronized", "test");
|
test("testMethodSynchronized", "test");
|
||||||
test("testMethodSynchronized", (Object) null);
|
test("testMethodSynchronized", (Object) null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,8 @@ package org.graalvm.compiler.core.test.ea;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.JavaConstant;
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.nodes.ReturnNode;
|
import org.graalvm.compiler.nodes.ReturnNode;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
|
@ -43,6 +37,10 @@ import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
|
||||||
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
|
import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import jdk.vm.ci.meta.JavaConstant;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
|
||||||
//JaCoCo Exclude
|
//JaCoCo Exclude
|
||||||
|
|
||||||
|
@ -154,8 +152,9 @@ public class EATestBase extends GraalCompilerTest {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
|
protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
|
||||||
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
|
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
|
||||||
try (Scope s = Debug.scope(getClass(), method, getCodeCache())) {
|
DebugContext debug = getDebugContext();
|
||||||
graph = parseEager(method, AllowAssumptions.YES);
|
try (DebugContext.Scope s = debug.scope(getClass(), method, getCodeCache())) {
|
||||||
|
graph = parseEager(method, AllowAssumptions.YES, debug);
|
||||||
context = getDefaultHighTierContext();
|
context = getDefaultHighTierContext();
|
||||||
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
||||||
new DeadCodeEliminationPhase().apply(graph);
|
new DeadCodeEliminationPhase().apply(graph);
|
||||||
|
@ -163,7 +162,7 @@ public class EATestBase extends GraalCompilerTest {
|
||||||
new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
|
new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
|
||||||
returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
|
returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,8 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test.ea;
|
package org.graalvm.compiler.core.test.ea;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.FrameState;
|
import org.graalvm.compiler.nodes.FrameState;
|
||||||
|
@ -40,6 +37,7 @@ import org.graalvm.compiler.phases.common.LoweringPhase;
|
||||||
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AbstractNewObjectNode#simplify(org.graalvm.compiler.graph.spi.SimplifierTool)}.
|
* Tests {@link AbstractNewObjectNode#simplify(org.graalvm.compiler.graph.spi.SimplifierTool)}.
|
||||||
|
@ -63,7 +61,8 @@ public class PoorMansEATest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private void test(final String snippet) {
|
private void test(final String snippet) {
|
||||||
try (Scope s = Debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) {
|
||||||
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
|
||||||
HighTierContext highTierContext = getDefaultHighTierContext();
|
HighTierContext highTierContext = getDefaultHighTierContext();
|
||||||
new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
|
new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
|
||||||
|
@ -82,7 +81,7 @@ public class PoorMansEATest extends GraalCompilerTest {
|
||||||
}
|
}
|
||||||
new CanonicalizerPhase().apply(graph, context);
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,21 +22,15 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.test.inlining;
|
package org.graalvm.compiler.core.test.inlining;
|
||||||
|
|
||||||
import jdk.vm.ci.code.site.InfopointReason;
|
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.FullInfopointNode;
|
import org.graalvm.compiler.nodes.FullInfopointNode;
|
||||||
import org.graalvm.compiler.nodes.Invoke;
|
import org.graalvm.compiler.nodes.Invoke;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
|
import org.graalvm.compiler.nodes.StructuredGraph.Builder;
|
||||||
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
|
@ -44,6 +38,11 @@ import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
||||||
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
|
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
|
||||||
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
||||||
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import jdk.vm.ci.code.site.InfopointReason;
|
||||||
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
|
|
||||||
public class InliningTest extends GraalCompilerTest {
|
public class InliningTest extends GraalCompilerTest {
|
||||||
|
|
||||||
|
@ -236,24 +235,26 @@ public class InliningTest extends GraalCompilerTest {
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private StructuredGraph getGraph(final String snippet, final boolean eagerInfopointMode) {
|
private StructuredGraph getGraph(final String snippet, final boolean eagerInfopointMode) {
|
||||||
try (Scope s = Debug.scope("InliningTest", new DebugDumpScope(snippet, true))) {
|
DebugContext debug = getDebugContext();
|
||||||
|
try (DebugContext.Scope s = debug.scope("InliningTest", new DebugDumpScope(snippet, true))) {
|
||||||
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
|
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
|
||||||
StructuredGraph graph = eagerInfopointMode ? parseDebug(method, AllowAssumptions.YES) : parseEager(method, AllowAssumptions.YES);
|
Builder builder = builder(method, AllowAssumptions.YES, debug);
|
||||||
try (Scope s2 = Debug.scope("Inlining", graph)) {
|
StructuredGraph graph = eagerInfopointMode ? parse(builder, getDebugGraphBuilderSuite()) : parse(builder, getEagerGraphBuilderSuite());
|
||||||
|
try (DebugContext.Scope s2 = debug.scope("Inlining", graph)) {
|
||||||
PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode
|
PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode
|
||||||
? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true))
|
? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true))
|
||||||
: getDefaultGraphBuilderSuite();
|
: getDefaultGraphBuilderSuite();
|
||||||
HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL);
|
HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
new CanonicalizerPhase().apply(graph, context);
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
||||||
new CanonicalizerPhase().apply(graph, context);
|
new CanonicalizerPhase().apply(graph, context);
|
||||||
new DeadCodeEliminationPhase().apply(graph);
|
new DeadCodeEliminationPhase().apply(graph);
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,14 @@ package org.graalvm.compiler.core.test.inlining;
|
||||||
import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Optional;
|
import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Optional;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.TTY;
|
import org.graalvm.compiler.debug.TTY;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.Invoke;
|
import org.graalvm.compiler.nodes.Invoke;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph;
|
import org.graalvm.compiler.nodes.StructuredGraph;
|
||||||
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
||||||
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.BasePhase;
|
import org.graalvm.compiler.phases.BasePhase;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
|
@ -100,10 +101,9 @@ public class NestedLoopEffectsPhaseComplexityTest extends GraalCompilerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testAndTime(String snippet) {
|
private void testAndTime(String snippet) {
|
||||||
initializeForTimeout();
|
|
||||||
for (int i = InliningCountLowerBound; i < InliningCountUpperBound; i++) {
|
for (int i = InliningCountLowerBound; i < InliningCountUpperBound; i++) {
|
||||||
StructuredGraph g1 = prepareGraph(snippet, i);
|
StructuredGraph g1 = prepareGraph(snippet, i);
|
||||||
StructuredGraph g2 = (StructuredGraph) g1.copy();
|
StructuredGraph g2 = (StructuredGraph) g1.copy(g1.getDebug());
|
||||||
ResolvedJavaMethod method = g1.method();
|
ResolvedJavaMethod method = g1.method();
|
||||||
long elapsedRE = runAndTimePhase(g1, new EarlyReadEliminationPhase(new CanonicalizerPhase()));
|
long elapsedRE = runAndTimePhase(g1, new EarlyReadEliminationPhase(new CanonicalizerPhase()));
|
||||||
long elapsedPEA = runAndTimePhase(g2, new PartialEscapePhase(true, new CanonicalizerPhase(), g1.getOptions()));
|
long elapsedPEA = runAndTimePhase(g2, new PartialEscapePhase(true, new CanonicalizerPhase(), g1.getOptions()));
|
||||||
|
@ -121,7 +121,8 @@ public class NestedLoopEffectsPhaseComplexityTest extends GraalCompilerTest {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
phase.apply(g, context);
|
phase.apply(g, context);
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
Debug.dump(Debug.DETAILED_LEVEL, g, "After %s", phase.contractorName());
|
DebugContext debug = g.getDebug();
|
||||||
|
debug.dump(DebugContext.DETAILED_LEVEL, g, "After %s", phase.contractorName());
|
||||||
return end - start;
|
return end - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +139,14 @@ public class NestedLoopEffectsPhaseComplexityTest extends GraalCompilerTest {
|
||||||
next = callerGraph.getNodes(MethodCallTargetNode.TYPE).first().invoke();
|
next = callerGraph.getNodes(MethodCallTargetNode.TYPE).first().invoke();
|
||||||
EconomicSet<Node> canonicalizeNodes = InliningUtil.inlineForCanonicalization(next, calleeGraph, false, calleeMethod);
|
EconomicSet<Node> canonicalizeNodes = InliningUtil.inlineForCanonicalization(next, calleeGraph, false, calleeMethod);
|
||||||
canonicalizer.applyIncremental(callerGraph, context, canonicalizeNodes);
|
canonicalizer.applyIncremental(callerGraph, context, canonicalizeNodes);
|
||||||
Debug.dump(Debug.DETAILED_LEVEL, callerGraph, "After inlining %s into %s iteration %d", calleeMethod, callerMethod, i);
|
callerGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, callerGraph, "After inlining %s into %s iteration %d", calleeMethod, callerMethod, i);
|
||||||
}
|
}
|
||||||
return callerGraph;
|
return callerGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
|
private StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
|
||||||
StructuredGraph newGraph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.NO).method(method).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
StructuredGraph newGraph = new StructuredGraph.Builder(options, getDebugContext(options), AllowAssumptions.NO).method(method).build();
|
||||||
context.getGraphBuilderSuite().apply(newGraph, context);
|
context.getGraphBuilderSuite().apply(newGraph, context);
|
||||||
new DeadCodeEliminationPhase(Optional).apply(newGraph);
|
new DeadCodeEliminationPhase(Optional).apply(newGraph);
|
||||||
canonicalizer.apply(newGraph, context);
|
canonicalizer.apply(newGraph, context);
|
||||||
|
|
|
@ -24,6 +24,7 @@ package org.graalvm.compiler.core.test.tutorial;
|
||||||
|
|
||||||
import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
|
import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
|
||||||
import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
|
import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.graalvm.compiler.api.test.Graal;
|
import org.graalvm.compiler.api.test.Graal;
|
||||||
|
@ -31,8 +32,8 @@ import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.core.GraalCompiler;
|
import org.graalvm.compiler.core.GraalCompiler;
|
||||||
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
||||||
import org.graalvm.compiler.core.target.Backend;
|
import org.graalvm.compiler.core.target.Backend;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.DebugDumpScope;
|
import org.graalvm.compiler.debug.DebugDumpScope;
|
||||||
import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
|
import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
|
||||||
import org.graalvm.compiler.lir.phases.LIRSuites;
|
import org.graalvm.compiler.lir.phases.LIRSuites;
|
||||||
|
@ -85,7 +86,8 @@ public class InvokeGraal {
|
||||||
/* Create a unique compilation identifier, visible in IGV. */
|
/* Create a unique compilation identifier, visible in IGV. */
|
||||||
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
|
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
|
||||||
OptionValues options = getInitialOptions();
|
OptionValues options = getInitialOptions();
|
||||||
try (Scope s = Debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
|
try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The graph that is compiled. We leave it empty (no nodes added yet). This means that
|
* The graph that is compiled. We leave it empty (no nodes added yet). This means that
|
||||||
|
@ -93,7 +95,7 @@ public class InvokeGraal {
|
||||||
* that we want the compilation to make optimistic assumptions about runtime state such
|
* that we want the compilation to make optimistic assumptions about runtime state such
|
||||||
* as the loaded class hierarchy.
|
* as the loaded class hierarchy.
|
||||||
*/
|
*/
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.YES).method(method).compilationId(compilationId).build();
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
|
* The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
|
||||||
|
@ -131,9 +133,9 @@ public class InvokeGraal {
|
||||||
* Install the compilation result into the VM, i.e., copy the byte[] array that contains
|
* Install the compilation result into the VM, i.e., copy the byte[] array that contains
|
||||||
* the machine code into an actual executable memory location.
|
* the machine code into an actual executable memory location.
|
||||||
*/
|
*/
|
||||||
return backend.addInstalledCode(method, asCompilationRequest(compilationId), compilationResult);
|
return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
throw Debug.handle(ex);
|
throw debug.handle(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.NodeMap;
|
import org.graalvm.compiler.graph.NodeMap;
|
||||||
import org.graalvm.compiler.java.GraphBuilderPhase;
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
|
@ -58,6 +58,7 @@ import org.graalvm.compiler.nodes.java.NewInstanceNode;
|
||||||
import org.graalvm.compiler.nodes.java.StoreFieldNode;
|
import org.graalvm.compiler.nodes.java.StoreFieldNode;
|
||||||
import org.graalvm.compiler.nodes.spi.StampProvider;
|
import org.graalvm.compiler.nodes.spi.StampProvider;
|
||||||
import org.graalvm.compiler.nodes.util.GraphUtil;
|
import org.graalvm.compiler.nodes.util.GraphUtil;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
||||||
import org.graalvm.compiler.phases.graph.StatelessPostOrderNodeIterator;
|
import org.graalvm.compiler.phases.graph.StatelessPostOrderNodeIterator;
|
||||||
|
|
||||||
|
@ -240,12 +241,14 @@ public class StaticAnalysis {
|
||||||
* Build the Graal graph for the method using the bytecode parser provided by Graal.
|
* Build the Graal graph for the method using the bytecode parser provided by Graal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
|
OptionValues options = getInitialOptions();
|
||||||
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
|
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
|
||||||
/*
|
/*
|
||||||
* Support for graph dumping, IGV uses this information to show the method name of a
|
* Support for graph dumping, IGV uses this information to show the method name of a
|
||||||
* graph.
|
* graph.
|
||||||
*/
|
*/
|
||||||
try (Scope scope = Debug.scope("graph building", graph)) {
|
try (DebugContext.Scope scope = debug.scope("graph building", graph)) {
|
||||||
/*
|
/*
|
||||||
* We want all types to be resolved by the graph builder, i.e., we want classes
|
* We want all types to be resolved by the graph builder, i.e., we want classes
|
||||||
* referenced by the bytecodes to be loaded and initialized. Since we do not run
|
* referenced by the bytecodes to be loaded and initialized. Since we do not run
|
||||||
|
@ -271,7 +274,7 @@ public class StaticAnalysis {
|
||||||
GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(metaAccess, stampProvider, null, null, graphBuilderConfig, optimisticOpts, null);
|
GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(metaAccess, stampProvider, null, null, graphBuilderConfig, optimisticOpts, null);
|
||||||
graphBuilder.apply(graph);
|
graphBuilder.apply(graph);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Debug.handle(ex);
|
debug.handle(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -22,42 +22,21 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core;
|
package org.graalvm.compiler.core;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.CompilerThreadFactory.DebugConfigAccess;
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.DebugDumpHandler;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY} and executes in the
|
* A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY}.
|
||||||
* context of a thread-local {@linkplain GraalDebugConfig debug configuration}.
|
|
||||||
*/
|
*/
|
||||||
public class CompilerThread extends Thread {
|
public class CompilerThread extends Thread {
|
||||||
|
|
||||||
private final DebugConfigAccess debugConfigAccess;
|
public CompilerThread(Runnable r, String namePrefix) {
|
||||||
|
|
||||||
public CompilerThread(Runnable r, String namePrefix, DebugConfigAccess debugConfigAccess) {
|
|
||||||
super(r);
|
super(r);
|
||||||
this.setName(namePrefix + "-" + this.getId());
|
this.setName(namePrefix + "-" + this.getId());
|
||||||
this.setPriority(Thread.MAX_PRIORITY);
|
this.setPriority(Thread.MAX_PRIORITY);
|
||||||
this.setDaemon(true);
|
this.setDaemon(true);
|
||||||
this.debugConfigAccess = debugConfigAccess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DebugConfig debugConfig = debugConfigAccess.getDebugConfig();
|
|
||||||
setContextClassLoader(getClass().getClassLoader());
|
setContextClassLoader(getClass().getClassLoader());
|
||||||
try {
|
super.run();
|
||||||
super.run();
|
|
||||||
} finally {
|
|
||||||
if (debugConfig != null) {
|
|
||||||
for (DebugDumpHandler dumpHandler : debugConfig.dumpHandlers()) {
|
|
||||||
try {
|
|
||||||
dumpHandler.close();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,34 +24,19 @@ package org.graalvm.compiler.core;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facility for creating {@linkplain CompilerThread compiler threads}.
|
* Facility for creating {@linkplain CompilerThread compiler threads}.
|
||||||
*/
|
*/
|
||||||
public class CompilerThreadFactory implements ThreadFactory {
|
public class CompilerThreadFactory implements ThreadFactory {
|
||||||
|
|
||||||
/**
|
|
||||||
* Capability to get a thread-local debug configuration for the current thread.
|
|
||||||
*/
|
|
||||||
public interface DebugConfigAccess {
|
|
||||||
/**
|
|
||||||
* Get a thread-local debug configuration for the current thread. This will be null if
|
|
||||||
* debugging is disabled.
|
|
||||||
*/
|
|
||||||
DebugConfig getDebugConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final String threadNamePrefix;
|
protected final String threadNamePrefix;
|
||||||
protected final DebugConfigAccess debugConfigAccess;
|
|
||||||
|
|
||||||
public CompilerThreadFactory(String threadNamePrefix, DebugConfigAccess debugConfigAccess) {
|
public CompilerThreadFactory(String threadNamePrefix) {
|
||||||
this.threadNamePrefix = threadNamePrefix;
|
this.threadNamePrefix = threadNamePrefix;
|
||||||
this.debugConfigAccess = debugConfigAccess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
return new CompilerThread(r, threadNamePrefix, debugConfigAccess);
|
return new CompilerThread(r, threadNamePrefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,12 @@ import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.core.common.util.CompilationAlarm;
|
import org.graalvm.compiler.core.common.util.CompilationAlarm;
|
||||||
import org.graalvm.compiler.core.target.Backend;
|
import org.graalvm.compiler.core.target.Backend;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.DebugCloseable;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.DebugTimer;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.debug.MethodFilter;
|
import org.graalvm.compiler.debug.MethodFilter;
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsRootScopeInfo;
|
import org.graalvm.compiler.debug.TimerKey;
|
||||||
import org.graalvm.compiler.lir.LIR;
|
import org.graalvm.compiler.lir.LIR;
|
||||||
import org.graalvm.compiler.lir.alloc.OutOfRegistersException;
|
import org.graalvm.compiler.lir.alloc.OutOfRegistersException;
|
||||||
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
||||||
|
@ -85,11 +83,11 @@ import jdk.vm.ci.meta.VMConstant;
|
||||||
*/
|
*/
|
||||||
public class GraalCompiler {
|
public class GraalCompiler {
|
||||||
|
|
||||||
private static final DebugTimer CompilerTimer = Debug.timer("GraalCompiler");
|
private static final TimerKey CompilerTimer = DebugContext.timer("GraalCompiler").doc("Time spent in compilation (excludes code installation).");
|
||||||
private static final DebugTimer FrontEnd = Debug.timer("FrontEnd");
|
private static final TimerKey FrontEnd = DebugContext.timer("FrontEnd").doc("Time spent processing HIR.");
|
||||||
private static final DebugTimer BackEnd = Debug.timer("BackEnd");
|
private static final TimerKey EmitLIR = DebugContext.timer("EmitLIR").doc("Time spent generating LIR from HIR.");
|
||||||
private static final DebugTimer EmitLIR = Debug.timer("EmitLIR");
|
private static final TimerKey EmitCode = DebugContext.timer("EmitCode").doc("Time spent generating machine code from LIR.");
|
||||||
private static final DebugTimer EmitCode = Debug.timer("EmitCode");
|
private static final TimerKey BackEnd = DebugContext.timer("BackEnd").doc("Time spent in EmitLIR and EmitCode.");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates all the inputs to a {@linkplain GraalCompiler#compile(Request) compilation}.
|
* Encapsulates all the inputs to a {@linkplain GraalCompiler#compile(Request) compilation}.
|
||||||
|
@ -167,14 +165,14 @@ public class GraalCompiler {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public static <T extends CompilationResult> T compile(Request<T> r) {
|
public static <T extends CompilationResult> T compile(Request<T> r) {
|
||||||
try (Scope s = MethodMetricsRootScopeInfo.createRootScopeIfAbsent(r.installedCodeOwner);
|
DebugContext debug = r.graph.getDebug();
|
||||||
CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
|
try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
|
||||||
assert !r.graph.isFrozen();
|
assert !r.graph.isFrozen();
|
||||||
try (Scope s0 = Debug.scope("GraalCompiler", r.graph, r.providers.getCodeCache()); DebugCloseable a = CompilerTimer.start()) {
|
try (DebugContext.Scope s0 = debug.scope("GraalCompiler", r.graph, r.providers.getCodeCache()); DebugCloseable a = CompilerTimer.start(debug)) {
|
||||||
emitFrontEnd(r.providers, r.backend, r.graph, r.graphBuilderSuite, r.optimisticOpts, r.profilingInfo, r.suites);
|
emitFrontEnd(r.providers, r.backend, r.graph, r.graphBuilderSuite, r.optimisticOpts, r.profilingInfo, r.suites);
|
||||||
emitBackEnd(r.graph, null, r.installedCodeOwner, r.backend, r.compilationResult, r.factory, null, r.lirSuites);
|
emitBackEnd(r.graph, null, r.installedCodeOwner, r.backend, r.compilationResult, r.factory, null, r.lirSuites);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
checkForRequestedCrash(r.graph);
|
checkForRequestedCrash(r.graph);
|
||||||
return r.compilationResult;
|
return r.compilationResult;
|
||||||
|
@ -217,32 +215,33 @@ public class GraalCompiler {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public static void emitFrontEnd(Providers providers, TargetProvider target, StructuredGraph graph, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts,
|
public static void emitFrontEnd(Providers providers, TargetProvider target, StructuredGraph graph, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts,
|
||||||
ProfilingInfo profilingInfo, Suites suites) {
|
ProfilingInfo profilingInfo, Suites suites) {
|
||||||
try (Scope s = Debug.scope("FrontEnd"); DebugCloseable a = FrontEnd.start()) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("FrontEnd"); DebugCloseable a = FrontEnd.start(debug)) {
|
||||||
HighTierContext highTierContext = new HighTierContext(providers, graphBuilderSuite, optimisticOpts);
|
HighTierContext highTierContext = new HighTierContext(providers, graphBuilderSuite, optimisticOpts);
|
||||||
if (graph.start().next() == null) {
|
if (graph.start().next() == null) {
|
||||||
graphBuilderSuite.apply(graph, highTierContext);
|
graphBuilderSuite.apply(graph, highTierContext);
|
||||||
new DeadCodeEliminationPhase(DeadCodeEliminationPhase.Optionality.Optional).apply(graph);
|
new DeadCodeEliminationPhase(DeadCodeEliminationPhase.Optionality.Optional).apply(graph);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After parsing");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After parsing");
|
||||||
} else {
|
} else {
|
||||||
Debug.dump(Debug.INFO_LEVEL, graph, "initial state");
|
debug.dump(DebugContext.INFO_LEVEL, graph, "initial state");
|
||||||
}
|
}
|
||||||
|
|
||||||
suites.getHighTier().apply(graph, highTierContext);
|
suites.getHighTier().apply(graph, highTierContext);
|
||||||
graph.maybeCompress();
|
graph.maybeCompress();
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After high tier");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After high tier");
|
||||||
|
|
||||||
MidTierContext midTierContext = new MidTierContext(providers, target, optimisticOpts, profilingInfo);
|
MidTierContext midTierContext = new MidTierContext(providers, target, optimisticOpts, profilingInfo);
|
||||||
suites.getMidTier().apply(graph, midTierContext);
|
suites.getMidTier().apply(graph, midTierContext);
|
||||||
graph.maybeCompress();
|
graph.maybeCompress();
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After mid tier");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After mid tier");
|
||||||
|
|
||||||
LowTierContext lowTierContext = new LowTierContext(providers, target);
|
LowTierContext lowTierContext = new LowTierContext(providers, target);
|
||||||
suites.getLowTier().apply(graph, lowTierContext);
|
suites.getLowTier().apply(graph, lowTierContext);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph, "After low tier");
|
debug.dump(DebugContext.BASIC_LEVEL, graph, "After low tier");
|
||||||
|
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph.getLastSchedule(), "Final HIR schedule");
|
debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "Final HIR schedule");
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
} finally {
|
} finally {
|
||||||
graph.checkCancellation();
|
graph.checkCancellation();
|
||||||
}
|
}
|
||||||
|
@ -251,18 +250,19 @@ public class GraalCompiler {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult,
|
public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult,
|
||||||
CompilationResultBuilderFactory factory, RegisterConfig registerConfig, LIRSuites lirSuites) {
|
CompilationResultBuilderFactory factory, RegisterConfig registerConfig, LIRSuites lirSuites) {
|
||||||
try (Scope s = Debug.scope("BackEnd", graph.getLastSchedule()); DebugCloseable a = BackEnd.start()) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("BackEnd", graph.getLastSchedule()); DebugCloseable a = BackEnd.start(debug)) {
|
||||||
LIRGenerationResult lirGen = null;
|
LIRGenerationResult lirGen = null;
|
||||||
lirGen = emitLIR(backend, graph, stub, registerConfig, lirSuites);
|
lirGen = emitLIR(backend, graph, stub, registerConfig, lirSuites);
|
||||||
try (Scope s2 = Debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
|
try (DebugContext.Scope s2 = debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
|
||||||
int bytecodeSize = graph.method() == null ? 0 : graph.getBytecodeSize();
|
int bytecodeSize = graph.method() == null ? 0 : graph.getBytecodeSize();
|
||||||
compilationResult.setHasUnsafeAccess(graph.hasUnsafeAccess());
|
compilationResult.setHasUnsafeAccess(graph.hasUnsafeAccess());
|
||||||
emitCode(backend, graph.getAssumptions(), graph.method(), graph.getMethods(), graph.getFields(), bytecodeSize, lirGen, compilationResult, installedCodeOwner, factory);
|
emitCode(backend, graph.getAssumptions(), graph.method(), graph.getMethods(), graph.getFields(), bytecodeSize, lirGen, compilationResult, installedCodeOwner, factory);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
} finally {
|
} finally {
|
||||||
graph.checkCancellation();
|
graph.checkCancellation();
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,8 @@ public class GraalCompiler {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites,
|
private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites,
|
||||||
String[] allocationRestrictedTo) {
|
String[] allocationRestrictedTo) {
|
||||||
try (Scope ds = Debug.scope("EmitLIR"); DebugCloseable a = EmitLIR.start()) {
|
DebugContext debug = graph.getDebug();
|
||||||
|
try (DebugContext.Scope ds = debug.scope("EmitLIR"); DebugCloseable a = EmitLIR.start(debug)) {
|
||||||
assert !graph.hasValueProxies();
|
assert !graph.hasValueProxies();
|
||||||
ScheduleResult schedule = graph.getLastSchedule();
|
ScheduleResult schedule = graph.getLastSchedule();
|
||||||
Block[] blocks = schedule.getCFG().getBlocks();
|
Block[] blocks = schedule.getCFG().getBlocks();
|
||||||
|
@ -299,7 +300,7 @@ public class GraalCompiler {
|
||||||
|
|
||||||
AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
|
AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
|
||||||
AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
|
AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
|
||||||
LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions());
|
LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
|
||||||
|
|
||||||
FrameMapBuilder frameMapBuilder = backend.newFrameMapBuilder(registerConfig);
|
FrameMapBuilder frameMapBuilder = backend.newFrameMapBuilder(registerConfig);
|
||||||
LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
|
LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
|
||||||
|
@ -310,16 +311,16 @@ public class GraalCompiler {
|
||||||
LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
|
LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
|
||||||
new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
|
new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
|
||||||
|
|
||||||
try (Scope s = Debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
|
try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
|
||||||
// Dump LIR along with HIR (the LIR is looked up from context)
|
// Dump LIR along with HIR (the LIR is looked up from context)
|
||||||
Debug.dump(Debug.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
|
debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
|
||||||
LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
|
LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
|
||||||
return result;
|
return result;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
} finally {
|
} finally {
|
||||||
graph.checkCancellation();
|
graph.checkCancellation();
|
||||||
}
|
}
|
||||||
|
@ -338,17 +339,18 @@ public class GraalCompiler {
|
||||||
|
|
||||||
public static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites,
|
public static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites,
|
||||||
RegisterAllocationConfig registerAllocationConfig) {
|
RegisterAllocationConfig registerAllocationConfig) {
|
||||||
|
DebugContext debug = lirGenRes.getLIR().getDebug();
|
||||||
PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
|
PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
|
||||||
lirSuites.getPreAllocationOptimizationStage().apply(target, lirGenRes, preAllocOptContext);
|
lirSuites.getPreAllocationOptimizationStage().apply(target, lirGenRes, preAllocOptContext);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, lirGenRes.getLIR(), "After PreAllocationOptimizationStage");
|
debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PreAllocationOptimizationStage");
|
||||||
|
|
||||||
AllocationContext allocContext = new AllocationContext(lirGen.getSpillMoveFactory(), registerAllocationConfig);
|
AllocationContext allocContext = new AllocationContext(lirGen.getSpillMoveFactory(), registerAllocationConfig);
|
||||||
lirSuites.getAllocationStage().apply(target, lirGenRes, allocContext);
|
lirSuites.getAllocationStage().apply(target, lirGenRes, allocContext);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, lirGenRes.getLIR(), "After AllocationStage");
|
debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After AllocationStage");
|
||||||
|
|
||||||
PostAllocationOptimizationContext postAllocOptContext = new PostAllocationOptimizationContext(lirGen);
|
PostAllocationOptimizationContext postAllocOptContext = new PostAllocationOptimizationContext(lirGen);
|
||||||
lirSuites.getPostAllocationOptimizationStage().apply(target, lirGenRes, postAllocOptContext);
|
lirSuites.getPostAllocationOptimizationStage().apply(target, lirGenRes, postAllocOptContext);
|
||||||
Debug.dump(Debug.BASIC_LEVEL, lirGenRes.getLIR(), "After PostAllocationOptimizationStage");
|
debug.dump(DebugContext.BASIC_LEVEL, lirGenRes.getLIR(), "After PostAllocationOptimizationStage");
|
||||||
|
|
||||||
return lirGenRes;
|
return lirGenRes;
|
||||||
}
|
}
|
||||||
|
@ -357,7 +359,8 @@ public class GraalCompiler {
|
||||||
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields,
|
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields,
|
||||||
int bytecodeSize, LIRGenerationResult lirGenRes,
|
int bytecodeSize, LIRGenerationResult lirGenRes,
|
||||||
CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
|
CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
|
||||||
try (DebugCloseable a = EmitCode.start()) {
|
DebugContext debug = lirGenRes.getLIR().getDebug();
|
||||||
|
try (DebugCloseable a = EmitCode.start(debug)) {
|
||||||
FrameMap frameMap = lirGenRes.getFrameMap();
|
FrameMap frameMap = lirGenRes.getFrameMap();
|
||||||
CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
|
CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
|
||||||
backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
|
backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
|
||||||
|
@ -370,12 +373,12 @@ public class GraalCompiler {
|
||||||
compilationResult.setBytecodeSize(bytecodeSize);
|
compilationResult.setBytecodeSize(bytecodeSize);
|
||||||
}
|
}
|
||||||
crb.finish();
|
crb.finish();
|
||||||
if (Debug.isCountEnabled()) {
|
if (debug.isCountEnabled()) {
|
||||||
List<DataPatch> ldp = compilationResult.getDataPatches();
|
List<DataPatch> ldp = compilationResult.getDataPatches();
|
||||||
JavaKind[] kindValues = JavaKind.values();
|
JavaKind[] kindValues = JavaKind.values();
|
||||||
DebugCounter[] dms = new DebugCounter[kindValues.length];
|
CounterKey[] dms = new CounterKey[kindValues.length];
|
||||||
for (int i = 0; i < dms.length; i++) {
|
for (int i = 0; i < dms.length; i++) {
|
||||||
dms[i] = Debug.counter("DataPatches-%s", kindValues[i]);
|
dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (DataPatch dp : ldp) {
|
for (DataPatch dp : ldp) {
|
||||||
|
@ -386,17 +389,17 @@ public class GraalCompiler {
|
||||||
kind = ((JavaConstant) constant).getJavaKind();
|
kind = ((JavaConstant) constant).getJavaKind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dms[kind.ordinal()].add(1);
|
dms[kind.ordinal()].add(debug, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.counter("CompilationResults").increment();
|
DebugContext.counter("CompilationResults").increment(debug);
|
||||||
Debug.counter("CodeBytesEmitted").add(compilationResult.getTargetCodeSize());
|
DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
|
||||||
Debug.counter("InfopointsEmitted").add(compilationResult.getInfopoints().size());
|
DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
|
||||||
Debug.counter("DataPatches").add(ldp.size());
|
DebugContext.counter("DataPatches").add(debug, ldp.size());
|
||||||
Debug.counter("ExceptionHandlersEmitted").add(compilationResult.getExceptionHandlers().size());
|
DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.dump(Debug.BASIC_LEVEL, compilationResult, "After code generation");
|
debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.core;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.Debug.Params;
|
|
||||||
import org.graalvm.compiler.debug.DebugInitializationParticipant;
|
|
||||||
import org.graalvm.compiler.debug.GraalDebugConfig;
|
|
||||||
import org.graalvm.compiler.debug.TTY;
|
|
||||||
import org.graalvm.compiler.debug.internal.method.MethodMetricsPrinter;
|
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
|
||||||
import org.graalvm.compiler.serviceprovider.ServiceProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A service provider that may modify the initialization of {@link Debug} based on the values
|
|
||||||
* specified for various {@link GraalDebugConfig} options.
|
|
||||||
*/
|
|
||||||
@ServiceProvider(DebugInitializationParticipant.class)
|
|
||||||
public class GraalDebugInitializationParticipant implements DebugInitializationParticipant {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(Params params) {
|
|
||||||
OptionValues options = params.getOptions();
|
|
||||||
if (GraalDebugConfig.areDebugScopePatternsEnabled(options)) {
|
|
||||||
params.enable = true;
|
|
||||||
}
|
|
||||||
if ("".equals(GraalDebugConfig.Options.Count.getValue(options))) {
|
|
||||||
params.enableUnscopedCounters = true;
|
|
||||||
}
|
|
||||||
if ("".equals(GraalDebugConfig.Options.MethodMeter.getValue(options))) {
|
|
||||||
params.enableUnscopedMethodMetrics = true;
|
|
||||||
// mm requires full debugging support
|
|
||||||
params.enable = true;
|
|
||||||
}
|
|
||||||
if ("".equals(GraalDebugConfig.Options.Time.getValue(options))) {
|
|
||||||
params.enableUnscopedTimers = true;
|
|
||||||
}
|
|
||||||
if ("".equals(GraalDebugConfig.Options.TrackMemUse.getValue(options))) {
|
|
||||||
params.enableUnscopedMemUseTrackers = true;
|
|
||||||
}
|
|
||||||
// unscoped counters/timers/mem use trackers/method metrics should respect method filter
|
|
||||||
// semantics
|
|
||||||
if (!params.enable && (params.enableUnscopedMemUseTrackers || params.enableUnscopedMethodMetrics || params.enableUnscopedCounters || params.enableUnscopedTimers) &&
|
|
||||||
GraalDebugConfig.isNotEmpty(GraalDebugConfig.Options.MethodFilter, options)) {
|
|
||||||
params.enable = true;
|
|
||||||
params.enableMethodFilter = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!params.enable && GraalDebugConfig.Options.DumpOnPhaseChange.getValue(options) != null) {
|
|
||||||
params.enable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!params.enableUnscopedMethodMetrics && GraalDebugConfig.Options.MethodMeter.getValue(options) != null) {
|
|
||||||
// mm requires full debugging support
|
|
||||||
params.enable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GraalDebugConfig.isGlobalMetricsInterceptedByMethodMetricsEnabled(options)) {
|
|
||||||
if (!params.enable) {
|
|
||||||
TTY.println("WARNING: MethodMeter is disabled but GlobalMetricsInterceptedByMethodMetrics is enabled. Ignoring MethodMeter and GlobalMetricsInterceptedByMethodMetrics.");
|
|
||||||
} else {
|
|
||||||
parseMethodMetricsDebugValueInterception(params, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (GraalDebugConfig.isNotEmpty(GraalDebugConfig.Options.MethodMeter, options) || params.enableUnscopedMethodMetrics) {
|
|
||||||
if (!MethodMetricsPrinter.methodMetricsDumpingEnabled(options)) {
|
|
||||||
TTY.println("WARNING: MethodMeter is enabled but MethodMeter dumping is disabled. Output will not contain MethodMetrics.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void parseMethodMetricsDebugValueInterception(Params params, OptionValues options) {
|
|
||||||
String interceptionGroup = GraalDebugConfig.Options.GlobalMetricsInterceptedByMethodMetrics.getValue(options);
|
|
||||||
boolean intercepted = false;
|
|
||||||
if (interceptionGroup.contains("Timers")) {
|
|
||||||
params.interceptTime = true;
|
|
||||||
intercepted = true;
|
|
||||||
}
|
|
||||||
if (interceptionGroup.contains("Counters")) {
|
|
||||||
params.interceptCount = true;
|
|
||||||
intercepted = true;
|
|
||||||
}
|
|
||||||
if (interceptionGroup.contains("MemUseTrackers")) {
|
|
||||||
params.interceptMem = true;
|
|
||||||
intercepted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!intercepted) {
|
|
||||||
TTY.println("WARNING: Ignoring GlobalMetricsInterceptedByMethodMetrics as the supplied argument does not contain Timers/Counters/MemUseTrackers.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,9 +26,10 @@ import java.util.List;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
import org.graalvm.compiler.core.common.cfg.BlockMap;
|
import org.graalvm.compiler.core.common.cfg.BlockMap;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
|
import org.graalvm.compiler.lir.LIR;
|
||||||
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
||||||
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
||||||
import org.graalvm.compiler.lir.phases.LIRPhase;
|
import org.graalvm.compiler.lir.phases.LIRPhase;
|
||||||
|
@ -56,8 +57,8 @@ public class LIRGenerationPhase extends LIRPhase<LIRGenerationPhase.LIRGeneratio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DebugCounter instructionCounter = Debug.counter("GeneratedLIRInstructions");
|
private static final CounterKey instructionCounter = DebugContext.counter("GeneratedLIRInstructions");
|
||||||
private static final DebugCounter nodeCount = Debug.counter("FinalNodeCount");
|
private static final CounterKey nodeCount = DebugContext.counter("FinalNodeCount");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void run(TargetDescription target, LIRGenerationResult lirGenRes, LIRGenerationPhase.LIRGenerationContext context) {
|
protected final void run(TargetDescription target, LIRGenerationResult lirGenRes, LIRGenerationPhase.LIRGenerationContext context) {
|
||||||
|
@ -69,18 +70,16 @@ public class LIRGenerationPhase extends LIRPhase<LIRGenerationPhase.LIRGeneratio
|
||||||
}
|
}
|
||||||
context.lirGen.beforeRegisterAllocation();
|
context.lirGen.beforeRegisterAllocation();
|
||||||
assert SSAUtil.verifySSAForm(lirGenRes.getLIR());
|
assert SSAUtil.verifySSAForm(lirGenRes.getLIR());
|
||||||
if (nodeCount.isEnabled()) {
|
nodeCount.add(graph.getDebug(), graph.getNodeCount());
|
||||||
nodeCount.add(graph.getNodeCount());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
|
private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
|
||||||
assert !isProcessed(lirGenRes, b) : "Block already processed " + b;
|
assert !isProcessed(lirGenRes, b) : "Block already processed " + b;
|
||||||
assert verifyPredecessors(lirGenRes, b);
|
assert verifyPredecessors(lirGenRes, b);
|
||||||
nodeLirGen.doBlock(b, graph, blockMap);
|
nodeLirGen.doBlock(b, graph, blockMap);
|
||||||
if (instructionCounter.isEnabled()) {
|
LIR lir = lirGenRes.getLIR();
|
||||||
instructionCounter.add(lirGenRes.getLIR().getLIRforBlock(b).size());
|
DebugContext debug = lir.getDebug();
|
||||||
}
|
instructionCounter.add(debug, lir.getLIRforBlock(b).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean verifyPredecessors(LIRGenerationResult lirGenRes, Block block) {
|
private static boolean verifyPredecessors(LIRGenerationResult lirGenRes, Block block) {
|
||||||
|
|
|
@ -26,8 +26,8 @@ import java.util.ArrayDeque;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.lir.ConstantValue;
|
import org.graalvm.compiler.lir.ConstantValue;
|
||||||
import org.graalvm.compiler.lir.LIRFrameState;
|
import org.graalvm.compiler.lir.LIRFrameState;
|
||||||
|
@ -42,8 +42,8 @@ import org.graalvm.compiler.nodes.virtual.EscapeObjectState;
|
||||||
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
||||||
import org.graalvm.compiler.virtual.nodes.MaterializedObjectState;
|
import org.graalvm.compiler.virtual.nodes.MaterializedObjectState;
|
||||||
import org.graalvm.compiler.virtual.nodes.VirtualObjectState;
|
import org.graalvm.compiler.virtual.nodes.VirtualObjectState;
|
||||||
import org.graalvm.util.Equivalence;
|
|
||||||
import org.graalvm.util.EconomicMap;
|
import org.graalvm.util.EconomicMap;
|
||||||
|
import org.graalvm.util.Equivalence;
|
||||||
|
|
||||||
import jdk.vm.ci.code.BytecodeFrame;
|
import jdk.vm.ci.code.BytecodeFrame;
|
||||||
import jdk.vm.ci.code.VirtualObject;
|
import jdk.vm.ci.code.VirtualObject;
|
||||||
|
@ -61,9 +61,11 @@ import jdk.vm.ci.meta.Value;
|
||||||
public class DebugInfoBuilder {
|
public class DebugInfoBuilder {
|
||||||
|
|
||||||
protected final NodeValueMap nodeValueMap;
|
protected final NodeValueMap nodeValueMap;
|
||||||
|
protected final DebugContext debug;
|
||||||
|
|
||||||
public DebugInfoBuilder(NodeValueMap nodeValueMap) {
|
public DebugInfoBuilder(NodeValueMap nodeValueMap, DebugContext debug) {
|
||||||
this.nodeValueMap = nodeValueMap;
|
this.nodeValueMap = nodeValueMap;
|
||||||
|
this.debug = debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final JavaValue[] NO_JAVA_VALUES = {};
|
private static final JavaValue[] NO_JAVA_VALUES = {};
|
||||||
|
@ -276,10 +278,10 @@ public class DebugInfoBuilder {
|
||||||
return toJavaValue(state.lockAt(i));
|
return toJavaValue(state.lockAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DebugCounter STATE_VIRTUAL_OBJECTS = Debug.counter("StateVirtualObjects");
|
private static final CounterKey STATE_VIRTUAL_OBJECTS = DebugContext.counter("StateVirtualObjects");
|
||||||
private static final DebugCounter STATE_ILLEGALS = Debug.counter("StateIllegals");
|
private static final CounterKey STATE_ILLEGALS = DebugContext.counter("StateIllegals");
|
||||||
private static final DebugCounter STATE_VARIABLES = Debug.counter("StateVariables");
|
private static final CounterKey STATE_VARIABLES = DebugContext.counter("StateVariables");
|
||||||
private static final DebugCounter STATE_CONSTANTS = Debug.counter("StateConstants");
|
private static final CounterKey STATE_CONSTANTS = DebugContext.counter("StateConstants");
|
||||||
|
|
||||||
private static JavaKind toSlotKind(ValueNode value) {
|
private static JavaKind toSlotKind(ValueNode value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -308,18 +310,18 @@ public class DebugInfoBuilder {
|
||||||
virtualObjects.put(obj, vobject);
|
virtualObjects.put(obj, vobject);
|
||||||
pendingVirtualObjects.add(obj);
|
pendingVirtualObjects.add(obj);
|
||||||
}
|
}
|
||||||
STATE_VIRTUAL_OBJECTS.increment();
|
STATE_VIRTUAL_OBJECTS.increment(debug);
|
||||||
return vobject;
|
return vobject;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remove proxies from constants so the constant can be directly embedded.
|
// Remove proxies from constants so the constant can be directly embedded.
|
||||||
ValueNode unproxied = GraphUtil.unproxify(value);
|
ValueNode unproxied = GraphUtil.unproxify(value);
|
||||||
if (unproxied instanceof ConstantNode) {
|
if (unproxied instanceof ConstantNode) {
|
||||||
STATE_CONSTANTS.increment();
|
STATE_CONSTANTS.increment(debug);
|
||||||
return unproxied.asJavaConstant();
|
return unproxied.asJavaConstant();
|
||||||
|
|
||||||
} else if (value != null) {
|
} else if (value != null) {
|
||||||
STATE_VARIABLES.increment();
|
STATE_VARIABLES.increment(debug);
|
||||||
Value operand = nodeValueMap.operand(value);
|
Value operand = nodeValueMap.operand(value);
|
||||||
if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
|
if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
|
||||||
return ((ConstantValue) operand).getJavaConstant();
|
return ((ConstantValue) operand).getJavaConstant();
|
||||||
|
@ -330,7 +332,7 @@ public class DebugInfoBuilder {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// return a dummy value because real value not needed
|
// return a dummy value because real value not needed
|
||||||
STATE_ILLEGALS.increment();
|
STATE_ILLEGALS.increment(debug);
|
||||||
return Value.ILLEGAL;
|
return Value.ILLEGAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,13 @@ import static jdk.vm.ci.code.ValueUtil.asRegister;
|
||||||
import static jdk.vm.ci.code.ValueUtil.isLegal;
|
import static jdk.vm.ci.code.ValueUtil.isLegal;
|
||||||
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
import static jdk.vm.ci.code.ValueUtil.isRegister;
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.MatchExpressions;
|
import static org.graalvm.compiler.core.common.GraalOptions.MatchExpressions;
|
||||||
import static org.graalvm.compiler.debug.GraalDebugConfig.Options.LogVerbose;
|
import static org.graalvm.compiler.debug.DebugOptions.LogVerbose;
|
||||||
import static org.graalvm.compiler.lir.LIR.verifyBlock;
|
import static org.graalvm.compiler.lir.LIR.verifyBlock;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.common.LIRKind;
|
import org.graalvm.compiler.core.common.LIRKind;
|
||||||
import org.graalvm.compiler.core.common.calc.Condition;
|
import org.graalvm.compiler.core.common.calc.Condition;
|
||||||
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
|
||||||
|
@ -41,8 +42,7 @@ import org.graalvm.compiler.core.match.ComplexMatchValue;
|
||||||
import org.graalvm.compiler.core.match.MatchPattern;
|
import org.graalvm.compiler.core.match.MatchPattern;
|
||||||
import org.graalvm.compiler.core.match.MatchRuleRegistry;
|
import org.graalvm.compiler.core.match.MatchRuleRegistry;
|
||||||
import org.graalvm.compiler.core.match.MatchStatement;
|
import org.graalvm.compiler.core.match.MatchStatement;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.debug.TTY;
|
import org.graalvm.compiler.debug.TTY;
|
||||||
import org.graalvm.compiler.graph.GraalGraphError;
|
import org.graalvm.compiler.graph.GraalGraphError;
|
||||||
|
@ -135,7 +135,7 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
this.debugInfoBuilder = createDebugInfoBuilder(graph, this);
|
this.debugInfoBuilder = createDebugInfoBuilder(graph, this);
|
||||||
OptionValues options = graph.getOptions();
|
OptionValues options = graph.getOptions();
|
||||||
if (MatchExpressions.getValue(options)) {
|
if (MatchExpressions.getValue(options)) {
|
||||||
matchRules = MatchRuleRegistry.lookup(nodeMatchRules.getClass(), options);
|
matchRules = MatchRuleRegistry.lookup(nodeMatchRules.getClass(), options, graph.getDebug());
|
||||||
}
|
}
|
||||||
traceLIRGeneratorLevel = TTY.isSuppressed() ? 0 : Options.TraceLIRGeneratorLevel.getValue(options);
|
traceLIRGeneratorLevel = TTY.isSuppressed() ? 0 : Options.TraceLIRGeneratorLevel.getValue(options);
|
||||||
|
|
||||||
|
@ -147,9 +147,8 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
return nodeMatchRules;
|
return nodeMatchRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unused"})
|
|
||||||
protected DebugInfoBuilder createDebugInfoBuilder(StructuredGraph graph, NodeValueMap nodeValueMap) {
|
protected DebugInfoBuilder createDebugInfoBuilder(StructuredGraph graph, NodeValueMap nodeValueMap) {
|
||||||
return new DebugInfoBuilder(nodeValueMap);
|
return new DebugInfoBuilder(nodeValueMap, graph.getDebug());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,6 +350,7 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
for (int i = 0; i < nodes.size(); i++) {
|
for (int i = 0; i < nodes.size(); i++) {
|
||||||
Node node = nodes.get(i);
|
Node node = nodes.get(i);
|
||||||
if (node instanceof ValueNode) {
|
if (node instanceof ValueNode) {
|
||||||
|
DebugContext debug = node.getDebug();
|
||||||
ValueNode valueNode = (ValueNode) node;
|
ValueNode valueNode = (ValueNode) node;
|
||||||
if (trace) {
|
if (trace) {
|
||||||
TTY.println("LIRGen for " + valueNode);
|
TTY.println("LIRGen for " + valueNode);
|
||||||
|
@ -368,9 +368,9 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
}
|
}
|
||||||
} else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
|
} else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
|
||||||
// Doesn't need to be evaluated
|
// Doesn't need to be evaluated
|
||||||
Debug.log("interior match for %s", valueNode);
|
debug.log("interior match for %s", valueNode);
|
||||||
} else if (operand instanceof ComplexMatchValue) {
|
} else if (operand instanceof ComplexMatchValue) {
|
||||||
Debug.log("complex match for %s", valueNode);
|
debug.log("complex match for %s", valueNode);
|
||||||
ComplexMatchValue match = (ComplexMatchValue) operand;
|
ComplexMatchValue match = (ComplexMatchValue) operand;
|
||||||
operand = match.evaluate(this);
|
operand = match.evaluate(this);
|
||||||
if (operand != null) {
|
if (operand != null) {
|
||||||
|
@ -403,11 +403,12 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
protected void matchComplexExpressions(List<Node> nodes) {
|
protected void matchComplexExpressions(List<Node> nodes) {
|
||||||
if (matchRules != null) {
|
if (matchRules != null) {
|
||||||
try (Scope s = Debug.scope("MatchComplexExpressions")) {
|
DebugContext debug = gen.getResult().getLIR().getDebug();
|
||||||
|
try (DebugContext.Scope s = debug.scope("MatchComplexExpressions")) {
|
||||||
if (LogVerbose.getValue(nodeOperands.graph().getOptions())) {
|
if (LogVerbose.getValue(nodeOperands.graph().getOptions())) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
Debug.log("%d: (%s) %1S", i++, node.getUsageCount(), node);
|
debug.log("%d: (%s) %1S", i++, node.getUsageCount(), node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,15 +440,15 @@ public abstract class NodeLIRBuilder implements NodeLIRBuilderTool, LIRGeneratio
|
||||||
TTY.println("Emitting LIR for instruction " + instr);
|
TTY.println("Emitting LIR for instruction " + instr);
|
||||||
}
|
}
|
||||||
currentInstruction = instr;
|
currentInstruction = instr;
|
||||||
|
DebugContext debug = instr.getDebug();
|
||||||
Debug.log("Visiting %s", instr);
|
debug.log("Visiting %s", instr);
|
||||||
emitNode(instr);
|
emitNode(instr);
|
||||||
Debug.log("Operand for %s = %s", instr, getOperand(instr));
|
debug.log("Operand for %s = %s", instr, getOperand(instr));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void emitNode(ValueNode node) {
|
protected void emitNode(ValueNode node) {
|
||||||
if (Debug.isLogEnabled() && node.stamp().isEmpty()) {
|
if (node.getDebug().isLogEnabled() && node.stamp().isEmpty()) {
|
||||||
Debug.log("This node has an empty stamp, we are emitting dead code(?): %s", node);
|
node.getDebug().log("This node has an empty stamp, we are emitting dead code(?): %s", node);
|
||||||
}
|
}
|
||||||
setSourcePosition(node.getNodeSourcePosition());
|
setSourcePosition(node.getNodeSourcePosition());
|
||||||
if (node instanceof LIRLowerable) {
|
if (node instanceof LIRLowerable) {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.match;
|
package org.graalvm.compiler.core.match;
|
||||||
|
|
||||||
import static org.graalvm.compiler.debug.GraalDebugConfig.Options.LogVerbose;
|
import static org.graalvm.compiler.debug.DebugOptions.LogVerbose;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -30,13 +30,13 @@ import java.util.List;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
||||||
import org.graalvm.compiler.core.match.MatchPattern.Result;
|
import org.graalvm.compiler.core.match.MatchPattern.Result;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodes.calc.FloatingNode;
|
import org.graalvm.compiler.nodes.calc.FloatingNode;
|
||||||
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
|
||||||
import org.graalvm.util.Equivalence;
|
|
||||||
import org.graalvm.util.EconomicMap;
|
import org.graalvm.util.EconomicMap;
|
||||||
|
import org.graalvm.util.Equivalence;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for state captured during a match.
|
* Container for state captured during a match.
|
||||||
|
@ -110,10 +110,11 @@ public class MatchContext {
|
||||||
continue;
|
continue;
|
||||||
} else if ((consumed == null || !consumed.contains(node)) && node != root) {
|
} else if ((consumed == null || !consumed.contains(node)) && node != root) {
|
||||||
if (LogVerbose.getValue(root.getOptions())) {
|
if (LogVerbose.getValue(root.getOptions())) {
|
||||||
Debug.log("unexpected node %s", node);
|
DebugContext debug = root.getDebug();
|
||||||
|
debug.log("unexpected node %s", node);
|
||||||
for (int j = startIndex; j <= endIndex; j++) {
|
for (int j = startIndex; j <= endIndex; j++) {
|
||||||
Node theNode = nodes.get(j);
|
Node theNode = nodes.get(j);
|
||||||
Debug.log("%s(%s) %1s", (consumed != null && consumed.contains(theNode) || theNode == root) ? "*" : " ", theNode.getUsageCount(), theNode);
|
debug.log("%s(%s) %1s", (consumed != null && consumed.contains(theNode) || theNode == root) ? "*" : " ", theNode.getUsageCount(), theNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result.notSafe(node, rule.getPattern());
|
return Result.notSafe(node, rule.getPattern());
|
||||||
|
@ -130,9 +131,10 @@ public class MatchContext {
|
||||||
*/
|
*/
|
||||||
public void setResult(ComplexMatchResult result) {
|
public void setResult(ComplexMatchResult result) {
|
||||||
ComplexMatchValue value = new ComplexMatchValue(result);
|
ComplexMatchValue value = new ComplexMatchValue(result);
|
||||||
if (Debug.isLogEnabled()) {
|
DebugContext debug = root.getDebug();
|
||||||
Debug.log("matched %s %s", rule.getName(), rule.getPattern());
|
if (debug.isLogEnabled()) {
|
||||||
Debug.log("with nodes %s", rule.formatMatch(root));
|
debug.log("matched %s %s", rule.getName(), rule.getPattern());
|
||||||
|
debug.log("with nodes %s", rule.formatMatch(root));
|
||||||
}
|
}
|
||||||
if (consumed != null) {
|
if (consumed != null) {
|
||||||
for (Node node : consumed) {
|
for (Node node : consumed) {
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.match;
|
package org.graalvm.compiler.core.match;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.graph.Position;
|
import org.graalvm.compiler.graph.Position;
|
||||||
import org.graalvm.compiler.nodeinfo.InputType;
|
import org.graalvm.compiler.nodeinfo.InputType;
|
||||||
|
@ -62,12 +62,12 @@ public class MatchPattern {
|
||||||
this.matcher = matcher;
|
this.matcher = matcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DebugCounter MatchResult_WRONG_CLASS = Debug.counter("MatchResult_WRONG_CLASS");
|
private static final CounterKey MatchResult_WRONG_CLASS = DebugContext.counter("MatchResult_WRONG_CLASS");
|
||||||
private static final DebugCounter MatchResult_NAMED_VALUE_MISMATCH = Debug.counter("MatchResult_NAMED_VALUE_MISMATCH");
|
private static final CounterKey MatchResult_NAMED_VALUE_MISMATCH = DebugContext.counter("MatchResult_NAMED_VALUE_MISMATCH");
|
||||||
private static final DebugCounter MatchResult_TOO_MANY_USERS = Debug.counter("MatchResult_TOO_MANY_USERS");
|
private static final CounterKey MatchResult_TOO_MANY_USERS = DebugContext.counter("MatchResult_TOO_MANY_USERS");
|
||||||
private static final DebugCounter MatchResult_NOT_IN_BLOCK = Debug.counter("MatchResult_NOT_IN_BLOCK");
|
private static final CounterKey MatchResult_NOT_IN_BLOCK = DebugContext.counter("MatchResult_NOT_IN_BLOCK");
|
||||||
private static final DebugCounter MatchResult_NOT_SAFE = Debug.counter("MatchResult_NOT_SAFE");
|
private static final CounterKey MatchResult_NOT_SAFE = DebugContext.counter("MatchResult_NOT_SAFE");
|
||||||
private static final DebugCounter MatchResult_ALREADY_USED = Debug.counter("MatchResult_ALREADY_USED");
|
private static final CounterKey MatchResult_ALREADY_USED = DebugContext.counter("MatchResult_ALREADY_USED");
|
||||||
|
|
||||||
static final Result OK = new Result(MatchResultCode.OK, null, null);
|
static final Result OK = new Result(MatchResultCode.OK, null, null);
|
||||||
private static final Result CACHED_WRONG_CLASS = new Result(MatchResultCode.WRONG_CLASS, null, null);
|
private static final Result CACHED_WRONG_CLASS = new Result(MatchResultCode.WRONG_CLASS, null, null);
|
||||||
|
@ -78,33 +78,33 @@ public class MatchPattern {
|
||||||
private static final Result CACHED_ALREADY_USED = new Result(MatchResultCode.ALREADY_USED, null, null);
|
private static final Result CACHED_ALREADY_USED = new Result(MatchResultCode.ALREADY_USED, null, null);
|
||||||
|
|
||||||
static Result wrongClass(Node node, MatchPattern matcher) {
|
static Result wrongClass(Node node, MatchPattern matcher) {
|
||||||
MatchResult_WRONG_CLASS.increment();
|
MatchResult_WRONG_CLASS.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result namedValueMismatch(Node node, MatchPattern matcher) {
|
static Result namedValueMismatch(Node node, MatchPattern matcher) {
|
||||||
MatchResult_NAMED_VALUE_MISMATCH.increment();
|
MatchResult_NAMED_VALUE_MISMATCH.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result tooManyUsers(Node node, MatchPattern matcher) {
|
static Result tooManyUsers(Node node, MatchPattern matcher) {
|
||||||
MatchResult_TOO_MANY_USERS.increment();
|
MatchResult_TOO_MANY_USERS.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result notInBlock(Node node, MatchPattern matcher) {
|
static Result notInBlock(Node node, MatchPattern matcher) {
|
||||||
MatchResult_NOT_IN_BLOCK.increment();
|
MatchResult_NOT_IN_BLOCK.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result notSafe(Node node, MatchPattern matcher) {
|
static Result notSafe(Node node, MatchPattern matcher) {
|
||||||
MatchResult_NOT_SAFE.increment();
|
MatchResult_NOT_SAFE.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result alreadyUsed(Node node, MatchPattern matcher) {
|
static Result alreadyUsed(Node node, MatchPattern matcher) {
|
||||||
MatchResult_ALREADY_USED.increment();
|
MatchResult_ALREADY_USED.increment(node.getDebug());
|
||||||
return Debug.isLogEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED;
|
return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,13 +22,13 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.match;
|
package org.graalvm.compiler.core.match;
|
||||||
|
|
||||||
import static org.graalvm.compiler.debug.GraalDebugConfig.Options.LogVerbose;
|
import static org.graalvm.compiler.debug.DebugOptions.LogVerbose;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.graalvm.compiler.core.gen.NodeMatchRules;
|
import org.graalvm.compiler.core.gen.NodeMatchRules;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.debug.GraalError;
|
import org.graalvm.compiler.debug.GraalError;
|
||||||
import org.graalvm.compiler.graph.Edges;
|
import org.graalvm.compiler.graph.Edges;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
|
@ -36,8 +36,8 @@ import org.graalvm.compiler.graph.NodeClass;
|
||||||
import org.graalvm.compiler.graph.Position;
|
import org.graalvm.compiler.graph.Position;
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.compiler.serviceprovider.GraalServices;
|
import org.graalvm.compiler.serviceprovider.GraalServices;
|
||||||
import org.graalvm.util.Equivalence;
|
|
||||||
import org.graalvm.util.EconomicMap;
|
import org.graalvm.util.EconomicMap;
|
||||||
|
import org.graalvm.util.Equivalence;
|
||||||
import org.graalvm.util.MapCursor;
|
import org.graalvm.util.MapCursor;
|
||||||
|
|
||||||
public class MatchRuleRegistry {
|
public class MatchRuleRegistry {
|
||||||
|
@ -77,7 +77,7 @@ public class MatchRuleRegistry {
|
||||||
* @return the set of {@link MatchStatement}s applicable to theClass.
|
* @return the set of {@link MatchStatement}s applicable to theClass.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public static synchronized EconomicMap<Class<? extends Node>, List<MatchStatement>> lookup(Class<? extends NodeMatchRules> theClass, OptionValues options) {
|
public static synchronized EconomicMap<Class<? extends Node>, List<MatchStatement>> lookup(Class<? extends NodeMatchRules> theClass, OptionValues options, DebugContext debug) {
|
||||||
EconomicMap<Class<? extends Node>, List<MatchStatement>> result = registry.get(theClass);
|
EconomicMap<Class<? extends Node>, List<MatchStatement>> result = registry.get(theClass);
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
@ -87,13 +87,13 @@ public class MatchRuleRegistry {
|
||||||
result = rules;
|
result = rules;
|
||||||
|
|
||||||
if (LogVerbose.getValue(options)) {
|
if (LogVerbose.getValue(options)) {
|
||||||
try (Scope s = Debug.scope("MatchComplexExpressions")) {
|
try (DebugContext.Scope s = debug.scope("MatchComplexExpressions")) {
|
||||||
Debug.log("Match rules for %s", theClass.getSimpleName());
|
debug.log("Match rules for %s", theClass.getSimpleName());
|
||||||
MapCursor<Class<? extends Node>, List<MatchStatement>> cursor = result.getEntries();
|
MapCursor<Class<? extends Node>, List<MatchStatement>> cursor = result.getEntries();
|
||||||
while (cursor.advance()) {
|
while (cursor.advance()) {
|
||||||
Debug.log(" For node class: %s", cursor.getKey());
|
debug.log(" For node class: %s", cursor.getKey());
|
||||||
for (MatchStatement statement : cursor.getValue()) {
|
for (MatchStatement statement : cursor.getValue()) {
|
||||||
Debug.log(" %s", statement.getPattern());
|
debug.log(" %s", statement.getPattern());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,28 +22,28 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.match;
|
package org.graalvm.compiler.core.match;
|
||||||
|
|
||||||
import static org.graalvm.compiler.debug.GraalDebugConfig.Options.LogVerbose;
|
import static org.graalvm.compiler.debug.DebugOptions.LogVerbose;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.Value;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
import org.graalvm.compiler.core.gen.NodeLIRBuilder;
|
||||||
import org.graalvm.compiler.core.match.MatchPattern.MatchResultCode;
|
import org.graalvm.compiler.core.match.MatchPattern.MatchResultCode;
|
||||||
import org.graalvm.compiler.core.match.MatchPattern.Result;
|
import org.graalvm.compiler.core.match.MatchPattern.Result;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
import org.graalvm.compiler.debug.DebugCounter;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.graph.GraalGraphError;
|
import org.graalvm.compiler.graph.GraalGraphError;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
import org.graalvm.compiler.nodeinfo.Verbosity;
|
import org.graalvm.compiler.nodeinfo.Verbosity;
|
||||||
|
|
||||||
|
import jdk.vm.ci.meta.Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A named {@link MatchPattern} along with a {@link MatchGenerator} that can be evaluated to replace
|
* A named {@link MatchPattern} along with a {@link MatchGenerator} that can be evaluated to replace
|
||||||
* one or more {@link Node}s with a single {@link Value}.
|
* one or more {@link Node}s with a single {@link Value}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MatchStatement {
|
public class MatchStatement {
|
||||||
private static final DebugCounter MatchStatementSuccess = Debug.counter("MatchStatementSuccess");
|
private static final CounterKey MatchStatementSuccess = DebugContext.counter("MatchStatementSuccess");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A printable name for this statement. Usually it's just the name of the method doing the
|
* A printable name for this statement. Usually it's just the name of the method doing the
|
||||||
|
@ -83,6 +83,7 @@ public class MatchStatement {
|
||||||
* evaluated by the NodeLIRBuilder.
|
* evaluated by the NodeLIRBuilder.
|
||||||
*/
|
*/
|
||||||
public boolean generate(NodeLIRBuilder builder, int index, Node node, List<Node> nodes) {
|
public boolean generate(NodeLIRBuilder builder, int index, Node node, List<Node> nodes) {
|
||||||
|
DebugContext debug = node.getDebug();
|
||||||
assert index == nodes.indexOf(node);
|
assert index == nodes.indexOf(node);
|
||||||
// Check that the basic shape matches
|
// Check that the basic shape matches
|
||||||
Result result = pattern.matchShape(node, this);
|
Result result = pattern.matchShape(node, this);
|
||||||
|
@ -97,19 +98,19 @@ public class MatchStatement {
|
||||||
ComplexMatchResult value = generatorMethod.match(builder.getNodeMatchRules(), buildArgList(context));
|
ComplexMatchResult value = generatorMethod.match(builder.getNodeMatchRules(), buildArgList(context));
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
context.setResult(value);
|
context.setResult(value);
|
||||||
MatchStatementSuccess.increment();
|
MatchStatementSuccess.increment(debug);
|
||||||
Debug.counter("MatchStatement[%s]", getName()).increment();
|
DebugContext.counter("MatchStatement[%s]", getName()).increment(debug);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// The pattern matched but some other code generation constraint disallowed code
|
// The pattern matched but some other code generation constraint disallowed code
|
||||||
// generation for the pattern.
|
// generation for the pattern.
|
||||||
if (LogVerbose.getValue(node.getOptions())) {
|
if (LogVerbose.getValue(node.getOptions())) {
|
||||||
Debug.log("while matching %s|%s %s %s returned null", context.getRoot().toString(Verbosity.Id), context.getRoot().getClass().getSimpleName(), getName(), generatorMethod.getName());
|
debug.log("while matching %s|%s %s %s returned null", context.getRoot().toString(Verbosity.Id), context.getRoot().getClass().getSimpleName(), getName(), generatorMethod.getName());
|
||||||
Debug.log("with nodes %s", formatMatch(node));
|
debug.log("with nodes %s", formatMatch(node));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (LogVerbose.getValue(node.getOptions()) && result.code != MatchResultCode.WRONG_CLASS) {
|
if (LogVerbose.getValue(node.getOptions()) && result.code != MatchResultCode.WRONG_CLASS) {
|
||||||
Debug.log("while matching %s|%s %s %s", context.getRoot().toString(Verbosity.Id), context.getRoot().getClass().getSimpleName(), getName(), result);
|
debug.log("while matching %s|%s %s %s", context.getRoot().toString(Verbosity.Id), context.getRoot().getClass().getSimpleName(), getName(), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class EconomyCompilerConfiguration implements CompilerConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIRPhaseSuite<AllocationContext> createAllocationStage(OptionValues options) {
|
public LIRPhaseSuite<AllocationContext> createAllocationStage(OptionValues options) {
|
||||||
return new EconomyAllocationStage();
|
return new EconomyAllocationStage(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.phases;
|
package org.graalvm.compiler.core.phases;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.graph.Graph.NodeEvent;
|
import org.graalvm.compiler.graph.Graph.NodeEvent;
|
||||||
import org.graalvm.compiler.graph.Graph.NodeEventScope;
|
import org.graalvm.compiler.graph.Graph.NodeEventScope;
|
||||||
import org.graalvm.compiler.graph.Node;
|
import org.graalvm.compiler.graph.Node;
|
||||||
|
@ -33,8 +32,8 @@ import org.graalvm.compiler.phases.BasePhase;
|
||||||
import org.graalvm.compiler.phases.PhaseSuite;
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
import org.graalvm.compiler.phases.common.util.HashSetNodeEventListener;
|
import org.graalvm.compiler.phases.common.util.HashSetNodeEventListener;
|
||||||
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
import org.graalvm.compiler.phases.tiers.PhaseContext;
|
||||||
import org.graalvm.util.Equivalence;
|
|
||||||
import org.graalvm.util.EconomicSet;
|
import org.graalvm.util.EconomicSet;
|
||||||
|
import org.graalvm.util.Equivalence;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility phase for detecting when a phase would change the graph and reporting extra information
|
* A utility phase for detecting when a phase would change the graph and reporting extra information
|
||||||
|
@ -68,12 +67,13 @@ public class GraphChangeMonitoringPhase<C extends PhaseContext> extends PhaseSui
|
||||||
* having their inputs change are the main interesting differences.
|
* having their inputs change are the main interesting differences.
|
||||||
*/
|
*/
|
||||||
HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
|
HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
|
||||||
StructuredGraph graphCopy = (StructuredGraph) graph.copy();
|
StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug());
|
||||||
|
DebugContext debug = graph.getDebug();
|
||||||
try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
|
try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
|
||||||
try (Scope s2 = Debug.sandbox("WithoutMonitoring", null)) {
|
try (DebugContext.Scope s2 = debug.sandbox("WithoutMonitoring", null)) {
|
||||||
super.run(graphCopy, context);
|
super.run(graphCopy, context);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Debug.handle(t);
|
debug.handle(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +90,15 @@ public class GraphChangeMonitoringPhase<C extends PhaseContext> extends PhaseSui
|
||||||
/* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
|
/* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
|
||||||
listener = new HashSetNodeEventListener();
|
listener = new HashSetNodeEventListener();
|
||||||
try (NodeEventScope s = graph.trackNodeEvents(listener)) {
|
try (NodeEventScope s = graph.trackNodeEvents(listener)) {
|
||||||
try (Scope s2 = Debug.scope("WithGraphChangeMonitoring")) {
|
try (DebugContext.Scope s2 = debug.scope("WithGraphChangeMonitoring")) {
|
||||||
if (Debug.isDumpEnabled(Debug.DETAILED_LEVEL)) {
|
if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
|
||||||
Debug.dump(Debug.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
|
debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
|
||||||
}
|
}
|
||||||
super.run(graph, context);
|
super.run(graph, context);
|
||||||
if (Debug.isDumpEnabled(Debug.DETAILED_LEVEL)) {
|
if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
|
||||||
Debug.dump(Debug.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
|
debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
|
||||||
}
|
}
|
||||||
Debug.log("*** %s %s %s\n", message, graph, filteredNodes);
|
debug.log("*** %s %s %s\n", message, graph, filteredNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,9 +26,14 @@ import static org.graalvm.compiler.core.common.GraalOptions.ConditionalEliminati
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
|
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.OptDeoptimizationGrouping;
|
import static org.graalvm.compiler.core.common.GraalOptions.OptDeoptimizationGrouping;
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.OptFloatingReads;
|
import static org.graalvm.compiler.core.common.GraalOptions.OptFloatingReads;
|
||||||
|
import static org.graalvm.compiler.core.common.GraalOptions.OptLoopTransform;
|
||||||
|
import static org.graalvm.compiler.core.common.GraalOptions.PartialUnroll;
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.ReassociateInvariants;
|
import static org.graalvm.compiler.core.common.GraalOptions.ReassociateInvariants;
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.VerifyHeapAtReturn;
|
import static org.graalvm.compiler.core.common.GraalOptions.VerifyHeapAtReturn;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
||||||
|
import org.graalvm.compiler.loop.LoopPolicies;
|
||||||
|
import org.graalvm.compiler.loop.phases.LoopPartialUnrollPhase;
|
||||||
import org.graalvm.compiler.loop.phases.LoopSafepointEliminationPhase;
|
import org.graalvm.compiler.loop.phases.LoopSafepointEliminationPhase;
|
||||||
import org.graalvm.compiler.loop.phases.ReassociateInvariantPhase;
|
import org.graalvm.compiler.loop.phases.ReassociateInvariantPhase;
|
||||||
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
||||||
|
@ -79,6 +84,12 @@ public class MidTier extends PhaseSuite<MidTierContext> {
|
||||||
|
|
||||||
appendPhase(new FrameStateAssignmentPhase());
|
appendPhase(new FrameStateAssignmentPhase());
|
||||||
|
|
||||||
|
LoopPolicies loopPolicies = createLoopPolicies();
|
||||||
|
if (OptLoopTransform.getValue(options)) {
|
||||||
|
if (PartialUnroll.getValue(options)) {
|
||||||
|
appendPhase(new LoopPartialUnrollPhase(loopPolicies, canonicalizer));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ReassociateInvariants.getValue(options)) {
|
if (ReassociateInvariants.getValue(options)) {
|
||||||
appendPhase(new ReassociateInvariantPhase());
|
appendPhase(new ReassociateInvariantPhase());
|
||||||
}
|
}
|
||||||
|
@ -89,4 +100,8 @@ public class MidTier extends PhaseSuite<MidTierContext> {
|
||||||
|
|
||||||
appendPhase(canonicalizer);
|
appendPhase(canonicalizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoopPolicies createLoopPolicies() {
|
||||||
|
return new DefaultLoopPolicies();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.core.target;
|
package org.graalvm.compiler.core.target;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.graalvm.compiler.asm.Assembler;
|
import org.graalvm.compiler.asm.Assembler;
|
||||||
import org.graalvm.compiler.code.CompilationResult;
|
import org.graalvm.compiler.code.CompilationResult;
|
||||||
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
||||||
|
@ -29,8 +31,7 @@ import org.graalvm.compiler.core.common.LIRKind;
|
||||||
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
|
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
|
||||||
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
||||||
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
|
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
|
||||||
import org.graalvm.compiler.debug.Debug;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.Debug.Scope;
|
|
||||||
import org.graalvm.compiler.lir.LIR;
|
import org.graalvm.compiler.lir.LIR;
|
||||||
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
||||||
import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
|
import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
|
||||||
|
@ -60,8 +61,6 @@ import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
||||||
import jdk.vm.ci.meta.SpeculationLog;
|
import jdk.vm.ci.meta.SpeculationLog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a compiler backend for Graal.
|
* Represents a compiler backend for Graal.
|
||||||
*/
|
*/
|
||||||
|
@ -155,22 +154,22 @@ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKin
|
||||||
protected abstract CompiledCode createCompiledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult);
|
protected abstract CompiledCode createCompiledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #createInstalledCode(ResolvedJavaMethod, CompilationRequest, CompilationResult,
|
* @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
|
||||||
* SpeculationLog, InstalledCode, boolean)
|
* CompilationResult, SpeculationLog, InstalledCode, boolean, Object[])
|
||||||
*/
|
*/
|
||||||
public InstalledCode createInstalledCode(ResolvedJavaMethod method, CompilationResult compilationResult,
|
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult,
|
||||||
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
|
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
|
||||||
return createInstalledCode(method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault);
|
return createInstalledCode(debug, method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #createInstalledCode(ResolvedJavaMethod, CompilationRequest, CompilationResult,
|
* @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
|
||||||
* SpeculationLog, InstalledCode, boolean, Object[])
|
* CompilationResult, SpeculationLog, InstalledCode, boolean, Object[])
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public InstalledCode createInstalledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
|
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
|
||||||
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
|
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
|
||||||
return createInstalledCode(method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
|
return createInstalledCode(debug, method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,19 +187,20 @@ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKin
|
||||||
* {@code compRequest.getMethod()}. The default implementation for a method is the
|
* {@code compRequest.getMethod()}. The default implementation for a method is the
|
||||||
* code executed for standard calls to the method. This argument is ignored if
|
* code executed for standard calls to the method. This argument is ignored if
|
||||||
* {@code compRequest == null}.
|
* {@code compRequest == null}.
|
||||||
* @param context a custom debug context to use for the code installation.
|
* @param context a custom debug context to use for the code installation
|
||||||
* @return a reference to the compiled and ready-to-run installed code
|
* @return a reference to the compiled and ready-to-run installed code
|
||||||
* @throws BailoutException if the code installation failed
|
* @throws BailoutException if the code installation failed
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public InstalledCode createInstalledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
|
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
|
||||||
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
|
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
|
||||||
Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult};
|
Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult};
|
||||||
CodeInstallationTask[] tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
|
CodeInstallationTask[] tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
|
||||||
for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
|
for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
|
||||||
tasks[i] = codeInstallationTaskFactories.get(i).create();
|
tasks[i] = codeInstallationTaskFactories.get(i).create();
|
||||||
}
|
}
|
||||||
try (Scope s = Debug.scope("CodeInstall", debugContext)) {
|
try (DebugContext.Scope s2 = debug.scope("CodeInstall", debugContext);
|
||||||
|
DebugContext.Activation a = debug.activate()) {
|
||||||
for (CodeInstallationTask task : tasks) {
|
for (CodeInstallationTask task : tasks) {
|
||||||
task.preProcess(compilationResult);
|
task.preProcess(compilationResult);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKin
|
||||||
}
|
}
|
||||||
return installedCode;
|
return installedCode;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw Debug.handle(e);
|
throw debug.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +236,8 @@ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKin
|
||||||
* @return a reference to the compiled and ready-to-run installed code
|
* @return a reference to the compiled and ready-to-run installed code
|
||||||
* @throws BailoutException if the code installation failed
|
* @throws BailoutException if the code installation failed
|
||||||
*/
|
*/
|
||||||
public InstalledCode addInstalledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) {
|
public InstalledCode addInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) {
|
||||||
return createInstalledCode(method, compilationRequest, compilationResult, null, null, false);
|
return createInstalledCode(debug, method, compilationRequest, compilationResult, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -250,8 +250,8 @@ public abstract class Backend implements TargetProvider, ValueKindFactory<LIRKin
|
||||||
* @return a reference to the compiled and ready-to-run installed code
|
* @return a reference to the compiled and ready-to-run installed code
|
||||||
* @throws BailoutException if the code installation failed
|
* @throws BailoutException if the code installation failed
|
||||||
*/
|
*/
|
||||||
public InstalledCode createDefaultInstalledCode(ResolvedJavaMethod method, CompilationResult compilationResult) {
|
public InstalledCode createDefaultInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult) {
|
||||||
return createInstalledCode(method, compilationResult, null, null, true);
|
return createInstalledCode(debug, method, compilationResult, null, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,281 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2013, 2015, 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.
|
||||||
|
*
|
||||||
|
* 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 org.graalvm.compiler.debug.test;
|
||||||
|
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Formatter;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.graalvm.compiler.debug.Assertions;
|
||||||
|
import org.graalvm.compiler.debug.CounterKey;
|
||||||
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
|
import org.graalvm.compiler.debug.DebugContext.Scope;
|
||||||
|
import org.graalvm.compiler.debug.DebugDumpHandler;
|
||||||
|
import org.graalvm.compiler.debug.DebugHandler;
|
||||||
|
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
||||||
|
import org.graalvm.compiler.debug.DebugOptions;
|
||||||
|
import org.graalvm.compiler.debug.DebugVerifyHandler;
|
||||||
|
import org.graalvm.compiler.options.OptionKey;
|
||||||
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
|
import org.graalvm.util.EconomicMap;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("try")
|
||||||
|
public class DebugContextTest {
|
||||||
|
|
||||||
|
static class DebugContextSetup {
|
||||||
|
final Formatter dumpOutput = new Formatter();
|
||||||
|
final Formatter verifyOutput = new Formatter();
|
||||||
|
final ByteArrayOutputStream logOutput = new ByteArrayOutputStream();
|
||||||
|
DebugHandlersFactory handlers = new DebugHandlersFactory() {
|
||||||
|
@Override
|
||||||
|
public List<DebugHandler> createHandlers(OptionValues options) {
|
||||||
|
return Arrays.asList(new DebugDumpHandler() {
|
||||||
|
@Override
|
||||||
|
public void dump(DebugContext ignore, Object object, String format, Object... arguments) {
|
||||||
|
dumpOutput.format("Dumping %s with label \"%s\"%n", object, String.format(format, arguments));
|
||||||
|
}
|
||||||
|
}, new DebugVerifyHandler() {
|
||||||
|
@Override
|
||||||
|
public void verify(DebugContext ignore, Object object, String format, Object... args) {
|
||||||
|
verifyOutput.format("Verifying %s with label \"%s\"%n", object, String.format(format, args));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DebugContext openDebugContext(OptionValues options) {
|
||||||
|
return DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(logOutput), Collections.singletonList(handlers));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisabledScopes() {
|
||||||
|
OptionValues options = new OptionValues(EconomicMap.create());
|
||||||
|
DebugContextSetup setup = new DebugContextSetup();
|
||||||
|
try (DebugContext debug = setup.openDebugContext(options);
|
||||||
|
DebugContext.Scope d = debug.scope("TestDisabledScoping")) {
|
||||||
|
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
|
||||||
|
debug.dump(level, "an object", "at level %d", level);
|
||||||
|
debug.verify("an object", "at level %d", level);
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String log = setup.logOutput.toString();
|
||||||
|
String dumpOutput = setup.dumpOutput.toString();
|
||||||
|
String verifyOutput = setup.verifyOutput.toString();
|
||||||
|
Assert.assertTrue(log, log.isEmpty());
|
||||||
|
Assert.assertTrue(dumpOutput, dumpOutput.isEmpty());
|
||||||
|
Assert.assertTrue(verifyOutput, verifyOutput.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDumping() {
|
||||||
|
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
|
||||||
|
OptionValues options = new OptionValues(EconomicMap.create());
|
||||||
|
options = new OptionValues(options, DebugOptions.Dump, "Scope" + level + ":" + level);
|
||||||
|
DebugContextSetup setup = new DebugContextSetup();
|
||||||
|
try (DebugContext debug = setup.openDebugContext(options);
|
||||||
|
DebugContext.Scope s0 = debug.scope("TestDumping")) {
|
||||||
|
try (DebugContext.Scope s1 = debug.scope("Scope1")) {
|
||||||
|
try (DebugContext.Scope s2 = debug.scope("Scope2")) {
|
||||||
|
try (DebugContext.Scope s3 = debug.scope("Scope3")) {
|
||||||
|
try (DebugContext.Scope s4 = debug.scope("Scope4")) {
|
||||||
|
try (DebugContext.Scope s5 = debug.scope("Scope5")) {
|
||||||
|
debug.dump(level, "an object", "at level %d", level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String expect = String.format("Dumping an object with label \"at level %d\"%n", level);
|
||||||
|
String dump = setup.dumpOutput.toString();
|
||||||
|
Assert.assertEquals(expect, dump);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogging() throws IOException {
|
||||||
|
OptionValues options = new OptionValues(EconomicMap.create());
|
||||||
|
options = new OptionValues(options, DebugOptions.Log, ":5");
|
||||||
|
DebugContextSetup setup = new DebugContextSetup();
|
||||||
|
try (DebugContext debug = setup.openDebugContext(options)) {
|
||||||
|
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
|
||||||
|
try (DebugContext.Scope s0 = debug.scope("TestLogging")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
try (DebugContext.Scope s1 = debug.scope("Level1")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
try (DebugContext.Scope s2 = debug.scope("Level2")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
try (DebugContext.Scope s3 = debug.scope("Level3")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
try (DebugContext.Scope s4 = debug.scope("Level4")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
try (DebugContext.Scope s5 = debug.scope("Level5")) {
|
||||||
|
debug.log(level, "log statement at level %d", level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DataInputStream in = new DataInputStream(getClass().getResourceAsStream(getClass().getSimpleName() + ".testLogging.input"));
|
||||||
|
byte[] buf = new byte[in.available()];
|
||||||
|
in.readFully(buf);
|
||||||
|
String threadLabel = "[thread:" + Thread.currentThread().getId() + "]";
|
||||||
|
String expect = new String(buf).replace("[thread:1]", threadLabel);
|
||||||
|
|
||||||
|
String log = setup.logOutput.toString();
|
||||||
|
Assert.assertEquals(expect, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnabledSandbox() {
|
||||||
|
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
|
||||||
|
// Configure with an option that enables scopes
|
||||||
|
map.put(DebugOptions.DumpOnError, true);
|
||||||
|
OptionValues options = new OptionValues(map);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
|
||||||
|
Exception e = new Exception("testEnabledSandbox");
|
||||||
|
String scopeName = "";
|
||||||
|
try {
|
||||||
|
try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
|
||||||
|
scopeName = d.getQualifiedName();
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
assert e == t;
|
||||||
|
debug.handle(t);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// The exception object should propagate all the way out through
|
||||||
|
// a enabled sandbox scope
|
||||||
|
Assert.assertEquals(e, t);
|
||||||
|
}
|
||||||
|
String logged = baos.toString();
|
||||||
|
String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
|
||||||
|
String line = "-------------------------------------------------------";
|
||||||
|
Assert.assertTrue(String.format("Could not find \"%s\" in content between lines below:%n%s%n%s%s", expected, line, logged, line), logged.contains(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisabledSandbox() {
|
||||||
|
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
|
||||||
|
// Configure with an option that enables scopes
|
||||||
|
map.put(DebugOptions.DumpOnError, true);
|
||||||
|
OptionValues options = new OptionValues(map);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
|
||||||
|
Exception e = new Exception("testDisabledSandbox");
|
||||||
|
try {
|
||||||
|
// Test a disabled sandbox scope
|
||||||
|
try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", null)) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
assert e == t;
|
||||||
|
debug.handle(t);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// The exception object should propagate all the way out through
|
||||||
|
// a disabled sandbox scope
|
||||||
|
Assert.assertEquals(e, t);
|
||||||
|
}
|
||||||
|
String logged = baos.toString();
|
||||||
|
Assert.assertTrue(logged, logged.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that using a {@link DebugContext} on a thread other than the one on which it was
|
||||||
|
* created causes an assertion failure.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testInvariantChecking() throws InterruptedException {
|
||||||
|
Assume.assumeTrue(Assertions.ENABLED);
|
||||||
|
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
|
||||||
|
// Configure with an option that enables counters
|
||||||
|
map.put(DebugOptions.Counters, "");
|
||||||
|
OptionValues options = new OptionValues(map);
|
||||||
|
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
||||||
|
CounterKey counter = DebugContext.counter("DebugContextTestCounter");
|
||||||
|
AssertionError[] result = {null};
|
||||||
|
Thread thread = new Thread() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
counter.add(debug, 1);
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
result[0] = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
thread.join();
|
||||||
|
|
||||||
|
Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisableIntercept() {
|
||||||
|
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
|
||||||
|
// Configure with an option that enables scopes
|
||||||
|
map.put(DebugOptions.DumpOnError, true);
|
||||||
|
OptionValues options = new OptionValues(map);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
|
||||||
|
Exception e = new Exception();
|
||||||
|
try {
|
||||||
|
try (DebugCloseable disabled = debug.disableIntercept(); Scope s1 = debug.scope("ScopeWithDisabledIntercept")) {
|
||||||
|
try (Scope s2 = debug.scope("InnerScopeInheritsDisabledIntercept")) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
assert e == t;
|
||||||
|
debug.handle(t);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// The exception object should propagate all the way out through
|
||||||
|
// an intercept disabled scope
|
||||||
|
Assert.assertEquals(e, t);
|
||||||
|
}
|
||||||
|
String logged = baos.toString();
|
||||||
|
Assert.assertEquals("Exception should not have been intercepted", "", logged);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
[thread:1] scope: main
|
||||||
|
[thread:1] scope: main.TestLogging
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging.Level1
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4.Level5
|
||||||
|
log statement at level 1
|
||||||
|
[thread:1] scope: main.TestLogging
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging.Level1
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4.Level5
|
||||||
|
log statement at level 2
|
||||||
|
[thread:1] scope: main.TestLogging
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging.Level1
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4.Level5
|
||||||
|
log statement at level 3
|
||||||
|
[thread:1] scope: main.TestLogging
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging.Level1
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4.Level5
|
||||||
|
log statement at level 4
|
||||||
|
[thread:1] scope: main.TestLogging
|
||||||
|
log statement at level 5
|
||||||
|
[thread:1] scope: main.TestLogging.Level1
|
||||||
|
log statement at level 5
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2
|
||||||
|
log statement at level 5
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3
|
||||||
|
log statement at level 5
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4
|
||||||
|
log statement at level 5
|
||||||
|
[thread:1] scope: main.TestLogging.Level1.Level2.Level3.Level4.Level5
|
||||||
|
log statement at level 5
|
|
@ -1,127 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2013, 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.
|
|
||||||
*
|
|
||||||
* 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 org.graalvm.compiler.debug.test;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugHistogram;
|
|
||||||
import org.graalvm.compiler.debug.internal.DebugHistogramAsciiPrinter;
|
|
||||||
import org.graalvm.compiler.debug.internal.DebugHistogramRPrinter;
|
|
||||||
|
|
||||||
public class DebugHistogramTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEmptyHistogram() {
|
|
||||||
DebugHistogram histogram = Debug.createHistogram("TestHistogram");
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
String line = outputStream.toString().split("\r?\n")[0];
|
|
||||||
Assert.assertEquals("TestHistogram is empty.", line);
|
|
||||||
|
|
||||||
outputStream.reset();
|
|
||||||
new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
Assert.assertEquals("", outputStream.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSingleEntryHistogram() {
|
|
||||||
DebugHistogram histogram = Debug.createHistogram("TestHistogram");
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
histogram.add(new Integer(1));
|
|
||||||
histogram.add(new Integer(1));
|
|
||||||
new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
String[] lines = outputStream.toString().split("\r?\n");
|
|
||||||
// @formatter:off
|
|
||||||
String[] expected = {
|
|
||||||
"TestHistogram has 1 unique elements and 2 total elements:",
|
|
||||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
|
|
||||||
"| 1 | 2 | ==================================================================================================== |",
|
|
||||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
|
|
||||||
};
|
|
||||||
// @formatter:on
|
|
||||||
Assert.assertArrayEquals(expected, lines);
|
|
||||||
|
|
||||||
outputStream.reset();
|
|
||||||
new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
lines = outputStream.toString().split("\r?\n");
|
|
||||||
// @formatter:off
|
|
||||||
expected = new String[] {
|
|
||||||
"TestHistogram <- c(2);",
|
|
||||||
"names(TestHistogram) <- c(\"1\");"
|
|
||||||
};
|
|
||||||
// @formatter:on
|
|
||||||
Assert.assertArrayEquals(expected, lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMultipleEntryHistogram() {
|
|
||||||
DebugHistogram histogram = Debug.createHistogram("TestHistogram");
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
histogram.add(new Integer(1));
|
|
||||||
histogram.add(new Integer(2));
|
|
||||||
histogram.add(new Integer(2));
|
|
||||||
new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
String[] lines = outputStream.toString().split("\r?\n");
|
|
||||||
// @formatter:off
|
|
||||||
String[] expected = new String[] {
|
|
||||||
"TestHistogram has 2 unique elements and 3 total elements:",
|
|
||||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
|
|
||||||
"| 2 | 2 | ==================================================================================================== |",
|
|
||||||
"| 1 | 1 | ================================================== |",
|
|
||||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
|
|
||||||
};
|
|
||||||
// @formatter:on
|
|
||||||
Assert.assertArrayEquals(expected, lines);
|
|
||||||
|
|
||||||
outputStream.reset();
|
|
||||||
new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
|
|
||||||
lines = outputStream.toString().split("\r?\n");
|
|
||||||
// @formatter:off
|
|
||||||
expected = new String[] {
|
|
||||||
"TestHistogram <- c(2, 1);",
|
|
||||||
"names(TestHistogram) <- c(\"2\", \"1\");"
|
|
||||||
};
|
|
||||||
// @formatter:on
|
|
||||||
Assert.assertArrayEquals(expected, lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTooLongValueString() {
|
|
||||||
DebugHistogram histogram = Debug.createHistogram("TestHistogram");
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
histogram.add("MyCustomValue");
|
|
||||||
new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram);
|
|
||||||
String[] lines = outputStream.toString().split("\r?\n");
|
|
||||||
Assert.assertEquals(4, lines.length);
|
|
||||||
Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]);
|
|
||||||
Assert.assertEquals("----------------------------------------", lines[1]);
|
|
||||||
Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]);
|
|
||||||
Assert.assertEquals("----------------------------------------", lines[3]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,16 +22,20 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.debug.test;
|
package org.graalvm.compiler.debug.test;
|
||||||
|
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.NO_CONFIG_CUSTOMIZERS;
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION;
|
||||||
|
import static org.graalvm.compiler.debug.DebugContext.NO_GLOBAL_METRIC_VALUES;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.lang.management.ThreadMXBean;
|
import java.lang.management.ThreadMXBean;
|
||||||
|
|
||||||
import org.graalvm.compiler.debug.Debug;
|
|
||||||
import org.graalvm.compiler.debug.DebugCloseable;
|
import org.graalvm.compiler.debug.DebugCloseable;
|
||||||
import org.graalvm.compiler.debug.DebugConfig;
|
import org.graalvm.compiler.debug.DebugContext;
|
||||||
import org.graalvm.compiler.debug.DebugConfigScope;
|
import org.graalvm.compiler.debug.DebugOptions;
|
||||||
import org.graalvm.compiler.debug.DebugTimer;
|
|
||||||
import org.graalvm.compiler.debug.Management;
|
import org.graalvm.compiler.debug.Management;
|
||||||
|
import org.graalvm.compiler.debug.TimerKey;
|
||||||
|
import org.graalvm.compiler.options.OptionKey;
|
||||||
import org.graalvm.compiler.options.OptionValues;
|
import org.graalvm.compiler.options.OptionValues;
|
||||||
import org.graalvm.util.EconomicMap;
|
import org.graalvm.util.EconomicMap;
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
|
@ -39,7 +43,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public class DebugTimerTest {
|
public class TimerKeyTest {
|
||||||
|
|
||||||
private static final ThreadMXBean threadMXBean = Management.getThreadMXBean();
|
private static final ThreadMXBean threadMXBean = Management.getThreadMXBean();
|
||||||
|
|
||||||
|
@ -71,28 +75,29 @@ public class DebugTimerTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test2() {
|
public void test2() {
|
||||||
OptionValues options = new OptionValues(EconomicMap.create());
|
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
|
||||||
DebugConfig debugConfig = Debug.fixedConfig(options, 0, 0, false, false, true, false, false, null, null, System.out);
|
map.put(DebugOptions.Time, "");
|
||||||
try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) {
|
OptionValues options = new OptionValues(map);
|
||||||
DebugTimer timerC = Debug.timer("TimerC");
|
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, DEFAULT_LOG_STREAM, NO_CONFIG_CUSTOMIZERS);
|
||||||
try (DebugCloseable c1 = timerC.start()) {
|
|
||||||
|
TimerKey timerC = DebugContext.timer("TimerC");
|
||||||
|
try (DebugCloseable c1 = timerC.start(debug)) {
|
||||||
|
spin(50);
|
||||||
|
try (DebugCloseable c2 = timerC.start(debug)) {
|
||||||
spin(50);
|
spin(50);
|
||||||
try (DebugCloseable c2 = timerC.start()) {
|
try (DebugCloseable c3 = timerC.start(debug)) {
|
||||||
spin(50);
|
spin(50);
|
||||||
try (DebugCloseable c3 = timerC.start()) {
|
try (DebugCloseable c4 = timerC.start(debug)) {
|
||||||
spin(50);
|
spin(50);
|
||||||
try (DebugCloseable c4 = timerC.start()) {
|
try (DebugCloseable c5 = timerC.start(debug)) {
|
||||||
spin(50);
|
spin(50);
|
||||||
try (DebugCloseable c5 = timerC.start()) {
|
|
||||||
spin(50);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (timerC.getFlat() != null) {
|
}
|
||||||
assertEquals(timerC.getFlat().getCurrentValue(), timerC.getCurrentValue());
|
if (timerC.getFlat() != null) {
|
||||||
}
|
assertEquals(timerC.getFlat().getCurrentValue(debug), timerC.getCurrentValue(debug));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,50 +20,61 @@
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.debug.internal;
|
package org.graalvm.compiler.debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A name and index for a value managed in a thread local value map. All access to the value is made
|
* A name and index for a metric value.
|
||||||
* via a {@link DebugValue} instance.
|
|
||||||
*/
|
*/
|
||||||
public abstract class DebugValue implements Comparable<DebugValue> {
|
abstract class AbstractKey implements MetricKey {
|
||||||
|
|
||||||
private final String name;
|
private final String nameFormat;
|
||||||
|
private final Object nameArg1;
|
||||||
|
private final Object nameArg2;
|
||||||
|
|
||||||
|
private String name;
|
||||||
private int index;
|
private int index;
|
||||||
private boolean conditional;
|
private String doc;
|
||||||
|
|
||||||
protected DebugValue(String name, boolean conditional) {
|
protected AbstractKey(String nameFormat, Object nameArg1, Object nameArg2) {
|
||||||
this.name = name;
|
this.nameFormat = nameFormat;
|
||||||
|
this.nameArg1 = nameArg1;
|
||||||
|
this.nameArg2 = nameArg2;
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
this.conditional = conditional;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCurrentValue() {
|
protected void setDoc(String doc) {
|
||||||
|
this.doc = doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDoc() {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDocName() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCurrentValue(DebugContext debug) {
|
||||||
ensureInitialized();
|
ensureInitialized();
|
||||||
return DebugScope.getInstance().getCurrentValue(index);
|
return debug.getMetricValue(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCurrentValue(long l) {
|
void setCurrentValue(DebugContext debug, long l) {
|
||||||
ensureInitialized();
|
ensureInitialized();
|
||||||
DebugScope.getInstance().setCurrentValue(index, l);
|
debug.setMetricValue(index, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConditional(boolean flag) {
|
void ensureInitialized() {
|
||||||
conditional = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isConditional() {
|
|
||||||
return conditional;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ensureInitialized() {
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
index = KeyRegistry.register(this);
|
index = KeyRegistry.register(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addToCurrentValue(long value) {
|
void addToCurrentValue(DebugContext debug, long value) {
|
||||||
setCurrentValue(getCurrentValue() + value);
|
ensureInitialized();
|
||||||
|
debug.setMetricValue(index, debug.getMetricValue(index) + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,29 +88,20 @@ public abstract class DebugValue implements Comparable<DebugValue> {
|
||||||
/**
|
/**
|
||||||
* Gets the globally unique name for the value represented by this object.
|
* Gets the globally unique name for the value represented by this object.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
if (name == null) {
|
||||||
|
name = createName(nameFormat, nameArg1, nameArg2);
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected String createName(String format, Object arg1, Object arg2) {
|
||||||
public int compareTo(DebugValue o) {
|
return DebugContext.formatDebugName(format, arg1, arg2);
|
||||||
return name.compareTo(o.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name + "@" + index;
|
return getName() + "@" + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String toString(long value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The raw unit of the value (e.g. 'us', 'ms'). Use {@code ""} if there is no unit.
|
|
||||||
*/
|
|
||||||
public abstract String rawUnit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The raw value.
|
|
||||||
*/
|
|
||||||
public abstract String toRawString(long value);
|
|
||||||
}
|
}
|
|
@ -20,13 +20,27 @@
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.debug.internal;
|
package org.graalvm.compiler.debug;
|
||||||
|
|
||||||
public abstract class AccumulatedDebugValue extends DebugValue {
|
abstract class AccumulatedKey extends AbstractKey {
|
||||||
protected final DebugValue flat;
|
protected final AbstractKey flat;
|
||||||
|
|
||||||
public AccumulatedDebugValue(String name, boolean conditional, DebugValue flat) {
|
static final String ACCUMULATED_KEY_SUFFIX = "_Accm";
|
||||||
super(name + "_Accm", conditional);
|
static final String FLAT_KEY_SUFFIX = "_Flat";
|
||||||
|
|
||||||
|
protected AccumulatedKey(AbstractKey flat, String nameFormat, Object nameArg1, Object nameArg2) {
|
||||||
|
super(nameFormat, nameArg1, nameArg2);
|
||||||
this.flat = flat;
|
this.flat = flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createName(String format, Object arg1, Object arg2) {
|
||||||
|
return super.createName(format, arg1, arg2) + ACCUMULATED_KEY_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDocName() {
|
||||||
|
String name = getName();
|
||||||
|
return name.substring(0, name.length() - ACCUMULATED_KEY_SUFFIX.length());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -84,7 +84,11 @@ public final class CSVUtil {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object[] escapeArgs(char separator, char quote, char escape, Object... args) {
|
public static Object[] escapeArgs(Object... args) {
|
||||||
|
return escapeArgs(SEPARATOR, QUOTE, ESCAPE, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object[] escapeArgs(char separator, char quote, char escape, Object... args) {
|
||||||
String separatorStr = String.valueOf(separator);
|
String separatorStr = String.valueOf(separator);
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
Object obj = args[i];
|
Object obj = args[i];
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue