1 /* |
1 /* |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
32 import org.graalvm.compiler.nodes.ConstantNode; |
32 import org.graalvm.compiler.nodes.ConstantNode; |
33 import org.graalvm.compiler.nodes.NodeView; |
33 import org.graalvm.compiler.nodes.NodeView; |
34 import org.graalvm.compiler.nodes.StructuredGraph; |
34 import org.graalvm.compiler.nodes.StructuredGraph; |
35 import org.graalvm.compiler.nodes.ValueNode; |
35 import org.graalvm.compiler.nodes.ValueNode; |
36 import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
36 import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
|
37 import org.graalvm.compiler.nodes.spi.CoreProviders; |
37 import org.graalvm.compiler.nodes.spi.Virtualizable; |
38 import org.graalvm.compiler.nodes.spi.Virtualizable; |
38 import org.graalvm.compiler.phases.VerifyPhase; |
39 import org.graalvm.compiler.phases.VerifyPhase; |
39 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
40 |
40 |
41 import jdk.vm.ci.meta.ResolvedJavaMethod; |
41 import jdk.vm.ci.meta.ResolvedJavaMethod; |
42 import jdk.vm.ci.meta.ResolvedJavaType; |
42 import jdk.vm.ci.meta.ResolvedJavaType; |
43 |
43 |
44 /** |
44 /** |
45 * Verifies that node types implementing the {@link Virtualizable} interface use it correctly. |
45 * Verifies that node types implementing the {@link Virtualizable} interface use it correctly. |
46 * Implementors of {@link Virtualizable#virtualize(org.graalvm.compiler.nodes.spi.VirtualizerTool)} |
46 * Implementors of {@link Virtualizable#virtualize(org.graalvm.compiler.nodes.spi.VirtualizerTool)} |
47 * must not apply effects on their {@link Graph graph} that cannot be easily undone. |
47 * must not apply effects on their {@link Graph graph} that cannot be easily undone. |
48 */ |
48 */ |
49 public class VerifyVirtualizableUsage extends VerifyPhase<PhaseContext> { |
49 public class VerifyVirtualizableUsage extends VerifyPhase<CoreProviders> { |
50 @Override |
50 @Override |
51 public boolean checkContract() { |
51 public boolean checkContract() { |
52 return false; |
52 return false; |
53 } |
53 } |
54 |
54 |
55 @Override |
55 @Override |
56 protected void verify(StructuredGraph graph, PhaseContext context) { |
56 protected void verify(StructuredGraph graph, CoreProviders context) { |
57 final ResolvedJavaType graphType = context.getMetaAccess().lookupJavaType(Graph.class); |
57 final ResolvedJavaType graphType = context.getMetaAccess().lookupJavaType(Graph.class); |
58 final ResolvedJavaType virtualizableType = context.getMetaAccess().lookupJavaType(Virtualizable.class); |
58 final ResolvedJavaType virtualizableType = context.getMetaAccess().lookupJavaType(Virtualizable.class); |
59 final ResolvedJavaType constantNodeType = context.getMetaAccess().lookupJavaType(ConstantNode.class); |
59 final ResolvedJavaType constantNodeType = context.getMetaAccess().lookupJavaType(ConstantNode.class); |
60 if (virtualizableType.isAssignableFrom(graph.method().getDeclaringClass()) && graph.method().getName().equals("virtualize")) { |
60 if (virtualizableType.isAssignableFrom(graph.method().getDeclaringClass()) && graph.method().getName().equals("virtualize")) { |
61 for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) { |
61 for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) { |