# HG changeset patch # User Christian Wimmer # Date 1353987054 28800 # Node ID 52c88c405d07989572ece4207bfb2bdc0ccdc43c # Parent 89df4e71940ad78bb84b61f97369fddecb7580da Simplify how stamp is preserved after lowering of allocation nodes diff -r 89df4e71940a -r 52c88c405d07 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CastFromHub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CastFromHub.java Mon Nov 26 18:58:28 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.nodes; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.snippets.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.graal.snippets.*; - -/** - * This node is used by the {@link NewObjectSnippets} to give a formatted new instance or object its exact type. - */ -public final class CastFromHub extends FloatingNode implements Canonicalizable { - - @Input private ValueNode object; - @Input private ValueNode hub; - - public ValueNode object() { - return object; - } - - public CastFromHub(ValueNode object, ValueNode hubObject) { - // TODO: the non-nullness should really be derived from 'object' but until - // control flow sensitive type analysis is implemented, the object coming - // from the TLAB fast path is not non-null - super(StampFactory.objectNonNull()); - this.object = object; - this.hub = hubObject; - } - - @Override - public ValueNode canonical(CanonicalizerTool tool) { - if (hub.isConstant()) { - ResolvedJavaType type = HotSpotResolvedJavaType.fromMetaspaceKlass(hub.asConstant()); - return graph().unique(new UnsafeCastNode(object, type, true, true)); - } - return this; - } - - @NodeIntrinsic - public static native T castFromHub(Object object, Word hub); -} diff -r 89df4e71940a -r 52c88c405d07 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:58:28 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Nov 26 19:30:54 2012 -0800 @@ -23,8 +23,9 @@ package com.oracle.graal.hotspot.snippets; import static com.oracle.graal.api.code.UnsignedMath.*; -import static com.oracle.graal.hotspot.nodes.CastFromHub.*; import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*; +import static com.oracle.graal.nodes.extended.UnsafeArrayCastNode.*; +import static com.oracle.graal.nodes.extended.UnsafeCastNode.*; import static com.oracle.graal.snippets.Snippet.Varargs.*; import static com.oracle.graal.snippets.SnippetTemplate.*; import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*; @@ -78,17 +79,19 @@ @ConstantParameter("fillContents") boolean fillContents, @ConstantParameter("locked") boolean locked) { + Object result; if (memory == Word.zero()) { new_stub.inc(); - return NewInstanceStubCall.call(hub); - } - if (locked) { - formatObject(hub, size, memory, thread().or(biasedLockPattern()), fillContents); + result = NewInstanceStubCall.call(hub); } else { - formatObject(hub, size, memory, prototypeMarkWord, fillContents); + if (locked) { + formatObject(hub, size, memory, thread().or(biasedLockPattern()), fillContents); + } else { + formatObject(hub, size, memory, prototypeMarkWord, fillContents); + } + result = memory.toObject(); } - Object instance = memory.toObject(); - return castFromHub(verifyOop(instance), hub); + return unsafeCast(verifyOop(result), StampFactory.forNodeIntrinsic()); } @Snippet @@ -126,22 +129,24 @@ } private static Object initializeArray(Word memory, Word hub, int length, int size, Word prototypeMarkWord, int headerSize, boolean isObjectArray, boolean fillContents) { + Object result; if (memory == Word.zero()) { if (isObjectArray) { anewarray_stub.inc(); } else { newarray_stub.inc(); } - return NewArrayStubCall.call(isObjectArray, hub, length); - } - if (isObjectArray) { - anewarray_loopInit.inc(); + result = NewArrayStubCall.call(isObjectArray, hub, length); } else { - newarray_loopInit.inc(); + if (isObjectArray) { + anewarray_loopInit.inc(); + } else { + newarray_loopInit.inc(); + } + formatArray(hub, size, length, headerSize, memory, prototypeMarkWord, fillContents); + result = memory.toObject(); } - formatArray(hub, size, length, headerSize, memory, prototypeMarkWord, fillContents); - Object instance = memory.toObject(); - return castFromHub(verifyOop(instance), hub); + return unsafeArrayCast(verifyOop(result), length, StampFactory.forNodeIntrinsic()); } /** diff -r 89df4e71940a -r 52c88c405d07 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeArrayCastNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeArrayCastNode.java Mon Nov 26 19:30:54 2012 -0800 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.nodes.extended; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; + +/** + * The {@code UnsafeCastNode} produces the same value as its input, but with a different type. + */ +public final class UnsafeArrayCastNode extends UnsafeCastNode implements ArrayLengthProvider { + + @Input + private ValueNode length; + + public ValueNode length() { + return length; + } + + public UnsafeArrayCastNode(ValueNode object, ValueNode length, Stamp stamp) { + super(object, stamp); + this.length = length; + } + + @Override + public ValueNode canonical(CanonicalizerTool tool) { + if (!(object() instanceof ArrayLengthProvider) || length() != ((ArrayLengthProvider) object()).length()) { + return this; + } + return super.canonical(tool); + } + + @NodeIntrinsic + public static native T unsafeArrayCast(Object object, int length, @ConstantNodeParameter Stamp stamp); +}