hotspot/test/compiler/7100757/Test7100757.java
author jjg
Fri, 07 Nov 2014 14:51:35 -0800
changeset 27547 d07b3dcbc707
parent 10736 1a11ec86574e
child 27453 9aeb9b97bef6
permissions -rw-r--r--
8063145: ToolBox should support extracting classes from a JavaFileManager/Location Reviewed-by: ksrini
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
/*
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    29
 *
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
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    33
import java.util.*;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    34
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    35
public class Test7100757 {
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 static final int NBITS = 256;
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 void main(String[] args) {
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
    BitSet bs = new BitSet(NBITS);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    42
    Random rnd = new Random();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    43
    long[] ra = new long[(NBITS+63)/64];
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    44
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    45
    for(int l=0; l < 5000000; l++) {
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 r = 0; r < ra.length; r++) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    48
        ra[r] = rnd.nextLong();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    49
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    50
      test(ra, bs);
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
  }
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
  static void test(long[] ra, BitSet bs) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    55
      bs.clear();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    56
      int bits_set = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    57
      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
    58
        long bit = 1L << b++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    59
        if((ra[t]&bit) != 0) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    60
          bs.set(i);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    61
          bits_set++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    62
        }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    63
        if(b == 64) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    64
          t++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    65
          b = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    66
        }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    67
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    68
      // Test Long.bitCount()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    69
      int check_bits = bs.cardinality();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    70
      if (check_bits != bits_set) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    71
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    72
        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
    73
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    74
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    75
      // Test Long.numberOfTrailingZeros()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    76
      check_bits = 0;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    77
      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
    78
        check_bits++;
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    79
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    80
      if (check_bits != bits_set) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    81
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    82
        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
    83
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    84
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    85
      // Test Long.numberOfLeadingZeros()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    86
      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
    87
        bs.clear(i-1);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    88
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    89
      // Test Long.bitCount()
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    90
      check_bits = bs.cardinality();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    91
      if (check_bits != 0) {
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    92
        String bs_str = bs.toString();
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    93
        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
    94
        System.exit(97);
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    95
      }
1a11ec86574e 7100757: The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
kvn
parents:
diff changeset
    96
  }
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
};