changeset 4354:3abb137806c7

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 17 Jan 2012 23:35:39 +0100
parents 043bec543161 (diff) 2bc254976621 (current diff)
children 636e2fcbbe32
files mx/benchmarkdb.py
diffstat 42 files changed, 809 insertions(+), 863 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiResult.java	Tue Jan 17 20:35:49 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, 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 com.oracle.max.cri.ci;
-
-/**
- * Represents the result of compiling a method. The result can include a target method with machine code and metadata,
- * and/or statistics. If the compiler bailed out due to malformed bytecode, an internal error, or other cause, it will
- * supply the bailout object.
- */
-public class CiResult {
-    private final CiTargetMethod targetMethod;
-    private final CiBailout bailout;
-
-    /**
-     * Creates a new compilation result.
-     * @param targetMethod the method that was produced, if any
-     * @param bailout the bailout condition that occurred
-     * @param stats statistics about the compilation
-     */
-    public CiResult(CiTargetMethod targetMethod, CiBailout bailout) {
-        this.targetMethod = targetMethod;
-        this.bailout = bailout;
-    }
-
-    /**
-     * Gets the target method that was produced by this compilation. If no target method was
-     * produced, but a bailout occured, then the bailout exception will be thrown at this point.
-     * @return the target method produced
-     * @throws {@link CiBailout} if a bailout occurred
-     */
-    public CiTargetMethod targetMethod() {
-        if (bailout != null) {
-            throw bailout;
-        }
-        return targetMethod;
-    }
-
-    /**
-     * Returns the bailout condition that occurred for this compilation, if any.
-     * @return the bailout
-     */
-    public CiBailout bailout() {
-        return bailout;
-    }
-}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/DataFlowAnalysis.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/DataFlowAnalysis.java	Tue Jan 17 23:35:39 2012 +0100
@@ -35,21 +35,20 @@
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.lir.LIRInstruction.ValueProcedure;
 import com.oracle.max.graal.compiler.schedule.*;
