8004867: VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"

Mon, 18 Feb 2013 16:47:15 -0800

author
kvn
date
Mon, 18 Feb 2013 16:47:15 -0800
changeset 4620
ad736b4683b4
parent 4619
a2bc322ca273
child 4621
2e4b16122164
child 4660
133bf557ef77

8004867: VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
Summary: Added few checks and early bailout from Superword optimization to avoid such cases in a future.
Reviewed-by: roland, twisti

src/share/vm/opto/superword.cpp file | annotate | diff | comparison | revisions
src/share/vm/opto/superword.hpp file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntAtomicCAS.java file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntAtomicOrdered.java file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntAtomicVolatile.java file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntUnsafeCAS.java file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntUnsafeOrdered.java file | annotate | diff | comparison | revisions
test/compiler/8004867/TestIntUnsafeVolatile.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/superword.cpp	Mon Feb 18 15:08:39 2013 -0800
     1.2 +++ b/src/share/vm/opto/superword.cpp	Mon Feb 18 16:47:15 2013 -0800
     1.3 @@ -143,7 +143,8 @@
     1.4  
     1.5    // Ready the block
     1.6  
     1.7 -  construct_bb();
     1.8 +  if (!construct_bb())
     1.9 +    return; // Exit if no interesting nodes or complex graph.
    1.10  
    1.11    dependence_graph();
    1.12  
    1.13 @@ -615,6 +616,7 @@
    1.14      if (n == stop) break;
    1.15      preds.push(n);
    1.16      prev = n;
    1.17 +    assert(n->is_Mem(), err_msg_res("unexpected node %s", n->Name()));
    1.18      n = n->in(MemNode::Memory);
    1.19    }
    1.20  }
    1.21 @@ -1578,7 +1580,7 @@
    1.22  
    1.23  //------------------------------construct_bb---------------------------
    1.24  // Construct reverse postorder list of block members
    1.25 -void SuperWord::construct_bb() {
    1.26 +bool SuperWord::construct_bb() {
    1.27    Node* entry = bb();
    1.28  
    1.29    assert(_stk.length() == 0,            "stk is empty");
    1.30 @@ -1596,6 +1598,12 @@
    1.31      Node *n = lpt()->_body.at(i);
    1.32      set_bb_idx(n, i); // Create a temporary map
    1.33      if (in_bb(n)) {
    1.34 +      if (n->is_LoadStore() || n->is_MergeMem() ||
    1.35 +          (n->is_Proj() && !n->as_Proj()->is_CFG())) {
    1.36 +        // Bailout if the loop has LoadStore, MergeMem or data Proj
    1.37 +        // nodes. Superword optimization does not work with them.
    1.38 +        return false;
    1.39 +      }
    1.40        bb_ct++;
    1.41        if (!n->is_CFG()) {
    1.42          bool found = false;
    1.43 @@ -1620,6 +1628,10 @@
    1.44      if (in_bb(n) && (n->is_Phi() && n->bottom_type() == Type::MEMORY)) {
    1.45        Node* n_tail  = n->in(LoopNode::LoopBackControl);
    1.46        if (n_tail != n->in(LoopNode::EntryControl)) {
    1.47 +        if (!n_tail->is_Mem()) {
    1.48 +          assert(n_tail->is_Mem(), err_msg_res("unexpected node for memory slice: %s", n_tail->Name()));
    1.49 +          return false; // Bailout
    1.50 +        }
    1.51          _mem_slice_head.push(n);
    1.52          _mem_slice_tail.push(n_tail);
    1.53        }
    1.54 @@ -1695,6 +1707,7 @@
    1.55    }
    1.56  #endif
    1.57    assert(rpo_idx == -1 && bb_ct == _block.length(), "all block members found");
    1.58 +  return (_mem_slice_head.length() > 0) || (_data_entry.length() > 0);
    1.59  }
    1.60  
    1.61  //------------------------------initialize_bb---------------------------
     2.1 --- a/src/share/vm/opto/superword.hpp	Mon Feb 18 15:08:39 2013 -0800
     2.2 +++ b/src/share/vm/opto/superword.hpp	Mon Feb 18 16:47:15 2013 -0800
     2.3 @@ -380,7 +380,7 @@
     2.4    // Is use->in(u_idx) a vector use?
     2.5    bool is_vector_use(Node* use, int u_idx);
     2.6    // Construct reverse postorder list of block members
     2.7 -  void construct_bb();
     2.8 +  bool construct_bb();
     2.9    // Initialize per node info
    2.10    void initialize_bb();
    2.11    // Insert n into block after pos
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/8004867/TestIntAtomicCAS.java	Mon Feb 18 16:47:15 2013 -0800
     3.3 @@ -0,0 +1,969 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + *
    3.26 + */
    3.27 +
    3.28 +/**
    3.29 + * @test
    3.30 + * @bug 8004867
    3.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    3.32 + *
    3.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntAtomicCAS
    3.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntAtomicCAS
    3.35 + */
    3.36 +
    3.37 +import java.util.concurrent.atomic.AtomicIntegerArray;
    3.38 +
    3.39 +public class TestIntAtomicCAS {
    3.40 +  private static final int ARRLEN = 97;
    3.41 +  private static final int ITERS  = 11000;
    3.42 +  private static final int OFFSET = 3;
    3.43 +  private static final int SCALE = 2;
    3.44 +  private static final int ALIGN_OFF = 8;
    3.45 +  private static final int UNALIGN_OFF = 5;
    3.46 +
    3.47 +  public static void main(String args[]) {
    3.48 +    System.out.println("Testing Integer array atomic CAS operations");
    3.49 +    int errn = test(false);
    3.50 +    if (errn > 0) {
    3.51 +      System.err.println("FAILED: " + errn + " errors");
    3.52 +      System.exit(97);
    3.53 +    }
    3.54 +    System.out.println("PASSED");
    3.55 +  }
    3.56 +
    3.57 +  static int test(boolean test_only) {
    3.58 +    AtomicIntegerArray a1 = new AtomicIntegerArray(ARRLEN);
    3.59 +    AtomicIntegerArray a2 = new AtomicIntegerArray(ARRLEN);
    3.60 +    // Initialize
    3.61 +    for (int i=0; i<ARRLEN; i++) {
    3.62 +      a1.set(i, -1);
    3.63 +      a2.set(i, -1);
    3.64 +    }
    3.65 +    System.out.println("Warmup");
    3.66 +    for (int i=0; i<ITERS; i++) {
    3.67 +      test_ci(a1);
    3.68 +      test_vi(a2, 123, -1);
    3.69 +      test_cp(a1, a2);
    3.70 +      test_2ci(a1, a2);
    3.71 +      test_2vi(a1, a2, 123, 103);
    3.72 +      test_ci_neg(a1, 123);
    3.73 +      test_vi_neg(a2, 123, 103);
    3.74 +      test_cp_neg(a1, a2);
    3.75 +      test_2ci_neg(a1, a2);
    3.76 +      test_2vi_neg(a1, a2, 123, 103);
    3.77 +      test_ci_oppos(a1, 123);
    3.78 +      test_vi_oppos(a2, 123, 103);
    3.79 +      test_cp_oppos(a1, a2);
    3.80 +      test_2ci_oppos(a1, a2);
    3.81 +      test_2vi_oppos(a1, a2, 123, 103);
    3.82 +      test_ci_off(a1, 123);
    3.83 +      test_vi_off(a2, 123, 103);
    3.84 +      test_cp_off(a1, a2);
    3.85 +      test_2ci_off(a1, a2);
    3.86 +      test_2vi_off(a1, a2, 123, 103);
    3.87 +      test_ci_inv(a1, OFFSET, 123);
    3.88 +      test_vi_inv(a2, 123, OFFSET, 103);
    3.89 +      test_cp_inv(a1, a2, OFFSET);
    3.90 +      test_2ci_inv(a1, a2, OFFSET);
    3.91 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
    3.92 +      test_ci_scl(a1, 123);
    3.93 +      test_vi_scl(a2, 123, 103);
    3.94 +      test_cp_scl(a1, a2);
    3.95 +      test_2ci_scl(a1, a2);
    3.96 +      test_2vi_scl(a1, a2, 123, 103);
    3.97 +      test_cp_alndst(a1, a2);
    3.98 +      test_cp_alnsrc(a1, a2);
    3.99 +      test_2ci_aln(a1, a2);
   3.100 +      test_2vi_aln(a1, a2, 123, 103);
   3.101 +      test_cp_unalndst(a1, a2);
   3.102 +      test_cp_unalnsrc(a1, a2);
   3.103 +      test_2ci_unaln(a1, a2);
   3.104 +      test_2vi_unaln(a1, a2, 123, 103);
   3.105 +    }
   3.106 +    // Initialize
   3.107 +    for (int i=0; i<ARRLEN; i++) {
   3.108 +      a1.set(i, -1);
   3.109 +      a2.set(i, -1);
   3.110 +    }
   3.111 +    // Test and verify results
   3.112 +    System.out.println("Verification");
   3.113 +    int errn = 0;
   3.114 +    {
   3.115 +      test_ci(a1);
   3.116 +      for (int i=0; i<ARRLEN; i++) {
   3.117 +        errn += verify("test_ci: a1", i, a1.get(i), -123);
   3.118 +      }
   3.119 +      test_vi(a2, 123, -1);
   3.120 +      for (int i=0; i<ARRLEN; i++) {
   3.121 +        errn += verify("test_vi: a2", i, a2.get(i), 123);
   3.122 +      }
   3.123 +      test_cp(a1, a2);
   3.124 +      for (int i=0; i<ARRLEN; i++) {
   3.125 +        errn += verify("test_cp: a1", i, a1.get(i), 123);
   3.126 +      }
   3.127 +      test_2ci(a1, a2);
   3.128 +      for (int i=0; i<ARRLEN; i++) {
   3.129 +        errn += verify("test_2ci: a1", i, a1.get(i), -123);
   3.130 +        errn += verify("test_2ci: a2", i, a2.get(i), -103);
   3.131 +      }
   3.132 +      test_2vi(a1, a2, 123, 103);
   3.133 +      for (int i=0; i<ARRLEN; i++) {
   3.134 +        errn += verify("test_2vi: a1", i, a1.get(i), 123);
   3.135 +        errn += verify("test_2vi: a2", i, a2.get(i), 103);
   3.136 +      }
   3.137 +      // Reset for negative stride
   3.138 +      for (int i=0; i<ARRLEN; i++) {
   3.139 +        a1.set(i, -1);
   3.140 +        a2.set(i, -1);
   3.141 +      }
   3.142 +      test_ci_neg(a1, -1);
   3.143 +      for (int i=0; i<ARRLEN; i++) {
   3.144 +        errn += verify("test_ci_neg: a1", i, a1.get(i), -123);
   3.145 +      }
   3.146 +      test_vi_neg(a2, 123, -1);
   3.147 +      for (int i=0; i<ARRLEN; i++) {
   3.148 +        errn += verify("test_vi_neg: a2", i, a2.get(i), 123);
   3.149 +      }
   3.150 +      test_cp_neg(a1, a2);
   3.151 +      for (int i=0; i<ARRLEN; i++) {
   3.152 +        errn += verify("test_cp_neg: a1", i, a1.get(i), 123);
   3.153 +      }
   3.154 +      test_2ci_neg(a1, a2);
   3.155 +      for (int i=0; i<ARRLEN; i++) {
   3.156 +        errn += verify("test_2ci_neg: a1", i, a1.get(i), -123);
   3.157 +        errn += verify("test_2ci_neg: a2", i, a2.get(i), -103);
   3.158 +      }
   3.159 +      test_2vi_neg(a1, a2, 123, 103);
   3.160 +      for (int i=0; i<ARRLEN; i++) {
   3.161 +        errn += verify("test_2vi_neg: a1", i, a1.get(i), 123);
   3.162 +        errn += verify("test_2vi_neg: a2", i, a2.get(i), 103);
   3.163 +      }
   3.164 +      // Reset for opposite stride
   3.165 +      for (int i=0; i<ARRLEN; i++) {
   3.166 +        a1.set(i, -1);
   3.167 +        a2.set(i, -1);
   3.168 +      }
   3.169 +      test_ci_oppos(a1, -1);
   3.170 +      for (int i=0; i<ARRLEN; i++) {
   3.171 +        errn += verify("test_ci_oppos: a1", i, a1.get(i), -123);
   3.172 +      }
   3.173 +      test_vi_oppos(a2, 123, -1);
   3.174 +      for (int i=0; i<ARRLEN; i++) {
   3.175 +        errn += verify("test_vi_oppos: a2", i, a2.get(i), 123);
   3.176 +      }
   3.177 +      test_cp_oppos(a1, a2);
   3.178 +      for (int i=0; i<ARRLEN; i++) {
   3.179 +        errn += verify("test_cp_oppos: a1", i, a1.get(i), 123);
   3.180 +      }
   3.181 +      test_2ci_oppos(a1, a2);
   3.182 +      for (int i=0; i<ARRLEN; i++) {
   3.183 +        errn += verify("test_2ci_oppos: a1", i, a1.get(i), -123);
   3.184 +        errn += verify("test_2ci_oppos: a2", i, a2.get(i), -103);
   3.185 +      }
   3.186 +      test_2vi_oppos(a1, a2, 123, 103);
   3.187 +      for (int i=0; i<ARRLEN; i++) {
   3.188 +        errn += verify("test_2vi_oppos: a1", i, a1.get(i), 123);
   3.189 +        errn += verify("test_2vi_oppos: a2", i, a2.get(i), 103);
   3.190 +      }
   3.191 +      // Reset for indexing with offset
   3.192 +      for (int i=0; i<ARRLEN; i++) {
   3.193 +        a1.set(i, -1);
   3.194 +        a2.set(i, -1);
   3.195 +      }
   3.196 +      test_ci_off(a1, -1);
   3.197 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.198 +        errn += verify("test_ci_off: a1", i, a1.get(i), -123);
   3.199 +      }
   3.200 +      test_vi_off(a2, 123, -1);
   3.201 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.202 +        errn += verify("test_vi_off: a2", i, a2.get(i), 123);
   3.203 +      }
   3.204 +      test_cp_off(a1, a2);
   3.205 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.206 +        errn += verify("test_cp_off: a1", i, a1.get(i), 123);
   3.207 +      }
   3.208 +      test_2ci_off(a1, a2);
   3.209 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.210 +        errn += verify("test_2ci_off: a1", i, a1.get(i), -123);
   3.211 +        errn += verify("test_2ci_off: a2", i, a2.get(i), -103);
   3.212 +      }
   3.213 +      test_2vi_off(a1, a2, 123, 103);
   3.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.215 +        errn += verify("test_2vi_off: a1", i, a1.get(i), 123);
   3.216 +        errn += verify("test_2vi_off: a2", i, a2.get(i), 103);
   3.217 +      }
   3.218 +      for (int i=0; i<OFFSET; i++) {
   3.219 +        errn += verify("test_2vi_off: a1", i, a1.get(i), -1);
   3.220 +        errn += verify("test_2vi_off: a2", i, a2.get(i), -1);
   3.221 +      }
   3.222 +      // Reset for indexing with invariant offset
   3.223 +      for (int i=0; i<ARRLEN; i++) {
   3.224 +        a1.set(i, -1);
   3.225 +        a2.set(i, -1);
   3.226 +      }
   3.227 +      test_ci_inv(a1, OFFSET, -1);
   3.228 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.229 +        errn += verify("test_ci_inv: a1", i, a1.get(i), -123);
   3.230 +      }
   3.231 +      test_vi_inv(a2, 123, OFFSET, -1);
   3.232 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.233 +        errn += verify("test_vi_inv: a2", i, a2.get(i), 123);
   3.234 +      }
   3.235 +      test_cp_inv(a1, a2, OFFSET);
   3.236 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.237 +        errn += verify("test_cp_inv: a1", i, a1.get(i), 123);
   3.238 +      }
   3.239 +      test_2ci_inv(a1, a2, OFFSET);
   3.240 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.241 +        errn += verify("test_2ci_inv: a1", i, a1.get(i), -123);
   3.242 +        errn += verify("test_2ci_inv: a2", i, a2.get(i), -103);
   3.243 +      }
   3.244 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   3.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   3.246 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), 123);
   3.247 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), 103);
   3.248 +      }
   3.249 +      for (int i=0; i<OFFSET; i++) {
   3.250 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), -1);
   3.251 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), -1);
   3.252 +      }
   3.253 +      // Reset for indexing with scale
   3.254 +      for (int i=0; i<ARRLEN; i++) {
   3.255 +        a1.set(i, -1);
   3.256 +        a2.set(i, -1);
   3.257 +      }
   3.258 +      test_ci_scl(a1, -1);
   3.259 +      for (int i=0; i<ARRLEN; i++) {
   3.260 +        int val = (i%SCALE != 0) ? -1 : -123;
   3.261 +        errn += verify("test_ci_scl: a1", i, a1.get(i), val);
   3.262 +      }
   3.263 +      test_vi_scl(a2, 123, -1);
   3.264 +      for (int i=0; i<ARRLEN; i++) {
   3.265 +        int val = (i%SCALE != 0) ? -1 : 123;
   3.266 +        errn += verify("test_vi_scl: a2", i, a2.get(i), val);
   3.267 +      }
   3.268 +      test_cp_scl(a1, a2);
   3.269 +      for (int i=0; i<ARRLEN; i++) {
   3.270 +        int val = (i%SCALE != 0) ? -1 : 123;
   3.271 +        errn += verify("test_cp_scl: a1", i, a1.get(i), val);
   3.272 +      }
   3.273 +      test_2ci_scl(a1, a2);
   3.274 +      for (int i=0; i<ARRLEN; i++) {
   3.275 +        if (i%SCALE != 0) {
   3.276 +          errn += verify("test_2ci_scl: a1", i, a1.get(i), -1);
   3.277 +        } else if (i*SCALE < ARRLEN) {
   3.278 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1.get(i*SCALE), -123);
   3.279 +        }
   3.280 +        if (i%SCALE != 0) {
   3.281 +          errn += verify("test_2ci_scl: a2", i, a2.get(i), -1);
   3.282 +        } else if (i*SCALE < ARRLEN) {
   3.283 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2.get(i*SCALE), -103);
   3.284 +        }
   3.285 +      }
   3.286 +      test_2vi_scl(a1, a2, 123, 103);
   3.287 +      for (int i=0; i<ARRLEN; i++) {
   3.288 +        if (i%SCALE != 0) {
   3.289 +          errn += verify("test_2vi_scl: a1", i, a1.get(i), -1);
   3.290 +        } else if (i*SCALE < ARRLEN) {
   3.291 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1.get(i*SCALE), 123);
   3.292 +        }
   3.293 +        if (i%SCALE != 0) {
   3.294 +          errn += verify("test_2vi_scl: a2", i, a2.get(i), -1);
   3.295 +        } else if (i*SCALE < ARRLEN) {
   3.296 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2.get(i*SCALE), 103);
   3.297 +        }
   3.298 +      }
   3.299 +      // Reset for 2 arrays with relative aligned offset
   3.300 +      for (int i=0; i<ARRLEN; i++) {
   3.301 +        a1.set(i, -1);
   3.302 +        a2.set(i, -1);
   3.303 +      }
   3.304 +      test_vi(a2, 123, -1);
   3.305 +      test_cp_alndst(a1, a2);
   3.306 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.307 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), -1);
   3.308 +      }
   3.309 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   3.310 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), 123);
   3.311 +      }
   3.312 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.313 +        a1.set(i, 123);
   3.314 +      }
   3.315 +      test_vi(a2, -123, 123);
   3.316 +      test_cp_alnsrc(a1, a2);
   3.317 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   3.318 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), -123);
   3.319 +      }
   3.320 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   3.321 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), 123);
   3.322 +      }
   3.323 +      for (int i=0; i<ARRLEN; i++) {
   3.324 +        a1.set(i, -1);
   3.325 +        a2.set(i, -1);
   3.326 +      }
   3.327 +      test_2ci_aln(a1, a2);
   3.328 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.329 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -1);
   3.330 +      }
   3.331 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   3.332 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -123);
   3.333 +      }
   3.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   3.335 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -103);
   3.336 +      }
   3.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   3.338 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -1);
   3.339 +      }
   3.340 +      for (int i=0; i<ARRLEN; i++) {
   3.341 +        a1.set(i, -1);
   3.342 +        a2.set(i, -1);
   3.343 +      }
   3.344 +      test_2vi_aln(a1, a2, 123, 103);
   3.345 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   3.346 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), 123);
   3.347 +      }
   3.348 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   3.349 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), -1);
   3.350 +      }
   3.351 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.352 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), -1);
   3.353 +      }
   3.354 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   3.355 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), 103);
   3.356 +      }
   3.357 +
   3.358 +      // Reset for 2 arrays with relative unaligned offset
   3.359 +      for (int i=0; i<ARRLEN; i++) {
   3.360 +        a1.set(i, -1);
   3.361 +        a2.set(i, -1);
   3.362 +      }
   3.363 +      test_vi(a2, 123, -1);
   3.364 +      test_cp_unalndst(a1, a2);
   3.365 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.366 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), -1);
   3.367 +      }
   3.368 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   3.369 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), 123);
   3.370 +      }
   3.371 +      test_vi(a2, -123, 123);
   3.372 +      test_cp_unalnsrc(a1, a2);
   3.373 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   3.374 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), -123);
   3.375 +      }
   3.376 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   3.377 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), 123);
   3.378 +      }
   3.379 +      for (int i=0; i<ARRLEN; i++) {
   3.380 +        a1.set(i, -1);
   3.381 +        a2.set(i, -1);
   3.382 +      }
   3.383 +      test_2ci_unaln(a1, a2);
   3.384 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.385 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -1);
   3.386 +      }
   3.387 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   3.388 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -123);
   3.389 +      }
   3.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   3.391 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -103);
   3.392 +      }
   3.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   3.394 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -1);
   3.395 +      }
   3.396 +      for (int i=0; i<ARRLEN; i++) {
   3.397 +        a1.set(i, -1);
   3.398 +        a2.set(i, -1);
   3.399 +      }
   3.400 +      test_2vi_unaln(a1, a2, 123, 103);
   3.401 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   3.402 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), 123);
   3.403 +      }
   3.404 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   3.405 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), -1);
   3.406 +      }
   3.407 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.408 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), -1);
   3.409 +      }
   3.410 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   3.411 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), 103);
   3.412 +      }
   3.413 +
   3.414 +      // Reset for aligned overlap initialization
   3.415 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.416 +        a1.set(i, i);
   3.417 +      }
   3.418 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   3.419 +        a1.set(i, -1);
   3.420 +      }
   3.421 +      test_cp_alndst(a1, a1);
   3.422 +      for (int i=0; i<ARRLEN; i++) {
   3.423 +        int v = i%ALIGN_OFF;
   3.424 +        errn += verify("test_cp_alndst_overlap: a1", i, a1.get(i), v);
   3.425 +      }
   3.426 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.427 +        a1.set((i+ALIGN_OFF), -1);
   3.428 +      }
   3.429 +      test_cp_alnsrc(a1, a1);
   3.430 +      for (int i=0; i<ALIGN_OFF; i++) {
   3.431 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), -1);
   3.432 +      }
   3.433 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   3.434 +        int v = i%ALIGN_OFF;
   3.435 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), v);
   3.436 +      }
   3.437 +      for (int i=0; i<ARRLEN; i++) {
   3.438 +        a1.set(i, -1);
   3.439 +      }
   3.440 +      test_2ci_aln(a1, a1);
   3.441 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   3.442 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -103);
   3.443 +      }
   3.444 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   3.445 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -123);
   3.446 +      }
   3.447 +      for (int i=0; i<ARRLEN; i++) {
   3.448 +        a1.set(i, -1);
   3.449 +      }
   3.450 +      test_2vi_aln(a1, a1, 123, 103);
   3.451 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   3.452 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 123);
   3.453 +      }
   3.454 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   3.455 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 103);
   3.456 +      }
   3.457 +
   3.458 +      // Reset for unaligned overlap initialization
   3.459 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.460 +        a1.set(i, i);
   3.461 +      }
   3.462 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   3.463 +        a1.set(i, -1);
   3.464 +      }
   3.465 +      test_cp_unalndst(a1, a1);
   3.466 +      for (int i=0; i<ARRLEN; i++) {
   3.467 +        int v = i%UNALIGN_OFF;
   3.468 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1.get(i), v);
   3.469 +      }
   3.470 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.471 +        a1.set((i+UNALIGN_OFF), -1);
   3.472 +      }
   3.473 +      test_cp_unalnsrc(a1, a1);
   3.474 +      for (int i=0; i<UNALIGN_OFF; i++) {
   3.475 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), -1);
   3.476 +      }
   3.477 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   3.478 +        int v = i%UNALIGN_OFF;
   3.479 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), v);
   3.480 +      }
   3.481 +      for (int i=0; i<ARRLEN; i++) {
   3.482 +        a1.set(i, -1);
   3.483 +      }
   3.484 +      test_2ci_unaln(a1, a1);
   3.485 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   3.486 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -103);
   3.487 +      }
   3.488 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   3.489 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -123);
   3.490 +      }
   3.491 +      for (int i=0; i<ARRLEN; i++) {
   3.492 +        a1.set(i, -1);
   3.493 +      }
   3.494 +      test_2vi_unaln(a1, a1, 123, 103);
   3.495 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   3.496 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 123);
   3.497 +      }
   3.498 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   3.499 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 103);
   3.500 +      }
   3.501 +
   3.502 +    }
   3.503 +
   3.504 +    if (errn > 0 || test_only)
   3.505 +      return errn;
   3.506 +
   3.507 +    // Initialize
   3.508 +    for (int i=0; i<ARRLEN; i++) {
   3.509 +      a1.set(i, -1);
   3.510 +      a2.set(i, -1);
   3.511 +    }
   3.512 +    System.out.println("Time");
   3.513 +    long start, end;
   3.514 +    start = System.currentTimeMillis();
   3.515 +    for (int i=0; i<ITERS; i++) {
   3.516 +      test_ci(a1);
   3.517 +    }
   3.518 +    end = System.currentTimeMillis();
   3.519 +    System.out.println("test_ci: " + (end - start));
   3.520 +    start = System.currentTimeMillis();
   3.521 +    for (int i=0; i<ITERS; i++) {
   3.522 +      test_vi(a2, 123, -1);
   3.523 +    }
   3.524 +    end = System.currentTimeMillis();
   3.525 +    System.out.println("test_vi: " + (end - start));
   3.526 +    start = System.currentTimeMillis();
   3.527 +    for (int i=0; i<ITERS; i++) {
   3.528 +      test_cp(a1, a2);
   3.529 +    }
   3.530 +    end = System.currentTimeMillis();
   3.531 +    System.out.println("test_cp: " + (end - start));
   3.532 +    start = System.currentTimeMillis();
   3.533 +    for (int i=0; i<ITERS; i++) {
   3.534 +      test_2ci(a1, a2);
   3.535 +    }
   3.536 +    end = System.currentTimeMillis();
   3.537 +    System.out.println("test_2ci: " + (end - start));
   3.538 +    start = System.currentTimeMillis();
   3.539 +    for (int i=0; i<ITERS; i++) {
   3.540 +      test_2vi(a1, a2, 123, 103);
   3.541 +    }
   3.542 +    end = System.currentTimeMillis();
   3.543 +    System.out.println("test_2vi: " + (end - start));
   3.544 +
   3.545 +    start = System.currentTimeMillis();
   3.546 +    for (int i=0; i<ITERS; i++) {
   3.547 +      test_ci_neg(a1, 123);
   3.548 +    }
   3.549 +    end = System.currentTimeMillis();
   3.550 +    System.out.println("test_ci_neg: " + (end - start));
   3.551 +    start = System.currentTimeMillis();
   3.552 +    for (int i=0; i<ITERS; i++) {
   3.553 +      test_vi_neg(a2, 123, 103);
   3.554 +    }
   3.555 +    end = System.currentTimeMillis();
   3.556 +    System.out.println("test_vi_neg: " + (end - start));
   3.557 +    start = System.currentTimeMillis();
   3.558 +    for (int i=0; i<ITERS; i++) {
   3.559 +      test_cp_neg(a1, a2);
   3.560 +    }
   3.561 +    end = System.currentTimeMillis();
   3.562 +    System.out.println("test_cp_neg: " + (end - start));
   3.563 +    start = System.currentTimeMillis();
   3.564 +    for (int i=0; i<ITERS; i++) {
   3.565 +      test_2ci_neg(a1, a2);
   3.566 +    }
   3.567 +    end = System.currentTimeMillis();
   3.568 +    System.out.println("test_2ci_neg: " + (end - start));
   3.569 +    start = System.currentTimeMillis();
   3.570 +    for (int i=0; i<ITERS; i++) {
   3.571 +      test_2vi_neg(a1, a2, 123, 103);
   3.572 +    }
   3.573 +    end = System.currentTimeMillis();
   3.574 +    System.out.println("test_2vi_neg: " + (end - start));
   3.575 +
   3.576 +    start = System.currentTimeMillis();
   3.577 +    for (int i=0; i<ITERS; i++) {
   3.578 +      test_ci_oppos(a1, 123);
   3.579 +    }
   3.580 +    end = System.currentTimeMillis();
   3.581 +    System.out.println("test_ci_oppos: " + (end - start));
   3.582 +    start = System.currentTimeMillis();
   3.583 +    for (int i=0; i<ITERS; i++) {
   3.584 +      test_vi_oppos(a2, 123, 103);
   3.585 +    }
   3.586 +    end = System.currentTimeMillis();
   3.587 +    System.out.println("test_vi_oppos: " + (end - start));
   3.588 +    start = System.currentTimeMillis();
   3.589 +    for (int i=0; i<ITERS; i++) {
   3.590 +      test_cp_oppos(a1, a2);
   3.591 +    }
   3.592 +    end = System.currentTimeMillis();
   3.593 +    System.out.println("test_cp_oppos: " + (end - start));
   3.594 +    start = System.currentTimeMillis();
   3.595 +    for (int i=0; i<ITERS; i++) {
   3.596 +      test_2ci_oppos(a1, a2);
   3.597 +    }
   3.598 +    end = System.currentTimeMillis();
   3.599 +    System.out.println("test_2ci_oppos: " + (end - start));
   3.600 +    start = System.currentTimeMillis();
   3.601 +    for (int i=0; i<ITERS; i++) {
   3.602 +      test_2vi_oppos(a1, a2, 123, 103);
   3.603 +    }
   3.604 +    end = System.currentTimeMillis();
   3.605 +    System.out.println("test_2vi_oppos: " + (end - start));
   3.606 +
   3.607 +    start = System.currentTimeMillis();
   3.608 +    for (int i=0; i<ITERS; i++) {
   3.609 +      test_ci_off(a1, 123);
   3.610 +    }
   3.611 +    end = System.currentTimeMillis();
   3.612 +    System.out.println("test_ci_off: " + (end - start));
   3.613 +    start = System.currentTimeMillis();
   3.614 +    for (int i=0; i<ITERS; i++) {
   3.615 +      test_vi_off(a2, 123, 103);
   3.616 +    }
   3.617 +    end = System.currentTimeMillis();
   3.618 +    System.out.println("test_vi_off: " + (end - start));
   3.619 +    start = System.currentTimeMillis();
   3.620 +    for (int i=0; i<ITERS; i++) {
   3.621 +      test_cp_off(a1, a2);
   3.622 +    }
   3.623 +    end = System.currentTimeMillis();
   3.624 +    System.out.println("test_cp_off: " + (end - start));
   3.625 +    start = System.currentTimeMillis();
   3.626 +    for (int i=0; i<ITERS; i++) {
   3.627 +      test_2ci_off(a1, a2);
   3.628 +    }
   3.629 +    end = System.currentTimeMillis();
   3.630 +    System.out.println("test_2ci_off: " + (end - start));
   3.631 +    start = System.currentTimeMillis();
   3.632 +    for (int i=0; i<ITERS; i++) {
   3.633 +      test_2vi_off(a1, a2, 123, 103);
   3.634 +    }
   3.635 +    end = System.currentTimeMillis();
   3.636 +    System.out.println("test_2vi_off: " + (end - start));
   3.637 +
   3.638 +    start = System.currentTimeMillis();
   3.639 +    for (int i=0; i<ITERS; i++) {
   3.640 +      test_ci_inv(a1, OFFSET, 123);
   3.641 +    }
   3.642 +    end = System.currentTimeMillis();
   3.643 +    System.out.println("test_ci_inv: " + (end - start));
   3.644 +    start = System.currentTimeMillis();
   3.645 +    for (int i=0; i<ITERS; i++) {
   3.646 +      test_vi_inv(a2, 123, OFFSET, 103);
   3.647 +    }
   3.648 +    end = System.currentTimeMillis();
   3.649 +    System.out.println("test_vi_inv: " + (end - start));
   3.650 +    start = System.currentTimeMillis();
   3.651 +    for (int i=0; i<ITERS; i++) {
   3.652 +      test_cp_inv(a1, a2, OFFSET);
   3.653 +    }
   3.654 +    end = System.currentTimeMillis();
   3.655 +    System.out.println("test_cp_inv: " + (end - start));
   3.656 +    start = System.currentTimeMillis();
   3.657 +    for (int i=0; i<ITERS; i++) {
   3.658 +      test_2ci_inv(a1, a2, OFFSET);
   3.659 +    }
   3.660 +    end = System.currentTimeMillis();
   3.661 +    System.out.println("test_2ci_inv: " + (end - start));
   3.662 +    start = System.currentTimeMillis();
   3.663 +    for (int i=0; i<ITERS; i++) {
   3.664 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   3.665 +    }
   3.666 +    end = System.currentTimeMillis();
   3.667 +    System.out.println("test_2vi_inv: " + (end - start));
   3.668 +
   3.669 +    start = System.currentTimeMillis();
   3.670 +    for (int i=0; i<ITERS; i++) {
   3.671 +      test_ci_scl(a1, 123);
   3.672 +    }
   3.673 +    end = System.currentTimeMillis();
   3.674 +    System.out.println("test_ci_scl: " + (end - start));
   3.675 +    start = System.currentTimeMillis();
   3.676 +    for (int i=0; i<ITERS; i++) {
   3.677 +      test_vi_scl(a2, 123, 103);
   3.678 +    }
   3.679 +    end = System.currentTimeMillis();
   3.680 +    System.out.println("test_vi_scl: " + (end - start));
   3.681 +    start = System.currentTimeMillis();
   3.682 +    for (int i=0; i<ITERS; i++) {
   3.683 +      test_cp_scl(a1, a2);
   3.684 +    }
   3.685 +    end = System.currentTimeMillis();
   3.686 +    System.out.println("test_cp_scl: " + (end - start));
   3.687 +    start = System.currentTimeMillis();
   3.688 +    for (int i=0; i<ITERS; i++) {
   3.689 +      test_2ci_scl(a1, a2);
   3.690 +    }
   3.691 +    end = System.currentTimeMillis();
   3.692 +    System.out.println("test_2ci_scl: " + (end - start));
   3.693 +    start = System.currentTimeMillis();
   3.694 +    for (int i=0; i<ITERS; i++) {
   3.695 +      test_2vi_scl(a1, a2, 123, 103);
   3.696 +    }
   3.697 +    end = System.currentTimeMillis();
   3.698 +    System.out.println("test_2vi_scl: " + (end - start));
   3.699 +
   3.700 +    start = System.currentTimeMillis();
   3.701 +    for (int i=0; i<ITERS; i++) {
   3.702 +      test_cp_alndst(a1, a2);
   3.703 +    }
   3.704 +    end = System.currentTimeMillis();
   3.705 +    System.out.println("test_cp_alndst: " + (end - start));
   3.706 +    start = System.currentTimeMillis();
   3.707 +    for (int i=0; i<ITERS; i++) {
   3.708 +      test_cp_alnsrc(a1, a2);
   3.709 +    }
   3.710 +    end = System.currentTimeMillis();
   3.711 +    System.out.println("test_cp_alnsrc: " + (end - start));
   3.712 +    start = System.currentTimeMillis();
   3.713 +    for (int i=0; i<ITERS; i++) {
   3.714 +      test_2ci_aln(a1, a2);
   3.715 +    }
   3.716 +    end = System.currentTimeMillis();
   3.717 +    System.out.println("test_2ci_aln: " + (end - start));
   3.718 +    start = System.currentTimeMillis();
   3.719 +    for (int i=0; i<ITERS; i++) {
   3.720 +      test_2vi_aln(a1, a2, 123, 103);
   3.721 +    }
   3.722 +    end = System.currentTimeMillis();
   3.723 +    System.out.println("test_2vi_aln: " + (end - start));
   3.724 +
   3.725 +    start = System.currentTimeMillis();
   3.726 +    for (int i=0; i<ITERS; i++) {
   3.727 +      test_cp_unalndst(a1, a2);
   3.728 +    }
   3.729 +    end = System.currentTimeMillis();
   3.730 +    System.out.println("test_cp_unalndst: " + (end - start));
   3.731 +    start = System.currentTimeMillis();
   3.732 +    for (int i=0; i<ITERS; i++) {
   3.733 +      test_cp_unalnsrc(a1, a2);
   3.734 +    }
   3.735 +    end = System.currentTimeMillis();
   3.736 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   3.737 +    start = System.currentTimeMillis();
   3.738 +    for (int i=0; i<ITERS; i++) {
   3.739 +      test_2ci_unaln(a1, a2);
   3.740 +    }
   3.741 +    end = System.currentTimeMillis();
   3.742 +    System.out.println("test_2ci_unaln: " + (end - start));
   3.743 +    start = System.currentTimeMillis();
   3.744 +    for (int i=0; i<ITERS; i++) {
   3.745 +      test_2vi_unaln(a1, a2, 123, 103);
   3.746 +    }
   3.747 +    end = System.currentTimeMillis();
   3.748 +    System.out.println("test_2vi_unaln: " + (end - start));
   3.749 +
   3.750 +    return errn;
   3.751 +  }
   3.752 +
   3.753 +  static void test_ci(AtomicIntegerArray a) {
   3.754 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.755 +      a.compareAndSet(i, -1, -123);
   3.756 +    }
   3.757 +  }
   3.758 +  static void test_vi(AtomicIntegerArray a, int b, int old) {
   3.759 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.760 +      a.compareAndSet(i, old, b);
   3.761 +    }
   3.762 +  }
   3.763 +  static void test_cp(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.764 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.765 +      a.compareAndSet(i, -123, b.get(i));
   3.766 +    }
   3.767 +  }
   3.768 +  static void test_2ci(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.769 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.770 +      a.compareAndSet(i, 123, -123);
   3.771 +      b.compareAndSet(i, 123, -103);
   3.772 +    }
   3.773 +  }
   3.774 +  static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.776 +      a.compareAndSet(i, -123, c);
   3.777 +      b.compareAndSet(i, -103, d);
   3.778 +    }
   3.779 +  }
   3.780 +  static void test_ci_neg(AtomicIntegerArray a, int old) {
   3.781 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   3.782 +      a.compareAndSet(i, old, -123);
   3.783 +    }
   3.784 +  }
   3.785 +  static void test_vi_neg(AtomicIntegerArray a, int b, int old) {
   3.786 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   3.787 +      a.compareAndSet(i, old, b);
   3.788 +    }
   3.789 +  }
   3.790 +  static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.791 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   3.792 +      a.compareAndSet(i, -123, b.get(i));
   3.793 +    }
   3.794 +  }
   3.795 +  static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.796 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   3.797 +      a.compareAndSet(i, 123, -123);
   3.798 +      b.compareAndSet(i, 123, -103);
   3.799 +    }
   3.800 +  }
   3.801 +  static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   3.803 +      a.compareAndSet(i, -123, c);
   3.804 +      b.compareAndSet(i, -103, d);
   3.805 +    }
   3.806 +  }
   3.807 +  static void test_ci_oppos(AtomicIntegerArray a, int old) {
   3.808 +    int limit = ARRLEN-1;
   3.809 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.810 +      a.compareAndSet((limit-i), old, -123);
   3.811 +    }
   3.812 +  }
   3.813 +  static void test_vi_oppos(AtomicIntegerArray a, int b, int old) {
   3.814 +    int limit = ARRLEN-1;
   3.815 +    for (int i = limit; i >= 0; i-=1) {
   3.816 +      a.compareAndSet((limit-i), old, b);
   3.817 +    }
   3.818 +  }
   3.819 +  static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.820 +    int limit = ARRLEN-1;
   3.821 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.822 +      a.compareAndSet(i, -123, b.get(limit-i));
   3.823 +    }
   3.824 +  }
   3.825 +  static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.826 +    int limit = ARRLEN-1;
   3.827 +    for (int i = 0; i < ARRLEN; i+=1) {
   3.828 +      a.compareAndSet((limit-i), 123, -123);
   3.829 +      b.compareAndSet(i, 123, -103);
   3.830 +    }
   3.831 +  }
   3.832 +  static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.833 +    int limit = ARRLEN-1;
   3.834 +    for (int i = limit; i >= 0; i-=1) {
   3.835 +      a.compareAndSet(i, -123, c);
   3.836 +      b.compareAndSet((limit-i), -103, d);
   3.837 +    }
   3.838 +  }
   3.839 +  static void test_ci_off(AtomicIntegerArray a, int old) {
   3.840 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   3.841 +      a.compareAndSet((i+OFFSET), old, -123);
   3.842 +    }
   3.843 +  }
   3.844 +  static void test_vi_off(AtomicIntegerArray a, int b, int old) {
   3.845 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   3.846 +      a.compareAndSet((i+OFFSET), old, b);
   3.847 +    }
   3.848 +  }
   3.849 +  static void test_cp_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.850 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   3.851 +      a.compareAndSet((i+OFFSET), -123, b.get(i+OFFSET));
   3.852 +    }
   3.853 +  }
   3.854 +  static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.855 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   3.856 +      a.compareAndSet((i+OFFSET), 123, -123);
   3.857 +      b.compareAndSet((i+OFFSET), 123, -103);
   3.858 +    }
   3.859 +  }
   3.860 +  static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   3.862 +      a.compareAndSet((i+OFFSET), -123, c);
   3.863 +      b.compareAndSet((i+OFFSET), -103, d);
   3.864 +    }
   3.865 +  }
   3.866 +  static void test_ci_inv(AtomicIntegerArray a, int k, int old) {
   3.867 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   3.868 +      a.compareAndSet((i+k), old, -123);
   3.869 +    }
   3.870 +  }
   3.871 +  static void test_vi_inv(AtomicIntegerArray a, int b, int k, int old) {
   3.872 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   3.873 +      a.compareAndSet((i+k), old, b);
   3.874 +    }
   3.875 +  }
   3.876 +  static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   3.877 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   3.878 +      a.compareAndSet((i+k), -123, b.get(i+k));
   3.879 +    }
   3.880 +  }
   3.881 +  static void test_2ci_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   3.882 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   3.883 +      a.compareAndSet((i+k), 123, -123);
   3.884 +      b.compareAndSet((i+k), 123, -103);
   3.885 +    }
   3.886 +  }
   3.887 +  static void test_2vi_inv(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d, int k) {
   3.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   3.889 +      a.compareAndSet((i+k), -123, c);
   3.890 +      b.compareAndSet((i+k), -103, d);
   3.891 +    }
   3.892 +  }
   3.893 +  static void test_ci_scl(AtomicIntegerArray a, int old) {
   3.894 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   3.895 +      a.compareAndSet((i*SCALE), old, -123);
   3.896 +    }
   3.897 +  }
   3.898 +  static void test_vi_scl(AtomicIntegerArray a, int b, int old) {
   3.899 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   3.900 +      a.compareAndSet((i*SCALE), old, b);
   3.901 +    }
   3.902 +  }
   3.903 +  static void test_cp_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.904 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   3.905 +      a.compareAndSet((i*SCALE), -123, b.get(i*SCALE));
   3.906 +    }
   3.907 +  }
   3.908 +  static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.909 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   3.910 +      a.compareAndSet((i*SCALE), 123, -123);
   3.911 +      b.compareAndSet((i*SCALE), 123, -103);
   3.912 +    }
   3.913 +  }
   3.914 +  static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   3.916 +      a.compareAndSet((i*SCALE), -123, c);
   3.917 +      b.compareAndSet((i*SCALE), -103, d);
   3.918 +    }
   3.919 +  }
   3.920 +  static void test_cp_alndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.921 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   3.922 +      a.compareAndSet((i+ALIGN_OFF), -1, b.get(i));
   3.923 +    }
   3.924 +  }
   3.925 +  static void test_cp_alnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.926 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   3.927 +      a.getAndSet(i, b.get(i+ALIGN_OFF));
   3.928 +    }
   3.929 +  }
   3.930 +  static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.931 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   3.932 +      a.compareAndSet((i+ALIGN_OFF), -1, -123);
   3.933 +      b.getAndSet(i, -103);
   3.934 +    }
   3.935 +  }
   3.936 +  static void test_2vi_aln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.937 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   3.938 +      a.getAndSet(i, c);
   3.939 +      b.getAndSet((i+ALIGN_OFF), d);
   3.940 +    }
   3.941 +  }
   3.942 +  static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.943 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   3.944 +      a.compareAndSet((i+UNALIGN_OFF), -1, b.get(i));
   3.945 +    }
   3.946 +  }
   3.947 +  static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.948 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   3.949 +      a.getAndSet(i, b.get(i+UNALIGN_OFF));
   3.950 +    }
   3.951 +  }
   3.952 +  static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) {
   3.953 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   3.954 +      a.compareAndSet((i+UNALIGN_OFF), -1, -123);
   3.955 +      b.getAndSet(i, -103);
   3.956 +    }
   3.957 +  }
   3.958 +  static void test_2vi_unaln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   3.959 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   3.960 +      a.getAndSet(i, c);
   3.961 +      b.getAndSet((i+UNALIGN_OFF), d);
   3.962 +    }
   3.963 +  }
   3.964 +
   3.965 +  static int verify(String text, int i, int elem, int val) {
   3.966 +    if (elem != val) {
   3.967 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   3.968 +      return 1;
   3.969 +    }
   3.970 +    return 0;
   3.971 +  }
   3.972 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/compiler/8004867/TestIntAtomicOrdered.java	Mon Feb 18 16:47:15 2013 -0800
     4.3 @@ -0,0 +1,969 @@
     4.4 +/*
     4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + *
    4.26 + */
    4.27 +
    4.28 +/**
    4.29 + * @test
    4.30 + * @bug 8004867
    4.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    4.32 + *
    4.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntAtomicOrdered
    4.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntAtomicOrdered
    4.35 + */
    4.36 +
    4.37 +import java.util.concurrent.atomic.AtomicIntegerArray;
    4.38 +
    4.39 +public class TestIntAtomicOrdered {
    4.40 +  private static final int ARRLEN = 97;
    4.41 +  private static final int ITERS  = 11000;
    4.42 +  private static final int OFFSET = 3;
    4.43 +  private static final int SCALE = 2;
    4.44 +  private static final int ALIGN_OFF = 8;
    4.45 +  private static final int UNALIGN_OFF = 5;
    4.46 +
    4.47 +  public static void main(String args[]) {
    4.48 +    System.out.println("Testing Integer array atomic ordered operations");
    4.49 +    int errn = test(false);
    4.50 +    if (errn > 0) {
    4.51 +      System.err.println("FAILED: " + errn + " errors");
    4.52 +      System.exit(97);
    4.53 +    }
    4.54 +    System.out.println("PASSED");
    4.55 +  }
    4.56 +
    4.57 +  static int test(boolean test_only) {
    4.58 +    AtomicIntegerArray a1 = new AtomicIntegerArray(ARRLEN);
    4.59 +    AtomicIntegerArray a2 = new AtomicIntegerArray(ARRLEN);
    4.60 +    // Initialize
    4.61 +    for (int i=0; i<ARRLEN; i++) {
    4.62 +      a1.lazySet(i, -1);
    4.63 +      a2.lazySet(i, -1);
    4.64 +    }
    4.65 +    System.out.println("Warmup");
    4.66 +    for (int i=0; i<ITERS; i++) {
    4.67 +      test_ci(a1);
    4.68 +      test_vi(a2, 123, -1);
    4.69 +      test_cp(a1, a2);
    4.70 +      test_2ci(a1, a2);
    4.71 +      test_2vi(a1, a2, 123, 103);
    4.72 +      test_ci_neg(a1, 123);
    4.73 +      test_vi_neg(a2, 123, 103);
    4.74 +      test_cp_neg(a1, a2);
    4.75 +      test_2ci_neg(a1, a2);
    4.76 +      test_2vi_neg(a1, a2, 123, 103);
    4.77 +      test_ci_oppos(a1, 123);
    4.78 +      test_vi_oppos(a2, 123, 103);
    4.79 +      test_cp_oppos(a1, a2);
    4.80 +      test_2ci_oppos(a1, a2);
    4.81 +      test_2vi_oppos(a1, a2, 123, 103);
    4.82 +      test_ci_off(a1, 123);
    4.83 +      test_vi_off(a2, 123, 103);
    4.84 +      test_cp_off(a1, a2);
    4.85 +      test_2ci_off(a1, a2);
    4.86 +      test_2vi_off(a1, a2, 123, 103);
    4.87 +      test_ci_inv(a1, OFFSET, 123);
    4.88 +      test_vi_inv(a2, 123, OFFSET, 103);
    4.89 +      test_cp_inv(a1, a2, OFFSET);
    4.90 +      test_2ci_inv(a1, a2, OFFSET);
    4.91 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
    4.92 +      test_ci_scl(a1, 123);
    4.93 +      test_vi_scl(a2, 123, 103);
    4.94 +      test_cp_scl(a1, a2);
    4.95 +      test_2ci_scl(a1, a2);
    4.96 +      test_2vi_scl(a1, a2, 123, 103);
    4.97 +      test_cp_alndst(a1, a2);
    4.98 +      test_cp_alnsrc(a1, a2);
    4.99 +      test_2ci_aln(a1, a2);
   4.100 +      test_2vi_aln(a1, a2, 123, 103);
   4.101 +      test_cp_unalndst(a1, a2);
   4.102 +      test_cp_unalnsrc(a1, a2);
   4.103 +      test_2ci_unaln(a1, a2);
   4.104 +      test_2vi_unaln(a1, a2, 123, 103);
   4.105 +    }
   4.106 +    // Initialize
   4.107 +    for (int i=0; i<ARRLEN; i++) {
   4.108 +      a1.lazySet(i, -1);
   4.109 +      a2.lazySet(i, -1);
   4.110 +    }
   4.111 +    // Test and verify results
   4.112 +    System.out.println("Verification");
   4.113 +    int errn = 0;
   4.114 +    {
   4.115 +      test_ci(a1);
   4.116 +      for (int i=0; i<ARRLEN; i++) {
   4.117 +        errn += verify("test_ci: a1", i, a1.get(i), -123);
   4.118 +      }
   4.119 +      test_vi(a2, 123, -1);
   4.120 +      for (int i=0; i<ARRLEN; i++) {
   4.121 +        errn += verify("test_vi: a2", i, a2.get(i), 123);
   4.122 +      }
   4.123 +      test_cp(a1, a2);
   4.124 +      for (int i=0; i<ARRLEN; i++) {
   4.125 +        errn += verify("test_cp: a1", i, a1.get(i), 123);
   4.126 +      }
   4.127 +      test_2ci(a1, a2);
   4.128 +      for (int i=0; i<ARRLEN; i++) {
   4.129 +        errn += verify("test_2ci: a1", i, a1.get(i), -123);
   4.130 +        errn += verify("test_2ci: a2", i, a2.get(i), -103);
   4.131 +      }
   4.132 +      test_2vi(a1, a2, 123, 103);
   4.133 +      for (int i=0; i<ARRLEN; i++) {
   4.134 +        errn += verify("test_2vi: a1", i, a1.get(i), 123);
   4.135 +        errn += verify("test_2vi: a2", i, a2.get(i), 103);
   4.136 +      }
   4.137 +      // Reset for negative stride
   4.138 +      for (int i=0; i<ARRLEN; i++) {
   4.139 +        a1.lazySet(i, -1);
   4.140 +        a2.lazySet(i, -1);
   4.141 +      }
   4.142 +      test_ci_neg(a1, -1);
   4.143 +      for (int i=0; i<ARRLEN; i++) {
   4.144 +        errn += verify("test_ci_neg: a1", i, a1.get(i), -123);
   4.145 +      }
   4.146 +      test_vi_neg(a2, 123, -1);
   4.147 +      for (int i=0; i<ARRLEN; i++) {
   4.148 +        errn += verify("test_vi_neg: a2", i, a2.get(i), 123);
   4.149 +      }
   4.150 +      test_cp_neg(a1, a2);
   4.151 +      for (int i=0; i<ARRLEN; i++) {
   4.152 +        errn += verify("test_cp_neg: a1", i, a1.get(i), 123);
   4.153 +      }
   4.154 +      test_2ci_neg(a1, a2);
   4.155 +      for (int i=0; i<ARRLEN; i++) {
   4.156 +        errn += verify("test_2ci_neg: a1", i, a1.get(i), -123);
   4.157 +        errn += verify("test_2ci_neg: a2", i, a2.get(i), -103);
   4.158 +      }
   4.159 +      test_2vi_neg(a1, a2, 123, 103);
   4.160 +      for (int i=0; i<ARRLEN; i++) {
   4.161 +        errn += verify("test_2vi_neg: a1", i, a1.get(i), 123);
   4.162 +        errn += verify("test_2vi_neg: a2", i, a2.get(i), 103);
   4.163 +      }
   4.164 +      // Reset for opposite stride
   4.165 +      for (int i=0; i<ARRLEN; i++) {
   4.166 +        a1.lazySet(i, -1);
   4.167 +        a2.lazySet(i, -1);
   4.168 +      }
   4.169 +      test_ci_oppos(a1, -1);
   4.170 +      for (int i=0; i<ARRLEN; i++) {
   4.171 +        errn += verify("test_ci_oppos: a1", i, a1.get(i), -123);
   4.172 +      }
   4.173 +      test_vi_oppos(a2, 123, -1);
   4.174 +      for (int i=0; i<ARRLEN; i++) {
   4.175 +        errn += verify("test_vi_oppos: a2", i, a2.get(i), 123);
   4.176 +      }
   4.177 +      test_cp_oppos(a1, a2);
   4.178 +      for (int i=0; i<ARRLEN; i++) {
   4.179 +        errn += verify("test_cp_oppos: a1", i, a1.get(i), 123);
   4.180 +      }
   4.181 +      test_2ci_oppos(a1, a2);
   4.182 +      for (int i=0; i<ARRLEN; i++) {
   4.183 +        errn += verify("test_2ci_oppos: a1", i, a1.get(i), -123);
   4.184 +        errn += verify("test_2ci_oppos: a2", i, a2.get(i), -103);
   4.185 +      }
   4.186 +      test_2vi_oppos(a1, a2, 123, 103);
   4.187 +      for (int i=0; i<ARRLEN; i++) {
   4.188 +        errn += verify("test_2vi_oppos: a1", i, a1.get(i), 123);
   4.189 +        errn += verify("test_2vi_oppos: a2", i, a2.get(i), 103);
   4.190 +      }
   4.191 +      // Reset for indexing with offset
   4.192 +      for (int i=0; i<ARRLEN; i++) {
   4.193 +        a1.lazySet(i, -1);
   4.194 +        a2.lazySet(i, -1);
   4.195 +      }
   4.196 +      test_ci_off(a1, -1);
   4.197 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.198 +        errn += verify("test_ci_off: a1", i, a1.get(i), -123);
   4.199 +      }
   4.200 +      test_vi_off(a2, 123, -1);
   4.201 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.202 +        errn += verify("test_vi_off: a2", i, a2.get(i), 123);
   4.203 +      }
   4.204 +      test_cp_off(a1, a2);
   4.205 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.206 +        errn += verify("test_cp_off: a1", i, a1.get(i), 123);
   4.207 +      }
   4.208 +      test_2ci_off(a1, a2);
   4.209 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.210 +        errn += verify("test_2ci_off: a1", i, a1.get(i), -123);
   4.211 +        errn += verify("test_2ci_off: a2", i, a2.get(i), -103);
   4.212 +      }
   4.213 +      test_2vi_off(a1, a2, 123, 103);
   4.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.215 +        errn += verify("test_2vi_off: a1", i, a1.get(i), 123);
   4.216 +        errn += verify("test_2vi_off: a2", i, a2.get(i), 103);
   4.217 +      }
   4.218 +      for (int i=0; i<OFFSET; i++) {
   4.219 +        errn += verify("test_2vi_off: a1", i, a1.get(i), -1);
   4.220 +        errn += verify("test_2vi_off: a2", i, a2.get(i), -1);
   4.221 +      }
   4.222 +      // Reset for indexing with invariant offset
   4.223 +      for (int i=0; i<ARRLEN; i++) {
   4.224 +        a1.lazySet(i, -1);
   4.225 +        a2.lazySet(i, -1);
   4.226 +      }
   4.227 +      test_ci_inv(a1, OFFSET, -1);
   4.228 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.229 +        errn += verify("test_ci_inv: a1", i, a1.get(i), -123);
   4.230 +      }
   4.231 +      test_vi_inv(a2, 123, OFFSET, -1);
   4.232 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.233 +        errn += verify("test_vi_inv: a2", i, a2.get(i), 123);
   4.234 +      }
   4.235 +      test_cp_inv(a1, a2, OFFSET);
   4.236 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.237 +        errn += verify("test_cp_inv: a1", i, a1.get(i), 123);
   4.238 +      }
   4.239 +      test_2ci_inv(a1, a2, OFFSET);
   4.240 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.241 +        errn += verify("test_2ci_inv: a1", i, a1.get(i), -123);
   4.242 +        errn += verify("test_2ci_inv: a2", i, a2.get(i), -103);
   4.243 +      }
   4.244 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   4.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   4.246 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), 123);
   4.247 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), 103);
   4.248 +      }
   4.249 +      for (int i=0; i<OFFSET; i++) {
   4.250 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), -1);
   4.251 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), -1);
   4.252 +      }
   4.253 +      // Reset for indexing with scale
   4.254 +      for (int i=0; i<ARRLEN; i++) {
   4.255 +        a1.lazySet(i, -1);
   4.256 +        a2.lazySet(i, -1);
   4.257 +      }
   4.258 +      test_ci_scl(a1, -1);
   4.259 +      for (int i=0; i<ARRLEN; i++) {
   4.260 +        int val = (i%SCALE != 0) ? -1 : -123;
   4.261 +        errn += verify("test_ci_scl: a1", i, a1.get(i), val);
   4.262 +      }
   4.263 +      test_vi_scl(a2, 123, -1);
   4.264 +      for (int i=0; i<ARRLEN; i++) {
   4.265 +        int val = (i%SCALE != 0) ? -1 : 123;
   4.266 +        errn += verify("test_vi_scl: a2", i, a2.get(i), val);
   4.267 +      }
   4.268 +      test_cp_scl(a1, a2);
   4.269 +      for (int i=0; i<ARRLEN; i++) {
   4.270 +        int val = (i%SCALE != 0) ? -1 : 123;
   4.271 +        errn += verify("test_cp_scl: a1", i, a1.get(i), val);
   4.272 +      }
   4.273 +      test_2ci_scl(a1, a2);
   4.274 +      for (int i=0; i<ARRLEN; i++) {
   4.275 +        if (i%SCALE != 0) {
   4.276 +          errn += verify("test_2ci_scl: a1", i, a1.get(i), -1);
   4.277 +        } else if (i*SCALE < ARRLEN) {
   4.278 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1.get(i*SCALE), -123);
   4.279 +        }
   4.280 +        if (i%SCALE != 0) {
   4.281 +          errn += verify("test_2ci_scl: a2", i, a2.get(i), -1);
   4.282 +        } else if (i*SCALE < ARRLEN) {
   4.283 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2.get(i*SCALE), -103);
   4.284 +        }
   4.285 +      }
   4.286 +      test_2vi_scl(a1, a2, 123, 103);
   4.287 +      for (int i=0; i<ARRLEN; i++) {
   4.288 +        if (i%SCALE != 0) {
   4.289 +          errn += verify("test_2vi_scl: a1", i, a1.get(i), -1);
   4.290 +        } else if (i*SCALE < ARRLEN) {
   4.291 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1.get(i*SCALE), 123);
   4.292 +        }
   4.293 +        if (i%SCALE != 0) {
   4.294 +          errn += verify("test_2vi_scl: a2", i, a2.get(i), -1);
   4.295 +        } else if (i*SCALE < ARRLEN) {
   4.296 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2.get(i*SCALE), 103);
   4.297 +        }
   4.298 +      }
   4.299 +      // Reset for 2 arrays with relative aligned offset
   4.300 +      for (int i=0; i<ARRLEN; i++) {
   4.301 +        a1.lazySet(i, -1);
   4.302 +        a2.lazySet(i, -1);
   4.303 +      }
   4.304 +      test_vi(a2, 123, -1);
   4.305 +      test_cp_alndst(a1, a2);
   4.306 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.307 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), -1);
   4.308 +      }
   4.309 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   4.310 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), 123);
   4.311 +      }
   4.312 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.313 +        a1.lazySet(i, 123);
   4.314 +      }
   4.315 +      test_vi(a2, -123, 123);
   4.316 +      test_cp_alnsrc(a1, a2);
   4.317 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   4.318 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), -123);
   4.319 +      }
   4.320 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   4.321 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), 123);
   4.322 +      }
   4.323 +      for (int i=0; i<ARRLEN; i++) {
   4.324 +        a1.lazySet(i, -1);
   4.325 +        a2.lazySet(i, -1);
   4.326 +      }
   4.327 +      test_2ci_aln(a1, a2);
   4.328 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.329 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -1);
   4.330 +      }
   4.331 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   4.332 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -123);
   4.333 +      }
   4.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   4.335 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -103);
   4.336 +      }
   4.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   4.338 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -1);
   4.339 +      }
   4.340 +      for (int i=0; i<ARRLEN; i++) {
   4.341 +        a1.lazySet(i, -1);
   4.342 +        a2.lazySet(i, -1);
   4.343 +      }
   4.344 +      test_2vi_aln(a1, a2, 123, 103);
   4.345 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   4.346 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), 123);
   4.347 +      }
   4.348 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   4.349 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), -1);
   4.350 +      }
   4.351 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.352 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), -1);
   4.353 +      }
   4.354 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   4.355 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), 103);
   4.356 +      }
   4.357 +
   4.358 +      // Reset for 2 arrays with relative unaligned offset
   4.359 +      for (int i=0; i<ARRLEN; i++) {
   4.360 +        a1.lazySet(i, -1);
   4.361 +        a2.lazySet(i, -1);
   4.362 +      }
   4.363 +      test_vi(a2, 123, -1);
   4.364 +      test_cp_unalndst(a1, a2);
   4.365 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.366 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), -1);
   4.367 +      }
   4.368 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   4.369 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), 123);
   4.370 +      }
   4.371 +      test_vi(a2, -123, 123);
   4.372 +      test_cp_unalnsrc(a1, a2);
   4.373 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   4.374 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), -123);
   4.375 +      }
   4.376 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   4.377 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), 123);
   4.378 +      }
   4.379 +      for (int i=0; i<ARRLEN; i++) {
   4.380 +        a1.lazySet(i, -1);
   4.381 +        a2.lazySet(i, -1);
   4.382 +      }
   4.383 +      test_2ci_unaln(a1, a2);
   4.384 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.385 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -1);
   4.386 +      }
   4.387 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   4.388 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -123);
   4.389 +      }
   4.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   4.391 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -103);
   4.392 +      }
   4.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   4.394 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -1);
   4.395 +      }
   4.396 +      for (int i=0; i<ARRLEN; i++) {
   4.397 +        a1.lazySet(i, -1);
   4.398 +        a2.lazySet(i, -1);
   4.399 +      }
   4.400 +      test_2vi_unaln(a1, a2, 123, 103);
   4.401 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   4.402 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), 123);
   4.403 +      }
   4.404 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   4.405 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), -1);
   4.406 +      }
   4.407 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.408 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), -1);
   4.409 +      }
   4.410 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   4.411 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), 103);
   4.412 +      }
   4.413 +
   4.414 +      // Reset for aligned overlap initialization
   4.415 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.416 +        a1.lazySet(i, i);
   4.417 +      }
   4.418 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   4.419 +        a1.lazySet(i, -1);
   4.420 +      }
   4.421 +      test_cp_alndst(a1, a1);
   4.422 +      for (int i=0; i<ARRLEN; i++) {
   4.423 +        int v = i%ALIGN_OFF;
   4.424 +        errn += verify("test_cp_alndst_overlap: a1", i, a1.get(i), v);
   4.425 +      }
   4.426 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.427 +        a1.lazySet((i+ALIGN_OFF), -1);
   4.428 +      }
   4.429 +      test_cp_alnsrc(a1, a1);
   4.430 +      for (int i=0; i<ALIGN_OFF; i++) {
   4.431 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), -1);
   4.432 +      }
   4.433 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   4.434 +        int v = i%ALIGN_OFF;
   4.435 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), v);
   4.436 +      }
   4.437 +      for (int i=0; i<ARRLEN; i++) {
   4.438 +        a1.lazySet(i, -1);
   4.439 +      }
   4.440 +      test_2ci_aln(a1, a1);
   4.441 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   4.442 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -103);
   4.443 +      }
   4.444 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   4.445 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -123);
   4.446 +      }
   4.447 +      for (int i=0; i<ARRLEN; i++) {
   4.448 +        a1.lazySet(i, -1);
   4.449 +      }
   4.450 +      test_2vi_aln(a1, a1, 123, 103);
   4.451 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   4.452 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 123);
   4.453 +      }
   4.454 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   4.455 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 103);
   4.456 +      }
   4.457 +
   4.458 +      // Reset for unaligned overlap initialization
   4.459 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.460 +        a1.lazySet(i, i);
   4.461 +      }
   4.462 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   4.463 +        a1.lazySet(i, -1);
   4.464 +      }
   4.465 +      test_cp_unalndst(a1, a1);
   4.466 +      for (int i=0; i<ARRLEN; i++) {
   4.467 +        int v = i%UNALIGN_OFF;
   4.468 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1.get(i), v);
   4.469 +      }
   4.470 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.471 +        a1.lazySet((i+UNALIGN_OFF), -1);
   4.472 +      }
   4.473 +      test_cp_unalnsrc(a1, a1);
   4.474 +      for (int i=0; i<UNALIGN_OFF; i++) {
   4.475 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), -1);
   4.476 +      }
   4.477 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   4.478 +        int v = i%UNALIGN_OFF;
   4.479 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), v);
   4.480 +      }
   4.481 +      for (int i=0; i<ARRLEN; i++) {
   4.482 +        a1.lazySet(i, -1);
   4.483 +      }
   4.484 +      test_2ci_unaln(a1, a1);
   4.485 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   4.486 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -103);
   4.487 +      }
   4.488 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   4.489 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -123);
   4.490 +      }
   4.491 +      for (int i=0; i<ARRLEN; i++) {
   4.492 +        a1.lazySet(i, -1);
   4.493 +      }
   4.494 +      test_2vi_unaln(a1, a1, 123, 103);
   4.495 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   4.496 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 123);
   4.497 +      }
   4.498 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   4.499 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 103);
   4.500 +      }
   4.501 +
   4.502 +    }
   4.503 +
   4.504 +    if (errn > 0 || test_only)
   4.505 +      return errn;
   4.506 +
   4.507 +    // Initialize
   4.508 +    for (int i=0; i<ARRLEN; i++) {
   4.509 +      a1.lazySet(i, -1);
   4.510 +      a2.lazySet(i, -1);
   4.511 +    }
   4.512 +    System.out.println("Time");
   4.513 +    long start, end;
   4.514 +    start = System.currentTimeMillis();
   4.515 +    for (int i=0; i<ITERS; i++) {
   4.516 +      test_ci(a1);
   4.517 +    }
   4.518 +    end = System.currentTimeMillis();
   4.519 +    System.out.println("test_ci: " + (end - start));
   4.520 +    start = System.currentTimeMillis();
   4.521 +    for (int i=0; i<ITERS; i++) {
   4.522 +      test_vi(a2, 123, -1);
   4.523 +    }
   4.524 +    end = System.currentTimeMillis();
   4.525 +    System.out.println("test_vi: " + (end - start));
   4.526 +    start = System.currentTimeMillis();
   4.527 +    for (int i=0; i<ITERS; i++) {
   4.528 +      test_cp(a1, a2);
   4.529 +    }
   4.530 +    end = System.currentTimeMillis();
   4.531 +    System.out.println("test_cp: " + (end - start));
   4.532 +    start = System.currentTimeMillis();
   4.533 +    for (int i=0; i<ITERS; i++) {
   4.534 +      test_2ci(a1, a2);
   4.535 +    }
   4.536 +    end = System.currentTimeMillis();
   4.537 +    System.out.println("test_2ci: " + (end - start));
   4.538 +    start = System.currentTimeMillis();
   4.539 +    for (int i=0; i<ITERS; i++) {
   4.540 +      test_2vi(a1, a2, 123, 103);
   4.541 +    }
   4.542 +    end = System.currentTimeMillis();
   4.543 +    System.out.println("test_2vi: " + (end - start));
   4.544 +
   4.545 +    start = System.currentTimeMillis();
   4.546 +    for (int i=0; i<ITERS; i++) {
   4.547 +      test_ci_neg(a1, 123);
   4.548 +    }
   4.549 +    end = System.currentTimeMillis();
   4.550 +    System.out.println("test_ci_neg: " + (end - start));
   4.551 +    start = System.currentTimeMillis();
   4.552 +    for (int i=0; i<ITERS; i++) {
   4.553 +      test_vi_neg(a2, 123, 103);
   4.554 +    }
   4.555 +    end = System.currentTimeMillis();
   4.556 +    System.out.println("test_vi_neg: " + (end - start));
   4.557 +    start = System.currentTimeMillis();
   4.558 +    for (int i=0; i<ITERS; i++) {
   4.559 +      test_cp_neg(a1, a2);
   4.560 +    }
   4.561 +    end = System.currentTimeMillis();
   4.562 +    System.out.println("test_cp_neg: " + (end - start));
   4.563 +    start = System.currentTimeMillis();
   4.564 +    for (int i=0; i<ITERS; i++) {
   4.565 +      test_2ci_neg(a1, a2);
   4.566 +    }
   4.567 +    end = System.currentTimeMillis();
   4.568 +    System.out.println("test_2ci_neg: " + (end - start));
   4.569 +    start = System.currentTimeMillis();
   4.570 +    for (int i=0; i<ITERS; i++) {
   4.571 +      test_2vi_neg(a1, a2, 123, 103);
   4.572 +    }
   4.573 +    end = System.currentTimeMillis();
   4.574 +    System.out.println("test_2vi_neg: " + (end - start));
   4.575 +
   4.576 +    start = System.currentTimeMillis();
   4.577 +    for (int i=0; i<ITERS; i++) {
   4.578 +      test_ci_oppos(a1, 123);
   4.579 +    }
   4.580 +    end = System.currentTimeMillis();
   4.581 +    System.out.println("test_ci_oppos: " + (end - start));
   4.582 +    start = System.currentTimeMillis();
   4.583 +    for (int i=0; i<ITERS; i++) {
   4.584 +      test_vi_oppos(a2, 123, 103);
   4.585 +    }
   4.586 +    end = System.currentTimeMillis();
   4.587 +    System.out.println("test_vi_oppos: " + (end - start));
   4.588 +    start = System.currentTimeMillis();
   4.589 +    for (int i=0; i<ITERS; i++) {
   4.590 +      test_cp_oppos(a1, a2);
   4.591 +    }
   4.592 +    end = System.currentTimeMillis();
   4.593 +    System.out.println("test_cp_oppos: " + (end - start));
   4.594 +    start = System.currentTimeMillis();
   4.595 +    for (int i=0; i<ITERS; i++) {
   4.596 +      test_2ci_oppos(a1, a2);
   4.597 +    }
   4.598 +    end = System.currentTimeMillis();
   4.599 +    System.out.println("test_2ci_oppos: " + (end - start));
   4.600 +    start = System.currentTimeMillis();
   4.601 +    for (int i=0; i<ITERS; i++) {
   4.602 +      test_2vi_oppos(a1, a2, 123, 103);
   4.603 +    }
   4.604 +    end = System.currentTimeMillis();
   4.605 +    System.out.println("test_2vi_oppos: " + (end - start));
   4.606 +
   4.607 +    start = System.currentTimeMillis();
   4.608 +    for (int i=0; i<ITERS; i++) {
   4.609 +      test_ci_off(a1, 123);
   4.610 +    }
   4.611 +    end = System.currentTimeMillis();
   4.612 +    System.out.println("test_ci_off: " + (end - start));
   4.613 +    start = System.currentTimeMillis();
   4.614 +    for (int i=0; i<ITERS; i++) {
   4.615 +      test_vi_off(a2, 123, 103);
   4.616 +    }
   4.617 +    end = System.currentTimeMillis();
   4.618 +    System.out.println("test_vi_off: " + (end - start));
   4.619 +    start = System.currentTimeMillis();
   4.620 +    for (int i=0; i<ITERS; i++) {
   4.621 +      test_cp_off(a1, a2);
   4.622 +    }
   4.623 +    end = System.currentTimeMillis();
   4.624 +    System.out.println("test_cp_off: " + (end - start));
   4.625 +    start = System.currentTimeMillis();
   4.626 +    for (int i=0; i<ITERS; i++) {
   4.627 +      test_2ci_off(a1, a2);
   4.628 +    }
   4.629 +    end = System.currentTimeMillis();
   4.630 +    System.out.println("test_2ci_off: " + (end - start));
   4.631 +    start = System.currentTimeMillis();
   4.632 +    for (int i=0; i<ITERS; i++) {
   4.633 +      test_2vi_off(a1, a2, 123, 103);
   4.634 +    }
   4.635 +    end = System.currentTimeMillis();
   4.636 +    System.out.println("test_2vi_off: " + (end - start));
   4.637 +
   4.638 +    start = System.currentTimeMillis();
   4.639 +    for (int i=0; i<ITERS; i++) {
   4.640 +      test_ci_inv(a1, OFFSET, 123);
   4.641 +    }
   4.642 +    end = System.currentTimeMillis();
   4.643 +    System.out.println("test_ci_inv: " + (end - start));
   4.644 +    start = System.currentTimeMillis();
   4.645 +    for (int i=0; i<ITERS; i++) {
   4.646 +      test_vi_inv(a2, 123, OFFSET, 103);
   4.647 +    }
   4.648 +    end = System.currentTimeMillis();
   4.649 +    System.out.println("test_vi_inv: " + (end - start));
   4.650 +    start = System.currentTimeMillis();
   4.651 +    for (int i=0; i<ITERS; i++) {
   4.652 +      test_cp_inv(a1, a2, OFFSET);
   4.653 +    }
   4.654 +    end = System.currentTimeMillis();
   4.655 +    System.out.println("test_cp_inv: " + (end - start));
   4.656 +    start = System.currentTimeMillis();
   4.657 +    for (int i=0; i<ITERS; i++) {
   4.658 +      test_2ci_inv(a1, a2, OFFSET);
   4.659 +    }
   4.660 +    end = System.currentTimeMillis();
   4.661 +    System.out.println("test_2ci_inv: " + (end - start));
   4.662 +    start = System.currentTimeMillis();
   4.663 +    for (int i=0; i<ITERS; i++) {
   4.664 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   4.665 +    }
   4.666 +    end = System.currentTimeMillis();
   4.667 +    System.out.println("test_2vi_inv: " + (end - start));
   4.668 +
   4.669 +    start = System.currentTimeMillis();
   4.670 +    for (int i=0; i<ITERS; i++) {
   4.671 +      test_ci_scl(a1, 123);
   4.672 +    }
   4.673 +    end = System.currentTimeMillis();
   4.674 +    System.out.println("test_ci_scl: " + (end - start));
   4.675 +    start = System.currentTimeMillis();
   4.676 +    for (int i=0; i<ITERS; i++) {
   4.677 +      test_vi_scl(a2, 123, 103);
   4.678 +    }
   4.679 +    end = System.currentTimeMillis();
   4.680 +    System.out.println("test_vi_scl: " + (end - start));
   4.681 +    start = System.currentTimeMillis();
   4.682 +    for (int i=0; i<ITERS; i++) {
   4.683 +      test_cp_scl(a1, a2);
   4.684 +    }
   4.685 +    end = System.currentTimeMillis();
   4.686 +    System.out.println("test_cp_scl: " + (end - start));
   4.687 +    start = System.currentTimeMillis();
   4.688 +    for (int i=0; i<ITERS; i++) {
   4.689 +      test_2ci_scl(a1, a2);
   4.690 +    }
   4.691 +    end = System.currentTimeMillis();
   4.692 +    System.out.println("test_2ci_scl: " + (end - start));
   4.693 +    start = System.currentTimeMillis();
   4.694 +    for (int i=0; i<ITERS; i++) {
   4.695 +      test_2vi_scl(a1, a2, 123, 103);
   4.696 +    }
   4.697 +    end = System.currentTimeMillis();
   4.698 +    System.out.println("test_2vi_scl: " + (end - start));
   4.699 +
   4.700 +    start = System.currentTimeMillis();
   4.701 +    for (int i=0; i<ITERS; i++) {
   4.702 +      test_cp_alndst(a1, a2);
   4.703 +    }
   4.704 +    end = System.currentTimeMillis();
   4.705 +    System.out.println("test_cp_alndst: " + (end - start));
   4.706 +    start = System.currentTimeMillis();
   4.707 +    for (int i=0; i<ITERS; i++) {
   4.708 +      test_cp_alnsrc(a1, a2);
   4.709 +    }
   4.710 +    end = System.currentTimeMillis();
   4.711 +    System.out.println("test_cp_alnsrc: " + (end - start));
   4.712 +    start = System.currentTimeMillis();
   4.713 +    for (int i=0; i<ITERS; i++) {
   4.714 +      test_2ci_aln(a1, a2);
   4.715 +    }
   4.716 +    end = System.currentTimeMillis();
   4.717 +    System.out.println("test_2ci_aln: " + (end - start));
   4.718 +    start = System.currentTimeMillis();
   4.719 +    for (int i=0; i<ITERS; i++) {
   4.720 +      test_2vi_aln(a1, a2, 123, 103);
   4.721 +    }
   4.722 +    end = System.currentTimeMillis();
   4.723 +    System.out.println("test_2vi_aln: " + (end - start));
   4.724 +
   4.725 +    start = System.currentTimeMillis();
   4.726 +    for (int i=0; i<ITERS; i++) {
   4.727 +      test_cp_unalndst(a1, a2);
   4.728 +    }
   4.729 +    end = System.currentTimeMillis();
   4.730 +    System.out.println("test_cp_unalndst: " + (end - start));
   4.731 +    start = System.currentTimeMillis();
   4.732 +    for (int i=0; i<ITERS; i++) {
   4.733 +      test_cp_unalnsrc(a1, a2);
   4.734 +    }
   4.735 +    end = System.currentTimeMillis();
   4.736 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   4.737 +    start = System.currentTimeMillis();
   4.738 +    for (int i=0; i<ITERS; i++) {
   4.739 +      test_2ci_unaln(a1, a2);
   4.740 +    }
   4.741 +    end = System.currentTimeMillis();
   4.742 +    System.out.println("test_2ci_unaln: " + (end - start));
   4.743 +    start = System.currentTimeMillis();
   4.744 +    for (int i=0; i<ITERS; i++) {
   4.745 +      test_2vi_unaln(a1, a2, 123, 103);
   4.746 +    }
   4.747 +    end = System.currentTimeMillis();
   4.748 +    System.out.println("test_2vi_unaln: " + (end - start));
   4.749 +
   4.750 +    return errn;
   4.751 +  }
   4.752 +
   4.753 +  static void test_ci(AtomicIntegerArray a) {
   4.754 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.755 +      a.lazySet(i, -123);
   4.756 +    }
   4.757 +  }
   4.758 +  static void test_vi(AtomicIntegerArray a, int b, int old) {
   4.759 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.760 +      a.lazySet(i, b);
   4.761 +    }
   4.762 +  }
   4.763 +  static void test_cp(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.764 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.765 +      a.lazySet(i, b.get(i));
   4.766 +    }
   4.767 +  }
   4.768 +  static void test_2ci(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.769 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.770 +      a.lazySet(i, -123);
   4.771 +      b.lazySet(i, -103);
   4.772 +    }
   4.773 +  }
   4.774 +  static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.776 +      a.lazySet(i, c);
   4.777 +      b.lazySet(i, d);
   4.778 +    }
   4.779 +  }
   4.780 +  static void test_ci_neg(AtomicIntegerArray a, int old) {
   4.781 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   4.782 +      a.lazySet(i,-123);
   4.783 +    }
   4.784 +  }
   4.785 +  static void test_vi_neg(AtomicIntegerArray a, int b, int old) {
   4.786 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   4.787 +      a.lazySet(i, b);
   4.788 +    }
   4.789 +  }
   4.790 +  static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.791 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   4.792 +      a.lazySet(i, b.get(i));
   4.793 +    }
   4.794 +  }
   4.795 +  static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.796 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   4.797 +      a.lazySet(i, -123);
   4.798 +      b.lazySet(i, -103);
   4.799 +    }
   4.800 +  }
   4.801 +  static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   4.803 +      a.lazySet(i, c);
   4.804 +      b.lazySet(i, d);
   4.805 +    }
   4.806 +  }
   4.807 +  static void test_ci_oppos(AtomicIntegerArray a, int old) {
   4.808 +    int limit = ARRLEN-1;
   4.809 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.810 +      a.lazySet((limit-i), -123);
   4.811 +    }
   4.812 +  }
   4.813 +  static void test_vi_oppos(AtomicIntegerArray a, int b, int old) {
   4.814 +    int limit = ARRLEN-1;
   4.815 +    for (int i = limit; i >= 0; i-=1) {
   4.816 +      a.lazySet((limit-i), b);
   4.817 +    }
   4.818 +  }
   4.819 +  static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.820 +    int limit = ARRLEN-1;
   4.821 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.822 +      a.lazySet(i, b.get(limit-i));
   4.823 +    }
   4.824 +  }
   4.825 +  static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.826 +    int limit = ARRLEN-1;
   4.827 +    for (int i = 0; i < ARRLEN; i+=1) {
   4.828 +      a.lazySet((limit-i), -123);
   4.829 +      b.lazySet(i, -103);
   4.830 +    }
   4.831 +  }
   4.832 +  static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.833 +    int limit = ARRLEN-1;
   4.834 +    for (int i = limit; i >= 0; i-=1) {
   4.835 +      a.lazySet(i, c);
   4.836 +      b.lazySet((limit-i), d);
   4.837 +    }
   4.838 +  }
   4.839 +  static void test_ci_off(AtomicIntegerArray a, int old) {
   4.840 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   4.841 +      a.lazySet((i+OFFSET), -123);
   4.842 +    }
   4.843 +  }
   4.844 +  static void test_vi_off(AtomicIntegerArray a, int b, int old) {
   4.845 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   4.846 +      a.lazySet((i+OFFSET), b);
   4.847 +    }
   4.848 +  }
   4.849 +  static void test_cp_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.850 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   4.851 +      a.lazySet((i+OFFSET), b.get(i+OFFSET));
   4.852 +    }
   4.853 +  }
   4.854 +  static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.855 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   4.856 +      a.lazySet((i+OFFSET), -123);
   4.857 +      b.lazySet((i+OFFSET), -103);
   4.858 +    }
   4.859 +  }
   4.860 +  static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   4.862 +      a.lazySet((i+OFFSET), c);
   4.863 +      b.lazySet((i+OFFSET), d);
   4.864 +    }
   4.865 +  }
   4.866 +  static void test_ci_inv(AtomicIntegerArray a, int k, int old) {
   4.867 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   4.868 +      a.lazySet((i+k),-123);
   4.869 +    }
   4.870 +  }
   4.871 +  static void test_vi_inv(AtomicIntegerArray a, int b, int k, int old) {
   4.872 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   4.873 +      a.lazySet((i+k), b);
   4.874 +    }
   4.875 +  }
   4.876 +  static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   4.877 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   4.878 +      a.lazySet((i+k), b.get(i+k));
   4.879 +    }
   4.880 +  }
   4.881 +  static void test_2ci_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   4.882 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   4.883 +      a.lazySet((i+k), -123);
   4.884 +      b.lazySet((i+k), -103);
   4.885 +    }
   4.886 +  }
   4.887 +  static void test_2vi_inv(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d, int k) {
   4.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   4.889 +      a.lazySet((i+k), c);
   4.890 +      b.lazySet((i+k), d);
   4.891 +    }
   4.892 +  }
   4.893 +  static void test_ci_scl(AtomicIntegerArray a, int old) {
   4.894 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   4.895 +      a.lazySet((i*SCALE), -123);
   4.896 +    }
   4.897 +  }
   4.898 +  static void test_vi_scl(AtomicIntegerArray a, int b, int old) {
   4.899 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   4.900 +      a.lazySet((i*SCALE), b);
   4.901 +    }
   4.902 +  }
   4.903 +  static void test_cp_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.904 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   4.905 +      a.lazySet((i*SCALE), b.get(i*SCALE));
   4.906 +    }
   4.907 +  }
   4.908 +  static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.909 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   4.910 +      a.lazySet((i*SCALE), -123);
   4.911 +      b.lazySet((i*SCALE), -103);
   4.912 +    }
   4.913 +  }
   4.914 +  static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   4.916 +      a.lazySet((i*SCALE), c);
   4.917 +      b.lazySet((i*SCALE), d);
   4.918 +    }
   4.919 +  }
   4.920 +  static void test_cp_alndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.921 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   4.922 +      a.lazySet((i+ALIGN_OFF), b.get(i));
   4.923 +    }
   4.924 +  }
   4.925 +  static void test_cp_alnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.926 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   4.927 +      a.lazySet(i, b.get(i+ALIGN_OFF));
   4.928 +    }
   4.929 +  }
   4.930 +  static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.931 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   4.932 +      a.lazySet((i+ALIGN_OFF), -123);
   4.933 +      b.lazySet(i, -103);
   4.934 +    }
   4.935 +  }
   4.936 +  static void test_2vi_aln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.937 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   4.938 +      a.lazySet(i, c);
   4.939 +      b.lazySet((i+ALIGN_OFF), d);
   4.940 +    }
   4.941 +  }
   4.942 +  static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.943 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   4.944 +      a.lazySet((i+UNALIGN_OFF), b.get(i));
   4.945 +    }
   4.946 +  }
   4.947 +  static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.948 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   4.949 +      a.lazySet(i, b.get(i+UNALIGN_OFF));
   4.950 +    }
   4.951 +  }
   4.952 +  static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) {
   4.953 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   4.954 +      a.lazySet((i+UNALIGN_OFF), -123);
   4.955 +      b.lazySet(i, -103);
   4.956 +    }
   4.957 +  }
   4.958 +  static void test_2vi_unaln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   4.959 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   4.960 +      a.lazySet(i, c);
   4.961 +      b.lazySet((i+UNALIGN_OFF), d);
   4.962 +    }
   4.963 +  }
   4.964 +
   4.965 +  static int verify(String text, int i, int elem, int val) {
   4.966 +    if (elem != val) {
   4.967 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   4.968 +      return 1;
   4.969 +    }
   4.970 +    return 0;
   4.971 +  }
   4.972 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/compiler/8004867/TestIntAtomicVolatile.java	Mon Feb 18 16:47:15 2013 -0800
     5.3 @@ -0,0 +1,969 @@
     5.4 +/*
     5.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + *
    5.26 + */
    5.27 +
    5.28 +/**
    5.29 + * @test
    5.30 + * @bug 8004867
    5.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    5.32 + *
    5.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntAtomicVolatile
    5.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntAtomicVolatile
    5.35 + */
    5.36 +
    5.37 +import java.util.concurrent.atomic.AtomicIntegerArray;
    5.38 +
    5.39 +public class TestIntAtomicVolatile {
    5.40 +  private static final int ARRLEN = 97;
    5.41 +  private static final int ITERS  = 11000;
    5.42 +  private static final int OFFSET = 3;
    5.43 +  private static final int SCALE = 2;
    5.44 +  private static final int ALIGN_OFF = 8;
    5.45 +  private static final int UNALIGN_OFF = 5;
    5.46 +
    5.47 +  public static void main(String args[]) {
    5.48 +    System.out.println("Testing Integer array atomic volatile operations");
    5.49 +    int errn = test(false);
    5.50 +    if (errn > 0) {
    5.51 +      System.err.println("FAILED: " + errn + " errors");
    5.52 +      System.exit(97);
    5.53 +    }
    5.54 +    System.out.println("PASSED");
    5.55 +  }
    5.56 +
    5.57 +  static int test(boolean test_only) {
    5.58 +    AtomicIntegerArray a1 = new AtomicIntegerArray(ARRLEN);
    5.59 +    AtomicIntegerArray a2 = new AtomicIntegerArray(ARRLEN);
    5.60 +    // Initialize
    5.61 +    for (int i=0; i<ARRLEN; i++) {
    5.62 +      a1.set(i, -1);
    5.63 +      a2.set(i, -1);
    5.64 +    }
    5.65 +    System.out.println("Warmup");
    5.66 +    for (int i=0; i<ITERS; i++) {
    5.67 +      test_ci(a1);
    5.68 +      test_vi(a2, 123, -1);
    5.69 +      test_cp(a1, a2);
    5.70 +      test_2ci(a1, a2);
    5.71 +      test_2vi(a1, a2, 123, 103);
    5.72 +      test_ci_neg(a1, 123);
    5.73 +      test_vi_neg(a2, 123, 103);
    5.74 +      test_cp_neg(a1, a2);
    5.75 +      test_2ci_neg(a1, a2);
    5.76 +      test_2vi_neg(a1, a2, 123, 103);
    5.77 +      test_ci_oppos(a1, 123);
    5.78 +      test_vi_oppos(a2, 123, 103);
    5.79 +      test_cp_oppos(a1, a2);
    5.80 +      test_2ci_oppos(a1, a2);
    5.81 +      test_2vi_oppos(a1, a2, 123, 103);
    5.82 +      test_ci_off(a1, 123);
    5.83 +      test_vi_off(a2, 123, 103);
    5.84 +      test_cp_off(a1, a2);
    5.85 +      test_2ci_off(a1, a2);
    5.86 +      test_2vi_off(a1, a2, 123, 103);
    5.87 +      test_ci_inv(a1, OFFSET, 123);
    5.88 +      test_vi_inv(a2, 123, OFFSET, 103);
    5.89 +      test_cp_inv(a1, a2, OFFSET);
    5.90 +      test_2ci_inv(a1, a2, OFFSET);
    5.91 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
    5.92 +      test_ci_scl(a1, 123);
    5.93 +      test_vi_scl(a2, 123, 103);
    5.94 +      test_cp_scl(a1, a2);
    5.95 +      test_2ci_scl(a1, a2);
    5.96 +      test_2vi_scl(a1, a2, 123, 103);
    5.97 +      test_cp_alndst(a1, a2);
    5.98 +      test_cp_alnsrc(a1, a2);
    5.99 +      test_2ci_aln(a1, a2);
   5.100 +      test_2vi_aln(a1, a2, 123, 103);
   5.101 +      test_cp_unalndst(a1, a2);
   5.102 +      test_cp_unalnsrc(a1, a2);
   5.103 +      test_2ci_unaln(a1, a2);
   5.104 +      test_2vi_unaln(a1, a2, 123, 103);
   5.105 +    }
   5.106 +    // Initialize
   5.107 +    for (int i=0; i<ARRLEN; i++) {
   5.108 +      a1.set(i, -1);
   5.109 +      a2.set(i, -1);
   5.110 +    }
   5.111 +    // Test and verify results
   5.112 +    System.out.println("Verification");
   5.113 +    int errn = 0;
   5.114 +    {
   5.115 +      test_ci(a1);
   5.116 +      for (int i=0; i<ARRLEN; i++) {
   5.117 +        errn += verify("test_ci: a1", i, a1.get(i), -123);
   5.118 +      }
   5.119 +      test_vi(a2, 123, -1);
   5.120 +      for (int i=0; i<ARRLEN; i++) {
   5.121 +        errn += verify("test_vi: a2", i, a2.get(i), 123);
   5.122 +      }
   5.123 +      test_cp(a1, a2);
   5.124 +      for (int i=0; i<ARRLEN; i++) {
   5.125 +        errn += verify("test_cp: a1", i, a1.get(i), 123);
   5.126 +      }
   5.127 +      test_2ci(a1, a2);
   5.128 +      for (int i=0; i<ARRLEN; i++) {
   5.129 +        errn += verify("test_2ci: a1", i, a1.get(i), -123);
   5.130 +        errn += verify("test_2ci: a2", i, a2.get(i), -103);
   5.131 +      }
   5.132 +      test_2vi(a1, a2, 123, 103);
   5.133 +      for (int i=0; i<ARRLEN; i++) {
   5.134 +        errn += verify("test_2vi: a1", i, a1.get(i), 123);
   5.135 +        errn += verify("test_2vi: a2", i, a2.get(i), 103);
   5.136 +      }
   5.137 +      // Reset for negative stride
   5.138 +      for (int i=0; i<ARRLEN; i++) {
   5.139 +        a1.set(i, -1);
   5.140 +        a2.set(i, -1);
   5.141 +      }
   5.142 +      test_ci_neg(a1, -1);
   5.143 +      for (int i=0; i<ARRLEN; i++) {
   5.144 +        errn += verify("test_ci_neg: a1", i, a1.get(i), -123);
   5.145 +      }
   5.146 +      test_vi_neg(a2, 123, -1);
   5.147 +      for (int i=0; i<ARRLEN; i++) {
   5.148 +        errn += verify("test_vi_neg: a2", i, a2.get(i), 123);
   5.149 +      }
   5.150 +      test_cp_neg(a1, a2);
   5.151 +      for (int i=0; i<ARRLEN; i++) {
   5.152 +        errn += verify("test_cp_neg: a1", i, a1.get(i), 123);
   5.153 +      }
   5.154 +      test_2ci_neg(a1, a2);
   5.155 +      for (int i=0; i<ARRLEN; i++) {
   5.156 +        errn += verify("test_2ci_neg: a1", i, a1.get(i), -123);
   5.157 +        errn += verify("test_2ci_neg: a2", i, a2.get(i), -103);
   5.158 +      }
   5.159 +      test_2vi_neg(a1, a2, 123, 103);
   5.160 +      for (int i=0; i<ARRLEN; i++) {
   5.161 +        errn += verify("test_2vi_neg: a1", i, a1.get(i), 123);
   5.162 +        errn += verify("test_2vi_neg: a2", i, a2.get(i), 103);
   5.163 +      }
   5.164 +      // Reset for opposite stride
   5.165 +      for (int i=0; i<ARRLEN; i++) {
   5.166 +        a1.set(i, -1);
   5.167 +        a2.set(i, -1);
   5.168 +      }
   5.169 +      test_ci_oppos(a1, -1);
   5.170 +      for (int i=0; i<ARRLEN; i++) {
   5.171 +        errn += verify("test_ci_oppos: a1", i, a1.get(i), -123);
   5.172 +      }
   5.173 +      test_vi_oppos(a2, 123, -1);
   5.174 +      for (int i=0; i<ARRLEN; i++) {
   5.175 +        errn += verify("test_vi_oppos: a2", i, a2.get(i), 123);
   5.176 +      }
   5.177 +      test_cp_oppos(a1, a2);
   5.178 +      for (int i=0; i<ARRLEN; i++) {
   5.179 +        errn += verify("test_cp_oppos: a1", i, a1.get(i), 123);
   5.180 +      }
   5.181 +      test_2ci_oppos(a1, a2);
   5.182 +      for (int i=0; i<ARRLEN; i++) {
   5.183 +        errn += verify("test_2ci_oppos: a1", i, a1.get(i), -123);
   5.184 +        errn += verify("test_2ci_oppos: a2", i, a2.get(i), -103);
   5.185 +      }
   5.186 +      test_2vi_oppos(a1, a2, 123, 103);
   5.187 +      for (int i=0; i<ARRLEN; i++) {
   5.188 +        errn += verify("test_2vi_oppos: a1", i, a1.get(i), 123);
   5.189 +        errn += verify("test_2vi_oppos: a2", i, a2.get(i), 103);
   5.190 +      }
   5.191 +      // Reset for indexing with offset
   5.192 +      for (int i=0; i<ARRLEN; i++) {
   5.193 +        a1.set(i, -1);
   5.194 +        a2.set(i, -1);
   5.195 +      }
   5.196 +      test_ci_off(a1, -1);
   5.197 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.198 +        errn += verify("test_ci_off: a1", i, a1.get(i), -123);
   5.199 +      }
   5.200 +      test_vi_off(a2, 123, -1);
   5.201 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.202 +        errn += verify("test_vi_off: a2", i, a2.get(i), 123);
   5.203 +      }
   5.204 +      test_cp_off(a1, a2);
   5.205 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.206 +        errn += verify("test_cp_off: a1", i, a1.get(i), 123);
   5.207 +      }
   5.208 +      test_2ci_off(a1, a2);
   5.209 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.210 +        errn += verify("test_2ci_off: a1", i, a1.get(i), -123);
   5.211 +        errn += verify("test_2ci_off: a2", i, a2.get(i), -103);
   5.212 +      }
   5.213 +      test_2vi_off(a1, a2, 123, 103);
   5.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.215 +        errn += verify("test_2vi_off: a1", i, a1.get(i), 123);
   5.216 +        errn += verify("test_2vi_off: a2", i, a2.get(i), 103);
   5.217 +      }
   5.218 +      for (int i=0; i<OFFSET; i++) {
   5.219 +        errn += verify("test_2vi_off: a1", i, a1.get(i), -1);
   5.220 +        errn += verify("test_2vi_off: a2", i, a2.get(i), -1);
   5.221 +      }
   5.222 +      // Reset for indexing with invariant offset
   5.223 +      for (int i=0; i<ARRLEN; i++) {
   5.224 +        a1.set(i, -1);
   5.225 +        a2.set(i, -1);
   5.226 +      }
   5.227 +      test_ci_inv(a1, OFFSET, -1);
   5.228 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.229 +        errn += verify("test_ci_inv: a1", i, a1.get(i), -123);
   5.230 +      }
   5.231 +      test_vi_inv(a2, 123, OFFSET, -1);
   5.232 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.233 +        errn += verify("test_vi_inv: a2", i, a2.get(i), 123);
   5.234 +      }
   5.235 +      test_cp_inv(a1, a2, OFFSET);
   5.236 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.237 +        errn += verify("test_cp_inv: a1", i, a1.get(i), 123);
   5.238 +      }
   5.239 +      test_2ci_inv(a1, a2, OFFSET);
   5.240 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.241 +        errn += verify("test_2ci_inv: a1", i, a1.get(i), -123);
   5.242 +        errn += verify("test_2ci_inv: a2", i, a2.get(i), -103);
   5.243 +      }
   5.244 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   5.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   5.246 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), 123);
   5.247 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), 103);
   5.248 +      }
   5.249 +      for (int i=0; i<OFFSET; i++) {
   5.250 +        errn += verify("test_2vi_inv: a1", i, a1.get(i), -1);
   5.251 +        errn += verify("test_2vi_inv: a2", i, a2.get(i), -1);
   5.252 +      }
   5.253 +      // Reset for indexing with scale
   5.254 +      for (int i=0; i<ARRLEN; i++) {
   5.255 +        a1.set(i, -1);
   5.256 +        a2.set(i, -1);
   5.257 +      }
   5.258 +      test_ci_scl(a1, -1);
   5.259 +      for (int i=0; i<ARRLEN; i++) {
   5.260 +        int val = (i%SCALE != 0) ? -1 : -123;
   5.261 +        errn += verify("test_ci_scl: a1", i, a1.get(i), val);
   5.262 +      }
   5.263 +      test_vi_scl(a2, 123, -1);
   5.264 +      for (int i=0; i<ARRLEN; i++) {
   5.265 +        int val = (i%SCALE != 0) ? -1 : 123;
   5.266 +        errn += verify("test_vi_scl: a2", i, a2.get(i), val);
   5.267 +      }
   5.268 +      test_cp_scl(a1, a2);
   5.269 +      for (int i=0; i<ARRLEN; i++) {
   5.270 +        int val = (i%SCALE != 0) ? -1 : 123;
   5.271 +        errn += verify("test_cp_scl: a1", i, a1.get(i), val);
   5.272 +      }
   5.273 +      test_2ci_scl(a1, a2);
   5.274 +      for (int i=0; i<ARRLEN; i++) {
   5.275 +        if (i%SCALE != 0) {
   5.276 +          errn += verify("test_2ci_scl: a1", i, a1.get(i), -1);
   5.277 +        } else if (i*SCALE < ARRLEN) {
   5.278 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1.get(i*SCALE), -123);
   5.279 +        }
   5.280 +        if (i%SCALE != 0) {
   5.281 +          errn += verify("test_2ci_scl: a2", i, a2.get(i), -1);
   5.282 +        } else if (i*SCALE < ARRLEN) {
   5.283 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2.get(i*SCALE), -103);
   5.284 +        }
   5.285 +      }
   5.286 +      test_2vi_scl(a1, a2, 123, 103);
   5.287 +      for (int i=0; i<ARRLEN; i++) {
   5.288 +        if (i%SCALE != 0) {
   5.289 +          errn += verify("test_2vi_scl: a1", i, a1.get(i), -1);
   5.290 +        } else if (i*SCALE < ARRLEN) {
   5.291 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1.get(i*SCALE), 123);
   5.292 +        }
   5.293 +        if (i%SCALE != 0) {
   5.294 +          errn += verify("test_2vi_scl: a2", i, a2.get(i), -1);
   5.295 +        } else if (i*SCALE < ARRLEN) {
   5.296 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2.get(i*SCALE), 103);
   5.297 +        }
   5.298 +      }
   5.299 +      // Reset for 2 arrays with relative aligned offset
   5.300 +      for (int i=0; i<ARRLEN; i++) {
   5.301 +        a1.set(i, -1);
   5.302 +        a2.set(i, -1);
   5.303 +      }
   5.304 +      test_vi(a2, 123, -1);
   5.305 +      test_cp_alndst(a1, a2);
   5.306 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.307 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), -1);
   5.308 +      }
   5.309 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   5.310 +        errn += verify("test_cp_alndst: a1", i, a1.get(i), 123);
   5.311 +      }
   5.312 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.313 +        a1.set(i, 123);
   5.314 +      }
   5.315 +      test_vi(a2, -123, 123);
   5.316 +      test_cp_alnsrc(a1, a2);
   5.317 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   5.318 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), -123);
   5.319 +      }
   5.320 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   5.321 +        errn += verify("test_cp_alnsrc: a1", i, a1.get(i), 123);
   5.322 +      }
   5.323 +      for (int i=0; i<ARRLEN; i++) {
   5.324 +        a1.set(i, -1);
   5.325 +        a2.set(i, -1);
   5.326 +      }
   5.327 +      test_2ci_aln(a1, a2);
   5.328 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.329 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -1);
   5.330 +      }
   5.331 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   5.332 +        errn += verify("test_2ci_aln: a1", i, a1.get(i), -123);
   5.333 +      }
   5.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   5.335 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -103);
   5.336 +      }
   5.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   5.338 +        errn += verify("test_2ci_aln: a2", i, a2.get(i), -1);
   5.339 +      }
   5.340 +      for (int i=0; i<ARRLEN; i++) {
   5.341 +        a1.set(i, -1);
   5.342 +        a2.set(i, -1);
   5.343 +      }
   5.344 +      test_2vi_aln(a1, a2, 123, 103);
   5.345 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   5.346 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), 123);
   5.347 +      }
   5.348 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   5.349 +        errn += verify("test_2vi_aln: a1", i, a1.get(i), -1);
   5.350 +      }
   5.351 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.352 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), -1);
   5.353 +      }
   5.354 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   5.355 +        errn += verify("test_2vi_aln: a2", i, a2.get(i), 103);
   5.356 +      }
   5.357 +
   5.358 +      // Reset for 2 arrays with relative unaligned offset
   5.359 +      for (int i=0; i<ARRLEN; i++) {
   5.360 +        a1.set(i, -1);
   5.361 +        a2.set(i, -1);
   5.362 +      }
   5.363 +      test_vi(a2, 123, -1);
   5.364 +      test_cp_unalndst(a1, a2);
   5.365 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.366 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), -1);
   5.367 +      }
   5.368 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   5.369 +        errn += verify("test_cp_unalndst: a1", i, a1.get(i), 123);
   5.370 +      }
   5.371 +      test_vi(a2, -123, 123);
   5.372 +      test_cp_unalnsrc(a1, a2);
   5.373 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   5.374 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), -123);
   5.375 +      }
   5.376 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   5.377 +        errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), 123);
   5.378 +      }
   5.379 +      for (int i=0; i<ARRLEN; i++) {
   5.380 +        a1.set(i, -1);
   5.381 +        a2.set(i, -1);
   5.382 +      }
   5.383 +      test_2ci_unaln(a1, a2);
   5.384 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.385 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -1);
   5.386 +      }
   5.387 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   5.388 +        errn += verify("test_2ci_unaln: a1", i, a1.get(i), -123);
   5.389 +      }
   5.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   5.391 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -103);
   5.392 +      }
   5.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   5.394 +        errn += verify("test_2ci_unaln: a2", i, a2.get(i), -1);
   5.395 +      }
   5.396 +      for (int i=0; i<ARRLEN; i++) {
   5.397 +        a1.set(i, -1);
   5.398 +        a2.set(i, -1);
   5.399 +      }
   5.400 +      test_2vi_unaln(a1, a2, 123, 103);
   5.401 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   5.402 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), 123);
   5.403 +      }
   5.404 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   5.405 +        errn += verify("test_2vi_unaln: a1", i, a1.get(i), -1);
   5.406 +      }
   5.407 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.408 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), -1);
   5.409 +      }
   5.410 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   5.411 +        errn += verify("test_2vi_unaln: a2", i, a2.get(i), 103);
   5.412 +      }
   5.413 +
   5.414 +      // Reset for aligned overlap initialization
   5.415 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.416 +        a1.set(i, i);
   5.417 +      }
   5.418 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   5.419 +        a1.set(i, -1);
   5.420 +      }
   5.421 +      test_cp_alndst(a1, a1);
   5.422 +      for (int i=0; i<ARRLEN; i++) {
   5.423 +        int v = i%ALIGN_OFF;
   5.424 +        errn += verify("test_cp_alndst_overlap: a1", i, a1.get(i), v);
   5.425 +      }
   5.426 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.427 +        a1.set((i+ALIGN_OFF), -1);
   5.428 +      }
   5.429 +      test_cp_alnsrc(a1, a1);
   5.430 +      for (int i=0; i<ALIGN_OFF; i++) {
   5.431 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), -1);
   5.432 +      }
   5.433 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   5.434 +        int v = i%ALIGN_OFF;
   5.435 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), v);
   5.436 +      }
   5.437 +      for (int i=0; i<ARRLEN; i++) {
   5.438 +        a1.set(i, -1);
   5.439 +      }
   5.440 +      test_2ci_aln(a1, a1);
   5.441 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   5.442 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -103);
   5.443 +      }
   5.444 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   5.445 +        errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -123);
   5.446 +      }
   5.447 +      for (int i=0; i<ARRLEN; i++) {
   5.448 +        a1.set(i, -1);
   5.449 +      }
   5.450 +      test_2vi_aln(a1, a1, 123, 103);
   5.451 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   5.452 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 123);
   5.453 +      }
   5.454 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   5.455 +        errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 103);
   5.456 +      }
   5.457 +
   5.458 +      // Reset for unaligned overlap initialization
   5.459 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.460 +        a1.set(i, i);
   5.461 +      }
   5.462 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   5.463 +        a1.set(i, -1);
   5.464 +      }
   5.465 +      test_cp_unalndst(a1, a1);
   5.466 +      for (int i=0; i<ARRLEN; i++) {
   5.467 +        int v = i%UNALIGN_OFF;
   5.468 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1.get(i), v);
   5.469 +      }
   5.470 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.471 +        a1.set((i+UNALIGN_OFF), -1);
   5.472 +      }
   5.473 +      test_cp_unalnsrc(a1, a1);
   5.474 +      for (int i=0; i<UNALIGN_OFF; i++) {
   5.475 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), -1);
   5.476 +      }
   5.477 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   5.478 +        int v = i%UNALIGN_OFF;
   5.479 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), v);
   5.480 +      }
   5.481 +      for (int i=0; i<ARRLEN; i++) {
   5.482 +        a1.set(i, -1);
   5.483 +      }
   5.484 +      test_2ci_unaln(a1, a1);
   5.485 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   5.486 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -103);
   5.487 +      }
   5.488 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   5.489 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -123);
   5.490 +      }
   5.491 +      for (int i=0; i<ARRLEN; i++) {
   5.492 +        a1.set(i, -1);
   5.493 +      }
   5.494 +      test_2vi_unaln(a1, a1, 123, 103);
   5.495 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   5.496 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 123);
   5.497 +      }
   5.498 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   5.499 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 103);
   5.500 +      }
   5.501 +
   5.502 +    }
   5.503 +
   5.504 +    if (errn > 0 || test_only)
   5.505 +      return errn;
   5.506 +
   5.507 +    // Initialize
   5.508 +    for (int i=0; i<ARRLEN; i++) {
   5.509 +      a1.set(i, -1);
   5.510 +      a2.set(i, -1);
   5.511 +    }
   5.512 +    System.out.println("Time");
   5.513 +    long start, end;
   5.514 +    start = System.currentTimeMillis();
   5.515 +    for (int i=0; i<ITERS; i++) {
   5.516 +      test_ci(a1);
   5.517 +    }
   5.518 +    end = System.currentTimeMillis();
   5.519 +    System.out.println("test_ci: " + (end - start));
   5.520 +    start = System.currentTimeMillis();
   5.521 +    for (int i=0; i<ITERS; i++) {
   5.522 +      test_vi(a2, 123, -1);
   5.523 +    }
   5.524 +    end = System.currentTimeMillis();
   5.525 +    System.out.println("test_vi: " + (end - start));
   5.526 +    start = System.currentTimeMillis();
   5.527 +    for (int i=0; i<ITERS; i++) {
   5.528 +      test_cp(a1, a2);
   5.529 +    }
   5.530 +    end = System.currentTimeMillis();
   5.531 +    System.out.println("test_cp: " + (end - start));
   5.532 +    start = System.currentTimeMillis();
   5.533 +    for (int i=0; i<ITERS; i++) {
   5.534 +      test_2ci(a1, a2);
   5.535 +    }
   5.536 +    end = System.currentTimeMillis();
   5.537 +    System.out.println("test_2ci: " + (end - start));
   5.538 +    start = System.currentTimeMillis();
   5.539 +    for (int i=0; i<ITERS; i++) {
   5.540 +      test_2vi(a1, a2, 123, 103);
   5.541 +    }
   5.542 +    end = System.currentTimeMillis();
   5.543 +    System.out.println("test_2vi: " + (end - start));
   5.544 +
   5.545 +    start = System.currentTimeMillis();
   5.546 +    for (int i=0; i<ITERS; i++) {
   5.547 +      test_ci_neg(a1, 123);
   5.548 +    }
   5.549 +    end = System.currentTimeMillis();
   5.550 +    System.out.println("test_ci_neg: " + (end - start));
   5.551 +    start = System.currentTimeMillis();
   5.552 +    for (int i=0; i<ITERS; i++) {
   5.553 +      test_vi_neg(a2, 123, 103);
   5.554 +    }
   5.555 +    end = System.currentTimeMillis();
   5.556 +    System.out.println("test_vi_neg: " + (end - start));
   5.557 +    start = System.currentTimeMillis();
   5.558 +    for (int i=0; i<ITERS; i++) {
   5.559 +      test_cp_neg(a1, a2);
   5.560 +    }
   5.561 +    end = System.currentTimeMillis();
   5.562 +    System.out.println("test_cp_neg: " + (end - start));
   5.563 +    start = System.currentTimeMillis();
   5.564 +    for (int i=0; i<ITERS; i++) {
   5.565 +      test_2ci_neg(a1, a2);
   5.566 +    }
   5.567 +    end = System.currentTimeMillis();
   5.568 +    System.out.println("test_2ci_neg: " + (end - start));
   5.569 +    start = System.currentTimeMillis();
   5.570 +    for (int i=0; i<ITERS; i++) {
   5.571 +      test_2vi_neg(a1, a2, 123, 103);
   5.572 +    }
   5.573 +    end = System.currentTimeMillis();
   5.574 +    System.out.println("test_2vi_neg: " + (end - start));
   5.575 +
   5.576 +    start = System.currentTimeMillis();
   5.577 +    for (int i=0; i<ITERS; i++) {
   5.578 +      test_ci_oppos(a1, 123);
   5.579 +    }
   5.580 +    end = System.currentTimeMillis();
   5.581 +    System.out.println("test_ci_oppos: " + (end - start));
   5.582 +    start = System.currentTimeMillis();
   5.583 +    for (int i=0; i<ITERS; i++) {
   5.584 +      test_vi_oppos(a2, 123, 103);
   5.585 +    }
   5.586 +    end = System.currentTimeMillis();
   5.587 +    System.out.println("test_vi_oppos: " + (end - start));
   5.588 +    start = System.currentTimeMillis();
   5.589 +    for (int i=0; i<ITERS; i++) {
   5.590 +      test_cp_oppos(a1, a2);
   5.591 +    }
   5.592 +    end = System.currentTimeMillis();
   5.593 +    System.out.println("test_cp_oppos: " + (end - start));
   5.594 +    start = System.currentTimeMillis();
   5.595 +    for (int i=0; i<ITERS; i++) {
   5.596 +      test_2ci_oppos(a1, a2);
   5.597 +    }
   5.598 +    end = System.currentTimeMillis();
   5.599 +    System.out.println("test_2ci_oppos: " + (end - start));
   5.600 +    start = System.currentTimeMillis();
   5.601 +    for (int i=0; i<ITERS; i++) {
   5.602 +      test_2vi_oppos(a1, a2, 123, 103);
   5.603 +    }
   5.604 +    end = System.currentTimeMillis();
   5.605 +    System.out.println("test_2vi_oppos: " + (end - start));
   5.606 +
   5.607 +    start = System.currentTimeMillis();
   5.608 +    for (int i=0; i<ITERS; i++) {
   5.609 +      test_ci_off(a1, 123);
   5.610 +    }
   5.611 +    end = System.currentTimeMillis();
   5.612 +    System.out.println("test_ci_off: " + (end - start));
   5.613 +    start = System.currentTimeMillis();
   5.614 +    for (int i=0; i<ITERS; i++) {
   5.615 +      test_vi_off(a2, 123, 103);
   5.616 +    }
   5.617 +    end = System.currentTimeMillis();
   5.618 +    System.out.println("test_vi_off: " + (end - start));
   5.619 +    start = System.currentTimeMillis();
   5.620 +    for (int i=0; i<ITERS; i++) {
   5.621 +      test_cp_off(a1, a2);
   5.622 +    }
   5.623 +    end = System.currentTimeMillis();
   5.624 +    System.out.println("test_cp_off: " + (end - start));
   5.625 +    start = System.currentTimeMillis();
   5.626 +    for (int i=0; i<ITERS; i++) {
   5.627 +      test_2ci_off(a1, a2);
   5.628 +    }
   5.629 +    end = System.currentTimeMillis();
   5.630 +    System.out.println("test_2ci_off: " + (end - start));
   5.631 +    start = System.currentTimeMillis();
   5.632 +    for (int i=0; i<ITERS; i++) {
   5.633 +      test_2vi_off(a1, a2, 123, 103);
   5.634 +    }
   5.635 +    end = System.currentTimeMillis();
   5.636 +    System.out.println("test_2vi_off: " + (end - start));
   5.637 +
   5.638 +    start = System.currentTimeMillis();
   5.639 +    for (int i=0; i<ITERS; i++) {
   5.640 +      test_ci_inv(a1, OFFSET, 123);
   5.641 +    }
   5.642 +    end = System.currentTimeMillis();
   5.643 +    System.out.println("test_ci_inv: " + (end - start));
   5.644 +    start = System.currentTimeMillis();
   5.645 +    for (int i=0; i<ITERS; i++) {
   5.646 +      test_vi_inv(a2, 123, OFFSET, 103);
   5.647 +    }
   5.648 +    end = System.currentTimeMillis();
   5.649 +    System.out.println("test_vi_inv: " + (end - start));
   5.650 +    start = System.currentTimeMillis();
   5.651 +    for (int i=0; i<ITERS; i++) {
   5.652 +      test_cp_inv(a1, a2, OFFSET);
   5.653 +    }
   5.654 +    end = System.currentTimeMillis();
   5.655 +    System.out.println("test_cp_inv: " + (end - start));
   5.656 +    start = System.currentTimeMillis();
   5.657 +    for (int i=0; i<ITERS; i++) {
   5.658 +      test_2ci_inv(a1, a2, OFFSET);
   5.659 +    }
   5.660 +    end = System.currentTimeMillis();
   5.661 +    System.out.println("test_2ci_inv: " + (end - start));
   5.662 +    start = System.currentTimeMillis();
   5.663 +    for (int i=0; i<ITERS; i++) {
   5.664 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   5.665 +    }
   5.666 +    end = System.currentTimeMillis();
   5.667 +    System.out.println("test_2vi_inv: " + (end - start));
   5.668 +
   5.669 +    start = System.currentTimeMillis();
   5.670 +    for (int i=0; i<ITERS; i++) {
   5.671 +      test_ci_scl(a1, 123);
   5.672 +    }
   5.673 +    end = System.currentTimeMillis();
   5.674 +    System.out.println("test_ci_scl: " + (end - start));
   5.675 +    start = System.currentTimeMillis();
   5.676 +    for (int i=0; i<ITERS; i++) {
   5.677 +      test_vi_scl(a2, 123, 103);
   5.678 +    }
   5.679 +    end = System.currentTimeMillis();
   5.680 +    System.out.println("test_vi_scl: " + (end - start));
   5.681 +    start = System.currentTimeMillis();
   5.682 +    for (int i=0; i<ITERS; i++) {
   5.683 +      test_cp_scl(a1, a2);
   5.684 +    }
   5.685 +    end = System.currentTimeMillis();
   5.686 +    System.out.println("test_cp_scl: " + (end - start));
   5.687 +    start = System.currentTimeMillis();
   5.688 +    for (int i=0; i<ITERS; i++) {
   5.689 +      test_2ci_scl(a1, a2);
   5.690 +    }
   5.691 +    end = System.currentTimeMillis();
   5.692 +    System.out.println("test_2ci_scl: " + (end - start));
   5.693 +    start = System.currentTimeMillis();
   5.694 +    for (int i=0; i<ITERS; i++) {
   5.695 +      test_2vi_scl(a1, a2, 123, 103);
   5.696 +    }
   5.697 +    end = System.currentTimeMillis();
   5.698 +    System.out.println("test_2vi_scl: " + (end - start));
   5.699 +
   5.700 +    start = System.currentTimeMillis();
   5.701 +    for (int i=0; i<ITERS; i++) {
   5.702 +      test_cp_alndst(a1, a2);
   5.703 +    }
   5.704 +    end = System.currentTimeMillis();
   5.705 +    System.out.println("test_cp_alndst: " + (end - start));
   5.706 +    start = System.currentTimeMillis();
   5.707 +    for (int i=0; i<ITERS; i++) {
   5.708 +      test_cp_alnsrc(a1, a2);
   5.709 +    }
   5.710 +    end = System.currentTimeMillis();
   5.711 +    System.out.println("test_cp_alnsrc: " + (end - start));
   5.712 +    start = System.currentTimeMillis();
   5.713 +    for (int i=0; i<ITERS; i++) {
   5.714 +      test_2ci_aln(a1, a2);
   5.715 +    }
   5.716 +    end = System.currentTimeMillis();
   5.717 +    System.out.println("test_2ci_aln: " + (end - start));
   5.718 +    start = System.currentTimeMillis();
   5.719 +    for (int i=0; i<ITERS; i++) {
   5.720 +      test_2vi_aln(a1, a2, 123, 103);
   5.721 +    }
   5.722 +    end = System.currentTimeMillis();
   5.723 +    System.out.println("test_2vi_aln: " + (end - start));
   5.724 +
   5.725 +    start = System.currentTimeMillis();
   5.726 +    for (int i=0; i<ITERS; i++) {
   5.727 +      test_cp_unalndst(a1, a2);
   5.728 +    }
   5.729 +    end = System.currentTimeMillis();
   5.730 +    System.out.println("test_cp_unalndst: " + (end - start));
   5.731 +    start = System.currentTimeMillis();
   5.732 +    for (int i=0; i<ITERS; i++) {
   5.733 +      test_cp_unalnsrc(a1, a2);
   5.734 +    }
   5.735 +    end = System.currentTimeMillis();
   5.736 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   5.737 +    start = System.currentTimeMillis();
   5.738 +    for (int i=0; i<ITERS; i++) {
   5.739 +      test_2ci_unaln(a1, a2);
   5.740 +    }
   5.741 +    end = System.currentTimeMillis();
   5.742 +    System.out.println("test_2ci_unaln: " + (end - start));
   5.743 +    start = System.currentTimeMillis();
   5.744 +    for (int i=0; i<ITERS; i++) {
   5.745 +      test_2vi_unaln(a1, a2, 123, 103);
   5.746 +    }
   5.747 +    end = System.currentTimeMillis();
   5.748 +    System.out.println("test_2vi_unaln: " + (end - start));
   5.749 +
   5.750 +    return errn;
   5.751 +  }
   5.752 +
   5.753 +  static void test_ci(AtomicIntegerArray a) {
   5.754 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.755 +      a.set(i, -123);
   5.756 +    }
   5.757 +  }
   5.758 +  static void test_vi(AtomicIntegerArray a, int b, int old) {
   5.759 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.760 +      a.set(i, b);
   5.761 +    }
   5.762 +  }
   5.763 +  static void test_cp(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.764 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.765 +      a.set(i, b.get(i));
   5.766 +    }
   5.767 +  }
   5.768 +  static void test_2ci(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.769 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.770 +      a.set(i, -123);
   5.771 +      b.set(i, -103);
   5.772 +    }
   5.773 +  }
   5.774 +  static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.776 +      a.set(i, c);
   5.777 +      b.set(i, d);
   5.778 +    }
   5.779 +  }
   5.780 +  static void test_ci_neg(AtomicIntegerArray a, int old) {
   5.781 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   5.782 +      a.set(i,-123);
   5.783 +    }
   5.784 +  }
   5.785 +  static void test_vi_neg(AtomicIntegerArray a, int b, int old) {
   5.786 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   5.787 +      a.set(i, b);
   5.788 +    }
   5.789 +  }
   5.790 +  static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.791 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   5.792 +      a.set(i, b.get(i));
   5.793 +    }
   5.794 +  }
   5.795 +  static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.796 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   5.797 +      a.set(i, -123);
   5.798 +      b.set(i, -103);
   5.799 +    }
   5.800 +  }
   5.801 +  static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   5.803 +      a.set(i, c);
   5.804 +      b.set(i, d);
   5.805 +    }
   5.806 +  }
   5.807 +  static void test_ci_oppos(AtomicIntegerArray a, int old) {
   5.808 +    int limit = ARRLEN-1;
   5.809 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.810 +      a.set((limit-i), -123);
   5.811 +    }
   5.812 +  }
   5.813 +  static void test_vi_oppos(AtomicIntegerArray a, int b, int old) {
   5.814 +    int limit = ARRLEN-1;
   5.815 +    for (int i = limit; i >= 0; i-=1) {
   5.816 +      a.set((limit-i), b);
   5.817 +    }
   5.818 +  }
   5.819 +  static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.820 +    int limit = ARRLEN-1;
   5.821 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.822 +      a.set(i, b.get(limit-i));
   5.823 +    }
   5.824 +  }
   5.825 +  static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.826 +    int limit = ARRLEN-1;
   5.827 +    for (int i = 0; i < ARRLEN; i+=1) {
   5.828 +      a.set((limit-i), -123);
   5.829 +      b.set(i, -103);
   5.830 +    }
   5.831 +  }
   5.832 +  static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.833 +    int limit = ARRLEN-1;
   5.834 +    for (int i = limit; i >= 0; i-=1) {
   5.835 +      a.set(i, c);
   5.836 +      b.set((limit-i), d);
   5.837 +    }
   5.838 +  }
   5.839 +  static void test_ci_off(AtomicIntegerArray a, int old) {
   5.840 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   5.841 +      a.set((i+OFFSET), -123);
   5.842 +    }
   5.843 +  }
   5.844 +  static void test_vi_off(AtomicIntegerArray a, int b, int old) {
   5.845 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   5.846 +      a.set((i+OFFSET), b);
   5.847 +    }
   5.848 +  }
   5.849 +  static void test_cp_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.850 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   5.851 +      a.set((i+OFFSET), b.get(i+OFFSET));
   5.852 +    }
   5.853 +  }
   5.854 +  static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.855 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   5.856 +      a.set((i+OFFSET), -123);
   5.857 +      b.set((i+OFFSET), -103);
   5.858 +    }
   5.859 +  }
   5.860 +  static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   5.862 +      a.set((i+OFFSET), c);
   5.863 +      b.set((i+OFFSET), d);
   5.864 +    }
   5.865 +  }
   5.866 +  static void test_ci_inv(AtomicIntegerArray a, int k, int old) {
   5.867 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   5.868 +      a.set((i+k),-123);
   5.869 +    }
   5.870 +  }
   5.871 +  static void test_vi_inv(AtomicIntegerArray a, int b, int k, int old) {
   5.872 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   5.873 +      a.set((i+k), b);
   5.874 +    }
   5.875 +  }
   5.876 +  static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   5.877 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   5.878 +      a.set((i+k), b.get(i+k));
   5.879 +    }
   5.880 +  }
   5.881 +  static void test_2ci_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
   5.882 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   5.883 +      a.set((i+k), -123);
   5.884 +      b.set((i+k), -103);
   5.885 +    }
   5.886 +  }
   5.887 +  static void test_2vi_inv(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d, int k) {
   5.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   5.889 +      a.set((i+k), c);
   5.890 +      b.set((i+k), d);
   5.891 +    }
   5.892 +  }
   5.893 +  static void test_ci_scl(AtomicIntegerArray a, int old) {
   5.894 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   5.895 +      a.set((i*SCALE), -123);
   5.896 +    }
   5.897 +  }
   5.898 +  static void test_vi_scl(AtomicIntegerArray a, int b, int old) {
   5.899 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   5.900 +      a.set((i*SCALE), b);
   5.901 +    }
   5.902 +  }
   5.903 +  static void test_cp_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.904 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   5.905 +      a.set((i*SCALE), b.get(i*SCALE));
   5.906 +    }
   5.907 +  }
   5.908 +  static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.909 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   5.910 +      a.set((i*SCALE), -123);
   5.911 +      b.set((i*SCALE), -103);
   5.912 +    }
   5.913 +  }
   5.914 +  static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   5.916 +      a.set((i*SCALE), c);
   5.917 +      b.set((i*SCALE), d);
   5.918 +    }
   5.919 +  }
   5.920 +  static void test_cp_alndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.921 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   5.922 +      a.set((i+ALIGN_OFF), b.get(i));
   5.923 +    }
   5.924 +  }
   5.925 +  static void test_cp_alnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.926 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   5.927 +      a.set(i, b.get(i+ALIGN_OFF));
   5.928 +    }
   5.929 +  }
   5.930 +  static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.931 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   5.932 +      a.set((i+ALIGN_OFF), -123);
   5.933 +      b.set(i, -103);
   5.934 +    }
   5.935 +  }
   5.936 +  static void test_2vi_aln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.937 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   5.938 +      a.set(i, c);
   5.939 +      b.set((i+ALIGN_OFF), d);
   5.940 +    }
   5.941 +  }
   5.942 +  static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.943 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   5.944 +      a.set((i+UNALIGN_OFF), b.get(i));
   5.945 +    }
   5.946 +  }
   5.947 +  static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.948 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   5.949 +      a.set(i, b.get(i+UNALIGN_OFF));
   5.950 +    }
   5.951 +  }
   5.952 +  static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) {
   5.953 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   5.954 +      a.set((i+UNALIGN_OFF), -123);
   5.955 +      b.set(i, -103);
   5.956 +    }
   5.957 +  }
   5.958 +  static void test_2vi_unaln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
   5.959 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   5.960 +      a.set(i, c);
   5.961 +      b.set((i+UNALIGN_OFF), d);
   5.962 +    }
   5.963 +  }
   5.964 +
   5.965 +  static int verify(String text, int i, int elem, int val) {
   5.966 +    if (elem != val) {
   5.967 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   5.968 +      return 1;
   5.969 +    }
   5.970 +    return 0;
   5.971 +  }
   5.972 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/compiler/8004867/TestIntUnsafeCAS.java	Mon Feb 18 16:47:15 2013 -0800
     6.3 @@ -0,0 +1,998 @@
     6.4 +/*
     6.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + *
    6.26 + */
    6.27 +
    6.28 +/**
    6.29 + * @test
    6.30 + * @bug 8004867
    6.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    6.32 + *
    6.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntUnsafeCAS
    6.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntUnsafeCAS
    6.35 + */
    6.36 +
    6.37 +import sun.misc.Unsafe;
    6.38 +import java.lang.reflect.*;
    6.39 +
    6.40 +public class TestIntUnsafeCAS {
    6.41 +  private static final int ARRLEN = 97;
    6.42 +  private static final int ITERS  = 11000;
    6.43 +  private static final int OFFSET = 3;
    6.44 +  private static final int SCALE = 2;
    6.45 +  private static final int ALIGN_OFF = 8;
    6.46 +  private static final int UNALIGN_OFF = 5;
    6.47 +
    6.48 +  private static final Unsafe unsafe;
    6.49 +  private static final int BASE;
    6.50 +  static {
    6.51 +    try {
    6.52 +      Class c = TestIntUnsafeCAS.class.getClassLoader().loadClass("sun.misc.Unsafe");
    6.53 +      Field f = c.getDeclaredField("theUnsafe");
    6.54 +      f.setAccessible(true);
    6.55 +      unsafe = (Unsafe)f.get(c);
    6.56 +      BASE = unsafe.arrayBaseOffset(int[].class);
    6.57 +    } catch (Exception e) {
    6.58 +      InternalError err = new InternalError();
    6.59 +      err.initCause(e);
    6.60 +      throw err;
    6.61 +    }
    6.62 +  }
    6.63 +
    6.64 +  public static void main(String args[]) {
    6.65 +    System.out.println("Testing Integer array unsafe CAS operations");
    6.66 +    int errn = test(false);
    6.67 +    if (errn > 0) {
    6.68 +      System.err.println("FAILED: " + errn + " errors");
    6.69 +      System.exit(97);
    6.70 +    }
    6.71 +    System.out.println("PASSED");
    6.72 +  }
    6.73 +
    6.74 +  static int test(boolean test_only) {
    6.75 +    int[] a1 = new int[ARRLEN];
    6.76 +    int[] a2 = new int[ARRLEN];
    6.77 +    // Initialize
    6.78 +    for (int i=0; i<ARRLEN; i++) {
    6.79 +      a1[i] = -1;
    6.80 +      a2[i] = -1;
    6.81 +    }
    6.82 +    System.out.println("Warmup");
    6.83 +    for (int i=0; i<ITERS; i++) {
    6.84 +      test_ci(a1);
    6.85 +      test_vi(a2, 123, -1);
    6.86 +      test_cp(a1, a2);
    6.87 +      test_2ci(a1, a2);
    6.88 +      test_2vi(a1, a2, 123, 103);
    6.89 +      test_ci_neg(a1, 123);
    6.90 +      test_vi_neg(a2, 123, 103);
    6.91 +      test_cp_neg(a1, a2);
    6.92 +      test_2ci_neg(a1, a2);
    6.93 +      test_2vi_neg(a1, a2, 123, 103);
    6.94 +      test_ci_oppos(a1, 123);
    6.95 +      test_vi_oppos(a2, 123, 103);
    6.96 +      test_cp_oppos(a1, a2);
    6.97 +      test_2ci_oppos(a1, a2);
    6.98 +      test_2vi_oppos(a1, a2, 123, 103);
    6.99 +      test_ci_off(a1, 123);
   6.100 +      test_vi_off(a2, 123, 103);
   6.101 +      test_cp_off(a1, a2);
   6.102 +      test_2ci_off(a1, a2);
   6.103 +      test_2vi_off(a1, a2, 123, 103);
   6.104 +      test_ci_inv(a1, OFFSET, 123);
   6.105 +      test_vi_inv(a2, 123, OFFSET, 103);
   6.106 +      test_cp_inv(a1, a2, OFFSET);
   6.107 +      test_2ci_inv(a1, a2, OFFSET);
   6.108 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   6.109 +      test_ci_scl(a1, 123);
   6.110 +      test_vi_scl(a2, 123, 103);
   6.111 +      test_cp_scl(a1, a2);
   6.112 +      test_2ci_scl(a1, a2);
   6.113 +      test_2vi_scl(a1, a2, 123, 103);
   6.114 +      test_cp_alndst(a1, a2);
   6.115 +      test_cp_alnsrc(a1, a2);
   6.116 +      test_2ci_aln(a1, a2);
   6.117 +      test_2vi_aln(a1, a2, 123, 103);
   6.118 +      test_cp_unalndst(a1, a2);
   6.119 +      test_cp_unalnsrc(a1, a2);
   6.120 +      test_2ci_unaln(a1, a2);
   6.121 +      test_2vi_unaln(a1, a2, 123, 103);
   6.122 +    }
   6.123 +    // Initialize
   6.124 +    for (int i=0; i<ARRLEN; i++) {
   6.125 +      a1[i] = -1;
   6.126 +      a2[i] = -1;
   6.127 +    }
   6.128 +    // Test and verify results
   6.129 +    System.out.println("Verification");
   6.130 +    int errn = 0;
   6.131 +    {
   6.132 +      test_ci(a1);
   6.133 +      for (int i=0; i<ARRLEN; i++) {
   6.134 +        errn += verify("test_ci: a1", i, a1[i], -123);
   6.135 +      }
   6.136 +      test_vi(a2, 123, -1);
   6.137 +      for (int i=0; i<ARRLEN; i++) {
   6.138 +        errn += verify("test_vi: a2", i, a2[i], 123);
   6.139 +      }
   6.140 +      test_cp(a1, a2);
   6.141 +      for (int i=0; i<ARRLEN; i++) {
   6.142 +        errn += verify("test_cp: a1", i, a1[i], 123);
   6.143 +      }
   6.144 +      test_2ci(a1, a2);
   6.145 +      for (int i=0; i<ARRLEN; i++) {
   6.146 +        errn += verify("test_2ci: a1", i, a1[i], -123);
   6.147 +        errn += verify("test_2ci: a2", i, a2[i], -103);
   6.148 +      }
   6.149 +      test_2vi(a1, a2, 123, 103);
   6.150 +      for (int i=0; i<ARRLEN; i++) {
   6.151 +        errn += verify("test_2vi: a1", i, a1[i], 123);
   6.152 +        errn += verify("test_2vi: a2", i, a2[i], 103);
   6.153 +      }
   6.154 +      // Reset for negative stride
   6.155 +      for (int i=0; i<ARRLEN; i++) {
   6.156 +        a1[i] = -1;
   6.157 +        a2[i] = -1;
   6.158 +      }
   6.159 +      test_ci_neg(a1, -1);
   6.160 +      for (int i=0; i<ARRLEN; i++) {
   6.161 +        errn += verify("test_ci_neg: a1", i, a1[i], -123);
   6.162 +      }
   6.163 +      test_vi_neg(a2, 123, -1);
   6.164 +      for (int i=0; i<ARRLEN; i++) {
   6.165 +        errn += verify("test_vi_neg: a2", i, a2[i], 123);
   6.166 +      }
   6.167 +      test_cp_neg(a1, a2);
   6.168 +      for (int i=0; i<ARRLEN; i++) {
   6.169 +        errn += verify("test_cp_neg: a1", i, a1[i], 123);
   6.170 +      }
   6.171 +      test_2ci_neg(a1, a2);
   6.172 +      for (int i=0; i<ARRLEN; i++) {
   6.173 +        errn += verify("test_2ci_neg: a1", i, a1[i], -123);
   6.174 +        errn += verify("test_2ci_neg: a2", i, a2[i], -103);
   6.175 +      }
   6.176 +      test_2vi_neg(a1, a2, 123, 103);
   6.177 +      for (int i=0; i<ARRLEN; i++) {
   6.178 +        errn += verify("test_2vi_neg: a1", i, a1[i], 123);
   6.179 +        errn += verify("test_2vi_neg: a2", i, a2[i], 103);
   6.180 +      }
   6.181 +      // Reset for opposite stride
   6.182 +      for (int i=0; i<ARRLEN; i++) {
   6.183 +        a1[i] = -1;
   6.184 +        a2[i] = -1;
   6.185 +      }
   6.186 +      test_ci_oppos(a1, -1);
   6.187 +      for (int i=0; i<ARRLEN; i++) {
   6.188 +        errn += verify("test_ci_oppos: a1", i, a1[i], -123);
   6.189 +      }
   6.190 +      test_vi_oppos(a2, 123, -1);
   6.191 +      for (int i=0; i<ARRLEN; i++) {
   6.192 +        errn += verify("test_vi_oppos: a2", i, a2[i], 123);
   6.193 +      }
   6.194 +      test_cp_oppos(a1, a2);
   6.195 +      for (int i=0; i<ARRLEN; i++) {
   6.196 +        errn += verify("test_cp_oppos: a1", i, a1[i], 123);
   6.197 +      }
   6.198 +      test_2ci_oppos(a1, a2);
   6.199 +      for (int i=0; i<ARRLEN; i++) {
   6.200 +        errn += verify("test_2ci_oppos: a1", i, a1[i], -123);
   6.201 +        errn += verify("test_2ci_oppos: a2", i, a2[i], -103);
   6.202 +      }
   6.203 +      test_2vi_oppos(a1, a2, 123, 103);
   6.204 +      for (int i=0; i<ARRLEN; i++) {
   6.205 +        errn += verify("test_2vi_oppos: a1", i, a1[i], 123);
   6.206 +        errn += verify("test_2vi_oppos: a2", i, a2[i], 103);
   6.207 +      }
   6.208 +      // Reset for indexing with offset
   6.209 +      for (int i=0; i<ARRLEN; i++) {
   6.210 +        a1[i] = -1;
   6.211 +        a2[i] = -1;
   6.212 +      }
   6.213 +      test_ci_off(a1, -1);
   6.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.215 +        errn += verify("test_ci_off: a1", i, a1[i], -123);
   6.216 +      }
   6.217 +      test_vi_off(a2, 123, -1);
   6.218 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.219 +        errn += verify("test_vi_off: a2", i, a2[i], 123);
   6.220 +      }
   6.221 +      test_cp_off(a1, a2);
   6.222 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.223 +        errn += verify("test_cp_off: a1", i, a1[i], 123);
   6.224 +      }
   6.225 +      test_2ci_off(a1, a2);
   6.226 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.227 +        errn += verify("test_2ci_off: a1", i, a1[i], -123);
   6.228 +        errn += verify("test_2ci_off: a2", i, a2[i], -103);
   6.229 +      }
   6.230 +      test_2vi_off(a1, a2, 123, 103);
   6.231 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.232 +        errn += verify("test_2vi_off: a1", i, a1[i], 123);
   6.233 +        errn += verify("test_2vi_off: a2", i, a2[i], 103);
   6.234 +      }
   6.235 +      for (int i=0; i<OFFSET; i++) {
   6.236 +        errn += verify("test_2vi_off: a1", i, a1[i], -1);
   6.237 +        errn += verify("test_2vi_off: a2", i, a2[i], -1);
   6.238 +      }
   6.239 +      // Reset for indexing with invariant offset
   6.240 +      for (int i=0; i<ARRLEN; i++) {
   6.241 +        a1[i] = -1;
   6.242 +        a2[i] = -1;
   6.243 +      }
   6.244 +      test_ci_inv(a1, OFFSET, -1);
   6.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.246 +        errn += verify("test_ci_inv: a1", i, a1[i], -123);
   6.247 +      }
   6.248 +      test_vi_inv(a2, 123, OFFSET, -1);
   6.249 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.250 +        errn += verify("test_vi_inv: a2", i, a2[i], 123);
   6.251 +      }
   6.252 +      test_cp_inv(a1, a2, OFFSET);
   6.253 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.254 +        errn += verify("test_cp_inv: a1", i, a1[i], 123);
   6.255 +      }
   6.256 +      test_2ci_inv(a1, a2, OFFSET);
   6.257 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.258 +        errn += verify("test_2ci_inv: a1", i, a1[i], -123);
   6.259 +        errn += verify("test_2ci_inv: a2", i, a2[i], -103);
   6.260 +      }
   6.261 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   6.262 +      for (int i=OFFSET; i<ARRLEN; i++) {
   6.263 +        errn += verify("test_2vi_inv: a1", i, a1[i], 123);
   6.264 +        errn += verify("test_2vi_inv: a2", i, a2[i], 103);
   6.265 +      }
   6.266 +      for (int i=0; i<OFFSET; i++) {
   6.267 +        errn += verify("test_2vi_inv: a1", i, a1[i], -1);
   6.268 +        errn += verify("test_2vi_inv: a2", i, a2[i], -1);
   6.269 +      }
   6.270 +      // Reset for indexing with scale
   6.271 +      for (int i=0; i<ARRLEN; i++) {
   6.272 +        a1[i] = -1;
   6.273 +        a2[i] = -1;
   6.274 +      }
   6.275 +      test_ci_scl(a1, -1);
   6.276 +      for (int i=0; i<ARRLEN; i++) {
   6.277 +        int val = (i%SCALE != 0) ? -1 : -123;
   6.278 +        errn += verify("test_ci_scl: a1", i, a1[i], val);
   6.279 +      }
   6.280 +      test_vi_scl(a2, 123, -1);
   6.281 +      for (int i=0; i<ARRLEN; i++) {
   6.282 +        int val = (i%SCALE != 0) ? -1 : 123;
   6.283 +        errn += verify("test_vi_scl: a2", i, a2[i], val);
   6.284 +      }
   6.285 +      test_cp_scl(a1, a2);
   6.286 +      for (int i=0; i<ARRLEN; i++) {
   6.287 +        int val = (i%SCALE != 0) ? -1 : 123;
   6.288 +        errn += verify("test_cp_scl: a1", i, a1[i], val);
   6.289 +      }
   6.290 +      test_2ci_scl(a1, a2);
   6.291 +      for (int i=0; i<ARRLEN; i++) {
   6.292 +        if (i%SCALE != 0) {
   6.293 +          errn += verify("test_2ci_scl: a1", i, a1[i], -1);
   6.294 +        } else if (i*SCALE < ARRLEN) {
   6.295 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1[i*SCALE], -123);
   6.296 +        }
   6.297 +        if (i%SCALE != 0) {
   6.298 +          errn += verify("test_2ci_scl: a2", i, a2[i], -1);
   6.299 +        } else if (i*SCALE < ARRLEN) {
   6.300 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2[i*SCALE], -103);
   6.301 +        }
   6.302 +      }
   6.303 +      test_2vi_scl(a1, a2, 123, 103);
   6.304 +      for (int i=0; i<ARRLEN; i++) {
   6.305 +        if (i%SCALE != 0) {
   6.306 +          errn += verify("test_2vi_scl: a1", i, a1[i], -1);
   6.307 +        } else if (i*SCALE < ARRLEN) {
   6.308 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1[i*SCALE], 123);
   6.309 +        }
   6.310 +        if (i%SCALE != 0) {
   6.311 +          errn += verify("test_2vi_scl: a2", i, a2[i], -1);
   6.312 +        } else if (i*SCALE < ARRLEN) {
   6.313 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2[i*SCALE], 103);
   6.314 +        }
   6.315 +      }
   6.316 +      // Reset for 2 arrays with relative aligned offset
   6.317 +      for (int i=0; i<ARRLEN; i++) {
   6.318 +        a1[i] = -1;
   6.319 +        a2[i] = -1;
   6.320 +      }
   6.321 +      test_vi(a2, 123, -1);
   6.322 +      test_cp_alndst(a1, a2);
   6.323 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.324 +        errn += verify("test_cp_alndst: a1", i, a1[i], -1);
   6.325 +      }
   6.326 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   6.327 +        errn += verify("test_cp_alndst: a1", i, a1[i], 123);
   6.328 +      }
   6.329 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.330 +        a1[i] = 123;
   6.331 +      }
   6.332 +      test_vi(a2, -123, 123);
   6.333 +      test_cp_alnsrc(a1, a2);
   6.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   6.335 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], -123);
   6.336 +      }
   6.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   6.338 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], 123);
   6.339 +      }
   6.340 +      for (int i=0; i<ARRLEN; i++) {
   6.341 +        a1[i] = -1;
   6.342 +        a2[i] = -1;
   6.343 +      }
   6.344 +      test_2ci_aln(a1, a2);
   6.345 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.346 +        errn += verify("test_2ci_aln: a1", i, a1[i], -1);
   6.347 +      }
   6.348 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   6.349 +        errn += verify("test_2ci_aln: a1", i, a1[i], -123);
   6.350 +      }
   6.351 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   6.352 +        errn += verify("test_2ci_aln: a2", i, a2[i], -103);
   6.353 +      }
   6.354 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   6.355 +        errn += verify("test_2ci_aln: a2", i, a2[i], -1);
   6.356 +      }
   6.357 +      for (int i=0; i<ARRLEN; i++) {
   6.358 +        a1[i] = -1;
   6.359 +        a2[i] = -1;
   6.360 +      }
   6.361 +      test_2vi_aln(a1, a2, 123, 103);
   6.362 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   6.363 +        errn += verify("test_2vi_aln: a1", i, a1[i], 123);
   6.364 +      }
   6.365 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   6.366 +        errn += verify("test_2vi_aln: a1", i, a1[i], -1);
   6.367 +      }
   6.368 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.369 +        errn += verify("test_2vi_aln: a2", i, a2[i], -1);
   6.370 +      }
   6.371 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   6.372 +        errn += verify("test_2vi_aln: a2", i, a2[i], 103);
   6.373 +      }
   6.374 +
   6.375 +      // Reset for 2 arrays with relative unaligned offset
   6.376 +      for (int i=0; i<ARRLEN; i++) {
   6.377 +        a1[i] = -1;
   6.378 +        a2[i] = -1;
   6.379 +      }
   6.380 +      test_vi(a2, 123, -1);
   6.381 +      test_cp_unalndst(a1, a2);
   6.382 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.383 +        errn += verify("test_cp_unalndst: a1", i, a1[i], -1);
   6.384 +      }
   6.385 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   6.386 +        errn += verify("test_cp_unalndst: a1", i, a1[i], 123);
   6.387 +      }
   6.388 +      test_vi(a2, -123, 123);
   6.389 +      test_cp_unalnsrc(a1, a2);
   6.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   6.391 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], -123);
   6.392 +      }
   6.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   6.394 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], 123);
   6.395 +      }
   6.396 +      for (int i=0; i<ARRLEN; i++) {
   6.397 +        a1[i] = -1;
   6.398 +        a2[i] = -1;
   6.399 +      }
   6.400 +      test_2ci_unaln(a1, a2);
   6.401 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.402 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -1);
   6.403 +      }
   6.404 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   6.405 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -123);
   6.406 +      }
   6.407 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   6.408 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -103);
   6.409 +      }
   6.410 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   6.411 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -1);
   6.412 +      }
   6.413 +      for (int i=0; i<ARRLEN; i++) {
   6.414 +        a1[i] = -1;
   6.415 +        a2[i] = -1;
   6.416 +      }
   6.417 +      test_2vi_unaln(a1, a2, 123, 103);
   6.418 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   6.419 +        errn += verify("test_2vi_unaln: a1", i, a1[i], 123);
   6.420 +      }
   6.421 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   6.422 +        errn += verify("test_2vi_unaln: a1", i, a1[i], -1);
   6.423 +      }
   6.424 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.425 +        errn += verify("test_2vi_unaln: a2", i, a2[i], -1);
   6.426 +      }
   6.427 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   6.428 +        errn += verify("test_2vi_unaln: a2", i, a2[i], 103);
   6.429 +      }
   6.430 +
   6.431 +      // Reset for aligned overlap initialization
   6.432 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.433 +        a1[i] = i;
   6.434 +      }
   6.435 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   6.436 +        a1[i] = -1;
   6.437 +      }
   6.438 +      test_cp_alndst(a1, a1);
   6.439 +      for (int i=0; i<ARRLEN; i++) {
   6.440 +        int v = i%ALIGN_OFF;
   6.441 +        errn += verify("test_cp_alndst_overlap: a1", i, a1[i], v);
   6.442 +      }
   6.443 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.444 +        a1[i+ALIGN_OFF] = -1;
   6.445 +      }
   6.446 +      test_cp_alnsrc(a1, a1);
   6.447 +      for (int i=0; i<ALIGN_OFF; i++) {
   6.448 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], -1);
   6.449 +      }
   6.450 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   6.451 +        int v = i%ALIGN_OFF;
   6.452 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], v);
   6.453 +      }
   6.454 +      for (int i=0; i<ARRLEN; i++) {
   6.455 +        a1[i] = -1;
   6.456 +      }
   6.457 +      test_2ci_aln(a1, a1);
   6.458 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   6.459 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -103);
   6.460 +      }
   6.461 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   6.462 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -123);
   6.463 +      }
   6.464 +      for (int i=0; i<ARRLEN; i++) {
   6.465 +        a1[i] = -1;
   6.466 +      }
   6.467 +      test_2vi_aln(a1, a1, 123, 103);
   6.468 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   6.469 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 123);
   6.470 +      }
   6.471 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   6.472 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 103);
   6.473 +      }
   6.474 +
   6.475 +      // Reset for unaligned overlap initialization
   6.476 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.477 +        a1[i] = i;
   6.478 +      }
   6.479 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   6.480 +        a1[i] = -1;
   6.481 +      }
   6.482 +      test_cp_unalndst(a1, a1);
   6.483 +      for (int i=0; i<ARRLEN; i++) {
   6.484 +        int v = i%UNALIGN_OFF;
   6.485 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1[i], v);
   6.486 +      }
   6.487 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.488 +        a1[i+UNALIGN_OFF] = -1;
   6.489 +      }
   6.490 +      test_cp_unalnsrc(a1, a1);
   6.491 +      for (int i=0; i<UNALIGN_OFF; i++) {
   6.492 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], -1);
   6.493 +      }
   6.494 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   6.495 +        int v = i%UNALIGN_OFF;
   6.496 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], v);
   6.497 +      }
   6.498 +      for (int i=0; i<ARRLEN; i++) {
   6.499 +        a1[i] = -1;
   6.500 +      }
   6.501 +      test_2ci_unaln(a1, a1);
   6.502 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   6.503 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -103);
   6.504 +      }
   6.505 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   6.506 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -123);
   6.507 +      }
   6.508 +      for (int i=0; i<ARRLEN; i++) {
   6.509 +        a1[i] = -1;
   6.510 +      }
   6.511 +      test_2vi_unaln(a1, a1, 123, 103);
   6.512 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   6.513 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 123);
   6.514 +      }
   6.515 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   6.516 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 103);
   6.517 +      }
   6.518 +
   6.519 +    }
   6.520 +
   6.521 +    if (errn > 0 || test_only)
   6.522 +      return errn;
   6.523 +
   6.524 +    // Initialize
   6.525 +    for (int i=0; i<ARRLEN; i++) {
   6.526 +      a1[i] = -1;
   6.527 +      a2[i] = -1;
   6.528 +    }
   6.529 +    System.out.println("Time");
   6.530 +    long start, end;
   6.531 +    start = System.currentTimeMillis();
   6.532 +    for (int i=0; i<ITERS; i++) {
   6.533 +      test_ci(a1);
   6.534 +    }
   6.535 +    end = System.currentTimeMillis();
   6.536 +    System.out.println("test_ci: " + (end - start));
   6.537 +    start = System.currentTimeMillis();
   6.538 +    for (int i=0; i<ITERS; i++) {
   6.539 +      test_vi(a2, 123, -1);
   6.540 +    }
   6.541 +    end = System.currentTimeMillis();
   6.542 +    System.out.println("test_vi: " + (end - start));
   6.543 +    start = System.currentTimeMillis();
   6.544 +    for (int i=0; i<ITERS; i++) {
   6.545 +      test_cp(a1, a2);
   6.546 +    }
   6.547 +    end = System.currentTimeMillis();
   6.548 +    System.out.println("test_cp: " + (end - start));
   6.549 +    start = System.currentTimeMillis();
   6.550 +    for (int i=0; i<ITERS; i++) {
   6.551 +      test_2ci(a1, a2);
   6.552 +    }
   6.553 +    end = System.currentTimeMillis();
   6.554 +    System.out.println("test_2ci: " + (end - start));
   6.555 +    start = System.currentTimeMillis();
   6.556 +    for (int i=0; i<ITERS; i++) {
   6.557 +      test_2vi(a1, a2, 123, 103);
   6.558 +    }
   6.559 +    end = System.currentTimeMillis();
   6.560 +    System.out.println("test_2vi: " + (end - start));
   6.561 +
   6.562 +    start = System.currentTimeMillis();
   6.563 +    for (int i=0; i<ITERS; i++) {
   6.564 +      test_ci_neg(a1, 123);
   6.565 +    }
   6.566 +    end = System.currentTimeMillis();
   6.567 +    System.out.println("test_ci_neg: " + (end - start));
   6.568 +    start = System.currentTimeMillis();
   6.569 +    for (int i=0; i<ITERS; i++) {
   6.570 +      test_vi_neg(a2, 123, 103);
   6.571 +    }
   6.572 +    end = System.currentTimeMillis();
   6.573 +    System.out.println("test_vi_neg: " + (end - start));
   6.574 +    start = System.currentTimeMillis();
   6.575 +    for (int i=0; i<ITERS; i++) {
   6.576 +      test_cp_neg(a1, a2);
   6.577 +    }
   6.578 +    end = System.currentTimeMillis();
   6.579 +    System.out.println("test_cp_neg: " + (end - start));
   6.580 +    start = System.currentTimeMillis();
   6.581 +    for (int i=0; i<ITERS; i++) {
   6.582 +      test_2ci_neg(a1, a2);
   6.583 +    }
   6.584 +    end = System.currentTimeMillis();
   6.585 +    System.out.println("test_2ci_neg: " + (end - start));
   6.586 +    start = System.currentTimeMillis();
   6.587 +    for (int i=0; i<ITERS; i++) {
   6.588 +      test_2vi_neg(a1, a2, 123, 103);
   6.589 +    }
   6.590 +    end = System.currentTimeMillis();
   6.591 +    System.out.println("test_2vi_neg: " + (end - start));
   6.592 +
   6.593 +    start = System.currentTimeMillis();
   6.594 +    for (int i=0; i<ITERS; i++) {
   6.595 +      test_ci_oppos(a1, 123);
   6.596 +    }
   6.597 +    end = System.currentTimeMillis();
   6.598 +    System.out.println("test_ci_oppos: " + (end - start));
   6.599 +    start = System.currentTimeMillis();
   6.600 +    for (int i=0; i<ITERS; i++) {
   6.601 +      test_vi_oppos(a2, 123, 103);
   6.602 +    }
   6.603 +    end = System.currentTimeMillis();
   6.604 +    System.out.println("test_vi_oppos: " + (end - start));
   6.605 +    start = System.currentTimeMillis();
   6.606 +    for (int i=0; i<ITERS; i++) {
   6.607 +      test_cp_oppos(a1, a2);
   6.608 +    }
   6.609 +    end = System.currentTimeMillis();
   6.610 +    System.out.println("test_cp_oppos: " + (end - start));
   6.611 +    start = System.currentTimeMillis();
   6.612 +    for (int i=0; i<ITERS; i++) {
   6.613 +      test_2ci_oppos(a1, a2);
   6.614 +    }
   6.615 +    end = System.currentTimeMillis();
   6.616 +    System.out.println("test_2ci_oppos: " + (end - start));
   6.617 +    start = System.currentTimeMillis();
   6.618 +    for (int i=0; i<ITERS; i++) {
   6.619 +      test_2vi_oppos(a1, a2, 123, 103);
   6.620 +    }
   6.621 +    end = System.currentTimeMillis();
   6.622 +    System.out.println("test_2vi_oppos: " + (end - start));
   6.623 +
   6.624 +    start = System.currentTimeMillis();
   6.625 +    for (int i=0; i<ITERS; i++) {
   6.626 +      test_ci_off(a1, 123);
   6.627 +    }
   6.628 +    end = System.currentTimeMillis();
   6.629 +    System.out.println("test_ci_off: " + (end - start));
   6.630 +    start = System.currentTimeMillis();
   6.631 +    for (int i=0; i<ITERS; i++) {
   6.632 +      test_vi_off(a2, 123, 103);
   6.633 +    }
   6.634 +    end = System.currentTimeMillis();
   6.635 +    System.out.println("test_vi_off: " + (end - start));
   6.636 +    start = System.currentTimeMillis();
   6.637 +    for (int i=0; i<ITERS; i++) {
   6.638 +      test_cp_off(a1, a2);
   6.639 +    }
   6.640 +    end = System.currentTimeMillis();
   6.641 +    System.out.println("test_cp_off: " + (end - start));
   6.642 +    start = System.currentTimeMillis();
   6.643 +    for (int i=0; i<ITERS; i++) {
   6.644 +      test_2ci_off(a1, a2);
   6.645 +    }
   6.646 +    end = System.currentTimeMillis();
   6.647 +    System.out.println("test_2ci_off: " + (end - start));
   6.648 +    start = System.currentTimeMillis();
   6.649 +    for (int i=0; i<ITERS; i++) {
   6.650 +      test_2vi_off(a1, a2, 123, 103);
   6.651 +    }
   6.652 +    end = System.currentTimeMillis();
   6.653 +    System.out.println("test_2vi_off: " + (end - start));
   6.654 +
   6.655 +    start = System.currentTimeMillis();
   6.656 +    for (int i=0; i<ITERS; i++) {
   6.657 +      test_ci_inv(a1, OFFSET, 123);
   6.658 +    }
   6.659 +    end = System.currentTimeMillis();
   6.660 +    System.out.println("test_ci_inv: " + (end - start));
   6.661 +    start = System.currentTimeMillis();
   6.662 +    for (int i=0; i<ITERS; i++) {
   6.663 +      test_vi_inv(a2, 123, OFFSET, 103);
   6.664 +    }
   6.665 +    end = System.currentTimeMillis();
   6.666 +    System.out.println("test_vi_inv: " + (end - start));
   6.667 +    start = System.currentTimeMillis();
   6.668 +    for (int i=0; i<ITERS; i++) {
   6.669 +      test_cp_inv(a1, a2, OFFSET);
   6.670 +    }
   6.671 +    end = System.currentTimeMillis();
   6.672 +    System.out.println("test_cp_inv: " + (end - start));
   6.673 +    start = System.currentTimeMillis();
   6.674 +    for (int i=0; i<ITERS; i++) {
   6.675 +      test_2ci_inv(a1, a2, OFFSET);
   6.676 +    }
   6.677 +    end = System.currentTimeMillis();
   6.678 +    System.out.println("test_2ci_inv: " + (end - start));
   6.679 +    start = System.currentTimeMillis();
   6.680 +    for (int i=0; i<ITERS; i++) {
   6.681 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   6.682 +    }
   6.683 +    end = System.currentTimeMillis();
   6.684 +    System.out.println("test_2vi_inv: " + (end - start));
   6.685 +
   6.686 +    start = System.currentTimeMillis();
   6.687 +    for (int i=0; i<ITERS; i++) {
   6.688 +      test_ci_scl(a1, 123);
   6.689 +    }
   6.690 +    end = System.currentTimeMillis();
   6.691 +    System.out.println("test_ci_scl: " + (end - start));
   6.692 +    start = System.currentTimeMillis();
   6.693 +    for (int i=0; i<ITERS; i++) {
   6.694 +      test_vi_scl(a2, 123, 103);
   6.695 +    }
   6.696 +    end = System.currentTimeMillis();
   6.697 +    System.out.println("test_vi_scl: " + (end - start));
   6.698 +    start = System.currentTimeMillis();
   6.699 +    for (int i=0; i<ITERS; i++) {
   6.700 +      test_cp_scl(a1, a2);
   6.701 +    }
   6.702 +    end = System.currentTimeMillis();
   6.703 +    System.out.println("test_cp_scl: " + (end - start));
   6.704 +    start = System.currentTimeMillis();
   6.705 +    for (int i=0; i<ITERS; i++) {
   6.706 +      test_2ci_scl(a1, a2);
   6.707 +    }
   6.708 +    end = System.currentTimeMillis();
   6.709 +    System.out.println("test_2ci_scl: " + (end - start));
   6.710 +    start = System.currentTimeMillis();
   6.711 +    for (int i=0; i<ITERS; i++) {
   6.712 +      test_2vi_scl(a1, a2, 123, 103);
   6.713 +    }
   6.714 +    end = System.currentTimeMillis();
   6.715 +    System.out.println("test_2vi_scl: " + (end - start));
   6.716 +
   6.717 +    start = System.currentTimeMillis();
   6.718 +    for (int i=0; i<ITERS; i++) {
   6.719 +      test_cp_alndst(a1, a2);
   6.720 +    }
   6.721 +    end = System.currentTimeMillis();
   6.722 +    System.out.println("test_cp_alndst: " + (end - start));
   6.723 +    start = System.currentTimeMillis();
   6.724 +    for (int i=0; i<ITERS; i++) {
   6.725 +      test_cp_alnsrc(a1, a2);
   6.726 +    }
   6.727 +    end = System.currentTimeMillis();
   6.728 +    System.out.println("test_cp_alnsrc: " + (end - start));
   6.729 +    start = System.currentTimeMillis();
   6.730 +    for (int i=0; i<ITERS; i++) {
   6.731 +      test_2ci_aln(a1, a2);
   6.732 +    }
   6.733 +    end = System.currentTimeMillis();
   6.734 +    System.out.println("test_2ci_aln: " + (end - start));
   6.735 +    start = System.currentTimeMillis();
   6.736 +    for (int i=0; i<ITERS; i++) {
   6.737 +      test_2vi_aln(a1, a2, 123, 103);
   6.738 +    }
   6.739 +    end = System.currentTimeMillis();
   6.740 +    System.out.println("test_2vi_aln: " + (end - start));
   6.741 +
   6.742 +    start = System.currentTimeMillis();
   6.743 +    for (int i=0; i<ITERS; i++) {
   6.744 +      test_cp_unalndst(a1, a2);
   6.745 +    }
   6.746 +    end = System.currentTimeMillis();
   6.747 +    System.out.println("test_cp_unalndst: " + (end - start));
   6.748 +    start = System.currentTimeMillis();
   6.749 +    for (int i=0; i<ITERS; i++) {
   6.750 +      test_cp_unalnsrc(a1, a2);
   6.751 +    }
   6.752 +    end = System.currentTimeMillis();
   6.753 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   6.754 +    start = System.currentTimeMillis();
   6.755 +    for (int i=0; i<ITERS; i++) {
   6.756 +      test_2ci_unaln(a1, a2);
   6.757 +    }
   6.758 +    end = System.currentTimeMillis();
   6.759 +    System.out.println("test_2ci_unaln: " + (end - start));
   6.760 +    start = System.currentTimeMillis();
   6.761 +    for (int i=0; i<ITERS; i++) {
   6.762 +      test_2vi_unaln(a1, a2, 123, 103);
   6.763 +    }
   6.764 +    end = System.currentTimeMillis();
   6.765 +    System.out.println("test_2vi_unaln: " + (end - start));
   6.766 +
   6.767 +    return errn;
   6.768 +  }
   6.769 +
   6.770 +  private final static long byte_offset(int i) {
   6.771 +    return ((long)i << 2) + BASE;
   6.772 +  }
   6.773 +
   6.774 +  static void test_ci(int[] a) {
   6.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.776 +      unsafe.compareAndSwapInt(a, byte_offset(i), -1, -123);
   6.777 +    }
   6.778 +  }
   6.779 +  static void test_vi(int[] a, int b, int old) {
   6.780 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.781 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, b);
   6.782 +    }
   6.783 +  }
   6.784 +  static void test_cp(int[] a, int[] b) {
   6.785 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.786 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[i]);
   6.787 +    }
   6.788 +  }
   6.789 +  static void test_2ci(int[] a, int[] b) {
   6.790 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.791 +      unsafe.compareAndSwapInt(a, byte_offset(i), 123, -123);
   6.792 +      unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103);
   6.793 +    }
   6.794 +  }
   6.795 +  static void test_2vi(int[] a, int[] b, int c, int d) {
   6.796 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.797 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, c);
   6.798 +      unsafe.compareAndSwapInt(b, byte_offset(i), -103, d);
   6.799 +    }
   6.800 +  }
   6.801 +  static void test_ci_neg(int[] a, int old) {
   6.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   6.803 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, -123);
   6.804 +    }
   6.805 +  }
   6.806 +  static void test_vi_neg(int[] a, int b, int old) {
   6.807 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   6.808 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, b);
   6.809 +    }
   6.810 +  }
   6.811 +  static void test_cp_neg(int[] a, int[] b) {
   6.812 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   6.813 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[i]);
   6.814 +    }
   6.815 +  }
   6.816 +  static void test_2ci_neg(int[] a, int[] b) {
   6.817 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   6.818 +      unsafe.compareAndSwapInt(a, byte_offset(i), 123, -123);
   6.819 +      unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103);
   6.820 +    }
   6.821 +  }
   6.822 +  static void test_2vi_neg(int[] a, int[] b, int c, int d) {
   6.823 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   6.824 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, c);
   6.825 +      unsafe.compareAndSwapInt(b, byte_offset(i), -103, d);
   6.826 +    }
   6.827 +  }
   6.828 +  static void test_ci_oppos(int[] a, int old) {
   6.829 +    int limit = ARRLEN-1;
   6.830 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.831 +      unsafe.compareAndSwapInt(a, byte_offset(limit-i), old, -123);
   6.832 +    }
   6.833 +  }
   6.834 +  static void test_vi_oppos(int[] a, int b, int old) {
   6.835 +    int limit = ARRLEN-1;
   6.836 +    for (int i = limit; i >= 0; i-=1) {
   6.837 +      unsafe.compareAndSwapInt(a, byte_offset(limit-i), old, b);
   6.838 +    }
   6.839 +  }
   6.840 +  static void test_cp_oppos(int[] a, int[] b) {
   6.841 +    int limit = ARRLEN-1;
   6.842 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.843 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, b[limit-i]);
   6.844 +    }
   6.845 +  }
   6.846 +  static void test_2ci_oppos(int[] a, int[] b) {
   6.847 +    int limit = ARRLEN-1;
   6.848 +    for (int i = 0; i < ARRLEN; i+=1) {
   6.849 +      unsafe.compareAndSwapInt(a, byte_offset(limit-i), 123, -123);
   6.850 +      unsafe.compareAndSwapInt(b, byte_offset(i), 123, -103);
   6.851 +    }
   6.852 +  }
   6.853 +  static void test_2vi_oppos(int[] a, int[] b, int c, int d) {
   6.854 +    int limit = ARRLEN-1;
   6.855 +    for (int i = limit; i >= 0; i-=1) {
   6.856 +      unsafe.compareAndSwapInt(a, byte_offset(i), -123, c);
   6.857 +      unsafe.compareAndSwapInt(b, byte_offset(limit-i), -103, d);
   6.858 +    }
   6.859 +  }
   6.860 +  static void test_ci_off(int[] a, int old) {
   6.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   6.862 +      unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), old, -123);
   6.863 +    }
   6.864 +  }
   6.865 +  static void test_vi_off(int[] a, int b, int old) {
   6.866 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   6.867 +      unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), old, b);
   6.868 +    }
   6.869 +  }
   6.870 +  static void test_cp_off(int[] a, int[] b) {
   6.871 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   6.872 +      unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), -123, b[i+OFFSET]);
   6.873 +    }
   6.874 +  }
   6.875 +  static void test_2ci_off(int[] a, int[] b) {
   6.876 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   6.877 +      unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), 123, -123);
   6.878 +      unsafe.compareAndSwapInt(b, byte_offset(i+OFFSET), 123, -103);
   6.879 +    }
   6.880 +  }
   6.881 +  static void test_2vi_off(int[] a, int[] b, int c, int d) {
   6.882 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   6.883 +      unsafe.compareAndSwapInt(a, byte_offset(i+OFFSET), -123, c);
   6.884 +      unsafe.compareAndSwapInt(b, byte_offset(i+OFFSET), -103, d);
   6.885 +    }
   6.886 +  }
   6.887 +  static void test_ci_inv(int[] a, int k, int old) {
   6.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   6.889 +      unsafe.compareAndSwapInt(a, byte_offset(i+k), old, -123);
   6.890 +    }
   6.891 +  }
   6.892 +  static void test_vi_inv(int[] a, int b, int k, int old) {
   6.893 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   6.894 +      unsafe.compareAndSwapInt(a, byte_offset(i+k), old, b);
   6.895 +    }
   6.896 +  }
   6.897 +  static void test_cp_inv(int[] a, int[] b, int k) {
   6.898 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   6.899 +      unsafe.compareAndSwapInt(a, byte_offset(i+k), -123, b[i+k]);
   6.900 +    }
   6.901 +  }
   6.902 +  static void test_2ci_inv(int[] a, int[] b, int k) {
   6.903 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   6.904 +      unsafe.compareAndSwapInt(a, byte_offset(i+k), 123, -123);
   6.905 +      unsafe.compareAndSwapInt(b, byte_offset(i+k), 123, -103);
   6.906 +    }
   6.907 +  }
   6.908 +  static void test_2vi_inv(int[] a, int[] b, int c, int d, int k) {
   6.909 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   6.910 +      unsafe.compareAndSwapInt(a, byte_offset(i+k), -123, c);
   6.911 +      unsafe.compareAndSwapInt(b, byte_offset(i+k), -103, d);
   6.912 +    }
   6.913 +  }
   6.914 +  static void test_ci_scl(int[] a, int old) {
   6.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   6.916 +      unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), old, -123);
   6.917 +    }
   6.918 +  }
   6.919 +  static void test_vi_scl(int[] a, int b, int old) {
   6.920 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   6.921 +      unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), old, b);
   6.922 +    }
   6.923 +  }
   6.924 +  static void test_cp_scl(int[] a, int[] b) {
   6.925 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   6.926 +      unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), -123, b[i*SCALE]);
   6.927 +    }
   6.928 +  }
   6.929 +  static void test_2ci_scl(int[] a, int[] b) {
   6.930 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   6.931 +      unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), 123, -123);
   6.932 +      unsafe.compareAndSwapInt(b, byte_offset(i*SCALE), 123, -103);
   6.933 +    }
   6.934 +  }
   6.935 +  static void test_2vi_scl(int[] a, int[] b, int c, int d) {
   6.936 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   6.937 +      unsafe.compareAndSwapInt(a, byte_offset(i*SCALE), -123, c);
   6.938 +      unsafe.compareAndSwapInt(b, byte_offset(i*SCALE), -103, d);
   6.939 +    }
   6.940 +  }
   6.941 +  static void test_cp_alndst(int[] a, int[] b) {
   6.942 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   6.943 +      unsafe.compareAndSwapInt(a, byte_offset(i+ALIGN_OFF), -1, b[i]);
   6.944 +    }
   6.945 +  }
   6.946 +  static void test_cp_alnsrc(int[] a, int[] b) {
   6.947 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   6.948 +      int old = unsafe.getIntVolatile(a, byte_offset(i));
   6.949 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, b[i+ALIGN_OFF]);
   6.950 +    }
   6.951 +  }
   6.952 +  static void test_2ci_aln(int[] a, int[] b) {
   6.953 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   6.954 +      unsafe.compareAndSwapInt(a, byte_offset(i+ALIGN_OFF), -1, -123);
   6.955 +      int old = unsafe.getIntVolatile(b, byte_offset(i));
   6.956 +      unsafe.compareAndSwapInt(b, byte_offset(i), old, -103);
   6.957 +    }
   6.958 +  }
   6.959 +  static void test_2vi_aln(int[] a, int[] b, int c, int d) {
   6.960 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   6.961 +      int old = unsafe.getIntVolatile(a, byte_offset(i));
   6.962 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, c);
   6.963 +      old = unsafe.getIntVolatile(b, byte_offset(i+ALIGN_OFF));
   6.964 +      unsafe.compareAndSwapInt(b, byte_offset(i+ALIGN_OFF), old, d);
   6.965 +    }
   6.966 +  }
   6.967 +  static void test_cp_unalndst(int[] a, int[] b) {
   6.968 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   6.969 +      unsafe.compareAndSwapInt(a, byte_offset(i+UNALIGN_OFF), -1, b[i]);
   6.970 +    }
   6.971 +  }
   6.972 +  static void test_cp_unalnsrc(int[] a, int[] b) {
   6.973 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   6.974 +      int old = unsafe.getIntVolatile(a, byte_offset(i));
   6.975 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, b[i+UNALIGN_OFF]);
   6.976 +    }
   6.977 +  }
   6.978 +  static void test_2ci_unaln(int[] a, int[] b) {
   6.979 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   6.980 +      unsafe.compareAndSwapInt(a, byte_offset(i+UNALIGN_OFF), -1, -123);
   6.981 +      int old = unsafe.getIntVolatile(b, byte_offset(i));
   6.982 +      unsafe.compareAndSwapInt(b, byte_offset(i), old, -103);
   6.983 +    }
   6.984 +  }
   6.985 +  static void test_2vi_unaln(int[] a, int[] b, int c, int d) {
   6.986 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   6.987 +      int old = unsafe.getIntVolatile(a, byte_offset(i));
   6.988 +      unsafe.compareAndSwapInt(a, byte_offset(i), old, c);
   6.989 +      old = unsafe.getIntVolatile(b, byte_offset(i+UNALIGN_OFF));
   6.990 +      unsafe.compareAndSwapInt(b, byte_offset(i+UNALIGN_OFF), old, d);
   6.991 +    }
   6.992 +  }
   6.993 +
   6.994 +  static int verify(String text, int i, int elem, int val) {
   6.995 +    if (elem != val) {
   6.996 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   6.997 +      return 1;
   6.998 +    }
   6.999 +    return 0;
  6.1000 +  }
  6.1001 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/compiler/8004867/TestIntUnsafeOrdered.java	Mon Feb 18 16:47:15 2013 -0800
     7.3 @@ -0,0 +1,990 @@
     7.4 +/*
     7.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 + * or visit www.oracle.com if you need additional information or have any
    7.24 + * questions.
    7.25 + *
    7.26 + */
    7.27 +
    7.28 +/**
    7.29 + * @test
    7.30 + * @bug 8004867
    7.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    7.32 + *
    7.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntUnsafeOrdered
    7.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntUnsafeOrdered
    7.35 + */
    7.36 +
    7.37 +import sun.misc.Unsafe;
    7.38 +import java.lang.reflect.*;
    7.39 +
    7.40 +public class TestIntUnsafeOrdered {
    7.41 +  private static final int ARRLEN = 97;
    7.42 +  private static final int ITERS  = 11000;
    7.43 +  private static final int OFFSET = 3;
    7.44 +  private static final int SCALE = 2;
    7.45 +  private static final int ALIGN_OFF = 8;
    7.46 +  private static final int UNALIGN_OFF = 5;
    7.47 +
    7.48 +  private static final Unsafe unsafe;
    7.49 +  private static final int BASE;
    7.50 +  static {
    7.51 +    try {
    7.52 +      Class c = TestIntUnsafeOrdered.class.getClassLoader().loadClass("sun.misc.Unsafe");
    7.53 +      Field f = c.getDeclaredField("theUnsafe");
    7.54 +      f.setAccessible(true);
    7.55 +      unsafe = (Unsafe)f.get(c);
    7.56 +      BASE = unsafe.arrayBaseOffset(int[].class);
    7.57 +    } catch (Exception e) {
    7.58 +      InternalError err = new InternalError();
    7.59 +      err.initCause(e);
    7.60 +      throw err;
    7.61 +    }
    7.62 +  }
    7.63 +
    7.64 +  public static void main(String args[]) {
    7.65 +    System.out.println("Testing Integer array unsafe ordered operations");
    7.66 +    int errn = test(false);
    7.67 +    if (errn > 0) {
    7.68 +      System.err.println("FAILED: " + errn + " errors");
    7.69 +      System.exit(97);
    7.70 +    }
    7.71 +    System.out.println("PASSED");
    7.72 +  }
    7.73 +
    7.74 +  static int test(boolean test_only) {
    7.75 +    int[] a1 = new int[ARRLEN];
    7.76 +    int[] a2 = new int[ARRLEN];
    7.77 +    // Initialize
    7.78 +    for (int i=0; i<ARRLEN; i++) {
    7.79 +      a1[i] = -1;
    7.80 +      a2[i] = -1;
    7.81 +    }
    7.82 +    System.out.println("Warmup");
    7.83 +    for (int i=0; i<ITERS; i++) {
    7.84 +      test_ci(a1);
    7.85 +      test_vi(a2, 123, -1);
    7.86 +      test_cp(a1, a2);
    7.87 +      test_2ci(a1, a2);
    7.88 +      test_2vi(a1, a2, 123, 103);
    7.89 +      test_ci_neg(a1, 123);
    7.90 +      test_vi_neg(a2, 123, 103);
    7.91 +      test_cp_neg(a1, a2);
    7.92 +      test_2ci_neg(a1, a2);
    7.93 +      test_2vi_neg(a1, a2, 123, 103);
    7.94 +      test_ci_oppos(a1, 123);
    7.95 +      test_vi_oppos(a2, 123, 103);
    7.96 +      test_cp_oppos(a1, a2);
    7.97 +      test_2ci_oppos(a1, a2);
    7.98 +      test_2vi_oppos(a1, a2, 123, 103);
    7.99 +      test_ci_off(a1, 123);
   7.100 +      test_vi_off(a2, 123, 103);
   7.101 +      test_cp_off(a1, a2);
   7.102 +      test_2ci_off(a1, a2);
   7.103 +      test_2vi_off(a1, a2, 123, 103);
   7.104 +      test_ci_inv(a1, OFFSET, 123);
   7.105 +      test_vi_inv(a2, 123, OFFSET, 103);
   7.106 +      test_cp_inv(a1, a2, OFFSET);
   7.107 +      test_2ci_inv(a1, a2, OFFSET);
   7.108 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   7.109 +      test_ci_scl(a1, 123);
   7.110 +      test_vi_scl(a2, 123, 103);
   7.111 +      test_cp_scl(a1, a2);
   7.112 +      test_2ci_scl(a1, a2);
   7.113 +      test_2vi_scl(a1, a2, 123, 103);
   7.114 +      test_cp_alndst(a1, a2);
   7.115 +      test_cp_alnsrc(a1, a2);
   7.116 +      test_2ci_aln(a1, a2);
   7.117 +      test_2vi_aln(a1, a2, 123, 103);
   7.118 +      test_cp_unalndst(a1, a2);
   7.119 +      test_cp_unalnsrc(a1, a2);
   7.120 +      test_2ci_unaln(a1, a2);
   7.121 +      test_2vi_unaln(a1, a2, 123, 103);
   7.122 +    }
   7.123 +    // Initialize
   7.124 +    for (int i=0; i<ARRLEN; i++) {
   7.125 +      a1[i] = -1;
   7.126 +      a2[i] = -1;
   7.127 +    }
   7.128 +    // Test and verify results
   7.129 +    System.out.println("Verification");
   7.130 +    int errn = 0;
   7.131 +    {
   7.132 +      test_ci(a1);
   7.133 +      for (int i=0; i<ARRLEN; i++) {
   7.134 +        errn += verify("test_ci: a1", i, a1[i], -123);
   7.135 +      }
   7.136 +      test_vi(a2, 123, -1);
   7.137 +      for (int i=0; i<ARRLEN; i++) {
   7.138 +        errn += verify("test_vi: a2", i, a2[i], 123);
   7.139 +      }
   7.140 +      test_cp(a1, a2);
   7.141 +      for (int i=0; i<ARRLEN; i++) {
   7.142 +        errn += verify("test_cp: a1", i, a1[i], 123);
   7.143 +      }
   7.144 +      test_2ci(a1, a2);
   7.145 +      for (int i=0; i<ARRLEN; i++) {
   7.146 +        errn += verify("test_2ci: a1", i, a1[i], -123);
   7.147 +        errn += verify("test_2ci: a2", i, a2[i], -103);
   7.148 +      }
   7.149 +      test_2vi(a1, a2, 123, 103);
   7.150 +      for (int i=0; i<ARRLEN; i++) {
   7.151 +        errn += verify("test_2vi: a1", i, a1[i], 123);
   7.152 +        errn += verify("test_2vi: a2", i, a2[i], 103);
   7.153 +      }
   7.154 +      // Reset for negative stride
   7.155 +      for (int i=0; i<ARRLEN; i++) {
   7.156 +        a1[i] = -1;
   7.157 +        a2[i] = -1;
   7.158 +      }
   7.159 +      test_ci_neg(a1, -1);
   7.160 +      for (int i=0; i<ARRLEN; i++) {
   7.161 +        errn += verify("test_ci_neg: a1", i, a1[i], -123);
   7.162 +      }
   7.163 +      test_vi_neg(a2, 123, -1);
   7.164 +      for (int i=0; i<ARRLEN; i++) {
   7.165 +        errn += verify("test_vi_neg: a2", i, a2[i], 123);
   7.166 +      }
   7.167 +      test_cp_neg(a1, a2);
   7.168 +      for (int i=0; i<ARRLEN; i++) {
   7.169 +        errn += verify("test_cp_neg: a1", i, a1[i], 123);
   7.170 +      }
   7.171 +      test_2ci_neg(a1, a2);
   7.172 +      for (int i=0; i<ARRLEN; i++) {
   7.173 +        errn += verify("test_2ci_neg: a1", i, a1[i], -123);
   7.174 +        errn += verify("test_2ci_neg: a2", i, a2[i], -103);
   7.175 +      }
   7.176 +      test_2vi_neg(a1, a2, 123, 103);
   7.177 +      for (int i=0; i<ARRLEN; i++) {
   7.178 +        errn += verify("test_2vi_neg: a1", i, a1[i], 123);
   7.179 +        errn += verify("test_2vi_neg: a2", i, a2[i], 103);
   7.180 +      }
   7.181 +      // Reset for opposite stride
   7.182 +      for (int i=0; i<ARRLEN; i++) {
   7.183 +        a1[i] = -1;
   7.184 +        a2[i] = -1;
   7.185 +      }
   7.186 +      test_ci_oppos(a1, -1);
   7.187 +      for (int i=0; i<ARRLEN; i++) {
   7.188 +        errn += verify("test_ci_oppos: a1", i, a1[i], -123);
   7.189 +      }
   7.190 +      test_vi_oppos(a2, 123, -1);
   7.191 +      for (int i=0; i<ARRLEN; i++) {
   7.192 +        errn += verify("test_vi_oppos: a2", i, a2[i], 123);
   7.193 +      }
   7.194 +      test_cp_oppos(a1, a2);
   7.195 +      for (int i=0; i<ARRLEN; i++) {
   7.196 +        errn += verify("test_cp_oppos: a1", i, a1[i], 123);
   7.197 +      }
   7.198 +      test_2ci_oppos(a1, a2);
   7.199 +      for (int i=0; i<ARRLEN; i++) {
   7.200 +        errn += verify("test_2ci_oppos: a1", i, a1[i], -123);
   7.201 +        errn += verify("test_2ci_oppos: a2", i, a2[i], -103);
   7.202 +      }
   7.203 +      test_2vi_oppos(a1, a2, 123, 103);
   7.204 +      for (int i=0; i<ARRLEN; i++) {
   7.205 +        errn += verify("test_2vi_oppos: a1", i, a1[i], 123);
   7.206 +        errn += verify("test_2vi_oppos: a2", i, a2[i], 103);
   7.207 +      }
   7.208 +      // Reset for indexing with offset
   7.209 +      for (int i=0; i<ARRLEN; i++) {
   7.210 +        a1[i] = -1;
   7.211 +        a2[i] = -1;
   7.212 +      }
   7.213 +      test_ci_off(a1, -1);
   7.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.215 +        errn += verify("test_ci_off: a1", i, a1[i], -123);
   7.216 +      }
   7.217 +      test_vi_off(a2, 123, -1);
   7.218 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.219 +        errn += verify("test_vi_off: a2", i, a2[i], 123);
   7.220 +      }
   7.221 +      test_cp_off(a1, a2);
   7.222 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.223 +        errn += verify("test_cp_off: a1", i, a1[i], 123);
   7.224 +      }
   7.225 +      test_2ci_off(a1, a2);
   7.226 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.227 +        errn += verify("test_2ci_off: a1", i, a1[i], -123);
   7.228 +        errn += verify("test_2ci_off: a2", i, a2[i], -103);
   7.229 +      }
   7.230 +      test_2vi_off(a1, a2, 123, 103);
   7.231 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.232 +        errn += verify("test_2vi_off: a1", i, a1[i], 123);
   7.233 +        errn += verify("test_2vi_off: a2", i, a2[i], 103);
   7.234 +      }
   7.235 +      for (int i=0; i<OFFSET; i++) {
   7.236 +        errn += verify("test_2vi_off: a1", i, a1[i], -1);
   7.237 +        errn += verify("test_2vi_off: a2", i, a2[i], -1);
   7.238 +      }
   7.239 +      // Reset for indexing with invariant offset
   7.240 +      for (int i=0; i<ARRLEN; i++) {
   7.241 +        a1[i] = -1;
   7.242 +        a2[i] = -1;
   7.243 +      }
   7.244 +      test_ci_inv(a1, OFFSET, -1);
   7.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.246 +        errn += verify("test_ci_inv: a1", i, a1[i], -123);
   7.247 +      }
   7.248 +      test_vi_inv(a2, 123, OFFSET, -1);
   7.249 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.250 +        errn += verify("test_vi_inv: a2", i, a2[i], 123);
   7.251 +      }
   7.252 +      test_cp_inv(a1, a2, OFFSET);
   7.253 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.254 +        errn += verify("test_cp_inv: a1", i, a1[i], 123);
   7.255 +      }
   7.256 +      test_2ci_inv(a1, a2, OFFSET);
   7.257 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.258 +        errn += verify("test_2ci_inv: a1", i, a1[i], -123);
   7.259 +        errn += verify("test_2ci_inv: a2", i, a2[i], -103);
   7.260 +      }
   7.261 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   7.262 +      for (int i=OFFSET; i<ARRLEN; i++) {
   7.263 +        errn += verify("test_2vi_inv: a1", i, a1[i], 123);
   7.264 +        errn += verify("test_2vi_inv: a2", i, a2[i], 103);
   7.265 +      }
   7.266 +      for (int i=0; i<OFFSET; i++) {
   7.267 +        errn += verify("test_2vi_inv: a1", i, a1[i], -1);
   7.268 +        errn += verify("test_2vi_inv: a2", i, a2[i], -1);
   7.269 +      }
   7.270 +      // Reset for indexing with scale
   7.271 +      for (int i=0; i<ARRLEN; i++) {
   7.272 +        a1[i] = -1;
   7.273 +        a2[i] = -1;
   7.274 +      }
   7.275 +      test_ci_scl(a1, -1);
   7.276 +      for (int i=0; i<ARRLEN; i++) {
   7.277 +        int val = (i%SCALE != 0) ? -1 : -123;
   7.278 +        errn += verify("test_ci_scl: a1", i, a1[i], val);
   7.279 +      }
   7.280 +      test_vi_scl(a2, 123, -1);
   7.281 +      for (int i=0; i<ARRLEN; i++) {
   7.282 +        int val = (i%SCALE != 0) ? -1 : 123;
   7.283 +        errn += verify("test_vi_scl: a2", i, a2[i], val);
   7.284 +      }
   7.285 +      test_cp_scl(a1, a2);
   7.286 +      for (int i=0; i<ARRLEN; i++) {
   7.287 +        int val = (i%SCALE != 0) ? -1 : 123;
   7.288 +        errn += verify("test_cp_scl: a1", i, a1[i], val);
   7.289 +      }
   7.290 +      test_2ci_scl(a1, a2);
   7.291 +      for (int i=0; i<ARRLEN; i++) {
   7.292 +        if (i%SCALE != 0) {
   7.293 +          errn += verify("test_2ci_scl: a1", i, a1[i], -1);
   7.294 +        } else if (i*SCALE < ARRLEN) {
   7.295 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1[i*SCALE], -123);
   7.296 +        }
   7.297 +        if (i%SCALE != 0) {
   7.298 +          errn += verify("test_2ci_scl: a2", i, a2[i], -1);
   7.299 +        } else if (i*SCALE < ARRLEN) {
   7.300 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2[i*SCALE], -103);
   7.301 +        }
   7.302 +      }
   7.303 +      test_2vi_scl(a1, a2, 123, 103);
   7.304 +      for (int i=0; i<ARRLEN; i++) {
   7.305 +        if (i%SCALE != 0) {
   7.306 +          errn += verify("test_2vi_scl: a1", i, a1[i], -1);
   7.307 +        } else if (i*SCALE < ARRLEN) {
   7.308 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1[i*SCALE], 123);
   7.309 +        }
   7.310 +        if (i%SCALE != 0) {
   7.311 +          errn += verify("test_2vi_scl: a2", i, a2[i], -1);
   7.312 +        } else if (i*SCALE < ARRLEN) {
   7.313 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2[i*SCALE], 103);
   7.314 +        }
   7.315 +      }
   7.316 +      // Reset for 2 arrays with relative aligned offset
   7.317 +      for (int i=0; i<ARRLEN; i++) {
   7.318 +        a1[i] = -1;
   7.319 +        a2[i] = -1;
   7.320 +      }
   7.321 +      test_vi(a2, 123, -1);
   7.322 +      test_cp_alndst(a1, a2);
   7.323 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.324 +        errn += verify("test_cp_alndst: a1", i, a1[i], -1);
   7.325 +      }
   7.326 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   7.327 +        errn += verify("test_cp_alndst: a1", i, a1[i], 123);
   7.328 +      }
   7.329 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.330 +        a1[i] = 123;
   7.331 +      }
   7.332 +      test_vi(a2, -123, 123);
   7.333 +      test_cp_alnsrc(a1, a2);
   7.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   7.335 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], -123);
   7.336 +      }
   7.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   7.338 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], 123);
   7.339 +      }
   7.340 +      for (int i=0; i<ARRLEN; i++) {
   7.341 +        a1[i] = -1;
   7.342 +        a2[i] = -1;
   7.343 +      }
   7.344 +      test_2ci_aln(a1, a2);
   7.345 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.346 +        errn += verify("test_2ci_aln: a1", i, a1[i], -1);
   7.347 +      }
   7.348 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   7.349 +        errn += verify("test_2ci_aln: a1", i, a1[i], -123);
   7.350 +      }
   7.351 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   7.352 +        errn += verify("test_2ci_aln: a2", i, a2[i], -103);
   7.353 +      }
   7.354 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   7.355 +        errn += verify("test_2ci_aln: a2", i, a2[i], -1);
   7.356 +      }
   7.357 +      for (int i=0; i<ARRLEN; i++) {
   7.358 +        a1[i] = -1;
   7.359 +        a2[i] = -1;
   7.360 +      }
   7.361 +      test_2vi_aln(a1, a2, 123, 103);
   7.362 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   7.363 +        errn += verify("test_2vi_aln: a1", i, a1[i], 123);
   7.364 +      }
   7.365 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   7.366 +        errn += verify("test_2vi_aln: a1", i, a1[i], -1);
   7.367 +      }
   7.368 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.369 +        errn += verify("test_2vi_aln: a2", i, a2[i], -1);
   7.370 +      }
   7.371 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   7.372 +        errn += verify("test_2vi_aln: a2", i, a2[i], 103);
   7.373 +      }
   7.374 +
   7.375 +      // Reset for 2 arrays with relative unaligned offset
   7.376 +      for (int i=0; i<ARRLEN; i++) {
   7.377 +        a1[i] = -1;
   7.378 +        a2[i] = -1;
   7.379 +      }
   7.380 +      test_vi(a2, 123, -1);
   7.381 +      test_cp_unalndst(a1, a2);
   7.382 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.383 +        errn += verify("test_cp_unalndst: a1", i, a1[i], -1);
   7.384 +      }
   7.385 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   7.386 +        errn += verify("test_cp_unalndst: a1", i, a1[i], 123);
   7.387 +      }
   7.388 +      test_vi(a2, -123, 123);
   7.389 +      test_cp_unalnsrc(a1, a2);
   7.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   7.391 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], -123);
   7.392 +      }
   7.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   7.394 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], 123);
   7.395 +      }
   7.396 +      for (int i=0; i<ARRLEN; i++) {
   7.397 +        a1[i] = -1;
   7.398 +        a2[i] = -1;
   7.399 +      }
   7.400 +      test_2ci_unaln(a1, a2);
   7.401 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.402 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -1);
   7.403 +      }
   7.404 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   7.405 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -123);
   7.406 +      }
   7.407 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   7.408 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -103);
   7.409 +      }
   7.410 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   7.411 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -1);
   7.412 +      }
   7.413 +      for (int i=0; i<ARRLEN; i++) {
   7.414 +        a1[i] = -1;
   7.415 +        a2[i] = -1;
   7.416 +      }
   7.417 +      test_2vi_unaln(a1, a2, 123, 103);
   7.418 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   7.419 +        errn += verify("test_2vi_unaln: a1", i, a1[i], 123);
   7.420 +      }
   7.421 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   7.422 +        errn += verify("test_2vi_unaln: a1", i, a1[i], -1);
   7.423 +      }
   7.424 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.425 +        errn += verify("test_2vi_unaln: a2", i, a2[i], -1);
   7.426 +      }
   7.427 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   7.428 +        errn += verify("test_2vi_unaln: a2", i, a2[i], 103);
   7.429 +      }
   7.430 +
   7.431 +      // Reset for aligned overlap initialization
   7.432 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.433 +        a1[i] = i;
   7.434 +      }
   7.435 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   7.436 +        a1[i] = -1;
   7.437 +      }
   7.438 +      test_cp_alndst(a1, a1);
   7.439 +      for (int i=0; i<ARRLEN; i++) {
   7.440 +        int v = i%ALIGN_OFF;
   7.441 +        errn += verify("test_cp_alndst_overlap: a1", i, a1[i], v);
   7.442 +      }
   7.443 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.444 +        a1[i+ALIGN_OFF] = -1;
   7.445 +      }
   7.446 +      test_cp_alnsrc(a1, a1);
   7.447 +      for (int i=0; i<ALIGN_OFF; i++) {
   7.448 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], -1);
   7.449 +      }
   7.450 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   7.451 +        int v = i%ALIGN_OFF;
   7.452 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], v);
   7.453 +      }
   7.454 +      for (int i=0; i<ARRLEN; i++) {
   7.455 +        a1[i] = -1;
   7.456 +      }
   7.457 +      test_2ci_aln(a1, a1);
   7.458 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   7.459 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -103);
   7.460 +      }
   7.461 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   7.462 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -123);
   7.463 +      }
   7.464 +      for (int i=0; i<ARRLEN; i++) {
   7.465 +        a1[i] = -1;
   7.466 +      }
   7.467 +      test_2vi_aln(a1, a1, 123, 103);
   7.468 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   7.469 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 123);
   7.470 +      }
   7.471 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   7.472 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 103);
   7.473 +      }
   7.474 +
   7.475 +      // Reset for unaligned overlap initialization
   7.476 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.477 +        a1[i] = i;
   7.478 +      }
   7.479 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   7.480 +        a1[i] = -1;
   7.481 +      }
   7.482 +      test_cp_unalndst(a1, a1);
   7.483 +      for (int i=0; i<ARRLEN; i++) {
   7.484 +        int v = i%UNALIGN_OFF;
   7.485 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1[i], v);
   7.486 +      }
   7.487 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.488 +        a1[i+UNALIGN_OFF] = -1;
   7.489 +      }
   7.490 +      test_cp_unalnsrc(a1, a1);
   7.491 +      for (int i=0; i<UNALIGN_OFF; i++) {
   7.492 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], -1);
   7.493 +      }
   7.494 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   7.495 +        int v = i%UNALIGN_OFF;
   7.496 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], v);
   7.497 +      }
   7.498 +      for (int i=0; i<ARRLEN; i++) {
   7.499 +        a1[i] = -1;
   7.500 +      }
   7.501 +      test_2ci_unaln(a1, a1);
   7.502 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   7.503 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -103);
   7.504 +      }
   7.505 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   7.506 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -123);
   7.507 +      }
   7.508 +      for (int i=0; i<ARRLEN; i++) {
   7.509 +        a1[i] = -1;
   7.510 +      }
   7.511 +      test_2vi_unaln(a1, a1, 123, 103);
   7.512 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   7.513 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 123);
   7.514 +      }
   7.515 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   7.516 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 103);
   7.517 +      }
   7.518 +
   7.519 +    }
   7.520 +
   7.521 +    if (errn > 0 || test_only)
   7.522 +      return errn;
   7.523 +
   7.524 +    // Initialize
   7.525 +    for (int i=0; i<ARRLEN; i++) {
   7.526 +      a1[i] = -1;
   7.527 +      a2[i] = -1;
   7.528 +    }
   7.529 +    System.out.println("Time");
   7.530 +    long start, end;
   7.531 +    start = System.currentTimeMillis();
   7.532 +    for (int i=0; i<ITERS; i++) {
   7.533 +      test_ci(a1);
   7.534 +    }
   7.535 +    end = System.currentTimeMillis();
   7.536 +    System.out.println("test_ci: " + (end - start));
   7.537 +    start = System.currentTimeMillis();
   7.538 +    for (int i=0; i<ITERS; i++) {
   7.539 +      test_vi(a2, 123, -1);
   7.540 +    }
   7.541 +    end = System.currentTimeMillis();
   7.542 +    System.out.println("test_vi: " + (end - start));
   7.543 +    start = System.currentTimeMillis();
   7.544 +    for (int i=0; i<ITERS; i++) {
   7.545 +      test_cp(a1, a2);
   7.546 +    }
   7.547 +    end = System.currentTimeMillis();
   7.548 +    System.out.println("test_cp: " + (end - start));
   7.549 +    start = System.currentTimeMillis();
   7.550 +    for (int i=0; i<ITERS; i++) {
   7.551 +      test_2ci(a1, a2);
   7.552 +    }
   7.553 +    end = System.currentTimeMillis();
   7.554 +    System.out.println("test_2ci: " + (end - start));
   7.555 +    start = System.currentTimeMillis();
   7.556 +    for (int i=0; i<ITERS; i++) {
   7.557 +      test_2vi(a1, a2, 123, 103);
   7.558 +    }
   7.559 +    end = System.currentTimeMillis();
   7.560 +    System.out.println("test_2vi: " + (end - start));
   7.561 +
   7.562 +    start = System.currentTimeMillis();
   7.563 +    for (int i=0; i<ITERS; i++) {
   7.564 +      test_ci_neg(a1, 123);
   7.565 +    }
   7.566 +    end = System.currentTimeMillis();
   7.567 +    System.out.println("test_ci_neg: " + (end - start));
   7.568 +    start = System.currentTimeMillis();
   7.569 +    for (int i=0; i<ITERS; i++) {
   7.570 +      test_vi_neg(a2, 123, 103);
   7.571 +    }
   7.572 +    end = System.currentTimeMillis();
   7.573 +    System.out.println("test_vi_neg: " + (end - start));
   7.574 +    start = System.currentTimeMillis();
   7.575 +    for (int i=0; i<ITERS; i++) {
   7.576 +      test_cp_neg(a1, a2);
   7.577 +    }
   7.578 +    end = System.currentTimeMillis();
   7.579 +    System.out.println("test_cp_neg: " + (end - start));
   7.580 +    start = System.currentTimeMillis();
   7.581 +    for (int i=0; i<ITERS; i++) {
   7.582 +      test_2ci_neg(a1, a2);
   7.583 +    }
   7.584 +    end = System.currentTimeMillis();
   7.585 +    System.out.println("test_2ci_neg: " + (end - start));
   7.586 +    start = System.currentTimeMillis();
   7.587 +    for (int i=0; i<ITERS; i++) {
   7.588 +      test_2vi_neg(a1, a2, 123, 103);
   7.589 +    }
   7.590 +    end = System.currentTimeMillis();
   7.591 +    System.out.println("test_2vi_neg: " + (end - start));
   7.592 +
   7.593 +    start = System.currentTimeMillis();
   7.594 +    for (int i=0; i<ITERS; i++) {
   7.595 +      test_ci_oppos(a1, 123);
   7.596 +    }
   7.597 +    end = System.currentTimeMillis();
   7.598 +    System.out.println("test_ci_oppos: " + (end - start));
   7.599 +    start = System.currentTimeMillis();
   7.600 +    for (int i=0; i<ITERS; i++) {
   7.601 +      test_vi_oppos(a2, 123, 103);
   7.602 +    }
   7.603 +    end = System.currentTimeMillis();
   7.604 +    System.out.println("test_vi_oppos: " + (end - start));
   7.605 +    start = System.currentTimeMillis();
   7.606 +    for (int i=0; i<ITERS; i++) {
   7.607 +      test_cp_oppos(a1, a2);
   7.608 +    }
   7.609 +    end = System.currentTimeMillis();
   7.610 +    System.out.println("test_cp_oppos: " + (end - start));
   7.611 +    start = System.currentTimeMillis();
   7.612 +    for (int i=0; i<ITERS; i++) {
   7.613 +      test_2ci_oppos(a1, a2);
   7.614 +    }
   7.615 +    end = System.currentTimeMillis();
   7.616 +    System.out.println("test_2ci_oppos: " + (end - start));
   7.617 +    start = System.currentTimeMillis();
   7.618 +    for (int i=0; i<ITERS; i++) {
   7.619 +      test_2vi_oppos(a1, a2, 123, 103);
   7.620 +    }
   7.621 +    end = System.currentTimeMillis();
   7.622 +    System.out.println("test_2vi_oppos: " + (end - start));
   7.623 +
   7.624 +    start = System.currentTimeMillis();
   7.625 +    for (int i=0; i<ITERS; i++) {
   7.626 +      test_ci_off(a1, 123);
   7.627 +    }
   7.628 +    end = System.currentTimeMillis();
   7.629 +    System.out.println("test_ci_off: " + (end - start));
   7.630 +    start = System.currentTimeMillis();
   7.631 +    for (int i=0; i<ITERS; i++) {
   7.632 +      test_vi_off(a2, 123, 103);
   7.633 +    }
   7.634 +    end = System.currentTimeMillis();
   7.635 +    System.out.println("test_vi_off: " + (end - start));
   7.636 +    start = System.currentTimeMillis();
   7.637 +    for (int i=0; i<ITERS; i++) {
   7.638 +      test_cp_off(a1, a2);
   7.639 +    }
   7.640 +    end = System.currentTimeMillis();
   7.641 +    System.out.println("test_cp_off: " + (end - start));
   7.642 +    start = System.currentTimeMillis();
   7.643 +    for (int i=0; i<ITERS; i++) {
   7.644 +      test_2ci_off(a1, a2);
   7.645 +    }
   7.646 +    end = System.currentTimeMillis();
   7.647 +    System.out.println("test_2ci_off: " + (end - start));
   7.648 +    start = System.currentTimeMillis();
   7.649 +    for (int i=0; i<ITERS; i++) {
   7.650 +      test_2vi_off(a1, a2, 123, 103);
   7.651 +    }
   7.652 +    end = System.currentTimeMillis();
   7.653 +    System.out.println("test_2vi_off: " + (end - start));
   7.654 +
   7.655 +    start = System.currentTimeMillis();
   7.656 +    for (int i=0; i<ITERS; i++) {
   7.657 +      test_ci_inv(a1, OFFSET, 123);
   7.658 +    }
   7.659 +    end = System.currentTimeMillis();
   7.660 +    System.out.println("test_ci_inv: " + (end - start));
   7.661 +    start = System.currentTimeMillis();
   7.662 +    for (int i=0; i<ITERS; i++) {
   7.663 +      test_vi_inv(a2, 123, OFFSET, 103);
   7.664 +    }
   7.665 +    end = System.currentTimeMillis();
   7.666 +    System.out.println("test_vi_inv: " + (end - start));
   7.667 +    start = System.currentTimeMillis();
   7.668 +    for (int i=0; i<ITERS; i++) {
   7.669 +      test_cp_inv(a1, a2, OFFSET);
   7.670 +    }
   7.671 +    end = System.currentTimeMillis();
   7.672 +    System.out.println("test_cp_inv: " + (end - start));
   7.673 +    start = System.currentTimeMillis();
   7.674 +    for (int i=0; i<ITERS; i++) {
   7.675 +      test_2ci_inv(a1, a2, OFFSET);
   7.676 +    }
   7.677 +    end = System.currentTimeMillis();
   7.678 +    System.out.println("test_2ci_inv: " + (end - start));
   7.679 +    start = System.currentTimeMillis();
   7.680 +    for (int i=0; i<ITERS; i++) {
   7.681 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   7.682 +    }
   7.683 +    end = System.currentTimeMillis();
   7.684 +    System.out.println("test_2vi_inv: " + (end - start));
   7.685 +
   7.686 +    start = System.currentTimeMillis();
   7.687 +    for (int i=0; i<ITERS; i++) {
   7.688 +      test_ci_scl(a1, 123);
   7.689 +    }
   7.690 +    end = System.currentTimeMillis();
   7.691 +    System.out.println("test_ci_scl: " + (end - start));
   7.692 +    start = System.currentTimeMillis();
   7.693 +    for (int i=0; i<ITERS; i++) {
   7.694 +      test_vi_scl(a2, 123, 103);
   7.695 +    }
   7.696 +    end = System.currentTimeMillis();
   7.697 +    System.out.println("test_vi_scl: " + (end - start));
   7.698 +    start = System.currentTimeMillis();
   7.699 +    for (int i=0; i<ITERS; i++) {
   7.700 +      test_cp_scl(a1, a2);
   7.701 +    }
   7.702 +    end = System.currentTimeMillis();
   7.703 +    System.out.println("test_cp_scl: " + (end - start));
   7.704 +    start = System.currentTimeMillis();
   7.705 +    for (int i=0; i<ITERS; i++) {
   7.706 +      test_2ci_scl(a1, a2);
   7.707 +    }
   7.708 +    end = System.currentTimeMillis();
   7.709 +    System.out.println("test_2ci_scl: " + (end - start));
   7.710 +    start = System.currentTimeMillis();
   7.711 +    for (int i=0; i<ITERS; i++) {
   7.712 +      test_2vi_scl(a1, a2, 123, 103);
   7.713 +    }
   7.714 +    end = System.currentTimeMillis();
   7.715 +    System.out.println("test_2vi_scl: " + (end - start));
   7.716 +
   7.717 +    start = System.currentTimeMillis();
   7.718 +    for (int i=0; i<ITERS; i++) {
   7.719 +      test_cp_alndst(a1, a2);
   7.720 +    }
   7.721 +    end = System.currentTimeMillis();
   7.722 +    System.out.println("test_cp_alndst: " + (end - start));
   7.723 +    start = System.currentTimeMillis();
   7.724 +    for (int i=0; i<ITERS; i++) {
   7.725 +      test_cp_alnsrc(a1, a2);
   7.726 +    }
   7.727 +    end = System.currentTimeMillis();
   7.728 +    System.out.println("test_cp_alnsrc: " + (end - start));
   7.729 +    start = System.currentTimeMillis();
   7.730 +    for (int i=0; i<ITERS; i++) {
   7.731 +      test_2ci_aln(a1, a2);
   7.732 +    }
   7.733 +    end = System.currentTimeMillis();
   7.734 +    System.out.println("test_2ci_aln: " + (end - start));
   7.735 +    start = System.currentTimeMillis();
   7.736 +    for (int i=0; i<ITERS; i++) {
   7.737 +      test_2vi_aln(a1, a2, 123, 103);
   7.738 +    }
   7.739 +    end = System.currentTimeMillis();
   7.740 +    System.out.println("test_2vi_aln: " + (end - start));
   7.741 +
   7.742 +    start = System.currentTimeMillis();
   7.743 +    for (int i=0; i<ITERS; i++) {
   7.744 +      test_cp_unalndst(a1, a2);
   7.745 +    }
   7.746 +    end = System.currentTimeMillis();
   7.747 +    System.out.println("test_cp_unalndst: " + (end - start));
   7.748 +    start = System.currentTimeMillis();
   7.749 +    for (int i=0; i<ITERS; i++) {
   7.750 +      test_cp_unalnsrc(a1, a2);
   7.751 +    }
   7.752 +    end = System.currentTimeMillis();
   7.753 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   7.754 +    start = System.currentTimeMillis();
   7.755 +    for (int i=0; i<ITERS; i++) {
   7.756 +      test_2ci_unaln(a1, a2);
   7.757 +    }
   7.758 +    end = System.currentTimeMillis();
   7.759 +    System.out.println("test_2ci_unaln: " + (end - start));
   7.760 +    start = System.currentTimeMillis();
   7.761 +    for (int i=0; i<ITERS; i++) {
   7.762 +      test_2vi_unaln(a1, a2, 123, 103);
   7.763 +    }
   7.764 +    end = System.currentTimeMillis();
   7.765 +    System.out.println("test_2vi_unaln: " + (end - start));
   7.766 +
   7.767 +    return errn;
   7.768 +  }
   7.769 +
   7.770 +  private final static long byte_offset(int i) {
   7.771 +    return ((long)i << 2) + BASE;
   7.772 +  }
   7.773 +
   7.774 +  static void test_ci(int[] a) {
   7.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.776 +      unsafe.putOrderedInt(a, byte_offset(i), -123);
   7.777 +    }
   7.778 +  }
   7.779 +  static void test_vi(int[] a, int b, int old) {
   7.780 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.781 +      unsafe.putOrderedInt(a, byte_offset(i), b);
   7.782 +    }
   7.783 +  }
   7.784 +  static void test_cp(int[] a, int[] b) {
   7.785 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.786 +      unsafe.putOrderedInt(a, byte_offset(i), b[i]);
   7.787 +    }
   7.788 +  }
   7.789 +  static void test_2ci(int[] a, int[] b) {
   7.790 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.791 +      unsafe.putOrderedInt(a, byte_offset(i), -123);
   7.792 +      unsafe.putOrderedInt(b, byte_offset(i), -103);
   7.793 +    }
   7.794 +  }
   7.795 +  static void test_2vi(int[] a, int[] b, int c, int d) {
   7.796 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.797 +      unsafe.putOrderedInt(a, byte_offset(i), c);
   7.798 +      unsafe.putOrderedInt(b, byte_offset(i), d);
   7.799 +    }
   7.800 +  }
   7.801 +  static void test_ci_neg(int[] a, int old) {
   7.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   7.803 +      unsafe.putOrderedInt(a, byte_offset(i), -123);
   7.804 +    }
   7.805 +  }
   7.806 +  static void test_vi_neg(int[] a, int b, int old) {
   7.807 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   7.808 +      unsafe.putOrderedInt(a, byte_offset(i), b);
   7.809 +    }
   7.810 +  }
   7.811 +  static void test_cp_neg(int[] a, int[] b) {
   7.812 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   7.813 +      unsafe.putOrderedInt(a, byte_offset(i), b[i]);
   7.814 +    }
   7.815 +  }
   7.816 +  static void test_2ci_neg(int[] a, int[] b) {
   7.817 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   7.818 +      unsafe.putOrderedInt(a, byte_offset(i), -123);
   7.819 +      unsafe.putOrderedInt(b, byte_offset(i), -103);
   7.820 +    }
   7.821 +  }
   7.822 +  static void test_2vi_neg(int[] a, int[] b, int c, int d) {
   7.823 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   7.824 +      unsafe.putOrderedInt(a, byte_offset(i), c);
   7.825 +      unsafe.putOrderedInt(b, byte_offset(i), d);
   7.826 +    }
   7.827 +  }
   7.828 +  static void test_ci_oppos(int[] a, int old) {
   7.829 +    int limit = ARRLEN-1;
   7.830 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.831 +      unsafe.putOrderedInt(a, byte_offset(limit-i), -123);
   7.832 +    }
   7.833 +  }
   7.834 +  static void test_vi_oppos(int[] a, int b, int old) {
   7.835 +    int limit = ARRLEN-1;
   7.836 +    for (int i = limit; i >= 0; i-=1) {
   7.837 +      unsafe.putOrderedInt(a, byte_offset(limit-i), b);
   7.838 +    }
   7.839 +  }
   7.840 +  static void test_cp_oppos(int[] a, int[] b) {
   7.841 +    int limit = ARRLEN-1;
   7.842 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.843 +      unsafe.putOrderedInt(a, byte_offset(i), b[limit-i]);
   7.844 +    }
   7.845 +  }
   7.846 +  static void test_2ci_oppos(int[] a, int[] b) {
   7.847 +    int limit = ARRLEN-1;
   7.848 +    for (int i = 0; i < ARRLEN; i+=1) {
   7.849 +      unsafe.putOrderedInt(a, byte_offset(limit-i), -123);
   7.850 +      unsafe.putOrderedInt(b, byte_offset(i), -103);
   7.851 +    }
   7.852 +  }
   7.853 +  static void test_2vi_oppos(int[] a, int[] b, int c, int d) {
   7.854 +    int limit = ARRLEN-1;
   7.855 +    for (int i = limit; i >= 0; i-=1) {
   7.856 +      unsafe.putOrderedInt(a, byte_offset(i), c);
   7.857 +      unsafe.putOrderedInt(b, byte_offset(limit-i), d);
   7.858 +    }
   7.859 +  }
   7.860 +  static void test_ci_off(int[] a, int old) {
   7.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   7.862 +      unsafe.putOrderedInt(a, byte_offset(i+OFFSET), -123);
   7.863 +    }
   7.864 +  }
   7.865 +  static void test_vi_off(int[] a, int b, int old) {
   7.866 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   7.867 +      unsafe.putOrderedInt(a, byte_offset(i+OFFSET), b);
   7.868 +    }
   7.869 +  }
   7.870 +  static void test_cp_off(int[] a, int[] b) {
   7.871 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   7.872 +      unsafe.putOrderedInt(a, byte_offset(i+OFFSET), b[i+OFFSET]);
   7.873 +    }
   7.874 +  }
   7.875 +  static void test_2ci_off(int[] a, int[] b) {
   7.876 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   7.877 +      unsafe.putOrderedInt(a, byte_offset(i+OFFSET), -123);
   7.878 +      unsafe.putOrderedInt(b, byte_offset(i+OFFSET), -103);
   7.879 +    }
   7.880 +  }
   7.881 +  static void test_2vi_off(int[] a, int[] b, int c, int d) {
   7.882 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   7.883 +      unsafe.putOrderedInt(a, byte_offset(i+OFFSET), c);
   7.884 +      unsafe.putOrderedInt(b, byte_offset(i+OFFSET), d);
   7.885 +    }
   7.886 +  }
   7.887 +  static void test_ci_inv(int[] a, int k, int old) {
   7.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   7.889 +      unsafe.putOrderedInt(a, byte_offset(i+k), -123);
   7.890 +    }
   7.891 +  }
   7.892 +  static void test_vi_inv(int[] a, int b, int k, int old) {
   7.893 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   7.894 +      unsafe.putOrderedInt(a, byte_offset(i+k), b);
   7.895 +    }
   7.896 +  }
   7.897 +  static void test_cp_inv(int[] a, int[] b, int k) {
   7.898 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   7.899 +      unsafe.putOrderedInt(a, byte_offset(i+k), b[i+k]);
   7.900 +    }
   7.901 +  }
   7.902 +  static void test_2ci_inv(int[] a, int[] b, int k) {
   7.903 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   7.904 +      unsafe.putOrderedInt(a, byte_offset(i+k), -123);
   7.905 +      unsafe.putOrderedInt(b, byte_offset(i+k), -103);
   7.906 +    }
   7.907 +  }
   7.908 +  static void test_2vi_inv(int[] a, int[] b, int c, int d, int k) {
   7.909 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   7.910 +      unsafe.putOrderedInt(a, byte_offset(i+k), c);
   7.911 +      unsafe.putOrderedInt(b, byte_offset(i+k), d);
   7.912 +    }
   7.913 +  }
   7.914 +  static void test_ci_scl(int[] a, int old) {
   7.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   7.916 +      unsafe.putOrderedInt(a, byte_offset(i*SCALE), -123);
   7.917 +    }
   7.918 +  }
   7.919 +  static void test_vi_scl(int[] a, int b, int old) {
   7.920 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   7.921 +      unsafe.putOrderedInt(a, byte_offset(i*SCALE), b);
   7.922 +    }
   7.923 +  }
   7.924 +  static void test_cp_scl(int[] a, int[] b) {
   7.925 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   7.926 +      unsafe.putOrderedInt(a, byte_offset(i*SCALE), b[i*SCALE]);
   7.927 +    }
   7.928 +  }
   7.929 +  static void test_2ci_scl(int[] a, int[] b) {
   7.930 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   7.931 +      unsafe.putOrderedInt(a, byte_offset(i*SCALE), -123);
   7.932 +      unsafe.putOrderedInt(b, byte_offset(i*SCALE), -103);
   7.933 +    }
   7.934 +  }
   7.935 +  static void test_2vi_scl(int[] a, int[] b, int c, int d) {
   7.936 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   7.937 +      unsafe.putOrderedInt(a, byte_offset(i*SCALE), c);
   7.938 +      unsafe.putOrderedInt(b, byte_offset(i*SCALE), d);
   7.939 +    }
   7.940 +  }
   7.941 +  static void test_cp_alndst(int[] a, int[] b) {
   7.942 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   7.943 +      unsafe.putOrderedInt(a, byte_offset(i+ALIGN_OFF), b[i]);
   7.944 +    }
   7.945 +  }
   7.946 +  static void test_cp_alnsrc(int[] a, int[] b) {
   7.947 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   7.948 +      unsafe.putOrderedInt(a, byte_offset(i), b[i+ALIGN_OFF]);
   7.949 +    }
   7.950 +  }
   7.951 +  static void test_2ci_aln(int[] a, int[] b) {
   7.952 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   7.953 +      unsafe.putOrderedInt(a, byte_offset(i+ALIGN_OFF), -123);
   7.954 +      unsafe.putOrderedInt(b, byte_offset(i), -103);
   7.955 +    }
   7.956 +  }
   7.957 +  static void test_2vi_aln(int[] a, int[] b, int c, int d) {
   7.958 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   7.959 +      unsafe.putOrderedInt(a, byte_offset(i), c);
   7.960 +      unsafe.putOrderedInt(b, byte_offset(i+ALIGN_OFF), d);
   7.961 +    }
   7.962 +  }
   7.963 +  static void test_cp_unalndst(int[] a, int[] b) {
   7.964 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   7.965 +      unsafe.putOrderedInt(a, byte_offset(i+UNALIGN_OFF), b[i]);
   7.966 +    }
   7.967 +  }
   7.968 +  static void test_cp_unalnsrc(int[] a, int[] b) {
   7.969 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   7.970 +      unsafe.putOrderedInt(a, byte_offset(i), b[i+UNALIGN_OFF]);
   7.971 +    }
   7.972 +  }
   7.973 +  static void test_2ci_unaln(int[] a, int[] b) {
   7.974 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   7.975 +      unsafe.putOrderedInt(a, byte_offset(i+UNALIGN_OFF), -123);
   7.976 +      unsafe.putOrderedInt(b, byte_offset(i), -103);
   7.977 +    }
   7.978 +  }
   7.979 +  static void test_2vi_unaln(int[] a, int[] b, int c, int d) {
   7.980 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   7.981 +      unsafe.putOrderedInt(a, byte_offset(i), c);
   7.982 +      unsafe.putOrderedInt(b, byte_offset(i+UNALIGN_OFF), d);
   7.983 +    }
   7.984 +  }
   7.985 +
   7.986 +  static int verify(String text, int i, int elem, int val) {
   7.987 +    if (elem != val) {
   7.988 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   7.989 +      return 1;
   7.990 +    }
   7.991 +    return 0;
   7.992 +  }
   7.993 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/compiler/8004867/TestIntUnsafeVolatile.java	Mon Feb 18 16:47:15 2013 -0800
     8.3 @@ -0,0 +1,990 @@
     8.4 +/*
     8.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + *
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + *
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + *
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + *
    8.26 + */
    8.27 +
    8.28 +/**
    8.29 + * @test
    8.30 + * @bug 8004867
    8.31 + * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob"
    8.32 + *
    8.33 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-OptimizeFill TestIntUnsafeVolatile
    8.34 + * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:+OptimizeFill TestIntUnsafeVolatile
    8.35 + */
    8.36 +
    8.37 +import sun.misc.Unsafe;
    8.38 +import java.lang.reflect.*;
    8.39 +
    8.40 +public class TestIntUnsafeVolatile {
    8.41 +  private static final int ARRLEN = 97;
    8.42 +  private static final int ITERS  = 11000;
    8.43 +  private static final int OFFSET = 3;
    8.44 +  private static final int SCALE = 2;
    8.45 +  private static final int ALIGN_OFF = 8;
    8.46 +  private static final int UNALIGN_OFF = 5;
    8.47 +
    8.48 +  private static final Unsafe unsafe;
    8.49 +  private static final int BASE;
    8.50 +  static {
    8.51 +    try {
    8.52 +      Class c = TestIntUnsafeVolatile.class.getClassLoader().loadClass("sun.misc.Unsafe");
    8.53 +      Field f = c.getDeclaredField("theUnsafe");
    8.54 +      f.setAccessible(true);
    8.55 +      unsafe = (Unsafe)f.get(c);
    8.56 +      BASE = unsafe.arrayBaseOffset(int[].class);
    8.57 +    } catch (Exception e) {
    8.58 +      InternalError err = new InternalError();
    8.59 +      err.initCause(e);
    8.60 +      throw err;
    8.61 +    }
    8.62 +  }
    8.63 +
    8.64 +  public static void main(String args[]) {
    8.65 +    System.out.println("Testing Integer array unsafe volatile operations");
    8.66 +    int errn = test(false);
    8.67 +    if (errn > 0) {
    8.68 +      System.err.println("FAILED: " + errn + " errors");
    8.69 +      System.exit(97);
    8.70 +    }
    8.71 +    System.out.println("PASSED");
    8.72 +  }
    8.73 +
    8.74 +  static int test(boolean test_only) {
    8.75 +    int[] a1 = new int[ARRLEN];
    8.76 +    int[] a2 = new int[ARRLEN];
    8.77 +    // Initialize
    8.78 +    for (int i=0; i<ARRLEN; i++) {
    8.79 +      a1[i] = -1;
    8.80 +      a2[i] = -1;
    8.81 +    }
    8.82 +    System.out.println("Warmup");
    8.83 +    for (int i=0; i<ITERS; i++) {
    8.84 +      test_ci(a1);
    8.85 +      test_vi(a2, 123, -1);
    8.86 +      test_cp(a1, a2);
    8.87 +      test_2ci(a1, a2);
    8.88 +      test_2vi(a1, a2, 123, 103);
    8.89 +      test_ci_neg(a1, 123);
    8.90 +      test_vi_neg(a2, 123, 103);
    8.91 +      test_cp_neg(a1, a2);
    8.92 +      test_2ci_neg(a1, a2);
    8.93 +      test_2vi_neg(a1, a2, 123, 103);
    8.94 +      test_ci_oppos(a1, 123);
    8.95 +      test_vi_oppos(a2, 123, 103);
    8.96 +      test_cp_oppos(a1, a2);
    8.97 +      test_2ci_oppos(a1, a2);
    8.98 +      test_2vi_oppos(a1, a2, 123, 103);
    8.99 +      test_ci_off(a1, 123);
   8.100 +      test_vi_off(a2, 123, 103);
   8.101 +      test_cp_off(a1, a2);
   8.102 +      test_2ci_off(a1, a2);
   8.103 +      test_2vi_off(a1, a2, 123, 103);
   8.104 +      test_ci_inv(a1, OFFSET, 123);
   8.105 +      test_vi_inv(a2, 123, OFFSET, 103);
   8.106 +      test_cp_inv(a1, a2, OFFSET);
   8.107 +      test_2ci_inv(a1, a2, OFFSET);
   8.108 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   8.109 +      test_ci_scl(a1, 123);
   8.110 +      test_vi_scl(a2, 123, 103);
   8.111 +      test_cp_scl(a1, a2);
   8.112 +      test_2ci_scl(a1, a2);
   8.113 +      test_2vi_scl(a1, a2, 123, 103);
   8.114 +      test_cp_alndst(a1, a2);
   8.115 +      test_cp_alnsrc(a1, a2);
   8.116 +      test_2ci_aln(a1, a2);
   8.117 +      test_2vi_aln(a1, a2, 123, 103);
   8.118 +      test_cp_unalndst(a1, a2);
   8.119 +      test_cp_unalnsrc(a1, a2);
   8.120 +      test_2ci_unaln(a1, a2);
   8.121 +      test_2vi_unaln(a1, a2, 123, 103);
   8.122 +    }
   8.123 +    // Initialize
   8.124 +    for (int i=0; i<ARRLEN; i++) {
   8.125 +      a1[i] = -1;
   8.126 +      a2[i] = -1;
   8.127 +    }
   8.128 +    // Test and verify results
   8.129 +    System.out.println("Verification");
   8.130 +    int errn = 0;
   8.131 +    {
   8.132 +      test_ci(a1);
   8.133 +      for (int i=0; i<ARRLEN; i++) {
   8.134 +        errn += verify("test_ci: a1", i, a1[i], -123);
   8.135 +      }
   8.136 +      test_vi(a2, 123, -1);
   8.137 +      for (int i=0; i<ARRLEN; i++) {
   8.138 +        errn += verify("test_vi: a2", i, a2[i], 123);
   8.139 +      }
   8.140 +      test_cp(a1, a2);
   8.141 +      for (int i=0; i<ARRLEN; i++) {
   8.142 +        errn += verify("test_cp: a1", i, a1[i], 123);
   8.143 +      }
   8.144 +      test_2ci(a1, a2);
   8.145 +      for (int i=0; i<ARRLEN; i++) {
   8.146 +        errn += verify("test_2ci: a1", i, a1[i], -123);
   8.147 +        errn += verify("test_2ci: a2", i, a2[i], -103);
   8.148 +      }
   8.149 +      test_2vi(a1, a2, 123, 103);
   8.150 +      for (int i=0; i<ARRLEN; i++) {
   8.151 +        errn += verify("test_2vi: a1", i, a1[i], 123);
   8.152 +        errn += verify("test_2vi: a2", i, a2[i], 103);
   8.153 +      }
   8.154 +      // Reset for negative stride
   8.155 +      for (int i=0; i<ARRLEN; i++) {
   8.156 +        a1[i] = -1;
   8.157 +        a2[i] = -1;
   8.158 +      }
   8.159 +      test_ci_neg(a1, -1);
   8.160 +      for (int i=0; i<ARRLEN; i++) {
   8.161 +        errn += verify("test_ci_neg: a1", i, a1[i], -123);
   8.162 +      }
   8.163 +      test_vi_neg(a2, 123, -1);
   8.164 +      for (int i=0; i<ARRLEN; i++) {
   8.165 +        errn += verify("test_vi_neg: a2", i, a2[i], 123);
   8.166 +      }
   8.167 +      test_cp_neg(a1, a2);
   8.168 +      for (int i=0; i<ARRLEN; i++) {
   8.169 +        errn += verify("test_cp_neg: a1", i, a1[i], 123);
   8.170 +      }
   8.171 +      test_2ci_neg(a1, a2);
   8.172 +      for (int i=0; i<ARRLEN; i++) {
   8.173 +        errn += verify("test_2ci_neg: a1", i, a1[i], -123);
   8.174 +        errn += verify("test_2ci_neg: a2", i, a2[i], -103);
   8.175 +      }
   8.176 +      test_2vi_neg(a1, a2, 123, 103);
   8.177 +      for (int i=0; i<ARRLEN; i++) {
   8.178 +        errn += verify("test_2vi_neg: a1", i, a1[i], 123);
   8.179 +        errn += verify("test_2vi_neg: a2", i, a2[i], 103);
   8.180 +      }
   8.181 +      // Reset for opposite stride
   8.182 +      for (int i=0; i<ARRLEN; i++) {
   8.183 +        a1[i] = -1;
   8.184 +        a2[i] = -1;
   8.185 +      }
   8.186 +      test_ci_oppos(a1, -1);
   8.187 +      for (int i=0; i<ARRLEN; i++) {
   8.188 +        errn += verify("test_ci_oppos: a1", i, a1[i], -123);
   8.189 +      }
   8.190 +      test_vi_oppos(a2, 123, -1);
   8.191 +      for (int i=0; i<ARRLEN; i++) {
   8.192 +        errn += verify("test_vi_oppos: a2", i, a2[i], 123);
   8.193 +      }
   8.194 +      test_cp_oppos(a1, a2);
   8.195 +      for (int i=0; i<ARRLEN; i++) {
   8.196 +        errn += verify("test_cp_oppos: a1", i, a1[i], 123);
   8.197 +      }
   8.198 +      test_2ci_oppos(a1, a2);
   8.199 +      for (int i=0; i<ARRLEN; i++) {
   8.200 +        errn += verify("test_2ci_oppos: a1", i, a1[i], -123);
   8.201 +        errn += verify("test_2ci_oppos: a2", i, a2[i], -103);
   8.202 +      }
   8.203 +      test_2vi_oppos(a1, a2, 123, 103);
   8.204 +      for (int i=0; i<ARRLEN; i++) {
   8.205 +        errn += verify("test_2vi_oppos: a1", i, a1[i], 123);
   8.206 +        errn += verify("test_2vi_oppos: a2", i, a2[i], 103);
   8.207 +      }
   8.208 +      // Reset for indexing with offset
   8.209 +      for (int i=0; i<ARRLEN; i++) {
   8.210 +        a1[i] = -1;
   8.211 +        a2[i] = -1;
   8.212 +      }
   8.213 +      test_ci_off(a1, -1);
   8.214 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.215 +        errn += verify("test_ci_off: a1", i, a1[i], -123);
   8.216 +      }
   8.217 +      test_vi_off(a2, 123, -1);
   8.218 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.219 +        errn += verify("test_vi_off: a2", i, a2[i], 123);
   8.220 +      }
   8.221 +      test_cp_off(a1, a2);
   8.222 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.223 +        errn += verify("test_cp_off: a1", i, a1[i], 123);
   8.224 +      }
   8.225 +      test_2ci_off(a1, a2);
   8.226 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.227 +        errn += verify("test_2ci_off: a1", i, a1[i], -123);
   8.228 +        errn += verify("test_2ci_off: a2", i, a2[i], -103);
   8.229 +      }
   8.230 +      test_2vi_off(a1, a2, 123, 103);
   8.231 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.232 +        errn += verify("test_2vi_off: a1", i, a1[i], 123);
   8.233 +        errn += verify("test_2vi_off: a2", i, a2[i], 103);
   8.234 +      }
   8.235 +      for (int i=0; i<OFFSET; i++) {
   8.236 +        errn += verify("test_2vi_off: a1", i, a1[i], -1);
   8.237 +        errn += verify("test_2vi_off: a2", i, a2[i], -1);
   8.238 +      }
   8.239 +      // Reset for indexing with invariant offset
   8.240 +      for (int i=0; i<ARRLEN; i++) {
   8.241 +        a1[i] = -1;
   8.242 +        a2[i] = -1;
   8.243 +      }
   8.244 +      test_ci_inv(a1, OFFSET, -1);
   8.245 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.246 +        errn += verify("test_ci_inv: a1", i, a1[i], -123);
   8.247 +      }
   8.248 +      test_vi_inv(a2, 123, OFFSET, -1);
   8.249 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.250 +        errn += verify("test_vi_inv: a2", i, a2[i], 123);
   8.251 +      }
   8.252 +      test_cp_inv(a1, a2, OFFSET);
   8.253 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.254 +        errn += verify("test_cp_inv: a1", i, a1[i], 123);
   8.255 +      }
   8.256 +      test_2ci_inv(a1, a2, OFFSET);
   8.257 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.258 +        errn += verify("test_2ci_inv: a1", i, a1[i], -123);
   8.259 +        errn += verify("test_2ci_inv: a2", i, a2[i], -103);
   8.260 +      }
   8.261 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   8.262 +      for (int i=OFFSET; i<ARRLEN; i++) {
   8.263 +        errn += verify("test_2vi_inv: a1", i, a1[i], 123);
   8.264 +        errn += verify("test_2vi_inv: a2", i, a2[i], 103);
   8.265 +      }
   8.266 +      for (int i=0; i<OFFSET; i++) {
   8.267 +        errn += verify("test_2vi_inv: a1", i, a1[i], -1);
   8.268 +        errn += verify("test_2vi_inv: a2", i, a2[i], -1);
   8.269 +      }
   8.270 +      // Reset for indexing with scale
   8.271 +      for (int i=0; i<ARRLEN; i++) {
   8.272 +        a1[i] = -1;
   8.273 +        a2[i] = -1;
   8.274 +      }
   8.275 +      test_ci_scl(a1, -1);
   8.276 +      for (int i=0; i<ARRLEN; i++) {
   8.277 +        int val = (i%SCALE != 0) ? -1 : -123;
   8.278 +        errn += verify("test_ci_scl: a1", i, a1[i], val);
   8.279 +      }
   8.280 +      test_vi_scl(a2, 123, -1);
   8.281 +      for (int i=0; i<ARRLEN; i++) {
   8.282 +        int val = (i%SCALE != 0) ? -1 : 123;
   8.283 +        errn += verify("test_vi_scl: a2", i, a2[i], val);
   8.284 +      }
   8.285 +      test_cp_scl(a1, a2);
   8.286 +      for (int i=0; i<ARRLEN; i++) {
   8.287 +        int val = (i%SCALE != 0) ? -1 : 123;
   8.288 +        errn += verify("test_cp_scl: a1", i, a1[i], val);
   8.289 +      }
   8.290 +      test_2ci_scl(a1, a2);
   8.291 +      for (int i=0; i<ARRLEN; i++) {
   8.292 +        if (i%SCALE != 0) {
   8.293 +          errn += verify("test_2ci_scl: a1", i, a1[i], -1);
   8.294 +        } else if (i*SCALE < ARRLEN) {
   8.295 +          errn += verify("test_2ci_scl: a1", i*SCALE, a1[i*SCALE], -123);
   8.296 +        }
   8.297 +        if (i%SCALE != 0) {
   8.298 +          errn += verify("test_2ci_scl: a2", i, a2[i], -1);
   8.299 +        } else if (i*SCALE < ARRLEN) {
   8.300 +          errn += verify("test_2ci_scl: a2", i*SCALE, a2[i*SCALE], -103);
   8.301 +        }
   8.302 +      }
   8.303 +      test_2vi_scl(a1, a2, 123, 103);
   8.304 +      for (int i=0; i<ARRLEN; i++) {
   8.305 +        if (i%SCALE != 0) {
   8.306 +          errn += verify("test_2vi_scl: a1", i, a1[i], -1);
   8.307 +        } else if (i*SCALE < ARRLEN) {
   8.308 +          errn += verify("test_2vi_scl: a1", i*SCALE, a1[i*SCALE], 123);
   8.309 +        }
   8.310 +        if (i%SCALE != 0) {
   8.311 +          errn += verify("test_2vi_scl: a2", i, a2[i], -1);
   8.312 +        } else if (i*SCALE < ARRLEN) {
   8.313 +          errn += verify("test_2vi_scl: a2", i*SCALE, a2[i*SCALE], 103);
   8.314 +        }
   8.315 +      }
   8.316 +      // Reset for 2 arrays with relative aligned offset
   8.317 +      for (int i=0; i<ARRLEN; i++) {
   8.318 +        a1[i] = -1;
   8.319 +        a2[i] = -1;
   8.320 +      }
   8.321 +      test_vi(a2, 123, -1);
   8.322 +      test_cp_alndst(a1, a2);
   8.323 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.324 +        errn += verify("test_cp_alndst: a1", i, a1[i], -1);
   8.325 +      }
   8.326 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   8.327 +        errn += verify("test_cp_alndst: a1", i, a1[i], 123);
   8.328 +      }
   8.329 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.330 +        a1[i] = 123;
   8.331 +      }
   8.332 +      test_vi(a2, -123, 123);
   8.333 +      test_cp_alnsrc(a1, a2);
   8.334 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   8.335 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], -123);
   8.336 +      }
   8.337 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   8.338 +        errn += verify("test_cp_alnsrc: a1", i, a1[i], 123);
   8.339 +      }
   8.340 +      for (int i=0; i<ARRLEN; i++) {
   8.341 +        a1[i] = -1;
   8.342 +        a2[i] = -1;
   8.343 +      }
   8.344 +      test_2ci_aln(a1, a2);
   8.345 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.346 +        errn += verify("test_2ci_aln: a1", i, a1[i], -1);
   8.347 +      }
   8.348 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   8.349 +        errn += verify("test_2ci_aln: a1", i, a1[i], -123);
   8.350 +      }
   8.351 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   8.352 +        errn += verify("test_2ci_aln: a2", i, a2[i], -103);
   8.353 +      }
   8.354 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   8.355 +        errn += verify("test_2ci_aln: a2", i, a2[i], -1);
   8.356 +      }
   8.357 +      for (int i=0; i<ARRLEN; i++) {
   8.358 +        a1[i] = -1;
   8.359 +        a2[i] = -1;
   8.360 +      }
   8.361 +      test_2vi_aln(a1, a2, 123, 103);
   8.362 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   8.363 +        errn += verify("test_2vi_aln: a1", i, a1[i], 123);
   8.364 +      }
   8.365 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   8.366 +        errn += verify("test_2vi_aln: a1", i, a1[i], -1);
   8.367 +      }
   8.368 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.369 +        errn += verify("test_2vi_aln: a2", i, a2[i], -1);
   8.370 +      }
   8.371 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   8.372 +        errn += verify("test_2vi_aln: a2", i, a2[i], 103);
   8.373 +      }
   8.374 +
   8.375 +      // Reset for 2 arrays with relative unaligned offset
   8.376 +      for (int i=0; i<ARRLEN; i++) {
   8.377 +        a1[i] = -1;
   8.378 +        a2[i] = -1;
   8.379 +      }
   8.380 +      test_vi(a2, 123, -1);
   8.381 +      test_cp_unalndst(a1, a2);
   8.382 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.383 +        errn += verify("test_cp_unalndst: a1", i, a1[i], -1);
   8.384 +      }
   8.385 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   8.386 +        errn += verify("test_cp_unalndst: a1", i, a1[i], 123);
   8.387 +      }
   8.388 +      test_vi(a2, -123, 123);
   8.389 +      test_cp_unalnsrc(a1, a2);
   8.390 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   8.391 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], -123);
   8.392 +      }
   8.393 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   8.394 +        errn += verify("test_cp_unalnsrc: a1", i, a1[i], 123);
   8.395 +      }
   8.396 +      for (int i=0; i<ARRLEN; i++) {
   8.397 +        a1[i] = -1;
   8.398 +        a2[i] = -1;
   8.399 +      }
   8.400 +      test_2ci_unaln(a1, a2);
   8.401 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.402 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -1);
   8.403 +      }
   8.404 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   8.405 +        errn += verify("test_2ci_unaln: a1", i, a1[i], -123);
   8.406 +      }
   8.407 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   8.408 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -103);
   8.409 +      }
   8.410 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   8.411 +        errn += verify("test_2ci_unaln: a2", i, a2[i], -1);
   8.412 +      }
   8.413 +      for (int i=0; i<ARRLEN; i++) {
   8.414 +        a1[i] = -1;
   8.415 +        a2[i] = -1;
   8.416 +      }
   8.417 +      test_2vi_unaln(a1, a2, 123, 103);
   8.418 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   8.419 +        errn += verify("test_2vi_unaln: a1", i, a1[i], 123);
   8.420 +      }
   8.421 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   8.422 +        errn += verify("test_2vi_unaln: a1", i, a1[i], -1);
   8.423 +      }
   8.424 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.425 +        errn += verify("test_2vi_unaln: a2", i, a2[i], -1);
   8.426 +      }
   8.427 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   8.428 +        errn += verify("test_2vi_unaln: a2", i, a2[i], 103);
   8.429 +      }
   8.430 +
   8.431 +      // Reset for aligned overlap initialization
   8.432 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.433 +        a1[i] = i;
   8.434 +      }
   8.435 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   8.436 +        a1[i] = -1;
   8.437 +      }
   8.438 +      test_cp_alndst(a1, a1);
   8.439 +      for (int i=0; i<ARRLEN; i++) {
   8.440 +        int v = i%ALIGN_OFF;
   8.441 +        errn += verify("test_cp_alndst_overlap: a1", i, a1[i], v);
   8.442 +      }
   8.443 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.444 +        a1[i+ALIGN_OFF] = -1;
   8.445 +      }
   8.446 +      test_cp_alnsrc(a1, a1);
   8.447 +      for (int i=0; i<ALIGN_OFF; i++) {
   8.448 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], -1);
   8.449 +      }
   8.450 +      for (int i=ALIGN_OFF; i<ARRLEN; i++) {
   8.451 +        int v = i%ALIGN_OFF;
   8.452 +        errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], v);
   8.453 +      }
   8.454 +      for (int i=0; i<ARRLEN; i++) {
   8.455 +        a1[i] = -1;
   8.456 +      }
   8.457 +      test_2ci_aln(a1, a1);
   8.458 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   8.459 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -103);
   8.460 +      }
   8.461 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   8.462 +        errn += verify("test_2ci_aln_overlap: a1", i, a1[i], -123);
   8.463 +      }
   8.464 +      for (int i=0; i<ARRLEN; i++) {
   8.465 +        a1[i] = -1;
   8.466 +      }
   8.467 +      test_2vi_aln(a1, a1, 123, 103);
   8.468 +      for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {
   8.469 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 123);
   8.470 +      }
   8.471 +      for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {
   8.472 +        errn += verify("test_2vi_aln_overlap: a1", i, a1[i], 103);
   8.473 +      }
   8.474 +
   8.475 +      // Reset for unaligned overlap initialization
   8.476 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.477 +        a1[i] = i;
   8.478 +      }
   8.479 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   8.480 +        a1[i] = -1;
   8.481 +      }
   8.482 +      test_cp_unalndst(a1, a1);
   8.483 +      for (int i=0; i<ARRLEN; i++) {
   8.484 +        int v = i%UNALIGN_OFF;
   8.485 +        errn += verify("test_cp_unalndst_overlap: a1", i, a1[i], v);
   8.486 +      }
   8.487 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.488 +        a1[i+UNALIGN_OFF] = -1;
   8.489 +      }
   8.490 +      test_cp_unalnsrc(a1, a1);
   8.491 +      for (int i=0; i<UNALIGN_OFF; i++) {
   8.492 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], -1);
   8.493 +      }
   8.494 +      for (int i=UNALIGN_OFF; i<ARRLEN; i++) {
   8.495 +        int v = i%UNALIGN_OFF;
   8.496 +        errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], v);
   8.497 +      }
   8.498 +      for (int i=0; i<ARRLEN; i++) {
   8.499 +        a1[i] = -1;
   8.500 +      }
   8.501 +      test_2ci_unaln(a1, a1);
   8.502 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   8.503 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -103);
   8.504 +      }
   8.505 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   8.506 +        errn += verify("test_2ci_unaln_overlap: a1", i, a1[i], -123);
   8.507 +      }
   8.508 +      for (int i=0; i<ARRLEN; i++) {
   8.509 +        a1[i] = -1;
   8.510 +      }
   8.511 +      test_2vi_unaln(a1, a1, 123, 103);
   8.512 +      for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {
   8.513 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 123);
   8.514 +      }
   8.515 +      for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {
   8.516 +        errn += verify("test_2vi_unaln_overlap: a1", i, a1[i], 103);
   8.517 +      }
   8.518 +
   8.519 +    }
   8.520 +
   8.521 +    if (errn > 0 || test_only)
   8.522 +      return errn;
   8.523 +
   8.524 +    // Initialize
   8.525 +    for (int i=0; i<ARRLEN; i++) {
   8.526 +      a1[i] = -1;
   8.527 +      a2[i] = -1;
   8.528 +    }
   8.529 +    System.out.println("Time");
   8.530 +    long start, end;
   8.531 +    start = System.currentTimeMillis();
   8.532 +    for (int i=0; i<ITERS; i++) {
   8.533 +      test_ci(a1);
   8.534 +    }
   8.535 +    end = System.currentTimeMillis();
   8.536 +    System.out.println("test_ci: " + (end - start));
   8.537 +    start = System.currentTimeMillis();
   8.538 +    for (int i=0; i<ITERS; i++) {
   8.539 +      test_vi(a2, 123, -1);
   8.540 +    }
   8.541 +    end = System.currentTimeMillis();
   8.542 +    System.out.println("test_vi: " + (end - start));
   8.543 +    start = System.currentTimeMillis();
   8.544 +    for (int i=0; i<ITERS; i++) {
   8.545 +      test_cp(a1, a2);
   8.546 +    }
   8.547 +    end = System.currentTimeMillis();
   8.548 +    System.out.println("test_cp: " + (end - start));
   8.549 +    start = System.currentTimeMillis();
   8.550 +    for (int i=0; i<ITERS; i++) {
   8.551 +      test_2ci(a1, a2);
   8.552 +    }
   8.553 +    end = System.currentTimeMillis();
   8.554 +    System.out.println("test_2ci: " + (end - start));
   8.555 +    start = System.currentTimeMillis();
   8.556 +    for (int i=0; i<ITERS; i++) {
   8.557 +      test_2vi(a1, a2, 123, 103);
   8.558 +    }
   8.559 +    end = System.currentTimeMillis();
   8.560 +    System.out.println("test_2vi: " + (end - start));
   8.561 +
   8.562 +    start = System.currentTimeMillis();
   8.563 +    for (int i=0; i<ITERS; i++) {
   8.564 +      test_ci_neg(a1, 123);
   8.565 +    }
   8.566 +    end = System.currentTimeMillis();
   8.567 +    System.out.println("test_ci_neg: " + (end - start));
   8.568 +    start = System.currentTimeMillis();
   8.569 +    for (int i=0; i<ITERS; i++) {
   8.570 +      test_vi_neg(a2, 123, 103);
   8.571 +    }
   8.572 +    end = System.currentTimeMillis();
   8.573 +    System.out.println("test_vi_neg: " + (end - start));
   8.574 +    start = System.currentTimeMillis();
   8.575 +    for (int i=0; i<ITERS; i++) {
   8.576 +      test_cp_neg(a1, a2);
   8.577 +    }
   8.578 +    end = System.currentTimeMillis();
   8.579 +    System.out.println("test_cp_neg: " + (end - start));
   8.580 +    start = System.currentTimeMillis();
   8.581 +    for (int i=0; i<ITERS; i++) {
   8.582 +      test_2ci_neg(a1, a2);
   8.583 +    }
   8.584 +    end = System.currentTimeMillis();
   8.585 +    System.out.println("test_2ci_neg: " + (end - start));
   8.586 +    start = System.currentTimeMillis();
   8.587 +    for (int i=0; i<ITERS; i++) {
   8.588 +      test_2vi_neg(a1, a2, 123, 103);
   8.589 +    }
   8.590 +    end = System.currentTimeMillis();
   8.591 +    System.out.println("test_2vi_neg: " + (end - start));
   8.592 +
   8.593 +    start = System.currentTimeMillis();
   8.594 +    for (int i=0; i<ITERS; i++) {
   8.595 +      test_ci_oppos(a1, 123);
   8.596 +    }
   8.597 +    end = System.currentTimeMillis();
   8.598 +    System.out.println("test_ci_oppos: " + (end - start));
   8.599 +    start = System.currentTimeMillis();
   8.600 +    for (int i=0; i<ITERS; i++) {
   8.601 +      test_vi_oppos(a2, 123, 103);
   8.602 +    }
   8.603 +    end = System.currentTimeMillis();
   8.604 +    System.out.println("test_vi_oppos: " + (end - start));
   8.605 +    start = System.currentTimeMillis();
   8.606 +    for (int i=0; i<ITERS; i++) {
   8.607 +      test_cp_oppos(a1, a2);
   8.608 +    }
   8.609 +    end = System.currentTimeMillis();
   8.610 +    System.out.println("test_cp_oppos: " + (end - start));
   8.611 +    start = System.currentTimeMillis();
   8.612 +    for (int i=0; i<ITERS; i++) {
   8.613 +      test_2ci_oppos(a1, a2);
   8.614 +    }
   8.615 +    end = System.currentTimeMillis();
   8.616 +    System.out.println("test_2ci_oppos: " + (end - start));
   8.617 +    start = System.currentTimeMillis();
   8.618 +    for (int i=0; i<ITERS; i++) {
   8.619 +      test_2vi_oppos(a1, a2, 123, 103);
   8.620 +    }
   8.621 +    end = System.currentTimeMillis();
   8.622 +    System.out.println("test_2vi_oppos: " + (end - start));
   8.623 +
   8.624 +    start = System.currentTimeMillis();
   8.625 +    for (int i=0; i<ITERS; i++) {
   8.626 +      test_ci_off(a1, 123);
   8.627 +    }
   8.628 +    end = System.currentTimeMillis();
   8.629 +    System.out.println("test_ci_off: " + (end - start));
   8.630 +    start = System.currentTimeMillis();
   8.631 +    for (int i=0; i<ITERS; i++) {
   8.632 +      test_vi_off(a2, 123, 103);
   8.633 +    }
   8.634 +    end = System.currentTimeMillis();
   8.635 +    System.out.println("test_vi_off: " + (end - start));
   8.636 +    start = System.currentTimeMillis();
   8.637 +    for (int i=0; i<ITERS; i++) {
   8.638 +      test_cp_off(a1, a2);
   8.639 +    }
   8.640 +    end = System.currentTimeMillis();
   8.641 +    System.out.println("test_cp_off: " + (end - start));
   8.642 +    start = System.currentTimeMillis();
   8.643 +    for (int i=0; i<ITERS; i++) {
   8.644 +      test_2ci_off(a1, a2);
   8.645 +    }
   8.646 +    end = System.currentTimeMillis();
   8.647 +    System.out.println("test_2ci_off: " + (end - start));
   8.648 +    start = System.currentTimeMillis();
   8.649 +    for (int i=0; i<ITERS; i++) {
   8.650 +      test_2vi_off(a1, a2, 123, 103);
   8.651 +    }
   8.652 +    end = System.currentTimeMillis();
   8.653 +    System.out.println("test_2vi_off: " + (end - start));
   8.654 +
   8.655 +    start = System.currentTimeMillis();
   8.656 +    for (int i=0; i<ITERS; i++) {
   8.657 +      test_ci_inv(a1, OFFSET, 123);
   8.658 +    }
   8.659 +    end = System.currentTimeMillis();
   8.660 +    System.out.println("test_ci_inv: " + (end - start));
   8.661 +    start = System.currentTimeMillis();
   8.662 +    for (int i=0; i<ITERS; i++) {
   8.663 +      test_vi_inv(a2, 123, OFFSET, 103);
   8.664 +    }
   8.665 +    end = System.currentTimeMillis();
   8.666 +    System.out.println("test_vi_inv: " + (end - start));
   8.667 +    start = System.currentTimeMillis();
   8.668 +    for (int i=0; i<ITERS; i++) {
   8.669 +      test_cp_inv(a1, a2, OFFSET);
   8.670 +    }
   8.671 +    end = System.currentTimeMillis();
   8.672 +    System.out.println("test_cp_inv: " + (end - start));
   8.673 +    start = System.currentTimeMillis();
   8.674 +    for (int i=0; i<ITERS; i++) {
   8.675 +      test_2ci_inv(a1, a2, OFFSET);
   8.676 +    }
   8.677 +    end = System.currentTimeMillis();
   8.678 +    System.out.println("test_2ci_inv: " + (end - start));
   8.679 +    start = System.currentTimeMillis();
   8.680 +    for (int i=0; i<ITERS; i++) {
   8.681 +      test_2vi_inv(a1, a2, 123, 103, OFFSET);
   8.682 +    }
   8.683 +    end = System.currentTimeMillis();
   8.684 +    System.out.println("test_2vi_inv: " + (end - start));
   8.685 +
   8.686 +    start = System.currentTimeMillis();
   8.687 +    for (int i=0; i<ITERS; i++) {
   8.688 +      test_ci_scl(a1, 123);
   8.689 +    }
   8.690 +    end = System.currentTimeMillis();
   8.691 +    System.out.println("test_ci_scl: " + (end - start));
   8.692 +    start = System.currentTimeMillis();
   8.693 +    for (int i=0; i<ITERS; i++) {
   8.694 +      test_vi_scl(a2, 123, 103);
   8.695 +    }
   8.696 +    end = System.currentTimeMillis();
   8.697 +    System.out.println("test_vi_scl: " + (end - start));
   8.698 +    start = System.currentTimeMillis();
   8.699 +    for (int i=0; i<ITERS; i++) {
   8.700 +      test_cp_scl(a1, a2);
   8.701 +    }
   8.702 +    end = System.currentTimeMillis();
   8.703 +    System.out.println("test_cp_scl: " + (end - start));
   8.704 +    start = System.currentTimeMillis();
   8.705 +    for (int i=0; i<ITERS; i++) {
   8.706 +      test_2ci_scl(a1, a2);
   8.707 +    }
   8.708 +    end = System.currentTimeMillis();
   8.709 +    System.out.println("test_2ci_scl: " + (end - start));
   8.710 +    start = System.currentTimeMillis();
   8.711 +    for (int i=0; i<ITERS; i++) {
   8.712 +      test_2vi_scl(a1, a2, 123, 103);
   8.713 +    }
   8.714 +    end = System.currentTimeMillis();
   8.715 +    System.out.println("test_2vi_scl: " + (end - start));
   8.716 +
   8.717 +    start = System.currentTimeMillis();
   8.718 +    for (int i=0; i<ITERS; i++) {
   8.719 +      test_cp_alndst(a1, a2);
   8.720 +    }
   8.721 +    end = System.currentTimeMillis();
   8.722 +    System.out.println("test_cp_alndst: " + (end - start));
   8.723 +    start = System.currentTimeMillis();
   8.724 +    for (int i=0; i<ITERS; i++) {
   8.725 +      test_cp_alnsrc(a1, a2);
   8.726 +    }
   8.727 +    end = System.currentTimeMillis();
   8.728 +    System.out.println("test_cp_alnsrc: " + (end - start));
   8.729 +    start = System.currentTimeMillis();
   8.730 +    for (int i=0; i<ITERS; i++) {
   8.731 +      test_2ci_aln(a1, a2);
   8.732 +    }
   8.733 +    end = System.currentTimeMillis();
   8.734 +    System.out.println("test_2ci_aln: " + (end - start));
   8.735 +    start = System.currentTimeMillis();
   8.736 +    for (int i=0; i<ITERS; i++) {
   8.737 +      test_2vi_aln(a1, a2, 123, 103);
   8.738 +    }
   8.739 +    end = System.currentTimeMillis();
   8.740 +    System.out.println("test_2vi_aln: " + (end - start));
   8.741 +
   8.742 +    start = System.currentTimeMillis();
   8.743 +    for (int i=0; i<ITERS; i++) {
   8.744 +      test_cp_unalndst(a1, a2);
   8.745 +    }
   8.746 +    end = System.currentTimeMillis();
   8.747 +    System.out.println("test_cp_unalndst: " + (end - start));
   8.748 +    start = System.currentTimeMillis();
   8.749 +    for (int i=0; i<ITERS; i++) {
   8.750 +      test_cp_unalnsrc(a1, a2);
   8.751 +    }
   8.752 +    end = System.currentTimeMillis();
   8.753 +    System.out.println("test_cp_unalnsrc: " + (end - start));
   8.754 +    start = System.currentTimeMillis();
   8.755 +    for (int i=0; i<ITERS; i++) {
   8.756 +      test_2ci_unaln(a1, a2);
   8.757 +    }
   8.758 +    end = System.currentTimeMillis();
   8.759 +    System.out.println("test_2ci_unaln: " + (end - start));
   8.760 +    start = System.currentTimeMillis();
   8.761 +    for (int i=0; i<ITERS; i++) {
   8.762 +      test_2vi_unaln(a1, a2, 123, 103);
   8.763 +    }
   8.764 +    end = System.currentTimeMillis();
   8.765 +    System.out.println("test_2vi_unaln: " + (end - start));
   8.766 +
   8.767 +    return errn;
   8.768 +  }
   8.769 +
   8.770 +  private final static long byte_offset(int i) {
   8.771 +    return ((long)i << 2) + BASE;
   8.772 +  }
   8.773 +
   8.774 +  static void test_ci(int[] a) {
   8.775 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.776 +      unsafe.putIntVolatile(a, byte_offset(i), -123);
   8.777 +    }
   8.778 +  }
   8.779 +  static void test_vi(int[] a, int b, int old) {
   8.780 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.781 +      unsafe.putIntVolatile(a, byte_offset(i), b);
   8.782 +    }
   8.783 +  }
   8.784 +  static void test_cp(int[] a, int[] b) {
   8.785 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.786 +      unsafe.putIntVolatile(a, byte_offset(i), b[i]);
   8.787 +    }
   8.788 +  }
   8.789 +  static void test_2ci(int[] a, int[] b) {
   8.790 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.791 +      unsafe.putIntVolatile(a, byte_offset(i), -123);
   8.792 +      unsafe.putIntVolatile(b, byte_offset(i), -103);
   8.793 +    }
   8.794 +  }
   8.795 +  static void test_2vi(int[] a, int[] b, int c, int d) {
   8.796 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.797 +      unsafe.putIntVolatile(a, byte_offset(i), c);
   8.798 +      unsafe.putIntVolatile(b, byte_offset(i), d);
   8.799 +    }
   8.800 +  }
   8.801 +  static void test_ci_neg(int[] a, int old) {
   8.802 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   8.803 +      unsafe.putIntVolatile(a, byte_offset(i), -123);
   8.804 +    }
   8.805 +  }
   8.806 +  static void test_vi_neg(int[] a, int b, int old) {
   8.807 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   8.808 +      unsafe.putIntVolatile(a, byte_offset(i), b);
   8.809 +    }
   8.810 +  }
   8.811 +  static void test_cp_neg(int[] a, int[] b) {
   8.812 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   8.813 +      unsafe.putIntVolatile(a, byte_offset(i), b[i]);
   8.814 +    }
   8.815 +  }
   8.816 +  static void test_2ci_neg(int[] a, int[] b) {
   8.817 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   8.818 +      unsafe.putIntVolatile(a, byte_offset(i), -123);
   8.819 +      unsafe.putIntVolatile(b, byte_offset(i), -103);
   8.820 +    }
   8.821 +  }
   8.822 +  static void test_2vi_neg(int[] a, int[] b, int c, int d) {
   8.823 +    for (int i = ARRLEN-1; i >= 0; i-=1) {
   8.824 +      unsafe.putIntVolatile(a, byte_offset(i), c);
   8.825 +      unsafe.putIntVolatile(b, byte_offset(i), d);
   8.826 +    }
   8.827 +  }
   8.828 +  static void test_ci_oppos(int[] a, int old) {
   8.829 +    int limit = ARRLEN-1;
   8.830 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.831 +      unsafe.putIntVolatile(a, byte_offset(limit-i), -123);
   8.832 +    }
   8.833 +  }
   8.834 +  static void test_vi_oppos(int[] a, int b, int old) {
   8.835 +    int limit = ARRLEN-1;
   8.836 +    for (int i = limit; i >= 0; i-=1) {
   8.837 +      unsafe.putIntVolatile(a, byte_offset(limit-i), b);
   8.838 +    }
   8.839 +  }
   8.840 +  static void test_cp_oppos(int[] a, int[] b) {
   8.841 +    int limit = ARRLEN-1;
   8.842 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.843 +      unsafe.putIntVolatile(a, byte_offset(i), b[limit-i]);
   8.844 +    }
   8.845 +  }
   8.846 +  static void test_2ci_oppos(int[] a, int[] b) {
   8.847 +    int limit = ARRLEN-1;
   8.848 +    for (int i = 0; i < ARRLEN; i+=1) {
   8.849 +      unsafe.putIntVolatile(a, byte_offset(limit-i), -123);
   8.850 +      unsafe.putIntVolatile(b, byte_offset(i), -103);
   8.851 +    }
   8.852 +  }
   8.853 +  static void test_2vi_oppos(int[] a, int[] b, int c, int d) {
   8.854 +    int limit = ARRLEN-1;
   8.855 +    for (int i = limit; i >= 0; i-=1) {
   8.856 +      unsafe.putIntVolatile(a, byte_offset(i), c);
   8.857 +      unsafe.putIntVolatile(b, byte_offset(limit-i), d);
   8.858 +    }
   8.859 +  }
   8.860 +  static void test_ci_off(int[] a, int old) {
   8.861 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   8.862 +      unsafe.putIntVolatile(a, byte_offset(i+OFFSET), -123);
   8.863 +    }
   8.864 +  }
   8.865 +  static void test_vi_off(int[] a, int b, int old) {
   8.866 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   8.867 +      unsafe.putIntVolatile(a, byte_offset(i+OFFSET), b);
   8.868 +    }
   8.869 +  }
   8.870 +  static void test_cp_off(int[] a, int[] b) {
   8.871 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   8.872 +      unsafe.putIntVolatile(a, byte_offset(i+OFFSET), b[i+OFFSET]);
   8.873 +    }
   8.874 +  }
   8.875 +  static void test_2ci_off(int[] a, int[] b) {
   8.876 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   8.877 +      unsafe.putIntVolatile(a, byte_offset(i+OFFSET), -123);
   8.878 +      unsafe.putIntVolatile(b, byte_offset(i+OFFSET), -103);
   8.879 +    }
   8.880 +  }
   8.881 +  static void test_2vi_off(int[] a, int[] b, int c, int d) {
   8.882 +    for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
   8.883 +      unsafe.putIntVolatile(a, byte_offset(i+OFFSET), c);
   8.884 +      unsafe.putIntVolatile(b, byte_offset(i+OFFSET), d);
   8.885 +    }
   8.886 +  }
   8.887 +  static void test_ci_inv(int[] a, int k, int old) {
   8.888 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   8.889 +      unsafe.putIntVolatile(a, byte_offset(i+k), -123);
   8.890 +    }
   8.891 +  }
   8.892 +  static void test_vi_inv(int[] a, int b, int k, int old) {
   8.893 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   8.894 +      unsafe.putIntVolatile(a, byte_offset(i+k), b);
   8.895 +    }
   8.896 +  }
   8.897 +  static void test_cp_inv(int[] a, int[] b, int k) {
   8.898 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   8.899 +      unsafe.putIntVolatile(a, byte_offset(i+k), b[i+k]);
   8.900 +    }
   8.901 +  }
   8.902 +  static void test_2ci_inv(int[] a, int[] b, int k) {
   8.903 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   8.904 +      unsafe.putIntVolatile(a, byte_offset(i+k), -123);
   8.905 +      unsafe.putIntVolatile(b, byte_offset(i+k), -103);
   8.906 +    }
   8.907 +  }
   8.908 +  static void test_2vi_inv(int[] a, int[] b, int c, int d, int k) {
   8.909 +    for (int i = 0; i < ARRLEN-k; i+=1) {
   8.910 +      unsafe.putIntVolatile(a, byte_offset(i+k), c);
   8.911 +      unsafe.putIntVolatile(b, byte_offset(i+k), d);
   8.912 +    }
   8.913 +  }
   8.914 +  static void test_ci_scl(int[] a, int old) {
   8.915 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   8.916 +      unsafe.putIntVolatile(a, byte_offset(i*SCALE), -123);
   8.917 +    }
   8.918 +  }
   8.919 +  static void test_vi_scl(int[] a, int b, int old) {
   8.920 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   8.921 +      unsafe.putIntVolatile(a, byte_offset(i*SCALE), b);
   8.922 +    }
   8.923 +  }
   8.924 +  static void test_cp_scl(int[] a, int[] b) {
   8.925 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   8.926 +      unsafe.putIntVolatile(a, byte_offset(i*SCALE), b[i*SCALE]);
   8.927 +    }
   8.928 +  }
   8.929 +  static void test_2ci_scl(int[] a, int[] b) {
   8.930 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   8.931 +      unsafe.putIntVolatile(a, byte_offset(i*SCALE), -123);
   8.932 +      unsafe.putIntVolatile(b, byte_offset(i*SCALE), -103);
   8.933 +    }
   8.934 +  }
   8.935 +  static void test_2vi_scl(int[] a, int[] b, int c, int d) {
   8.936 +    for (int i = 0; i*SCALE < ARRLEN; i+=1) {
   8.937 +      unsafe.putIntVolatile(a, byte_offset(i*SCALE), c);
   8.938 +      unsafe.putIntVolatile(b, byte_offset(i*SCALE), d);
   8.939 +    }
   8.940 +  }
   8.941 +  static void test_cp_alndst(int[] a, int[] b) {
   8.942 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   8.943 +      unsafe.putIntVolatile(a, byte_offset(i+ALIGN_OFF), b[i]);
   8.944 +    }
   8.945 +  }
   8.946 +  static void test_cp_alnsrc(int[] a, int[] b) {
   8.947 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   8.948 +      unsafe.putIntVolatile(a, byte_offset(i), b[i+ALIGN_OFF]);
   8.949 +    }
   8.950 +  }
   8.951 +  static void test_2ci_aln(int[] a, int[] b) {
   8.952 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   8.953 +      unsafe.putIntVolatile(a, byte_offset(i+ALIGN_OFF), -123);
   8.954 +      unsafe.putIntVolatile(b, byte_offset(i), -103);
   8.955 +    }
   8.956 +  }
   8.957 +  static void test_2vi_aln(int[] a, int[] b, int c, int d) {
   8.958 +    for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
   8.959 +      unsafe.putIntVolatile(a, byte_offset(i), c);
   8.960 +      unsafe.putIntVolatile(b, byte_offset(i+ALIGN_OFF), d);
   8.961 +    }
   8.962 +  }
   8.963 +  static void test_cp_unalndst(int[] a, int[] b) {
   8.964 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   8.965 +      unsafe.putIntVolatile(a, byte_offset(i+UNALIGN_OFF), b[i]);
   8.966 +    }
   8.967 +  }
   8.968 +  static void test_cp_unalnsrc(int[] a, int[] b) {
   8.969 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   8.970 +      unsafe.putIntVolatile(a, byte_offset(i), b[i+UNALIGN_OFF]);
   8.971 +    }
   8.972 +  }
   8.973 +  static void test_2ci_unaln(int[] a, int[] b) {
   8.974 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   8.975 +      unsafe.putIntVolatile(a, byte_offset(i+UNALIGN_OFF), -123);
   8.976 +      unsafe.putIntVolatile(b, byte_offset(i), -103);
   8.977 +    }
   8.978 +  }
   8.979 +  static void test_2vi_unaln(int[] a, int[] b, int c, int d) {
   8.980 +    for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
   8.981 +      unsafe.putIntVolatile(a, byte_offset(i), c);
   8.982 +      unsafe.putIntVolatile(b, byte_offset(i+UNALIGN_OFF), d);
   8.983 +    }
   8.984 +  }
   8.985 +
   8.986 +  static int verify(String text, int i, int elem, int val) {
   8.987 +    if (elem != val) {
   8.988 +      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
   8.989 +      return 1;
   8.990 +    }
   8.991 +    return 0;
   8.992 +  }
   8.993 +}

mercurial