81 code.executeVarargs(this, Integer.MAX_VALUE); 82 } catch (ArithmeticException e) { 83 // An ArithmeticException is expected to be thrown. 84 } 85 assertTrue(code.isValid()); 86 } 87 } 88 89 public void testIntegerExactOverflowWithoutUse1(int input) { 90 Math.addExact(intCounter, input); 91 } 92 93 public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) { 94 if (cond) { 95 Math.addExact(intCounter, input); 96 } else { 97 intCounter = Math.addExact(intCounter, input); 98 } 99 } 100 101 @Test 102 public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException { 103 ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1"); 104 InstalledCode code = getCode(method); 105 106 boolean gotException = false; 107 try { 108 code.executeVarargs(this, Integer.MAX_VALUE); 109 } catch (ArithmeticException e) { 110 gotException = true; 111 } 112 assertTrue(gotException); 113 } 114 115 @Test 116 public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException { 117 ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2"); 118 InstalledCode code = getCode(method); 119 120 boolean gotException = false; 121 try { 122 code.executeVarargs(this, Integer.MAX_VALUE, true); 123 } catch (ArithmeticException e) { 124 gotException = true; 125 } 126 assertTrue(gotException); 127 } 128 129 static long longCounter = 10; 130 131 public void testLongExactOverflowSnippet(long input) { 132 try { 133 longCounter = Math.addExact(longCounter, input); 134 } catch (ArithmeticException e) { 135 longCounter = longCounter / 2; 136 } 137 } 138 139 @Test 140 public void testLongExact() throws InvalidInstalledCodeException { 141 ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowSnippet"); 142 InstalledCode code = getCode(method); 143 code.executeVarargs(this, Long.MAX_VALUE); 144 145 if (!code.isValid()) { 146 code = getCode(method); 147 code.executeVarargs(this, Long.MAX_VALUE); 148 assertTrue(code.isValid()); | 81 code.executeVarargs(this, Integer.MAX_VALUE); 82 } catch (ArithmeticException e) { 83 // An ArithmeticException is expected to be thrown. 84 } 85 assertTrue(code.isValid()); 86 } 87 } 88 89 public void testIntegerExactOverflowWithoutUse1(int input) { 90 Math.addExact(intCounter, input); 91 } 92 93 public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) { 94 if (cond) { 95 Math.addExact(intCounter, input); 96 } else { 97 intCounter = Math.addExact(intCounter, input); 98 } 99 } 100 101 public void testIntegerExactOverflowWithoutUse3() { 102 Math.addExact(Integer.MAX_VALUE, 1); 103 } 104 105 @Test 106 public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException { 107 ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1"); 108 InstalledCode code = getCode(method); 109 110 boolean gotException = false; 111 try { 112 code.executeVarargs(this, Integer.MAX_VALUE); 113 } catch (ArithmeticException e) { 114 gotException = true; 115 } 116 assertTrue(gotException); 117 } 118 119 @Test 120 public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException { 121 ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2"); 122 InstalledCode code = getCode(method); 123 124 boolean gotException = false; 125 try { 126 code.executeVarargs(this, Integer.MAX_VALUE, true); 127 } catch (ArithmeticException e) { 128 gotException = true; 129 } 130 assertTrue(gotException); 131 } 132 133 @Test 134 public void testIntegerExactWithoutUse3() throws InvalidInstalledCodeException { 135 ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse3"); 136 InstalledCode code = getCode(method); 137 138 boolean gotException = false; 139 try { 140 code.executeVarargs(this); 141 } catch (ArithmeticException e) { 142 gotException = true; 143 } 144 assertTrue(gotException); 145 } 146 147 static long longCounter = 10; 148 149 public void testLongExactOverflowSnippet(long input) { 150 try { 151 longCounter = Math.addExact(longCounter, input); 152 } catch (ArithmeticException e) { 153 longCounter = longCounter / 2; 154 } 155 } 156 157 @Test 158 public void testLongExact() throws InvalidInstalledCodeException { 159 ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowSnippet"); 160 InstalledCode code = getCode(method); 161 code.executeVarargs(this, Long.MAX_VALUE); 162 163 if (!code.isValid()) { 164 code = getCode(method); 165 code.executeVarargs(this, Long.MAX_VALUE); 166 assertTrue(code.isValid()); |