< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java

Print this page

        

*** 84,93 **** --- 84,133 ---- } assertTrue(code.isValid()); } } + public void testIntegerExactOverflowWithoutUse1(int input) { + Math.addExact(intCounter, input); + } + + public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) { + if (cond) { + Math.addExact(intCounter, input); + } else { + intCounter = Math.addExact(intCounter, input); + } + } + + @Test + public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException { + ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1"); + InstalledCode code = getCode(method); + + boolean gotException = false; + try { + code.executeVarargs(this, Integer.MAX_VALUE); + } catch (ArithmeticException e) { + gotException = true; + } + assertTrue(gotException); + } + + @Test + public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException { + ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2"); + InstalledCode code = getCode(method); + + boolean gotException = false; + try { + code.executeVarargs(this, Integer.MAX_VALUE, true); + } catch (ArithmeticException e) { + gotException = true; + } + assertTrue(gotException); + } + static long longCounter = 10; public void testLongExactOverflowSnippet(long input) { try { longCounter = Math.addExact(longCounter, input);
*** 136,141 **** --- 176,221 ---- // An ArithmeticException is expected to be thrown. } assertTrue(code.isValid()); } } + + public void testLongExactOverflowWithoutUse1(long input) { + Math.addExact(longCounter, input); + } + + public void testLongExactOverflowWithoutUse2(long input, boolean cond) { + if (cond) { + Math.addExact(longCounter, input); + } else { + longCounter = Math.addExact(longCounter, input); + } + } + + @Test + public void testLongExactWithoutUse1() throws InvalidInstalledCodeException { + ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse1"); + InstalledCode code = getCode(method); + + boolean gotException = false; + try { + code.executeVarargs(this, Long.MAX_VALUE); + } catch (ArithmeticException e) { + gotException = true; + } + assertTrue(gotException); + } + + @Test + public void testLongExactWithoutUse2() throws InvalidInstalledCodeException { + ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse2"); + InstalledCode code = getCode(method); + + boolean gotException = false; + try { + code.executeVarargs(this, Long.MAX_VALUE, true); + } catch (ArithmeticException e) { + gotException = true; + } + assertTrue(gotException); + } }
< prev index next >