# HG changeset patch # User Lukas Stadler # Date 1326295071 -3600 # Node ID 4643ccd37dacab6920e5d708c7db7e03b37356d0 # Parent 6043f74b1ca057323c714603e3d13f6082f8dc06 * removed CiStatistics * always use registerConfig via FrameMap * completely remove GraalCompilation * removed DebugInfoLevel * changed CompilationObserver start and finished events to also use CompilationEvent * some scoping support in ObservableContext (to be replaced by the new Logging/Tracing/Metrics/Plotting code) * removed CiCompiler diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiCompiler.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiCompiler.java Wed Jan 11 14:02:08 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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.cri.ci; - -import com.oracle.max.cri.ri.*; - -public interface CiCompiler { - - /** - * Denotes the level of debug info for safepoints that should be generated by a compilation. - */ - enum DebugInfoLevel { - /** - * Only ref maps are required. - */ - REF_MAPS, - - /** - * Code positions and ref maps are required. - */ - CODE_POS_AND_REF_MAPS, - - /** - * Frame info, code positions and ref maps are required. - * Only a compilation with level can make speculative optimizations. - */ - FULL - } - - /** - * Compile the specified method. - * - * @param method the method to compile - * @param osrBCI the bytecode index of the entrypoint for an on-stack-replacement or {@code -1} if this is not an - * on-stack-replacement compilation - * @param debugInfoLevel TODO - */ - CiResult compileMethod(RiResolvedMethod method, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel); -} diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiResult.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiResult.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiResult.java Wed Jan 11 16:17:51 2012 +0100 @@ -30,7 +30,6 @@ public class CiResult { private final CiTargetMethod targetMethod; private final CiBailout bailout; - private final CiStatistics stats; /** * Creates a new compilation result. @@ -38,10 +37,9 @@ * @param bailout the bailout condition that occurred * @param stats statistics about the compilation */ - public CiResult(CiTargetMethod targetMethod, CiBailout bailout, CiStatistics stats) { + public CiResult(CiTargetMethod targetMethod, CiBailout bailout) { this.targetMethod = targetMethod; this.bailout = bailout; - this.stats = stats; } /** @@ -58,14 +56,6 @@ } /** - * Returns the statistics about the compilation that were produced, if any. - * @return the statistics - */ - public CiStatistics statistics() { - return stats; - } - - /** * Returns the bailout condition that occurred for this compilation, if any. * @return the bailout */ diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiStatistics.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiStatistics.java Wed Jan 11 14:02:08 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +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; - -/** - * Contains statistics gathered during the compilation of a method and reported back - * from the compiler as the result of compilation. - */ -public class CiStatistics { - - /** - * 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; - -} diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java Wed Jan 11 16:17:51 2012 +0100 @@ -22,7 +22,6 @@ */ package com.oracle.max.graal.alloc.simple; -import static com.oracle.max.graal.compiler.lir.LIRPhiMapping.*; import static com.oracle.max.cri.ci.CiValueUtil.*; import static com.oracle.max.graal.alloc.util.ValueUtil.*; @@ -30,12 +29,14 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ci.CiRegister.RegisterFlag; -import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; import com.oracle.max.graal.alloc.util.*; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.lir.*; -import com.oracle.max.graal.compiler.lir.LIRInstruction.*; +import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandFlag; +import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandMode; +import com.oracle.max.graal.compiler.lir.LIRInstruction.ValueProcedure; +import com.oracle.max.graal.compiler.lir.LIRPhiMapping.PhiValueProcedure; import com.oracle.max.graal.compiler.schedule.*; import com.oracle.max.graal.compiler.util.*; @@ -43,17 +44,15 @@ private final GraalContext context; private final LIR lir; private final FrameMap frameMap; - private final RiRegisterConfig registerConfig; private final DataFlowAnalysis dataFlow; - public SpillAllAllocator(GraalContext context, LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) { + public SpillAllAllocator(GraalContext context, LIR lir, FrameMap frameMap) { this.context = context; this.lir = lir; - this.registerConfig = registerConfig; this.frameMap = frameMap; - this.dataFlow = new DataFlowAnalysis(context, lir, registerConfig); + this.dataFlow = new DataFlowAnalysis(context, lir, frameMap.registerConfig); this.blockLocations = new LocationMap[lir.linearScanOrder().size()]; this.moveResolver = new MoveResolverImpl(frameMap); } @@ -65,7 +64,7 @@ @Override protected CiValue scratchRegister(Variable spilled) { - EnumMap categorizedRegs = registerConfig.getCategorizedAllocatableRegisters(); + EnumMap categorizedRegs = frameMap.registerConfig.getCategorizedAllocatableRegisters(); CiRegister[] availableRegs = categorizedRegs.get(spilled.flag); for (CiRegister reg : availableRegs) { if (curInRegisterState[reg.number] == null && curOutRegisterState[reg.number] == null) { @@ -110,7 +109,7 @@ } private boolean isAllocatableRegister(CiValue value) { - return isRegister(value) && registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; + return isRegister(value) && frameMap.registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; } @@ -132,7 +131,7 @@ private LIRInstruction curInstruction; public void execute() { - assert LIRVerifier.verify(true, lir, frameMap, registerConfig); + assert LIRVerifier.verify(true, lir, frameMap); dataFlow.execute(); allocate(); @@ -144,13 +143,13 @@ resolveDataFlow.execute(); context.observable.fireCompilationEvent("After resolve data flow", lir); - assert RegisterVerifier.verify(lir, frameMap, registerConfig); + assert RegisterVerifier.verify(lir, frameMap); AssignRegisters assignRegisters = new AssignRegistersImpl(lir, frameMap); assignRegisters.execute(); context.observable.fireCompilationEvent("After register asignment", lir); - assert LIRVerifier.verify(true, lir, frameMap, registerConfig); + assert LIRVerifier.verify(true, lir, frameMap); } private void allocate() { @@ -404,7 +403,7 @@ } } - EnumMap categorizedRegs = registerConfig.getCategorizedAllocatableRegisters(); + EnumMap categorizedRegs = frameMap.registerConfig.getCategorizedAllocatableRegisters(); CiRegister[] availableRegs = categorizedRegs.get(variable.flag); for (CiRegister reg : availableRegs) { @@ -457,7 +456,7 @@ } private boolean checkNoCallerSavedRegister() { - for (CiRegister reg : registerConfig.getCallerSaveRegisters()) { + for (CiRegister reg : frameMap.registerConfig.getCallerSaveRegisters()) { assert curOutRegisterState[reg.number] == null || curOutRegisterState[reg.number] == curInstruction : "caller saved register in use accross call site"; } return true; diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/LIRVerifier.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/LIRVerifier.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/LIRVerifier.java Wed Jan 11 16:17:51 2012 +0100 @@ -28,7 +28,6 @@ import java.util.*; import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; import com.oracle.max.graal.compiler.lir.*; import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandFlag; @@ -41,7 +40,6 @@ public final class LIRVerifier { private final LIR lir; private final FrameMap frameMap; - private final RiRegisterConfig registerConfig; private final boolean beforeRegisterAllocation; @@ -60,7 +58,7 @@ } private boolean isAllocatableRegister(CiValue value) { - return isRegister(value) && registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; + return isRegister(value) && frameMap.registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; } public static boolean verify(final LIRInstruction op) { @@ -74,18 +72,17 @@ return true; } - public static boolean verify(boolean beforeRegisterAllocation, LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) { - LIRVerifier verifier = new LIRVerifier(beforeRegisterAllocation, lir, frameMap, registerConfig); + public static boolean verify(boolean beforeRegisterAllocation, LIR lir, FrameMap frameMap) { + LIRVerifier verifier = new LIRVerifier(beforeRegisterAllocation, lir, frameMap); verifier.verify(); return true; } - private LIRVerifier(boolean beforeRegisterAllocation, LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) { + private LIRVerifier(boolean beforeRegisterAllocation, LIR lir, FrameMap frameMap) { this.beforeRegisterAllocation = beforeRegisterAllocation; this.lir = lir; this.frameMap = frameMap; - this.registerConfig = registerConfig; this.blockLiveOut = new BitSet[lir.linearScanOrder().size()]; this.variableDefinitions = new Object[lir.numVariables()]; } @@ -120,7 +117,7 @@ op.forEachInput(useProc); if (op.hasCall()) { - for (CiRegister register : registerConfig.getCallerSaveRegisters()) { + for (CiRegister register : frameMap.registerConfig.getCallerSaveRegisters()) { curRegistersLive[register.number] = null; } } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/RegisterVerifier.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/RegisterVerifier.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/RegisterVerifier.java Wed Jan 11 16:17:51 2012 +0100 @@ -22,12 +22,12 @@ */ package com.oracle.max.graal.alloc.util; +import static com.oracle.max.cri.ci.CiValueUtil.*; import static com.oracle.max.graal.alloc.util.ValueUtil.*; import java.util.*; import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.lir.*; @@ -36,7 +36,6 @@ public final class RegisterVerifier { private final FrameMap frameMap; - private final RiRegisterConfig registerConfig; /** * All blocks that must be processed. @@ -70,16 +69,15 @@ return new HashMap<>(inputState); } - public static boolean verify(LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) { - RegisterVerifier verifier = new RegisterVerifier(lir, frameMap, registerConfig); + public static boolean verify(LIR lir, FrameMap frameMap) { + RegisterVerifier verifier = new RegisterVerifier(lir, frameMap); verifier.verify(lir.startBlock()); return true; } @SuppressWarnings("unchecked") - private RegisterVerifier(LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) { + private RegisterVerifier(LIR lir, FrameMap frameMap) { this.frameMap = frameMap; - this.registerConfig = registerConfig; this.workList = new LinkedList<>(); this.blockStates = new Map[lir.linearScanOrder().size()]; } @@ -162,7 +160,7 @@ Iterator iter = curInputState.keySet().iterator(); while (iter.hasNext()) { Object value1 = iter.next(); - if (value1 instanceof CiRegister && registerConfig.getAttributesMap()[((CiRegister) value1).number].isCallerSave) { + if (value1 instanceof CiRegister && frameMap.registerConfig.getAttributesMap()[((CiRegister) value1).number].isCallerSave) { trace(2, " remove caller save register %s", value1); iter.remove(); } @@ -187,7 +185,7 @@ } private boolean isIgnoredRegister(CiValue value) { - return isRegister(value) && !registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; + return isRegister(value) && !frameMap.registerConfig.getAttributesMap()[asRegister(value).number].isAllocatable; } private CiValue use(CiValue value) { diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java Wed Jan 11 14:02:08 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,385 +0,0 @@ -/* - * Copyright (c) 2009, 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.compiler; - -import java.util.*; - -import com.oracle.max.asm.*; -import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ci.CiCompiler.DebugInfoLevel; -import com.oracle.max.cri.ri.*; -import com.oracle.max.cri.xir.*; -import com.oracle.max.criutils.*; -import com.oracle.max.graal.alloc.simple.*; -import com.oracle.max.graal.compiler.alloc.*; -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.debug.*; -import com.oracle.max.graal.graph.*; -import com.oracle.max.graal.nodes.*; - -/** - * This class encapsulates global information about the compilation of a particular method, - * including a reference to the runtime, statistics about the compiled code, etc. - */ -public final class GraalCompilation { - public final GraalCompiler compiler; - public final RiResolvedMethod method; - public final RiRegisterConfig registerConfig; - public final CiStatistics stats; - public final FrameState placeholderState; - - public final StructuredGraph graph; - public final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null; - - private FrameMap frameMap; - - private LIR lir; - - /** - * Creates a new compilation for the specified method and runtime. - * - * @param context the compilation context - * @param compiler the compiler - * @param method the method to be compiled or {@code null} if generating code for a stub - * @param osrBCI the bytecode index for on-stack replacement, if requested - * @param stats externally supplied statistics object to be used if not {@code null} - * @param debugInfoLevel TODO - */ - private GraalCompilation(GraalContext context, GraalCompiler compiler, RiResolvedMethod method, StructuredGraph graph, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel) { - if (osrBCI != -1) { - throw new CiBailout("No OSR supported"); - } - this.compiler = compiler; - this.graph = graph; - this.method = method; - this.stats = stats == null ? new CiStatistics() : stats; - this.registerConfig = method == null ? compiler.runtime.getGlobalStubRegisterConfig() : compiler.runtime.getRegisterConfig(method); - this.placeholderState = debugInfoLevel == DebugInfoLevel.REF_MAPS ? new FrameState(method, 0, 0, 0, false) : null; - - if (context().isObserved() && method != null) { - context().observable.fireCompilationStarted(this); - } - } - - public GraalCompilation(GraalContext context, GraalCompiler compiler, RiResolvedMethod method, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel) { - this(context, compiler, method, new StructuredGraph(method), osrBCI, stats, debugInfoLevel); - } - - - public void close() { - // TODO(tw): Check if we can delete this method. - } - - public LIR lir() { - return lir; - } - - /** - * Converts this compilation to a string. - * @return a string representation of this compilation - */ - @Override - public String toString() { - return "compile: " + method; - } - - /** - * Returns the frame map of this compilation. - * @return the frame map - */ - public FrameMap frameMap() { - return frameMap; - } - - private TargetMethodAssembler createAssembler() { - AbstractAssembler masm = compiler.backend.newAssembler(registerConfig); - TargetMethodAssembler tasm = new TargetMethodAssembler(context(), compiler, compiler.target, compiler.runtime, frameMap, lir.slowPaths, masm); - tasm.setFrameSize(frameMap.frameSize()); - tasm.targetMethod.setCustomStackAreaOffset(frameMap.offsetToCustomArea()); - return tasm; - } - - public CiTargetMethod compile(PhasePlan plan) { - CiTargetMethod targetMethod; - try { - try { - emitHIR(plan); - emitLIR(compiler.xir); - targetMethod = emitCode(); - - if (GraalOptions.Meter) { - context().metrics.BytecodesCompiled += method.codeSize(); - } - } catch (CiBailout bailout) { - throw bailout; - } catch (GraalInternalError e) { - throw e.addContext("method", CiUtil.format("%H.%n(%p):%r", method)); - } catch (Throwable t) { - throw new RuntimeException("Exception while compiling: " + method, t); - } - } catch (GraalInternalError error) { - 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 { - if (context().isObserved()) { - context().observable.fireCompilationFinished(this); - } - } - - return targetMethod; - } - - /** - * Builds the graph, optimizes it. - */ - public void emitHIR(PhasePlan plan) { - try { - context().timers.startScope("HIR"); - - 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); - - if (GraalOptions.ProbabilityAnalysis && graph.start().probability() == 0) { - new ComputeProbabilityPhase().apply(graph, context()); - } - - if (GraalOptions.Intrinsify) { - new IntrinsificationPhase(compiler.runtime).apply(graph, context()); - } - - if (GraalOptions.Inline && !plan.isPhaseDisabled(InliningPhase.class)) { - new InliningPhase(compiler.target, compiler.runtime, null, assumptions, plan).apply(graph, context()); - new DeadCodeEliminationPhase().apply(graph, context()); - new PhiStampPhase().apply(graph); - } - - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(compiler.target, compiler.runtime, assumptions).apply(graph, context()); - } - - plan.runPhases(PhasePosition.HIGH_LEVEL, graph, context()); - - if (GraalOptions.OptLoops) { - graph.mark(); - new FindInductionVariablesPhase().apply(graph, context()); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(compiler.target, compiler.runtime, true, assumptions).apply(graph, context()); - } - new SafepointPollingEliminationPhase().apply(graph, context()); - } - - if (GraalOptions.EscapeAnalysis && !plan.isPhaseDisabled(EscapeAnalysisPhase.class)) { - new EscapeAnalysisPhase(compiler.target, compiler.runtime, assumptions, plan).apply(graph, context()); - new PhiStampPhase().apply(graph); - new CanonicalizerPhase(compiler.target, compiler.runtime, assumptions).apply(graph, context()); - } - - if (GraalOptions.OptGVN) { - new GlobalValueNumberingPhase().apply(graph, context()); - } - - graph.mark(); - new LoweringPhase(compiler.runtime).apply(graph, context()); - new CanonicalizerPhase(compiler.target, compiler.runtime, true, assumptions).apply(graph, context()); - - if (GraalOptions.OptLoops) { - graph.mark(); - new RemoveInductionVariablesPhase().apply(graph, context()); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(compiler.target, compiler.runtime, true, assumptions).apply(graph, context()); - } - } - - 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()); - - IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY); - schedule.apply(graph, context()); - stats.loopCount = schedule.loopCount(); - - if (context().isObserved()) { - context().observable.fireCompilationEvent("After IdentifyBlocksPhase", this, graph, schedule); - } - - List blocks = schedule.getBlocks(); - NodeMap 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; - - context().timers.startScope("Compute Linear Scan Order"); - try { - ComputeLinearScanOrder clso = new ComputeLinearScanOrder(blocks.size(), stats.loopCount, startBlock); - List linearScanOrder = clso.linearScanOrder(); - List codeEmittingOrder = clso.codeEmittingOrder(); - - int z = 0; - for (LIRBlock b : linearScanOrder) { - b.setLinearScanNumber(z++); - } - - lir = new LIR(startBlock, linearScanOrder, codeEmittingOrder, valueToBlock, schedule.loopCount()); - - if (context().isObserved()) { - context().observable.fireCompilationEvent("After linear scan order", this, graph, lir); - } - } catch (AssertionError t) { - context().observable.fireCompilationEvent("AssertionError in ComputeLinearScanOrder", CompilationEvent.ERROR, this, graph); - throw t; - } catch (RuntimeException t) { - context().observable.fireCompilationEvent("RuntimeException in ComputeLinearScanOrder", CompilationEvent.ERROR, this, graph); - throw t; - } finally { - context().timers.endScope(); - } - } finally { - context().timers.endScope(); - } - } - - public void initFrameMap() { - frameMap = this.compiler.backend.newFrameMap(registerConfig); - } - - private void emitLIR(RiXirGenerator xir) { - context().timers.startScope("LIR"); - try { - if (GraalOptions.GenLIR) { - context().timers.startScope("Create LIR"); - LIRGenerator lirGenerator = null; - try { - initFrameMap(); - - lirGenerator = compiler.backend.newLIRGenerator(this, xir); - - for (LIRBlock b : lir.linearScanOrder()) { - lirGenerator.doBlock(b); - } - - for (LIRBlock b : lir.linearScanOrder()) { - if (b.phis != null) { - b.phis.fillInputs(lirGenerator); - } - } - } finally { - context().timers.endScope(); - } - - if (context().isObserved()) { - context().observable.fireCompilationEvent("After LIR generation", this, graph, lir); - } - if (GraalOptions.PrintLIR && !TTY.isSuppressed()) { - LIR.printLIR(lir.linearScanOrder()); - } - - if (GraalOptions.AllocSSA) { - new SpillAllAllocator(context(), lir, frameMap, registerConfig).execute(); - } else { - new LinearScan(this, lir, lirGenerator, frameMap()).allocate(); - } - } - } catch (Error e) { - if (context().isObserved() && GraalOptions.PlotOnError) { - context().observable.fireCompilationEvent(e.getClass().getSimpleName() + " in emitLIR", CompilationEvent.ERROR, this, graph); - } - throw e; - } catch (RuntimeException e) { - if (context().isObserved() && GraalOptions.PlotOnError) { - context().observable.fireCompilationEvent(e.getClass().getSimpleName() + " in emitLIR", CompilationEvent.ERROR, this, graph); - } - throw e; - } finally { - context().timers.endScope(); - } - } - - private CiTargetMethod emitCode() { - if (GraalOptions.GenLIR && GraalOptions.GenCode) { - context().timers.startScope("Create Code"); - try { - TargetMethodAssembler tasm = createAssembler(); - 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", this, lir, targetMethod); - } - return targetMethod; - } finally { - context().timers.endScope(); - } - } - - return null; - } - - private GraalContext context() { - return compiler.context; - } - - public void printGraph(String phase, Graph printedGraph) { - if (context().isObserved()) { - context().observable.fireCompilationEvent(phase, this, printedGraph); - } - } -} diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Wed Jan 11 16:17:51 2012 +0100 @@ -22,13 +22,26 @@ */ package com.oracle.max.graal.compiler; +import java.util.*; + +import com.oracle.max.asm.*; import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.cri.xir.*; import com.oracle.max.criutils.*; +import com.oracle.max.graal.alloc.simple.*; +import com.oracle.max.graal.compiler.alloc.*; +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.graph.*; +import com.oracle.max.graal.nodes.*; public class GraalCompiler { @@ -54,20 +67,18 @@ */ public final Backend backend; - public GraalCompiler(GraalContext context, GraalRuntime runtime, CiTarget target, RiXirGenerator xirGen) { + public GraalCompiler(GraalContext context, GraalRuntime runtime, CiTarget target, Backend backend, RiXirGenerator xirGen) { this.context = context; this.runtime = runtime; this.target = target; this.xir = xirGen; - this.backend = Backend.create(target.arch, runtime, target); - xir.initialize(backend.newXirAssembler()); + this.backend = backend; } - public CiTargetMethod compileMethod(RiResolvedMethod method, int osrBCI, CiStatistics stats, CiCompiler.DebugInfoLevel debugInfoLevel) { - return compileMethod(method, osrBCI, stats, debugInfoLevel, PhasePlan.DEFAULT); - } - - public CiTargetMethod compileMethod(RiResolvedMethod method, int osrBCI, CiStatistics stats, CiCompiler.DebugInfoLevel debugInfoLevel, PhasePlan plan) { + public CiTargetMethod compileMethod(RiResolvedMethod method, int osrBCI, PhasePlan plan) { + if (osrBCI != -1) { + throw new CiBailout("No OSR supported"); + } context.timers.startScope(getClass()); try { long startTime = 0; @@ -81,13 +92,38 @@ method.signature().asString())); startTime = System.nanoTime(); } + TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); + StructuredGraph graph = new StructuredGraph(method); CiTargetMethod result = null; - TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); - GraalCompilation compilation = new GraalCompilation(context, this, method, osrBCI, stats, debugInfoLevel); + context.observable.fireCompilationStarted(runtime, target, method); try { - result = compilation.compile(plan); + 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); + } + } 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; @@ -98,7 +134,7 @@ "", time / 10, time % 10, - compilation.graph.getNodeCount(), + graph.getNodeCount(), (result != null ? result.targetCodeSize() : -1))); } } @@ -108,4 +144,223 @@ 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, context); + new DeadCodeEliminationPhase().apply(graph, context); + } else { + if (context.isObserved()) { + context.observable.fireCompilationEvent("initial state", graph); + } + } + + new PhiStampPhase().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.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.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(graph, context); + } + + plan.runPhases(PhasePosition.HIGH_LEVEL, graph, context); + + 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.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.OptGVN) { + new GlobalValueNumberingPhase().apply(graph, context); + } + + graph.mark(); + new LoweringPhase(runtime).apply(graph, context); + new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph, context); + + if (GraalOptions.OptLoops) { + graph.mark(); + new RemoveInductionVariablesPhase().apply(graph, context); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, true, assumptions).apply(graph, context); + } + } + + 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); + + IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY); + schedule.apply(graph, context); + + if (context.isObserved()) { + context.observable.fireCompilationEvent("After IdentifyBlocksPhase", graph, schedule); + } + + List blocks = schedule.getBlocks(); + NodeMap 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; + + context.timers.startScope("Compute Linear Scan Order"); + try { + ComputeLinearScanOrder clso = new ComputeLinearScanOrder(blocks.size(), schedule.loopCount(), startBlock); + List linearScanOrder = clso.linearScanOrder(); + List codeEmittingOrder = clso.codeEmittingOrder(); + + int z = 0; + for (LIRBlock b : linearScanOrder) { + b.setLinearScanNumber(z++); + } + + LIR lir = new LIR(startBlock, linearScanOrder, codeEmittingOrder, valueToBlock, schedule.loopCount()); + + if (context.isObserved()) { + context.observable.fireCompilationEvent("After linear scan order", graph, lir); + } + 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); + + for (LIRBlock b : lir.linearScanOrder()) { + lirGenerator.doBlock(b); + } + + for (LIRBlock b : lir.linearScanOrder()) { + if (b.phis != null) { + b.phis.fillInputs(lirGenerator); + } + } + } finally { + context.timers.endScope(); + } + + if (context.isObserved()) { + context.observable.fireCompilationEvent("After LIR generation", graph, lir); + } + if (GraalOptions.PrintLIR && !TTY.isSuppressed()) { + LIR.printLIR(lir.linearScanOrder()); + } + + if (GraalOptions.AllocSSA) { + new SpillAllAllocator(context, lir, frameMap).execute(); + } else { + new LinearScan(context, 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); + 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); + + 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(); + } + } + + return null; + } } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java Wed Jan 11 16:17:51 2012 +0100 @@ -74,6 +74,45 @@ 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() { diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Wed Jan 11 16:17:51 2012 +0100 @@ -37,9 +37,12 @@ import com.oracle.max.graal.compiler.alloc.Interval.SpillState; import com.oracle.max.graal.compiler.gen.*; import com.oracle.max.graal.compiler.lir.*; -import com.oracle.max.graal.compiler.lir.LIRInstruction.*; +import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandFlag; +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.graph.*; +import com.oracle.max.graal.nodes.*; /** * An implementation of the linear scan register allocator algorithm described @@ -49,7 +52,6 @@ public final class LinearScan { final GraalContext context; - final RiRegisterConfig registerConfig; final CiTarget target; final RiMethod method; final LIR ir; @@ -117,19 +119,21 @@ */ private final int firstVariableNumber; + private final StructuredGraph graph; - public LinearScan(GraalCompilation compilation, LIR ir, LIRGenerator gen, FrameMap frameMap) { - this.context = compilation.compiler.context; - this.target = compilation.compiler.target; - this.registerConfig = compilation.registerConfig; - this.method = compilation.method; + + public LinearScan(GraalContext context, CiTarget target, RiResolvedMethod method, StructuredGraph graph, LIR ir, LIRGenerator gen, FrameMap frameMap) { + this.context = context; + this.target = target; + this.method = method; + this.graph = graph; this.ir = ir; this.gen = gen; this.frameMap = frameMap; this.sortedBlocks = ir.linearScanOrder().toArray(new LIRBlock[ir.linearScanOrder().size()]); - this.registerAttributes = compilation.registerConfig.getAttributesMap(); + this.registerAttributes = frameMap.registerConfig.getAttributesMap(); - this.registers = compilation.compiler.target.arch.registers; + this.registers = target.arch.registers; this.firstVariableNumber = registers.length; this.variables = new ArrayList<>(ir.numVariables() * 3 / 2); } @@ -1063,7 +1067,7 @@ intervals = new Interval[intervalsSize + INITIAL_SPLIT_INTERVALS_CAPACITY]; // create a list with all caller-save registers (cpu, fpu, xmm) - CiRegister[] callerSaveRegs = registerConfig.getCallerSaveRegisters(); + CiRegister[] callerSaveRegs = frameMap.registerConfig.getCallerSaveRegisters(); // iterate all blocks in reverse order for (int i = blockCount() - 1; i >= 0; i--) { @@ -1872,8 +1876,7 @@ } if (context.isObserved()) { - // FIX(ls) -// context.observable.fireCompilationEvent(label, compilation, this, Arrays.copyOf(intervals, intervalsSize)); + context.observable.fireCompilationEvent(label, graph, this, Arrays.copyOf(intervals, intervalsSize)); } } @@ -1886,8 +1889,7 @@ } if (context.isObserved()) { - // FIX(ls) -// context.observable.fireCompilationEvent(label, compilation, hirValid ? compilation.graph : null, compilation.lir()); + context.observable.fireCompilationEvent(label, hirValid ? graph : null, ir); } } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java Wed Jan 11 16:17:51 2012 +0100 @@ -819,7 +819,7 @@ } void initVarsForAlloc(Interval interval) { - EnumMap categorizedRegs = allocator.registerConfig.getCategorizedAllocatableRegisters(); + EnumMap categorizedRegs = allocator.frameMap.registerConfig.getCategorizedAllocatableRegisters(); availableRegs = categorizedRegs.get(asVariable(interval.operand).flag); } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java Wed Jan 11 16:17:51 2012 +0100 @@ -245,7 +245,7 @@ op.forEachInput(useProc); // invalidate all caller save registers at calls if (op.hasCall()) { - for (CiRegister r : allocator.registerConfig.getCallerSaveRegisters()) { + for (CiRegister r : allocator.frameMap.registerConfig.getCallerSaveRegisters()) { statePut(inputState, r.asValue(), null); } } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java Wed Jan 11 16:17:51 2012 +0100 @@ -43,15 +43,13 @@ public final RiRuntime runtime; public final FrameMap frameMap; public final List slowPaths; - public final GraalCompiler compiler; private List exceptionInfoList; private int lastSafepointPos; private final GraalContext context; - public TargetMethodAssembler(GraalContext context, GraalCompiler compiler, CiTarget target, RiRuntime runtime, FrameMap frameMap, List slowPaths, AbstractAssembler asm) { + public TargetMethodAssembler(GraalContext context, CiTarget target, RiRuntime runtime, FrameMap frameMap, List slowPaths, AbstractAssembler asm) { this.context = context; - this.compiler = compiler; this.target = target; this.runtime = runtime; this.frameMap = frameMap; diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/DebugInfoBuilder.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/DebugInfoBuilder.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/DebugInfoBuilder.java Wed Jan 11 16:17:51 2012 +0100 @@ -33,22 +33,16 @@ import com.oracle.max.graal.nodes.virtual.*; public class DebugInfoBuilder { - private final boolean disable; private final NodeMap nodeOperands; - public DebugInfoBuilder(NodeMap nodeOperands, boolean disable) { + public DebugInfoBuilder(NodeMap nodeOperands) { this.nodeOperands = nodeOperands; - this.disable = disable; } private HashMap virtualObjects = new HashMap<>(); public LIRDebugInfo build(FrameState topState, LockScope locks, List pointerSlots, LabelRef exceptionEdge) { - if (disable) { - return null; - } - assert virtualObjects.size() == 0; CiFrame frame = computeFrameForState(topState, locks); diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jan 11 16:17:51 2012 +0100 @@ -70,7 +70,6 @@ protected final CiTarget target; protected final RiResolvedMethod method; protected final FrameMap frameMap; - protected final RiRegisterConfig registerConfig; public final NodeMap nodeOperands; protected final LIR lir; @@ -139,19 +138,18 @@ private LockScope curLocks; - public LIRGenerator(GraalCompilation compilation, RiXirGenerator xir) { - this.context = compilation.compiler.context; - this.graph = compilation.graph; - this.runtime = compilation.compiler.runtime; - this.target = compilation.compiler.target; - this.frameMap = compilation.frameMap(); - this.method = compilation.method; - this.registerConfig = compilation.registerConfig; + public LIRGenerator(GraalContext context, Graph graph, RiRuntime runtime, CiTarget target, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir) { + this.context = context; + this.graph = graph; + this.runtime = runtime; + this.target = target; + this.frameMap = frameMap; + this.method = method; this.nodeOperands = graph.createNodeMap(); - this.lir = compilation.lir(); + this.lir = lir; this.xir = xir; this.xirSupport = new XirSupport(); - this.debugInfoBuilder = new DebugInfoBuilder(nodeOperands, compilation.placeholderState != null); + this.debugInfoBuilder = new DebugInfoBuilder(nodeOperands); this.blockLocks = new LockScope[lir.linearScanOrder().size()]; } @@ -275,7 +273,7 @@ if (kind == CiKind.Void) { return IllegalValue; } - return registerConfig.getReturnRegister(kind).asValue(kind); + return frameMap.registerConfig.getReturnRegister(kind).asValue(kind); } @@ -440,7 +438,7 @@ } private void emitPrologue() { - CiCallingConvention incomingArguments = registerConfig.getCallingConvention(JavaCallee, CiUtil.signatureToKinds(method), target, false); + CiCallingConvention incomingArguments = frameMap.registerConfig.getCallingConvention(JavaCallee, CiUtil.signatureToKinds(method), target, false); CiValue[] params = new CiValue[incomingArguments.locations.length]; for (int i = 0; i < params.length; i++) { @@ -890,7 +888,7 @@ CiValue resultOperand = resultOperandFor(x.node().kind()); CiKind[] signature = CiUtil.signatureToKinds(callTarget.targetMethod().signature(), callTarget.isStatic() ? null : callTarget.targetMethod().holder().kind(true)); - CiCallingConvention cc = registerConfig.getCallingConvention(JavaCall, signature, target(), false); + CiCallingConvention cc = frameMap.registerConfig.getCallingConvention(JavaCall, signature, target(), false); frameMap.callsMethod(cc, JavaCall); List pointerSlots = new ArrayList<>(2); List argList = visitInvokeArguments(cc, callTarget.arguments(), pointerSlots); @@ -970,7 +968,7 @@ List argumentList; if (arguments.length > 0) { // move the arguments into the correct location - CiCallingConvention cc = registerConfig.getCallingConvention(RuntimeCall, arguments, target(), false); + CiCallingConvention cc = frameMap.registerConfig.getCallingConvention(RuntimeCall, arguments, target(), false); frameMap.callsMethod(cc, RuntimeCall); assert cc.locations.length == args.length : "argument count mismatch"; for (int i = 0; i < args.length; i++) { @@ -999,7 +997,7 @@ // TODO Merge with emitCallToRuntime() method above. CiValue resultOperand = resultOperandFor(x.kind()); - CiCallingConvention cc = registerConfig.getCallingConvention(RuntimeCall, x.call().arguments, target(), false); + CiCallingConvention cc = frameMap.registerConfig.getCallingConvention(RuntimeCall, x.call().arguments, target(), false); frameMap.callsMethod(cc, RuntimeCall); List pointerSlots = new ArrayList<>(2); List argList = visitInvokeArguments(cc, x.arguments(), pointerSlots); @@ -1336,7 +1334,7 @@ List argumentList; if (arguments.length > 0) { // move the arguments into the correct location - CiCallingConvention cc = registerConfig.getCallingConvention(RuntimeCall, arguments, target(), false); + CiCallingConvention cc = frameMap.registerConfig.getCallingConvention(RuntimeCall, arguments, target(), false); frameMap.callsMethod(cc, RuntimeCall); assert cc.locations.length == args.length : "argument count mismatch"; for (int i = 0; i < args.length; i++) { diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java Wed Jan 11 16:17:51 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.observer; +import java.util.*; + /** * An event that occurred during compilation. Instances of this class provide information about the event and the state * of the compilation when the event was raised. Depending on the state of the compiler and the compilation phase, @@ -36,16 +38,17 @@ public static final Object ERROR = new Object() {}; public final String label; - private Object[] debugObjects; + private List debugObjects; - protected CompilationEvent(String label, Object...debugObjects) { + protected CompilationEvent(String label, ArrayList debugObjects) { this.label = label; this.debugObjects = debugObjects; } @SuppressWarnings("unchecked") public T debugObject(Class type) { - for (Object o : debugObjects) { + for (ListIterator iter = debugObjects.listIterator(debugObjects.size()); iter.hasPrevious();) { + Object o = iter.previous(); if (type.isInstance(o)) { return (T) o; } @@ -54,7 +57,8 @@ } public boolean hasDebugObject(Object search) { - for (Object o : debugObjects) { + for (ListIterator iter = debugObjects.listIterator(debugObjects.size()); iter.hasPrevious();) { + Object o = iter.previous(); if (o == search) { return true; } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationObserver.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationObserver.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationObserver.java Wed Jan 11 16:17:51 2012 +0100 @@ -22,7 +22,6 @@ */ package com.oracle.max.graal.compiler.observer; -import com.oracle.max.graal.compiler.*; /** * Interface for classes that observe events of an {@link ObservableCompiler}. @@ -31,11 +30,11 @@ /** * Called when compilation of a method has started. This is always the first event raised for a particular - * {@link GraalCompilation}. + * method compilation. * - * @param compilation Current state of the compilation. + * @param event Information associated with the event and current state of the compilation. */ - void compilationStarted(GraalCompilation compilation); + void compilationStarted(CompilationEvent event); /** * Called when an event has occurred, for example that a particular phase in the compilation has been entered. @@ -46,10 +45,10 @@ /** * Called when compilation of a method has completed (successfully or not). This is always the last event raised for - * a particular {@link GraalCompilation}. + * a particular method compilation. * - * @param compilation Current state of the compilation. + * @param event Information associated with the event and current state of the compilation. */ - void compilationFinished(GraalCompilation compilation); + void compilationFinished(CompilationEvent event); } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableContext.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableContext.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableContext.java Wed Jan 11 16:17:51 2012 +0100 @@ -24,8 +24,6 @@ import java.util.*; -import com.oracle.max.graal.compiler.*; - /** * Base class for compilers that notify subscribed {@link CompilationObserver CompilationObservers} of * {@link CompilationEvent CompilationEvents} that occur during their compilations. @@ -34,6 +32,20 @@ private List observers; + private ThreadLocal scopeName = new ThreadLocal() { + @Override + protected StringBuilder initialValue() { + return new StringBuilder(); + } + }; + + private ThreadLocal> debugObjects = new ThreadLocal>() { + @Override + protected ArrayList initialValue() { + return new ArrayList<>(); + } + }; + /** * @return {@code true} if one or more observers are subscribed to receive notifications from this compiler, * {@code false} otherwise. @@ -56,28 +68,36 @@ observers.add(observer); } - public void fireCompilationStarted(GraalCompilation compilation) { + public void fireCompilationStarted(Object... additionalDebugObjects) { if (isObserved()) { + addDebugObjects(null, additionalDebugObjects); + CompilationEvent event = new CompilationEvent("started", debugObjects.get()); for (CompilationObserver observer : observers) { - observer.compilationStarted(compilation); + observer.compilationStarted(event); } + removeDebugObjects(null, additionalDebugObjects); } } - public void fireCompilationEvent(String label, Object...debugObjects) { + public void fireCompilationEvent(String label, Object... additionalDebugObjects) { if (isObserved()) { - CompilationEvent event = new CompilationEvent(label, debugObjects); + addDebugObjects(null, additionalDebugObjects); + CompilationEvent event = new CompilationEvent(label, debugObjects.get()); for (CompilationObserver observer : observers) { observer.compilationEvent(event); } + removeDebugObjects(null, additionalDebugObjects); } } - public void fireCompilationFinished(GraalCompilation compilation) { + public void fireCompilationFinished(Object... additionalDebugObjects) { if (isObserved()) { + addDebugObjects(null, additionalDebugObjects); + CompilationEvent event = new CompilationEvent("finished", debugObjects.get()); for (CompilationObserver observer : observers) { - observer.compilationFinished(compilation); + observer.compilationFinished(event); } + removeDebugObjects(null, additionalDebugObjects); } } @@ -100,4 +120,25 @@ observers = null; } } + + public void addDebugObjects(String name, Object[] additionalDebugObjects) { + if (name != null) { + if (scopeName.get().length() > 0) { + scopeName.get().append('.'); + } + scopeName.get().append(name); + } + for (Object obj : additionalDebugObjects) { + debugObjects.get().add(obj); + } + } + + public void removeDebugObjects(String name, Object[] additionalDebugObjects) { + if (name != null) { + scopeName.get().setLength(Math.max(0, scopeName.get().length() - name.length())); + } + for (int i = 0; i < additionalDebugObjects.length; i++) { + debugObjects.get().remove(debugObjects.get().size() - 1); + } + } } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java Wed Jan 11 16:17:51 2012 +0100 @@ -31,6 +31,7 @@ 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.*; /** * The {@code Backend} class represents a compiler backend for Graal. @@ -56,7 +57,7 @@ } public abstract FrameMap newFrameMap(RiRegisterConfig registerConfig); - public abstract LIRGenerator newLIRGenerator(GraalCompilation compilation, RiXirGenerator xir); + public abstract LIRGenerator newLIRGenerator(GraalContext context, Graph graph, FrameMap frameMap, RiResolvedMethod method, LIR lir, RiXirGenerator xir); public abstract AbstractAssembler newAssembler(RiRegisterConfig registerConfig); public abstract CiXirAssembler newXirAssembler(); diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java Wed Jan 11 16:17:51 2012 +0100 @@ -31,6 +31,7 @@ import com.oracle.max.graal.compiler.gen.*; import com.oracle.max.graal.compiler.lir.*; import com.oracle.max.graal.compiler.target.*; +import com.oracle.max.graal.graph.*; /** * The {@code X86Backend} class represents the backend for the AMD64 architecture. @@ -46,8 +47,8 @@ * @return an appropriate LIR generator instance */ @Override - public LIRGenerator newLIRGenerator(GraalCompilation compilation, RiXirGenerator xir) { - return new AMD64LIRGenerator(compilation, xir); + 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); } @Override diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Jan 11 16:17:51 2012 +0100 @@ -40,11 +40,13 @@ import com.oracle.max.asm.*; import com.oracle.max.asm.target.amd64.*; 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.*; +import com.oracle.max.graal.graph.*; import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction; import com.oracle.max.graal.nodes.*; import com.oracle.max.graal.nodes.calc.*; @@ -72,8 +74,8 @@ StandardOpcode.XIR = AMD64XirOpcode.XIR; } - public AMD64LIRGenerator(GraalCompilation compilation, RiXirGenerator xir) { - super(compilation, 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); lir.methodEndMarker = new AMD64MethodEndStub(); } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java Wed Jan 11 16:17:51 2012 +0100 @@ -31,6 +31,7 @@ import com.oracle.max.cri.xir.*; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.observer.*; +import com.oracle.max.graal.compiler.target.*; import com.oracle.max.graal.cri.*; import com.oracle.max.graal.hotspot.bridge.*; import com.oracle.max.graal.hotspot.logging.*; @@ -158,7 +159,11 @@ if (Logger.ENABLED) { generator = LoggingProxy.getProxy(RiXirGenerator.class, generator); } - compiler = new GraalCompiler(context, getRuntime(), getTarget(), generator); + + Backend backend = Backend.create(target.arch, runtime, target); + generator.initialize(backend.newXirAssembler()); + + compiler = new GraalCompiler(context, getRuntime(), getTarget(), backend, generator); } return compiler; } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java Wed Jan 11 16:17:51 2012 +0100 @@ -27,12 +27,11 @@ import java.util.concurrent.*; import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ci.CiCompiler.*; import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.phases.*; -import com.oracle.max.graal.compiler.phases.PhasePlan.*; +import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition; import com.oracle.max.graal.hotspot.*; import com.oracle.max.graal.hotspot.Compiler; import com.oracle.max.graal.hotspot.ri.*; @@ -168,9 +167,9 @@ public void run() { try { PhasePlan plan = new PhasePlan(); - GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime(), null); + GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime()); plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); - CiTargetMethod result = compiler.getCompiler().compileMethod(method, -1, null, DebugInfoLevel.FULL, plan); + CiTargetMethod result = compiler.getCompiler().compileMethod(method, -1, plan); HotSpotTargetMethod.installMethod(compiler, method, result, true); } catch (CiBailout bailout) { if (GraalOptions.ExitVMOnBailout) { diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java Wed Jan 11 16:17:51 2012 +0100 @@ -67,7 +67,6 @@ private StructuredGraph currentGraph; - private final CiStatistics stats; private final RiRuntime runtime; private RiConstantPool constantPool; private RiExceptionHandler[] exceptionHandlers; @@ -104,17 +103,12 @@ private final GraphBuilderConfiguration config; public GraphBuilderPhase(RiRuntime runtime) { - this(runtime, null); + this(runtime, GraphBuilderConfiguration.getDefault()); } - public GraphBuilderPhase(RiRuntime runtime, CiStatistics stats) { - this(runtime, stats, GraphBuilderConfiguration.getDefault()); - } - - public GraphBuilderPhase(RiRuntime runtime, CiStatistics stats, GraphBuilderConfiguration config) { + public GraphBuilderPhase(RiRuntime runtime, GraphBuilderConfiguration config) { this.config = config; this.runtime = runtime; - this.stats = stats; this.log = GraalOptions.TraceBytecodeParserLevel > 0 ? new LogStream(TTY.out()) : null; } @@ -144,9 +138,7 @@ private BlockMap createBlockMap() { BlockMap map = new BlockMap(method, config.useBranchPrediction()); map.build(); - if (stats != null) { - stats.bytecodeCount += method.code().length; - } + currentContext.metrics.bytecodeCount += method.code().length; if (currentContext.isObserved()) { String label = CiUtil.format("BlockListBuilder %f %R %H.%n(%P)", method); @@ -166,9 +158,8 @@ this.canTrapBitSet = blockMap.canTrap; exceptionHandlers = blockMap.exceptionHandlers(); - if (stats != null) { - stats.blockCount += blockMap.blocks.size(); - } + currentContext.metrics.blockCount += blockMap.blocks.size(); + nextBlockNumber = blockMap.blocks.size(); lastInstr = currentGraph.start(); @@ -209,9 +200,7 @@ } private int nextBlockNumber() { - if (stats != null) { - stats.blockCount++; - } + currentContext.metrics.blockCount++; return nextBlockNumber++; } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinter.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinter.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinter.java Wed Jan 11 16:17:51 2012 +0100 @@ -30,15 +30,15 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; -import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.alloc.*; import com.oracle.max.graal.compiler.alloc.Interval.UsePosList; import com.oracle.max.graal.compiler.gen.*; import com.oracle.max.graal.compiler.lir.*; import com.oracle.max.graal.compiler.schedule.*; import com.oracle.max.graal.graph.*; -import com.oracle.max.graal.graph.Node.*; -import com.oracle.max.graal.graph.NodeClass.*; +import com.oracle.max.graal.graph.Node.Verbosity; +import com.oracle.max.graal.graph.NodeClass.NodeClassIterator; +import com.oracle.max.graal.graph.NodeClass.Position; import com.oracle.max.graal.java.*; import com.oracle.max.graal.nodes.*; import com.oracle.max.graal.nodes.calc.*; @@ -49,34 +49,25 @@ class CFGPrinter extends CompilationPrinter { public final ByteArrayOutputStream buffer; - private final LIR lir; - private LIRGenerator lirGenerator; public final CiTarget target; public final RiRuntime runtime; + private LIR lir; + private LIRGenerator lirGenerator; /** * Creates a control flow graph printer. * * @param buffer where the output generated via this printer shown be written - * @param nodeOperands */ - public CFGPrinter(ByteArrayOutputStream buffer, GraalCompilation compilation) { + public CFGPrinter(ByteArrayOutputStream buffer, CiTarget target, RiRuntime runtime) { super(buffer); this.buffer = buffer; - this.lir = compilation.lir(); - this.target = compilation.compiler.target; - this.runtime = compilation.compiler.runtime; - } - - public CFGPrinter(ByteArrayOutputStream buffer, GraalCompilation compilation, CiTarget target, RiRuntime runtime) { - super(buffer); - this.buffer = buffer; - this.lir = compilation.lir(); this.target = target; this.runtime = runtime; } - public void setLIRGenerator(LIRGenerator lirGenerator) { + public void setLIR(LIR lir, LIRGenerator lirGenerator) { + this.lir = lir; this.lirGenerator = lirGenerator; } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinterObserver.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/CFGPrinterObserver.java Wed Jan 11 16:17:51 2012 +0100 @@ -28,7 +28,6 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; -import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.alloc.*; import com.oracle.max.graal.compiler.gen.*; import com.oracle.max.graal.compiler.lir.*; @@ -55,13 +54,15 @@ }; @Override - public void compilationStarted(GraalCompilation compilation) { + public void compilationStarted(CompilationEvent event) { if (TTY.isSuppressed()) { return; } + RiRuntime runtime = event.debugObject(RiRuntime.class); + CiTarget target = event.debugObject(CiTarget.class); - CFGPrinter cfgPrinter = new CFGPrinter(new ByteArrayOutputStream(), compilation); - cfgPrinter.printCompilation(compilation.method); + CFGPrinter cfgPrinter = new CFGPrinter(new ByteArrayOutputStream(), target, runtime); + cfgPrinter.printCompilation(event.debugObject(RiResolvedMethod.class)); observations.get().push(cfgPrinter); } @@ -76,7 +77,7 @@ } RiRuntime runtime = cfgPrinter.runtime; - cfgPrinter.setLIRGenerator(event.debugObject(LIRGenerator.class)); + cfgPrinter.setLIR(event.debugObject(LIR.class), event.debugObject(LIRGenerator.class)); BlockMap blockMap = event.debugObject(BlockMap.class); Graph graph = event.debugObject(Graph.class); IdentifyBlocksPhase schedule = event.debugObject(IdentifyBlocksPhase.class); @@ -118,7 +119,7 @@ } @Override - public void compilationFinished(GraalCompilation compilation) { + public void compilationFinished(CompilationEvent event) { if (TTY.isSuppressed()) { return; } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java Wed Jan 11 16:17:51 2012 +0100 @@ -85,23 +85,23 @@ } @Override - public void compilationStarted(GraalCompilation compilation) { - openPrinter(compilation, false); + public void compilationStarted(CompilationEvent event) { + openPrinter(event.debugObject(RiResolvedMethod.class), false); } - private void openPrinter(GraalCompilation compilation, boolean error) { + private void openPrinter(RiResolvedMethod method, boolean error) { assert (context().stream == null && printer() == null); if ((!TTY.isSuppressed() && GraalOptions.Plot) || (GraalOptions.PlotOnError && error)) { String name; - if (compilation != null) { - name = compilation.method.holder().name(); + if (method != null) { + name = method.holder().name(); name = name.substring(1, name.length() - 1).replace('/', '.'); - name = name + "." + compilation.method.name(); + name = name + "." + method.name(); } else { name = "null"; } - openPrinter(name, compilation == null ? null : compilation.method); + openPrinter(name, method); } } @@ -189,7 +189,7 @@ public void compilationEvent(CompilationEvent event) { boolean lazyStart = false; if (printer() == null && event.hasDebugObject(CompilationEvent.ERROR)) { - openPrinter(event.debugObject(GraalCompilation.class), true); + openPrinter(event.debugObject(RiResolvedMethod.class), true); lazyStart = true; } Graph graph = event.debugObject(Graph.class); @@ -202,7 +202,7 @@ } @Override - public void compilationFinished(GraalCompilation compilation) { + public void compilationFinished(CompilationEvent event) { if (printer() != null) { closePrinter(); } diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java --- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java Wed Jan 11 16:17:51 2012 +0100 @@ -129,7 +129,7 @@ private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, GraalContext context, BoxingMethodPool pool, PhasePlan plan, IdealGraphPrinterObserver observer) { GraphBuilderConfiguration config = GraphBuilderConfiguration.getDeoptFreeDefault(); - GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, null, config); + GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config); StructuredGraph graph = new StructuredGraph(snippetRiMethod); graphBuilder.apply(graph, context); diff -r 6043f74b1ca0 -r 4643ccd37dac graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java Wed Jan 11 14:02:08 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java Wed Jan 11 16:17:51 2012 +0100 @@ -103,13 +103,13 @@ protected StructuredGraph parse(Method m) { RiResolvedMethod riMethod = runtime.getRiMethod(m); StructuredGraph graph = new StructuredGraph(riMethod); - new GraphBuilderPhase(runtime, null, GraphBuilderConfiguration.getDeoptFreeDefault()).apply(graph); + new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDeoptFreeDefault()).apply(graph); return graph; } protected PhasePlan getDefaultPhasePlan() { PhasePlan plan = new PhasePlan(); - plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, null, GraphBuilderConfiguration.getDeoptFreeDefault())); + plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDeoptFreeDefault())); return plan; }