Mercurial > hg > graal-compiler
changeset 19911:d8e7f4eaaa8b
Make DynamicCounterNode LIRLowerable.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Mon, 16 Mar 2015 17:36:45 +0100 |
parents | 3bc0ac89fa5a |
children | 94289b44c934 |
files | graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java |
diffstat | 3 files changed, 32 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Tue Mar 17 17:19:04 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Mon Mar 16 17:36:45 2015 +0100 @@ -27,26 +27,13 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import sun.misc.*; - -import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.debug.*; -import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.bridge.*; -import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.replacements.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.HeapAccess.BarrierType; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.debug.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.options.*; -import com.oracle.graal.replacements.nodes.*; import edu.umd.cs.findbugs.annotations.*; @@ -155,36 +142,6 @@ return counter; } - private static int getIndex(DynamicCounterNode counter, StructuredGraph currentGraph, HotSpotVMConfig config) { - if (!enabled) { - throw new GraalInternalError("counter nodes shouldn't exist when counters are not enabled: " + counter.getGroup() + ", " + counter.getName()); - } - String name; - String group = counter.getGroup(); - if (counter.isWithContext()) { - name = counter.getName() + " @ "; - if (currentGraph.method() != null) { - StackTraceElement stackTraceElement = currentGraph.method().asStackTraceElement(0); - if (stackTraceElement != null) { - name += " " + stackTraceElement.toString(); - } else { - name += currentGraph.method().format("%h.%n"); - } - } - if (currentGraph.name != null) { - name += " (" + currentGraph.name + ")"; - } - name += "#" + group; - - } else { - name = counter.getName() + "#" + group; - } - if (counter.getIncrement().isConstant()) { - return getIndexConstantIncrement(name, group, config, counter.getIncrement().asJavaConstant().asLong()); - } - return getIndex(name, group, config); - } - private static synchronized void dump(PrintStream out, double seconds, long[] counters, int maxRows) { if (!counterMap.isEmpty()) { out.println("====== dynamic counters (" + counterMap.size() + " in total) ======"); @@ -417,47 +374,4 @@ dump(TTY.cachedOut, (System.nanoTime() - compilerStartTime) / 1000000000d, compilerToVM.collectCounters(), 100); } } - - private static final LocationIdentity COUNTER_ARRAY_LOCATION = NamedLocationIdentity.mutable("COUNTER_ARRAY_LOCATION"); - private static final LocationIdentity COUNTER_LOCATION = NamedLocationIdentity.mutable("COUNTER_LOCATION"); - - @NodeInfo(nameTemplate = "CounterIndex") - private static final class CounterIndexNode extends FloatingNode implements LIRLowerable { - - public static final NodeClass<CounterIndexNode> TYPE = NodeClass.create(CounterIndexNode.class); - protected final Object counter; - protected final HotSpotVMConfig config; - - protected CounterIndexNode(Stamp stamp, DynamicCounterNode counter, HotSpotVMConfig config) { - super(TYPE, stamp); - this.config = config; - this.counter = counter; - } - - @Override - public void generate(NodeLIRBuilderTool generator) { - int index = BenchmarkCounters.getIndex((DynamicCounterNode) counter, graph(), config); - generator.setResult(this, JavaConstant.forIntegerKind(getKind(), index)); - } - } - - public static void lower(DynamicCounterNode counter, HotSpotRegistersProvider registers, HotSpotVMConfig config, Kind wordKind) { - StructuredGraph graph = counter.graph(); - - ReadRegisterNode thread = graph.add(new ReadRegisterNode(registers.getThreadRegister(), wordKind, true, false)); - - CounterIndexNode index = graph.unique(new CounterIndexNode(StampFactory.forKind(wordKind), counter, config)); - ConstantLocationNode arrayLocation = graph.unique(new ConstantLocationNode(COUNTER_ARRAY_LOCATION, config.graalCountersThreadOffset)); - ReadNode readArray = graph.add(new ReadNode(thread, arrayLocation, StampFactory.forKind(wordKind), BarrierType.NONE)); - IndexedLocationNode location = graph.unique(new IndexedLocationNode(COUNTER_LOCATION, 0, index, Unsafe.ARRAY_LONG_INDEX_SCALE)); - ReadNode read = graph.add(new ReadNode(readArray, location, StampFactory.forKind(Kind.Long), BarrierType.NONE)); - AddNode add = graph.unique(new AddNode(read, counter.getIncrement())); - WriteNode write = graph.add(new WriteNode(readArray, add, location, BarrierType.NONE)); - - graph.addBeforeFixed(counter, thread); - graph.addBeforeFixed(counter, readArray); - graph.addBeforeFixed(counter, read); - graph.addBeforeFixed(counter, write); - graph.removeFixed(counter); - } }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Tue Mar 17 17:19:04 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java Mon Mar 16 17:36:45 2015 +0100 @@ -36,7 +36,6 @@ import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.debug.*; import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.hotspot.nodes.type.*; import com.oracle.graal.hotspot.replacements.*; @@ -105,8 +104,6 @@ lowerStoreHubNode((StoreHubNode) n, graph); } else if (n instanceof OSRStartNode) { lowerOSRStartNode((OSRStartNode) n); - } else if (n instanceof DynamicCounterNode) { - lowerDynamicCounterNode((DynamicCounterNode) n); } else if (n instanceof BytecodeExceptionNode) { lowerBytecodeExceptionNode((BytecodeExceptionNode) n); } else if (n instanceof CheckCastDynamicNode) { @@ -369,13 +366,6 @@ } } - private void lowerDynamicCounterNode(DynamicCounterNode n) { - StructuredGraph graph = n.graph(); - if (graph.getGuardsStage().areFrameStatesAtDeopts()) { - BenchmarkCounters.lower(n, registers, runtime.getConfig(), runtime.getTarget().wordKind); - } - } - static final class Exceptions { protected static final ArrayIndexOutOfBoundsException cachedArrayIndexOutOfBoundsException; protected static final NullPointerException cachedNullPointerException;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java Tue Mar 17 17:19:04 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java Mon Mar 16 17:36:45 2015 +0100 @@ -22,8 +22,11 @@ */ package com.oracle.graal.nodes.debug; +import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; +import com.oracle.graal.lir.*; +import com.oracle.graal.lir.gen.*; import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; @@ -37,7 +40,7 @@ * value of withContext, the name of the root method is added to the counter's name. */ @NodeInfo -public class DynamicCounterNode extends FixedWithNextNode implements Lowerable { +public class DynamicCounterNode extends FixedWithNextNode implements LIRLowerable { public static final NodeClass<DynamicCounterNode> TYPE = NodeClass.create(DynamicCounterNode.class); @Input ValueNode increment; @@ -74,11 +77,6 @@ return withContext; } - @Override - public void lower(LoweringTool tool) { - tool.getLowerer().lower(this, tool); - } - public static void addCounterBefore(String group, String name, long increment, boolean withContext, FixedNode position) { StructuredGraph graph = position.graph(); graph.addBeforeFixed(position, position.graph().add(new DynamicCounterNode(name, group, ConstantNode.forLong(increment, position.graph()), withContext))); @@ -87,4 +85,32 @@ @NodeIntrinsic public static native void counter(@ConstantNodeParameter String name, @ConstantNodeParameter String group, long increment, @ConstantNodeParameter boolean addContext); + public void generate(NodeLIRBuilderTool generator) { + LIRGeneratorTool lirGen = generator.getLIRGeneratorTool(); + String nameWithContext; + if (isWithContext()) { + nameWithContext = getName() + " @ "; + if (graph().method() != null) { + StackTraceElement stackTraceElement = graph().method().asStackTraceElement(0); + if (stackTraceElement != null) { + nameWithContext += " " + stackTraceElement.toString(); + } else { + nameWithContext += graph().method().format("%h.%n"); + } + } + if (graph().name != null) { + nameWithContext += " (" + graph().name + ")"; + } + + } else { + nameWithContext = getName(); + } + LIRInstruction counterOp = lirGen.createBenchmarkCounter(nameWithContext, getGroup(), generator.operand(increment)); + if (counterOp != null) { + lirGen.append(counterOp); + } else { + throw GraalInternalError.unimplemented("Benchmark counters not enabled or not implemented by the back end."); + } + } + }