changeset 46640:70bdce04c59b

8183991: Update Graal Reviewed-by: kvn
author iveresov
date Fri, 07 Jul 2017 09:40:47 -0700
parents 3c5c50af29a7
children f64dc604ef8d
files hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTBackend.java hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompilationTask.java hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataBuilder.java hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java hotspot/src/jdk.internal.vm.compiler/.mx.graal/suite.py hotspot/src/jdk.internal.vm.compiler/share/classes/module-info.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.api.directives.test/src/org/graalvm/compiler/api/directives/test/ControlFlowAnchorDirectiveTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64Assembler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.test/src/org/graalvm/compiler/asm/test/AssemblerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.bytecode/src/org/graalvm/compiler/bytecode/BytecodeDisassembler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressLowering.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64NodeMatchRules.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/GraalOptions.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/BiDirectionalTraceBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/SingleBlockTraceBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceBuilderResult.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceStatisticsPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/UniDirectionalTraceBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/cfg/Loop.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTest13.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTestBase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DegeneratedLoopsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DontReuseArgumentSpaceTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FinalizableSubclassTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FloatingReadTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerAssumptionsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalDebugHandlersFactoryTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GuardedIntrinsicTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/IfCanonicalizerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ImplicitNullCheckTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InfopointReasonTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InterfaceMethodHandleTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LongNodeChainTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopFullUnrollTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopUnswitchTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryGraphCanonicalizeTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryScheduleTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MergeCanonicalizerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NestedLoopTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NodePropertiesTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PhiCreationTests.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushNodesThroughPiTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ReadAfterCheckCastTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ScalarTypeSystemTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SchedulingTest2.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SimpleCFGTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StaticInterfaceFieldTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StraighteningTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/TypeSystemTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsageTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsageTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyVirtualizableTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/BackendTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest1.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest2.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest3.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest4.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest5.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest6.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTestInterception01.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTestInterception02.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/VerifyMethodMetricsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/MonitorDeoptTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/SynchronizedMethodDeoptimizationTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/EATestBase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PoorMansEATest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/InliningTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/NestedLoopEffectsPhaseComplexityTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/InvokeGraal.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThread.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThreadFactory.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/GraalCompiler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/GraalDebugInitializationParticipant.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/DebugInfoBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchPattern.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchRuleRegistry.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchStatement.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/EconomyCompilerConfiguration.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/GraphChangeMonitoringPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/MidTier.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/target/Backend.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugContextTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugContextTest.testLogging.input hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugHistogramTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugTimerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/TimerKeyTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/AbstractKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/AccumulatedKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/CSVUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/CloseableCounter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/CounterKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/CounterKeyImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/Debug.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugCloseable.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugConfig.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugConfigCustomizer.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugConfigImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugConfigScope.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugContext.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugCounter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugDumpHandler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugEnvironment.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugFilter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugHandler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugHandlersFactory.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugHistogram.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugInitializationParticipant.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugMemUseTracker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugMethodMetrics.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugOptions.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugRetryableTask.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugTimer.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugValueFactory.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugValueMap.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugVerifyHandler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DelegatingDebugConfig.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/GlobalMetrics.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/GraalDebugConfig.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/Indent.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/JavaMethodContext.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/KeyRegistry.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/MemUseTrackerKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/MemUseTrackerKeyImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/MetricKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/ScopeImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/TimerKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/TimerKeyImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/TopLevelDebugConfig.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/UniquePathUtilities.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/AccumulatedDebugValue.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/CloseableCounterImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/CounterImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugHistogramAsciiPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugHistogramImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugHistogramRPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugScope.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValue.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValueMap.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValuesPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/KeyRegistry.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/MemUseTrackerImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/TimerImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/method/MethodMetricsImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/method/MethodMetricsInlineeScopeInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/method/MethodMetricsPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/method/MethodMetricsRootScopeInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/GraphTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/NodeMapTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/NodeUsagesTests.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/NodeValidationChecksTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/TypedNodeIteratorTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/TypedNodeIteratorTest2.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/CachedGraph.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Node.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeClass.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeWorkList.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotBackend.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLoweringProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotNodeLIRBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotAddressLowering.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotBackend.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotLIRGenerator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.sparc/src/org/graalvm/compiler/hotspot/sparc/SPARCHotSpotBackend.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.sparc/src/org/graalvm/compiler/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ClassSubstitutionsTests.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ConstantPoolSubstitutionsTests.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRLockTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRTestBase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotCryptoSubstitutionTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotGraalCompilerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotGraalMBeanTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotMonitorValueTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotNodeSubstitutionsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/InstalledCodeExecuteHelperTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/JVMCIInfopointErrorTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/MemoryUsageBenchmark.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/OptionsInFileTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/RetryableCompilationTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/TestIntrinsicCompiles.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/WriteBarrierAdditionTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/WriteBarrierVerificationTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationTask.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/FingerprintUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotDebugInfoBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompiler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalMBean.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalRuntime.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalRuntimeProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalVMEventListener.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotHostBackend.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotReplacementsImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotRetryableCompilation.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/PrintStreamOptionKey.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/debug/BenchmarkCounters.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/lir/HotSpotZapRegistersPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/DefaultHotSpotLoweringProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotAOTProfilingPlugin.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotForeignCallsProviderImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotLoweringProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotSuitesProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/OnStackReplacementPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/AOTInliningPolicy.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/phases/aot/ReplaceConstantNodesPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/AssertionSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HashCodeSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/InstanceOfSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/LoadExceptionObjectSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/MonitorSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/NewObjectSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/ObjectCloneNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/StringToBytesSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/UnsafeLoadSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/WriteBarrierSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/aot/ResolveConstantSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/ArrayCopySnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/arraycopy/UnsafeArrayCopySnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling/ProbabilisticProfileSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling/ProfileSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/CreateExceptionStub.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/ForeignCallStub.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/SnippetStub.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/Stub.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BciBlockMapping.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/FrameStateBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/LocalLiveness.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/JTTTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.jtt/src/org/graalvm/compiler/jtt/threads/Object_wait03.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.aarch64/src/org/graalvm/compiler/lir/aarch64/AArch64PrefetchOp.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/phases/StackMoveOptimizationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.jtt/src/org/graalvm/compiler/lir/jtt/SPARCBranchBailoutTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/CompositeValue.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/ControlFlowOptimizer.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/LIR.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/LIRInstruction.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/RedundantMoveElimination.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/IntervalWalker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScan.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanAssignLocationsPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanEliminateSpillMovePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanLifetimeAnalysisPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanOptimizeSpillPositionPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanRegisterAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanResolveDataFlowPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanWalker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/MoveResolver.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/OptimizingLinearScanWalker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/RegisterVerifier.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/ssa/SSALinearScan.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/ssa/SSALinearScanEliminateSpillMovePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/ssa/SSALinearScanLifetimeAnalysisPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/ssa/SSALinearScanResolveDataFlowPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/DefaultTraceRegisterAllocationPolicy.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/GlobalLivenessAnalysisPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/GlobalLivenessInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceBuilderPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceGlobalMoveResolver.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceRegisterAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceRegisterAllocationPolicy.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/bu/BottomUpAllocator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/RegisterVerifier.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanAssignLocationsPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanEliminateSpillMovePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanLifetimeAnalysisPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanRegisterAllocationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanResolveDataFlowPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLinearScanWalker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/lsra/TraceLocalMoveResolver.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/asm/CompilationResultBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/asm/CompilationResultBuilderFactory.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/constopt/ConstantLoadOptimization.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/constopt/ConstantTreeAnalyzer.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/debug/LIRGenerationDebugContext.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/dfa/LocationMarker.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/framemap/FrameMapBuilderImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/gen/LIRGenerationResult.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/gen/LIRGenerator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/phases/EconomyAllocationStage.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/phases/LIRPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/ssa/SSAVerifier.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/stackslotalloc/FixPointIntervalBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/stackslotalloc/LSStackSlotAllocator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/stackslotalloc/SimpleStackSlotAllocator.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/stackslotalloc/StackSlotAllocatorUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopFullUnrollPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPartialUnrollPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPeelingPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopTransformations.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopUnswitchingPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/ReassociateInvariantPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.test/src/org/graalvm/compiler/loop/test/LoopPartialUnrollTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/BasicInductionVariable.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/CountedLoopInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/DefaultLoopPolicies.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopFragment.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopFragmentInside.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopFragmentWhole.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopPolicies.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopsData.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/GraphCopyBenchmark.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraalState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraalUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraphState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/lir/GraalCompilerState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/lir/trace/TraceBuilderBenchmark.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/IntegerStampTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/NegateNodeCanonicalizationTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/StaticFieldAccessTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/AbstractEndNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/AbstractMergeNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/DeoptimizeNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/FrameState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphDecoder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/LoopBeginNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/cfg/Block.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/cfg/ControlFlowGraph.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderTool.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/memory/FloatingReadNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/memory/WriteNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/VirtualizerTool.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/util/GraphUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.options/src/org/graalvm/compiler/options/UniquePathUtilities.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/AddressLoweringByUsePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/ConditionalEliminationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/ConvertDeoptimizeToGuardPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/DeadCodeEliminationPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/FixReadsPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/GuardLoweringPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/UseTrappingNullChecksPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/InliningUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/info/AbstractInlineInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/info/MultiTypeGuardInlineInfo.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/info/elem/InlineableGraph.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/policy/GreedyInliningPolicy.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/inlining/walker/InliningData.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/BasePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/LazyName.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/OptimisticOptimizations.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/PhaseSuite.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/contract/NodeCostUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/graph/FixedNodeProbabilityCache.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/schedule/MemoryScheduleVerification.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/schedule/SchedulePhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/util/GraphOrder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/verify/VerifyDebugUsage.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/BinaryGraphPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CFGPrinterObserver.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CanonicalStringGraphPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraalDebugConfigCustomizer.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraalDebugHandlersFactory.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/IdealGraphPrinter.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/NoDeadCodeVerifyHandler.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.aarch64/src/org/graalvm/compiler/replacements/aarch64/AArch64FloatArithmeticSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.aarch64/src/org/graalvm/compiler/replacements/aarch64/AArch64IntegerArithmeticSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.amd64/src/org/graalvm/compiler/replacements/amd64/AMD64ConvertSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/CompiledExceptionHandlerTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/CompiledNullPointerExceptionTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/DerivedOopTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/EdgesTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/InstanceOfTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/MethodSubstitutionTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/PEGraphDecoderTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/PointerTrackingTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/ReplacementsParseTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/SnippetsTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/WordTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/BoxingSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/CachingPEGraphDecoder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ConstantStringIndexOfSnippets.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/DefaultJavaLoweringProvider.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/GraphKit.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/InstanceOfSnippetsTemplates.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/IntrinsicGraphBuilder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/PEGraphDecoder.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetCounterNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/BasicArrayCopyNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/MacroNode.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.test/src/org/graalvm/compiler/test/GraalTest.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/EffectList.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/EffectsClosure.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/EffectsPhase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/GraphEffectList.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/ObjectState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationBlockState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PEReadEliminationClosure.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PartialEscapeBlockState.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PartialEscapeClosure.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/ReadEliminationClosure.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualUtil.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualizerToolImpl.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.word/src/org/graalvm/compiler/word/Word.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.word/src/org/graalvm/compiler/word/WordOperationPlugin.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionDescriptor.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.options/src/org/graalvm/options/OptionDescriptors.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.word/src/org/graalvm/word/PointerBase.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.word/src/org/graalvm/word/PointerUtils.java hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.word/src/org/graalvm/word/WordFactory.java hotspot/test/compiler/aot/scripts/build-bootmodules.sh
diffstat 432 files changed, 11490 insertions(+), 11584 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTBackend.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTBackend.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,8 +27,7 @@
 
 import org.graalvm.compiler.code.CompilationResult;
 import org.graalvm.compiler.core.GraalCompiler;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.hotspot.HotSpotBackend;
 import org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder;
 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
@@ -82,6 +81,10 @@
         return backend;
     }
 
+    public HotSpotProviders getProviders() {
+        return providers;
+    }
+
     private Suites getSuites() {
         // create suites every time, as we modify options for the compiler
         return backend.getSuites().getDefaultSuites(graalOptions);
@@ -93,10 +96,10 @@
     }
 
     @SuppressWarnings("try")
