# HG changeset patch # User Lukas Stadler # Date 1422961422 -3600 # Node ID a8a2cc98eb558e0bfdec7ea884c755beb82eba71 # Parent 9865883b51148aca910183a093a4bf6d63b1ba41 allocation profiling fixes diff -r 9865883b5114 -r a8a2cc98eb55 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Tue Feb 03 15:29:03 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Tue Feb 03 12:03:42 2015 +0100 @@ -37,11 +37,13 @@ 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.*; @@ -108,17 +110,24 @@ public static final ArrayList staticCounters = new ArrayList<>(); @SuppressFBWarnings(value = "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", justification = "concurrent abstraction calls are in synchronized block") - private static int getIndex(DynamicCounterNode counter) { + private static int getIndex(DynamicCounterNode counter, StructuredGraph currentGraph) { 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()) { - StructuredGraph graph = counter.graph(); - name = counter.getName() + " @ " + graph.graphId() + ":" + (graph.method() == null ? "" : graph.method().format("%h.%n")); - if (graph.name != null) { - name += " (" + graph.name + ")"; + 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; @@ -374,20 +383,41 @@ } } + 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 class CounterIndexNode extends FloatingNode implements LIRLowerable { + + protected final Object counter; + protected final int countersSize; + + protected CounterIndexNode(Stamp stamp, DynamicCounterNode counter, int countersSize) { + super(stamp); + this.countersSize = countersSize; + this.counter = counter; + } + + @Override + public void generate(NodeLIRBuilderTool generator) { + int index = BenchmarkCounters.getIndex((DynamicCounterNode) counter, graph()); + if (index >= countersSize) { + throw new GraalInternalError("too many counters, reduce number of counters or increase -XX:GraalCounterSize=... (current value: " + countersSize + ")"); + } + + 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)); - int index = BenchmarkCounters.getIndex(counter); - if (index >= config.graalCountersSize) { - throw new GraalInternalError("too many counters, reduce number of counters or increase -XX:GraalCounterSize=... (current value: " + config.graalCountersSize + ")"); - } - ConstantLocationNode arrayLocation = graph.unique(new ConstantLocationNode(COUNTER_LOCATION, config.graalCountersThreadOffset)); + CounterIndexNode index = graph.unique(new CounterIndexNode(StampFactory.forKind(wordKind), counter, config.graalCountersSize)); + ConstantLocationNode arrayLocation = graph.unique(new ConstantLocationNode(COUNTER_ARRAY_LOCATION, config.graalCountersThreadOffset)); ReadNode readArray = graph.add(new ReadNode(thread, arrayLocation, StampFactory.forKind(wordKind), BarrierType.NONE)); - ConstantLocationNode location = graph.unique(new ConstantLocationNode(COUNTER_LOCATION, Unsafe.ARRAY_LONG_INDEX_SCALE * index)); + 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)); diff -r 9865883b5114 -r a8a2cc98eb55 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java Tue Feb 03 15:29:03 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java Tue Feb 03 12:03:42 2015 +0100 @@ -41,12 +41,18 @@ @Override public Object asObject(ResolvedJavaType type, JavaConstant constant) { + if (constant.isNull()) { + return null; + } HotSpotObjectConstant hsConstant = (HotSpotObjectConstant) constant; return hsConstant.asObject(type); } @Override public T asObject(Class type, JavaConstant constant) { + if (constant.isNull()) { + return null; + } HotSpotObjectConstant hsConstant = (HotSpotObjectConstant) constant; return hsConstant.asObject(type); }