test/hotspot/jtreg/compiler/c2/Test6603011.java
author jiangli
Fri, 02 Nov 2018 19:30:31 -0400
changeset 52397 1322829d1501
parent 49486 a3f1db30ab85
permissions -rw-r--r--
8209564: runtime/appcds/CDSandJFR.java timeout on tier6 on sparc Summary: Set timeout 500 in CDSandJFR.java Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     4
 *
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     8
 *
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    13
 * accompanied this code).
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    14
 *
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2031
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2031
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2031
diff changeset
    21
 * questions.
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    22
 */
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    23
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    24
/**
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    25
 * @test
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    26
 * @bug 6603011
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    27
 * @summary long/int division by constant
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 33187
diff changeset
    28
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    29
 * @library /test/lib
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    30
 *
49486
a3f1db30ab85 8199212: [TESTBUG] don't run compiler/aot tests with -Xcomp
kvn
parents: 47216
diff changeset
    31
 * @run main/othervm/timeout=480 -Xcomp -Xbatch -XX:-Inline compiler.c2.Test6603011
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    32
 */
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    33
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    34
//
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    35
// -XX:-Inline is essential to this test so that verification functions
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    36
//   divi, modi, divl and modl generate "plain" divides.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    37
// -Xcomp -Xbatch are also useful to ensure the full range of
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    38
//   dividend and divisor combinations are tested
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    39
//
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    40
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    41
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    42
33187
384728911193 8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests
kshefov
parents: 27699
diff changeset
    43
