# HG changeset patch # User Roland Schatz # Date 1393410050 -3600 # Node ID 2b5b3fcd65ba82e5d97ca8ec12c6c0c27892792f # Parent 740367295912bad3fc79e9c04a421b339b93acfc Separate singleton stamp for the void type. diff -r 740367295912 -r 2b5b3fcd65ba graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AbstractMethodHandleNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AbstractMethodHandleNode.java Wed Feb 26 11:08:08 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AbstractMethodHandleNode.java Wed Feb 26 11:20:50 2014 +0100 @@ -22,31 +22,18 @@ */ package com.oracle.graal.hotspot.replacements; -import java.lang.reflect.Modifier; -import java.util.Arrays; +import java.lang.reflect.*; +import java.util.*; -import com.oracle.graal.api.meta.Constant; -import com.oracle.graal.api.meta.JavaType; -import com.oracle.graal.api.meta.ResolvedJavaField; -import com.oracle.graal.api.meta.ResolvedJavaMethod; -import com.oracle.graal.api.meta.ResolvedJavaType; -import com.oracle.graal.graph.GraalInternalError; -import com.oracle.graal.graph.NodeInputList; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; -import com.oracle.graal.hotspot.meta.HotSpotResolvedJavaMethod; -import com.oracle.graal.hotspot.meta.HotSpotResolvedObjectType; -import com.oracle.graal.hotspot.meta.HotSpotSignature; -import com.oracle.graal.nodes.CallTargetNode; -import com.oracle.graal.nodes.Invoke; -import com.oracle.graal.nodes.InvokeNode; -import com.oracle.graal.nodes.PiNode; -import com.oracle.graal.nodes.ValueNode; -import com.oracle.graal.nodes.java.MethodCallTargetNode; +import com.oracle.graal.hotspot.meta.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind; -import com.oracle.graal.nodes.java.SelfReplacingMethodCallTargetNode; import com.oracle.graal.nodes.type.*; -import com.oracle.graal.nodes.type.GenericStamp.*; -import com.oracle.graal.replacements.nodes.MacroNode; +import com.oracle.graal.replacements.nodes.*; /** * Common base class for method handle invoke nodes. @@ -282,7 +269,7 @@ // invoker's stamp would be wrong because it's a less concrete type // (usually java.lang.Object). InvokeNode invoke; - if (stamp() instanceof GenericStamp && ((GenericStamp) stamp()).type() == GenericStampType.Void) { + if (stamp() == StampFactory.forVoid()) { invoke = new InvokeNode(callTarget, getBci(), stamp()); } else { invoke = new InvokeNode(callTarget, getBci()); diff -r 740367295912 -r 2b5b3fcd65ba graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java Wed Feb 26 11:08:08 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java Wed Feb 26 11:20:50 2014 +0100 @@ -29,7 +29,7 @@ public final class GenericStamp extends Stamp { public enum GenericStampType { - Dependency, Extension, Condition, Void + Dependency, Extension, Condition } private final GenericStampType type; @@ -49,11 +49,7 @@ @Override public Kind getStackKind() { - if (type == GenericStampType.Void) { - return Kind.Void; - } else { - return Kind.Illegal; - } + return Kind.Illegal; } @Override @@ -63,8 +59,7 @@ @Override public ResolvedJavaType javaType(MetaAccessProvider metaAccess) { - assert type == GenericStampType.Void; - return metaAccess.lookupJavaType(Void.TYPE); + throw GraalInternalError.shouldNotReachHere(type + " stamp has not Java type"); } @Override diff -r 740367295912 -r 2b5b3fcd65ba graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Wed Feb 26 11:08:08 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Wed Feb 26 11:20:50 2014 +0100 @@ -38,7 +38,6 @@ private static final Stamp dependencyStamp = new GenericStamp(GenericStampType.Dependency); private static final Stamp extensionStamp = new GenericStamp(GenericStampType.Extension); private static final Stamp conditionStamp = new GenericStamp(GenericStampType.Condition); - private static final Stamp voidStamp = new GenericStamp(GenericStampType.Void); private static final Stamp nodeIntrinsicStamp = new ObjectStamp(null, false, false, false); private static final Stamp positiveInt = forInteger(Kind.Int, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE); @@ -73,7 +72,7 @@ setFloatCache(Kind.Double); setCache(Kind.Object, objectStamp); - setCache(Kind.Void, voidStamp); + setCache(Kind.Void, VoidStamp.getInstance()); for (Kind k : Kind.values()) { illegalStampCache[k.ordinal()] = new IllegalStamp(k); } @@ -87,8 +86,12 @@ return stampCache[kind.ordinal()]; } + /** + * Return the stamp for the {@code void} type. This will return a singleton instance than can be + * compared using {@code ==}. + */ public static Stamp forVoid() { - return voidStamp; + return VoidStamp.getInstance(); } /** diff -r 740367295912 -r 2b5b3fcd65ba graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/VoidStamp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/VoidStamp.java Wed Feb 26 11:20:50 2014 +0100 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014, 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.type; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.spi.*; + +/** + * Singleton stamp representing the value of type {@code void}. + */ +public final class VoidStamp extends Stamp { + + private VoidStamp() { + } + + @Override + public Stamp unrestricted() { + return this; + } + + @Override + public Kind getStackKind() { + return Kind.Void; + } + + @Override + public PlatformKind getPlatformKind(LIRTypeTool tool) { + throw GraalInternalError.shouldNotReachHere("void stamp has no value"); + } + + @Override + public ResolvedJavaType javaType(MetaAccessProvider metaAccess) { + return metaAccess.lookupJavaType(Void.TYPE); + } + + @Override + public String toString() { + return "void"; + } + + @Override + public boolean alwaysDistinct(Stamp other) { + return this != other; + } + + @Override + public Stamp meet(Stamp other) { + if (other instanceof IllegalStamp) { + return other.join(this); + } + if (this == other) { + return this; + } + return StampFactory.illegal(Kind.Illegal); + } + + @Override + public Stamp join(Stamp other) { + if (other instanceof IllegalStamp) { + return other.join(this); + } + if (this == other) { + return this; + } + return StampFactory.illegal(Kind.Illegal); + } + + @Override + public boolean isCompatible(Stamp stamp) { + return this == stamp; + } + + private static VoidStamp instance = new VoidStamp(); + + static VoidStamp getInstance() { + return instance; + } +}