-    public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod) {
-        StructuredGraph graph = buildStructuredGraph(resolvedMethod);
+    public CompilationResult compileMethod(ResolvedJavaMethod resolvedMethod, DebugContext debug) {
+        StructuredGraph graph = buildStructuredGraph(resolvedMethod, debug);
         if (graph != null) {
-            return compileGraph(resolvedMethod, graph);
+            return compileGraph(resolvedMethod, graph, debug);
         }
         return null;
     }
@@ -105,12 +108,13 @@
      * Build a structured graph for the member.
      *
      * @param javaMethod method for whose code the graph is to be created
+     * @param debug
      * @return structured graph
      */
     @SuppressWarnings("try")
-    private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod) {
-        try (Scope s = Debug.scope("AOTParseMethod")) {
-            StructuredGraph graph = new StructuredGraph.Builder(graalOptions).method(javaMethod).useProfilingInfo(false).build();
+    private StructuredGraph buildStructuredGraph(ResolvedJavaMethod javaMethod, DebugContext debug) {
+        try (DebugContext.Scope s = debug.scope("AOTParseMethod")) {
+            StructuredGraph graph = new StructuredGraph.Builder(graalOptions, debug).method(javaMethod).useProfilingInfo(false).build();
             graphBuilderSuite.apply(graph, highTierContext);
             return graph;
         } catch (Throwable e) {
@@ -120,8 +124,8 @@
     }
 
     @SuppressWarnings("try")
-    private CompilationResult compileGraph(ResolvedJavaMethod resolvedMethod, StructuredGraph graph) {
-        try (Scope s = Debug.scope("AOTCompileMethod")) {
+    private CompilationResult compileGraph(ResolvedJavaMethod resolvedMethod, StructuredGraph graph, DebugContext debug) {
+        try (DebugContext.Scope s = debug.scope("AOTCompileMethod")) {
             ProfilingInfo profilingInfo = DefaultProfilingInfo.get(TriState.FALSE);
 
             final boolean isImmutablePIC = true;
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompilationTask.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompilationTask.java	Fri Jul 07 09:40:47 2017 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,14 +26,15 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
 import org.graalvm.compiler.code.CompilationResult;
 import org.graalvm.compiler.core.GraalCompilerOptions;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugEnvironment;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.Management;
 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.printer.GraalDebugHandlersFactory;
 
 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
@@ -88,15 +89,12 @@
     /**
      * Compile a method or a constructor.
      */
+    @SuppressWarnings("try")
     public void run() {
         // Ensure a JVMCI runtime is initialized prior to Debug being initialized as the former
         // may include processing command line options used by the latter.
         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");
 
         final long threadId = Thread.currentThread().getId();
@@ -117,8 +115,12 @@
             allocatedBytesBefore = 0L;
         }
 
+        CompilationResult compResult = null;
         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();
 
         if (printAfterCompilation || printCompilation) {
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -33,8 +33,7 @@
 import jdk.tools.jaotc.binformat.HeaderContainer;
 import jdk.tools.jaotc.utils.Timer;
 import org.graalvm.compiler.code.CompilationResult;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
 import org.graalvm.compiler.hotspot.stubs.Stub;
@@ -124,10 +123,12 @@
     /**
      * Prepare data with all compiled classes and stubs.
      *
+     * @param debug
+     *
      * @throws Exception
      */
     @SuppressWarnings("try")
-    public void prepareData() throws Exception {
+    public void prepareData(DebugContext debug) throws Exception {
         try (Timer t = new Timer(main, "Parsing compiled code")) {
             /*
              * Copy compiled code into code section container and calls stubs (PLT trampoline).
@@ -142,7 +143,7 @@
             }
         }
 
-        AOTCompiledClass stubCompiledCode = retrieveStubCode();
+        AOTCompiledClass stubCompiledCode = retrieveStubCode(debug);
 
         // Free memory!
         try (Timer t = main.options.verbose ? new Timer(main, "Freeing memory") : null) {
@@ -177,18 +178,20 @@
 
     /**
      * Get all stubs from Graal and add them to the code section.
+     *
+     * @param debug
      */
     @SuppressWarnings("try")
-    private AOTCompiledClass retrieveStubCode() {
+    private AOTCompiledClass retrieveStubCode(DebugContext debug) {
         ArrayList<CompiledMethodInfo> stubs = new ArrayList<>();
         HotSpotForeignCallsProvider foreignCallsProvider = backend.getProviders().getForeignCalls();
         for (Stub stub : foreignCallsProvider.getStubs()) {
-            try (Scope scope = Debug.scope("CompileStubs")) {
-                CompilationResult result = stub.getCompilationResult(backend);
+            try (DebugContext.Scope scope = debug.scope("CompileStubs")) {
+                CompilationResult result = stub.getCompilationResult(debug, backend);
                 CompiledMethodInfo cm = new CompiledMethodInfo(result, new AOTStub(stub, backend));
                 stubs.add(cm);
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
         }
         AOTCompiledClass stubCompiledCode = new AOTCompiledClass(stubs);
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Fri Jul 07 09:40:47 2017 -0700
@@ -59,7 +59,10 @@
 import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
 import jdk.tools.jaotc.utils.Timer;
 
+import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
 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.GraalHotSpotVMConfig;
 import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
@@ -72,6 +75,7 @@
 import org.graalvm.compiler.phases.BasePhase;
 import org.graalvm.compiler.phases.PhaseSuite;
 import org.graalvm.compiler.phases.tiers.HighTierContext;
+import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
 import org.graalvm.compiler.runtime.RuntimeProvider;
 
 import jdk.vm.ci.meta.MetaAccessProvider;
@@ -467,6 +471,7 @@
             }
 
             AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, filters);
+            SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection();
             AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads);
             classes = compiler.compileClasses(classes);
 
@@ -485,7 +490,10 @@
 
             BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
             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
             printContainerInfo(binaryContainer.getHeaderContainer().getContainer());
--- a/hotspot/src/jdk.internal.vm.compiler/.mx.graal/suite.py	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/.mx.graal/suite.py	Fri Jul 07 09:40:47 2017 -0700
@@ -70,15 +70,15 @@
       "exports" : [
         "<package-info>",  # exports all packages containing package-info.java
       ],
-      "checkstyle" : "org.graalvm.api.word",
+      "checkstyle" : "org.graalvm.word",
       "javaCompliance" : "1.8",
       "workingSets" : "API,SDK",
     },
-    "org.graalvm.api.word" : {
+    "org.graalvm.word" : {
       "subDir" : "share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [],
-      "checkstyle" : "org.graalvm.api.word",
+      "checkstyle" : "org.graalvm.word",
       "javaCompliance" : "1.8",
       "workingSets" : "API,SDK",
     },
@@ -142,8 +142,7 @@
       "sourceDirs" : ["src"],
       "checkstyle" : "org.graalvm.compiler.graph",
       "uses" : [
-        "org.graalvm.compiler.debug.DebugConfigCustomizer",
-        "org.graalvm.compiler.debug.DebugInitializationParticipant",
+        "org.graalvm.compiler.debug.DebugHandlersFactory",
         "org.graalvm.compiler.debug.TTYStreamProvider",
       ],
       "dependencies" : [
@@ -792,6 +791,36 @@
       "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" : {
       "subDir" : "share/classes",
       "sourceDirs" : ["src"],
@@ -970,7 +999,7 @@
       "sourceDirs" : ["src"],
       "dependencies" : [
         "org.graalvm.compiler.debug",
-        "org.graalvm.api.word",
+        "org.graalvm.word",
       ],
       "annotationProcessors" : ["GRAAL_OPTIONS_PROCESSOR"],
       "checkstyle" : "org.graalvm.compiler.graph",
@@ -998,6 +1027,7 @@
       "subDir" : "share/classes",
       "sourceDirs" : ["src"],
       "dependencies" : [
+        "org.graalvm.compiler.debug",
         "org.graalvm.util",
         "mx:JUNIT",
       ],
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/module-info.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/module-info.java	Fri Jul 07 09:40:47 2017 -0700
@@ -32,8 +32,6 @@
 
     uses org.graalvm.compiler.code.DisassemblerProvider;
     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.hotspot.CompilerConfigurationFactory;
     uses org.graalvm.compiler.hotspot.HotSpotBackendFactory;
@@ -51,7 +49,6 @@
     exports org.graalvm.compiler.core.common            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.internal         to jdk.aot;
     exports org.graalvm.compiler.graph                  to jdk.aot;
     exports org.graalvm.compiler.hotspot                to jdk.aot;
     exports org.graalvm.compiler.hotspot.meta           to jdk.aot;
@@ -66,6 +63,7 @@
     exports org.graalvm.compiler.options                to jdk.aot;
     exports org.graalvm.compiler.phases                 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.replacements           to jdk.aot;
     exports org.graalvm.compiler.word                   to jdk.aot;
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.api.directives.test/src/org/graalvm/compiler/api/directives/test/ControlFlowAnchorDirectiveTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.api.directives.test/src/org/graalvm/compiler/api/directives/test/ControlFlowAnchorDirectiveTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -220,7 +220,7 @@
     @Test
     public void testClone() {
         StructuredGraph g = parseEager("preventPeelSnippet", AllowAssumptions.NO);
-        g.copy();
+        g.copy(g.getDebug());
     }
 
     private static List<NodeCount> getNodeCountAnnotations(StructuredGraph graph) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64Assembler.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64Assembler.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,6 +22,7 @@
  */
 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.ADDS;
 import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADR;
@@ -1010,6 +1011,100 @@
         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.
      *
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java	Fri Jul 07 09:40:47 2017 -0700
@@ -146,10 +146,10 @@
                     return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
                 }
             } else {
-                if (NumUtil.isSignedNbit(9, displacement)) {
+                if (displacementScalable && NumUtil.isUnsignedNbit(12, scaledDisplacement)) {
+                    return new AddressGenerationPlan(NO_WORK, IMMEDIATE_SCALED, false);
+                } else if (NumUtil.isSignedNbit(9, displacement)) {
                     return new AddressGenerationPlan(NO_WORK, IMMEDIATE_UNSCALED, false);
-                } else if (displacementScalable && NumUtil.isUnsignedNbit(12, scaledDisplacement)) {
-                    return new AddressGenerationPlan(NO_WORK, IMMEDIATE_SCALED, false);
                 } else {
                     boolean needsScratch = !isArithmeticImmediate(displacement);
                     return new AddressGenerationPlan(ADD_TO_BASE, REGISTER_OFFSET, needsScratch);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.test/src/org/graalvm/compiler/asm/test/AssemblerTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.asm.test/src/org/graalvm/compiler/asm/test/AssemblerTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -31,8 +31,7 @@
 import org.graalvm.compiler.code.DisassemblerProvider;
 import org.graalvm.compiler.core.common.CompilationIdentifier;
 import org.graalvm.compiler.core.target.Backend;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.runtime.RuntimeProvider;
@@ -83,10 +82,12 @@
     @SuppressWarnings("try")
     protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
         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();
             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();
 
             CompilationResult compResult = new CompilationResult();
@@ -95,7 +96,7 @@
             compResult.setTotalFrameSize(0);
             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)) {
                 String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
@@ -105,7 +106,7 @@
             }
             return code;
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.bytecode/src/org/graalvm/compiler/bytecode/BytecodeDisassembler.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.bytecode/src/org/graalvm/compiler/bytecode/BytecodeDisassembler.java	Fri Jul 07 09:40:47 2017 -0700
@@ -165,7 +165,7 @@
                 stream.next();
                 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);
         }
         return buf.toString();
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressLowering.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressLowering.java	Fri Jul 07 09:40:47 2017 -0700
@@ -28,6 +28,7 @@
 import org.graalvm.compiler.core.common.NumUtil;
 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
 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.calc.AddNode;
 import org.graalvm.compiler.nodes.calc.LeftShiftNode;
@@ -47,12 +48,15 @@
         AMD64AddressNode ret = new AMD64AddressNode(base, offset);
         boolean changed;
         do {
-            changed = improve(ret);
+            changed = improve(base.getDebug(), ret);
         } while (changed);
         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);
         if (newBase != ret.getBase()) {
             ret.setBase(newBase);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,10 +26,16 @@
 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
 import org.graalvm.compiler.core.common.LIRKind;
 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.gen.LIRGeneratorTool;
 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.calc.AddNode;
 import org.graalvm.compiler.nodes.memory.address.AddressNode;
 import org.graalvm.compiler.nodes.spi.LIRLowerable;
 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
@@ -42,7 +48,7 @@
  * optional.
  */
 @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);
 
@@ -64,6 +70,28 @@
         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
     public void generate(NodeLIRBuilderTool gen) {
         LIRGeneratorTool tool = gen.getLIRGeneratorTool();
@@ -135,4 +163,9 @@
     public long getMaxConstantDisplacement() {
         return displacement;
     }
+
+    @Override
+    public void simplify(SimplifierTool tool) {
+        canonicalizeIndex(tool);
+    }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64NodeMatchRules.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64NodeMatchRules.java	Fri Jul 07 09:40:47 2017 -0700
@@ -36,7 +36,6 @@
 import static org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD;
 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.AMD64RMOp;
 import org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp;
@@ -44,12 +43,12 @@
 import org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize;
 import org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp;
 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.gen.NodeLIRBuilder;
 import org.graalvm.compiler.core.gen.NodeMatchRules;
 import org.graalvm.compiler.core.match.ComplexMatchResult;
 import org.graalvm.compiler.core.match.MatchRule;
-import org.graalvm.compiler.debug.Debug;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.lir.LIRFrameState;
 import org.graalvm.compiler.lir.LIRValueUtil;
@@ -147,7 +146,7 @@
                 matchedAsConstant = true;
             }
             if (kind.isXMM()) {
-                Debug.log("Skipping constant compares for float kinds");
+                ifNode.getDebug().log("Skipping constant compares for float kinds");
                 return null;
             }
         }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/GraalOptions.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/GraalOptions.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,8 +24,8 @@
 
 import org.graalvm.compiler.debug.Assertions;
 import org.graalvm.compiler.options.Option;
+import org.graalvm.compiler.options.OptionKey;
 import org.graalvm.compiler.options.OptionType;
-import org.graalvm.compiler.options.OptionKey;
 
 /**
  * This class encapsulates options that control the behavior of the Graal compiler.
@@ -109,6 +109,9 @@
     @Option(help = "", type = OptionType.Debug)
     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)
     public static final OptionKey<Float> MinimumPeelProbability = new OptionKey<>(0.35f);
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/BiDirectionalTraceBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/BiDirectionalTraceBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -31,7 +31,7 @@
 
 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
 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;
 
 /**
@@ -40,8 +40,8 @@
  */
 public final class BiDirectionalTraceBuilder {
 
-    public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
-        return new BiDirectionalTraceBuilder(blocks).build(startBlock, blocks, pred);
+    public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
+        return new BiDirectionalTraceBuilder(blocks).build(debug, startBlock, blocks, pred);
     }
 
     private final Deque<AbstractBlockBase<?>> worklist;
@@ -69,22 +69,22 @@
     }
 
     @SuppressWarnings("try")
-    private TraceBuilderResult build(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
-        try (Indent indent = Debug.logAndIndent("BiDirectionalTraceBuilder: start trace building")) {
-            ArrayList<Trace> traces = buildTraces();
+    private TraceBuilderResult build(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
+        try (Indent indent = debug.logAndIndent("BiDirectionalTraceBuilder: start trace building")) {
+            ArrayList<Trace> traces = buildTraces(debug);
             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<>();
         // process worklist
         while (!worklist.isEmpty()) {
             AbstractBlockBase<?> block = worklist.pollFirst();
             assert block != null;
             if (!processed(block)) {
-                Trace trace = new Trace(startTrace(block));
+                Trace trace = new Trace(startTrace(debug, block));
                 for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
                     blockToTrace[traceBlock.getId()] = trace;
                 }
@@ -97,14 +97,16 @@
 
     /**
      * Build a new trace starting at {@code block}.
+     *
+     * @param debug
      */
     @SuppressWarnings("try")
-    private Collection<AbstractBlockBase<?>> startTrace(AbstractBlockBase<?> block) {
+    private Collection<AbstractBlockBase<?>> startTrace(DebugContext debug, AbstractBlockBase<?> block) {
         ArrayDeque<AbstractBlockBase<?>> trace = new ArrayDeque<>();
-        try (Indent i = Debug.logAndIndent("StartTrace: %s", block)) {
-            try (Indent indentFront = Debug.logAndIndent("Head:")) {
+        try (Indent i = debug.logAndIndent("StartTrace: %s", block)) {
+            try (Indent indentFront = debug.logAndIndent("Head:")) {
                 for (AbstractBlockBase<?> currentBlock = block; currentBlock != null; currentBlock = selectPredecessor(currentBlock)) {
-                    addBlockToTrace(currentBlock);
+                    addBlockToTrace(debug, currentBlock);
                     trace.addFirst(currentBlock);
                 }
             }
@@ -114,21 +116,21 @@
                 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)) {
-                    addBlockToTrace(currentBlock);
+                    addBlockToTrace(debug, currentBlock);
                     trace.addLast(currentBlock);
                     /* This time we can number the blocks immediately as we go forwards. */
                     currentBlock.setLinearScanNumber(blockNr++);
                 }
             }
         }
-        Debug.log("Trace: %s", trace);
+        debug.log("Trace: %s", trace);
         return trace;
     }
 
-    private void addBlockToTrace(AbstractBlockBase<?> currentBlock) {
-        Debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
+    private void addBlockToTrace(DebugContext debug, AbstractBlockBase<?> currentBlock) {
+        debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
         processed.set(currentBlock.getId());
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/SingleBlockTraceBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/SingleBlockTraceBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,17 +26,18 @@
 
 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
+import org.graalvm.compiler.debug.DebugContext;
 
 /**
  * Builds traces consisting of a single basic block.
  */
 public final class SingleBlockTraceBuilder {
 
-    public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
-        return build(startBlock, blocks, pred);
+    public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate 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];
         ArrayList<Trace> traces = new ArrayList<>(blocks.length);
 
@@ -49,7 +50,7 @@
         }
 
         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);
     }
 
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceBuilderResult.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceBuilderResult.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,7 +27,7 @@
 import java.util.BitSet;
 
 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;
 
 public final class TraceBuilderResult {
@@ -39,9 +39,9 @@
     private final ArrayList<Trace> traces;
     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);
-        ArrayList<Trace> newTraces = reorderTraces(traces, pred);
+        ArrayList<Trace> newTraces = reorderTraces(debug, traces, pred);
         TraceBuilderResult traceBuilderResult = new TraceBuilderResult(newTraces, blockToTrace);
         traceBuilderResult.numberTraces();
         assert verify(traceBuilderResult, blocks.length);
@@ -157,11 +157,11 @@
     }
 
     @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) {
             return oldTraces;
         }
-        try (Indent indent = Debug.logAndIndent("ReorderTrace")) {
+        try (Indent indent = debug.logAndIndent("ReorderTrace")) {
             ArrayList<Trace> newTraces = new ArrayList<>(oldTraces.size());
             for (int oldTraceIdx = 0; oldTraceIdx < oldTraces.size(); oldTraceIdx++) {
                 Trace currentTrace = oldTraces.get(oldTraceIdx);
@@ -171,7 +171,7 @@
                     addTrace(newTraces, currentTrace);
                     for (Trace succTrace : currentTrace.getSuccessors()) {
                         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
                             addTrace(newTraces, succTrace);
                         }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceStatisticsPrinter.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/TraceStatisticsPrinter.java	Fri Jul 07 09:40:47 2017 -0700
@@ -25,33 +25,32 @@
 import java.util.List;
 
 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.Indent;
 
 public final class TraceStatisticsPrinter {
     private static final String SEP = ";";
 
     @SuppressWarnings("try")
-    public static void printTraceStatistics(TraceBuilderResult result, String compilationUnitName) {
-        try (Scope s = Debug.scope("DumpTraceStatistics")) {
-            if (Debug.isLogEnabled(Debug.VERBOSE_LEVEL)) {
-                print(result, compilationUnitName);
+    public static void printTraceStatistics(DebugContext debug, TraceBuilderResult result, String compilationUnitName) {
+        try (DebugContext.Scope s = debug.scope("DumpTraceStatistics")) {
+            if (debug.isLogEnabled(DebugContext.VERBOSE_LEVEL)) {
+                print(debug, result, compilationUnitName);
             }
         } catch (Throwable e) {
-            Debug.handle(e);
+            debug.handle(e);
         }
     }
 
     @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();
         int numTraces = traces.size();
 
-        try (Indent indent0 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<tracestatistics>")) {
-            Debug.log(Debug.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
-            try (Indent indent1 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<traces>")) {
-                printRawLine("tracenumber", "total", "min", "max", "numBlocks");
+        try (Indent indent0 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<tracestatistics>")) {
+            debug.log(DebugContext.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
+            try (Indent indent1 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<traces>")) {
+                printRawLine(debug, "tracenumber", "total", "min", "max", "numBlocks");
                 for (int i = 0; i < numTraces; i++) {
                     AbstractBlockBase<?>[] t = traces.get(i).getBlocks();
                     double total = 0;
@@ -67,20 +66,20 @@
                             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) {
-        Debug.log(Debug.VERBOSE_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString()));
+    private static void printRawLine(DebugContext debug, Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) {
+        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) {
-        printRawLine(tracenr, totalTime, minProb, maxProb, numBlocks);
+    private static void printLine(DebugContext debug, int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) {
+        printRawLine(debug, tracenr, totalTime, minProb, maxProb, numBlocks);
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/UniDirectionalTraceBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/alloc/UniDirectionalTraceBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -29,7 +29,7 @@
 
 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate;
 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;
 
 /**
@@ -37,8 +37,8 @@
  */
 public final class UniDirectionalTraceBuilder {
 
-    public static TraceBuilderResult computeTraces(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
-        return new UniDirectionalTraceBuilder(blocks).build(startBlock, blocks, pred);
+    public static TraceBuilderResult computeTraces(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
+        return new UniDirectionalTraceBuilder(blocks).build(debug, startBlock, blocks, pred);
     }
 
     private final PriorityQueue<AbstractBlockBase<?>> worklist;
@@ -71,14 +71,14 @@
     }
 
     @SuppressWarnings("try")
-    private TraceBuilderResult build(AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
-        try (Indent indent = Debug.logAndIndent("UniDirectionalTraceBuilder: start trace building: %s", startBlock)) {
-            ArrayList<Trace> traces = buildTraces(startBlock);
-            return TraceBuilderResult.create(blocks, traces, blockToTrace, pred);
+    private TraceBuilderResult build(DebugContext debug, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] blocks, TrivialTracePredicate pred) {
+        try (Indent indent = debug.logAndIndent("UniDirectionalTraceBuilder: start trace building: %s", startBlock)) {
+            ArrayList<Trace> traces = buildTraces(debug, startBlock);
+            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<>();
         // add start block
         worklist.add(startBlock);
@@ -87,7 +87,7 @@
             AbstractBlockBase<?> block = worklist.poll();
             assert block != null;
             if (!processed(block)) {
-                Trace trace = new Trace(startTrace(block));
+                Trace trace = new Trace(startTrace(debug, block));
                 for (AbstractBlockBase<?> traceBlock : trace.getBlocks()) {
                     blockToTrace[traceBlock.getId()] = trace;
                 }
@@ -102,13 +102,13 @@
      * Build a new trace starting at {@code block}.
      */
     @SuppressWarnings("try")
-    private List<AbstractBlockBase<?>> startTrace(AbstractBlockBase<?> block) {
+    private List<AbstractBlockBase<?>> startTrace(DebugContext debug, AbstractBlockBase<?> block) {
         assert checkPredecessorsProcessed(block);
         ArrayList<AbstractBlockBase<?>> trace = new ArrayList<>();
         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)) {
-                Debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
+                debug.log("add %s (prob: %f)", currentBlock, currentBlock.probability());
                 processed.set(currentBlock.getId());
                 trace.add(currentBlock);
                 unblock(currentBlock);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/cfg/Loop.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/cfg/Loop.java	Fri Jul 07 09:40:47 2017 -0700
@@ -87,6 +87,10 @@
         return exits;
     }
 
+    public void addExit(T t) {
+        exits.add(t);
+    }
+
     /**
      * Determines if one loop is a transitive parent of another loop.
      *
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,8 +22,6 @@
  */
 package org.graalvm.compiler.core.test;
 
-import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -48,14 +46,11 @@
 import org.graalvm.compiler.api.test.Graal;
 import org.graalvm.compiler.bytecode.BridgeMethodUtils;
 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.type.ArithmeticOpTable;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugConfigScope;
-import org.graalvm.compiler.debug.DebugEnvironment;
-import org.graalvm.compiler.debug.DelegatingDebugConfig;
-import org.graalvm.compiler.debug.GraalDebugConfig;
+import org.graalvm.compiler.debug.DebugCloseable;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.NodeClass;
@@ -203,12 +198,7 @@
         String[] filters = property == null ? null : property.split(",");
 
         OptionValues options = getInitialOptions();
-        CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread", new DebugConfigAccess() {
-            @Override
-            public GraalDebugConfig getDebugConfig() {
-                return DebugEnvironment.ensureInitialized(options);
-            }
-        });
+        CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread");
         int availableProcessors = Runtime.getRuntime().availableProcessors();
         ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);
 
@@ -216,17 +206,19 @@
 
         for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) {
             ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
-            StructuredGraph graph = new StructuredGraph.Builder(options, AllowAssumptions.YES).method(method).build();
-            try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("CheckingGraph", graph, method)) {
-                graphBuilderSuite.apply(graph, context);
-                // update phi stamps
-                graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
-                checkGraph(context, graph);
-                errors.add(String.format("Expected error while checking %s", m));
-            } catch (VerificationError e) {
-                // expected!
-            } catch (Throwable e) {
-                errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
+            try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
+                StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build();
+                try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
+                    graphBuilderSuite.apply(graph, context);
+                    // update phi stamps
+                    graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
+                    checkGraph(context, graph);
+                    errors.add(String.format("Expected error while checking %s", m));
+                } catch (VerificationError e) {
+                    // expected!
+                } catch (Throwable e) {
+                    errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
+                }
             }
         }
         if (errors.isEmpty()) {
@@ -251,26 +243,29 @@
                         String methodName = className + "." + m.getName();
                         if (matches(filters, methodName)) {
                             executor.execute(() -> {
-                                ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
-                                StructuredGraph graph = new StructuredGraph.Builder(options).method(method).build();
-                                try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("CheckingGraph", graph, method)) {
-                                    checkMethod(method);
-                                    graphBuilderSuite.apply(graph, context);
-                                    // update phi stamps
-                                    graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
-                                    checkGraph(context, graph);
-                                } catch (VerificationError e) {
-                                    errors.add(e.getMessage());
-                                } catch (LinkageError e) {
-                                    // suppress linkages errors resulting from eager resolution
-                                } catch (BailoutException e) {
-                                    // Graal bail outs on certain patterns in Java bytecode (e.g.,
-                                    // unbalanced monitors introduced by jacoco).
-                                } catch (Throwable e) {
-                                    try {
-                                        tool.handleParsingException(e);
-                                    } catch (Throwable t) {
-                                        errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
+                                try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) {
+                                    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
+                                    StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
+                                    try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
+                                        checkMethod(method);
+                                        graphBuilderSuite.apply(graph, context);
+                                        // update phi stamps
+                                        graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
+                                        checkGraph(context, graph);
+                                    } catch (VerificationError e) {
+                                        errors.add(e.getMessage());
+                                    } catch (LinkageError e) {
+                                        // suppress linkages errors resulting from eager resolution
+                                    } catch (BailoutException e) {
+                                        // Graal bail outs on certain patterns in Java bytecode
+                                        // (e.g.,
+                                        // unbalanced monitors introduced by jacoco).
+                                    } catch (Throwable e) {
+                                        try {
+                                            tool.handleParsingException(e);
+                                        } catch (Throwable t) {
+                                            errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
+                                        }
                                     }
                                 }
                             });
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTest13.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTest13.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,7 +22,7 @@
  */
 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.ValueNode;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
@@ -310,7 +310,8 @@
         super.prepareGraph(graph, canonicalizer, context, applyLowering);
         graph.clearAllStateAfter();
         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);
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTestBase.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTestBase.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,16 +22,16 @@
  */
 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.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.nodes.spi.LoweringTool;
 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.IterativeConditionalEliminationPhase;
 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.tiers.PhaseContext;
 import org.junit.Assert;
@@ -52,21 +52,22 @@
     @SuppressWarnings("try")
     protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
         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());
         CanonicalizerPhase canonicalizer1 = 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);
             new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
             canonicalizer.apply(graph, context);
             canonicalizer.apply(graph, context);
             new ConvertDeoptimizeToGuardPhase().apply(graph, context);
         } catch (Throwable t) {
-            Debug.handle(t);
+            debug.handle(t);
         }
         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);
             if (applyConditionalEliminationOnReference) {
                 new ConditionalEliminationPhase(true).apply(referenceGraph, context);
@@ -75,7 +76,7 @@
             canonicalizer.apply(referenceGraph, context);
             new ConvertDeoptimizeToGuardPhase().apply(graph, context);
         } catch (Throwable t) {
-            Debug.handle(t);
+            debug.handle(t);
         }
         assertEquals(referenceGraph, graph);
     }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DegeneratedLoopsTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DegeneratedLoopsTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,16 +22,14 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
 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
@@ -81,17 +79,18 @@
 
     @SuppressWarnings("try")
     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);
             HighTierContext context = getDefaultHighTierContext();
             new InliningPhase(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);
-            Debug.dump(Debug.BASIC_LEVEL, referenceGraph, "ReferenceGraph");
+            debug.dump(DebugContext.BASIC_LEVEL, referenceGraph, "ReferenceGraph");
             assertEquals(referenceGraph, graph);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DontReuseArgumentSpaceTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DontReuseArgumentSpaceTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -28,6 +28,7 @@
 
 import org.graalvm.compiler.code.CompilationResult;
 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.AllowAssumptions;
 import org.graalvm.compiler.options.OptionValues;
@@ -72,7 +73,8 @@
         ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
         StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
         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);
     }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FinalizableSubclassTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FinalizableSubclassTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -28,26 +28,26 @@
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
 
+import org.graalvm.compiler.debug.DebugContext;
+import org.graalvm.compiler.java.GraphBuilderPhase;
+import org.graalvm.compiler.nodes.StructuredGraph;
+import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
+import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
+import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
+import org.graalvm.compiler.options.OptionValues;
+import org.graalvm.compiler.phases.OptimisticOptimizations;
+import org.graalvm.compiler.phases.common.CanonicalizerPhase;
+import org.graalvm.compiler.phases.common.inlining.InliningPhase;
+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;
 
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.java.GraphBuilderPhase;
-import org.graalvm.compiler.nodes.StructuredGraph;
-import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
-import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
-import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
-import org.graalvm.compiler.phases.OptimisticOptimizations;
-import org.graalvm.compiler.phases.common.CanonicalizerPhase;
-import org.graalvm.compiler.phases.common.inlining.InliningPhase;
-import org.graalvm.compiler.phases.tiers.HighTierContext;
-
 public class FinalizableSubclassTest extends GraalCompilerTest {
 
     /**
@@ -71,7 +71,8 @@
         Constructor<?>[] constructors = cl.getConstructors();
         Assert.assertTrue(constructors.length == 1);
         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());
         new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), getProviders().getConstantReflection(), getProviders().getConstantFieldProvider(), conf,
@@ -107,8 +108,9 @@
      */
     @Test
     public void test1() throws ClassNotFoundException {
+        DebugContext debug = getDebugContext();
         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"), false, AllowAssumptions.YES);
 
@@ -126,8 +128,11 @@
         private final String replaceTo;
         private HashMap<String, Class<?>> cache = new HashMap<>();
 
-        ClassTemplateLoader() {
+        private final DebugContext debug;
+
+        ClassTemplateLoader(DebugContext debug) {
             loaderInstance++;
+            this.debug = debug;
             replaceTo = String.format("%04d", loaderInstance);
         }
 
@@ -155,14 +160,15 @@
             } catch (IOException e) {
                 Assert.fail("can't access class: " + name);
             }
-            dumpStringsInByteArray(classData);
+
+            dumpStringsInByteArray(debug, classData);
 
             // replace all occurrences of "AAAA" in classfile
             int index = -1;
             while ((index = indexOfAAAA(classData, index + 1)) != -1) {
                 replaceAAAA(classData, index, replaceTo);
             }
-            dumpStringsInByteArray(classData);
+            dumpStringsInByteArray(debug, classData);
 
             Class<?> c = defineClass(null, classData, 0, classData.length);
             cache.put(nameReplaced, c);
@@ -192,14 +198,14 @@
             }
         }
 
-        private static void dumpStringsInByteArray(byte[] b) {
+        private static void dumpStringsInByteArray(DebugContext debug, byte[] b) {
             boolean wasChar = true;
             StringBuilder sb = new StringBuilder();
             for (Byte x : b) {
                 // check for [a-zA-Z0-9]
                 if ((x >= 0x41 && x <= 0x7a) || (x >= 0x30 && x <= 0x39)) {
                     if (!wasChar) {
-                        Debug.log(sb + "");
+                        debug.log(sb + "");
                         sb.setLength(0);
                     }
                     sb.append(String.format("%c", x));
@@ -208,7 +214,7 @@
                     wasChar = false;
                 }
             }
-            Debug.log(sb + "");
+            debug.log(sb + "");
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,19 +22,17 @@
  */
 package org.graalvm.compiler.core.test;
 
+import org.graalvm.compiler.debug.DebugContext;
+import org.graalvm.compiler.nodes.ReturnNode;
+import org.graalvm.compiler.nodes.StructuredGraph;
+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;
 
-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.StructuredGraph;
-import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
-
 /**
  * This test illustrates problems and limitations with class hierarchy analysis when default methods
  * are involved.
@@ -139,13 +137,14 @@
 
     @SuppressWarnings("try")
     protected StructuredGraph buildGraph(final String snippet) {
-        try (Scope s = Debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
-            StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
+        DebugContext debug = getDebugContext();
+        try (DebugContext.Scope s = debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
+            StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
             compile(graph.method(), graph);
-            Debug.dump(Debug.BASIC_LEVEL, graph, snippet);
+            debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
             return graph;
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FloatingReadTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FloatingReadTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,11 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.ReturnNode;
@@ -39,6 +35,8 @@
 import org.graalvm.compiler.phases.common.FloatingReadPhase;
 import org.graalvm.compiler.phases.common.LoweringPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class FloatingReadTest extends GraphScheduleTest {
 
@@ -63,7 +61,8 @@
 
     @SuppressWarnings("try")
     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);
             PhaseContext context = new PhaseContext(getProviders());
@@ -82,7 +81,7 @@
                 }
             }
 
-            Debug.dump(Debug.BASIC_LEVEL, graph, "After lowering");
+            debug.dump(DebugContext.BASIC_LEVEL, graph, "After lowering");
 
             Assert.assertNotNull(returnNode);
             Assert.assertNotNull(monitorexit);
@@ -92,7 +91,7 @@
 
             assertOrderedAfterSchedule(graph, read, (Node) monitorexit);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerAssumptionsTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerAssumptionsTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -65,7 +65,7 @@
         checkGraph(expectedAssumption, 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());
         if (classToLoad != null) {
             String fullName = getClass().getName() + "$" + classToLoad;
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -37,6 +37,7 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
@@ -55,10 +56,10 @@
 import org.graalvm.compiler.core.common.CompilationIdentifier;
 import org.graalvm.compiler.core.common.type.StampFactory;
 import org.graalvm.compiler.core.target.Backend;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
+import org.graalvm.compiler.debug.DebugDumpHandler;
 import org.graalvm.compiler.debug.DebugDumpScope;
-import org.graalvm.compiler.debug.DebugEnvironment;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.debug.TTY;
 import org.graalvm.compiler.graph.Node;
@@ -85,6 +86,7 @@
 import org.graalvm.compiler.nodes.ReturnNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
 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.ValueNode;
 import org.graalvm.compiler.nodes.cfg.Block;
@@ -111,13 +113,13 @@
 import org.graalvm.compiler.phases.tiers.Suites;
 import org.graalvm.compiler.phases.tiers.TargetProvider;
 import org.graalvm.compiler.phases.util.Providers;
+import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
 import org.graalvm.compiler.runtime.RuntimeProvider;
 import org.graalvm.compiler.test.AddExports;
 import org.graalvm.compiler.test.GraalTest;
 import org.graalvm.compiler.test.JLModule;
 import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.internal.AssumptionViolatedException;
 
@@ -364,14 +366,7 @@
         this.providers = backend.getProviders();
     }
 
-    private Scope debugScope;
-
-    @Before
-    public void beforeTest() {
-        assert debugScope == null;
-        debugScope = Debug.scope(getClass());
-    }
-
+    @Override
     @After
     public void afterTest() {
         if (invocationPluginExtensions != null) {
@@ -383,10 +378,21 @@
                 }
             }
         }
-        if (debugScope != null) {
-            debugScope.close();
-        }
-        debugScope = null;
+        super.afterTest();
+    }
+
+    /**
+     * 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) {
@@ -413,13 +419,13 @@
         String mismatchString = compareGraphStrings(expected, expectedString, graph, actualString);
 
         if (!excludeVirtual && getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
-            Debug.dump(Debug.BASIC_LEVEL, expected, "Node count not matching - expected");
-            Debug.dump(Debug.BASIC_LEVEL, graph, "Node count not matching - actual");
+            expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "Node count not matching - expected");
+            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);
         }
         if (!expectedString.equals(actualString)) {
-            Debug.dump(Debug.BASIC_LEVEL, expected, "mismatching graphs - expected");
-            Debug.dump(Debug.BASIC_LEVEL, graph, "mismatching graphs - actual");
+            expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "mismatching graphs - expected");
+            graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "mismatching graphs - actual");
             Assert.fail(mismatchString);
         }
     }
@@ -932,24 +938,27 @@
             final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
 
             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();
                 if (printCompilation) {
                     TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s ...", id, installedCodeOwner.getDeclaringClass().getName(), installedCodeOwner.getName(),
                                     installedCodeOwner.getSignature()));
                 }
                 long start = System.currentTimeMillis();
-                CompilationResult compResult = compile(installedCodeOwner, graph, new CompilationResult(), id, options);
+                CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
                 if (printCompilation) {
                     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 {
                         if (installAsDefault) {
-                            installedCode = addDefaultMethod(installedCodeOwner, compResult);
+                            installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
                         } else {
-                            installedCode = addMethod(installedCodeOwner, compResult);
+                            installedCode = addMethod(debug, installedCodeOwner, compResult);
                         }
                         if (installedCode == null) {
                             throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
@@ -963,10 +972,10 @@
                         throw e;
                     }
                 } catch (Throwable e) {
-                    throw Debug.handle(e);
+                    throw debug.handle(e);
                 }
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
 
             if (!forceCompile) {
@@ -988,6 +997,10 @@
         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) {
         return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
     }
@@ -1032,13 +1045,14 @@
     protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
         StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
         lastCompiledGraph = graphToCompile;
-        try (Scope s = Debug.scope("Compile", graphToCompile)) {
+        DebugContext debug = graphToCompile.getDebug();
+        try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
             assert options != null;
             Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
                             graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
             return GraalCompiler.compile(request);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
@@ -1048,12 +1062,12 @@
         return null;
     }
 
-    protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compilationResult) {
-        return backend.addInstalledCode(method, null, compilationResult);
+    protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
+        return backend.addInstalledCode(debug, method, null, compilationResult);
     }
 
-    protected InstalledCode addDefaultMethod(final ResolvedJavaMethod method, final CompilationResult compilationResult) {
-        return backend.createDefaultInstalledCode(method, compilationResult);
+    protected InstalledCode addDefaultMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
+        return backend.createDefaultInstalledCode(debug, method, compilationResult);
     }
 
     private final Map<ResolvedJavaMethod, Executable> methodMap = new HashMap<>();
@@ -1108,7 +1122,8 @@
      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
      */
     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 @@
      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
      */
     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 @@
      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
      */
     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 @@
      * @param options the option values to be used when compiling the graph
      */
     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 @@
      * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
      */
     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 @@
      * @param options the option values to be used when compiling the graph
      */
     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 @@
      * @param compilationId the compilation identifier to be associated with 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) {
-        return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true)), allowAssumptions, compilationId, options);
+    protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
+        return parse(builder(method, allowAssumptions, compilationId, options), getEagerGraphBuilderSuite());
     }
 
-    /**
-     * Parses a Java method using {@linkplain GraphBuilderConfiguration#withFullInfopoints(boolean)
-     * full debug} set to true to produce a graph.
-     *
-     * @param method the method to be parsed
-     * @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
-     */
-    protected StructuredGraph parseDebug(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
-        return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)), allowAssumptions, getCompilationId(method),
-                        getInitialOptions());
+    protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
+        OptionValues options = debug.getOptions();
+        return new Builder(options, debug, allowAssumptions).method(method).compilationId(getCompilationId(method));
+    }
+
+    protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
+        OptionValues options = getInitialOptions();
+        return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
+    }
+
+    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")
-    private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId,
-                    OptionValues options) {
+    protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
+        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;
-        // @formatter:off
-        StructuredGraph graph = new StructuredGraph.Builder(options, allowAssumptions).
-                        method(javaMethod).
-                        speculationLog(getSpeculationLog()).
-                        useProfilingInfo(true).
-                        compilationId(compilationId).
-                        cancellable(getCancellable(javaMethod)).
-                        build();
-        // @formatter:on
-        try (Scope ds = Debug.scope("Parsing", javaMethod, graph)) {
+        StructuredGraph graph = builder.build();
+        DebugContext debug = graph.getDebug();
+        try (DebugContext.Scope ds = debug.scope("Parsing", javaMethod, graph)) {
             graphBuilderSuite.apply(graph, getDefaultHighTierContext());
             return graph;
         } 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
      * {@code parse...()} methods.
@@ -1385,6 +1421,6 @@
     public static void initializeForTimeout() {
         // timeout tests run in a separate thread which needs the DebugEnvironment to be
         // initialized
-        DebugEnvironment.ensureInitialized(getInitialOptions());
+        // DebugEnvironment.ensureInitialized(getInitialOptions());
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalDebugHandlersFactoryTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -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);
+    }
+}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GuardedIntrinsicTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GuardedIntrinsicTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -112,7 +112,7 @@
     @Override
     protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
         graph = super.parseForCompile(method, compilationId, options);
-        parsedForCompile = (StructuredGraph) graph.copy();
+        parsedForCompile = (StructuredGraph) graph.copy(graph.getDebug());
         return graph;
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/IfCanonicalizerTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/IfCanonicalizerTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,9 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.ConstantNode;
 import org.graalvm.compiler.nodes.FrameState;
@@ -40,6 +38,7 @@
 import org.graalvm.compiler.phases.common.LoweringPhase;
 import org.graalvm.compiler.phases.tiers.MidTierContext;
 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
@@ -237,6 +236,7 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
+        DebugContext debug = graph.getDebug();
         ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
         for (Node n : param.usages().snapshot()) {
@@ -244,7 +244,7 @@
                 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()));
         for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
             fs.replaceFirstInput(param, null);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ImplicitNullCheckTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ImplicitNullCheckTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,13 +22,8 @@
  */
 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.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.nodes.DeoptimizeNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
@@ -42,6 +37,9 @@
 import org.graalvm.compiler.phases.common.LoweringPhase;
 import org.graalvm.compiler.phases.tiers.MidTierContext;
 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.
@@ -68,8 +66,9 @@
 
     @SuppressWarnings("try")
     private void test(final String snippet) {
-        try (Scope s = Debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
-            StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
+        DebugContext debug = getDebugContext();
+        try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
+            StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
             PhaseContext context = new PhaseContext(getProviders());
             new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
             new FloatingReadPhase().apply(graph);
@@ -80,7 +79,7 @@
             Assert.assertTrue(graph.getNodes().filter(ReadNode.class).first().canNullCheck());
 
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InfopointReasonTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InfopointReasonTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -76,7 +76,7 @@
     @Test
     public void lineInfopoints() {
         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;
         for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
             if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InterfaceMethodHandleTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/InterfaceMethodHandleTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,6 +27,7 @@
 import java.lang.invoke.MethodType;
 
 import org.graalvm.compiler.code.CompilationResult;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.test.ExportingClassLoader;
 import org.junit.Test;
 import org.objectweb.asm.ClassWriter;
@@ -104,12 +105,12 @@
     }
 
     @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))) {
             // 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);
     }
 
     /**
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LongNodeChainTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LongNodeChainTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,13 +26,15 @@
 
 import org.junit.Assert;
 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.ReturnNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.ValueNode;
 import org.graalvm.compiler.nodes.calc.AddNode;
 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.schedule.SchedulePhase;
 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
@@ -52,7 +54,8 @@
 
     private void longAddChain(boolean reverse) {
         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 value = null;
         if (reverse) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopFullUnrollTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopFullUnrollTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,8 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.loop.DefaultLoopPolicies;
 import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
@@ -83,15 +82,16 @@
 
     @SuppressWarnings("try")
     private void test(String snippet, int loopCount) {
-        try (Scope s = Debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
-            final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
+        DebugContext debug = getDebugContext();
+        try (DebugContext.Scope s = debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
+            final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
 
             PhaseContext context = new PhaseContext(getProviders());
             new LoopFullUnrollPhase(new CanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context);
 
             assertTrue(graph.getNodes().filter(LoopBeginNode.class).count() == loopCount);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopUnswitchTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/LoopUnswitchTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,10 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.loop.DefaultLoopPolicies;
 import org.graalvm.compiler.loop.phases.LoopUnswitchingPhase;
@@ -33,6 +30,7 @@
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 public class LoopUnswitchTest extends GraalCompilerTest {
 
@@ -124,6 +122,7 @@
 
     @SuppressWarnings("try")
     private void test(String snippet, String referenceSnippet) {
+        DebugContext debug = getDebugContext();
         final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
         final StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
 
@@ -135,10 +134,10 @@
 
         new CanonicalizerPhase().apply(graph, 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);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryGraphCanonicalizeTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -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);
+    }
+}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryScheduleTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryScheduleTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -31,12 +31,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.junit.Assert;
-import org.junit.Test;
-
 import org.graalvm.compiler.api.directives.GraalDirectives;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.iterators.NodeIterable;
 import org.graalvm.compiler.nodes.ReturnNode;
@@ -60,6 +56,8 @@
 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
 import org.graalvm.compiler.phases.tiers.HighTierContext;
 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
@@ -706,7 +704,8 @@
     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);
         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();
             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
             canonicalizer.apply(graph, context);
@@ -717,7 +716,7 @@
             if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
                 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 RemoveValueProxyPhase().apply(graph);
@@ -732,7 +731,7 @@
             assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
             return graph.getLastSchedule();
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MergeCanonicalizerTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MergeCanonicalizerTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,14 +22,13 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.ReturnNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 public class MergeCanonicalizerTest extends GraalCompilerTest {
 
@@ -61,7 +60,7 @@
         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
         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());
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NestedLoopTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NestedLoopTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,11 +22,8 @@
  */
 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.debug.Debug;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.Invoke;
 import org.graalvm.compiler.nodes.StructuredGraph;
@@ -34,6 +31,8 @@
 import org.graalvm.compiler.nodes.cfg.Block;
 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
+import org.junit.Assert;
+import org.junit.Test;
 
 public class NestedLoopTest extends GraalCompilerTest {
 
@@ -142,7 +141,8 @@
 
     private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
         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);
 
         Assert.assertEquals(3, cfg.getLoops().size());
@@ -162,7 +162,7 @@
         Assert.assertEquals(rootExits, rootLoop.getExits().size());
         Assert.assertEquals(nestedExits, nestedLoop.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) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NodePropertiesTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NodePropertiesTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -23,7 +23,6 @@
 package org.graalvm.compiler.core.test;
 
 import org.graalvm.compiler.api.directives.GraalDirectives;
-import org.graalvm.compiler.debug.Debug;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.iterators.NodeIterable;
 import org.graalvm.compiler.graph.spi.Canonicalizable;
@@ -196,7 +195,7 @@
         GraphCostPhase gc2 = new GraphCostPhase();
         gc1.apply(g1, 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.finalSize == gc1.finalSize);
     }
@@ -214,7 +213,7 @@
         GraphCostPhase gc2 = new GraphCostPhase();
         gc1.apply(g1, 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.finalSize == gc1.finalSize);
     }
@@ -231,7 +230,7 @@
         GraphCostPhase gc2 = new GraphCostPhase();
         gc1.apply(g1, 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);
     }
 
@@ -246,7 +245,7 @@
         GraphCostPhase gc2 = new GraphCostPhase();
         gc1.apply(g1, 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.finalSize == gc1.finalSize);
     }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PhiCreationTests.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PhiCreationTests.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,13 +22,12 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Assert;
-import org.junit.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.AllowAssumptions;
 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.
@@ -70,7 +69,8 @@
     @Test
     public void test3() {
         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());
     }
 
@@ -86,7 +86,8 @@
     @Test
     public void test4() {
         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());
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushNodesThroughPiTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushNodesThroughPiTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,15 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import jdk.vm.ci.meta.ResolvedJavaField;
-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.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.nodes.ParameterNode;
 import org.graalvm.compiler.nodes.PiNode;
@@ -44,6 +36,12 @@
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.common.LoweringPhase;
 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 {
 
@@ -77,7 +75,8 @@
     @SuppressWarnings("try")
     public void test1() {
         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);
             for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
                 OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
@@ -96,7 +95,7 @@
 
             Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,15 +22,14 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.FrameState;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.nodes.util.GraphUtil;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 public class PushThroughIfTest extends GraalCompilerTest {
 
@@ -59,7 +58,8 @@
 
     private void test(String snippet, String reference) {
         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()) {
             fs.replaceAtUsages(null);
             GraphUtil.killWithUnusedFloatingInputs(fs);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ReadAfterCheckCastTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ReadAfterCheckCastTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,11 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.nodes.ParameterNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
@@ -37,6 +33,8 @@
 import org.graalvm.compiler.phases.common.FloatingReadPhase;
 import org.graalvm.compiler.phases.common.LoweringPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Assert;
+import org.junit.Test;
 
 /* consider
  *     B b = (B) a;
@@ -84,7 +82,8 @@
 
     @SuppressWarnings("try")
     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
             // structure changes significantly
             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
@@ -94,7 +93,7 @@
             new FloatingReadPhase().apply(graph);
             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)) {
                 // Checking that the parameter a is not directly used for the access to field
@@ -102,7 +101,7 @@
                 Assert.assertTrue(node.getLocationIdentity().isImmutable());
             }
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ScalarTypeSystemTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ScalarTypeSystemTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,13 +22,12 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.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.AllowAssumptions;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 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
@@ -131,7 +130,7 @@
     private void test(final String snippet, final String referenceSnippet) {
         // No debug scope to reduce console noise for @Test(expected = ...) tests
         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());
         new CanonicalizerPhase().apply(graph, context);
         StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SchedulingTest2.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SchedulingTest2.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,10 +24,8 @@
 
 import java.util.List;
 
-import org.junit.Test;
-
 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.NodeMap;
 import org.graalvm.compiler.nodes.BeginNode;
@@ -51,6 +49,7 @@
 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
 import org.graalvm.compiler.phases.tiers.MidTierContext;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 public class SchedulingTest2 extends GraphScheduleTest {
 
@@ -65,11 +64,12 @@
     @Test
     public void testValueProxyInputs() {
         StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
+        DebugContext debug = graph.getDebug();
         ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
         BeginNode beginNode = graph.add(new BeginNode());
         returnNode.replaceAtPredecessor(beginNode);
         beginNode.setNext(returnNode);
-        Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");
+        debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
         SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST);
         schedulePhase.apply(graph);
         ScheduleResult schedule = graph.getLastSchedule();
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SimpleCFGTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/SimpleCFGTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,10 +22,7 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.graalvm.compiler.debug.Debug;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.AbstractBeginNode;
 import org.graalvm.compiler.nodes.AbstractMergeNode;
 import org.graalvm.compiler.nodes.BeginNode;
@@ -37,16 +34,23 @@
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.nodes.cfg.Block;
 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 {
 
     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
     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 falseEnd = graph.add(new EndNode());
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StaticInterfaceFieldTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StaticInterfaceFieldTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -23,19 +23,19 @@
 package org.graalvm.compiler.core.test;
 
 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
-import static org.graalvm.compiler.debug.DelegatingDebugConfig.Feature.INTERCEPT;
 
 import java.lang.reflect.Method;
 
 import org.graalvm.compiler.api.test.Graal;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugConfigScope;
-import org.graalvm.compiler.debug.DelegatingDebugConfig;
+import org.graalvm.compiler.debug.DebugCloseable;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 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.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.PhaseSuite;
 import org.graalvm.compiler.phases.VerifyPhase;
@@ -90,11 +90,13 @@
 
         final Method m = getMethod(clazz, methodName);
         ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
-        StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
-        try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); Debug.Scope ds = Debug.scope("GraphBuilding", graph, method)) {
+        OptionValues options = getInitialOptions();
+        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);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StraighteningTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/StraighteningTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,13 +22,12 @@
  */
 package org.graalvm.compiler.core.test;
 
-import org.junit.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.AllowAssumptions;
 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 public class StraighteningTest extends GraalCompilerTest {
 
@@ -88,7 +87,8 @@
     private void test(final String snippet) {
         // No debug scope to reduce console noise for @Test(expected = ...) tests
         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()));
         StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
         assertEquals(referenceGraph, graph);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/TypeSystemTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/TypeSystemTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -28,7 +28,7 @@
 import java.io.IOException;
 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.graph.Node;
 import org.graalvm.compiler.nodeinfo.Verbosity;
@@ -179,7 +179,8 @@
 
     private void test(String snippet, String referenceSnippet) {
         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,
          * tail-duplication gets activated thus resulting in a graph with more nodes than the
@@ -198,9 +199,10 @@
 
     @Override
     protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
+        DebugContext debug = graph.getDebug();
         if (getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
-            Debug.dump(Debug.BASIC_LEVEL, expected, "expected (node count)");
-            Debug.dump(Debug.BASIC_LEVEL, graph, "graph (node count)");
+            debug.dump(DebugContext.BASIC_LEVEL, expected, "expected (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());
         }
     }
@@ -243,7 +245,8 @@
         StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
         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());
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,6 +27,7 @@
 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.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.junit.Test;
 import org.objectweb.asm.ClassWriter;
@@ -85,7 +86,8 @@
     private void checkForBailout(String name) throws ClassNotFoundException {
         ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
         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());
             GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
             OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsageTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsageTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,19 +27,19 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
-import org.junit.Test;
-
 import org.graalvm.compiler.api.test.Graal;
 import org.graalvm.compiler.core.common.PermanentBailoutException;
 import org.graalvm.compiler.core.common.RetryableBailoutException;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugConfigScope;
+import org.graalvm.compiler.debug.DebugCloseable;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 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.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.Phase;
 import org.graalvm.compiler.phases.PhaseSuite;
@@ -48,6 +48,7 @@
 import org.graalvm.compiler.phases.util.Providers;
 import org.graalvm.compiler.phases.verify.VerifyBailoutUsage;
 import org.graalvm.compiler.runtime.RuntimeProvider;
+import org.junit.Test;
 
 import jdk.vm.ci.code.BailoutException;
 import jdk.vm.ci.meta.MetaAccessProvider;
@@ -125,12 +126,14 @@
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
+        OptionValues options = getInitialOptions();
+        DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
         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();
+                StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
                 graphBuilderSuite.apply(graph, context);
-                try (DebugConfigScope s = Debug.disableIntercept()) {
+                try (DebugCloseable s = debug.disableIntercept()) {
                     new VerifyBailoutUsage().apply(graph, context);
                 }
             }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsageTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsageTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -27,11 +27,10 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
-import org.junit.Test;
-
 import org.graalvm.compiler.api.test.Graal;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugConfigScope;
+import org.graalvm.compiler.debug.DebugCloseable;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.debug.Indent;
 import org.graalvm.compiler.graph.Node;
@@ -40,6 +39,7 @@
 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.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.Phase;
 import org.graalvm.compiler.phases.PhaseSuite;
@@ -48,6 +48,7 @@
 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;
@@ -58,8 +59,9 @@
 
         @Override
         protected void run(StructuredGraph graph) {
+            DebugContext debug = graph.getDebug();
             for (Node n : graph.getNodes()) {
-                Debug.log("%s", n.toString());
+                debug.log("%s", n.toString());
             }
         }
 
@@ -70,9 +72,10 @@
         @Override
         @SuppressWarnings("try")
         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()) {
-                    Debug.log("%s", n);
+                    debug.log("%s", n);
                 }
             }
         }
@@ -83,7 +86,8 @@
 
         @Override
         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 @@
 
         @Override
         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 @@
 
         @Override
         protected void run(StructuredGraph graph) {
-            Debug.dump(getLevel(), graph, "%s", graph);
+            DebugContext debug = graph.getDebug();
+            debug.dump(getLevel(), graph, "%s", graph);
         }
 
         int getLevel() {
@@ -111,7 +117,8 @@
 
         @Override
         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 @@
 
         @Override
         protected void run(StructuredGraph graph) {
+            DebugContext debug = graph.getDebug();
             for (Node n : graph.getNodes()) {
-                Debug.log("error " + n);
+                debug.log("error " + n);
             }
         }
 
@@ -132,9 +140,10 @@
         @Override
         @SuppressWarnings("try")
         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()) {
-                    Debug.log("%s", n);
+                    debug.log("%s", n);
                 }
             }
         }
