8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 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.hotspot.test; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.core.test.GraalCompilerTest; 28 import org.graalvm.compiler.nodes.extended.ForeignCallNode; 29 30 import jdk.vm.ci.code.InstalledCode; 31 import jdk.vm.ci.meta.ResolvedJavaMethod; 32 33 public class ExplicitExceptionTest extends GraalCompilerTest { 34 35 private int expectedForeignCallCount; 36 37 @Override 38 protected InstalledCode getCode(ResolvedJavaMethod method) { 39 InstalledCode installedCode = super.getCode(method); 40 assertDeepEquals(expectedForeignCallCount, lastCompiledGraph.getNodes().filter(ForeignCallNode.class).count()); 41 return installedCode; 42 } 43 44 public static int testAIOOBESnippet(int[] array) { 45 return array[10]; 46 } 47 48 @Test 49 public void testAIOOBE() { 50 int[] array = new int[4]; 51 for (int i = 0; i < 10000; i++) { 52 try { 53 testAIOOBESnippet(array); 54 } catch (ArrayIndexOutOfBoundsException e) { 55 // nothing to do 56 } 57 } 58 expectedForeignCallCount = 2; 59 test("testAIOOBESnippet", array); | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 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.hotspot.test; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.core.test.GraalCompilerTest; 28 import org.graalvm.compiler.nodes.StructuredGraph; 29 import org.graalvm.compiler.nodes.extended.ForeignCallNode; 30 import org.graalvm.compiler.options.OptionValues; 31 32 import jdk.vm.ci.code.InstalledCode; 33 import jdk.vm.ci.meta.ResolvedJavaMethod; 34 35 public class ExplicitExceptionTest extends GraalCompilerTest { 36 37 private int expectedForeignCallCount; 38 39 @Override 40 protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) { 41 InstalledCode installedCode = super.getCode(method, graph, forceCompile, installAsDefault, options); 42 assertDeepEquals(expectedForeignCallCount, lastCompiledGraph.getNodes().filter(ForeignCallNode.class).count()); 43 return installedCode; 44 } 45 46 public static int testAIOOBESnippet(int[] array) { 47 return array[10]; 48 } 49 50 @Test 51 public void testAIOOBE() { 52 int[] array = new int[4]; 53 for (int i = 0; i < 10000; i++) { 54 try { 55 testAIOOBESnippet(array); 56 } catch (ArrayIndexOutOfBoundsException e) { 57 // nothing to do 58 } 59 } 60 expectedForeignCallCount = 2; 61 test("testAIOOBESnippet", array); |