# HG changeset patch # User Doug Simon # Date 1386937301 -3600 # Node ID 4c3e527bf8574eec6efb482716ba511e3be1ae79 # Parent 6dd9a1455e648f25077df4ad79dfb489384881b8 added test for any optimization that commons loads of non-inlineable constants diff -r 6dd9a1455e64 -r 4c3e527bf857 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CommonedConstantsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CommonedConstantsTest.java Fri Dec 13 13:21:41 2013 +0100 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012, 2012, 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; + +import java.lang.reflect.*; + +import org.junit.*; + +import com.oracle.graal.api.meta.*; + +/** + * Tests any optimization that commons loads of non-inlineable constants. + */ +public class CommonedConstantsTest extends GraalCompilerTest { + + public static final String[] array = {"1", "2", null}; + + // A method where a constant is used on the normal and exception edge of a non-inlined call. + // The dominating block of both usages is the block containing the call. + public static Object testSnippet(String[] arr, int i) { + Object result = null; + try { + result = Array.get(arr, i); + } catch (ArrayIndexOutOfBoundsException e) { + result = array[0]; + } + if (result == null) { + result = array[2]; + } + return result; + } + + @Test + public void test0() { + // Ensure the exception path is profiled + ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(getMethod("testSnippet")); + javaMethod.reprofile(); + testSnippet(array, array.length); + + test("testSnippet", array, 0); + test("testSnippet", array, 2); + test("testSnippet", array, 3); + test("testSnippet", array, 1); + } +}