+import com.oracle.max.graal.debug.*;
 
 public class DataFlowAnalysis {
-    private final GraalContext context;
     private final LIR lir;
     private final RiRegisterConfig registerConfig;
 
-    public DataFlowAnalysis(GraalContext context, LIR lir, RiRegisterConfig registerConfig) {
-        this.context = context;
+    public DataFlowAnalysis(LIR lir, RiRegisterConfig registerConfig) {
         this.lir = lir;
         this.registerConfig = registerConfig;
     }
 
     public void execute() {
         numberInstructions();
-        context.observable.fireCompilationEvent("After instruction numbering", lir);
+        Debug.dump(lir, "After instruction numbering");
         backwardDataFlow();
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java	Tue Jan 17 23:35:39 2012 +0100
@@ -39,20 +39,19 @@
 import com.oracle.max.graal.compiler.lir.LIRPhiMapping.PhiValueProcedure;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 public class SpillAllAllocator {
-    private final GraalContext context;
     private final LIR lir;
     private final FrameMap frameMap;
 
     private final DataFlowAnalysis dataFlow;
 
-    public SpillAllAllocator(GraalContext context, LIR lir, FrameMap frameMap) {
-        this.context = context;
+    public SpillAllAllocator(LIR lir, FrameMap frameMap) {
         this.lir = lir;
         this.frameMap = frameMap;
 
-        this.dataFlow = new DataFlowAnalysis(context, lir, frameMap.registerConfig);
+        this.dataFlow = new DataFlowAnalysis(lir, frameMap.registerConfig);
         this.blockLocations = new LocationMap[lir.linearScanOrder().size()];
         this.moveResolver = new MoveResolverImpl(frameMap);
     }
@@ -137,18 +136,18 @@
         allocate();
         frameMap.finish();
 
-        context.observable.fireCompilationEvent("After spill all allocation", lir);
+        Debug.dump(lir, "After spill all allocation");
 
         ResolveDataFlow resolveDataFlow = new ResolveDataFlowImpl(lir, moveResolver);
         resolveDataFlow.execute();
 
-        context.observable.fireCompilationEvent("After resolve data flow", lir);
+        Debug.dump(lir, "After resolve data flow");
         assert RegisterVerifier.verify(lir, frameMap);
 
         AssignRegisters assignRegisters = new AssignRegistersImpl(lir, frameMap);
         assignRegisters.execute();
 
-        context.observable.fireCompilationEvent("After register asignment", lir);
+        Debug.dump(lir, "After register asignment");
         assert LIRVerifier.verify(true, lir, frameMap);
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jan 17 23:35:39 2012 +0100
@@ -23,6 +23,7 @@
 package com.oracle.max.graal.compiler;
 
 import java.util.*;
+import java.util.concurrent.*;
 
 import com.oracle.max.asm.*;
 import com.oracle.max.cri.ci.*;
@@ -34,19 +35,17 @@
 import com.oracle.max.graal.compiler.asm.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
-import com.oracle.max.graal.compiler.observer.*;
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.target.*;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
 public class GraalCompiler {
 
-    public final GraalContext context;
-
     /**
      * The target that this compiler has been configured for.
      */
@@ -67,8 +66,7 @@
      */
     public final Backend backend;
 
-    public GraalCompiler(GraalContext context, GraalRuntime runtime, CiTarget target, Backend backend, RiXirGenerator xirGen) {
-        this.context = context;
+    public GraalCompiler(GraalRuntime runtime, CiTarget target, Backend backend, RiXirGenerator xirGen) {
         this.runtime = runtime;
         this.target = target;
         this.xir = xirGen;
@@ -79,177 +77,120 @@
         return compileMethod(method, new StructuredGraph(method), osrBCI, plan);
     }
 
-    public CiTargetMethod compileMethod(RiResolvedMethod method, StructuredGraph graph, int osrBCI, PhasePlan plan) {
+    public CiTargetMethod compileMethod(final RiResolvedMethod method, final StructuredGraph graph, int osrBCI, final PhasePlan plan) {
         if (osrBCI != -1) {
             throw new CiBailout("No OSR supported");
         }
-        context.timers.startScope(getClass());
-        try {
-            long startTime = 0;
-            int index = context.metrics.CompiledMethods++;
-            final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
-            if (printCompilation) {
-                TTY.println(String.format("Graal %4d %-70s %-45s %-50s ...",
-                                index,
-                                method.holder().name(),
-                                method.name(),
-                                method.signature().asString()));
-                startTime = System.nanoTime();
-            }
-            TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method);
-
-            CiTargetMethod result = null;
-            context.observable.fireCompilationStarted(runtime, target, method);
-            try {
-                try {
-                    CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null;
-                    LIR lir = emitHIR(graph, assumptions, plan);
-                    FrameMap frameMap = emitLIR(lir, graph, method);
-                    result = emitCode(assumptions, method, lir, frameMap);
-
-                    if (GraalOptions.Meter) {
-                        context.metrics.BytecodesCompiled += method.codeSize();
-                    }
-                } catch (CiBailout bailout) {
-                    throw bailout;
-                } catch (Throwable t) {
-                    throw new GraalInternalError(t);
+        return Debug.scope("CompileMethod", method, new Callable<CiTargetMethod>() {
+                public CiTargetMethod call() {
+                        final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null;
+                        LIR lir = Debug.scope("EmitHIR", graph, new Callable<LIR>() {
+                            public LIR call() {
+                                return emitHIR(graph, assumptions, plan);
+                            }
+                        });
+                        FrameMap frameMap = emitLIR(lir, graph, method);
+                        return emitCode(assumptions, method, lir, frameMap);
                 }
-            } catch (GraalInternalError error) {
-                error.addContext("method", CiUtil.format("%H.%n(%p):%r", method));
-                if (context.isObserved()) {
-                    if (error.node() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Node " + error.node(), CompilationEvent.ERROR, this, error.node().graph());
-                    } else if (error.graph() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Graph " + error.graph(), CompilationEvent.ERROR, this, error.graph());
-                    }
-                }
-                throw error;
-            } finally {
-                context.observable.fireCompilationFinished(runtime, target, method);
-                filter.remove();
-                if (printCompilation) {
-                    long time = (System.nanoTime() - startTime) / 100000;
-                    TTY.println(String.format("Graal %4d %-70s %-45s %-50s | %3d.%dms %4dnodes %5dB",
-                                    index,
-                                    "",
-                                    "",
-                                    "",
-                                    time / 10,
-                                    time % 10,
-                                    graph.getNodeCount(),
-                                    (result != null ? result.targetCodeSize() : -1)));
-                }
-            }
-
-            return result;
-        } finally {
-            context.timers.endScope();
-        }
+        });
     }
 
     /**
      * Builds the graph, optimizes it.
      */
     public LIR emitHIR(StructuredGraph graph, CiAssumptions assumptions, PhasePlan plan) {
-        try {
-            context.timers.startScope("HIR");
+
+        if (graph.start().next() == null) {
+            plan.runPhases(PhasePosition.AFTER_PARSING, graph);
+            new DeadCodeEliminationPhase().apply(graph);
+        } else {
+            Debug.dump(graph, "initial state");
+        }
 
-            if (graph.start().next() == null) {
-                plan.runPhases(PhasePosition.AFTER_PARSING, graph, context);
-                new DeadCodeEliminationPhase().apply(graph, context);
-            } else {
-                if (context.isObserved()) {
-                    context.observable.fireCompilationEvent("initial state", graph);
-                }
-            }
+        new PhiStampPhase().apply(graph);
 
-            new PhiStampPhase().apply(graph);
+        if (GraalOptions.ProbabilityAnalysis && graph.start().probability() == 0) {
+            new ComputeProbabilityPhase().apply(graph);
+        }
 
-            if (GraalOptions.ProbabilityAnalysis && graph.start().probability() == 0) {
-                new ComputeProbabilityPhase().apply(graph, context);
-            }
-
-            if (GraalOptions.Intrinsify) {
-                new IntrinsificationPhase(runtime).apply(graph, context);
-            }
+        if (GraalOptions.Intrinsify) {
+            new IntrinsificationPhase(runtime).apply(graph);
+        }
 
-            if (GraalOptions.Inline && !plan.isPhaseDisabled(InliningPhase.class)) {
-                new InliningPhase(target, runtime, null, assumptions, plan).apply(graph, context);
-                new DeadCodeEliminationPhase().apply(graph, context);
-                new PhiStampPhase().apply(graph);
-            }
+        if (GraalOptions.Inline && !plan.isPhaseDisabled(InliningPhase.class)) {
+            new InliningPhase(target, runtime, null, assumptions, plan).apply(graph);
+            new DeadCodeEliminationPhase().apply(graph);
+            new PhiStampPhase().apply(graph);
+        }
 
-            if (GraalOptions.OptCanonicalizer) {
-                new CanonicalizerPhase(target, runtime, assumptions).apply(graph, context);
-            }
+        if (GraalOptions.OptCanonicalizer) {
+            new CanonicalizerPhase(target, runtime, assumptions).apply(graph);
+        }
 
-            plan.runPhases(PhasePosition.HIGH_LEVEL, graph, context);
+        plan.runPhases(PhasePosition.HIGH_LEVEL, graph);
 
-            if (GraalOptions.OptLoops) {
-                graph.mark();
-                new FindInductionVariablesPhase().apply(graph, context);
-                if (GraalOptions.OptCanonicalizer) {
-                    new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph, context);
-                }
-                new SafepointPollingEliminationPhase().apply(graph, context);
+        if (GraalOptions.OptLoops) {
+            graph.mark();
+            new FindInductionVariablesPhase().apply(graph);
+            if (GraalOptions.OptCanonicalizer) {
+                new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph);
             }
+            new SafepointPollingEliminationPhase().apply(graph);
+        }
 
-            if (GraalOptions.EscapeAnalysis && !plan.isPhaseDisabled(EscapeAnalysisPhase.class)) {
-                new EscapeAnalysisPhase(target, runtime, assumptions, plan).apply(graph, context);
-                new PhiStampPhase().apply(graph);
-                new CanonicalizerPhase(target, runtime, assumptions).apply(graph, context);
-            }
+        if (GraalOptions.EscapeAnalysis && !plan.isPhaseDisabled(EscapeAnalysisPhase.class)) {
+            new EscapeAnalysisPhase(target, runtime, assumptions, plan).apply(graph);
+            new PhiStampPhase().apply(graph);
+            new CanonicalizerPhase(target, runtime, assumptions).apply(graph);
+        }
 
-            if (GraalOptions.OptGVN) {
-                new GlobalValueNumberingPhase().apply(graph, context);
-            }
+        if (GraalOptions.OptGVN) {
+            new GlobalValueNumberingPhase().apply(graph);
+        }
 
-            graph.mark();
-            new LoweringPhase(runtime).apply(graph, context);
-            new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph, context);
+        graph.mark();
+        new LoweringPhase(runtime).apply(graph);
+        new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph);
 
-            if (GraalOptions.OptLoops) {
-                graph.mark();
-                new RemoveInductionVariablesPhase().apply(graph, context);
-                if (GraalOptions.OptCanonicalizer) {
-                    new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph, context);
-                }
+        if (GraalOptions.OptLoops) {
+            graph.mark();
+            new RemoveInductionVariablesPhase().apply(graph);
+            if (GraalOptions.OptCanonicalizer) {
+                new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph);
             }
-
-            if (GraalOptions.Lower) {
-                new FloatingReadPhase().apply(graph, context);
-                if (GraalOptions.OptReadElimination) {
-                    new ReadEliminationPhase().apply(graph, context);
-                }
-            }
-            new RemovePlaceholderPhase().apply(graph, context);
-            new DeadCodeEliminationPhase().apply(graph, context);
+        }
 
-            plan.runPhases(PhasePosition.MID_LEVEL, graph, context);
-
-            plan.runPhases(PhasePosition.LOW_LEVEL, graph, context);
+        if (GraalOptions.Lower) {
+            new FloatingReadPhase().apply(graph);
+            if (GraalOptions.OptReadElimination) {
+                new ReadEliminationPhase().apply(graph);
+            }
+        }
+        new RemovePlaceholderPhase().apply(graph);
+        new DeadCodeEliminationPhase().apply(graph);
 
-            IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY);
-            schedule.apply(graph, context);
+        plan.runPhases(PhasePosition.MID_LEVEL, graph);
 
-            if (context.isObserved()) {
-                context.observable.fireCompilationEvent("After IdentifyBlocksPhase", graph, schedule);
-            }
+        plan.runPhases(PhasePosition.LOW_LEVEL, graph);
+
+        final IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY);
+        schedule.apply(graph);
 
-            List<Block> blocks = schedule.getBlocks();
-            NodeMap<LIRBlock> valueToBlock = new NodeMap<>(graph);
-            for (Block b : blocks) {
-                for (Node i : b.getInstructions()) {
-                    valueToBlock.set(i, (LIRBlock) b);
-                }
+        final List<Block> blocks = schedule.getBlocks();
+        final NodeMap<LIRBlock> valueToBlock = new NodeMap<>(graph);
+        for (Block b : blocks) {
+            for (Node i : b.getInstructions()) {
+                valueToBlock.set(i, (LIRBlock) b);
             }
-            LIRBlock startBlock = valueToBlock.get(graph.start());
-            assert startBlock != null;
-            assert startBlock.numberOfPreds() == 0;
+        }
+        final LIRBlock startBlock = valueToBlock.get(graph.start());
+        assert startBlock != null;
+        assert startBlock.numberOfPreds() == 0;
 
-            context.timers.startScope("Compute Linear Scan Order");
-            try {
+        return Debug.scope("Compute Linear Scan Order", new Callable<LIR>() {
+
+            @Override
+            public LIR call() {
                 ComputeLinearScanOrder clso = new ComputeLinearScanOrder(blocks.size(), schedule.loopCount(), startBlock);
                 List<LIRBlock> linearScanOrder = clso.linearScanOrder();
                 List<LIRBlock> codeEmittingOrder = clso.codeEmittingOrder();
@@ -260,36 +201,19 @@
                 }
 
                 LIR lir = new LIR(startBlock, linearScanOrder, codeEmittingOrder, valueToBlock, schedule.loopCount());
-
-                if (context.isObserved()) {
-                    context.observable.fireCompilationEvent("After linear scan order", graph, lir);
-                }
+                Debug.dump(lir, "After linear scan order");
                 return lir;
-            } catch (AssertionError t) {
-                    context.observable.fireCompilationEvent("AssertionError in ComputeLinearScanOrder", CompilationEvent.ERROR, graph);
-                throw t;
-            } catch (RuntimeException t) {
-                    context.observable.fireCompilationEvent("RuntimeException in ComputeLinearScanOrder", CompilationEvent.ERROR, graph);
-                throw t;
-            } finally {
-                context.timers.endScope();
+
             }
-        } finally {
-            context.timers.endScope();
-        }
+        });
     }
 
     public FrameMap emitLIR(LIR lir, StructuredGraph graph, RiResolvedMethod method) {
-        context.timers.startScope("LIR");
-        try {
-            if (GraalOptions.GenLIR) {
-                context.timers.startScope("Create LIR");
                 LIRGenerator lirGenerator = null;
                 FrameMap frameMap;
-                try {
                     frameMap = backend.newFrameMap(runtime.getRegisterConfig(method));
 
-                    lirGenerator = backend.newLIRGenerator(context, graph, frameMap, method, lir, xir);
+                    lirGenerator = backend.newLIRGenerator(graph, frameMap, method, lir, xir);
 
                     for (LIRBlock b : lir.linearScanOrder()) {
                         lirGenerator.doBlock(b);
@@ -300,70 +224,38 @@
                             b.phis.fillInputs(lirGenerator);
                         }
                     }
-                } finally {
-                    context.timers.endScope();
-                }
 
-                if (context.isObserved()) {
-                    context.observable.fireCompilationEvent("After LIR generation", graph, lir, lirGenerator);
-                }
+                Debug.dump(lirGenerator, "After LIR generation");
                 if (GraalOptions.PrintLIR && !TTY.isSuppressed()) {
                     LIR.printLIR(lir.linearScanOrder());
                 }
 
                 if (GraalOptions.AllocSSA) {
-                    new SpillAllAllocator(context, lir, frameMap).execute();
+                    new SpillAllAllocator(lir, frameMap).execute();
                 } else {
-                    new LinearScan(context, target, method, graph, lir, lirGenerator, frameMap).allocate();
+                    new LinearScan(target, method, graph, lir, lirGenerator, frameMap).allocate();
                 }
                 return frameMap;
-            } else {
-                return null;
-            }
-        } catch (Error e) {
-            if (context.isObserved() && GraalOptions.PlotOnError) {
-                context.observable.fireCompilationEvent(e.getClass().getSimpleName() + " in emitLIR", CompilationEvent.ERROR, graph);
-            }
-            throw e;
-        } catch (RuntimeException e) {
-            if (context.isObserved() && GraalOptions.PlotOnError) {
-                context.observable.fireCompilationEvent(e.getClass().getSimpleName() + " in emitLIR", CompilationEvent.ERROR, graph);
-            }
-            throw e;
-        } finally {
-            context.timers.endScope();
-        }
     }
 
     private TargetMethodAssembler createAssembler(FrameMap frameMap, LIR lir) {
         AbstractAssembler masm = backend.newAssembler(frameMap.registerConfig);
-        TargetMethodAssembler tasm = new TargetMethodAssembler(context, target, runtime, frameMap, lir.slowPaths, masm);
+        TargetMethodAssembler tasm = new TargetMethodAssembler(target, runtime, frameMap, lir.slowPaths, masm);
         tasm.setFrameSize(frameMap.frameSize());
         tasm.targetMethod.setCustomStackAreaOffset(frameMap.offsetToCustomArea());
         return tasm;
     }
 
     public CiTargetMethod emitCode(CiAssumptions assumptions, RiResolvedMethod method, LIR lir, FrameMap frameMap) {
-        if (GraalOptions.GenLIR && GraalOptions.GenCode) {
-            context.timers.startScope("Create Code");
-            try {
-                TargetMethodAssembler tasm = createAssembler(frameMap, lir);
-                lir.emitCode(tasm);
+        TargetMethodAssembler tasm = createAssembler(frameMap, lir);
+        lir.emitCode(tasm);
 
-                CiTargetMethod targetMethod = tasm.finishTargetMethod(method, false);
-                if (assumptions != null && !assumptions.isEmpty()) {
-                    targetMethod.setAssumptions(assumptions);
-                }
-
-                if (context.isObserved()) {
-                    context.observable.fireCompilationEvent("After code generation", lir, targetMethod);
-                }
-                return targetMethod;
-            } finally {
-                context.timers.endScope();
-            }
+        CiTargetMethod targetMethod = tasm.finishTargetMethod(method, false);
+        if (assumptions != null && !assumptions.isEmpty()) {
+            targetMethod.setAssumptions(assumptions);
         }
 
-        return null;
+        Debug.dump(targetMethod, "After code generation");
+        return targetMethod;
     }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalContext.java	Tue Jan 17 20:35:49 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2011, 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 com.oracle.max.graal.compiler;
-
-import com.oracle.max.criutils.*;
-import com.oracle.max.graal.compiler.observer.*;
-
-/**
- * This class is intended for non-essential stuff like statistics, observing, etc. It should not be used for anything
- * that has a direct influence on the result of a compilation!
- */
-public class GraalContext {
-
-    public static final GraalContext EMPTY_CONTEXT = new GraalContext("silent context");
-
-    public final ObservableContext observable = new ObservableContext();
-    public final GraalTimers timers = new GraalTimers();
-    public final GraalMetrics metrics = new GraalMetrics();
-
-    private final String name;
-
-    public GraalContext(String name) {
-        this.name = name;
-    }
-
-    public boolean isObserved() {
-        return observable.isObserved();
-    }
-
-    public void addCompilationObserver(CompilationObserver observer) {
-        observable.addCompilationObserver(observer);
-    }
-
-    public void print() {
-        if (GraalOptions.Meter || GraalOptions.Time) {
-            for (int i = 0; i < 22 + name.length(); i++) {
-                TTY.print('=');
-            }
-            TTY.println("\n========== " + name + " ==========");
-            if (GraalOptions.Meter) {
-                metrics.print();
-            }
-            if (GraalOptions.Time) {
-                timers.print();
-            }
-        }
-    }
-}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java	Tue Jan 17 20:35:49 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,202 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, 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 com.oracle.max.graal.compiler;
-
-import java.lang.reflect.*;
-import java.util.*;
-import java.util.Map.Entry;
-
-import com.oracle.max.criutils.*;
-
-
-/**
- * This class contains a number of fields that collect metrics about compilation, particularly
- * the number of times certain optimizations are performed.
- */
-public final class GraalMetrics {
-    // Checkstyle: stop
-    public int CompiledMethods;
-    public int TargetMethods;
-    public int LocalValueNumberHits;
-    public int ValueMapResizes;
-    public int InlinedFinalizerChecks;
-    public int InlineForcedMethods;
-    public int InlineForbiddenMethods;
-    public int InlineConsidered;
-    public int InlinePerformed;
-    public int InlineUncompiledConsidered;
-    public int InlineUncompiledPerformed;
-    public int BlocksDeleted;
-    public int BytecodesCompiled;
-    public int CodeBytesEmitted;
-    public int SafepointsEmitted;
-    public int ExceptionHandlersEmitted;
-    public int DataPatches;
-    public int DirectCallSitesEmitted;
-    public int IndirectCallSitesEmitted;
-    public int LiveHIRInstructions;
-    public int LIRInstructions;
-    public int LIRVariables;
-    public int LIRXIRInstructions;
-    public int LIRMoveInstructions;
-    public int LSRAIntervalsCreated;
-    public int LSRASpills;
-    public int LoadConstantIterations;
-    public int CodeBufferCopies;
-    public int UniqueValueIdsAssigned;
-    public int FrameStatesCreated;
-    public int FrameStateValuesCreated;
-    public int LoopsPeeled;
-    public int LoopsInverted;
-    public int PartialUsageProbability;
-    public int FullUsageProbability;
-    public int Rematerializations;
-    public int GlobalValueNumberingHits;
-    public int ExplicitExceptions;
-    public int GuardsHoisted;
-
-
-
-    /**
-     * The total number of bytes of bytecode parsed during this compilation, including any inlined methods.
-     */
-    public int bytecodeCount;
-
-    /**
-     * The number of internal graph nodes created during this compilation.
-     */
-    public int nodeCount;
-
-    /**
-     * The number of basic blocks created during this compilation.
-     */
-    public int blockCount;
-
-    /**
-     * The number of loops in the compiled method.
-     */
-    public int loopCount;
-
-    /**
-     * The number of methods inlined.
-     */
-    public int inlineCount;
-
-    /**
-     * The number of methods folded (i.e. evaluated).
-     */
-    public int foldCount;
-
-    /**
-     * The number of intrinsics inlined in this compilation.
-     */
-    public int intrinsicCount;
-
-
-    // Checkstyle: resume
-
-    public void print() {
-        for (Entry<String, MetricsEntry> m : map.entrySet()) {
-            printField(m.getKey(), m.getValue().value);
-        }
-        printFields(GraalMetrics.class);
-    }
-
-    public static class MetricsEntry {
-        public int value;
-
-        public void increment() {
-            increment(1);
-        }
-
-        public void increment(int val) {
-            value += val;
-        }
-    }
-
-    private LinkedHashMap<String, MetricsEntry> map = new LinkedHashMap<>();
-
-    public MetricsEntry get(String name) {
-        if (!map.containsKey(name)) {
-            map.put(name, new MetricsEntry());
-        }
-        return map.get(name);
-    }
-
-    public void printFields(Class<?> javaClass) {
-        final String className = javaClass.getSimpleName();
-        TTY.println(className + " {");
-        for (final Field field : javaClass.getFields()) {
-            printField(field, false);
-        }
-        TTY.println("}");
-    }
-
-    public void printField(final Field field, boolean tabbed) {
-        final String fieldName = String.format("%35s", field.getName());
-        try {
-            String prefix = tabbed ? "" : "    " + fieldName + " = ";
-            String postfix = tabbed ? "\t" : "\n";
-            if (field.getType() == int.class) {
-                TTY.print(prefix + field.getInt(this) + postfix);
-            } else if (field.getType() == boolean.class) {
-                TTY.print(prefix + field.getBoolean(this) + postfix);
-            } else if (field.getType() == float.class) {
-                TTY.print(prefix + field.getFloat(this) + postfix);
-            } else if (field.getType() == String.class) {
-                TTY.print(prefix + field.get(this) + postfix);
-            } else if (field.getType() == Map.class) {
-                Map<?, ?> m = (Map<?, ?>) field.get(this);
-                TTY.print(prefix + printMap(m) + postfix);
-            } else {
-                TTY.print(prefix + field.get(this) + postfix);
-            }
-        } catch (IllegalAccessException e) {
-            // do nothing.
-        }
-    }
-
-    private static String printMap(Map<?, ?> m) {
-        StringBuilder sb = new StringBuilder();
-
-        List<String> keys = new ArrayList<>();
-        for (Object key : m.keySet()) {
-            keys.add((String) key);
-        }
-        Collections.sort(keys);
-
-        for (String key : keys) {
-            sb.append(key);
-            sb.append("\t");
-            sb.append(m.get(key));
-            sb.append("\n");
-        }
-
-        return sb.toString();
-    }
-
-    private static void printField(String fieldName, long value) {
-        TTY.print("    " + fieldName + " = " + value + "\n");
-    }
-}
-
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jan 17 23:35:39 2012 +0100
@@ -126,8 +126,6 @@
     public static boolean AssumeVerifiedBytecode             = true;
 
     // Code generator settings
-    public static boolean GenLIR                             = true;
-    public static boolean GenCode                            = true;
     public static boolean UseBranchPrediction                = true;
     public static boolean UseExceptionProbability            = ____;
     public static boolean AllowExplicitExceptionChecks       = true;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Tue Jan 17 23:35:39 2012 +0100
@@ -24,10 +24,10 @@
 
 import java.util.*;
 
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 /**
  * This class performs basic optimizations on the control flow graph after LIR generation.
@@ -38,8 +38,8 @@
      * Performs control flow optimizations on the given LIR graph.
      * @param ir the LIR graph that should be optimized
      */
-    public static void optimize(LIR ir, GraalContext context) {
-        ControlFlowOptimizer optimizer = new ControlFlowOptimizer(ir, context);
+    public static void optimize(LIR ir) {
+        ControlFlowOptimizer optimizer = new ControlFlowOptimizer(ir);
         List<LIRBlock> code = ir.codeEmittingOrder();
         //optimizer.reorderShortLoops(code);
         optimizer.deleteEmptyBlocks(code);
@@ -48,11 +48,9 @@
     }
 
     private final LIR ir;
-    private final GraalContext context;
 
-    private ControlFlowOptimizer(LIR ir, GraalContext context) {
+    private ControlFlowOptimizer(LIR ir) {
         this.ir = ir;
-        this.context = context;
     }
 /*
     private void reorderShortLoop(List<LIRBlock> code, LIRBlock headerBlock, int headerIdx) {
@@ -123,7 +121,7 @@
             if (canDeleteBlock(block)) {
                 // adjust successor and predecessor lists
                 block.replaceWith(block.suxAt(0));
-                context.metrics.BlocksDeleted++;
+                Debug.metric("BlocksDeleted").increment();
             } else {
                 // adjust position of this block in the block list if blocks before
                 // have been deleted
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Tue Jan 17 23:35:39 2012 +0100
@@ -657,12 +657,9 @@
     /**
      * Sentinel interval to denote the end of an interval list.
      */
-    static final Interval EndMarker = new Interval(null, CiValue.IllegalValue, -1);
+    static final Interval EndMarker = new Interval(CiValue.IllegalValue, -1);
 
-    Interval(GraalContext context, CiValue operand, int operandNumber) {
-        if (GraalOptions.Meter && context != null) {
-            context.metrics.LSRAIntervalsCreated++;
-        }
+    Interval(CiValue operand, int operandNumber) {
         assert operand != null;
         this.operand = operand;
         this.operandNumber = operandNumber;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Tue Jan 17 23:35:39 2012 +0100
@@ -41,6 +41,7 @@
 import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandMode;
 import com.oracle.max.graal.compiler.lir.LIRInstruction.ValueProcedure;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -51,7 +52,6 @@
  */
 public final class LinearScan {
 
-    final GraalContext context;
     final CiTarget target;
     final RiMethod method;
     final LIR ir;
@@ -122,8 +122,7 @@
     private final StructuredGraph graph;
 
 
-    public LinearScan(GraalContext context, CiTarget target, RiResolvedMethod method, StructuredGraph graph, LIR ir, LIRGenerator gen, FrameMap frameMap) {
-        this.context = context;
+    public LinearScan(CiTarget target, RiResolvedMethod method, StructuredGraph graph, LIR ir, LIRGenerator gen, FrameMap frameMap) {
         this.target = target;
         this.method = method;
         this.graph = graph;
@@ -237,7 +236,7 @@
         assert isProcessed(operand);
         assert isLegal(operand);
         int operandNumber = operandNumber(operand);
-        Interval interval = new Interval(context, operand, operandNumber);
+        Interval interval = new Interval(operand, operandNumber);
         assert operandNumber < intervalsSize;
         assert intervals[operandNumber] == null;
         intervals[operandNumber] = interval;
@@ -288,7 +287,7 @@
     }
 
     int numLoops() {
-        return ir.loopCount();
+        return ir.numLoops();
     }
 
     boolean isIntervalInLoop(int interval, int loop) {
@@ -1619,7 +1618,7 @@
         // intervals that have no oops inside need not to be processed.
         // to ensure a walking until the last instruction id, add a dummy interval
         // with a high operation id
-        nonOopIntervals = new Interval(context, CiValue.IllegalValue, -1);
+        nonOopIntervals = new Interval(CiValue.IllegalValue, -1);
         nonOopIntervals.addRange(Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1);
 
         return new IntervalWalker(this, oopIntervals, nonOopIntervals);
@@ -1786,8 +1785,15 @@
         }
     }
 
+    private static final Debug.Timer timerLifetimeAnalysis = Debug.timer("LifetimeAnalysis");
+    private static final Debug.Timer timerLinearScan = Debug.timer("LinearScan");
+    private static final Debug.Timer timerLinearScanResolution = Debug.timer("LinearScanResolution");
+    private static final Debug.Timer timerDebugInfo = Debug.timer("DebugInfo");
+    private static final Debug.Timer timerControlFlowOptimizations = Debug.timer("ControlFlowOptimizations");
+
     public void allocate() {
-        context.timers.startScope("Lifetime Analysis");
+
+        timerLifetimeAnalysis.start();
         try {
             numberInstructions();
 
@@ -1799,27 +1805,27 @@
             buildIntervals();
             sortIntervalsBeforeAllocation();
         } finally {
-            context.timers.endScope();
+            timerLifetimeAnalysis.stop();
         }
 
-        context.timers.startScope("Linear Scan");
+        timerLinearScan.start();
         try {
             printIntervals("Before register allocation");
 
             allocateRegisters();
 
         } finally {
-            context.timers.endScope();
+            timerLinearScan.stop();
         }
 
-        context.timers.startScope("Resolution");
+        timerLinearScanResolution.start();
         try {
             resolveDataFlow();
         } finally {
-            context.timers.endScope();
+            timerLinearScanResolution.stop();
         }
 
-        context.timers.startScope("Create Debug Info");
+        timerDebugInfo.start();
         try {
             frameMap.finish();
 
@@ -1839,17 +1845,17 @@
                 verifyIntervals();
             }
         } finally {
-            context.timers.endScope();
+            timerDebugInfo.stop();
         }
 
-        context.timers.startScope("Control Flow Optimizations");
+        timerControlFlowOptimizations.start();
         try {
             printLir("After register number assignment", true);
             EdgeMoveOptimizer.optimize(ir.linearScanOrder());
-            ControlFlowOptimizer.optimize(ir, context);
+            ControlFlowOptimizer.optimize(ir);
             printLir("After control flow optimization", false);
         } finally {
-            context.timers.endScope();
+            timerControlFlowOptimizations.stop();
         }
     }
 
@@ -1875,9 +1881,7 @@
             TTY.println();
         }
 
-        if (context.isObserved()) {
-            context.observable.fireCompilationEvent(label, graph, this, Arrays.copyOf(intervals, intervalsSize));
-        }
+        Debug.dump(Arrays.copyOf(intervals, intervalsSize), label);
     }
 
     void printLir(String label, boolean hirValid) {
@@ -1888,9 +1892,7 @@
             TTY.println();
         }
 
-        if (context.isObserved()) {
-            context.observable.fireCompilationEvent(label, hirValid ? graph : null, ir);
-        }
+        Debug.dump(ir, label);
     }
 
     boolean verify() {
@@ -2027,7 +2029,7 @@
         fixedIntervals = createUnhandledLists(IS_PRECOLORED_INTERVAL, null).first;
         // to ensure a walking until the last instruction id, add a dummy interval
         // with a high operation id
-        otherIntervals = new Interval(context, CiValue.IllegalValue, -1);
+        otherIntervals = new Interval(CiValue.IllegalValue, -1);
         otherIntervals.addRange(Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1);
         IntervalWalker iw = new IntervalWalker(this, fixedIntervals, otherIntervals);
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Tue Jan 17 23:35:39 2012 +0100
@@ -34,6 +34,7 @@
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.lir.LIR.SlowPath;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 public class TargetMethodAssembler {
 
@@ -46,10 +47,7 @@
 
     private List<ExceptionInfo> exceptionInfoList;
     private int lastSafepointPos;
-    private final GraalContext context;
-
-    public TargetMethodAssembler(GraalContext context, CiTarget target, RiRuntime runtime, FrameMap frameMap, List<SlowPath> slowPaths, AbstractAssembler asm) {
-        this.context = context;
+    public TargetMethodAssembler(CiTarget target, RiRuntime runtime, FrameMap frameMap, List<SlowPath> slowPaths, AbstractAssembler asm) {
         this.target = target;
         this.runtime = runtime;
         this.frameMap = frameMap;
@@ -84,13 +82,11 @@
             }
         }
 
-        if (GraalOptions.Meter) {
-            context.metrics.TargetMethods++;
-            context.metrics.CodeBytesEmitted += targetMethod.targetCodeSize();
-            context.metrics.SafepointsEmitted += targetMethod.safepoints.size();
-            context.metrics.DataPatches += targetMethod.dataReferences.size();
-            context.metrics.ExceptionHandlersEmitted += targetMethod.exceptionHandlers.size();
-        }
+        Debug.metric("TargetMethods").increment();
+        Debug.metric("CodeBytesEmitted").add(targetMethod.targetCodeSize());
+        Debug.metric("SafepointsEmitted").add(targetMethod.safepoints.size());
+        Debug.metric("DataPatches").add(targetMethod.dataReferences.size());
+        Debug.metric("ExceptionHandlersEmitted").add(targetMethod.exceptionHandlers.size());
 
         if (GraalOptions.PrintAssembly && !TTY.isSuppressed() && !isStub) {
             Util.printSection("Target Method", Util.SECTION_CHARACTER);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Tue Jan 17 23:35:39 2012 +0100
@@ -49,6 +49,7 @@
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
@@ -63,8 +64,6 @@
  * This class traverses the HIR instructions and generates LIR instructions from them.
  */
 public abstract class LIRGenerator extends LIRGeneratorTool {
-    public final GraalContext context;
-
     protected final Graph graph;
     protected final RiRuntime runtime;
     protected final CiTarget target;
@@ -138,8 +137,7 @@
     private LockScope curLocks;
 
 
-    public LIRGenerator(GraalContext context, Graph graph, RiRuntime runtime, CiTarget target, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
-        this.context = context;
+    public LIRGenerator(Graph graph, RiRuntime runtime, CiTarget target, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
         this.graph = graph;
         this.runtime = runtime;
         this.target = target;
@@ -1316,9 +1314,7 @@
                     inputOperandArray, tempOperandArray, inputOperandIndicesArray, tempOperandIndicesArray,
                     (allocatedResultOperand == IllegalValue) ? -1 : resultOperand.index,
                     info, infoAfter, currentMethod));
-            if (GraalOptions.Meter) {
-                context.metrics.LIRXIRInstructions++;
-            }
+            Debug.metric("LIRXIRInstructions").increment();
         }
 
         return operandsArray[resultOperand.index];
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIR.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIR.java	Tue Jan 17 23:35:39 2012 +0100
@@ -64,9 +64,7 @@
     public SlowPath methodEndMarker;
 
     private int numVariables;
-
-    private final int loopCount;
-
+    private final int numLoops;
 
     public interface SlowPath {
         void emitCode(TargetMethodAssembler tasm);
@@ -77,12 +75,12 @@
      * @param loopCount number of loops
      * @param compilation the compilation
      */
-    public LIR(LIRBlock startBlock, List<LIRBlock> linearScanOrder, List<LIRBlock> codeEmittingOrder, NodeMap<LIRBlock> valueToBlock, int loopCount) {
+    public LIR(LIRBlock startBlock, List<LIRBlock> linearScanOrder, List<LIRBlock> codeEmittingOrder, NodeMap<LIRBlock> valueToBlock, int numLoops) {
         this.codeEmittingOrder = codeEmittingOrder;
         this.linearScanOrder = linearScanOrder;
         this.startBlock = startBlock;
         this.valueToBlock = valueToBlock;
-        this.loopCount = loopCount;
+        this.numLoops = numLoops;
 
         slowPaths = new ArrayList<>();
         deoptimizationStubs = new ArrayList<>();
@@ -108,10 +106,6 @@
         return valueToBlock;
     }
 
-    public int loopCount() {
-        return loopCount;
-    }
-
     public int numVariables() {
         return numVariables;
     }
@@ -253,4 +247,8 @@
             TTY.println();
         }
     }
+
+    public int numLoops() {
+        return numLoops;
+    }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ComputeProbabilityPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ComputeProbabilityPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -27,6 +27,7 @@
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.graph.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -50,13 +51,9 @@
     @Override
     protected void run(StructuredGraph graph) {
         new PropagateProbability(graph.start()).apply();
-        if (currentContext.isObserved() && GraalOptions.TraceProbability) {
-            currentContext.observable.fireCompilationEvent("After PropagateProbability", graph);
-        }
+        Debug.dump(graph, "After PropagateProbability");
         computeLoopFactors();
-        if (currentContext.isObserved() && GraalOptions.TraceProbability) {
-            currentContext.observable.fireCompilationEvent("After computeLoopFactors", graph);
-        }
+        Debug.dump(graph, "After computeLoopFactors");
         new PropagateLoopFrequency(graph.start()).apply();
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -29,6 +29,7 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.PhiNode.PhiType;
@@ -428,21 +429,10 @@
             }
             if (invokes.size() == 0) {
 
-                if (currentContext.isObserved()) {
-                    currentContext.observable.fireCompilationEvent("Before escape " + node, graph);
-                }
-                if (GraalOptions.TraceEscapeAnalysis || GraalOptions.PrintEscapeAnalysis) {
-                    TTY.println("%n!!!!!!!! non-escaping object: %s (%s)", node, node.exactType());
-                }
-                try {
-                    currentContext.timers.startScope("Escape Analysis Fixup");
-                    removeAllocation(node, op);
-                } finally {
-                    currentContext.timers.endScope();
-                }
-                if (currentContext.isObserved()) {
-                    currentContext.observable.fireCompilationEvent("After escape", graph);
-                }
+                Debug.dump(graph, "Before escape %s", node);
+                Debug.log("!!!!!!!! non-escaping object: %s (%s)", node, node.exactType());
+                removeAllocation(node, op);
+                Debug.dump(graph, "After escape", graph);
                 break;
             }
             if (weight < minimumWeight) {
@@ -457,8 +447,8 @@
             if (GraalOptions.TraceEscapeAnalysis || GraalOptions.PrintEscapeAnalysis) {
                 TTY.println("Trying inlining to get a non-escaping object for %s", node);
             }
-            new InliningPhase(target, runtime, invokes, assumptions, plan).apply(graph, currentContext);
-            new DeadCodeEliminationPhase().apply(graph, currentContext);
+            new InliningPhase(target, runtime, invokes, assumptions, plan).apply(graph);
+            new DeadCodeEliminationPhase().apply(graph);
             if (node.isDeleted()) {
                 if (GraalOptions.TraceEscapeAnalysis || GraalOptions.PrintEscapeAnalysis) {
                     TTY.println("%n!!!!!!!! object died while performing escape analysis: %s (%s)", node, node.exactType());
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FloatingReadPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FloatingReadPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -249,7 +249,7 @@
 
         // Identify blocks.
         final IdentifyBlocksPhase s = new IdentifyBlocksPhase(false);
-        s.apply(graph, currentContext);
+        s.apply(graph);
         List<Block> blocks = s.getBlocks();
 
         // Process blocks (predecessors first).
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -24,11 +24,14 @@
 
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
 public class GlobalValueNumberingPhase extends Phase {
 
+    public static final Debug.Metric metricGlobalValueNumberingHits = Debug.metric("GlobalValueNumberingHits");
+
     @Override
     protected void run(StructuredGraph graph) {
         NodeBitMap visited = graph.createNodeBitMap();
@@ -47,9 +50,7 @@
                 Node newNode = compilerGraph.findDuplicate(n);
                 if (newNode != null) {
                     n.replaceAndDelete(newNode);
-                    if (GraalOptions.Meter) {
-                        currentContext.metrics.GlobalValueNumberingHits++;
-                    }
+                    metricGlobalValueNumberingHits.increment();
                     if (GraalOptions.TraceGVN) {
                         TTY.println("GVN applied and new node is " + newNode);
                     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -33,6 +33,7 @@
 import com.oracle.max.graal.compiler.util.InliningUtil.InlineInfo;
 import com.oracle.max.graal.compiler.util.InliningUtil.InliningCallback;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -54,6 +55,10 @@
 
     private final PhasePlan plan;
 
+    // Metrics
+    private static final Debug.Metric metricInliningPerformed = Debug.metric("InliningPerformed");
+    private static final Debug.Metric metricInliningConsidered = Debug.metric("InliningConsidered");
+
     public InliningPhase(CiTarget target, GraalRuntime runtime, Collection<Invoke> hints, CiAssumptions assumptions, PhasePlan plan) {
         this.target = target;
         this.runtime = runtime;
@@ -94,20 +99,16 @@
                     if (GraalOptions.TraceInlining) {
                         TTY.println("inlining %f: %s", info.weight, info);
                     }
-                    if (GraalOptions.TraceInlining) {
-                        currentContext.observable.fireCompilationEvent("after inlining " + info, graph);
-                    }
+                    Debug.dump(graph, "after inlining %s", info);
                     // get the new nodes here, the canonicalizer phase will reset the mark
                     newNodes = graph.getNewNodes();
                     if (GraalOptions.OptCanonicalizer) {
                         new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph);
                     }
                     if (GraalOptions.Intrinsify) {
-                        new IntrinsificationPhase(runtime).apply(graph, currentContext);
+                        new IntrinsificationPhase(runtime).apply(graph);
                     }
-                    if (GraalOptions.Meter) {
-                        currentContext.metrics.InlinePerformed++;
-                    }
+                    metricInliningPerformed.increment();
                 } catch (CiBailout bailout) {
                     // TODO determine if we should really bail out of the whole compilation.
                     throw bailout;
@@ -146,10 +147,7 @@
     private void scanInvoke(Invoke invoke, int level) {
         InlineInfo info = InliningUtil.getInlineInfo(invoke, level, runtime, assumptions, this);
         if (info != null) {
-            if (GraalOptions.Meter) {
-                currentContext.metrics.InlineConsidered++;
-            }
-
+            metricInliningConsidered.increment();
             inlineCandidates.add(info);
         }
     }
@@ -161,14 +159,14 @@
         StructuredGraph newGraph = new StructuredGraph(method);
 
         if (plan != null) {
-            plan.runPhases(PhasePosition.AFTER_PARSING, newGraph, currentContext);
+            plan.runPhases(PhasePosition.AFTER_PARSING, newGraph);
         }
 
         if (GraalOptions.ProbabilityAnalysis) {
-            new DeadCodeEliminationPhase().apply(newGraph, currentContext, false);
-            new ComputeProbabilityPhase().apply(newGraph, currentContext, false);
+            new DeadCodeEliminationPhase().apply(newGraph);
+            new ComputeProbabilityPhase().apply(newGraph);
         }
-        new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph, currentContext, false);
+        new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph);
         return newGraph;
     }
 
@@ -213,9 +211,9 @@
             if (!parsedMethods.containsKey(method)) {
                 StructuredGraph newGraph = new StructuredGraph(method);
                 if (plan != null) {
-                    plan.runPhases(PhasePosition.AFTER_PARSING, newGraph, currentContext);
+                    plan.runPhases(PhasePosition.AFTER_PARSING, newGraph);
                 }
-                new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph, currentContext, false);
+                new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph);
                 count = graphComplexity(newGraph);
                 parsedMethods.put(method, count);
             } else {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -40,7 +40,7 @@
     @Override
     protected void run(final StructuredGraph graph) {
         final IdentifyBlocksPhase s = new IdentifyBlocksPhase(false);
-        s.apply(graph, currentContext);
+        s.apply(graph);
         s.calculateAlwaysReachedBlock();
 
         NodeBitMap processed = graph.createNodeBitMap();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -22,100 +22,27 @@
  */
 package com.oracle.max.graal.compiler.phases;
 
-import com.oracle.max.cri.ci.*;
-import com.oracle.max.graal.compiler.*;
-import com.oracle.max.graal.compiler.schedule.*;
-import com.oracle.max.graal.graph.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 
 public abstract class Phase {
 
     private final String name;
-    private final boolean shouldVerify;
-    protected GraalContext currentContext;
 
     protected Phase() {
         this.name = this.getClass().getSimpleName();
-        this.shouldVerify = GraalOptions.VerifyPhases;
     }
 
     protected Phase(String name) {
-        this(name, GraalOptions.VerifyPhases);
-    }
-
-    protected Phase(String name, boolean shouldVerify) {
         this.name = name;
-        this.shouldVerify = shouldVerify;
     }
 
     protected String getDetailedName() {
         return getName();
     }
 
-    public final void apply(StructuredGraph graph) {
-        apply(graph, GraalContext.EMPTY_CONTEXT);
-    }
-
-    public final void apply(StructuredGraph graph, GraalContext context) {
-        apply(graph, context, true);
-    }
-
-    public final void apply(StructuredGraph graph, boolean plot) {
-        apply(graph,  GraalContext.EMPTY_CONTEXT, plot);
-    }
-
-    public final void apply(StructuredGraph graph, GraalContext context, boolean plot) {
-
-        this.currentContext = context;
-        try {
-            assert graph != null && (!shouldVerify || graph.verify());
-        } catch (GraalInternalError e) {
-            throw e.addContext("start of phase", getDetailedName());
-        }
-
-        int startDeletedNodeCount = graph.getDeletedNodeCount();
-        int startNodeCount = graph.getNodeCount();
-        if (context != null) {
-            context.timers.startScope(getName());
-        }
-        try {
-            try {
-                run(graph);
-            } catch (CiBailout bailout) {
-                throw bailout;
-            } catch (AssertionError e) {
-                throw new GraalInternalError(e);
-            } catch (RuntimeException e) {
-                throw new GraalInternalError(e);
-            } finally {
-                if (context != null) {
-                    context.timers.endScope();
-                }
-            }
-        } catch (GraalInternalError e) {
-            throw e.addContext(graph).addContext("phase", getDetailedName());
-        }
-
-        if (context != null) {
-            if (GraalOptions.Meter) {
-                int deletedNodeCount = graph.getDeletedNodeCount() - startDeletedNodeCount;
-                int createdNodeCount = graph.getNodeCount() - startNodeCount + deletedNodeCount;
-                context.metrics.get(getName().concat(".executed")).increment();
-                context.metrics.get(getName().concat(".deletedNodes")).increment(deletedNodeCount);
-                context.metrics.get(getName().concat(".createdNodes")).increment(createdNodeCount);
-            }
-
-            boolean shouldFireCompilationEvents = context.isObserved() && this.getClass() != IdentifyBlocksPhase.class && (plot || GraalOptions.PlotVerbose);
-            if (shouldFireCompilationEvents && context.timers.currentLevel() < GraalOptions.PlotLevel) {
-                context.observable.fireCompilationEvent("After " + getName(), graph);
-            }
-        }
-
-        try {
-            assert !shouldVerify || graph.verify();
-        } catch (GraalInternalError e) {
-            throw e.addContext("end of phase", getDetailedName());
-        }
+    public final void apply(final StructuredGraph graph) {
+        Debug.scope(name, this, new Runnable() { public void run() { Phase.this.run(graph); }});
     }
 
     public final String getName() {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhasePlan.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhasePlan.java	Tue Jan 17 23:35:39 2012 +0100
@@ -24,7 +24,6 @@
 
 import java.util.*;
 
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.nodes.*;
 
 /**
@@ -68,10 +67,10 @@
         phases[pos.ordinal()].add(phase);
     }
 
-    public void runPhases(PhasePosition pos, StructuredGraph graph, GraalContext context) {
+    public void runPhases(PhasePosition pos, StructuredGraph graph) {
         if (phases[pos.ordinal()] != null) {
             for (Phase p : phases[pos.ordinal()]) {
-                p.apply(graph, context);
+                p.apply(graph);
             }
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -57,7 +57,7 @@
     }
 
     public IdentifyBlocksPhase(boolean scheduleAllNodes, BlockFactory blockFactory) {
-        super(scheduleAllNodes ? "FullSchedule" : "PartSchedule", false);
+        super(scheduleAllNodes ? "FullSchedule" : "PartSchedule");
         this.blockFactory = blockFactory;
         this.scheduleAllNodes = scheduleAllNodes;
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java	Tue Jan 17 23:35:39 2012 +0100
@@ -28,7 +28,6 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.cri.xir.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.graph.*;
@@ -57,7 +56,7 @@
     }
 
     public abstract FrameMap newFrameMap(RiRegisterConfig registerConfig);
-    public abstract LIRGenerator newLIRGenerator(GraalContext context, Graph graph, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir);
+    public abstract LIRGenerator newLIRGenerator(Graph graph, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir);
     public abstract AbstractAssembler newAssembler(RiRegisterConfig registerConfig);
     public abstract CiXirAssembler newXirAssembler();
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java	Tue Jan 17 23:35:39 2012 +0100
@@ -27,7 +27,6 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.cri.xir.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.target.*;
@@ -47,8 +46,8 @@
      * @return an appropriate LIR generator instance
      */
     @Override
-    public LIRGenerator newLIRGenerator(GraalContext context, Graph graph, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
-        return new AMD64LIRGenerator(context, graph, runtime, target, frameMap, method, lir, xir);
+    public LIRGenerator newLIRGenerator(Graph graph, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
+        return new AMD64LIRGenerator(graph, runtime, target, frameMap, method, lir, xir);
     }
 
     @Override
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Tue Jan 17 23:35:39 2012 +0100
@@ -40,7 +40,6 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.cri.xir.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.util.*;
@@ -72,8 +71,8 @@
         StandardOpcode.XIR = AMD64XirOpcode.XIR;
     }
 
-    public AMD64LIRGenerator(GraalContext context, Graph graph, RiRuntime runtime, CiTarget target, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
-        super(context, graph, runtime, target, frameMap, method, lir, xir);
+    public AMD64LIRGenerator(Graph graph, RiRuntime runtime, CiTarget target, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) {
+        super(graph, runtime, target, frameMap, method, lir, xir);
         lir.methodEndMarker = new AMD64MethodEndStub();
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug;
+
+import com.oracle.max.graal.debug.internal.DebugScope;
+import com.oracle.max.graal.debug.internal.MetricImpl;
+import com.oracle.max.graal.debug.internal.TimerImpl;
+import java.util.Collections;
+import java.util.concurrent.*;
+
+
+public class Debug {
+    public static boolean SCOPE = false;
+    public static boolean LOG = false;
+    public static boolean METER = false;
+    public static boolean TIME = false;
+
+    public static void sandbox(String name, Runnable runnable) {
+        if (SCOPE) {
+            DebugScope.getInstance().scope(name, runnable, null, true, new Object[0]);
+        } else {
+            runnable.run();
+        }
+    }
+
+    public static void scope(String name, Runnable runnable) {
+        scope(name, null, runnable);
+    }
+
+    public static <T> T scope(String name, Callable<T> callable) {
+        return scope(name, null, callable);
+    }
+
+    public static void scope(String name, Object context, Runnable runnable) {
+        if (SCOPE) {
+            DebugScope.getInstance().scope(name, runnable, null, false, new Object[]{context});
+        } else {
+            runnable.run();
+        }
+    }
+
+    public static <T> T scope(String name, Object context, Callable<T> callable) {
+        if (SCOPE) {
+            return DebugScope.getInstance().scope(name, null, callable, false, new Object[]{context});
+        } else {
+            return DebugScope.call(callable);
+        }
+    }
+
+    public static void log(String msg, Object... args) {
+        if (LOG) {
+            DebugScope.getInstance().log(msg, args);
+        }
+    }
+
+    public static void dump(Object object, String msg, Object... args) {
+        if (LOG) {
+            DebugScope.getInstance().log(msg, args);
+        }
+    }
+
+    public static Iterable<Object> context() {
+        if (SCOPE) {
+            return DebugScope.getInstance().getCurrentContext();
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    public static Metric metric(String name) {
+        if (METER) {
+            return new MetricImpl(name);
+        } else {
+            return VOID_METRIC;
+        }
+    }
+
+    public interface Metric {
+        void increment();
+        void add(int value);
+    }
+
+    private static final Metric VOID_METRIC = new Metric() {
+        @Override
+        public void increment() { }
+        @Override
+        public void add(int value) { }
+    };
+
+    public static Timer timer(String name) {
+        if (TIME) {
+            return new TimerImpl(name);
+        } else {
+            return VOID_TIMER;
+        }
+    }
+
+    public interface Timer {
+        void start();
+        void stop();
+    }
+
+    private static final Timer VOID_TIMER = new Timer() {
+        @Override
+        public void start() { }
+        @Override
+        public void stop() { }
+    };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.*;
+
+
+public final class DebugScope {
+
+    private static ThreadLocal<DebugScope> instance = new ThreadLocal<>();
+    private final List<DebugScope> children = new ArrayList<>(4);
+    private final String name;
+    private final DebugScope parent;
+    private final Object[] context;
+    private final DebugValueMap valueMap = new DebugValueMap();
+
+    public static final DebugScope DEFAULT_CONTEXT = new DebugScope("DEFAULT", null);
+
+    public static DebugScope getInstance() {
+        DebugScope result = instance.get();
+        if (result == null) {
+            return DEFAULT_CONTEXT;
+        } else {
+            return result;
+        }
+    }
+
+    private DebugScope(String name, DebugScope parent, Object... context) {
+        this.name = name;
+        this.parent = parent;
+        this.context = context;
+    }
+
+    public void log(String msg, Object... args) {
+    }
+
+    public <T> T scope(String newName, Runnable runnable, Callable<T> callable, boolean sandbox, Object[] newContext) {
+        DebugScope oldContext = getInstance();
+        DebugScope newChild = null;
+        if (sandbox) {
+            newChild = new DebugScope(name, null, newContext);
+        } else {
+            oldContext.createChild(newName, newContext);
+        }
+        instance.set(newChild);
+        T result = null;
+        try {
+            if (runnable != null) {
+                runnable.run();
+            }
+            if (callable != null) {
+                call(callable);
+            }
+        } catch (RuntimeException e) {
+            throw interceptException(e);
+        } finally {
+            instance.set(oldContext);
+        }
+        return result;
+    }
+
+    public DebugValueMap getValueMap() {
+        return valueMap;
+    }
+
+    private RuntimeException interceptException(RuntimeException e) {
+        return e;
+    }
+
+    long getCurrentValue(int index) {
+        return valueMap.getCurrentValue(index);
+    }
+
+    void setCurrentValue(int index, long l) {
+        valueMap.setCurrentValue(index, l);
+    }
+
+    private DebugScope createChild(String newName, Object[] newContext) {
+        DebugScope result = new DebugScope(newName, this, newContext);
+        children.add(result);
+        return result;
+    }
+
+    public Iterable<Object> getCurrentContext() {
+        return new Iterable<Object>() {
+
+            @Override
+            public Iterator<Object> iterator() {
+                return new Iterator<Object>() {
+
+                    DebugScope currentScope = DebugScope.this;
+                    int objectIndex;
+
+                    @Override
+                    public boolean hasNext() {
+                        selectScope();
+                        return currentScope != null;
+                    }
+
+                    private void selectScope() {
+                        while (currentScope != null && currentScope.context.length <= objectIndex) {
+                            currentScope = currentScope.parent;
+                            objectIndex = 0;
+                        }
+                    }
+
+                    @Override
+                    public Object next() {
+                        selectScope();
+                        if (currentScope != null) {
+                            return currentScope.context[objectIndex++];
+                        }
+                        throw new IllegalStateException("May only be called if there is a next element.");
+                    }
+
+                    @Override
+                    public void remove() {
+                        throw new UnsupportedOperationException("This iterator is read only.");
+                    }
+                };
+            }
+        };
+    }
+
+    public static <T> T call(Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException) e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugValue.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+public class DebugValue {
+
+    private String name;
+    private int index;
+
+    protected DebugValue(String name) {
+        this.name = name;
+        this.index = -1;
+    }
+
+    protected long getCurrentValue() {
+        ensureInitialized();
+        return DebugScope.getInstance().getCurrentValue(index);
+    }
+
+    protected void setCurrentValue(long l) {
+        ensureInitialized();
+        DebugScope.getInstance().setCurrentValue(index, l);
+    }
+
+    private void ensureInitialized() {
+        if (index == -1) {
+            index = KeyRegistry.register(name);
+        }
+    }
+
+    protected void addToCurrentValue(long timeSpan) {
+        setCurrentValue(getCurrentValue() + timeSpan);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugValueMap.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+import java.util.Arrays;
+
+public class DebugValueMap {
+
+    private long[] values;
+
+    public void setCurrentValue(int index, long l) {
+        ensureSize(index);
+        values[index] = l;
+    }
+
+    public long getCurrentValue(int index) {
+        ensureSize(index);
+        return values[index];
+    }
+
+    private void ensureSize(int index) {
+        if (values == null || values.length <= index) {
+            values = Arrays.copyOf(values, index + 1);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/KeyRegistry.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class KeyRegistry {
+
+    private static int keyCount;
+    private static Map<String, Integer> keyMap = new HashMap<>();
+
+    public static synchronized int register(String name) {
+        if (!keyMap.containsKey(name)) {
+            keyMap.put(name, keyCount++);
+        }
+        return keyMap.get(name);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/MetricImpl.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+import com.oracle.max.graal.debug.Debug.Metric;
+
+public final class MetricImpl extends DebugValue implements Metric {
+
+    public MetricImpl(String name) {
+        super(name);
+    }
+
+    public void increment() {
+        add(1);
+    }
+
+    public void add(int value) {
+        super.addToCurrentValue(value);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/TimerImpl.java	Tue Jan 17 23:35:39 2012 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012, 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 com.oracle.max.graal.debug.internal;
+
+import com.oracle.max.graal.debug.Debug;
+
+public final class TimerImpl extends DebugValue implements Debug.Timer {
+
+    private long startTime = -1;
+
+    public TimerImpl(String name) {
+        super(name);
+    }
+
+    @Override
+    public void start() {
+        startTime = System.currentTimeMillis();
+    }
+
+    @Override
+    public void stop() {
+        long timeSpan = System.currentTimeMillis() - startTime;
+        super.addToCurrentValue(timeSpan);
+    }
+}
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java	Tue Jan 17 23:35:39 2012 +0100
@@ -90,7 +90,6 @@
     private final CompilerToVM vmEntries;
     private final VMToCompiler vmExits;
 
-    private GraalContext context;
     private HotSpotRuntime runtime;
     private GraalCompiler compiler;
     private CiTarget target;
@@ -163,7 +162,7 @@
             Backend backend = Backend.create(target.arch, runtime, target);
             generator.initialize(backend.newXirAssembler());
 
-            compiler = new GraalCompiler(context, getRuntime(), getTarget(), backend, generator);
+            compiler = new GraalCompiler(getRuntime(), getTarget(), backend, generator);
         }
         return compiler;
     }
@@ -216,9 +215,8 @@
     @Override
     public HotSpotRuntime getRuntime() {
         if (runtime == null) {
-            context = new GraalContext("Virtual Machine Compiler");
             if (GraalOptions.PrintCFGToFile) {
-                context.addCompilationObserver(new CFGPrinterObserver());
+//                context.addCompilationObserver(new CFGPrinterObserver());
             }
             if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot || GraalOptions.PlotOnError) {
                 CompilationObserver observer;
@@ -227,9 +225,10 @@
                 } else {
                     observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort);
                 }
-                context.addCompilationObserver(observer);
+//                context.addCompilationObserver(observer);
+                // TODO(tw): Install observer.
             }
-            runtime = new HotSpotRuntime(context, config, this);
+            runtime = new HotSpotRuntime(config, this);
         }
         return runtime;
     }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jan 17 23:35:39 2012 +0100
@@ -45,6 +45,7 @@
 public class VMToCompilerImpl implements VMToCompiler, Remote {
 
     private final Compiler compiler;
+    private int compiledMethodCount;
 
     public final HotSpotTypePrimitive typeBoolean;
     public final HotSpotTypePrimitive typeChar;
@@ -152,7 +153,8 @@
     }
 
     public void shutdownCompiler() throws Throwable {
-        compiler.getCompiler().context.print();
+//        compiler.getCompiler().context.print();
+        // TODO(tw): Print context results.
         compileQueue.shutdown();
     }
 
@@ -169,7 +171,37 @@
                         PhasePlan plan = new PhasePlan();
                         GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime());
                         plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
-                        CiTargetMethod result = compiler.getCompiler().compileMethod(method, -1, plan);
+                        long startTime = 0;
+                        int index = compiledMethodCount++;
+                        final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
+                        if (printCompilation) {
+                            TTY.println(String.format("Graal %4d %-70s %-45s %-50s ...",
+                                            index,
+                                            method.holder().name(),
+                                            method.name(),
+                                            method.signature().asString()));
+                            startTime = System.nanoTime();
+                        }
+
+                        CiTargetMethod result = null;
+                        TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method);
+                        try {
+                            result = compiler.getCompiler().compileMethod(method, -1, plan);
+                        } finally {
+                            filter.remove();
+                            if (printCompilation) {
+                                long time = (System.nanoTime() - startTime) / 100000;
+                                TTY.println(String.format("Graal %4d %-70s %-45s %-50s | %3d.%dms %4dnodes %5dB",
+                                                index,
+                                                "",
+                                                "",
+                                                "",
+                                                time / 10,
+                                                time % 10,
+                                                0,
+                                                (result != null ? result.targetCodeSize() : -1)));
+                            }
+                        }
                         HotSpotTargetMethod.installMethod(compiler, method, result, true);
                     } catch (CiBailout bailout) {
                         if (GraalOptions.ExitVMOnBailout) {
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotRuntime.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotRuntime.java	Tue Jan 17 23:35:39 2012 +0100
@@ -48,14 +48,12 @@
  * CRI runtime implementation for the HotSpot VM.
  */
 public class HotSpotRuntime implements GraalRuntime {
-    final GraalContext context;
     final HotSpotVMConfig config;
     final HotSpotRegisterConfig regConfig;
     private final HotSpotRegisterConfig globalStubRegConfig;
     private final Compiler compiler;
 
-    public HotSpotRuntime(GraalContext context, HotSpotVMConfig config, Compiler compiler) {
-        this.context = context;
+    public HotSpotRuntime(HotSpotVMConfig config, Compiler compiler) {
         this.config = config;
         this.compiler = compiler;
         regConfig = new HotSpotRegisterConfig(config, false);
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Tue Jan 17 23:35:39 2012 +0100
@@ -36,6 +36,7 @@
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.java.BlockMap.*;
 import com.oracle.max.graal.nodes.*;
@@ -137,12 +138,12 @@
     private BlockMap createBlockMap() {
         BlockMap map = new BlockMap(method, config.useBranchPrediction());
         map.build();
-        currentContext.metrics.bytecodeCount += method.code().length;
 
-        if (currentContext.isObserved()) {
-            String label = CiUtil.format("BlockListBuilder %f %R %H.%n(%P)", method);
-            currentContext.observable.fireCompilationEvent(label, map);
-        }
+//        if (currentContext.isObserved()) {
+//            String label = CiUtil.format("BlockListBuilder %f %R %H.%n(%P)", method);
+//            currentContext.observable.fireCompilationEvent(label, map);
+//        }
+        // TODO(tw): Reinstall this logging code when debug framework is finished.
         return map;
     }
 
@@ -157,7 +158,6 @@
         this.canTrapBitSet = blockMap.canTrap;
 
         exceptionHandlers = blockMap.exceptionHandlers();
-        currentContext.metrics.blockCount += blockMap.blocks.size();
 
         nextBlockNumber = blockMap.blocks.size();
 
@@ -199,7 +199,6 @@
     }
 
     private int nextBlockNumber() {
-        currentContext.metrics.blockCount++;
         return nextBlockNumber++;
     }
 
@@ -869,9 +868,7 @@
             } else {
                 exception.exceptionEdge.setNext(createTarget(unwindBlock(bci()), frameState.duplicateWithException(bci(), exception.exception)));
             }
-            if (GraalOptions.Meter) {
-                currentContext.metrics.ExplicitExceptions++;
-            }
+            Debug.metric("ExplicitExceptions").increment();
         }
     }
 
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinterObserver.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinterObserver.java	Tue Jan 17 23:35:39 2012 +0100
@@ -105,7 +105,7 @@
             if (schedule == null) {
                 try {
                     schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY);
-                    schedule.apply((StructuredGraph) graph, false);
+                    schedule.apply((StructuredGraph) graph);
                     blocks = schedule.getBlocks();
 
                     ComputeLinearScanOrder clso = new ComputeLinearScanOrder(schedule.getBlocks().size(), schedule.loopCount(), (LIRBlock) schedule.getStartBlock());
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Tue Jan 17 23:35:39 2012 +0100
@@ -137,7 +137,7 @@
         if (schedule == null) {
             try {
                 schedule = new IdentifyBlocksPhase(true);
-                schedule.apply((StructuredGraph) graph, false);
+                schedule.apply((StructuredGraph) graph);
             } catch (Throwable t) {
                 // nothing to do here...
             }
--- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 17 20:35:49 2012 +0100
+++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 17 23:35:39 2012 +0100
@@ -27,7 +27,6 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.compiler.*;
-import com.oracle.max.graal.compiler.observer.*;
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.cri.*;
@@ -45,43 +44,29 @@
 
     public static void install(GraalRuntime runtime, CiTarget target, SnippetsInterface obj, boolean plotGraphs, PhasePlan plan) {
         Class<? extends SnippetsInterface> clazz = obj.getClass();
-        GraalContext context = new GraalContext("Installing Snippet");
         BoxingMethodPool pool = new BoxingMethodPool(runtime);
         if (clazz.isAnnotationPresent(ClassSubstitution.class)) {
-            installSubstitution(runtime, target, plotGraphs, plan, clazz, context, pool, clazz.getAnnotation(ClassSubstitution.class).value());
+            installSubstitution(runtime, target, plotGraphs, plan, clazz, pool, clazz.getAnnotation(ClassSubstitution.class).value());
         } else {
-            installSnippets(runtime, target, plotGraphs, plan, clazz, context, pool);
+            installSnippets(runtime, target, plotGraphs, plan, clazz, pool);
         }
     }
 
-    private static void installSnippets(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz, GraalContext context,
+    private static void installSnippets(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
                     BoxingMethodPool pool) {
         for (Method snippet : clazz.getDeclaredMethods()) {
-            try {
-                int modifiers = snippet.getModifiers();
-                if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
-                    throw new RuntimeException("Snippet must not be abstract or native");
-                }
-                RiResolvedMethod snippetRiMethod = runtime.getRiMethod(snippet);
-                if (snippetRiMethod.compilerStorage().get(Graph.class) == null) {
-                    buildSnippetGraph(snippetRiMethod, runtime, target, context, pool, plotGraphs, plan);
-                }
-            } catch (GraalInternalError error) {
-                if (context.isObserved()) {
-                    if (error.node() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Node " + error.node(), CompilationEvent.ERROR, error.node().graph());
-                    } else if (error.graph() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Graph " + error.graph(), CompilationEvent.ERROR, error.graph());
-                    }
-                }
-                throw error;
-            } catch (Throwable t) {
-                throw new RuntimeException("Error when installing snippet for " + clazz, t);
+            int modifiers = snippet.getModifiers();
+            if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
+                throw new RuntimeException("Snippet must not be abstract or native");
+            }
+            RiResolvedMethod snippetRiMethod = runtime.getRiMethod(snippet);
+            if (snippetRiMethod.compilerStorage().get(Graph.class) == null) {
+                buildSnippetGraph(snippetRiMethod, runtime, target, pool, plotGraphs, plan);
             }
         }
     }
 
-    private static void installSubstitution(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz, GraalContext context,
+    private static void installSubstitution(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
                     BoxingMethodPool pool, Class<?> original) throws GraalInternalError {
         for (Method snippet : clazz.getDeclaredMethods()) {
             try {
@@ -94,50 +79,39 @@
                     throw new RuntimeException("Snippet must not be abstract or native");
                 }
                 RiResolvedMethod snippetRiMethod = runtime.getRiMethod(snippet);
-                StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, context, pool, plotGraphs, plan);
+                StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, pool, plotGraphs, plan);
                 runtime.getRiMethod(method).compilerStorage().put(Graph.class, graph);
             } catch (NoSuchMethodException e) {
                 throw new RuntimeException("Could not resolve method to substitute with: " + snippet.getName(), e);
-            } catch (GraalInternalError error) {
-                if (context.isObserved()) {
-                    if (error.node() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Node " + error.node(), CompilationEvent.ERROR, error.node().graph());
-                    } else if (error.graph() != null) {
-                        context.observable.fireCompilationEvent("VerificationError on Graph " + error.graph(), CompilationEvent.ERROR, error.graph());
-                    }
-                }
-                throw error;
-            } catch (Throwable t) {
-                throw new RuntimeException("Error when installing snippet for " + clazz, t);
             }
         }
     }
 
-    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, GraalContext context, BoxingMethodPool pool, boolean plotGraphs, PhasePlan plan) {
+    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, boolean plotGraphs, PhasePlan plan) {
         IdealGraphPrinterObserver observer = null;
         if (plotGraphs) {
             observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort);
             observer.compilationStarted(CiUtil.format("snippet:%h.%n(%p)", snippetRiMethod));
         }
-        StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, context, pool, plan, observer);
+        StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, pool, plan, observer);
         if (observer != null) {
             observer.compilationFinished(null);
         }
         return graph;
     }
 
-    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, GraalContext context, BoxingMethodPool pool, PhasePlan plan, IdealGraphPrinterObserver observer) {
+    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, PhasePlan plan, IdealGraphPrinterObserver observer) {
 
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDeoptFreeDefault();
         GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config);
         StructuredGraph graph = new StructuredGraph(snippetRiMethod);
-        graphBuilder.apply(graph, context);
+        graphBuilder.apply(graph);
 
         if (observer != null) {
             observer.printGraph(snippetRiMethod.name() + ":" + GraphBuilderPhase.class.getSimpleName(), graph);
         }
 
-        new SnippetIntrinsificationPhase(runtime, pool).apply(graph, context);
+        new SnippetIntrinsificationPhase(runtime, pool).apply(graph);
 
         for (Invoke invoke : graph.getInvokes()) {
             MethodCallTargetNode callTarget = invoke.callTarget();
@@ -146,20 +120,20 @@
             if (holder.isSubtypeOf(runtime.getType(SnippetsInterface.class))) {
                 StructuredGraph targetGraph = (StructuredGraph) targetMethod.compilerStorage().get(Graph.class);
                 if (targetGraph == null) {
-                    targetGraph = buildSnippetGraph(targetMethod, runtime, target, context, pool, plan, observer);
+                    targetGraph = buildSnippetGraph(targetMethod, runtime, target, pool, plan, observer);
                 }
                 InliningUtil.inline(invoke, targetGraph, true);
                 new CanonicalizerPhase(target, runtime, null).apply(graph);
             }
         }
 
-        new SnippetIntrinsificationPhase(runtime, pool).apply(graph, context);
+        new SnippetIntrinsificationPhase(runtime, pool).apply(graph);
 
         if (observer != null) {
             observer.printGraph(snippetRiMethod.name() + ":" + SnippetIntrinsificationPhase.class.getSimpleName(), graph);
         }
-        new DeadCodeEliminationPhase().apply(graph, context);
-        new CanonicalizerPhase(target, runtime, null).apply(graph, context);
+        new DeadCodeEliminationPhase().apply(graph);
+        new CanonicalizerPhase(target, runtime, null).apply(graph);
 
         // TODO (gd) remove when we have safepoint polling elimination
         for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) {
--- a/mx/projects	Tue Jan 17 20:35:49 2012 +0100
+++ b/mx/projects	Tue Jan 17 23:35:39 2012 +0100
@@ -50,7 +50,12 @@
 # graal.graph
 project@com.oracle.max.graal.graph@subDir=graal
 project@com.oracle.max.graal.graph@sourceDirs=src
-project@com.oracle.max.graal.graph@dependencies=JUNIT
+project@com.oracle.max.graal.graph@dependencies=com.oracle.max.graal.debug,JUNIT
+
+# graal.debug
+project@com.oracle.max.graal.debug@subDir=graal
+project@com.oracle.max.graal.debug@sourceDirs=src
+project@com.oracle.max.graal.debug@checkstyle=com.oracle.max.graal.graph
 
 # graal.snippets
 project@com.oracle.max.graal.snippets@subDir=graal
--- a/src/share/vm/graal/graal_paths.hpp	Tue Jan 17 20:35:49 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2012, 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.
- */
- 
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.cri");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.criutils");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.asm");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.graph");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.nodes");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.compiler");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.java");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.printer");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.snippets");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.base");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.asmdis");
-    prepend_to_graal_classpath(scp_compiler, graal_dir, "com.oracle.max.graal.hotspot");
--- a/src/share/vm/runtime/arguments.cpp	Tue Jan 17 20:35:49 2012 +0100
+++ b/src/share/vm/runtime/arguments.cpp	Tue Jan 17 23:35:39 2012 +0100
@@ -2096,9 +2096,22 @@
       }
     }
     if (PrintVMOptions) tty->print_cr("GRAAL=%s", graal_dir);
-
+    
     SysClassPath scp_compiler(Arguments::get_sysclasspath());
-#include "graal/graal_paths.hpp"
+    struct dirent* dentry;
+    char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(graal_dir));
+    errno = 0;
+    DIR* graal_dir_handle = os::opendir(graal_dir);
+    while ((dentry = os::readdir(graal_dir_handle, (struct dirent *)tdbuf)) != NULL) {
+      if (strcmp(dentry->d_name, ".") != 0 && strcmp(dentry->d_name, "..")) {
+        prepend_to_graal_classpath(scp_compiler, graal_dir, dentry->d_name);
+        if (PrintVMOptions) {
+          tty->print_cr("Adding project directory %s to bootclasspath", dentry->d_name);
+        }
+      }
+    }
+    os::closedir(graal_dir_handle);
+    FREE_C_HEAP_ARRAY(char, tdbuf);
     scp_compiler.expand_endorsed();
 
     Arguments::set_compilerclasspath(scp_compiler.combined_path());