Lazy.java revision 0
0N/A/*
0N/A * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6275329
0N/A * @summary lazySet methods
0N/A */
0N/A
0N/Aimport java.util.concurrent.atomic.*;
0N/Aimport java.util.*;
0N/A
0N/Apublic class Lazy {
0N/A volatile int ii;
0N/A volatile long ll;
0N/A volatile Boolean bb;
0N/A static final Lazy z = new Lazy();
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A final AtomicBoolean b = new AtomicBoolean();
0N/A final AtomicInteger i = new AtomicInteger();
0N/A final AtomicLong l = new AtomicLong();
0N/A final AtomicReference<Long> r = new AtomicReference<Long>();
0N/A
0N/A final AtomicIntegerArray ia = new AtomicIntegerArray(1);
0N/A final AtomicLongArray la = new AtomicLongArray(1);
0N/A final AtomicReferenceArray<Long> ra = new AtomicReferenceArray<Long>(1);
0N/A
0N/A final AtomicIntegerFieldUpdater<Lazy> iu =
0N/A AtomicIntegerFieldUpdater.newUpdater(Lazy.class, "ii");
0N/A final AtomicLongFieldUpdater<Lazy> lu =
0N/A AtomicLongFieldUpdater.newUpdater(Lazy.class, "ll");
0N/A final AtomicReferenceFieldUpdater<Lazy,Boolean> ru =
0N/A AtomicReferenceFieldUpdater.newUpdater(Lazy.class,
0N/A Boolean.class, "bb");
0N/A
0N/A Thread[] threads = {
0N/A new Thread() { public void run() { b.lazySet(true); }},
0N/A new Thread() { public void run() { i.lazySet(2); }},
0N/A new Thread() { public void run() { l.lazySet(3L); }},
0N/A new Thread() { public void run() { r.lazySet(9L); }},
0N/A new Thread() { public void run() { ia.lazySet(0,4); }},
0N/A new Thread() { public void run() { la.lazySet(0,5L); }},
0N/A new Thread() { public void run() { ra.lazySet(0,6L); }},
0N/A new Thread() { public void run() { iu.lazySet(z,7); }},
0N/A new Thread() { public void run() { lu.lazySet(z,8L); }},
0N/A new Thread() { public void run() { ru.lazySet(z,true); }}};
0N/A
0N/A for (Thread t : threads) t.start();
0N/A for (Thread t : threads) t.join();
0N/A
0N/A if (! (b.get() == true &&
0N/A i.get() == 2 &&
0N/A l.get() == 3L &&
0N/A r.get() == 9L &&
0N/A ia.get(0) == 4 &&
0N/A la.get(0) == 5L &&
0N/A ra.get(0) == 6L &&
0N/A z.ii == 7 &&
0N/A z.ll == 8L &&
0N/A z.bb == true))
0N/A throw new Exception("lazySet failed");
0N/A }
0N/A}