# HG changeset patch # User Doug Simon # Date 1411747855 -7200 # Node ID 1278680407e79f9602b7b1cee8427b5ee98b962e # Parent be6f5fad74c61b53094e8823410f44eabfb1958a moved intrinsifications for Edges back into EdgesSubstitutions diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java Fri Sep 26 14:53:35 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java Fri Sep 26 18:10:55 2014 +0200 @@ -34,7 +34,7 @@ public class Fields { protected final Class clazz; - private final long[] offsets; + protected final long[] offsets; private final String[] names; private final Class[] types; @@ -212,48 +212,8 @@ return unsafe.getDouble(n, offsets[i]); } - /** - * Gets the value of an object field. - * - * @param object the object whose field is to be read - * @param index the index of the field (between 0 and {@link #getCount()}) - * @return the value of the specified field cast to {@code c} - */ - public Object getObject(Object object, int index) { - return getObject(object, offsets[index], Object.class); - } - - /** - * Gets the value of an object field and casts it to a given type. - * - * NOTE: All callers of this method should use a class literal for the last argument. - * - * @param object the object whose field is to be read - * @param index the index of the field (between 0 and {@link #getCount()}) - * @param asType the type to which the returned object is cast - * @return the value of the specified field cast to {@code c} - */ - protected T getObject(Object object, int index, Class asType) { - return getObject(object, offsets[index], asType); - } - - private static T getObject(Object object, long offset, Class asType) { - return asType.cast(unsafe.getObject(object, offset)); - } - - /** - * Sets the value of an object field. - * - * @param object the object whose field is to be written - * @param index the index of the field (between 0 and {@link #getCount()}) - * @param value the value to be written to the field - */ - protected void putObject(Object object, int index, Object value) { - assert checkAssignableFrom(index, value); - putObject(object, offsets[index], value); - } - - private static void putObject(Object object, long offset, Object value) { - unsafe.putObject(object, offset, value); + public Object getObject(Object object, int i) { + assert !types[i].isPrimitive(); + return unsafe.getObject(object, offsets[i]); } } diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Fri Sep 26 14:53:35 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Fri Sep 26 18:10:55 2014 +0200 @@ -211,7 +211,6 @@ new VerifyUsageWithEquals(JavaMethod.class).apply(graph, context); new VerifyUsageWithEquals(JavaField.class).apply(graph, context); new VerifyUsageWithEquals(LIRKind.class).apply(graph, context); - new VerifyFieldsGetNode().apply(graph, context); } new VerifyDebugUsage().apply(graph, context); } diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/VerifyFieldsGetNode.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/VerifyFieldsGetNode.java Fri Sep 26 14:53:35 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013, 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.compiler.test; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.tiers.*; - -/** - * Verifies that the third parameter of a call to {@link Fields#getObject(Object, int, Class)} is a - * class literal. This is required so that the DeferredPiNode in the substitution of this method is - * resolved to a constant after the (substitute) method is inlined. - */ -@SuppressWarnings("javadoc") -public class VerifyFieldsGetNode extends VerifyPhase { - - @Override - protected boolean verify(StructuredGraph graph, PhaseContext context) { - ResolvedJavaMethod getObjectMethod; - try { - getObjectMethod = context.getMetaAccess().lookupJavaMethod(Fields.class.getDeclaredMethod("getObject", Object.class, int.class, Class.class)); - } catch (Exception e) { - throw new VerificationError(e.toString()); - } - - for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.class)) { - ResolvedJavaMethod callee = t.targetMethod(); - if (callee.equals(getObjectMethod)) { - ValueNode arg3 = t.arguments().get(3); - if (!arg3.isConstant()) { - StackTraceElement e = graph.method().asStackTraceElement(t.invoke().bci()); - throw new VerificationError(String.format("%s: parameter 2 of call to %s must be a class literal, not %s", e, callee.format("%H.%n(%p)"), arg3)); - } - } - } - return true; - } -} diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java Fri Sep 26 14:53:35 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java Fri Sep 26 18:10:55 2014 +0200 @@ -22,6 +22,7 @@ */ package com.oracle.graal.graph; +import static com.oracle.graal.compiler.common.UnsafeAccess.*; import static com.oracle.graal.graph.Graph.*; import static com.oracle.graal.graph.Node.*; @@ -52,6 +53,23 @@ this.directCount = directCount; } + private static Node getNode(Node node, long offset) { + return (Node) unsafe.getObject(node, offset); + } + + @SuppressWarnings("unchecked") + private static NodeList getNodeList(Node node, long offset) { + return (NodeList) unsafe.getObject(node, offset); + } + + private static void putNode(Node node, long offset, Node value) { + unsafe.putObject(node, offset, value); + } + + private static void putNodeList(Node node, long offset, NodeList value) { + unsafe.putObject(node, offset, value); + } + /** * Get the number of direct edges represented by this object. A direct edge goes directly to * another {@link Node}. An indirect edge goes via a {@link NodeList}. @@ -69,7 +87,7 @@ */ public Node getNode(Node node, int index) { assert index >= 0 && index < directCount; - return getObject(node, index, Node.class); + return getNode(node, offsets[index]); } /** @@ -80,10 +98,9 @@ * {@link #getDirectCount()}) * @return the {@link NodeList} at the other edge of the requested edge */ - @SuppressWarnings("unchecked") public NodeList getNodeList(Node node, int index) { assert index >= directCount && index < getCount(); - return getObject(node, index, NodeList.class); + return getNodeList(node, offsets[index]); } /** @@ -175,12 +192,12 @@ * @param value the node to be written to the edge */ public void initializeNode(Node node, int index, Node value) { - putObject(node, index, value); + putNode(node, offsets[index], value); } public void initializeList(Node node, int index, NodeList value) { assert index >= directCount; - putObject(node, index, value); + putNodeList(node, offsets[index], value); } /** @@ -193,8 +210,8 @@ */ public void setNode(Node node, int index, Node value) { assert index < directCount; - Node old = getObject(node, index, Node.class); - putObject(node, index, value); + Node old = getNode(node, offsets[index]); + putNode(node, offsets[index], value); update(node, old, value); } diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/EdgesTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/EdgesTest.java Fri Sep 26 14:53:35 2014 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/EdgesTest.java Fri Sep 26 18:10:55 2014 +0200 @@ -74,7 +74,8 @@ } /** - * Checks that there are no checkcasts in {@link Edges#getNode(Node, int)} + * Checks that there are no checkcasts in the compiled version of + * {@link Edges#getNode(Node, int)} */ @Test public void test0() { @@ -82,7 +83,8 @@ } /** - * Checks that there are no checkcasts in {@link Edges#getNodeList(Node, int)} + * Checks that there are no checkcasts in the compiled version of + * {@link Edges#getNodeList(Node, int)} */ @Test public void test1() { @@ -90,7 +92,8 @@ } /** - * Checks that there are no checkcasts in {@link Edges#setNode(Node, int, Node)} + * Checks that there are no checkcasts in the compiled version of + * {@link Edges#setNode(Node, int, Node)} */ @Test public void test2() { diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/EdgesSubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/EdgesSubstitutions.java Fri Sep 26 18:10:55 2014 +0200 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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.replacements; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.api.replacements.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.replacements.nodes.*; + +/** + * Substitutions for improving the performance of some critical methods in {@link Edges}. These + * substitutions improve the performance by forcing the relevant methods to be inlined + * (intrinsification being a special form of inlining) and removing a checked cast. The latter + * cannot be done directly in Java code as {@link DeferredPiNode} is not available to the project + * containing {@link Edges}. + */ +@ClassSubstitution(Edges.class) +public class EdgesSubstitutions { + + @MethodSubstitution + private static Node getNode(Node node, long offset) { + return PiNode.piCast(UnsafeLoadNode.load(node, offset, Kind.Object, LocationIdentity.ANY_LOCATION), Node.class); + } + + @MethodSubstitution + private static NodeList getNodeList(Node node, long offset) { + return PiNode.piCast(UnsafeLoadNode.load(node, offset, Kind.Object, LocationIdentity.ANY_LOCATION), NodeList.class); + } + + @MethodSubstitution + private static void putNode(Node node, long offset, Node value) { + UnsafeStoreNode.store(node, offset, value, Kind.Object, LocationIdentity.ANY_LOCATION); + } + + @MethodSubstitution + private static void putNodeList(Node node, long offset, NodeList value) { + UnsafeStoreNode.store(node, offset, value, Kind.Object, LocationIdentity.ANY_LOCATION); + } +} diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/FieldsSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/FieldsSubstitutions.java Fri Sep 26 14:53:35 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 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.replacements; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.replacements.nodes.*; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** - * Substitutions for improving the performance of some critical methods in {@link Fields}. These - * substitutions improve the performance by forcing the relevant methods to be inlined - * (intrinsification being a special form of inlining) and removing a checked cast. The latter - * cannot be done directly in Java code as {@link DeferredPiNode} is not available to the project - * containing {@link Fields}. - */ -@ClassSubstitution(Fields.class) -public class FieldsSubstitutions { - - /** - * This substitution exists to force inline {@link Fields#getObject(Object, int, Class)}. - */ - @SuppressWarnings("javadoc") - @SuppressFBWarnings - @MethodSubstitution(isStatic = false) - private static T getObject(Fields thisObj, Object object, int index, Class asType) { - return getObject(thisObj, object, index, asType); - } - - @MethodSubstitution - private static T getObject(Object object, long offset, Class c) { - return DeferredPiNode.piCast(c, UnsafeLoadNode.load(object, offset, Kind.Object, LocationIdentity.ANY_LOCATION)); - } - - @MethodSubstitution - private static void putObject(Object node, long offset, Object value) { - UnsafeStoreNode.store(node, offset, value, Kind.Object, LocationIdentity.ANY_LOCATION); - } -} diff -r be6f5fad74c6 -r 1278680407e7 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Fri Sep 26 14:53:35 2014 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Fri Sep 26 18:10:55 2014 +0200 @@ -30,7 +30,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.api.runtime.*; -import com.oracle.graal.compiler.common.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.spi.*; /** @@ -51,7 +51,7 @@ replacements.registerSubstitutions(Character.class, CharacterSubstitutions.class); replacements.registerSubstitutions(Short.class, ShortSubstitutions.class); replacements.registerSubstitutions(UnsignedMath.class, UnsignedMathSubstitutions.class); - replacements.registerSubstitutions(Fields.class, FieldsSubstitutions.class); + replacements.registerSubstitutions(Edges.class, EdgesSubstitutions.class); } } }