Path: blob/master/test/hotspot/jtreg/compiler/codegen/Test7009231.java
41149 views
/*1* Copyright (c) 2010, 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* @bug 700923126* @summary C1: Incorrect CAS code for longs on SPARC 32bit27*28* @run main/othervm -Xbatch compiler.codegen.Test700923129*/3031package compiler.codegen;3233import java.util.concurrent.atomic.AtomicLong;3435public class Test7009231 {36public static void main(String[] args) throws InterruptedException {37doTest(8);38}3940private static void doTest(int nThreads) throws InterruptedException {41Thread[] aThreads = new Thread[nThreads];42final AtomicLong atl = new AtomicLong();4344for (int i = 0; i < nThreads; i++) {45aThreads[i] = new RunnerThread(atl, 1L << (8 * i));46}4748for (int i = 0; i < nThreads; i++) {49aThreads[i].start();50}5152for (int i = 0; i < nThreads; i++) {53aThreads[i].join();54}55}5657public static class RunnerThread extends Thread {58public RunnerThread(AtomicLong atomic, long lMask) {59m_lMask = lMask;60m_atomic = atomic;61}6263public void run() {64AtomicLong atomic = m_atomic;65long lMask = m_lMask;66for (int i = 0; i < 100000; i++) {67setBit(atomic, lMask);68clearBit(atomic, lMask);69}70}7172protected void setBit(AtomicLong atomic, long lMask) {73long lWord;74do {75lWord = atomic.get();76} while (!atomic.compareAndSet(lWord, lWord | lMask));7778if ((atomic.get() & lMask) == 0L) {79throw new InternalError();80}81}8283protected void clearBit(AtomicLong atomic, long lMask) {84long lWord;85do {86lWord = atomic.get();87} while (!atomic.compareAndSet(lWord, lWord & ~lMask));8889if ((atomic.get() & lMask) != 0L) {90throw new InternalError();91}92}9394private long m_lMask;95private AtomicLong m_atomic;96}97}9899100