10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.test; 24 25 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions; 26 27 import java.lang.reflect.Method; 28 import java.lang.reflect.Modifier; 29 30 import org.junit.Test; 31 32 import org.graalvm.compiler.api.test.Graal; 33 import org.graalvm.compiler.core.common.PermanentBailoutException; 34 import org.graalvm.compiler.core.common.RetryableBailoutException; 35 import org.graalvm.compiler.debug.Debug; 36 import org.graalvm.compiler.debug.DebugConfigScope; 37 import org.graalvm.compiler.debug.GraalError; 38 import org.graalvm.compiler.java.GraphBuilderPhase; 39 import org.graalvm.compiler.nodes.StructuredGraph; 40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 41 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; 42 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 43 import org.graalvm.compiler.phases.OptimisticOptimizations; 44 import org.graalvm.compiler.phases.Phase; 45 import org.graalvm.compiler.phases.PhaseSuite; 46 import org.graalvm.compiler.phases.VerifyPhase.VerificationError; 47 import org.graalvm.compiler.phases.tiers.HighTierContext; 48 import org.graalvm.compiler.phases.util.Providers; 49 import org.graalvm.compiler.phases.verify.VerifyBailoutUsage; 50 import org.graalvm.compiler.runtime.RuntimeProvider; 51 52 import jdk.vm.ci.code.BailoutException; 53 import jdk.vm.ci.meta.MetaAccessProvider; 54 import jdk.vm.ci.meta.ResolvedJavaMethod; 55 56 public class VerifyBailoutUsageTest { 57 58 private static class InvalidBailoutUsagePhase1 extends Phase { 59 @Override 60 protected void run(StructuredGraph graph) { 61 throw new BailoutException("Bailout in graph %s", graph); 62 } 63 } 64 65 private static class InvalidBailoutUsagePhase2 extends Phase { 66 @Override 67 protected void run(StructuredGraph graph) { 68 throw new BailoutException(new GraalError("other cause"), "Bailout in graph %s", graph); 69 } 70 } 108 @Test 109 public void testValidPermanentBailout() { 110 testBailoutUsage(ValidPermanentBailoutUsage.class); 111 } 112 113 @Test 114 public void testValidRetryableBailout() { 115 testBailoutUsage(ValidRetryableBailoutUsage.class); 116 } 117 118 @SuppressWarnings("try") 119 private static void testBailoutUsage(Class<?> c) { 120 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); 121 Providers providers = rt.getHostBackend().getProviders(); 122 MetaAccessProvider metaAccess = providers.getMetaAccess(); 123 PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>(); 124 Plugins plugins = new Plugins(new InvocationPlugins()); 125 GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true); 126 graphBuilderSuite.appendPhase(new GraphBuilderPhase(config)); 127 HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE); 128 for (Method m : c.getDeclaredMethods()) { 129 if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) { 130 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); 131 StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build(); 132 graphBuilderSuite.apply(graph, context); 133 try (DebugConfigScope s = Debug.disableIntercept()) { 134 new VerifyBailoutUsage().apply(graph, context); 135 } 136 } 137 } 138 } 139 } | 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.test; 24 25 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions; 26 27 import java.lang.reflect.Method; 28 import java.lang.reflect.Modifier; 29 30 import org.graalvm.compiler.api.test.Graal; 31 import org.graalvm.compiler.core.common.PermanentBailoutException; 32 import org.graalvm.compiler.core.common.RetryableBailoutException; 33 import org.graalvm.compiler.debug.DebugCloseable; 34 import org.graalvm.compiler.debug.DebugHandlersFactory; 35 import org.graalvm.compiler.debug.DebugContext; 36 import org.graalvm.compiler.debug.GraalError; 37 import org.graalvm.compiler.java.GraphBuilderPhase; 38 import org.graalvm.compiler.nodes.StructuredGraph; 39 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; 41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 42 import org.graalvm.compiler.options.OptionValues; 43 import org.graalvm.compiler.phases.OptimisticOptimizations; 44 import org.graalvm.compiler.phases.Phase; 45 import org.graalvm.compiler.phases.PhaseSuite; 46 import org.graalvm.compiler.phases.VerifyPhase.VerificationError; 47 import org.graalvm.compiler.phases.tiers.HighTierContext; 48 import org.graalvm.compiler.phases.util.Providers; 49 import org.graalvm.compiler.phases.verify.VerifyBailoutUsage; 50 import org.graalvm.compiler.runtime.RuntimeProvider; 51 import org.junit.Test; 52 53 import jdk.vm.ci.code.BailoutException; 54 import jdk.vm.ci.meta.MetaAccessProvider; 55 import jdk.vm.ci.meta.ResolvedJavaMethod; 56 57 public class VerifyBailoutUsageTest { 58 59 private static class InvalidBailoutUsagePhase1 extends Phase { 60 @Override 61 protected void run(StructuredGraph graph) { 62 throw new BailoutException("Bailout in graph %s", graph); 63 } 64 } 65 66 private static class InvalidBailoutUsagePhase2 extends Phase { 67 @Override 68 protected void run(StructuredGraph graph) { 69 throw new BailoutException(new GraalError("other cause"), "Bailout in graph %s", graph); 70 } 71 } 109 @Test 110 public void testValidPermanentBailout() { 111 testBailoutUsage(ValidPermanentBailoutUsage.class); 112 } 113 114 @Test 115 public void testValidRetryableBailout() { 116 testBailoutUsage(ValidRetryableBailoutUsage.class); 117 } 118 119 @SuppressWarnings("try") 120 private static void testBailoutUsage(Class<?> c) { 121 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); 122 Providers providers = rt.getHostBackend().getProviders(); 123 MetaAccessProvider metaAccess = providers.getMetaAccess(); 124 PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>(); 125 Plugins plugins = new Plugins(new InvocationPlugins()); 126 GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true); 127 graphBuilderSuite.appendPhase(new GraphBuilderPhase(config)); 128 HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE); 129 OptionValues options = getInitialOptions(); 130 DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER); 131 for (Method m : c.getDeclaredMethods()) { 132 if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) { 133 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m); 134 StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build(); 135 graphBuilderSuite.apply(graph, context); 136 try (DebugCloseable s = debug.disableIntercept()) { 137 new VerifyBailoutUsage().apply(graph, context); 138 } 139 } 140 } 141 } 142 } |