Mercurial > hg > truffle
changeset 19957:3a1ce0aeb829
added support for checking nodes added to the graph by an Invocation plugin and used this to check that only legal constants are added under ImmutableCode
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 19 Mar 2015 12:46:06 +0100 |
parents | cd38af126abf |
children | e018185695f6 |
files | graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInvocationPlugins.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java |
diffstat | 4 files changed, 45 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Wed Mar 18 12:39:43 2015 +0100 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Thu Mar 19 12:46:06 2015 +0100 @@ -30,6 +30,8 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; +import com.oracle.graal.graph.Node; +import com.oracle.graal.graph.iterators.*; import com.oracle.graal.nodes.*; /** @@ -385,4 +387,18 @@ public int size() { return registrations.size(); } + + /** + * Checks a set of nodes added to the graph by an {@link InvocationPlugin}. + * + * @param b the graph builder that applied the plugin + * @param plugin a plugin that was just applied + * @param newNodes the nodes added to the graph by {@code plugin} + * @throws AssertionError if any check fail + */ + public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) { + if (parent != null) { + parent.checkNewNodes(b, plugin, newNodes); + } + } }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInvocationPlugins.java Wed Mar 18 12:39:43 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInvocationPlugins.java Thu Mar 19 12:46:06 2015 +0100 @@ -23,8 +23,13 @@ package com.oracle.graal.hotspot.meta; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.graph.iterators.*; import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.phases.*; +import com.oracle.graal.nodes.*; import com.oracle.graal.replacements.StandardGraphBuilderPlugins.BoxPlugin; /** @@ -65,6 +70,22 @@ return; } } + super.register(plugin, declaringClass, name, argumentTypes); } + + @Override + public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) { + if (GraalOptions.ImmutableCode.getValue()) { + for (Node node : newNodes) { + if (node instanceof ConstantNode) { + ConstantNode c = (ConstantNode) node; + if (c.getKind() == Kind.Object && !AheadOfTimeVerificationPhase.isLegalObjectConstant(c)) { + throw new AssertionError("illegal constant node in AOT: " + node); + } + } + } + } + super.checkNewNodes(b, plugin, newNodes); + } }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java Wed Mar 18 12:39:43 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java Thu Mar 19 12:46:06 2015 +0100 @@ -32,9 +32,8 @@ import com.oracle.graal.phases.tiers.*; /** - * Checks for illegal object constants in a graph processed for AOT compilation. The only legal - * object constants are {@linkplain String#intern() interned} strings as they will be installed in - * the Class Data Sharing (CDS) space. + * Checks for {@link #isLegalObjectConstant(ConstantNode) illegal} object constants in a graph + * processed for AOT compilation. * * @see LoadJavaMirrorWithKlassPhase */ @@ -43,13 +42,17 @@ @Override protected boolean verify(StructuredGraph graph, PhaseContext context) { for (ConstantNode node : getConstantNodes(graph)) { - if (isObject(node) && !isNullReference(node) && !isInternedString(node) && !isDirectMethodHandle(node) && !isBoundMethodHandle(node)) { + if (isLegalObjectConstant(node)) { throw new VerificationError("illegal object constant: " + node); } } return true; } + public static boolean isLegalObjectConstant(ConstantNode node) { + return isObject(node) && !isNullReference(node) && !isInternedString(node) && !isDirectMethodHandle(node) && !isBoundMethodHandle(node); + } + private static boolean isObject(ConstantNode node) { return node.getKind() == Kind.Object; }
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Mar 18 12:39:43 2015 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Mar 19 12:46:06 2015 +0100 @@ -1190,6 +1190,7 @@ StateSplit.class.getSimpleName(), targetMethod.format("%H.%n(%p)"), stateSplit, plugin.getApplySourceLocation(metaAccess)); } } + graphBuilderConfig.getPlugins().getInvocationPlugins().checkNewNodes(BytecodeParser.this, plugin, newNodes); } else { assert nodeCount == currentGraph.getNodeCount() : "plugin that returns false must not create new nodes"; assert beforeStackSize == frameState.stackSize : "plugin that returns false must modify the stack";