changeset 22961:09d0f549f05e

Add a pure graal version of the SafepointRethrowDeopt test
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 09 Nov 2015 17:09:52 +0100
parents 20e85d1dd9a5
children d710cf41f9a0
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/SafepointRethrowDeoptTest.java
diffstat 1 files changed, 115 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/SafepointRethrowDeoptTest.java	Mon Nov 09 17:09:52 2015 +0100
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015, 2015, 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.compiler.test.deopt;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+
+import com.oracle.graal.compiler.common.GraalOptions;
+import com.oracle.graal.compiler.test.GraalCompilerTest;
+
+import jdk.vm.ci.code.InstalledCode;
+
+public final class SafepointRethrowDeoptTest extends GraalCompilerTest {
+
+    private static final Object RETURN_VALUE = "1 2 3";
+    private static final RuntimeException BREAK_EX = new RuntimeException();
+    private static final RuntimeException CONTINUE_EX = new RuntimeException();
+    private static volatile int terminate;
+    private static volatile int entered;
+
+    public static Object execute() {
+        entered = 1;
+        for (;;) {
+            try {
+                if (terminate != 0) {
+                    throw BREAK_EX;
+                } else {
+                    throw CONTINUE_EX;
+                }
+            } catch (RuntimeException e) {
+                if (e == BREAK_EX) {
+                    break;
+                } else if (e == CONTINUE_EX) {
+                    continue;
+                }
+                throw e;
+            }
+        }
+        return RETURN_VALUE;
+    }
+
+    @Test
+    public void test() {
+        Assume.assumeTrue(GraalOptions.GenLoopSafepoints.getValue());
+        synchronized (SafepointRethrowDeoptTest.class) {
+            // needs static fields
+            terminate = 1;
+
+            InstalledCode installed = getCode(getResolvedJavaMethod("execute"));
+
+            terminate = 0;
+            entered = 0;
+            CountDownLatch cdl = new CountDownLatch(1);
+            Thread t1 = new Thread(() -> {
+                try {
+                    cdl.await();
+                    while (entered == 0) {
+                        /* spin */
+                    }
+                    installed.invalidate();
+                } catch (InterruptedException e) {
+                    Assert.fail("interrupted");
+                } finally {
+                    terminate = 1;
+                }
+            });
+            Thread t2 = new Thread(() -> {
+                cdl.countDown();
+                Object result;
+                try {
+                    result = installed.executeVarargs();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    Assert.fail("exception");
+                    return;
+                }
+                Assert.assertEquals(RETURN_VALUE, result);
+            });
+
+            t1.start();
+            t2.start();
+            try {
+                t1.join();
+                t2.join();
+            } catch (InterruptedException e) {
+                Assert.fail("interrupted");
+            }
+        }
+    }
+}