@@ -145,7 +154,8 @@
 
         @Override
         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 @@
 
         @Override
         protected void run(StructuredGraph graph) {
-            Debug.verify(graph, "error " + graph);
+            DebugContext debug = graph.getDebug();
+            debug.verify(graph, "error " + graph);
         }
 
     }
@@ -163,8 +174,9 @@
 
         @Override
         protected void run(StructuredGraph graph) {
+            DebugContext debug = graph.getDebug();
             for (Node n : graph.getNodes()) {
-                Debug.log("%s", n);
+                debug.log("%s", n);
             }
         }
 
@@ -175,9 +187,10 @@
         @Override
         @SuppressWarnings("try")
         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()) {
-                    Debug.log("%s", n);
+                    debug.log("%s", n);
                 }
             }
         }
@@ -188,7 +201,8 @@
 
         @Override
         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 @@
 
         @Override
         protected void run(StructuredGraph graph) {
-            Debug.verify(graph, "%s", graph);
+            DebugContext debug = graph.getDebug();
+            debug.verify(graph, "%s", graph);
         }
 
     }
@@ -332,12 +347,14 @@
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
+        OptionValues options = getInitialOptions();
+        DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
         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();
+                StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
                 graphBuilderSuite.apply(graph, context);
-                try (DebugConfigScope s = Debug.disableIntercept()) {
+                try (DebugCloseable s = debug.disableIntercept()) {
                     new VerifyDebugUsage().apply(graph, context);
                 }
             }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyVirtualizableTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyVirtualizableTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -29,12 +29,11 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
