# HG changeset patch # User Josef Eisl # Date 1403720135 -7200 # Node ID aabd00bc60283b721263a03af5cd8ad1cc330f28 # Parent 14e56cef5be8d2ca7c11e32acf4c8ce2b752208f Move ValuePosition into LIRIntrospection. diff -r 14e56cef5be8 -r aabd00bc6028 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Wed Jun 25 19:23:30 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Wed Jun 25 20:15:35 2014 +0200 @@ -30,7 +30,7 @@ import com.oracle.graal.lir.LIRInstruction.OperandFlag; import com.oracle.graal.lir.LIRInstruction.OperandMode; import com.oracle.graal.lir.LIRInstruction.ValuePositionProcedure; -import com.oracle.graal.lir.LIRInstructionClass.ValuePosition; +import com.oracle.graal.lir.LIRIntrospection.ValuePosition; /** * Base class to represent values that need to be stored in more than one register. diff -r 14e56cef5be8 -r aabd00bc6028 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java Wed Jun 25 19:23:30 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValueClass.java Wed Jun 25 20:15:35 2014 +0200 @@ -32,7 +32,6 @@ import com.oracle.graal.lir.LIRInstruction.OperandFlag; import com.oracle.graal.lir.LIRInstruction.OperandMode; import com.oracle.graal.lir.LIRInstruction.ValuePositionProcedure; -import com.oracle.graal.lir.LIRInstructionClass.ValuePosition; /** * Lazily associated metadata for every {@link CompositeValue} type. The metadata includes: @@ -162,7 +161,15 @@ return result.toString(); } - Value get(CompositeValue obj, ValuePosition pos) { + Value getValue(CompositeValue obj, ValuePosition pos) { return getValueForPosition(obj, componentOffsets, directComponentCount, pos); } + + void setValue(CompositeValue obj, ValuePosition pos, Value value) { + setValueForPosition(obj, componentOffsets, directComponentCount, pos, value); + } + + EnumSet getFlags(ValuePosition pos) { + return componentFlags[pos.getIndex()]; + } } diff -r 14e56cef5be8 -r aabd00bc6028 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Wed Jun 25 19:23:30 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstruction.java Wed Jun 25 20:15:35 2014 +0200 @@ -32,7 +32,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; -import com.oracle.graal.lir.LIRInstructionClass.ValuePosition; +import com.oracle.graal.lir.LIRIntrospection.ValuePosition; import com.oracle.graal.lir.asm.*; /** diff -r 14e56cef5be8 -r aabd00bc6028 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java Wed Jun 25 19:23:30 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRInstructionClass.java Wed Jun 25 20:15:35 2014 +0200 @@ -242,117 +242,7 @@ return str.toString(); } - /** - * Describes an operand slot for a {@link LIRInstructionClass}. - * - * @see LIRInstructionClass#get(LIRInstruction, ValuePosition) - */ - public static final class ValuePosition { - - private final OperandMode mode; - private final int index; - private final int subIndex; - private final ValuePosition superPosition; - - public static final int NO_SUBINDEX = -1; - public static final ValuePosition ROOT_VALUE_POSITION = null; - - public ValuePosition(OperandMode mode, int index, int subIndex, ValuePosition superPosition) { - this.mode = mode; - this.index = index; - this.subIndex = subIndex; - this.superPosition = superPosition; - } - - public Value get(LIRInstruction inst) { - return inst.getLIRInstructionClass().get(inst, this); - } - - /** - * @deprecated Not yet sure this is safe for {@link CompositeValue}s. - */ - @Deprecated - public EnumSet getFlags(LIRInstruction inst) { - return inst.getLIRInstructionClass().getFlags(this); - } - - /** - * @deprecated Not yet sure this is safe for {@link CompositeValue}s. - */ - @Deprecated - public void set(LIRInstruction inst, Value value) { - inst.getLIRInstructionClass().set(inst, this, value); - } - - public int getSubIndex() { - return subIndex; - } - - public int getIndex() { - return index; - } - - public OperandMode getMode() { - return mode; - } - - public ValuePosition getSuperPosition() { - return superPosition; - } - - @Override - public String toString() { - if (superPosition == ROOT_VALUE_POSITION) { - return mode.toString() + index + "/" + subIndex; - } - return superPosition.toString() + "[" + mode.toString() + index + "/" + subIndex + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - result = prime * result + ((mode == null) ? 0 : mode.hashCode()); - result = prime * result + subIndex; - result = prime * result + ((superPosition == null) ? 0 : superPosition.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ValuePosition other = (ValuePosition) obj; - if (index != other.index) { - return false; - } - if (mode != other.mode) { - return false; - } - if (subIndex != other.subIndex) { - return false; - } - if (superPosition == null) { - if (other.superPosition != null) { - return false; - } - } else if (!superPosition.equals(other.superPosition)) { - return false; - } - return true; - } - - } - - private Value getValueFromLIRInstruction(LIRInstruction obj, ValuePosition pos) { + Value getValue(LIRInstruction obj, ValuePosition pos) { long[] offsets; int directCount; switch (pos.getMode()) { @@ -378,26 +268,7 @@ return getValueForPosition(obj, offsets, directCount, pos); } - private Value getRecursive(LIRInstruction obj, ValuePosition pos) { - ValuePosition superPosition = pos.getSuperPosition(); - if (superPosition == ValuePosition.ROOT_VALUE_POSITION) { - // At this point we are at the top of the ValuePosition tree - return getValueFromLIRInstruction(obj, pos); - } - // Get the containing value - Value superValue = getRecursive(obj, superPosition); - assert superValue instanceof CompositeValue : "only CompositeValue can contain nested values " + superValue; - CompositeValue compValue = (CompositeValue) superValue; - return compValue.getValueClass().get(compValue, pos); - } - - private Value get(LIRInstruction obj, ValuePosition pos) { - Value value = getRecursive(obj, pos); - assert !(value instanceof CompositeValue) : "should never return a CompositeValue"; - return value; - } - - private void set(LIRInstruction obj, ValuePosition pos, Value value) { + void setValue(LIRInstruction obj, ValuePosition pos, Value value) { long[] offsets; int directCount; switch (pos.getMode()) { @@ -420,13 +291,10 @@ default: throw GraalInternalError.shouldNotReachHere("unkown OperandMode: " + pos.getMode()); } - if (pos.index < directCount) { - setValue(obj, offsets[pos.getIndex()], value); - } - getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()] = value; + setValueForPosition(obj, offsets, directCount, pos, value); } - private EnumSet getFlags(ValuePosition pos) { + EnumSet getFlags(ValuePosition pos) { switch (pos.getMode()) { case USE: return useFlags[pos.getIndex()]; diff -r 14e56cef5be8 -r aabd00bc6028 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java Wed Jun 25 19:23:30 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRIntrospection.java Wed Jun 25 20:15:35 2014 +0200 @@ -23,7 +23,6 @@ package com.oracle.graal.lir; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.lir.LIRInstructionClass.ValuePosition.*; import java.lang.annotation.*; import java.lang.reflect.*; @@ -37,7 +36,6 @@ import com.oracle.graal.lir.LIRInstruction.OperandFlag; import com.oracle.graal.lir.LIRInstruction.OperandMode; import com.oracle.graal.lir.LIRInstruction.ValuePositionProcedure; -import com.oracle.graal.lir.LIRInstructionClass.ValuePosition; abstract class LIRIntrospection extends FieldIntrospection { @@ -156,7 +154,7 @@ if (i < directCount) { Value value = getValue(obj, offsets[i]); - doForValue(inst, mode, proc, superPosition, i, NO_SUBINDEX, value); + doForValue(inst, mode, proc, superPosition, i, ValuePosition.NO_SUBINDEX, value); } else { Value[] values = getValueArray(obj, offsets[i]); for (int j = 0; j < values.length; j++) { @@ -177,6 +175,144 @@ } } + /** + * Describes an operand slot for a {@link LIRInstructionClass}. + */ + public static final class ValuePosition { + + private final OperandMode mode; + private final int index; + private final int subIndex; + private final ValuePosition superPosition; + + public static final int NO_SUBINDEX = -1; + public static final ValuePosition ROOT_VALUE_POSITION = null; + + public ValuePosition(OperandMode mode, int index, int subIndex, ValuePosition superPosition) { + this.mode = mode; + this.index = index; + this.subIndex = subIndex; + this.superPosition = superPosition; + } + + public Value get(LIRInstruction inst) { + return LIRIntrospection.get(inst, this); + } + + public EnumSet getFlags(LIRInstruction inst) { + return LIRIntrospection.getFlags(inst, this); + } + + public void set(LIRInstruction inst, Value value) { + LIRIntrospection.set(inst, this, value); + } + + public int getSubIndex() { + return subIndex; + } + + public int getIndex() { + return index; + } + + public OperandMode getMode() { + return mode; + } + + public ValuePosition getSuperPosition() { + return superPosition; + } + + @Override + public String toString() { + if (superPosition == ROOT_VALUE_POSITION) { + return mode.toString() + index + "/" + subIndex; + } + return superPosition.toString() + "[" + mode.toString() + index + "/" + subIndex + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + index; + result = prime * result + ((mode == null) ? 0 : mode.hashCode()); + result = prime * result + subIndex; + result = prime * result + ((superPosition == null) ? 0 : superPosition.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ValuePosition other = (ValuePosition) obj; + if (index != other.index) { + return false; + } + if (mode != other.mode) { + return false; + } + if (subIndex != other.subIndex) { + return false; + } + if (superPosition == null) { + if (other.superPosition != null) { + return false; + } + } else if (!superPosition.equals(other.superPosition)) { + return false; + } + return true; + } + + } + + private static CompositeValue getCompositeValue(LIRInstruction inst, ValuePosition pos) { + ValuePosition superPosition = pos.getSuperPosition(); + Value value; + if (superPosition == ValuePosition.ROOT_VALUE_POSITION) { + // At this point we are at the top of the ValuePosition tree + value = inst.getLIRInstructionClass().getValue(inst, pos); + } else { + // Get the containing value + value = getCompositeValue(inst, superPosition); + } + assert value instanceof CompositeValue : "only CompositeValue can contain nested values " + value; + return (CompositeValue) value; + } + + private static Value get(LIRInstruction inst, ValuePosition pos) { + if (pos.getSuperPosition() == ValuePosition.ROOT_VALUE_POSITION) { + return inst.getLIRInstructionClass().getValue(inst, pos); + } + CompositeValue compValue = getCompositeValue(inst, pos); + return compValue.getValueClass().getValue(compValue, pos); + } + + private static void set(LIRInstruction inst, ValuePosition pos, Value value) { + if (pos.getSuperPosition() == ValuePosition.ROOT_VALUE_POSITION) { + inst.getLIRInstructionClass().setValue(inst, pos, value); + } + CompositeValue compValue = getCompositeValue(inst, pos); + compValue.getValueClass().setValue(compValue, pos, value); + } + + private static EnumSet getFlags(LIRInstruction inst, ValuePosition pos) { + if (pos.getSuperPosition() == ValuePosition.ROOT_VALUE_POSITION) { + return inst.getLIRInstructionClass().getFlags(pos); + } + CompositeValue compValue = getCompositeValue(inst, pos); + return compValue.getValueClass().getFlags(pos); + } + protected static Value getValueForPosition(Object obj, long[] offsets, int directCount, ValuePosition pos) { if (pos.getIndex() < directCount) { return getValue(obj, offsets[pos.getIndex()]); @@ -184,6 +320,13 @@ return getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()]; } + protected static void setValueForPosition(Object obj, long[] offsets, int directCount, ValuePosition pos, Value value) { + if (pos.getIndex() < directCount) { + setValue(obj, offsets[pos.getIndex()], value); + } + getValueArray(obj, offsets[pos.getIndex()])[pos.getSubIndex()] = value; + } + protected static Value getValue(Object obj, long offset) { return (Value) unsafe.getObject(obj, offset); }