hotspot/test/compiler/c1/MultiplyByMaxInt.java
author thartmann
Fri, 14 Jul 2017 11:55:58 +0200
changeset 46663 715d5f268f62
parent 45632 e56cfcaea55c
permissions -rw-r--r--
8184271: Time related C1 intrinsics produce inconsistent results when floating around Summary: C1 intrinsics for System.nanoTime(), System.currentTimeMillis() and JVM.counterTime() should be pinned. Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45632
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     1
/*
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     4
 *
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     8
 *
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    14
 *
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    18
 *
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    21
 * questions.
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    22
 */
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    23
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    24
/*
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    25
 * @test
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    26
 * @bug 8181872
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    27
 *
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    28
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    29
 *                   -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=1
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    30
 *                   -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,compiler.c1.MultiplyByMaxInt::test
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    31
 *                   compiler.c1.MultiplyByMaxInt
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    32
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-BackgroundCompilation
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    33
 *                   -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=3
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    34
 *                   -XX:CompileCommand=dontinline,compiler.c1.MultiplyByMaxInt::test
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    35
 *                   compiler.c1.MultiplyByMaxInt
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    36
 */
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    37
package compiler.c1;
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    38
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    39
public class MultiplyByMaxInt {
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    40
    static int test(int x) {
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    41
        int loops = (x >>> 4) & 7;
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    42
        while (loops-- > 0) {
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    43
            x = (x * 2147483647) % 16807;
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    44
        }
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    45
        return x;
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    46
    }
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    47
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    48
    public static void main(String[] args) {
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    49
        for (int i = 0; i < 20000; i++) {
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    50
            test(i);
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    51
        }
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    52
    }
e56cfcaea55c 8181872: C1: possible overflow when strength reducing integer multiply by constant
vlivanov
parents:
diff changeset
    53
}