-import org.junit.Test;
-
 import org.graalvm.compiler.api.test.Graal;
 import org.graalvm.compiler.core.common.type.StampFactory;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugConfigScope;
+import org.graalvm.compiler.debug.DebugCloseable;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.NodeClass;
 import org.graalvm.compiler.java.GraphBuilderPhase;
 import org.graalvm.compiler.nodeinfo.NodeInfo;
@@ -47,6 +46,7 @@
 import org.graalvm.compiler.nodes.java.ArrayLengthNode;
 import org.graalvm.compiler.nodes.spi.Virtualizable;
 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
+import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.PhaseSuite;
 import org.graalvm.compiler.phases.VerifyPhase.VerificationError;
@@ -54,6 +54,7 @@
 import org.graalvm.compiler.phases.util.Providers;
 import org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage;
 import org.graalvm.compiler.runtime.RuntimeProvider;
+import org.junit.Test;
 
 import jdk.vm.ci.meta.MetaAccessProvider;
 import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -270,12 +271,14 @@
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
         graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
         HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
+        OptionValues options = getInitialOptions();
+        DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
         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();
+                StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
                 graphBuilderSuite.apply(graph, context);
-                try (DebugConfigScope s = Debug.disableIntercept()) {
+                try (DebugCloseable s = debug.disableIntercept()) {
                     new VerifyVirtualizableUsage().apply(graph, context);
                 }
             }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,15 +24,8 @@
 
 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.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.lir.LIR;
 import org.graalvm.compiler.lir.LIRInstruction;
 import org.graalvm.compiler.lir.LIRValueUtil;
