# HG changeset patch # User Doug Simon # Date 1428569698 -7200 # Node ID 56ff43bb250adadc6be569550ae1ab17e2ea7809 # Parent 9c8743f5ff53f402f141d568419d9395f88f5d5d rename SystemIdentityHashCodeNode to IdentityHashCodeNode and use it for Object.hashCode diff -r 9c8743f5ff53 -r 56ff43bb250a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Apr 09 10:26:28 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Apr 09 10:54:58 2015 +0200 @@ -100,7 +100,12 @@ return true; } }); - r.registerMethodSubstitution(ObjectSubstitutions.class, "hashCode", Receiver.class); + r.register1("hashCode", Receiver.class, new InvocationPlugin() { + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + b.addPush(new IdentityHashCodeNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnType(), receiver.get())); + return true; + } + }); } private static void registerClassPlugins(InvocationPlugins plugins) { @@ -168,7 +173,7 @@ r.register0("nanoTime", new ForeignCallPlugin(foreignCalls, JAVA_TIME_NANOS)); r.register1("identityHashCode", Object.class, new InvocationPlugin() { public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { - b.addPush(new SystemIdentityHashCodeNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnType(), object)); + b.addPush(new IdentityHashCodeNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnType(), object)); return true; } }); diff -r 9c8743f5ff53 -r 56ff43bb250a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/IdentityHashCodeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/IdentityHashCodeNode.java Thu Apr 09 10:54:58 2015 +0200 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013, 2015, 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.replacements; + +import static com.oracle.graal.compiler.common.GraalOptions.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.meta.*; +import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.CallTargetNode.InvokeKind; +import com.oracle.graal.replacements.nodes.*; + +@NodeInfo +public final class IdentityHashCodeNode extends PureFunctionMacroNode { + + public static final NodeClass TYPE = NodeClass.create(IdentityHashCodeNode.class); + + public IdentityHashCodeNode(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, int bci, JavaType returnType, ValueNode object) { + super(TYPE, invokeKind, targetMethod, bci, returnType, object); + } + + @Override + protected JavaConstant evaluate(JavaConstant param, MetaAccessProvider metaAccess) { + if (ImmutableCode.getValue() || param.isNull()) { + return null; + } + HotSpotObjectConstant c = (HotSpotObjectConstant) param; + return JavaConstant.forInt(c.getIdentityHashCode()); + } +} diff -r 9c8743f5ff53 -r 56ff43bb250a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemIdentityHashCodeNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemIdentityHashCodeNode.java Thu Apr 09 10:26:28 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013, 2015, 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.replacements; - -import static com.oracle.graal.compiler.common.GraalOptions.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.CallTargetNode.InvokeKind; -import com.oracle.graal.replacements.nodes.*; - -@NodeInfo -public final class SystemIdentityHashCodeNode extends PureFunctionMacroNode { - - public static final NodeClass TYPE = NodeClass.create(SystemIdentityHashCodeNode.class); - - public SystemIdentityHashCodeNode(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, int bci, JavaType returnType, ValueNode object) { - super(TYPE, invokeKind, targetMethod, bci, returnType, object); - } - - @Override - protected JavaConstant evaluate(JavaConstant param, MetaAccessProvider metaAccess) { - if (ImmutableCode.getValue() || param.isNull()) { - return null; - } - HotSpotObjectConstant c = (HotSpotObjectConstant) param; - return JavaConstant.forInt(c.getIdentityHashCode()); - } -} diff -r 9c8743f5ff53 -r 56ff43bb250a graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/Object_hashCode02.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/Object_hashCode02.java Thu Apr 09 10:54:58 2015 +0200 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2007, 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.jtt.lang; + +import java.time.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.graal.jtt.*; + +public final class Object_hashCode02 extends JTTTest { + + public static final Object obj1 = new Object(); + public static final Object obj2 = DayOfWeek.FRIDAY; + public static final Object obj3 = new HashMap<>(); + + public static int test(int a) { + if (a == 1) { + return obj1.hashCode(); + } + if (a == 2) { + return obj2.hashCode(); + } + return obj3.hashCode(); + } + + @Test + public void run0() throws Throwable { + runTest("test", 1); + } + + @Test + public void run1() throws Throwable { + runTest("test", 2); + } + + @Test + public void run2() throws Throwable { + runTest("test", 3); + } +}