1977N/A/*
1977N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
1977N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1977N/A *
1977N/A * This code is free software; you can redistribute it and/or modify it
1977N/A * under the terms of the GNU General Public License version 2 only, as
1977N/A * published by the Free Software Foundation.
1977N/A *
1977N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1977N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1977N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1977N/A * version 2 for more details (a copy is included in the LICENSE file that
1977N/A * accompanied this code).
1977N/A *
1977N/A * You should have received a copy of the GNU General Public License version
1977N/A * 2 along with this work; if not, write to the Free Software Foundation,
1977N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1977N/A *
1977N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1977N/A * or visit www.oracle.com if you need additional information or have any
1977N/A * questions.
1977N/A *
1977N/A */
1977N/A
1977N/A/**
1977N/A * @test
1977N/A * @bug 7009231
1977N/A * @summary C1: Incorrect CAS code for longs on SPARC 32bit
1977N/A *
1977N/A * @run main/othervm -Xbatch Test7009231
1977N/A *
1977N/A */
1977N/A
1977N/Aimport java.util.Random;
1977N/Aimport java.util.concurrent.atomic.AtomicLong;
1977N/A
1977N/A
1977N/Apublic class Test7009231 {
1977N/A public static void main(String[] args) throws InterruptedException {
1977N/A doTest(8);
1977N/A }
1977N/A
1977N/A private static void doTest(int nThreads) throws InterruptedException {
1977N/A Thread[] aThreads = new Thread[nThreads];
1977N/A final AtomicLong atl = new AtomicLong();
1977N/A
1977N/A for (int i = 0; i < nThreads; i++) {
1977N/A aThreads[i] = new RunnerThread(atl, 1L << (8 * i));
1977N/A }
1977N/A
1977N/A for (int i = 0; i < nThreads; i++) {
1977N/A aThreads[i].start();
1977N/A }
1977N/A
1977N/A for (int i = 0; i < nThreads; i++) {
1977N/A aThreads[i].join();
1977N/A }
1977N/A }
1977N/A
1977N/A public static class RunnerThread extends Thread {
1977N/A public RunnerThread(AtomicLong atomic, long lMask) {
1977N/A m_lMask = lMask;
1977N/A m_atomic = atomic;
1977N/A }
1977N/A
1977N/A public void run() {
1977N/A AtomicLong atomic = m_atomic;
1977N/A long lMask = m_lMask;
1977N/A for (int i = 0; i < 100000; i++) {
1977N/A setBit(atomic, lMask);
1977N/A clearBit(atomic, lMask);
1977N/A }
1977N/A }
1977N/A
1977N/A protected void setBit(AtomicLong atomic, long lMask) {
1977N/A long lWord;
1977N/A do {
1977N/A lWord = atomic.get();
1977N/A } while (!atomic.compareAndSet(lWord, lWord | lMask));
1977N/A
1977N/A if ((atomic.get() & lMask) == 0L) {
1977N/A throw new InternalError();
1977N/A }
1977N/A }
1977N/A
1977N/A protected void clearBit(AtomicLong atomic, long lMask) {
1977N/A long lWord;
1977N/A do {
1977N/A lWord = atomic.get();
1977N/A } while (!atomic.compareAndSet(lWord, lWord & ~lMask));
1977N/A
1977N/A if ((atomic.get() & lMask) != 0L) {
1977N/A throw new InternalError();
1977N/A }
1977N/A }
1977N/A
1977N/A private long m_lMask;
1977N/A private AtomicLong m_atomic;
1977N/A }
1977N/A}