@@ -40,23 +33,29 @@
 import org.graalvm.compiler.lir.ValueProcedure;
 import org.graalvm.compiler.nodes.StructuredGraph;
 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 {
 
     @SuppressWarnings("try")
     protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
         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());
-            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("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
                 Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/BackendTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/BackendTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,16 +22,15 @@
  */
 package org.graalvm.compiler.core.test.backend;
 
-import jdk.vm.ci.code.Architecture;
-
 import org.graalvm.compiler.core.GraalCompiler;
 import org.graalvm.compiler.core.test.GraalCompilerTest;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 
+import jdk.vm.ci.code.Architecture;
+
 public abstract class BackendTest extends GraalCompilerTest {
 
     public BackendTest() {
@@ -44,10 +43,11 @@
 
     @SuppressWarnings("try")
     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()));
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
 
         LIRGenerationResult lirGen = GraalCompiler.emitLIR(getBackend(), graph, null, null, createLIRSuites(graph.getOptions()));
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);
-        }
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest1.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest2.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest3.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest4.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest5.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +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 MethodMetricsTest5 extends MethodMetricsTest {
-
-    @Override
-    protected Phase additionalPhase() {
-        return new MethodMetricPhases.CountingDivPhase();
-    }
-
-    @Override
-    DebugConfig getConfig() {
-        return overrideGraalDebugConfig(System.out, "MethodMetricsTest$TestApplication.*", "CountingDivPhase");
-    }
-
-    @Override
-    void assertValues() throws Throwable {
-        assertValues("Divs", new long[]{0, 0, 0, 0, 0, 0, 0, 0, 1, 0});
-    }
-
-    @Override
-    @Test
-    public void test() throws Throwable {
-        super.test();
-    }
-
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTest6.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTestInterception01.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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});
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/MethodMetricsTestInterception02.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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});
-    }
-
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/debug/VerifyMethodMetricsTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);
-                }
-            }
-        }
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/MonitorDeoptTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/MonitorDeoptTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -189,7 +189,7 @@
         removeLoopSafepoint(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();
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/SynchronizedMethodDeoptimizationTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/deopt/SynchronizedMethodDeoptimizationTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,6 +22,7 @@
  */
 package org.graalvm.compiler.core.test.deopt;
 
+import org.junit.Assume;
 import org.junit.Test;
 
 import org.graalvm.compiler.core.test.GraalCompilerTest;
@@ -44,6 +45,9 @@
 
     @Test
     public void test1() {
+        // https://bugs.openjdk.java.net/browse/JDK-8182755
+        Assume.assumeTrue(Java8OrEarlier);
+
         test("testMethodSynchronized", "test");
         test("testMethodSynchronized", (Object) null);
     }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/EATestBase.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/EATestBase.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,14 +24,8 @@
 
 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.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.nodes.ReturnNode;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
@@ -43,6 +37,10 @@
 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
 import org.graalvm.compiler.phases.tiers.HighTierContext;
 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
 
@@ -154,8 +152,9 @@
     @SuppressWarnings("try")
     protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
         ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
-        try (Scope s = Debug.scope(getClass(), method, getCodeCache())) {
-            graph = parseEager(method, AllowAssumptions.YES);
+        DebugContext debug = getDebugContext();
+        try (DebugContext.Scope s = debug.scope(getClass(), method, getCodeCache())) {
+            graph = parseEager(method, AllowAssumptions.YES, debug);
             context = getDefaultHighTierContext();
             new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
             new DeadCodeEliminationPhase().apply(graph);
@@ -163,7 +162,7 @@
             new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
             returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PoorMansEATest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PoorMansEATest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,11 +22,8 @@
  */
 package org.graalvm.compiler.core.test.ea;
 
-import org.junit.Test;
-
 import org.graalvm.compiler.core.test.GraalCompilerTest;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.FrameState;
@@ -40,6 +37,7 @@
 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
 import org.graalvm.compiler.phases.tiers.HighTierContext;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.junit.Test;
 
 /**
  * Tests {@link AbstractNewObjectNode#simplify(org.graalvm.compiler.graph.spi.SimplifierTool)}.
@@ -63,7 +61,8 @@
 
     @SuppressWarnings("try")
     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);
             HighTierContext highTierContext = getDefaultHighTierContext();
             new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
@@ -82,7 +81,7 @@
             }
             new CanonicalizerPhase().apply(graph, context);
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/InliningTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/InliningTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,21 +22,15 @@
  */
 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.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.nodes.FullInfopointNode;
 import org.graalvm.compiler.nodes.Invoke;
 import org.graalvm.compiler.nodes.StructuredGraph;
 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.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.PhaseSuite;
@@ -44,6 +38,11 @@
 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
 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 {
 
@@ -236,24 +235,26 @@
 
     @SuppressWarnings("try")
     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);
-            StructuredGraph graph = eagerInfopointMode ? parseDebug(method, AllowAssumptions.YES) : parseEager(method, AllowAssumptions.YES);
-            try (Scope s2 = Debug.scope("Inlining", graph)) {
+            Builder builder = builder(method, AllowAssumptions.YES, debug);
+            StructuredGraph graph = eagerInfopointMode ? parse(builder, getDebugGraphBuilderSuite()) : parse(builder, getEagerGraphBuilderSuite());
+            try (DebugContext.Scope s2 = debug.scope("Inlining", graph)) {
                 PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode
                                 ? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true))
                                 : getDefaultGraphBuilderSuite();
                 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 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 DeadCodeEliminationPhase().apply(graph);
                 return graph;
             }
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/NestedLoopEffectsPhaseComplexityTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/inlining/NestedLoopEffectsPhaseComplexityTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -25,13 +25,14 @@
 import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Optional;
 
 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.graph.Node;
 import org.graalvm.compiler.nodes.Invoke;
 import org.graalvm.compiler.nodes.StructuredGraph;
 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
+import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.phases.BasePhase;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.PhaseSuite;
@@ -100,10 +101,9 @@
     }
 
     private void testAndTime(String snippet) {
-        initializeForTimeout();
         for (int i = InliningCountLowerBound; i < InliningCountUpperBound; i++) {
             StructuredGraph g1 = prepareGraph(snippet, i);
-            StructuredGraph g2 = (StructuredGraph) g1.copy();
+            StructuredGraph g2 = (StructuredGraph) g1.copy(g1.getDebug());
             ResolvedJavaMethod method = g1.method();
             long elapsedRE = runAndTimePhase(g1, new EarlyReadEliminationPhase(new CanonicalizerPhase()));
             long elapsedPEA = runAndTimePhase(g2, new PartialEscapePhase(true, new CanonicalizerPhase(), g1.getOptions()));
@@ -121,7 +121,8 @@
         long start = System.currentTimeMillis();
         phase.apply(g, context);
         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;
     }
 
@@ -138,13 +139,14 @@
             next = callerGraph.getNodes(MethodCallTargetNode.TYPE).first().invoke();
             EconomicSet<Node> canonicalizeNodes = InliningUtil.inlineForCanonicalization(next, calleeGraph, false, calleeMethod);
             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;
     }
 
-    private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
-        StructuredGraph newGraph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.NO).method(method).build();
+    private StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
+        OptionValues options = getInitialOptions();
+        StructuredGraph newGraph = new StructuredGraph.Builder(options, getDebugContext(options), AllowAssumptions.NO).method(method).build();
         context.getGraphBuilderSuite().apply(newGraph, context);
         new DeadCodeEliminationPhase(Optional).apply(newGraph);
         canonicalizer.apply(newGraph, context);
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/InvokeGraal.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/InvokeGraal.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,6 +24,7 @@
 
 import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
