test/compiler/7009231/Test7009231.java

Fri, 02 Dec 2011 15:11:40 -0800

author
jcoomes
date
Fri, 02 Dec 2011 15:11:40 -0800
changeset 3301
aed8bf036ce2
parent 0
f90c822e73f8
permissions
-rw-r--r--

Added tag hs23-b07 for changeset 6de8c9ba5907

     1 /*
     2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /**
    26  * @test
    27  * @bug 7009231
    28  * @summary C1: Incorrect CAS code for longs on SPARC 32bit
    29  *
    30  * @run main/othervm -Xbatch Test7009231
    31  *
    32  */
    34 import java.util.Random;
    35 import java.util.concurrent.atomic.AtomicLong;
    38 public class Test7009231 {
    39     public static void main(String[] args) throws InterruptedException {
    40         doTest(8);
    41     }
    43     private static void doTest(int nThreads) throws InterruptedException {
    44         Thread[]         aThreads = new Thread[nThreads];
    45         final AtomicLong atl      = new AtomicLong();
    47         for (int i = 0; i < nThreads; i++) {
    48           aThreads[i] = new RunnerThread(atl, 1L << (8 * i));
    49         }
    51         for (int i = 0; i < nThreads; i++) {
    52           aThreads[i].start();
    53         }
    55         for (int i = 0; i < nThreads; i++) {
    56           aThreads[i].join();
    57         }
    58     }
    60     public static class RunnerThread extends Thread {
    61         public RunnerThread(AtomicLong atomic, long lMask) {
    62             m_lMask  = lMask;
    63             m_atomic = atomic;
    64         }
    66         public void run() {
    67             AtomicLong atomic = m_atomic;
    68             long       lMask  = m_lMask;
    69             for (int i = 0; i < 100000; i++) {
    70                 setBit(atomic, lMask);
    71                 clearBit(atomic, lMask);
    72             }
    73         }
    75         protected void setBit(AtomicLong atomic, long lMask) {
    76             long lWord;
    77             do {
    78                 lWord = atomic.get();
    79             } while (!atomic.compareAndSet(lWord, lWord | lMask));
    81             if ((atomic.get() & lMask) == 0L) {
    82                 throw new InternalError();
    83             }
    84         }
    86         protected void clearBit(AtomicLong atomic, long lMask) {
    87             long lWord;
    88             do {
    89                 lWord = atomic.get();
    90             } while (!atomic.compareAndSet(lWord, lWord & ~lMask));
    92             if ((atomic.get() & lMask) != 0L) {
    93                 throw new InternalError();
    94             }
    95         }
    97         private long m_lMask;
    98         private AtomicLong m_atomic;
    99     }
   100 }

mercurial