Path: blob/master/test/hotspot/jtreg/compiler/codegen/Test7100757.java
41149 views
/*1* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @key randomness26* @bug 710075727* @summary The BitSet.nextSetBit() produces incorrect result in 32bit VM on Sparc28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31*32* @run main/timeout=300 compiler.codegen.Test710075733*/3435package compiler.codegen;3637import jdk.test.lib.Utils;3839import java.util.BitSet;40import java.util.Random;4142public class Test7100757 {4344public static final int NBITS = 256;4546public static void main(String[] args) {4748BitSet bs = new BitSet(NBITS);49Random rnd = Utils.getRandomInstance();50long[] ra = new long[(NBITS+63)/64];5152for(int l=0; l < 5000000; l++) {5354for(int r = 0; r < ra.length; r++) {55ra[r] = rnd.nextLong();56}57test(ra, bs);58}59}6061static void test(long[] ra, BitSet bs) {62bs.clear();63int bits_set = 0;64for(int i = 0, t = 0, b = 0; i < NBITS; i++) {65long bit = 1L << b++;66if((ra[t]&bit) != 0) {67bs.set(i);68bits_set++;69}70if(b == 64) {71t++;72b = 0;73}74}75// Test Long.bitCount()76int check_bits = bs.cardinality();77if (check_bits != bits_set) {78String bs_str = bs.toString();79System.err.printf("cardinality bits: %d != %d bs: %s\n", check_bits, bits_set, bs_str);80System.exit(97);81}82// Test Long.numberOfTrailingZeros()83check_bits = 0;84for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {85check_bits++;86}87if (check_bits != bits_set) {88String bs_str = bs.toString();89System.err.printf("nextSetBit bits: %d != %d bs: %s\n", check_bits, bits_set, bs_str);90System.exit(97);91}92// Test Long.numberOfLeadingZeros()93for(int i = bs.length(); i > 0; i = bs.length()) {94bs.clear(i-1);95}96// Test Long.bitCount()97check_bits = bs.cardinality();98if (check_bits != 0) {99String bs_str = bs.toString();100System.err.printf("after clear bits: %d != 0 bs: %s\n", check_bits, bs_str);101System.exit(97);102}103}104105};106107108