src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java
author dlong
Tue, 24 Sep 2019 12:47:15 -0400
changeset 58299 6df94ce3ab2f
parent 53495 b693b0d2053d
permissions -rw-r--r--
8229201: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51436
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 53495
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
51436
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     4
 *
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     8
 *
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    13
 * accompanied this code).
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    14
 *
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    18
 *
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    21
 * questions.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    22
 */
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    23
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    24
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    25
package org.graalvm.compiler.replacements.test;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    26
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    27
import org.graalvm.compiler.core.test.GraalCompilerTest;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    28
import org.junit.Test;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    29
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    30
import jdk.vm.ci.code.InstalledCode;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    31
import jdk.vm.ci.code.InvalidInstalledCodeException;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    32
import jdk.vm.ci.meta.ResolvedJavaMethod;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    33
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    34
public class IntegerExactExceptionTest extends GraalCompilerTest {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    35
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    36
    static int intCounter = 32;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    37
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    38
    public void testIntegerExactOverflowSnippet(int input) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    39
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    40
            intCounter = Math.addExact(intCounter, input);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    41
        } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    42
            intCounter = intCounter / 2;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    43
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    44
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    45
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    46
    @Test
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    47
    public void testIntegerExact() throws InvalidInstalledCodeException {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    48
        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowSnippet");
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    49
        InstalledCode code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    50
        code.executeVarargs(this, Integer.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    51
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    52
        if (!code.isValid()) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    53
            code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    54
            code.executeVarargs(this, Integer.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    55
            assertTrue(code.isValid());
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    56
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    57
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    58
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    59
    public void testIntegerExactOverflowWithoutHandlerSnippetW(int input) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    60
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    61
            intCounter = Math.addExact(intCounter, input);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    62
        } finally {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    63
            intCounter = intCounter / 2;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    64
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    65
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    66
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    67
    @Test
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    68
    public void testIntegerExactWithoutHandler() throws InvalidInstalledCodeException {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    69
        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutHandlerSnippetW");
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    70
        InstalledCode code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    71
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    72
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    73
            code.executeVarargs(this, Integer.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    74
        } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    75
            // An ArithmeticException is expected to be thrown.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    76
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    77
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    78
        if (!code.isValid()) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    79
            code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    80
            try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    81
                code.executeVarargs(this, Integer.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    82
            } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    83
                // An ArithmeticException is expected to be thrown.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    84
            }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    85
            assertTrue(code.isValid());
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    86
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    87
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
    88
53309
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    89
    public void testIntegerExactOverflowWithoutUse1(int input) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    90
        Math.addExact(intCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    91
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    92
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    93
    public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    94
        if (cond) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    95
            Math.addExact(intCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    96
        } else {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    97
            intCounter = Math.addExact(intCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    98
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
    99
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   100
53495
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   101
    public void testIntegerExactOverflowWithoutUse3() {
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   102
        Math.addExact(Integer.MAX_VALUE, 1);
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   103
    }
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   104
53309
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   105
    @Test
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   106
    public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   107
        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1");
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   108
        InstalledCode code = getCode(method);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   109
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   110
        boolean gotException = false;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   111
        try {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   112
            code.executeVarargs(this, Integer.MAX_VALUE);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   113
        } catch (ArithmeticException e) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   114
            gotException = true;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   115
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   116
        assertTrue(gotException);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   117
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   118
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   119
    @Test
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   120
    public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   121
        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2");
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   122
        InstalledCode code = getCode(method);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   123
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   124
        boolean gotException = false;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   125
        try {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   126
            code.executeVarargs(this, Integer.MAX_VALUE, true);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   127
        } catch (ArithmeticException e) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   128
            gotException = true;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   129
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   130
        assertTrue(gotException);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   131
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   132
53495
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   133
    @Test
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   134
    public void testIntegerExactWithoutUse3() throws InvalidInstalledCodeException {
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   135
        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse3");
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   136
        InstalledCode code = getCode(method);
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   137
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   138
        boolean gotException = false;
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   139
        try {
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   140
            code.executeVarargs(this);
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   141
        } catch (ArithmeticException e) {
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   142
            gotException = true;
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   143
        }
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   144
        assertTrue(gotException);
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   145
    }
b693b0d2053d 8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
iveresov
parents: 53309
diff changeset
   146
51436
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   147
    static long longCounter = 10;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   148
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   149
    public void testLongExactOverflowSnippet(long input) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   150
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   151
            longCounter = Math.addExact(longCounter, input);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   152
        } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   153
            longCounter = longCounter / 2;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   154
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   155
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   156
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   157
    @Test
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   158
    public void testLongExact() throws InvalidInstalledCodeException {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   159
        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowSnippet");
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   160
        InstalledCode code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   161
        code.executeVarargs(this, Long.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   162
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   163
        if (!code.isValid()) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   164
            code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   165
            code.executeVarargs(this, Long.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   166
            assertTrue(code.isValid());
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   167
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   168
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   169
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   170
    public void testLongExactWithoutHandlerSnippet(long input) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   171
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   172
            longCounter = Math.addExact(longCounter, input);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   173
        } finally {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   174
            longCounter = longCounter / 2;
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   175
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   176
    }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   177
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   178
    @Test
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   179
    public void testLongExactWithoutHandler() throws InvalidInstalledCodeException {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   180
        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactWithoutHandlerSnippet");
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   181
        InstalledCode code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   182
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   183
        try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   184
            code.executeVarargs(this, Long.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   185
        } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   186
            // An ArithmeticException is expected to be thrown.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   187
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   188
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   189
        if (!code.isValid()) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   190
            code = getCode(method);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   191
            try {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   192
                code.executeVarargs(this, Long.MAX_VALUE);
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   193
            } catch (ArithmeticException e) {
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   194
                // An ArithmeticException is expected to be thrown.
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   195
            }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   196
            assertTrue(code.isValid());
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   197
        }
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   198
    }
53309
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   199
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   200
    public void testLongExactOverflowWithoutUse1(long input) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   201
        Math.addExact(longCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   202
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   203
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   204
    public void testLongExactOverflowWithoutUse2(long input, boolean cond) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   205
        if (cond) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   206
            Math.addExact(longCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   207
        } else {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   208
            longCounter = Math.addExact(longCounter, input);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   209
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   210
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   211
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   212
    @Test
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   213
    public void testLongExactWithoutUse1() throws InvalidInstalledCodeException {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   214
        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse1");
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   215
        InstalledCode code = getCode(method);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   216
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   217
        boolean gotException = false;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   218
        try {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   219
            code.executeVarargs(this, Long.MAX_VALUE);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   220
        } catch (ArithmeticException e) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   221
            gotException = true;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   222
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   223
        assertTrue(gotException);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   224
    }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   225
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   226
    @Test
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   227
    public void testLongExactWithoutUse2() throws InvalidInstalledCodeException {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   228
        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse2");
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   229
        InstalledCode code = getCode(method);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   230
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   231
        boolean gotException = false;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   232
        try {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   233
            code.executeVarargs(this, Long.MAX_VALUE, true);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   234
        } catch (ArithmeticException e) {
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   235
            gotException = true;
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   236
        }
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   237
        assertTrue(gotException);
314c5b5d9369 8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
iveresov
parents: 51436
diff changeset
   238
    }
51436
091c0d22e735 8206992: Update Graal
iveresov
parents:
diff changeset
   239
}