# HG changeset patch # User Christian Wimmer # Date 1354239789 28800 # Node ID f1f32b695d1ef1987afa54351a2fc4c8999ece61 # Parent 5c25483b5515b1f5a64c9f4ca07cc9ab24bcae42 Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields. diff -r 5c25483b5515 -r f1f32b695d1e graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java Thu Nov 29 16:53:44 2012 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java Thu Nov 29 17:43:09 2012 -0800 @@ -34,27 +34,27 @@ private static final Constant[] INT_CONSTANT_CACHE = new Constant[100]; static { for (int i = 0; i < INT_CONSTANT_CACHE.length; ++i) { - INT_CONSTANT_CACHE[i] = new Constant(Kind.Int, i); + INT_CONSTANT_CACHE[i] = new Constant(Kind.Int, null, i); } } - public static final Constant NULL_OBJECT = new Constant(null); - public static final Constant INT_MINUS_1 = new Constant(Kind.Int, -1); + public static final Constant NULL_OBJECT = new Constant(Kind.Object, null, 0); + public static final Constant INT_MINUS_1 = new Constant(Kind.Int, null, -1); public static final Constant INT_0 = forInt(0); public static final Constant INT_1 = forInt(1); public static final Constant INT_2 = forInt(2); public static final Constant INT_3 = forInt(3); public static final Constant INT_4 = forInt(4); public static final Constant INT_5 = forInt(5); - public static final Constant LONG_0 = new Constant(Kind.Long, 0L); - public static final Constant LONG_1 = new Constant(Kind.Long, 1L); - public static final Constant FLOAT_0 = new Constant(Kind.Float, Float.floatToRawIntBits(0.0F)); - public static final Constant FLOAT_1 = new Constant(Kind.Float, Float.floatToRawIntBits(1.0F)); - public static final Constant FLOAT_2 = new Constant(Kind.Float, Float.floatToRawIntBits(2.0F)); - public static final Constant DOUBLE_0 = new Constant(Kind.Double, Double.doubleToRawLongBits(0.0D)); - public static final Constant DOUBLE_1 = new Constant(Kind.Double, Double.doubleToRawLongBits(1.0D)); - public static final Constant TRUE = new Constant(Kind.Boolean, 1L); - public static final Constant FALSE = new Constant(Kind.Boolean, 0L); + public static final Constant LONG_0 = new Constant(Kind.Long, null, 0L); + public static final Constant LONG_1 = new Constant(Kind.Long, null, 1L); + public static final Constant FLOAT_0 = new Constant(Kind.Float, null, Float.floatToRawIntBits(0.0F)); + public static final Constant FLOAT_1 = new Constant(Kind.Float, null, Float.floatToRawIntBits(1.0F)); + public static final Constant FLOAT_2 = new Constant(Kind.Float, null, Float.floatToRawIntBits(2.0F)); + public static final Constant DOUBLE_0 = new Constant(Kind.Double, null, Double.doubleToRawLongBits(0.0D)); + public static final Constant DOUBLE_1 = new Constant(Kind.Double, null, Double.doubleToRawLongBits(1.0D)); + public static final Constant TRUE = new Constant(Kind.Boolean, null, 1L); + public static final Constant FALSE = new Constant(Kind.Boolean, null, 0L); static { assert FLOAT_0 != forFloat(-0.0F) : "Constant for 0.0f must be different from -0.0f"; @@ -75,43 +75,9 @@ */ private final long primitive; - /** - * Creates a constant represented by the specified object reference. - * @param object the value of this constant - */ - private Constant(Object object) { - super(Kind.Object); - this.object = object; - this.primitive = 0L; - } - - /** - * Creates a constant represented by the specified primitive. - * - * @param kind the type of this constant - * @param primitive the value of this constant - */ - public Constant(Kind kind, long primitive) { + private Constant(Kind kind, Object object, long primitive) { super(kind); - assert kind != Kind.Object; - this.object = null; - this.primitive = primitive; - } - - /** - * Creates an annotated primitive constant. An annotation enables a {@linkplain MetaAccessProvider provider} to - * associate some extra semantic or debugging information with a primitive. An annotated primitive constant - * is never {@linkplain #equals(Object) equal} to a non-annotated constant. - * - * @param kind the type of this constant - * @param primitive the value of this constant - * @param annotation an arbitrary non-null object - */ - public Constant(Kind kind, long primitive, Object annotation) { - super(kind); - assert kind != Kind.Object; - assert annotation != null; - this.object = annotation; + this.object = object; this.primitive = primitive; } @@ -302,7 +268,7 @@ if (Double.compare(d, 1.0D) == 0) { return DOUBLE_1; } - return new Constant(Kind.Double, Double.doubleToRawLongBits(d)); + return new Constant(Kind.Double, null, Double.doubleToRawLongBits(d)); } /** @@ -321,7 +287,7 @@ if (Float.compare(f, 2.0F) == 0) { return FLOAT_2; } - return new Constant(Kind.Float, Float.floatToRawIntBits(f)); + return new Constant(Kind.Float, null, Float.floatToRawIntBits(f)); } /** @@ -331,7 +297,7 @@ * @return a boxed copy of {@code value} */ public static Constant forLong(long i) { - return i == 0 ? LONG_0 : i == 1 ? LONG_1 : new Constant(Kind.Long, i); + return i == 0 ? LONG_0 : i == 1 ? LONG_1 : new Constant(Kind.Long, null, i); } /** @@ -347,7 +313,7 @@ if (i >= 0 && i < INT_CONSTANT_CACHE.length) { return INT_CONSTANT_CACHE[i]; } - return new Constant(Kind.Int, i); + return new Constant(Kind.Int, null, i); } /** @@ -357,7 +323,7 @@ * @return a boxed copy of {@code value} */ public static Constant forByte(byte i) { - return new Constant(Kind.Byte, i); + return new Constant(Kind.Byte, null, i); } /** @@ -377,7 +343,7 @@ * @return a boxed copy of {@code value} */ public static Constant forChar(char i) { - return new Constant(Kind.Char, i); + return new Constant(Kind.Char, null, i); } /** @@ -387,7 +353,7 @@ * @return a boxed copy of {@code value} */ public static Constant forShort(short i) { - return new Constant(Kind.Short, i); + return new Constant(Kind.Short, null, i); } /** @@ -397,7 +363,7 @@ * @return a boxed copy of {@code value} */ public static Constant forJsr(int i) { - return new Constant(Kind.Jsr, i); + return new Constant(Kind.Jsr, null, i); } /** @@ -410,7 +376,27 @@ if (o == null) { return NULL_OBJECT; } - return new Constant(o); + return new Constant(Kind.Object, o, 0L); + } + + /** + * Creates an annotated int or long constant. An annotation enables a client to associate some extra semantic or + * debugging information with a primitive. An annotated primitive constant is never {@linkplain #equals(Object) + * equal} to a non-annotated constant. + * + * @param kind the type of this constant + * @param i the value of this constant + * @param annotation an arbitrary non-null object + */ + public static Constant forIntegerKind(Kind kind, long i, Object annotation) { + switch (kind) { + case Int: + return new Constant(kind, annotation, (int) i); + case Long: + return new Constant(kind, annotation, i); + default: + throw new IllegalArgumentException("not an integer kind: " + kind); + } } /** diff -r 5c25483b5515 -r f1f32b695d1e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Nov 29 16:53:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Nov 29 17:43:09 2012 -0800 @@ -448,7 +448,7 @@ * Gets the address of the C++ Klass object for this type. */ public Constant klass() { - return new Constant(HotSpotGraalRuntime.getInstance().getTarget().wordKind, metaspaceKlass, this); + return Constant.forIntegerKind(HotSpotGraalRuntime.getInstance().getTarget().wordKind, metaspaceKlass, this); } public boolean isPrimaryType() { diff -r 5c25483b5515 -r f1f32b695d1e 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 Thu Nov 29 16:53:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/BeginLockScopeNode.java Thu Nov 29 17:43:09 2012 -0800 @@ -56,10 +56,11 @@ public void generate(LIRGenerator gen) { gen.lock(); StackSlot lockData = gen.peekLock(); - Value result = eliminated ? new Constant(gen.target().wordKind, 0L) : gen.emitLea(lockData); - FrameState stateAfter = stateAfter(); - assert stateAfter != null; - gen.setResult(this, result); + assert stateAfter() != null; + if (!eliminated) { + Value result = gen.emitLea(lockData); + gen.setResult(this, result); + } } @NodeIntrinsic diff -r 5c25483b5515 -r f1f32b695d1e 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 Thu Nov 29 16:53:44 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Thu Nov 29 17:43:09 2012 -0800 @@ -273,7 +273,7 @@ ValueNode memory; if (!useTLAB) { - memory = ConstantNode.forConstant(new Constant(target.wordKind, 0L), runtime, graph); + memory = ConstantNode.defaultForKind(target.wordKind, graph); } else { ConstantNode sizeNode = ConstantNode.forInt(size, graph); TLABAllocateNode tlabAllocateNode = graph.add(new TLABAllocateNode(sizeNode)); @@ -300,7 +300,7 @@ final Integer length = lengthNode.isConstant() ? Integer.valueOf(lengthNode.asConstant().asInt()) : null; int log2ElementSize = CodeUtil.log2(target.sizeInBytes(elementKind)); if (!useTLAB) { - ConstantNode zero = ConstantNode.forConstant(new Constant(target.wordKind, 0L), runtime, graph); + ConstantNode zero = ConstantNode.defaultForKind(target.wordKind, graph); // value for 'size' doesn't matter as it isn't used since a stub call will be made anyway // for both allocation and initialization - it just needs to be non-null ConstantNode size = ConstantNode.forInt(-1, graph);