# HG changeset patch # User Doug Simon # Date 1374248855 -7200 # Node ID 2c9332a969d6eae27738edd897dce3ccbefd1fc5 # Parent a61fa3e171e724a1c6935c852b15d62a2b2edb83 made it possible to use enum constants in snippets diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeLoadSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeLoadSnippets.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeLoadSnippets.java Fri Jul 19 17:47:35 2013 +0200 @@ -26,6 +26,7 @@ import static com.oracle.graal.replacements.SnippetTemplate.*; import com.oracle.graal.api.code.*; +import com.oracle.graal.nodes.HeapAccess.WriteBarrierType; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.replacements.*; @@ -40,9 +41,9 @@ public static Object lowerUnsafeLoad(Object object, long offset, int disp) { long displacement = disp + offset; if (object instanceof java.lang.ref.Reference && referentOffset() == displacement) { - return Word.fromObject(object).readObject((int) displacement, 1, true); + return Word.fromObject(object).readObject((int) displacement, WriteBarrierType.PRECISE, true); } else { - return Word.fromObject(object).readObject((int) displacement, 0, true); + return Word.fromObject(object).readObject((int) displacement, WriteBarrierType.NONE, true); } } diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Fri Jul 19 17:47:35 2013 +0200 @@ -33,6 +33,7 @@ import com.oracle.graal.graph.Node.NodeIntrinsic; import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.HeapAccess.WriteBarrierType; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; @@ -118,7 +119,7 @@ // If the previous value has to be loaded (before the write), the load is issued. // The load is always issued except the cases of CAS and referent field. if (probability(LIKELY_PROBABILITY, doLoad)) { - previousOop = (Word) Word.fromObject(field.readObject(0, 0, true)); + previousOop = (Word) Word.fromObject(field.readObject(0, WriteBarrierType.NONE, true)); if (trace) { log(trace, "[%d] G1-Pre Thread %p Previous Object %p\n ", gcCycle, thread.rawValue(), previousOop.rawValue()); verifyOop(previousOop.toObject()); @@ -225,7 +226,7 @@ for (int i = startIndex; i < length; i++) { Word address = (Word) Word.fromObject(dest).add(header).add(Word.unsigned(i * (long) scale)); - oop = (Word) Word.fromObject(address.readObject(0, 0, true)); + oop = (Word) Word.fromObject(address.readObject(0, WriteBarrierType.NONE, true)); if (oop.notEqual(0)) { if (indexValue.notEqual(0)) { Word nextIndex = indexValue.subtract(wordSize()); diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java Fri Jul 19 17:47:35 2013 +0200 @@ -57,7 +57,20 @@ @Override public ValueNode canonical(CanonicalizerTool tool) { MetaAccessProvider runtime = tool.runtime(); - if (tool.canonicalizeReads() && runtime != null) { + if (tool.canonicalizeReads()) { + ConstantNode constant = asConstant(runtime); + if (constant != null) { + return constant; + } + } + return this; + } + + /** + * Gets a constant value for this load if possible. + */ + public ConstantNode asConstant(MetaAccessProvider runtime) { + if (runtime != null) { Constant constant = null; if (isStatic()) { constant = field().readConstantValue(null); @@ -68,7 +81,7 @@ return ConstantNode.forConstant(constant, runtime, graph()); } } - return this; + return null; } @Override diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Pointer.java Fri Jul 19 17:47:35 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.word; import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.HeapAccess.WriteBarrierType; import com.oracle.graal.nodes.extended.*; public interface Pointer extends Unsigned { @@ -622,7 +623,7 @@ * @param compress whether or not the object is a decompression candidate * @return the result of the memory access */ - Object readObject(WordBase offset, int barrierType, boolean compress); + Object readObject(WordBase offset, WriteBarrierType barrierType, boolean compress); /** * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in @@ -714,7 +715,7 @@ * @param compress whether or not the object is a decompression candidate * @return the result of the memory access */ - Object readObject(int offset, int barrierType, boolean compress); + Object readObject(int offset, WriteBarrierType barrierType, boolean compress); /** * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Fri Jul 19 17:47:35 2013 +0200 @@ -30,6 +30,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.HeapAccess.WriteBarrierType; import com.oracle.graal.nodes.calc.*; public abstract class Word implements Signed, Unsigned, Pointer { @@ -881,7 +882,7 @@ public native Object readObject(WordBase offset); @Operation(opcode = Opcode.READ_HEAP) - public native Object readObject(WordBase offset, int barrierType, boolean compress); + public native Object readObject(WordBase offset, WriteBarrierType barrierType, boolean compress); @Override @Operation(opcode = Opcode.READ) @@ -938,7 +939,7 @@ } @Operation(opcode = Opcode.READ_HEAP) - public Object readObject(int offset, int barrierType, boolean compress) { + public Object readObject(int offset, WriteBarrierType barrierType, boolean compress) { return readObject(signed(offset), barrierType, compress); } diff -r a61fa3e171e7 -r 2c9332a969d6 graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Fri Jul 19 12:45:59 2013 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Fri Jul 19 17:47:35 2013 +0200 @@ -98,6 +98,14 @@ } } + // Fold constant field reads (e.g. enum constants) + for (LoadFieldNode load : graph.getNodes(LoadFieldNode.class).snapshot()) { + ConstantNode constant = load.asConstant(metaAccess); + if (constant != null) { + graph.replaceFixedWithFloating(load, constant); + } + } + // Replace ObjectEqualsNodes with IntegerEqualsNodes where the values being compared are // words for (ObjectEqualsNode objectEqualsNode : graph.getNodes().filter(ObjectEqualsNode.class).snapshot()) { @@ -175,14 +183,15 @@ } else { location = makeLocation(graph, arguments.get(1), readKind, arguments.get(2)); } - replace(invoke, readOp(graph, arguments.get(0), invoke, location, 0, false)); + replace(invoke, readOp(graph, arguments.get(0), invoke, location, WriteBarrierType.NONE, false)); break; } case READ_HEAP: { assert arguments.size() == 4; Kind readKind = asKind(callTargetNode.returnType()); LocationNode location = makeLocation(graph, arguments.get(1), readKind, ANY_LOCATION); - replace(invoke, readOp(graph, arguments.get(0), invoke, location, arguments.get(2).asConstant().asInt(), arguments.get(3).asConstant().asInt() == 0 ? false : true)); + WriteBarrierType barrierType = (WriteBarrierType) arguments.get(2).asConstant().asObject(); + replace(invoke, readOp(graph, arguments.get(0), invoke, location, barrierType, arguments.get(3).asConstant().asInt() == 0 ? false : true)); break; } case WRITE: @@ -323,8 +332,8 @@ return IndexedLocationNode.create(locationIdentity, readKind, 0, offset, graph, 1); } - private static ValueNode readOp(StructuredGraph graph, ValueNode base, Invoke invoke, LocationNode location, int barrierType, boolean compress) { - ReadNode read = graph.add(new ReadNode(base, location, invoke.asNode().stamp(), WriteBarrierType.values()[barrierType], compress)); + private static ValueNode readOp(StructuredGraph graph, ValueNode base, Invoke invoke, LocationNode location, WriteBarrierType barrierType, boolean compress) { + ReadNode read = graph.add(new ReadNode(base, location, invoke.asNode().stamp(), barrierType, compress)); graph.addBeforeFixed(invoke.asNode(), read); // The read must not float outside its block otherwise it may float above an explicit zero // check on its base address