2839N/A/*
2839N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2839N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2839N/A *
2839N/A * This code is free software; you can redistribute it and/or modify it
2839N/A * under the terms of the GNU General Public License version 2 only, as
2839N/A * published by the Free Software Foundation.
2839N/A *
2839N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2839N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2839N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2839N/A * version 2 for more details (a copy is included in the LICENSE file that
2839N/A * accompanied this code).
2839N/A *
2839N/A * You should have received a copy of the GNU General Public License version
2839N/A * 2 along with this work; if not, write to the Free Software Foundation,
2839N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2839N/A *
2839N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2839N/A * or visit www.oracle.com if you need additional information or have any
2839N/A * questions.
2839N/A *
2839N/A */
2839N/A
2839N/A/**
2839N/A * @test
2839N/A * @bug 7100757
2839N/A * @summary The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc
2839N/A *
2839N/A * @run main/timeout=300 Test7100757
2839N/A */
2839N/A
2839N/Aimport java.util.*;
2839N/A
2839N/Apublic class Test7100757 {
2839N/A
2839N/A public static final int NBITS = 256;
2839N/A
2839N/A public static void main(String[] args) {
2839N/A
2839N/A BitSet bs = new BitSet(NBITS);
2839N/A Random rnd = new Random();
2839N/A long[] ra = new long[(NBITS+63)/64];
2839N/A
2839N/A for(int l=0; l < 5000000; l++) {
2839N/A
2839N/A for(int r = 0; r < ra.length; r++) {
2839N/A ra[r] = rnd.nextLong();
2839N/A }
2839N/A test(ra, bs);
2839N/A }
2839N/A }
2839N/A
2839N/A static void test(long[] ra, BitSet bs) {
2839N/A bs.clear();
2839N/A int bits_set = 0;
2839N/A for(int i = 0, t = 0, b = 0; i < NBITS; i++) {
2839N/A long bit = 1L << b++;
2839N/A if((ra[t]&bit) != 0) {
2839N/A bs.set(i);
2839N/A bits_set++;
2839N/A }
2839N/A if(b == 64) {
2839N/A t++;
2839N/A b = 0;
2839N/A }
2839N/A }
2839N/A // Test Long.bitCount()
2839N/A int check_bits = bs.cardinality();
2839N/A if (check_bits != bits_set) {
2839N/A String bs_str = bs.toString();
2839N/A System.err.printf("cardinality bits: %d != %d bs: %s\n", check_bits, bits_set, bs_str);
2839N/A System.exit(97);
2839N/A }
2839N/A // Test Long.numberOfTrailingZeros()
2839N/A check_bits = 0;
2839N/A for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
2839N/A check_bits++;
2839N/A }
2839N/A if (check_bits != bits_set) {
2839N/A String bs_str = bs.toString();
2839N/A System.err.printf("nextSetBit bits: %d != %d bs: %s\n", check_bits, bits_set, bs_str);
2839N/A System.exit(97);
2839N/A }
2839N/A // Test Long.numberOfLeadingZeros()
2839N/A for(int i = bs.length(); i > 0; i = bs.length()) {
2839N/A bs.clear(i-1);
2839N/A }
2839N/A // Test Long.bitCount()
2839N/A check_bits = bs.cardinality();
2839N/A if (check_bits != 0) {
2839N/A String bs_str = bs.toString();
2839N/A System.err.printf("after clear bits: %d != 0 bs: %s\n", check_bits, bs_str);
2839N/A System.exit(97);
2839N/A }
2839N/A }
2839N/A
2839N/A};