+
 import java.lang.reflect.Method;
 
 import org.graalvm.compiler.api.test.Graal;
@@ -31,8 +32,8 @@
 import org.graalvm.compiler.core.GraalCompiler;
 import org.graalvm.compiler.core.common.CompilationIdentifier;
 import org.graalvm.compiler.core.target.Backend;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugHandlersFactory;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.DebugDumpScope;
 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
 import org.graalvm.compiler.lir.phases.LIRSuites;
@@ -85,7 +86,8 @@
         /* Create a unique compilation identifier, visible in IGV. */
         CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
         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
@@ -93,7 +95,7 @@
              * that we want the compilation to make optimistic assumptions about runtime state such
              * 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
@@ -131,9 +133,9 @@
              * Install the compilation result into the VM, i.e., copy the byte[] array that contains
              * 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) {
-            throw Debug.handle(ex);
+            throw debug.handle(ex);
         }
     }
 
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java	Fri Jul 07 09:40:47 2017 -0700
@@ -32,9 +32,9 @@
 import java.util.Map;
 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.Debug.Scope;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.NodeMap;
 import org.graalvm.compiler.java.GraphBuilderPhase;
@@ -58,6 +58,7 @@
 import org.graalvm.compiler.nodes.java.StoreFieldNode;
 import org.graalvm.compiler.nodes.spi.StampProvider;
 import org.graalvm.compiler.nodes.util.GraphUtil;
+import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.phases.OptimisticOptimizations;
 import org.graalvm.compiler.phases.graph.StatelessPostOrderNodeIterator;
 
@@ -240,12 +241,14 @@
                  * 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
                  * 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
                      * referenced by the bytecodes to be loaded and initialized. Since we do not run
@@ -271,7 +274,7 @@
                     GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(metaAccess, stampProvider, null, null, graphBuilderConfig, optimisticOpts, null);
                     graphBuilder.apply(graph);
                 } catch (Throwable ex) {
-                    Debug.handle(ex);
+                    debug.handle(ex);
                 }
 
                 /*
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThread.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThread.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,42 +22,21 @@
  */
 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