import jdk.test.lib.Utils;
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    44
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    45
public class Test6603011 implements Runnable {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    46
  static class s {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    47
    static int  divi(int  dividend, int  divisor) { return dividend / divisor; }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    48
    static int  modi(int  dividend, int  divisor) { return dividend % divisor; }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    49
    static long divl(long dividend, long divisor) { return dividend / divisor; }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    50
    static long modl(long dividend, long divisor) { return dividend % divisor; }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    51
  }
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    52
  // Report verbose messages on failure; turn off to suppress
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    53
  // too much output with gross numbers of failures.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    54
  static final boolean VERBOSE = true;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    55
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    56
  // Initailize DIVISOR so that it is final in this class.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    57
  static final int DIVISOR;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    58
  static {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    59
    int value = 0;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    60
    try {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    61
      value = Integer.decode(System.getProperty("divisor"));
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    62
    } catch (Throwable e) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    63
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    64
    DIVISOR = value;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    65
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    66
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    67
  // The methods of interest. We want the JIT to compile these
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    68
  // and convert the divide into a multiply.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    69
  public int divbyI (int dividend)   { return dividend / DIVISOR; }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    70
  public int modbyI (int dividend)   { return dividend % DIVISOR; }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    71
  public long divbyL (long dividend) { return dividend / DIVISOR; }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    72
  public long modbyL (long dividend) { return dividend % DIVISOR; }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    73
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    74
  public int divisor() { return DIVISOR; }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    75
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    76
  public boolean checkI (int dividend) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    77
    int quo = divbyI(dividend);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    78
    int rem = modbyI(dividend);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    79
    int quo0 = s.divi(dividend, divisor());
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    80
    int rem0 = s.modi(dividend, divisor());
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    81
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    82
    if (quo != quo0 || rem != rem0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    83
      if (VERBOSE) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    84
        System.out.println("Computed: " + dividend + " / " + divisor() + " = " +
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    85
                           quo  + ", " + dividend + " % " + divisor() + " = " + rem );
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    86
        System.out.println("expected: " + dividend + " / " + divisor() + " = " +
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    87
                           quo0 + ", " + dividend + " % " + divisor() + " = " + rem0);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    88
        // Report sign of rem failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    89
        if (rem != 0 && (rem ^ dividend) < 0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    90
          System.out.println("  rem & dividend have different signs");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    91
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    92
        // Report range of rem failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    93
        if (java.lang.Math.abs(rem) >= java.lang.Math.abs(divisor())) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    94
          System.out.println("  remainder out of range");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    95
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    96
        // Report quo/rem identity relationship failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    97
        if ((quo * divisor()) + rem != dividend) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    98
          System.out.println("  quotien/remainder invariant broken");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
    99
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   100
      }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   101
      return false;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   102
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   103
    return true;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   104
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   105
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   106
  public boolean checkL (long dividend) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   107
    long quo = divbyL(dividend);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   108
    long rem = modbyL(dividend);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   109
    long quo0 = s.divl(dividend, divisor());
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   110
    long rem0 = s.modl(dividend, divisor());
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   111
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   112
    if (quo != quo0 || rem != rem0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   113
      if (VERBOSE) {
7121
69928525c55c 6997311: SIGFPE in new long division asm code
kvn
parents: 5547
diff changeset
   114
        System.out.println("Computed: " + dividend + " / " + divisor() + " = " +
69928525c55c 6997311: SIGFPE in new long division asm code
kvn
parents: 5547
diff changeset
   115
                           quo  + ", " + dividend + " % " + divisor() + " = " + rem );
69928525c55c 6997311: SIGFPE in new long division asm code
kvn
parents: 5547
diff changeset
   116
        System.out.println("expected: " + dividend + " / " + divisor() + " = " +
69928525c55c 6997311: SIGFPE in new long division asm code
kvn
parents: 5547
diff changeset
   117
                           quo0 + ", " + dividend + " % " + divisor() + " = " + rem0);
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   118
        // Report sign of rem failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   119
        if (rem != 0 && (rem ^ dividend) < 0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   120
          System.out.println("  rem & dividend have different signs");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   121
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   122
        // Report range of rem failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   123
        if (java.lang.Math.abs(rem) >= java.lang.Math.abs(divisor())) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   124
          System.out.println("  remainder out of range");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   125
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   126
        // Report quo/rem identity relationship failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   127
        if ((quo * divisor()) + rem != dividend) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   128
          System.out.println(" (" + quo + " * " + divisor() + ") + " + rem + " != "
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   129
                             + dividend);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   130
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   131
      }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   132
      return false;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   133
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   134
    return true;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   135
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   136
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   137
  public void run() {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   138
    // Don't try to divide by zero
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   139
    if (divisor() == 0) return;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   140
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   141
    // Range of dividends to check. Try dividends from start to end
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   142
    // inclusive, as well as variations on those values as shifted
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   143
    // left.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   144
    int start = -1024;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   145
    int end = 1024;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   146
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   147
    // Test int division using a variety of dividends.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   148
    int wrong = 0;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   149
    int total = 0;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   150
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   151
    outerloop:
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   152
    for (int i = start; i <= end; i++) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   153
      for (int s = 0; s < 32; s += 4) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   154
        total++;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   155
        int dividend = i << s;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   156
        if (!checkI(dividend)) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   157
          wrong++;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   158
          // Stop on the first failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   159
          // break outerloop;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   160
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   161
      }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   162
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   163
    if (wrong > 0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   164
      System.out.println("divisor " + divisor() + ": " +
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   165
                         wrong + "/" + total + " wrong int divisions");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   166
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   167
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   168
    // Test long division using a variety of dividends.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   169
    wrong = 0;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   170
    total = 0;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   171
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   172
    outerloop:
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   173
    for (int i = start; i <= end; i++) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   174
      for (int s = 0; s < 64; s += 4) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   175
        total++;
7121
69928525c55c 6997311: SIGFPE in new long division asm code
kvn
parents: 5547
diff changeset
   176
        long dividend = ((long)i) << s;
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   177
        if (!checkL(dividend)) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   178
          wrong++;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   179
          // Stop on the first failure
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   180
          // break outerloop;
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   181
        }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   182
      }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   183
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   184
    if (wrong > 0) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   185
      System.out.println("divisor " + divisor() + ": " +
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   186
                         wrong + "/" + total + " wrong long divisions");
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   187
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   188
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   189
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   190
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   191
  // Reload this class with the "divisor" property set to the input parameter.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   192
  // This allows the JIT to see q.DIVISOR as a final constant, and change
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   193
  // any divisions or mod operations into multiplies.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   194
  public static void test_divisor(int divisor,
33187
384728911193 8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests
kshefov
parents: 27699
diff changeset
   195
                                  ClassLoader apploader) throws Exception {
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   196
    System.setProperty("divisor", "" + divisor);
33187
384728911193 8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests
kshefov
parents: 27699
diff changeset
   197
    ClassLoader loader
384728911193 8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests
kshefov
parents: 27699
diff changeset
   198
                = Utils.getTestClassPathURLClassLoader(apploader.getParent());
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
   199
    Class c = loader.loadClass(Test6603011.class.getName());
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   200
    Runnable r = (Runnable)c.newInstance();
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   201
    r.run();
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   202
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   203
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   204
  public static void main(String[] args) throws Exception {
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
   205
    Class cl = Test6603011.class;
33187
384728911193 8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests
kshefov
parents: 27699
diff changeset
   206
    ClassLoader apploader = cl.getClassLoader();
2031
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   207
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   208
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   209
    // Test every divisor between -100 and 100.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   210
    for (int i = -100; i <= 100; i++) {
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   211
      test_divisor(i, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   212
    }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   213
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   214
    // Try a few divisors outside the typical range.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   215
    // The values below have been observed in rt.jar.
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   216
    test_divisor(101, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   217
    test_divisor(400, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   218
    test_divisor(1000, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   219
    test_divisor(3600, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   220
    test_divisor(9973, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   221
    test_divisor(86400, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   222
    test_divisor(1000000, apploader);
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   223
  }
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   224
24e034f56dcb 6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff changeset
   225
}