# HG changeset patch # User Christos Kotselidis # Date 1374492923 -7200 # Node ID 02a5f5abd8425fe68d6b99f1db79e438fa530af5 # Parent 981c8a4d711a96622a4c75699b88345d8c4724b7# Parent 04f817fb0456d11a0443cc645ddd5b5df9c33793 Merge diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Mon Jul 22 13:35:23 2013 +0200 @@ -137,7 +137,9 @@ } /** - * Represents a reference to data from the code. The associated data can be any constant. + * Represents a reference to data from the code. The associated data can be either a + * {@link Constant} or a raw byte array. The raw byte array is patched as is, no endian swapping + * is done on it. */ public static final class DataPatch extends Site { @@ -161,6 +163,8 @@ private DataPatch(int pcOffset, Constant data, byte[] rawData, int alignment, boolean inlined) { super(pcOffset); + assert (data == null) != (rawData == null) : "only one of data and rawData is allowed"; + assert !inlined || rawData == null : "rawData can not be inlined"; this.constant = data; this.rawConstant = rawData; this.alignment = alignment; diff -r 981c8a4d711a -r 02a5f5abd842 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 Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Jul 22 13:35:23 2013 +0200 @@ -66,6 +66,7 @@ import com.oracle.graal.api.code.CompilationResult.Infopoint; import com.oracle.graal.api.code.CompilationResult.Mark; import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.*; import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect; @@ -934,6 +935,44 @@ return IndexedLocationNode.create(NamedLocationIdentity.getArrayLocation(elementKind), elementKind, getArrayBaseOffset(elementKind), index, graph, scale); } + @Override + public ValueNode reconstructArrayIndex(LocationNode location) { + Kind elementKind = location.getValueKind(); + assert location.getLocationIdentity().equals(NamedLocationIdentity.getArrayLocation(elementKind)); + + long base; + ValueNode index; + int scale = getScalingFactor(elementKind); + + if (location instanceof ConstantLocationNode) { + base = ((ConstantLocationNode) location).getDisplacement(); + index = null; + } else if (location instanceof IndexedLocationNode) { + IndexedLocationNode indexedLocation = (IndexedLocationNode) location; + assert indexedLocation.getIndexScaling() == scale; + base = indexedLocation.getDisplacement(); + index = indexedLocation.getIndex(); + } else { + throw GraalInternalError.shouldNotReachHere(); + } + + base -= getArrayBaseOffset(elementKind); + assert base >= 0 && base % scale == 0; + + base /= scale; + assert NumUtil.isInt(base); + + if (index == null) { + return ConstantNode.forInt((int) base, location.graph()); + } else { + if (base == 0) { + return index; + } else { + return IntegerArithmeticNode.add(ConstantNode.forInt((int) base, location.graph()), index); + } + } + } + private static GuardingNode createBoundsCheck(AccessIndexedNode n, LoweringTool tool) { StructuredGraph graph = n.graph(); ArrayLengthNode arrayLength = graph.add(new ArrayLengthNode(n.array())); diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierAdditionPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierAdditionPhase.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierAdditionPhase.java Mon Jul 22 13:35:23 2013 +0200 @@ -56,9 +56,7 @@ private static void addReadNodeBarriers(ReadNode node, StructuredGraph graph) { if (node.getBarrierType() == BarrierType.PRECISE) { assert useG1GC(); - G1ReferentFieldReadBarrier barrier = graph.add(new G1ReferentFieldReadBarrier(node.object(), node, node.location(), false, node.getNullCheck())); - barrier.setDeoptimizationState(node.getDeoptimizationState()); - node.setNullCheck(false); + G1ReferentFieldReadBarrier barrier = graph.add(new G1ReferentFieldReadBarrier(node.object(), node, node.location(), false, false)); graph.addAfterFixed(node, barrier); } else { assert node.getBarrierType() == BarrierType.NONE : "Non precise read barrier has been attached to read node."; @@ -69,7 +67,7 @@ BarrierType barrierType = node.getBarrierType(); if (barrierType == BarrierType.PRECISE) { if (useG1GC()) { - if (node.isInitialized()) { + if (!node.isInitialization()) { G1PreWriteBarrier preBarrier = graph.add(new G1PreWriteBarrier(node.object(), null, node.location(), true, node.getNullCheck())); preBarrier.setDeoptimizationState(node.getDeoptimizationState()); node.setNullCheck(false); @@ -118,7 +116,7 @@ private static void addArrayRangeBarriers(ArrayRangeWriteNode node, StructuredGraph graph) { if (useG1GC()) { - if (node.isInitialized()) { + if (!node.isInitialization()) { G1ArrayRangePreWriteBarrier g1ArrayRangePreWriteBarrier = graph.add(new G1ArrayRangePreWriteBarrier(node.getArray(), node.getIndex(), node.getLength())); graph.addBeforeFixed(node, g1ArrayRangePreWriteBarrier); } diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopyNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopyNode.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopyNode.java Mon Jul 22 13:35:23 2013 +0200 @@ -83,8 +83,8 @@ } @Override - public boolean isInitialized() { - return true; + public boolean isInitialization() { + return false; } public Kind getElementKind() { diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ArrayRangeWriteNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ArrayRangeWriteNode.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ArrayRangeWriteNode.java Mon Jul 22 13:35:23 2013 +0200 @@ -56,8 +56,9 @@ public abstract boolean isObjectArray(); /** - * If {@link #isInitialized()} is true, the memory location contains a valid value. If - * {@link #isInitialized()} is false, the memory location is uninitialized or zero. + * Returns whether this write is the initialization of the written location. If it is true, the + * old value of the memory location is either uninitialized or zero. If it is false, the memory + * location is guaranteed to contain a valid value or zero. */ - public abstract boolean isInitialized(); + public abstract boolean isInitialization(); } diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java Mon Jul 22 13:35:23 2013 +0200 @@ -37,7 +37,7 @@ @Input private ValueNode value; @Input(notDataflow = true) private FrameState stateAfter; - private final boolean initialized; + private final boolean initialization; public FrameState stateAfter() { return stateAfter; @@ -58,21 +58,22 @@ } /** - * If {@link #isInitialized()} is true, the memory location contains a valid value. If - * {@link #isInitialized()} is false, the memory location is uninitialized or zero. + * Returns whether this write is the initialization of the written location. If it is true, the + * old value of the memory location is either uninitialized or zero. If it is false, the memory + * location is guaranteed to contain a valid value or zero. */ - public boolean isInitialized() { - return initialized; + public boolean isInitialization() { + return initialization; } public WriteNode(ValueNode object, ValueNode value, ValueNode location, BarrierType barrierType, boolean compressible) { - this(object, value, location, barrierType, compressible, true); + this(object, value, location, barrierType, compressible, false); } - public WriteNode(ValueNode object, ValueNode value, ValueNode location, BarrierType barrierType, boolean compressible, boolean initialized) { + public WriteNode(ValueNode object, ValueNode value, ValueNode location, BarrierType barrierType, boolean compressible, boolean initialization) { super(object, location, StampFactory.forVoid(), barrierType, compressible); this.value = value; - this.initialized = initialized; + this.initialization = initialization; } @Override diff -r 981c8a4d711a -r 02a5f5abd842 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/GraalCodeCacheProvider.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/GraalCodeCacheProvider.java Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/GraalCodeCacheProvider.java Mon Jul 22 13:35:23 2013 +0200 @@ -25,6 +25,8 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; /** * Graal-specific extensions for the code cache provider interface. @@ -44,4 +46,13 @@ InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, Graph graph); void lower(Node n, LoweringTool tool); + + /** + * Reconstruct the array index from a location node that was created as a lowering of an indexed + * access to an array. + * + * @param location a location pointing to an element in an array + * @return a node that gives the index of the element + */ + ValueNode reconstructArrayIndex(LocationNode location); } diff -r 981c8a4d711a -r 02a5f5abd842 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 Mon Jul 22 13:34:53 2013 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Mon Jul 22 13:35:23 2013 +0200 @@ -343,7 +343,7 @@ private static ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode value, Invoke invoke, LocationNode location, Opcode op) { assert op == Opcode.WRITE || op == Opcode.INITIALIZE; - WriteNode write = graph.add(new WriteNode(base, value, location, BarrierType.NONE, false, op == Opcode.WRITE)); + WriteNode write = graph.add(new WriteNode(base, value, location, BarrierType.NONE, false, op == Opcode.INITIALIZE)); write.setStateAfter(invoke.stateAfter()); graph.addBeforeFixed(invoke.asNode(), write); return write;