< prev index next >

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

Print this page
rev 52889 : 8214023: Update Graal

*** 1,7 **** /* ! * Copyright (c) 2014, 2016, 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. --- 1,7 ---- /* ! * Copyright (c) 2014, 2018, 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.
*** 70,89 **** import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.VerifyPhase; import org.graalvm.compiler.phases.VerifyPhase.VerificationError; import org.graalvm.compiler.phases.contract.VerifyNodeCosts; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.phases.util.Providers; - import org.graalvm.compiler.phases.verify.VerifyBailoutUsage; - import org.graalvm.compiler.phases.verify.VerifyCallerSensitiveMethods; - import org.graalvm.compiler.phases.verify.VerifyDebugUsage; - import org.graalvm.compiler.phases.verify.VerifyGetOptionsUsage; - import org.graalvm.compiler.phases.verify.VerifyGraphAddUsage; - import org.graalvm.compiler.phases.verify.VerifyInstanceOfUsage; - import org.graalvm.compiler.phases.verify.VerifyUpdateUsages; - import org.graalvm.compiler.phases.verify.VerifyUsageWithEquals; - import org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage; import org.graalvm.compiler.runtime.RuntimeProvider; import jdk.internal.vm.compiler.word.LocationIdentity; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; --- 70,81 ---- import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.VerifyPhase; import org.graalvm.compiler.phases.VerifyPhase.VerificationError; import org.graalvm.compiler.phases.contract.VerifyNodeCosts; import org.graalvm.compiler.phases.tiers.HighTierContext; + import org.graalvm.compiler.phases.tiers.PhaseContext; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.runtime.RuntimeProvider; import jdk.internal.vm.compiler.word.LocationIdentity; import org.junit.Assert; import org.junit.Assume; import org.junit.Test;
*** 174,183 **** --- 166,179 ---- } protected void handleParsingException(Throwable t) { GraalError.shouldNotReachHere(t); } + + public boolean shouldVerifyFoldableMethods() { + return true; + } } @Test @SuppressWarnings("try") public void test() {
*** 217,226 **** --- 213,228 ---- * Native Image is an external tool and does not need to follow the * Graal invariants. */ continue; } + if (isGSON(className)) { + /* + * GSON classes are compiled with old JDK + */ + continue; + } classNames.add(className); } } } catch (IOException ex) { Assert.fail(ex.toString());
*** 238,256 **** int availableProcessors = Runtime.getRuntime().availableProcessors(); ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory); List<String> errors = Collections.synchronizedList(new ArrayList<>()); for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) { ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) { StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build(); try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) { graphBuilderSuite.apply(graph, context); // update phi stamps graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp); ! checkGraph(context, graph); errors.add(String.format("Expected error while checking %s", m)); } catch (VerificationError e) { // expected! } catch (Throwable e) { errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e))); --- 240,287 ---- int availableProcessors = Runtime.getRuntime().availableProcessors(); ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory); List<String> errors = Collections.synchronizedList(new ArrayList<>()); + List<VerifyPhase<PhaseContext>> verifiers = new ArrayList<>(); + + // If you add a new type to test here, be sure to add appropriate + // methods to the BadUsageWithEquals class below + verifiers.add(new VerifyUsageWithEquals(Value.class)); + verifiers.add(new VerifyUsageWithEquals(Register.class)); + verifiers.add(new VerifyUsageWithEquals(RegisterCategory.class)); + verifiers.add(new VerifyUsageWithEquals(JavaType.class)); + verifiers.add(new VerifyUsageWithEquals(JavaMethod.class)); + verifiers.add(new VerifyUsageWithEquals(JavaField.class)); + verifiers.add(new VerifyUsageWithEquals(LocationIdentity.class)); + verifiers.add(new VerifyUsageWithEquals(LIRKind.class)); + verifiers.add(new VerifyUsageWithEquals(ArithmeticOpTable.class)); + verifiers.add(new VerifyUsageWithEquals(ArithmeticOpTable.Op.class)); + + verifiers.add(new VerifyDebugUsage()); + verifiers.add(new VerifyCallerSensitiveMethods()); + verifiers.add(new VerifyVirtualizableUsage()); + verifiers.add(new VerifyUpdateUsages()); + verifiers.add(new VerifyBailoutUsage()); + verifiers.add(new VerifyInstanceOfUsage()); + verifiers.add(new VerifyGraphAddUsage()); + verifiers.add(new VerifyGetOptionsUsage()); + + VerifyFoldableMethods foldableMethodsVerifier = new VerifyFoldableMethods(); + if (tool.shouldVerifyFoldableMethods()) { + verifiers.add(foldableMethodsVerifier); + } + for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) { ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); try (DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER)) { StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build(); try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) { graphBuilderSuite.apply(graph, context); // update phi stamps graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp); ! checkGraph(verifiers, context, graph); errors.add(String.format("Expected error while checking %s", m)); } catch (VerificationError e) { // expected! } catch (Throwable e) { errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
*** 286,296 **** try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) { checkMethod(method); graphBuilderSuite.apply(graph, context); // update phi stamps graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp); ! checkGraph(context, graph); } catch (VerificationError e) { errors.add(e.getMessage()); } catch (LinkageError e) { // suppress linkages errors resulting from eager resolution } catch (BailoutException e) { --- 317,327 ---- try (DebugCloseable s = debug.disableIntercept(); DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) { checkMethod(method); graphBuilderSuite.apply(graph, context); // update phi stamps graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp); ! checkGraph(verifiers, context, graph); } catch (VerificationError e) { errors.add(e.getMessage()); } catch (LinkageError e) { // suppress linkages errors resulting from eager resolution } catch (BailoutException e) {
*** 308,323 **** --- 339,363 ---- }); } } } } + executor.shutdown(); try { executor.awaitTermination(1, TimeUnit.HOURS); } catch (InterruptedException e1) { throw new RuntimeException(e1); } + + if (tool.shouldVerifyFoldableMethods()) { + try { + foldableMethodsVerifier.finish(); + } catch (Throwable e) { + errors.add(e.getMessage()); + } + } } if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder(); String nl = String.format("%n"); for (String e : errors) {
*** 332,341 **** --- 372,385 ---- private static boolean isInNativeImage(String className) { return className.startsWith("org.graalvm.nativeimage"); } + private static boolean isGSON(String className) { + return className.contains("com.google.gson"); + } + private static List<Class<?>> initializeClasses(InvariantsTool tool, List<String> classNames) { List<Class<?>> classes = new ArrayList<>(classNames.size()); for (String className : classNames) { if (!tool.shouldLoadClass(className)) { continue;
*** 380,412 **** } /** * Checks the invariants for a single graph. */ ! private static void checkGraph(HighTierContext context, StructuredGraph graph) { ! if (shouldVerifyEquals(graph.method())) { ! // If you add a new type to test here, be sure to add appropriate ! // methods to the BadUsageWithEquals class below ! new VerifyUsageWithEquals(Value.class).apply(graph, context); ! new VerifyUsageWithEquals(Register.class).apply(graph, context); ! new VerifyUsageWithEquals(RegisterCategory.class).apply(graph, context); ! new VerifyUsageWithEquals(JavaType.class).apply(graph, context); ! new VerifyUsageWithEquals(JavaMethod.class).apply(graph, context); ! new VerifyUsageWithEquals(JavaField.class).apply(graph, context); ! new VerifyUsageWithEquals(LocationIdentity.class).apply(graph, context); ! new VerifyUsageWithEquals(LIRKind.class).apply(graph, context); ! new VerifyUsageWithEquals(ArithmeticOpTable.class).apply(graph, context); ! new VerifyUsageWithEquals(ArithmeticOpTable.Op.class).apply(graph, context); ! } ! new VerifyDebugUsage().apply(graph, context); ! new VerifyCallerSensitiveMethods().apply(graph, context); ! new VerifyVirtualizableUsage().apply(graph, context); ! new VerifyUpdateUsages().apply(graph, context); ! new VerifyBailoutUsage().apply(graph, context); ! new VerifyInstanceOfUsage().apply(graph, context); ! new VerifyGraphAddUsage().apply(graph, context); ! new VerifyGetOptionsUsage().apply(graph, context); if (graph.method().isBridge()) { BridgeMethodUtils.getBridgedMethod(graph.method()); } } --- 424,441 ---- } /** * Checks the invariants for a single graph. */ ! private static void checkGraph(List<VerifyPhase<PhaseContext>> verifiers, HighTierContext context, StructuredGraph graph) { ! for (VerifyPhase<PhaseContext> verifier : verifiers) { ! if (!(verifier instanceof VerifyUsageWithEquals) || shouldVerifyEquals(graph.method())) { ! verifier.apply(graph, context); ! } else { ! verifier.apply(graph, context); ! } ! } if (graph.method().isBridge()) { BridgeMethodUtils.getBridgedMethod(graph.method()); } }
< prev index next >