< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ExplicitExceptionTest.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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);




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   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.graalvm.compiler.core.test.GraalCompilerTest;
  26 import org.graalvm.compiler.nodes.StructuredGraph;
  27 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  28 import org.graalvm.compiler.options.OptionValues;
  29 import org.junit.Assume;
  30 import org.junit.Test;
  31 
  32 import jdk.vm.ci.code.InstalledCode;
  33 import jdk.vm.ci.meta.ProfilingInfo;
  34 import jdk.vm.ci.meta.ResolvedJavaMethod;
  35 import jdk.vm.ci.meta.TriState;
  36 
  37 public class ExplicitExceptionTest extends GraalCompilerTest {
  38 
  39     private int expectedForeignCallCount;
  40 
  41     /**
  42      * Determines if profiling info for {@code method} indicates an exception was thrown somewhere
  43      * in the method. In the case of the {@code -Xcomp} VM option, interpreter execution can be
  44      * skipped altogether and other execution engines (e.g., C1) may not record seen exceptions in a
  45      * method profile.
  46      */
  47     private static boolean exceptionWasSeen(ResolvedJavaMethod method) {
  48         ProfilingInfo profilingInfo = method.getProfilingInfo();
  49         if (profilingInfo != null) {
  50             for (int i = 0; i < profilingInfo.getCodeSize(); i++) {
  51                 if (profilingInfo.getExceptionSeen(i) == TriState.TRUE) {
  52                     return true;
  53                 }
  54             }
  55         }
  56         return false;
  57     }
  58 
  59     @Override
  60     protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
  61         InstalledCode installedCode = super.getCode(method, graph, forceCompile, installAsDefault, options);
  62         Assume.assumeTrue(exceptionWasSeen(method));
  63         assertDeepEquals(expectedForeignCallCount, lastCompiledGraph.getNodes().filter(ForeignCallNode.class).count());
  64         return installedCode;
  65     }
  66 
  67     public static int testAIOOBESnippet(int[] array) {
  68         return array[10];
  69     }
  70 
  71     @Test
  72     public void testAIOOBE() {
  73         int[] array = new int[4];
  74         for (int i = 0; i < 10000; i++) {
  75             try {
  76                 testAIOOBESnippet(array);
  77             } catch (ArrayIndexOutOfBoundsException e) {
  78                 // nothing to do
  79             }
  80         }
  81         expectedForeignCallCount = 2;
  82         test("testAIOOBESnippet", array);


< prev index next >