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