- * context of a thread-local {@linkplain GraalDebugConfig debug configuration}.
+ * A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY}.
  */
 public class CompilerThread extends Thread {
 
-    private final DebugConfigAccess debugConfigAccess;
-
-    public CompilerThread(Runnable r, String namePrefix, DebugConfigAccess debugConfigAccess) {
+    public CompilerThread(Runnable r, String namePrefix) {
         super(r);
         this.setName(namePrefix + "-" + this.getId());
         this.setPriority(Thread.MAX_PRIORITY);
         this.setDaemon(true);
-        this.debugConfigAccess = debugConfigAccess;
     }
 
     @Override
     public void run() {
-        DebugConfig debugConfig = debugConfigAccess.getDebugConfig();
         setContextClassLoader(getClass().getClassLoader());
-        try {
-            super.run();
-        } finally {
-            if (debugConfig != null) {
-                for (DebugDumpHandler dumpHandler : debugConfig.dumpHandlers()) {
-                    try {
-                        dumpHandler.close();
-                    } catch (Throwable t) {
-                    }
-                }
-            }
-        }
+        super.run();
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThreadFactory.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilerThreadFactory.java	Fri Jul 07 09:40:47 2017 -0700
@@ -24,34 +24,19 @@
 
 import java.util.concurrent.ThreadFactory;
 
-import org.graalvm.compiler.debug.DebugConfig;
-
 /**
  * Facility for creating {@linkplain CompilerThread compiler threads}.
  */
 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.debugConfigAccess = debugConfigAccess;
     }
 
     @Override
     public Thread newThread(Runnable r) {
-        return new CompilerThread(r, threadNamePrefix, debugConfigAccess);
+        return new CompilerThread(r, threadNamePrefix);
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/GraalCompiler.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/GraalCompiler.java	Fri Jul 07 09:40:47 2017 -0700
@@ -33,14 +33,12 @@
 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
 import org.graalvm.compiler.core.common.util.CompilationAlarm;
 import org.graalvm.compiler.core.target.Backend;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.CounterKey;
 import org.graalvm.compiler.debug.DebugCloseable;
-import org.graalvm.compiler.debug.DebugCounter;
-import org.graalvm.compiler.debug.DebugTimer;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 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.alloc.OutOfRegistersException;
 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
@@ -85,11 +83,11 @@
  */
 public class GraalCompiler {
 
-    private static final DebugTimer CompilerTimer = Debug.timer("GraalCompiler");
-    private static final DebugTimer FrontEnd = Debug.timer("FrontEnd");
-    private static final DebugTimer BackEnd = Debug.timer("BackEnd");
-    private static final DebugTimer EmitLIR = Debug.timer("EmitLIR");
-    private static final DebugTimer EmitCode = Debug.timer("EmitCode");
+    private static final TimerKey CompilerTimer = DebugContext.timer("GraalCompiler").doc("Time spent in compilation (excludes code installation).");
+    private static final TimerKey FrontEnd = DebugContext.timer("FrontEnd").doc("Time spent processing HIR.");
+    private static final TimerKey EmitLIR = DebugContext.timer("EmitLIR").doc("Time spent generating LIR from HIR.");
+    private static final TimerKey EmitCode = DebugContext.timer("EmitCode").doc("Time spent generating machine code from LIR.");
+    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}.
@@ -167,14 +165,14 @@
      */
     @SuppressWarnings("try")
     public static <T extends CompilationResult> T compile(Request<T> r) {
-        try (Scope s = MethodMetricsRootScopeInfo.createRootScopeIfAbsent(r.installedCodeOwner);
-                        CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
+        DebugContext debug = r.graph.getDebug();
+        try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
             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);
                 emitBackEnd(r.graph, null, r.installedCodeOwner, r.backend, r.compilationResult, r.factory, null, r.lirSuites);
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
             checkForRequestedCrash(r.graph);
             return r.compilationResult;
@@ -217,32 +215,33 @@
     @SuppressWarnings("try")
     public static void emitFrontEnd(Providers providers, TargetProvider target, StructuredGraph graph, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts,
                     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);
             if (graph.start().next() == null) {
                 graphBuilderSuite.apply(graph, highTierContext);
                 new DeadCodeEliminationPhase(DeadCodeEliminationPhase.Optionality.Optional).apply(graph);
-                Debug.dump(Debug.BASIC_LEVEL, graph, "After parsing");
+                debug.dump(DebugContext.BASIC_LEVEL, graph, "After parsing");
             } else {
-                Debug.dump(Debug.INFO_LEVEL, graph, "initial state");
+                debug.dump(DebugContext.INFO_LEVEL, graph, "initial state");
             }
 
             suites.getHighTier().apply(graph, highTierContext);
             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);
             suites.getMidTier().apply(graph, midTierContext);
             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);
             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) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         } finally {
             graph.checkCancellation();
         }
@@ -251,18 +250,19 @@
     @SuppressWarnings("try")
     public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult,
                     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;
             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();
                 compilationResult.setHasUnsafeAccess(graph.hasUnsafeAccess());
                 emitCode(backend, graph.getAssumptions(), graph.method(), graph.getMethods(), graph.getFields(), bytecodeSize, lirGen, compilationResult, installedCodeOwner, factory);
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         } finally {
             graph.checkCancellation();
         }
@@ -289,7 +289,8 @@
     @SuppressWarnings("try")
     private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites,
                     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();
             ScheduleResult schedule = graph.getLastSchedule();
             Block[] blocks = schedule.getCFG().getBlocks();
@@ -299,7 +300,7 @@
 
             AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(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);
             LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
@@ -310,16 +311,16 @@
             LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
             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)
-                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));
                 return result;
             } catch (Throwable e) {
-                throw Debug.handle(e);
+                throw debug.handle(e);
             }
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         } finally {
             graph.checkCancellation();
         }
@@ -338,17 +339,18 @@
 
     public static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGenerationResult lirGenRes, LIRGeneratorTool lirGen, LIRSuites lirSuites,
                     RegisterAllocationConfig registerAllocationConfig) {
+        DebugContext debug = lirGenRes.getLIR().getDebug();
         PreAllocationOptimizationContext preAllocOptContext = new PreAllocationOptimizationContext(lirGen);
         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);
         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);
         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;
     }
@@ -357,7 +359,8 @@
     public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields,
                     int bytecodeSize, LIRGenerationResult lirGenRes,
                     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();
             CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
             backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
@@ -370,12 +373,12 @@
                 compilationResult.setBytecodeSize(bytecodeSize);
             }
             crb.finish();
-            if (Debug.isCountEnabled()) {
+            if (debug.isCountEnabled()) {
                 List<DataPatch> ldp = compilationResult.getDataPatches();
                 JavaKind[] kindValues = JavaKind.values();
-                DebugCounter[] dms = new DebugCounter[kindValues.length];
+                CounterKey[] dms = new CounterKey[kindValues.length];
                 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) {
@@ -386,17 +389,17 @@
                             kind = ((JavaConstant) constant).getJavaKind();
                         }
                     }
-                    dms[kind.ordinal()].add(1);
+                    dms[kind.ordinal()].add(debug, 1);
                 }
 
-                Debug.counter("CompilationResults").increment();
-                Debug.counter("CodeBytesEmitted").add(compilationResult.getTargetCodeSize());
-                Debug.counter("InfopointsEmitted").add(compilationResult.getInfopoints().size());
-                Debug.counter("DataPatches").add(ldp.size());
-                Debug.counter("ExceptionHandlersEmitted").add(compilationResult.getExceptionHandlers().size());
+                DebugContext.counter("CompilationResults").increment(debug);
+                DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
+                DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
+                DebugContext.counter("DataPatches").add(debug, ldp.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");
         }
     }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/GraalDebugInitializationParticipant.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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.");
-        }
-    }
-}
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/LIRGenerationPhase.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,9 +26,10 @@
 
 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
 import org.graalvm.compiler.core.common.cfg.BlockMap;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugCounter;
+import org.graalvm.compiler.debug.CounterKey;
+import org.graalvm.compiler.debug.DebugContext;
 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.LIRGeneratorTool;
 import org.graalvm.compiler.lir.phases.LIRPhase;
@@ -56,8 +57,8 @@
         }
     }
 
-    private static final DebugCounter instructionCounter = Debug.counter("GeneratedLIRInstructions");
-    private static final DebugCounter nodeCount = Debug.counter("FinalNodeCount");
+    private static final CounterKey instructionCounter = DebugContext.counter("GeneratedLIRInstructions");
+    private static final CounterKey nodeCount = DebugContext.counter("FinalNodeCount");
 
     @Override
     protected final void run(TargetDescription target, LIRGenerationResult lirGenRes, LIRGenerationPhase.LIRGenerationContext context) {
@@ -69,18 +70,16 @@
         }
         context.lirGen.beforeRegisterAllocation();
         assert SSAUtil.verifySSAForm(lirGenRes.getLIR());
-        if (nodeCount.isEnabled()) {
-            nodeCount.add(graph.getNodeCount());
-        }
+        nodeCount.add(graph.getDebug(), graph.getNodeCount());
     }
 
     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 verifyPredecessors(lirGenRes, b);
         nodeLirGen.doBlock(b, graph, blockMap);
-        if (instructionCounter.isEnabled()) {
-            instructionCounter.add(lirGenRes.getLIR().getLIRforBlock(b).size());
-        }
+        LIR lir = lirGenRes.getLIR();
+        DebugContext debug = lir.getDebug();
+        instructionCounter.add(debug, lir.getLIRforBlock(b).size());
     }
 
     private static boolean verifyPredecessors(LIRGenerationResult lirGenRes, Block block) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/DebugInfoBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/DebugInfoBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,8 +26,8 @@
 import java.util.Arrays;
 import java.util.Queue;
 
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugCounter;
+import org.graalvm.compiler.debug.CounterKey;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.lir.ConstantValue;
 import org.graalvm.compiler.lir.LIRFrameState;
@@ -42,8 +42,8 @@
 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
 import org.graalvm.compiler.virtual.nodes.MaterializedObjectState;
 import org.graalvm.compiler.virtual.nodes.VirtualObjectState;
+import org.graalvm.util.EconomicMap;
 import org.graalvm.util.Equivalence;
-import org.graalvm.util.EconomicMap;
 
 import jdk.vm.ci.code.BytecodeFrame;
 import jdk.vm.ci.code.VirtualObject;
@@ -61,9 +61,11 @@
 public class DebugInfoBuilder {
 
     protected final NodeValueMap nodeValueMap;
+    protected final DebugContext debug;
 
-    public DebugInfoBuilder(NodeValueMap nodeValueMap) {
+    public DebugInfoBuilder(NodeValueMap nodeValueMap, DebugContext debug) {
         this.nodeValueMap = nodeValueMap;
+        this.debug = debug;
     }
 
     private static final JavaValue[] NO_JAVA_VALUES = {};
@@ -276,10 +278,10 @@
         return toJavaValue(state.lockAt(i));
     }
 
-    private static final DebugCounter STATE_VIRTUAL_OBJECTS = Debug.counter("StateVirtualObjects");
-    private static final DebugCounter STATE_ILLEGALS = Debug.counter("StateIllegals");
-    private static final DebugCounter STATE_VARIABLES = Debug.counter("StateVariables");
-    private static final DebugCounter STATE_CONSTANTS = Debug.counter("StateConstants");
+    private static final CounterKey STATE_VIRTUAL_OBJECTS = DebugContext.counter("StateVirtualObjects");
+    private static final CounterKey STATE_ILLEGALS = DebugContext.counter("StateIllegals");
+    private static final CounterKey STATE_VARIABLES = DebugContext.counter("StateVariables");
+    private static final CounterKey STATE_CONSTANTS = DebugContext.counter("StateConstants");
 
     private static JavaKind toSlotKind(ValueNode value) {
         if (value == null) {
@@ -308,18 +310,18 @@
                         virtualObjects.put(obj, vobject);
                         pendingVirtualObjects.add(obj);
                     }
-                    STATE_VIRTUAL_OBJECTS.increment();
+                    STATE_VIRTUAL_OBJECTS.increment(debug);
                     return vobject;
                 }
             } else {
                 // Remove proxies from constants so the constant can be directly embedded.
                 ValueNode unproxied = GraphUtil.unproxify(value);
                 if (unproxied instanceof ConstantNode) {
-                    STATE_CONSTANTS.increment();
+                    STATE_CONSTANTS.increment(debug);
                     return unproxied.asJavaConstant();
 
                 } else if (value != null) {
-                    STATE_VARIABLES.increment();
+                    STATE_VARIABLES.increment(debug);
                     Value operand = nodeValueMap.operand(value);
                     if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
                         return ((ConstantValue) operand).getJavaConstant();
@@ -330,7 +332,7 @@
 
                 } else {
                     // return a dummy value because real value not needed
-                    STATE_ILLEGALS.increment();
+                    STATE_ILLEGALS.increment(debug);
                     return Value.ILLEGAL;
                 }
             }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,12 +26,13 @@
 import static jdk.vm.ci.code.ValueUtil.isLegal;
 import static jdk.vm.ci.code.ValueUtil.isRegister;
 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 java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+
 import org.graalvm.compiler.core.common.LIRKind;
 import org.graalvm.compiler.core.common.calc.Condition;
 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
@@ -41,8 +42,7 @@
 import org.graalvm.compiler.core.match.MatchPattern;
 import org.graalvm.compiler.core.match.MatchRuleRegistry;
 import org.graalvm.compiler.core.match.MatchStatement;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.debug.TTY;
 import org.graalvm.compiler.graph.GraalGraphError;
@@ -135,7 +135,7 @@
         this.debugInfoBuilder = createDebugInfoBuilder(graph, this);
         OptionValues options = graph.getOptions();
         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);
 
@@ -147,9 +147,8 @@
         return nodeMatchRules;
     }
 
-    @SuppressWarnings({"unused"})
     protected DebugInfoBuilder createDebugInfoBuilder(StructuredGraph graph, NodeValueMap nodeValueMap) {
-        return new DebugInfoBuilder(nodeValueMap);
+        return new DebugInfoBuilder(nodeValueMap, graph.getDebug());
     }
 
     /**
@@ -351,6 +350,7 @@
             for (int i = 0; i < nodes.size(); i++) {
                 Node node = nodes.get(i);
                 if (node instanceof ValueNode) {
+                    DebugContext debug = node.getDebug();
                     ValueNode valueNode = (ValueNode) node;
                     if (trace) {
                         TTY.println("LIRGen for " + valueNode);
@@ -368,9 +368,9 @@
                         }
                     } else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
                         // 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) {
-                        Debug.log("complex match for %s", valueNode);
+                        debug.log("complex match for %s", valueNode);
                         ComplexMatchValue match = (ComplexMatchValue) operand;
                         operand = match.evaluate(this);
                         if (operand != null) {
@@ -403,11 +403,12 @@
     @SuppressWarnings("try")
     protected void matchComplexExpressions(List<Node> nodes) {
         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())) {
                     int i = 0;
                     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 @@
             TTY.println("Emitting LIR for instruction " + instr);
         }
         currentInstruction = instr;
-
-        Debug.log("Visiting %s", instr);
+        DebugContext debug = instr.getDebug();
+        debug.log("Visiting %s", 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) {
-        if (Debug.isLogEnabled() && node.stamp().isEmpty()) {
-            Debug.log("This node has an empty stamp, we are emitting dead code(?): %s", node);
+        if (node.getDebug().isLogEnabled() && node.stamp().isEmpty()) {
+            node.getDebug().log("This node has an empty stamp, we are emitting dead code(?): %s", node);
         }
         setSourcePosition(node.getNodeSourcePosition());
         if (node instanceof LIRLowerable) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,7 +22,7 @@
  */
 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.Arrays;
@@ -30,13 +30,13 @@
 
 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
 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.graph.Node;
 import org.graalvm.compiler.nodes.calc.FloatingNode;
 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
+import org.graalvm.util.EconomicMap;
 import org.graalvm.util.Equivalence;
