diff -r 000000000000 -r f90c822e73f8 test/compiler/8004867/TestIntAtomicCAS.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/8004867/TestIntAtomicCAS.java Wed Apr 27 01:25:04 2016 +0800 @@ -0,0 +1,969 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test + * @bug 8004867 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob" + * + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntAtomicCAS + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntAtomicCAS + */ + +import java.util.concurrent.atomic.AtomicIntegerArray; + +public class TestIntAtomicCAS { + private static final int ARRLEN = 97; + private static final int ITERS = 11000; + private static final int OFFSET = 3; + private static final int SCALE = 2; + private static final int ALIGN_OFF = 8; + private static final int UNALIGN_OFF = 5; + + public static void main(String args[]) { + System.out.println("Testing Integer array atomic CAS operations"); + int errn = test(false); + if (errn > 0) { + System.err.println("FAILED: " + errn + " errors"); + System.exit(97); + } + System.out.println("PASSED"); + } + + static int test(boolean test_only) { + AtomicIntegerArray a1 = new AtomicIntegerArray(ARRLEN); + AtomicIntegerArray a2 = new AtomicIntegerArray(ARRLEN); + // Initialize + for (int i=0; i 0 || test_only) + return errn; + + // Initialize + for (int i=0; i= 0; i-=1) { + a.compareAndSet(i, old, -123); + } + } + static void test_vi_neg(AtomicIntegerArray a, int b, int old) { + for (int i = ARRLEN-1; i >= 0; i-=1) { + a.compareAndSet(i, old, b); + } + } + static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = ARRLEN-1; i >= 0; i-=1) { + a.compareAndSet(i, -123, b.get(i)); + } + } + static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = ARRLEN-1; i >= 0; i-=1) { + a.compareAndSet(i, 123, -123); + b.compareAndSet(i, 123, -103); + } + } + static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + for (int i = ARRLEN-1; i >= 0; i-=1) { + a.compareAndSet(i, -123, c); + b.compareAndSet(i, -103, d); + } + } + static void test_ci_oppos(AtomicIntegerArray a, int old) { + int limit = ARRLEN-1; + for (int i = 0; i < ARRLEN; i+=1) { + a.compareAndSet((limit-i), old, -123); + } + } + static void test_vi_oppos(AtomicIntegerArray a, int b, int old) { + int limit = ARRLEN-1; + for (int i = limit; i >= 0; i-=1) { + a.compareAndSet((limit-i), old, b); + } + } + static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) { + int limit = ARRLEN-1; + for (int i = 0; i < ARRLEN; i+=1) { + a.compareAndSet(i, -123, b.get(limit-i)); + } + } + static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) { + int limit = ARRLEN-1; + for (int i = 0; i < ARRLEN; i+=1) { + a.compareAndSet((limit-i), 123, -123); + b.compareAndSet(i, 123, -103); + } + } + static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + int limit = ARRLEN-1; + for (int i = limit; i >= 0; i-=1) { + a.compareAndSet(i, -123, c); + b.compareAndSet((limit-i), -103, d); + } + } + static void test_ci_off(AtomicIntegerArray a, int old) { + for (int i = 0; i < ARRLEN-OFFSET; i+=1) { + a.compareAndSet((i+OFFSET), old, -123); + } + } + static void test_vi_off(AtomicIntegerArray a, int b, int old) { + for (int i = 0; i < ARRLEN-OFFSET; i+=1) { + a.compareAndSet((i+OFFSET), old, b); + } + } + static void test_cp_off(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-OFFSET; i+=1) { + a.compareAndSet((i+OFFSET), -123, b.get(i+OFFSET)); + } + } + static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-OFFSET; i+=1) { + a.compareAndSet((i+OFFSET), 123, -123); + b.compareAndSet((i+OFFSET), 123, -103); + } + } + static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + for (int i = 0; i < ARRLEN-OFFSET; i+=1) { + a.compareAndSet((i+OFFSET), -123, c); + b.compareAndSet((i+OFFSET), -103, d); + } + } + static void test_ci_inv(AtomicIntegerArray a, int k, int old) { + for (int i = 0; i < ARRLEN-k; i+=1) { + a.compareAndSet((i+k), old, -123); + } + } + static void test_vi_inv(AtomicIntegerArray a, int b, int k, int old) { + for (int i = 0; i < ARRLEN-k; i+=1) { + a.compareAndSet((i+k), old, b); + } + } + static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) { + for (int i = 0; i < ARRLEN-k; i+=1) { + a.compareAndSet((i+k), -123, b.get(i+k)); + } + } + static void test_2ci_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) { + for (int i = 0; i < ARRLEN-k; i+=1) { + a.compareAndSet((i+k), 123, -123); + b.compareAndSet((i+k), 123, -103); + } + } + static void test_2vi_inv(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d, int k) { + for (int i = 0; i < ARRLEN-k; i+=1) { + a.compareAndSet((i+k), -123, c); + b.compareAndSet((i+k), -103, d); + } + } + static void test_ci_scl(AtomicIntegerArray a, int old) { + for (int i = 0; i*SCALE < ARRLEN; i+=1) { + a.compareAndSet((i*SCALE), old, -123); + } + } + static void test_vi_scl(AtomicIntegerArray a, int b, int old) { + for (int i = 0; i*SCALE < ARRLEN; i+=1) { + a.compareAndSet((i*SCALE), old, b); + } + } + static void test_cp_scl(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i*SCALE < ARRLEN; i+=1) { + a.compareAndSet((i*SCALE), -123, b.get(i*SCALE)); + } + } + static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i*SCALE < ARRLEN; i+=1) { + a.compareAndSet((i*SCALE), 123, -123); + b.compareAndSet((i*SCALE), 123, -103); + } + } + static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + for (int i = 0; i*SCALE < ARRLEN; i+=1) { + a.compareAndSet((i*SCALE), -123, c); + b.compareAndSet((i*SCALE), -103, d); + } + } + static void test_cp_alndst(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { + a.compareAndSet((i+ALIGN_OFF), -1, b.get(i)); + } + } + static void test_cp_alnsrc(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { + a.getAndSet(i, b.get(i+ALIGN_OFF)); + } + } + static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { + a.compareAndSet((i+ALIGN_OFF), -1, -123); + b.getAndSet(i, -103); + } + } + static void test_2vi_aln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { + a.getAndSet(i, c); + b.getAndSet((i+ALIGN_OFF), d); + } + } + static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { + a.compareAndSet((i+UNALIGN_OFF), -1, b.get(i)); + } + } + static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { + a.getAndSet(i, b.get(i+UNALIGN_OFF)); + } + } + static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) { + for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { + a.compareAndSet((i+UNALIGN_OFF), -1, -123); + b.getAndSet(i, -103); + } + } + static void test_2vi_unaln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { + for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { + a.getAndSet(i, c); + b.getAndSet((i+UNALIGN_OFF), d); + } + } + + static int verify(String text, int i, int elem, int val) { + if (elem != val) { + System.err.println(text + "[" + i + "] = " + elem + " != " + val); + return 1; + } + return 0; + } +}