changeset 17232:be6f5fad74c6

check that all callers of Fields.getObject(Object, int, Class) pass a class literal for the last parameter
author Doug Simon <doug.simon@oracle.com>
date Fri, 26 Sep 2014 14:53:35 +0200
parents 58f1d1335ef4
children 1278680407e7
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/VerifyFieldsGetNode.java
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java	Fri Sep 26 14:53:23 2014 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java	Fri Sep 26 14:53:35 2014 +0200
@@ -211,6 +211,7 @@
             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);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/VerifyFieldsGetNode.java	Fri Sep 26 14:53:35 2014 +0200
@@ -0,0 +1,61 @@
+/*
+ * 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<PhaseContext> {
+
+    @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;
+    }
+}