-import org.graalvm.util.EconomicMap;
 
 /**
  * Container for state captured during a match.
@@ -110,10 +110,11 @@
                 continue;
             } else if ((consumed == null || !consumed.contains(node)) && node != root) {
                 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++) {
                         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());
@@ -130,9 +131,10 @@
      */
     public void setResult(ComplexMatchResult result) {
         ComplexMatchValue value = new ComplexMatchValue(result);
-        if (Debug.isLogEnabled()) {
-            Debug.log("matched %s %s", rule.getName(), rule.getPattern());
-            Debug.log("with nodes %s", rule.formatMatch(root));
+        DebugContext debug = root.getDebug();
+        if (debug.isLogEnabled()) {
+            debug.log("matched %s %s", rule.getName(), rule.getPattern());
+            debug.log("with nodes %s", rule.formatMatch(root));
         }
         if (consumed != null) {
             for (Node node : consumed) {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchPattern.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchPattern.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,8 +22,8 @@
  */
 package org.graalvm.compiler.core.match;
 
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugCounter;
+import org.graalvm.compiler.debug.CounterKey;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.Node;
 import org.graalvm.compiler.graph.Position;
 import org.graalvm.compiler.nodeinfo.InputType;
@@ -62,12 +62,12 @@
             this.matcher = matcher;
         }
 
-        private static final DebugCounter MatchResult_WRONG_CLASS = Debug.counter("MatchResult_WRONG_CLASS");
-        private static final DebugCounter MatchResult_NAMED_VALUE_MISMATCH = Debug.counter("MatchResult_NAMED_VALUE_MISMATCH");
-        private static final DebugCounter MatchResult_TOO_MANY_USERS = Debug.counter("MatchResult_TOO_MANY_USERS");
-        private static final DebugCounter MatchResult_NOT_IN_BLOCK = Debug.counter("MatchResult_NOT_IN_BLOCK");
-        private static final DebugCounter MatchResult_NOT_SAFE = Debug.counter("MatchResult_NOT_SAFE");
-        private static final DebugCounter MatchResult_ALREADY_USED = Debug.counter("MatchResult_ALREADY_USED");
+        private static final CounterKey MatchResult_WRONG_CLASS = DebugContext.counter("MatchResult_WRONG_CLASS");
+        private static final CounterKey MatchResult_NAMED_VALUE_MISMATCH = DebugContext.counter("MatchResult_NAMED_VALUE_MISMATCH");
+        private static final CounterKey MatchResult_TOO_MANY_USERS = DebugContext.counter("MatchResult_TOO_MANY_USERS");
+        private static final CounterKey MatchResult_NOT_IN_BLOCK = DebugContext.counter("MatchResult_NOT_IN_BLOCK");
+        private static final CounterKey MatchResult_NOT_SAFE = DebugContext.counter("MatchResult_NOT_SAFE");
+        private static final CounterKey MatchResult_ALREADY_USED = DebugContext.counter("MatchResult_ALREADY_USED");
 
         static final Result OK = new Result(MatchResultCode.OK, null, null);
         private static final Result CACHED_WRONG_CLASS = new Result(MatchResultCode.WRONG_CLASS, null, null);
@@ -78,33 +78,33 @@
         private static final Result CACHED_ALREADY_USED = new Result(MatchResultCode.ALREADY_USED, null, null);
 
         static Result wrongClass(Node node, MatchPattern matcher) {
-            MatchResult_WRONG_CLASS.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS;
+            MatchResult_WRONG_CLASS.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS;
         }
 
         static Result namedValueMismatch(Node node, MatchPattern matcher) {
-            MatchResult_NAMED_VALUE_MISMATCH.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH;
+            MatchResult_NAMED_VALUE_MISMATCH.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH;
         }
 
         static Result tooManyUsers(Node node, MatchPattern matcher) {
-            MatchResult_TOO_MANY_USERS.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS;
+            MatchResult_TOO_MANY_USERS.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS;
         }
 
         static Result notInBlock(Node node, MatchPattern matcher) {
-            MatchResult_NOT_IN_BLOCK.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK;
+            MatchResult_NOT_IN_BLOCK.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK;
         }
 
         static Result notSafe(Node node, MatchPattern matcher) {
-            MatchResult_NOT_SAFE.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE;
+            MatchResult_NOT_SAFE.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE;
         }
 
         static Result alreadyUsed(Node node, MatchPattern matcher) {
-            MatchResult_ALREADY_USED.increment();
-            return Debug.isLogEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED;
+            MatchResult_ALREADY_USED.increment(node.getDebug());
+            return node.getDebug().isLogEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED;
         }
 
         @Override
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchRuleRegistry.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchRuleRegistry.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,13 +22,13 @@
  */
 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.List;
 
 import org.graalvm.compiler.core.gen.NodeMatchRules;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.debug.GraalError;
 import org.graalvm.compiler.graph.Edges;
 import org.graalvm.compiler.graph.Node;
@@ -36,8 +36,8 @@
 import org.graalvm.compiler.graph.Position;
 import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.serviceprovider.GraalServices;
+import org.graalvm.util.EconomicMap;
 import org.graalvm.util.Equivalence;
-import org.graalvm.util.EconomicMap;
 import org.graalvm.util.MapCursor;
 
 public class MatchRuleRegistry {
@@ -77,7 +77,7 @@
      * @return the set of {@link MatchStatement}s applicable to theClass.
      */
     @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);
 
         if (result == null) {
@@ -87,13 +87,13 @@
             result = rules;
 
             if (LogVerbose.getValue(options)) {
-                try (Scope s = Debug.scope("MatchComplexExpressions")) {
-                    Debug.log("Match rules for %s", theClass.getSimpleName());
+                try (DebugContext.Scope s = debug.scope("MatchComplexExpressions")) {
+                    debug.log("Match rules for %s", theClass.getSimpleName());
                     MapCursor<Class<? extends Node>, List<MatchStatement>> cursor = result.getEntries();
                     while (cursor.advance()) {
-                        Debug.log("  For node class: %s", cursor.getKey());
+                        debug.log("  For node class: %s", cursor.getKey());
                         for (MatchStatement statement : cursor.getValue()) {
-                            Debug.log("    %s", statement.getPattern());
+                            debug.log("    %s", statement.getPattern());
                         }
                     }
                 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchStatement.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchStatement.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,28 +22,28 @@
  */
 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 jdk.vm.ci.meta.Value;
-
 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
 import org.graalvm.compiler.core.match.MatchPattern.MatchResultCode;
 import org.graalvm.compiler.core.match.MatchPattern.Result;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.DebugCounter;
+import org.graalvm.compiler.debug.CounterKey;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.GraalGraphError;
 import org.graalvm.compiler.graph.Node;
 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
  * one or more {@link Node}s with a single {@link Value}.
  */
 
 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
@@ -83,6 +83,7 @@
      *         evaluated by the NodeLIRBuilder.
      */
     public boolean generate(NodeLIRBuilder builder, int index, Node node, List<Node> nodes) {
+        DebugContext debug = node.getDebug();
         assert index == nodes.indexOf(node);
         // Check that the basic shape matches
         Result result = pattern.matchShape(node, this);
@@ -97,19 +98,19 @@
             ComplexMatchResult value = generatorMethod.match(builder.getNodeMatchRules(), buildArgList(context));
             if (value != null) {
                 context.setResult(value);
-                MatchStatementSuccess.increment();
-                Debug.counter("MatchStatement[%s]", getName()).increment();
+                MatchStatementSuccess.increment(debug);
+                DebugContext.counter("MatchStatement[%s]", getName()).increment(debug);
                 return true;
             }
             // The pattern matched but some other code generation constraint disallowed code
             // generation for the pattern.
             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("with nodes %s", formatMatch(node));
+                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));
             }
         } else {
             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;
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/EconomyCompilerConfiguration.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/EconomyCompilerConfiguration.java	Fri Jul 07 09:40:47 2017 -0700
@@ -60,7 +60,7 @@
 
     @Override
     public LIRPhaseSuite<AllocationContext> createAllocationStage(OptionValues options) {
-        return new EconomyAllocationStage();
+        return new EconomyAllocationStage(options);
     }
 
     @Override
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/GraphChangeMonitoringPhase.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/GraphChangeMonitoringPhase.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,8 +22,7 @@
  */
 package org.graalvm.compiler.core.phases;
 
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.graph.Graph.NodeEvent;
 import org.graalvm.compiler.graph.Graph.NodeEventScope;
 import org.graalvm.compiler.graph.Node;
@@ -33,8 +32,8 @@
 import org.graalvm.compiler.phases.PhaseSuite;
 import org.graalvm.compiler.phases.common.util.HashSetNodeEventListener;
 import org.graalvm.compiler.phases.tiers.PhaseContext;
+import org.graalvm.util.EconomicSet;
 import org.graalvm.util.Equivalence;
-import org.graalvm.util.EconomicSet;
 
 /**
  * A utility phase for detecting when a phase would change the graph and reporting extra information
@@ -68,12 +67,13 @@
          * having their inputs change are the main interesting differences.
          */
         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 (Scope s2 = Debug.sandbox("WithoutMonitoring", null)) {
+            try (DebugContext.Scope s2 = debug.sandbox("WithoutMonitoring", null)) {
                 super.run(graphCopy, context);
             } catch (Throwable t) {
-                Debug.handle(t);
+                debug.handle(t);
             }
         }
 
@@ -90,15 +90,15 @@
             /* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
             listener = new HashSetNodeEventListener();
             try (NodeEventScope s = graph.trackNodeEvents(listener)) {
-                try (Scope s2 = Debug.scope("WithGraphChangeMonitoring")) {
-                    if (Debug.isDumpEnabled(Debug.DETAILED_LEVEL)) {
-                        Debug.dump(Debug.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
+                try (DebugContext.Scope s2 = debug.scope("WithGraphChangeMonitoring")) {
+                    if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
+                        debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
                     }
                     super.run(graph, context);
-                    if (Debug.isDumpEnabled(Debug.DETAILED_LEVEL)) {
-                        Debug.dump(Debug.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
+                    if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
+                        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 {
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/MidTier.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/phases/MidTier.java	Fri Jul 07 09:40:47 2017 -0700
@@ -26,9 +26,14 @@
 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.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.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.ReassociateInvariantPhase;
 import org.graalvm.compiler.nodes.spi.LoweringTool;
@@ -79,6 +84,12 @@
 
         appendPhase(new FrameStateAssignmentPhase());
 
+        LoopPolicies loopPolicies = createLoopPolicies();
+        if (OptLoopTransform.getValue(options)) {
+            if (PartialUnroll.getValue(options)) {
+                appendPhase(new LoopPartialUnrollPhase(loopPolicies, canonicalizer));
+            }
+        }
         if (ReassociateInvariants.getValue(options)) {
             appendPhase(new ReassociateInvariantPhase());
         }
@@ -89,4 +100,8 @@
 
         appendPhase(canonicalizer);
     }
+
+    public LoopPolicies createLoopPolicies() {
+        return new DefaultLoopPolicies();
+    }
 }
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/target/Backend.java	Fri Jul 07 10:37:52 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/target/Backend.java	Fri Jul 07 09:40:47 2017 -0700
@@ -22,6 +22,8 @@
  */
 package org.graalvm.compiler.core.target;
 
+import java.util.ArrayList;
+
 import org.graalvm.compiler.asm.Assembler;
 import org.graalvm.compiler.code.CompilationResult;
 import org.graalvm.compiler.core.common.CompilationIdentifier;
@@ -29,8 +31,7 @@
 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
-import org.graalvm.compiler.debug.Debug;
-import org.graalvm.compiler.debug.Debug.Scope;
+import org.graalvm.compiler.debug.DebugContext;
 import org.graalvm.compiler.lir.LIR;
 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
@@ -60,8 +61,6 @@
 import jdk.vm.ci.meta.ResolvedJavaMethod;
 import jdk.vm.ci.meta.SpeculationLog;
 
-import java.util.ArrayList;
-
 /**
  * Represents a compiler backend for Graal.
  */
@@ -155,22 +154,22 @@
     protected abstract CompiledCode createCompiledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult);
 
     /**
-     * @see #createInstalledCode(ResolvedJavaMethod, CompilationRequest, CompilationResult,
-     *      SpeculationLog, InstalledCode, boolean)
+     * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
+     *      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) {
-        return createInstalledCode(method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault);
+        return createInstalledCode(debug, method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
     }
 
     /**
-     * @see #createInstalledCode(ResolvedJavaMethod, CompilationRequest, CompilationResult,
-     *      SpeculationLog, InstalledCode, boolean, Object[])
+     * @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
+     *      CompilationResult, SpeculationLog, InstalledCode, boolean, Object[])
      */
     @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) {
-        return createInstalledCode(method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
+        return createInstalledCode(debug, method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
     }
 
     /**
@@ -188,19 +187,20 @@
      *            {@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 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
      * @throws BailoutException if the code installation failed
      */
     @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) {
         Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult};
         CodeInstallationTask[] tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
         for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
             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) {
                 task.preProcess(compilationResult);
             }
@@ -222,7 +222,7 @@
             }
             return installedCode;
         } catch (Throwable e) {
-            throw Debug.handle(e);
+            throw debug.handle(e);
         }
     }
 
@@ -236,8 +236,8 @@
      * @return a reference to the compiled and ready-to-run installed code
      * @throws BailoutException if the code installation failed
      */
-    public InstalledCode addInstalledCode(ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) {
-        return createInstalledCode(method, compilationRequest, compilationResult, null, null, false);
+    public InstalledCode addInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) {
+        return createInstalledCode(debug, method, compilationRequest, compilationResult, null, null, false);
     }
 
     /**
@@ -250,8 +250,8 @@
      * @return a reference to the compiled and ready-to-run installed code
      * @throws BailoutException if the code installation failed
      */
-    public InstalledCode createDefaultInstalledCode(ResolvedJavaMethod method, CompilationResult compilationResult) {
-        return createInstalledCode(method, compilationResult, null, null, true);
+    public InstalledCode createDefaultInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult) {
+        return createInstalledCode(debug, method, compilationResult, null, null, true);
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugContextTest.java	Fri Jul 07 09:40:47 2017 -0700
@@ -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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugContextTest.testLogging.input	Fri Jul 07 09:40:47 2017 -0700
@@ -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
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugHistogramTest.java	Fri Jul 07 10:37:52 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);