# HG changeset patch # User Christian Wimmer # Date 1353985108 28800 # Node ID 89df4e71940ad78bb84b61f97369fddecb7580da # Parent d9930fec7553b43f3475fb6af082de6d3bd3228f More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state. diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Nov 26 18:58:28 2012 -0800 @@ -33,7 +33,6 @@ import com.oracle.graal.hotspot.logging.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; /** @@ -62,7 +61,6 @@ } private static Kind wordKind; - private static Stamp wordStamp; /** * Gets the kind of a word value. @@ -72,14 +70,6 @@ return wordKind; } - /** - * Gets the stamp for a word value. - */ - public static Stamp wordStamp() { - assert wordStamp != null; - return wordStamp; - } - protected final CompilerToVM compilerToVm; protected final VMToCompiler vmToCompiler; @@ -122,7 +112,6 @@ target = createTarget(); assert wordKind == null || wordKind.equals(target.wordKind); wordKind = target.wordKind; - wordStamp = StampFactory.forInteger(wordKind, wordKind.getMinValue(), wordKind.getMaxValue()); runtime = createRuntime(); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Nov 26 18:58:28 2012 -0800 @@ -136,7 +136,7 @@ @Override public void run() { VMToCompilerImpl.this.intrinsifyArrayCopy = new IntrinsifyArrayCopyPhase(runtime); - SnippetInstaller installer = new SnippetInstaller(runtime, runtime.getGraalRuntime().getTarget(), HotSpotGraalRuntime.wordStamp()); + SnippetInstaller installer = new SnippetInstaller(runtime, runtime.getGraalRuntime().getTarget()); GraalIntrinsics.installIntrinsics(installer); runtime.installSnippets(installer); } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Nov 26 18:58:28 2012 -0800 @@ -213,10 +213,10 @@ installer.install(NewObjectSnippets.class); installer.install(MonitorSnippets.class); - checkcastSnippets = new CheckCastSnippets.Templates(this); - instanceofSnippets = new InstanceOfSnippets.Templates(this); + checkcastSnippets = new CheckCastSnippets.Templates(this, graalRuntime.getTarget()); + instanceofSnippets = new InstanceOfSnippets.Templates(this, graalRuntime.getTarget()); newObjectSnippets = new NewObjectSnippets.Templates(this, graalRuntime.getTarget(), config.useTLAB); - monitorSnippets = new MonitorSnippets.Templates(this, config.useFastLocking); + monitorSnippets = new MonitorSnippets.Templates(this, graalRuntime.getTarget(), config.useFastLocking); } @@ -405,8 +405,8 @@ // as HotSpot does not guarantee they are final values. assert vtableEntryOffset > 0; LoadHubNode hub = graph.add(new LoadHubNode(receiver, wordKind)); - ReadNode metaspaceMethod = graph.add(new ReadNode(hub, LocationNode.create(LocationNode.ANY_LOCATION, wordKind, vtableEntryOffset, graph), wordStamp())); - ReadNode compiledEntry = graph.add(new ReadNode(metaspaceMethod, LocationNode.create(LocationNode.ANY_LOCATION, wordKind, config.methodCompiledEntryOffset, graph), wordStamp())); + ReadNode metaspaceMethod = graph.add(new ReadNode(hub, LocationNode.create(LocationNode.ANY_LOCATION, wordKind, vtableEntryOffset, graph), StampFactory.forKind(wordKind()))); + ReadNode compiledEntry = graph.add(new ReadNode(metaspaceMethod, LocationNode.create(LocationNode.ANY_LOCATION, wordKind, config.methodCompiledEntryOffset, graph), StampFactory.forKind(wordKind()))); loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters, invoke.node().stamp(), signature, callTarget.targetMethod(), CallingConvention.Type.JavaCall)); @@ -499,7 +499,7 @@ } else { LoadHubNode arrayClass = graph.add(new LoadHubNode(array, wordKind)); LocationNode location = LocationNode.create(LocationNode.FINAL_LOCATION, wordKind, config.arrayClassElementOffset, graph); - FloatingReadNode arrayElementKlass = graph.unique(new FloatingReadNode(arrayClass, location, null, wordStamp())); + FloatingReadNode arrayElementKlass = graph.unique(new FloatingReadNode(arrayClass, location, null, StampFactory.forKind(wordKind()))); CheckCastDynamicNode checkcast = graph.add(new CheckCastDynamicNode(arrayElementKlass, value)); graph.addBeforeFixed(storeIndexed, checkcast); graph.addBeforeFixed(checkcast, arrayClass); @@ -548,7 +548,7 @@ LocationNode location = LocationNode.create(LocationNode.FINAL_LOCATION, wordKind, config.hubOffset, graph); ValueNode object = loadHub.object(); ValueNode guard = tool.createNullCheckGuard(object, StructuredGraph.INVALID_GRAPH_ID); - ReadNode hub = graph.add(new ReadNode(object, location, wordStamp())); + ReadNode hub = graph.add(new ReadNode(object, location, StampFactory.forKind(wordKind()))); hub.dependencies().add(guard); graph.replaceFixed(loadHub, hub); } else if (n instanceof CheckCastNode) { @@ -625,7 +625,7 @@ if (fullName.equals("getModifiers()I")) { StructuredGraph graph = new StructuredGraph(); LocalNode receiver = graph.unique(new LocalNode(0, StampFactory.objectNonNull())); - SafeReadNode klass = safeRead(graph, wordKind, receiver, config.klassOffset, wordStamp(), INVALID_GRAPH_ID); + SafeReadNode klass = safeRead(graph, wordKind, receiver, config.klassOffset, StampFactory.forKind(wordKind), INVALID_GRAPH_ID); graph.start().setNext(klass); LocationNode location = LocationNode.create(LocationNode.FINAL_LOCATION, Kind.Int, config.klassModifierFlagsOffset, graph); FloatingReadNode readModifiers = graph.unique(new FloatingReadNode(klass, location, null, StampFactory.intValue())); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/BeginLockScopeNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/BeginLockScopeNode.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/BeginLockScopeNode.java Mon Nov 26 18:58:28 2012 -0800 @@ -26,9 +26,9 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; /** @@ -43,7 +43,7 @@ private final boolean eliminated; public BeginLockScopeNode(boolean eliminated) { - super(HotSpotGraalRuntime.wordStamp()); + super(StampFactory.forWord()); this.eliminated = eliminated; } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentLockNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentLockNode.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentLockNode.java Mon Nov 26 18:58:28 2012 -0800 @@ -25,8 +25,8 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; /** @@ -35,7 +35,7 @@ public final class CurrentLockNode extends FixedWithNextNode implements LIRGenLowerable { public CurrentLockNode() { - super(HotSpotGraalRuntime.wordStamp()); + super(StampFactory.forWord()); } @Override diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/DimensionsNode.java Mon Nov 26 18:58:28 2012 -0800 @@ -26,12 +26,11 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; - /** * Intrinsic for allocating an on-stack array of integers to hold the dimensions * of a multianewarray instruction. @@ -41,7 +40,7 @@ private final int rank; public DimensionsNode(int rank) { - super(HotSpotGraalRuntime.wordStamp()); + super(StampFactory.forWord()); this.rank = rank; } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorCounterNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorCounterNode.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/MonitorCounterNode.java Mon Nov 26 18:58:28 2012 -0800 @@ -26,8 +26,8 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; /** @@ -37,7 +37,7 @@ public final class MonitorCounterNode extends FloatingNode implements LIRGenLowerable { public MonitorCounterNode() { - super(HotSpotGraalRuntime.wordStamp()); + super(StampFactory.forWord()); } @Override diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TLABAllocateNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TLABAllocateNode.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/TLABAllocateNode.java Mon Nov 26 18:58:28 2012 -0800 @@ -22,9 +22,9 @@ */ package com.oracle.graal.hotspot.nodes; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.*; /** @@ -36,7 +36,7 @@ @Input private ValueNode size; public TLABAllocateNode(ValueNode size) { - super(HotSpotGraalRuntime.wordStamp()); + super(StampFactory.forWord()); this.size = size; } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Nov 26 18:58:28 2012 -0800 @@ -21,7 +21,7 @@ * questions. */ package com.oracle.graal.hotspot.snippets; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; + import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*; import static com.oracle.graal.snippets.SnippetTemplate.*; import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*; @@ -36,6 +36,7 @@ import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; import com.oracle.graal.snippets.*; import com.oracle.graal.snippets.Snippet.ConstantParameter; @@ -235,8 +236,8 @@ private final ResolvedJavaMethod secondary; private final ResolvedJavaMethod dynamic; - public Templates(CodeCacheProvider runtime) { - super(runtime, CheckCastSnippets.class); + public Templates(CodeCacheProvider runtime, TargetDescription target) { + super(runtime, target, CheckCastSnippets.class); exact = snippet("checkcastExact", Object.class, Word.class, boolean.class); primary = snippet("checkcastPrimary", Word.class, Object.class, boolean.class, int.class); secondary = snippet("checkcastSecondary", Word.class, Object.class, Word[].class, boolean.class); @@ -267,7 +268,7 @@ arguments = arguments("hub", hub).add("object", object); } else { ConstantNode[] hints = createHints(hintInfo, runtime, graph); - key = new Key(secondary).add("hints", Varargs.vargargs(new Word[hints.length], wordStamp())).add("checkNull", checkNull); + key = new Key(secondary).add("hints", Varargs.vargargs(new Word[hints.length], StampFactory.forKind(wordKind()))).add("checkNull", checkNull); arguments = arguments("hub", hub).add("object", object).add("hints", hints); } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Nov 26 18:58:28 2012 -0800 @@ -21,7 +21,7 @@ * questions. */ package com.oracle.graal.hotspot.snippets; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; + import static com.oracle.graal.hotspot.snippets.CheckCastSnippets.*; import static com.oracle.graal.hotspot.snippets.CheckCastSnippets.Templates.*; import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*; @@ -33,6 +33,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; import com.oracle.graal.snippets.*; import com.oracle.graal.snippets.Snippet.ConstantParameter; @@ -164,8 +165,8 @@ private final ResolvedJavaMethod instanceofPrimary; private final ResolvedJavaMethod instanceofSecondary; - public Templates(CodeCacheProvider runtime) { - super(runtime, InstanceOfSnippets.class); + public Templates(CodeCacheProvider runtime, TargetDescription target) { + super(runtime, target, InstanceOfSnippets.class); instanceofExact = snippet("instanceofExact", Object.class, Word.class, Object.class, Object.class, boolean.class); instanceofPrimary = snippet("instanceofPrimary", Word.class, Object.class, Object.class, Object.class, boolean.class, int.class); instanceofSecondary = snippet("instanceofSecondary", Word.class, Object.class, Object.class, Object.class, Word[].class, boolean.class); @@ -193,7 +194,7 @@ arguments = arguments("hub", hub).add("object", object).add("trueValue", trueValue).add("falseValue", falseValue); } else { ConstantNode[] hints = createHints(hintInfo, runtime, hub.graph()); - key = new Key(instanceofSecondary).add("hints", Varargs.vargargs(new Word[hints.length], wordStamp())).add("checkNull", checkNull); + key = new Key(instanceofSecondary).add("hints", Varargs.vargargs(new Word[hints.length], StampFactory.forKind(wordKind()))).add("checkNull", checkNull); arguments = arguments("hub", hub).add("object", object).add("hints", hints).add("trueValue", trueValue).add("falseValue", falseValue); } return new KeyAndArguments(key, arguments); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Nov 26 18:58:28 2012 -0800 @@ -399,8 +399,8 @@ private final ResolvedJavaMethod checkCounter; private final boolean useFastLocking; - public Templates(CodeCacheProvider runtime, boolean useFastLocking) { - super(runtime, MonitorSnippets.class); + public Templates(CodeCacheProvider runtime, TargetDescription target, boolean useFastLocking) { + super(runtime, target, MonitorSnippets.class); monitorenter = snippet("monitorenter", Object.class, boolean.class, boolean.class); monitorexit = snippet("monitorexit", Object.class, boolean.class); monitorenterStub = snippet("monitorenterStub", Object.class, boolean.class, boolean.class); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Nov 26 18:58:28 2012 -0800 @@ -243,7 +243,7 @@ private final boolean useTLAB; public Templates(CodeCacheProvider runtime, TargetDescription target, boolean useTLAB) { - super(runtime, NewObjectSnippets.class); + super(runtime, target, NewObjectSnippets.class); this.target = target; this.useTLAB = useTLAB; allocate = snippet("allocate", int.class); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Mon Nov 26 18:58:28 2012 -0800 @@ -22,6 +22,7 @@ */ package com.oracle.graal.nodes.type; +import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.type.GenericStamp.GenericStampType; @@ -38,6 +39,7 @@ private static final Stamp conditionStamp = new GenericStamp(GenericStampType.Condition); private static final Stamp voidStamp = new GenericStamp(GenericStampType.Void); private static final Stamp nodeIntrinsicStamp = new ObjectStamp(null, false, false, false); + private static final Stamp wordStamp = new ObjectStamp(null, false, false, false); private static final Stamp positiveInt = forInteger(Kind.Int, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); private static void setCache(Kind kind, Stamp stamp) { @@ -78,6 +80,14 @@ return nodeIntrinsicStamp; } + /** + * A stamp used only in the graph of intrinsics, e.g., snippets. It is then replaced by the actual primitive type + * stamp for the target-specific {@link TargetDescription#wordKind}. + */ + public static Stamp forWord() { + return wordStamp; + } + public static Stamp intValue() { return forKind(Kind.Int); } diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/WordTest.java --- a/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/WordTest.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/WordTest.java Mon Nov 26 18:58:28 2012 -0800 @@ -32,7 +32,6 @@ import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.type.*; import com.oracle.graal.snippets.Snippet.InliningPolicy; /** @@ -44,9 +43,7 @@ public WordTest() { TargetDescription target = Graal.getRequiredCapability(GraalCompiler.class).target; - Kind wordKind = target.wordKind; - Stamp wordStamp = StampFactory.forInteger(wordKind, wordKind.getMinValue(), wordKind.getMaxValue()); - installer = new SnippetInstaller(runtime, target, wordStamp); + installer = new SnippetInstaller(runtime, target); } private static final ThreadLocal inliningPolicy = new ThreadLocal<>(); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java Mon Nov 26 18:58:28 2012 -0800 @@ -26,6 +26,7 @@ import java.util.*; +import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; @@ -54,8 +55,8 @@ */ public abstract class InstanceOfSnippetsTemplates extends AbstractTemplates { - public InstanceOfSnippetsTemplates(MetaAccessProvider runtime, Class snippetsClass) { - super(runtime, snippetsClass); + public InstanceOfSnippetsTemplates(MetaAccessProvider runtime, TargetDescription target, Class snippetsClass) { + super(runtime, target, snippetsClass); } /** diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java Mon Nov 26 18:58:28 2012 -0800 @@ -35,7 +35,6 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; import com.oracle.graal.snippets.Snippet.InliningPolicy; @@ -47,7 +46,6 @@ private final MetaAccessProvider runtime; private final TargetDescription target; - private final Stamp wordStamp; private final BoxingMethodPool pool; /** @@ -58,10 +56,9 @@ */ private final Map graphCache; - public SnippetInstaller(MetaAccessProvider runtime, TargetDescription target, Stamp wordStamp) { + public SnippetInstaller(MetaAccessProvider runtime, TargetDescription target) { this.runtime = runtime; this.target = target; - this.wordStamp = wordStamp; this.pool = new BoxingMethodPool(runtime); this.graphCache = new HashMap<>(); } @@ -182,7 +179,7 @@ InliningUtil.inline(invoke, targetGraph, true); Debug.dump(graph, "after inlining %s", callee); if (GraalOptions.OptCanonicalizer) { - new WordTypeRewriterPhase(target.wordKind, wordStamp).apply(graph); + new WordTypeRewriterPhase(target.wordKind).apply(graph); new CanonicalizerPhase(target, runtime, null).apply(graph); } } @@ -190,7 +187,7 @@ new SnippetIntrinsificationPhase(runtime, pool, true).apply(graph); - new WordTypeRewriterPhase(target.wordKind, wordStamp).apply(graph); + new WordTypeRewriterPhase(target.wordKind).apply(graph); new DeadCodeEliminationPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Mon Nov 26 18:58:28 2012 -0800 @@ -27,6 +27,7 @@ import java.util.Map.Entry; import java.util.concurrent.*; +import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; @@ -153,10 +154,12 @@ private final ConcurrentHashMap templates = new ConcurrentHashMap<>(); private final MetaAccessProvider runtime; + private final TargetDescription target; - public Cache(MetaAccessProvider runtime) { + public Cache(MetaAccessProvider runtime, TargetDescription target) { this.runtime = runtime; + this.target = target; } /** @@ -168,7 +171,7 @@ template = Debug.scope("SnippetSpecialization", key.method, new Callable() { @Override public SnippetTemplate call() throws Exception { - return new SnippetTemplate(runtime, key); + return new SnippetTemplate(runtime, target, key); } }); //System.out.println(key + " -> " + template); @@ -182,10 +185,10 @@ protected final Cache cache; protected final MetaAccessProvider runtime; protected Class snippetsClass; - public AbstractTemplates(MetaAccessProvider runtime, Class snippetsClass) { + public AbstractTemplates(MetaAccessProvider runtime, TargetDescription target, Class snippetsClass) { this.runtime = runtime; this.snippetsClass = snippetsClass; - this.cache = new Cache(runtime); + this.cache = new Cache(runtime, target); } protected ResolvedJavaMethod snippet(String name, Class... parameterTypes) { @@ -214,7 +217,7 @@ /** * Creates a snippet template. */ - public SnippetTemplate(MetaAccessProvider runtime, SnippetTemplate.Key key) { + public SnippetTemplate(MetaAccessProvider runtime, TargetDescription target, SnippetTemplate.Key key) { ResolvedJavaMethod method = key.method; assert Modifier.isStatic(method.getModifiers()) : "snippet method must be static: " + method; Signature signature = method.getSignature(); @@ -259,6 +262,7 @@ if (!replacements.isEmpty()) { // Do deferred intrinsification of node intrinsics new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy); + new WordTypeRewriterPhase(target.wordKind).apply(snippetCopy); new CanonicalizerPhase(null, runtime, null, 0, null).apply(snippetCopy); } @@ -327,7 +331,7 @@ // Remove all frame states from inlined snippet graph. Snippets must be atomic (i.e. free // of side-effects that prevent deoptimizing to a point before the snippet). - Node curSideEffectNode = null; + List curSideEffectNodes = new ArrayList<>(); Node curStampNode = null; for (Node node : snippetCopy.getNodes()) { if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) { @@ -338,8 +342,7 @@ StateSplit stateSplit = (StateSplit) node; FrameState frameState = stateSplit.stateAfter(); if (stateSplit.hasSideEffect()) { - assert curSideEffectNode == null : "Currently limited to one side-effecting node (but this can be converted to a List if necessary)"; - curSideEffectNode = node; + curSideEffectNodes.add(node); } if (frameState != null) { stateSplit.setStateAfter(null); @@ -369,7 +372,7 @@ } } - this.sideEffectNode = curSideEffectNode; + this.sideEffectNodes = curSideEffectNodes; this.stampNode = curStampNode; this.returnNode = retNode; } @@ -420,9 +423,9 @@ private final ReturnNode returnNode; /** - * Node that inherits the {@link StateSplit#stateAfter()} from the replacee during instantiation. + * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during instantiation. */ - private final Node sideEffectNode; + private final List sideEffectNodes; /** * Node that inherits the {@link ValueNode#stamp()} from the replacee during instantiation. @@ -535,10 +538,12 @@ FixedNode next = replacee.next(); replacee.setNext(null); - if (sideEffectNode != null) { - assert ((StateSplit) replacee).hasSideEffect(); - Node sideEffectDup = duplicates.get(sideEffectNode); - ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); + if (replacee instanceof StateSplit) { + for (Node sideEffectNode : sideEffectNodes) { + assert ((StateSplit) replacee).hasSideEffect(); + Node sideEffectDup = duplicates.get(sideEffectNode); + ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); + } } if (stampNode != null) { Node stampDup = duplicates.get(stampNode); @@ -602,10 +607,12 @@ FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); replaceeGraph.addAfterFixed(lastFixedNode, firstCFGNodeDuplicate); - if (sideEffectNode != null) { - assert ((StateSplit) replacee).hasSideEffect(); - Node sideEffectDup = duplicates.get(sideEffectNode); - ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); + if (replacee instanceof StateSplit) { + for (Node sideEffectNode : sideEffectNodes) { + assert ((StateSplit) replacee).hasSideEffect(); + Node sideEffectDup = duplicates.get(sideEffectNode); + ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter()); + } } if (stampNode != null) { Node stampDup = duplicates.get(stampNode); diff -r d9930fec7553 -r 89df4e71940a graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java Mon Nov 26 18:25:44 2012 -0800 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/WordTypeRewriterPhase.java Mon Nov 26 18:58:28 2012 -0800 @@ -46,11 +46,9 @@ private static final String WordClassName = MetaUtil.toInternalName(Word.class.getName()); private final Kind wordKind; - private final Stamp wordStamp; - public WordTypeRewriterPhase(Kind wordKind, Stamp wordStamp) { + public WordTypeRewriterPhase(Kind wordKind) { this.wordKind = wordKind; - this.wordStamp = wordStamp; } @Override @@ -85,7 +83,7 @@ // Replace ObjectEqualsNodes with IntegerEqualsNodes where the values being compared are words for (LoadIndexedNode load : graph.getNodes().filter(LoadIndexedNode.class).snapshot()) { if (isWord(load)) { - load.setStamp(wordStamp); + load.setStamp(StampFactory.forKind(wordKind)); } } @@ -192,7 +190,7 @@ assert arguments.size() == 1; ValueNode value = arguments.first(); assert value.kind() == Kind.Object : value + ", " + targetMethod; - UnsafeCastNode cast = graph.unique(new UnsafeCastNode(value, wordStamp)); + UnsafeCastNode cast = graph.unique(new UnsafeCastNode(value, StampFactory.forKind(wordKind))); replace(invoke, cast); break; } @@ -292,6 +290,9 @@ } public static boolean isWord(ValueNode node) { + if (node.stamp() == StampFactory.forWord()) { + return true; + } if (node instanceof LoadIndexedNode) { return isWord(((LoadIndexedNode) node).array().objectStamp().type().getComponentType()); } @@ -310,7 +311,7 @@ private void changeToWord(ValueNode valueNode) { assert !(valueNode instanceof ConstantNode); - valueNode.setStamp(wordStamp); + valueNode.setStamp(StampFactory.forKind(wordKind)); // Propagate word kind. for (Node n : valueNode.usages()) {