< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyGraphAddUsage.java

Print this page




  49 import jdk.vm.ci.meta.ResolvedJavaType;
  50 
  51 public class VerifyGraphAddUsage extends VerifyPhase<PhaseContext> {
  52     private static final Method ADD_OR_UNIQUE;
  53     private static final Method CONSTRUCTOR_NEW_INSTANCE;
  54     private static final EconomicSet<Class<?>> ALLOWED_CLASSES = EconomicSet.create();
  55 
  56     static {
  57         try {
  58             ADD_OR_UNIQUE = Graph.class.getDeclaredMethod("addOrUnique", Node.class);
  59             CONSTRUCTOR_NEW_INSTANCE = Constructor.class.getDeclaredMethod("newInstance", Object[].class);
  60         } catch (NoSuchMethodException e) {
  61             throw new GraalError(e);
  62         }
  63 
  64         ALLOWED_CLASSES.add(Graph.class);
  65         ALLOWED_CLASSES.add(LoweringProvider.class);
  66     }
  67 
  68     @Override
  69     protected boolean verify(StructuredGraph graph, PhaseContext context) {
  70         boolean allowed = false;
  71         for (Class<?> cls : ALLOWED_CLASSES) {
  72             ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
  73             if (context.getMetaAccess().lookupJavaType(cls).isAssignableFrom(declaringClass)) {
  74                 allowed = true;
  75             }
  76         }
  77         if (!allowed) {
  78             ResolvedJavaMethod addOrUniqueMethod = context.getMetaAccess().lookupJavaMethod(ADD_OR_UNIQUE);
  79             for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
  80                 ResolvedJavaMethod callee = t.targetMethod();
  81                 if (callee.equals(addOrUniqueMethod)) {
  82                     ValueNode nodeArgument = t.arguments().get(1);
  83                     EconomicSet<Node> seen = EconomicSet.create();
  84                     checkNonFactory(graph, seen, context, nodeArgument);
  85                 }
  86             }
  87         }
  88 
  89         return true;
  90     }
  91 
  92     private void checkNonFactory(StructuredGraph graph, EconomicSet<Node> seen, PhaseContext context, ValueNode node) {
  93         if (seen.contains(node)) {
  94             return;
  95         }
  96         seen.add(node);
  97 
  98         // Check where the value came from recursively, or if it is allowed.
  99         if (node instanceof ValuePhiNode) {
 100             for (ValueNode input : ((ValuePhiNode) node).values()) {
 101                 checkNonFactory(graph, seen, context, input);
 102             }
 103         } else if (node instanceof PiNode) {
 104             checkNonFactory(graph, seen, context, ((PiNode) node).object());
 105         } else if (node instanceof ParameterNode) {
 106             return;
 107         } else if (node instanceof ConstantNode) {
 108             return;
 109         } else if (node instanceof ValueProxyNode) {


  49 import jdk.vm.ci.meta.ResolvedJavaType;
  50 
  51 public class VerifyGraphAddUsage extends VerifyPhase<PhaseContext> {
  52     private static final Method ADD_OR_UNIQUE;
  53     private static final Method CONSTRUCTOR_NEW_INSTANCE;
  54     private static final EconomicSet<Class<?>> ALLOWED_CLASSES = EconomicSet.create();
  55 
  56     static {
  57         try {
  58             ADD_OR_UNIQUE = Graph.class.getDeclaredMethod("addOrUnique", Node.class);
  59             CONSTRUCTOR_NEW_INSTANCE = Constructor.class.getDeclaredMethod("newInstance", Object[].class);
  60         } catch (NoSuchMethodException e) {
  61             throw new GraalError(e);
  62         }
  63 
  64         ALLOWED_CLASSES.add(Graph.class);
  65         ALLOWED_CLASSES.add(LoweringProvider.class);
  66     }
  67 
  68     @Override
  69     protected void verify(StructuredGraph graph, PhaseContext context) {
  70         boolean allowed = false;
  71         for (Class<?> cls : ALLOWED_CLASSES) {
  72             ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
  73             if (context.getMetaAccess().lookupJavaType(cls).isAssignableFrom(declaringClass)) {
  74                 allowed = true;
  75             }
  76         }
  77         if (!allowed) {
  78             ResolvedJavaMethod addOrUniqueMethod = context.getMetaAccess().lookupJavaMethod(ADD_OR_UNIQUE);
  79             for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
  80                 ResolvedJavaMethod callee = t.targetMethod();
  81                 if (callee.equals(addOrUniqueMethod)) {
  82                     ValueNode nodeArgument = t.arguments().get(1);
  83                     EconomicSet<Node> seen = EconomicSet.create();
  84                     checkNonFactory(graph, seen, context, nodeArgument);
  85                 }
  86             }
  87         }


  88     }
  89 
  90     private void checkNonFactory(StructuredGraph graph, EconomicSet<Node> seen, PhaseContext context, ValueNode node) {
  91         if (seen.contains(node)) {
  92             return;
  93         }
  94         seen.add(node);
  95 
  96         // Check where the value came from recursively, or if it is allowed.
  97         if (node instanceof ValuePhiNode) {
  98             for (ValueNode input : ((ValuePhiNode) node).values()) {
  99                 checkNonFactory(graph, seen, context, input);
 100             }
 101         } else if (node instanceof PiNode) {
 102             checkNonFactory(graph, seen, context, ((PiNode) node).object());
 103         } else if (node instanceof ParameterNode) {
 104             return;
 105         } else if (node instanceof ConstantNode) {
 106             return;
 107         } else if (node instanceof ValueProxyNode) {
< prev index next >