hotspot/test/compiler/codegen/7100757/Test7100757.java
author zmajo
Tue, 18 Nov 2014 19:44:45 +0100
changeset 27699 9913b19c0948
parent 27453 hotspot/test/compiler/7100757/Test7100757.java@9aeb9b97bef6
child 29678 dd2f3932c21e
permissions -rw-r--r--
8062854: move compiler jtreg test to corresponding subfolders and use those in TEST.groups Summary: move all test from <bug_id> directories to <functional_dir_name>/<bug_id>; update TEST.groups to execute more tests Reviewed-by: drchase, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10736
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     1
/*
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
10736
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     4
 *
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     8
 *
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    13
 * accompanied this code).
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    14
 *
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    18
 *
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    21
 * questions.
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    22
 *
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    23
 */
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    24
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    25
/**
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    26
 * @test
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    27
 * @bug 7100757
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    28
 * @summary The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
    29
 * @library /testlibrary
10736
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    30
 * @run main/timeout=300 Test7100757
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    31
 */
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    32
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
    33
import com.oracle.java.testlibrary.Utils;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
    34
import java.util.BitSet;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
    35
import java.util.Random;
10736
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    36
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    37
public class Test7100757 {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    38
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    39
  public static final int NBITS = 256;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    40
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    41
  public static void main(String[] args) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    42
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    43
    BitSet bs = new BitSet(NBITS);
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 10736
diff changeset
    44
    Random rnd = Utils.getRandomInstance();
10736
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    45
    long[] ra = new long[(NBITS+63)/64];
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    46
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    47
    for(int l=0; l < 5000000; l++) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    48
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    49
      for(int r = 0; r < ra.length; r++) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    50
        ra[r] = rnd.nextLong();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    51
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    52
      test(ra, bs);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    53
    }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    54
  }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    55
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    56
  static void test(long[] ra, BitSet bs) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    57
      bs.clear();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    58
      int bits_set = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    59
      for(int i = 0, t = 0, b = 0; i < NBITS; i++) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    60
        long bit = 1L << b++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    61
        if((ra[t]&bit) != 0) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    62
          bs.set(i);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    63
          bits_set++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    64
        }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    65
        if(b == 64) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    66
          t++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    67
          b = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    68
        }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    69
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    70
      // Test Long.bitCount()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    71
      int check_bits = bs.cardinality();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    72
      if (check_bits != bits_set) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    73
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    74
        System.err.printf("cardinality bits: %d != %d  bs: %s\n", check_bits, bits_set, bs_str);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    75
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    76
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    77
      // Test Long.numberOfTrailingZeros()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    78
      check_bits = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    79
      for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    80
        check_bits++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    81
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    82
      if (check_bits != bits_set) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    83
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    84
        System.err.printf("nextSetBit bits: %d != %d  bs: %s\n", check_bits, bits_set, bs_str);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    85
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    86
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    87
      // Test Long.numberOfLeadingZeros()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    88
      for(int i = bs.length(); i > 0; i = bs.length()) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    89
        bs.clear(i-1);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    90
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    91
      // Test Long.bitCount()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    92
      check_bits = bs.cardinality();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    93
      if (check_bits != 0) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    94
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    95
        System.err.printf("after clear bits: %d != 0  bs: %s\n", check_bits, bs_str);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    96
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    97
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    98
  }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    99
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
   100
};