# HG changeset patch # User Andreas Woess # Date 1390942130 -3600 # Node ID 9f730a04ba38d1ae9627f84c3342fd8e49845be1 # Parent a98d5959a81313b89841561c62c1022e5abf0f64 add partial evaluation test for a ControlFlowException catch block that follows a SlowPathException catch block diff -r a98d5959a813 -r 9f730a04ba38 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ControlFlowExceptionPartialEvaluationTest.java Tue Jan 28 21:48:50 2014 +0100 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2014, 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test; + +import org.junit.*; + +import com.oracle.graal.truffle.test.nodes.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; + +@Ignore("Currently ignored due to problems with code coverage tools.") +public class ControlFlowExceptionPartialEvaluationTest extends PartialEvaluationTest { + + public static Object constant42() { + return 42; + } + + @Test + public void catchControlFlowException() { + FrameDescriptor fd = new FrameDescriptor(); + AbstractTestNode result = new CatchControlFlowExceptionTestNode(new ThrowControlFlowExceptionTestNode()); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "catchControlFlowException", result)); + } + + @Test + public void catchSlowPathAndControlFlowException() { + FrameDescriptor fd = new FrameDescriptor(); + AbstractTestNode result = new CatchSlowPathAndControlFlowExceptionTestNode(new ThrowControlFlowExceptionTestNode()); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "catchSlowPathAndControlFlowException", result)); + } + + public static class ThrowControlFlowExceptionTestNode extends AbstractTestNode { + + @Override + public int execute(VirtualFrame frame) { + throw new ControlFlowException(); + } + } + + public static class CatchControlFlowExceptionTestNode extends AbstractTestNode { + + @Child private AbstractTestNode child; + + public CatchControlFlowExceptionTestNode(AbstractTestNode child) { + this.child = adoptChild(child); + } + + @Override + public int execute(VirtualFrame frame) { + try { + return child.execute(frame); + } catch (ControlFlowException e) { + return 42; + } + } + } + + public static class CatchSlowPathAndControlFlowExceptionTestNode extends AbstractTestNode { + + @Child private AbstractTestNode child; + + public CatchSlowPathAndControlFlowExceptionTestNode(AbstractTestNode child) { + this.child = adoptChild(child); + } + + @Override + public int execute(VirtualFrame frame) { + try { + return executeChild(frame); + } catch (SlowPathException spe) { + return -1; + } catch (ControlFlowException e) { + return 42; + } + } + + @SuppressWarnings("unused") + private int executeChild(VirtualFrame frame) throws SlowPathException { + return child.execute(frame); + } + } +}