1/* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 8004867 27 * @summary VM crashing with assert "share/vm/opto/node.hpp:357 - assert(i < _max) failed: oob" 28 * 29 * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation 30 * -XX:-OptimizeFill 31 * compiler.c2.cr8004867.TestIntAtomicVolatile 32 * @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation 33 * -XX:+OptimizeFill 34 * compiler.c2.cr8004867.TestIntAtomicVolatile 35 */ 36 37package compiler.c2.cr8004867; 38 39import java.util.concurrent.atomic.AtomicIntegerArray; 40 41public class TestIntAtomicVolatile { 42 private static final int ARRLEN = 97; 43 private static final int ITERS = 11000; 44 private static final int OFFSET = 3; 45 private static final int SCALE = 2; 46 private static final int ALIGN_OFF = 8; 47 private static final int UNALIGN_OFF = 5; 48 49 public static void main(String args[]) { 50 System.out.println("Testing Integer array atomic volatile operations"); 51 int errn = test(false); 52 if (errn > 0) { 53 System.err.println("FAILED: " + errn + " errors"); 54 System.exit(97); 55 } 56 System.out.println("PASSED"); 57 } 58 59 static int test(boolean test_only) { 60 AtomicIntegerArray a1 = new AtomicIntegerArray(ARRLEN); 61 AtomicIntegerArray a2 = new AtomicIntegerArray(ARRLEN); 62 // Initialize 63 for (int i=0; i<ARRLEN; i++) { 64 a1.set(i, -1); 65 a2.set(i, -1); 66 } 67 System.out.println("Warmup"); 68 for (int i=0; i<ITERS; i++) { 69 test_ci(a1); 70 test_vi(a2, 123, -1); 71 test_cp(a1, a2); 72 test_2ci(a1, a2); 73 test_2vi(a1, a2, 123, 103); 74 test_ci_neg(a1, 123); 75 test_vi_neg(a2, 123, 103); 76 test_cp_neg(a1, a2); 77 test_2ci_neg(a1, a2); 78 test_2vi_neg(a1, a2, 123, 103); 79 test_ci_oppos(a1, 123); 80 test_vi_oppos(a2, 123, 103); 81 test_cp_oppos(a1, a2); 82 test_2ci_oppos(a1, a2); 83 test_2vi_oppos(a1, a2, 123, 103); 84 test_ci_off(a1, 123); 85 test_vi_off(a2, 123, 103); 86 test_cp_off(a1, a2); 87 test_2ci_off(a1, a2); 88 test_2vi_off(a1, a2, 123, 103); 89 test_ci_inv(a1, OFFSET, 123); 90 test_vi_inv(a2, 123, OFFSET, 103); 91 test_cp_inv(a1, a2, OFFSET); 92 test_2ci_inv(a1, a2, OFFSET); 93 test_2vi_inv(a1, a2, 123, 103, OFFSET); 94 test_ci_scl(a1, 123); 95 test_vi_scl(a2, 123, 103); 96 test_cp_scl(a1, a2); 97 test_2ci_scl(a1, a2); 98 test_2vi_scl(a1, a2, 123, 103); 99 test_cp_alndst(a1, a2); 100 test_cp_alnsrc(a1, a2); 101 test_2ci_aln(a1, a2); 102 test_2vi_aln(a1, a2, 123, 103); 103 test_cp_unalndst(a1, a2); 104 test_cp_unalnsrc(a1, a2); 105 test_2ci_unaln(a1, a2); 106 test_2vi_unaln(a1, a2, 123, 103); 107 } 108 // Initialize 109 for (int i=0; i<ARRLEN; i++) { 110 a1.set(i, -1); 111 a2.set(i, -1); 112 } 113 // Test and verify results 114 System.out.println("Verification"); 115 int errn = 0; 116 { 117 test_ci(a1); 118 for (int i=0; i<ARRLEN; i++) { 119 errn += verify("test_ci: a1", i, a1.get(i), -123); 120 } 121 test_vi(a2, 123, -1); 122 for (int i=0; i<ARRLEN; i++) { 123 errn += verify("test_vi: a2", i, a2.get(i), 123); 124 } 125 test_cp(a1, a2); 126 for (int i=0; i<ARRLEN; i++) { 127 errn += verify("test_cp: a1", i, a1.get(i), 123); 128 } 129 test_2ci(a1, a2); 130 for (int i=0; i<ARRLEN; i++) { 131 errn += verify("test_2ci: a1", i, a1.get(i), -123); 132 errn += verify("test_2ci: a2", i, a2.get(i), -103); 133 } 134 test_2vi(a1, a2, 123, 103); 135 for (int i=0; i<ARRLEN; i++) { 136 errn += verify("test_2vi: a1", i, a1.get(i), 123); 137 errn += verify("test_2vi: a2", i, a2.get(i), 103); 138 } 139 // Reset for negative stride 140 for (int i=0; i<ARRLEN; i++) { 141 a1.set(i, -1); 142 a2.set(i, -1); 143 } 144 test_ci_neg(a1, -1); 145 for (int i=0; i<ARRLEN; i++) { 146 errn += verify("test_ci_neg: a1", i, a1.get(i), -123); 147 } 148 test_vi_neg(a2, 123, -1); 149 for (int i=0; i<ARRLEN; i++) { 150 errn += verify("test_vi_neg: a2", i, a2.get(i), 123); 151 } 152 test_cp_neg(a1, a2); 153 for (int i=0; i<ARRLEN; i++) { 154 errn += verify("test_cp_neg: a1", i, a1.get(i), 123); 155 } 156 test_2ci_neg(a1, a2); 157 for (int i=0; i<ARRLEN; i++) { 158 errn += verify("test_2ci_neg: a1", i, a1.get(i), -123); 159 errn += verify("test_2ci_neg: a2", i, a2.get(i), -103); 160 } 161 test_2vi_neg(a1, a2, 123, 103); 162 for (int i=0; i<ARRLEN; i++) { 163 errn += verify("test_2vi_neg: a1", i, a1.get(i), 123); 164 errn += verify("test_2vi_neg: a2", i, a2.get(i), 103); 165 } 166 // Reset for opposite stride 167 for (int i=0; i<ARRLEN; i++) { 168 a1.set(i, -1); 169 a2.set(i, -1); 170 } 171 test_ci_oppos(a1, -1); 172 for (int i=0; i<ARRLEN; i++) { 173 errn += verify("test_ci_oppos: a1", i, a1.get(i), -123); 174 } 175 test_vi_oppos(a2, 123, -1); 176 for (int i=0; i<ARRLEN; i++) { 177 errn += verify("test_vi_oppos: a2", i, a2.get(i), 123); 178 } 179 test_cp_oppos(a1, a2); 180 for (int i=0; i<ARRLEN; i++) { 181 errn += verify("test_cp_oppos: a1", i, a1.get(i), 123); 182 } 183 test_2ci_oppos(a1, a2); 184 for (int i=0; i<ARRLEN; i++) { 185 errn += verify("test_2ci_oppos: a1", i, a1.get(i), -123); 186 errn += verify("test_2ci_oppos: a2", i, a2.get(i), -103); 187 } 188 test_2vi_oppos(a1, a2, 123, 103); 189 for (int i=0; i<ARRLEN; i++) { 190 errn += verify("test_2vi_oppos: a1", i, a1.get(i), 123); 191 errn += verify("test_2vi_oppos: a2", i, a2.get(i), 103); 192 } 193 // Reset for indexing with offset 194 for (int i=0; i<ARRLEN; i++) { 195 a1.set(i, -1); 196 a2.set(i, -1); 197 } 198 test_ci_off(a1, -1); 199 for (int i=OFFSET; i<ARRLEN; i++) { 200 errn += verify("test_ci_off: a1", i, a1.get(i), -123); 201 } 202 test_vi_off(a2, 123, -1); 203 for (int i=OFFSET; i<ARRLEN; i++) { 204 errn += verify("test_vi_off: a2", i, a2.get(i), 123); 205 } 206 test_cp_off(a1, a2); 207 for (int i=OFFSET; i<ARRLEN; i++) { 208 errn += verify("test_cp_off: a1", i, a1.get(i), 123); 209 } 210 test_2ci_off(a1, a2); 211 for (int i=OFFSET; i<ARRLEN; i++) { 212 errn += verify("test_2ci_off: a1", i, a1.get(i), -123); 213 errn += verify("test_2ci_off: a2", i, a2.get(i), -103); 214 } 215 test_2vi_off(a1, a2, 123, 103); 216 for (int i=OFFSET; i<ARRLEN; i++) { 217 errn += verify("test_2vi_off: a1", i, a1.get(i), 123); 218 errn += verify("test_2vi_off: a2", i, a2.get(i), 103); 219 } 220 for (int i=0; i<OFFSET; i++) { 221 errn += verify("test_2vi_off: a1", i, a1.get(i), -1); 222 errn += verify("test_2vi_off: a2", i, a2.get(i), -1); 223 } 224 // Reset for indexing with invariant offset 225 for (int i=0; i<ARRLEN; i++) { 226 a1.set(i, -1); 227 a2.set(i, -1); 228 } 229 test_ci_inv(a1, OFFSET, -1); 230 for (int i=OFFSET; i<ARRLEN; i++) { 231 errn += verify("test_ci_inv: a1", i, a1.get(i), -123); 232 } 233 test_vi_inv(a2, 123, OFFSET, -1); 234 for (int i=OFFSET; i<ARRLEN; i++) { 235 errn += verify("test_vi_inv: a2", i, a2.get(i), 123); 236 } 237 test_cp_inv(a1, a2, OFFSET); 238 for (int i=OFFSET; i<ARRLEN; i++) { 239 errn += verify("test_cp_inv: a1", i, a1.get(i), 123); 240 } 241 test_2ci_inv(a1, a2, OFFSET); 242 for (int i=OFFSET; i<ARRLEN; i++) { 243 errn += verify("test_2ci_inv: a1", i, a1.get(i), -123); 244 errn += verify("test_2ci_inv: a2", i, a2.get(i), -103); 245 } 246 test_2vi_inv(a1, a2, 123, 103, OFFSET); 247 for (int i=OFFSET; i<ARRLEN; i++) { 248 errn += verify("test_2vi_inv: a1", i, a1.get(i), 123); 249 errn += verify("test_2vi_inv: a2", i, a2.get(i), 103); 250 } 251 for (int i=0; i<OFFSET; i++) { 252 errn += verify("test_2vi_inv: a1", i, a1.get(i), -1); 253 errn += verify("test_2vi_inv: a2", i, a2.get(i), -1); 254 } 255 // Reset for indexing with scale 256 for (int i=0; i<ARRLEN; i++) { 257 a1.set(i, -1); 258 a2.set(i, -1); 259 } 260 test_ci_scl(a1, -1); 261 for (int i=0; i<ARRLEN; i++) { 262 int val = (i%SCALE != 0) ? -1 : -123; 263 errn += verify("test_ci_scl: a1", i, a1.get(i), val); 264 } 265 test_vi_scl(a2, 123, -1); 266 for (int i=0; i<ARRLEN; i++) { 267 int val = (i%SCALE != 0) ? -1 : 123; 268 errn += verify("test_vi_scl: a2", i, a2.get(i), val); 269 } 270 test_cp_scl(a1, a2); 271 for (int i=0; i<ARRLEN; i++) { 272 int val = (i%SCALE != 0) ? -1 : 123; 273 errn += verify("test_cp_scl: a1", i, a1.get(i), val); 274 } 275 test_2ci_scl(a1, a2); 276 for (int i=0; i<ARRLEN; i++) { 277 if (i%SCALE != 0) { 278 errn += verify("test_2ci_scl: a1", i, a1.get(i), -1); 279 } else if (i*SCALE < ARRLEN) { 280 errn += verify("test_2ci_scl: a1", i*SCALE, a1.get(i*SCALE), -123); 281 } 282 if (i%SCALE != 0) { 283 errn += verify("test_2ci_scl: a2", i, a2.get(i), -1); 284 } else if (i*SCALE < ARRLEN) { 285 errn += verify("test_2ci_scl: a2", i*SCALE, a2.get(i*SCALE), -103); 286 } 287 } 288 test_2vi_scl(a1, a2, 123, 103); 289 for (int i=0; i<ARRLEN; i++) { 290 if (i%SCALE != 0) { 291 errn += verify("test_2vi_scl: a1", i, a1.get(i), -1); 292 } else if (i*SCALE < ARRLEN) { 293 errn += verify("test_2vi_scl: a1", i*SCALE, a1.get(i*SCALE), 123); 294 } 295 if (i%SCALE != 0) { 296 errn += verify("test_2vi_scl: a2", i, a2.get(i), -1); 297 } else if (i*SCALE < ARRLEN) { 298 errn += verify("test_2vi_scl: a2", i*SCALE, a2.get(i*SCALE), 103); 299 } 300 } 301 // Reset for 2 arrays with relative aligned offset 302 for (int i=0; i<ARRLEN; i++) { 303 a1.set(i, -1); 304 a2.set(i, -1); 305 } 306 test_vi(a2, 123, -1); 307 test_cp_alndst(a1, a2); 308 for (int i=0; i<ALIGN_OFF; i++) { 309 errn += verify("test_cp_alndst: a1", i, a1.get(i), -1); 310 } 311 for (int i=ALIGN_OFF; i<ARRLEN; i++) { 312 errn += verify("test_cp_alndst: a1", i, a1.get(i), 123); 313 } 314 for (int i=0; i<ALIGN_OFF; i++) { 315 a1.set(i, 123); 316 } 317 test_vi(a2, -123, 123); 318 test_cp_alnsrc(a1, a2); 319 for (int i=0; i<ARRLEN-ALIGN_OFF; i++) { 320 errn += verify("test_cp_alnsrc: a1", i, a1.get(i), -123); 321 } 322 for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) { 323 errn += verify("test_cp_alnsrc: a1", i, a1.get(i), 123); 324 } 325 for (int i=0; i<ARRLEN; i++) { 326 a1.set(i, -1); 327 a2.set(i, -1); 328 } 329 test_2ci_aln(a1, a2); 330 for (int i=0; i<ALIGN_OFF; i++) { 331 errn += verify("test_2ci_aln: a1", i, a1.get(i), -1); 332 } 333 for (int i=ALIGN_OFF; i<ARRLEN; i++) { 334 errn += verify("test_2ci_aln: a1", i, a1.get(i), -123); 335 } 336 for (int i=0; i<ARRLEN-ALIGN_OFF; i++) { 337 errn += verify("test_2ci_aln: a2", i, a2.get(i), -103); 338 } 339 for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) { 340 errn += verify("test_2ci_aln: a2", i, a2.get(i), -1); 341 } 342 for (int i=0; i<ARRLEN; i++) { 343 a1.set(i, -1); 344 a2.set(i, -1); 345 } 346 test_2vi_aln(a1, a2, 123, 103); 347 for (int i=0; i<ARRLEN-ALIGN_OFF; i++) { 348 errn += verify("test_2vi_aln: a1", i, a1.get(i), 123); 349 } 350 for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) { 351 errn += verify("test_2vi_aln: a1", i, a1.get(i), -1); 352 } 353 for (int i=0; i<ALIGN_OFF; i++) { 354 errn += verify("test_2vi_aln: a2", i, a2.get(i), -1); 355 } 356 for (int i=ALIGN_OFF; i<ARRLEN; i++) { 357 errn += verify("test_2vi_aln: a2", i, a2.get(i), 103); 358 } 359 360 // Reset for 2 arrays with relative unaligned offset 361 for (int i=0; i<ARRLEN; i++) { 362 a1.set(i, -1); 363 a2.set(i, -1); 364 } 365 test_vi(a2, 123, -1); 366 test_cp_unalndst(a1, a2); 367 for (int i=0; i<UNALIGN_OFF; i++) { 368 errn += verify("test_cp_unalndst: a1", i, a1.get(i), -1); 369 } 370 for (int i=UNALIGN_OFF; i<ARRLEN; i++) { 371 errn += verify("test_cp_unalndst: a1", i, a1.get(i), 123); 372 } 373 test_vi(a2, -123, 123); 374 test_cp_unalnsrc(a1, a2); 375 for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) { 376 errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), -123); 377 } 378 for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) { 379 errn += verify("test_cp_unalnsrc: a1", i, a1.get(i), 123); 380 } 381 for (int i=0; i<ARRLEN; i++) { 382 a1.set(i, -1); 383 a2.set(i, -1); 384 } 385 test_2ci_unaln(a1, a2); 386 for (int i=0; i<UNALIGN_OFF; i++) { 387 errn += verify("test_2ci_unaln: a1", i, a1.get(i), -1); 388 } 389 for (int i=UNALIGN_OFF; i<ARRLEN; i++) { 390 errn += verify("test_2ci_unaln: a1", i, a1.get(i), -123); 391 } 392 for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) { 393 errn += verify("test_2ci_unaln: a2", i, a2.get(i), -103); 394 } 395 for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) { 396 errn += verify("test_2ci_unaln: a2", i, a2.get(i), -1); 397 } 398 for (int i=0; i<ARRLEN; i++) { 399 a1.set(i, -1); 400 a2.set(i, -1); 401 } 402 test_2vi_unaln(a1, a2, 123, 103); 403 for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) { 404 errn += verify("test_2vi_unaln: a1", i, a1.get(i), 123); 405 } 406 for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) { 407 errn += verify("test_2vi_unaln: a1", i, a1.get(i), -1); 408 } 409 for (int i=0; i<UNALIGN_OFF; i++) { 410 errn += verify("test_2vi_unaln: a2", i, a2.get(i), -1); 411 } 412 for (int i=UNALIGN_OFF; i<ARRLEN; i++) { 413 errn += verify("test_2vi_unaln: a2", i, a2.get(i), 103); 414 } 415 416 // Reset for aligned overlap initialization 417 for (int i=0; i<ALIGN_OFF; i++) { 418 a1.set(i, i); 419 } 420 for (int i=ALIGN_OFF; i<ARRLEN; i++) { 421 a1.set(i, -1); 422 } 423 test_cp_alndst(a1, a1); 424 for (int i=0; i<ARRLEN; i++) { 425 int v = i%ALIGN_OFF; 426 errn += verify("test_cp_alndst_overlap: a1", i, a1.get(i), v); 427 } 428 for (int i=0; i<ALIGN_OFF; i++) { 429 a1.set((i+ALIGN_OFF), -1); 430 } 431 test_cp_alnsrc(a1, a1); 432 for (int i=0; i<ALIGN_OFF; i++) { 433 errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), -1); 434 } 435 for (int i=ALIGN_OFF; i<ARRLEN; i++) { 436 int v = i%ALIGN_OFF; 437 errn += verify("test_cp_alnsrc_overlap: a1", i, a1.get(i), v); 438 } 439 for (int i=0; i<ARRLEN; i++) { 440 a1.set(i, -1); 441 } 442 test_2ci_aln(a1, a1); 443 for (int i=0; i<ARRLEN-ALIGN_OFF; i++) { 444 errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -103); 445 } 446 for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) { 447 errn += verify("test_2ci_aln_overlap: a1", i, a1.get(i), -123); 448 } 449 for (int i=0; i<ARRLEN; i++) { 450 a1.set(i, -1); 451 } 452 test_2vi_aln(a1, a1, 123, 103); 453 for (int i=0; i<ARRLEN-ALIGN_OFF; i++) { 454 errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 123); 455 } 456 for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) { 457 errn += verify("test_2vi_aln_overlap: a1", i, a1.get(i), 103); 458 } 459 460 // Reset for unaligned overlap initialization 461 for (int i=0; i<UNALIGN_OFF; i++) { 462 a1.set(i, i); 463 } 464 for (int i=UNALIGN_OFF; i<ARRLEN; i++) { 465 a1.set(i, -1); 466 } 467 test_cp_unalndst(a1, a1); 468 for (int i=0; i<ARRLEN; i++) { 469 int v = i%UNALIGN_OFF; 470 errn += verify("test_cp_unalndst_overlap: a1", i, a1.get(i), v); 471 } 472 for (int i=0; i<UNALIGN_OFF; i++) { 473 a1.set((i+UNALIGN_OFF), -1); 474 } 475 test_cp_unalnsrc(a1, a1); 476 for (int i=0; i<UNALIGN_OFF; i++) { 477 errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), -1); 478 } 479 for (int i=UNALIGN_OFF; i<ARRLEN; i++) { 480 int v = i%UNALIGN_OFF; 481 errn += verify("test_cp_unalnsrc_overlap: a1", i, a1.get(i), v); 482 } 483 for (int i=0; i<ARRLEN; i++) { 484 a1.set(i, -1); 485 } 486 test_2ci_unaln(a1, a1); 487 for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) { 488 errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -103); 489 } 490 for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) { 491 errn += verify("test_2ci_unaln_overlap: a1", i, a1.get(i), -123); 492 } 493 for (int i=0; i<ARRLEN; i++) { 494 a1.set(i, -1); 495 } 496 test_2vi_unaln(a1, a1, 123, 103); 497 for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) { 498 errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 123); 499 } 500 for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) { 501 errn += verify("test_2vi_unaln_overlap: a1", i, a1.get(i), 103); 502 } 503 504 } 505 506 if (errn > 0 || test_only) 507 return errn; 508 509 // Initialize 510 for (int i=0; i<ARRLEN; i++) { 511 a1.set(i, -1); 512 a2.set(i, -1); 513 } 514 System.out.println("Time"); 515 long start, end; 516 start = System.currentTimeMillis(); 517 for (int i=0; i<ITERS; i++) { 518 test_ci(a1); 519 } 520 end = System.currentTimeMillis(); 521 System.out.println("test_ci: " + (end - start)); 522 start = System.currentTimeMillis(); 523 for (int i=0; i<ITERS; i++) { 524 test_vi(a2, 123, -1); 525 } 526 end = System.currentTimeMillis(); 527 System.out.println("test_vi: " + (end - start)); 528 start = System.currentTimeMillis(); 529 for (int i=0; i<ITERS; i++) { 530 test_cp(a1, a2); 531 } 532 end = System.currentTimeMillis(); 533 System.out.println("test_cp: " + (end - start)); 534 start = System.currentTimeMillis(); 535 for (int i=0; i<ITERS; i++) { 536 test_2ci(a1, a2); 537 } 538 end = System.currentTimeMillis(); 539 System.out.println("test_2ci: " + (end - start)); 540 start = System.currentTimeMillis(); 541 for (int i=0; i<ITERS; i++) { 542 test_2vi(a1, a2, 123, 103); 543 } 544 end = System.currentTimeMillis(); 545 System.out.println("test_2vi: " + (end - start)); 546 547 start = System.currentTimeMillis(); 548 for (int i=0; i<ITERS; i++) { 549 test_ci_neg(a1, 123); 550 } 551 end = System.currentTimeMillis(); 552 System.out.println("test_ci_neg: " + (end - start)); 553 start = System.currentTimeMillis(); 554 for (int i=0; i<ITERS; i++) { 555 test_vi_neg(a2, 123, 103); 556 } 557 end = System.currentTimeMillis(); 558 System.out.println("test_vi_neg: " + (end - start)); 559 start = System.currentTimeMillis(); 560 for (int i=0; i<ITERS; i++) { 561 test_cp_neg(a1, a2); 562 } 563 end = System.currentTimeMillis(); 564 System.out.println("test_cp_neg: " + (end - start)); 565 start = System.currentTimeMillis(); 566 for (int i=0; i<ITERS; i++) { 567 test_2ci_neg(a1, a2); 568 } 569 end = System.currentTimeMillis(); 570 System.out.println("test_2ci_neg: " + (end - start)); 571 start = System.currentTimeMillis(); 572 for (int i=0; i<ITERS; i++) { 573 test_2vi_neg(a1, a2, 123, 103); 574 } 575 end = System.currentTimeMillis(); 576 System.out.println("test_2vi_neg: " + (end - start)); 577 578 start = System.currentTimeMillis(); 579 for (int i=0; i<ITERS; i++) { 580 test_ci_oppos(a1, 123); 581 } 582 end = System.currentTimeMillis(); 583 System.out.println("test_ci_oppos: " + (end - start)); 584 start = System.currentTimeMillis(); 585 for (int i=0; i<ITERS; i++) { 586 test_vi_oppos(a2, 123, 103); 587 } 588 end = System.currentTimeMillis(); 589 System.out.println("test_vi_oppos: " + (end - start)); 590 start = System.currentTimeMillis(); 591 for (int i=0; i<ITERS; i++) { 592 test_cp_oppos(a1, a2); 593 } 594 end = System.currentTimeMillis(); 595 System.out.println("test_cp_oppos: " + (end - start)); 596 start = System.currentTimeMillis(); 597 for (int i=0; i<ITERS; i++) { 598 test_2ci_oppos(a1, a2); 599 } 600 end = System.currentTimeMillis(); 601 System.out.println("test_2ci_oppos: " + (end - start)); 602 start = System.currentTimeMillis(); 603 for (int i=0; i<ITERS; i++) { 604 test_2vi_oppos(a1, a2, 123, 103); 605 } 606 end = System.currentTimeMillis(); 607 System.out.println("test_2vi_oppos: " + (end - start)); 608 609 start = System.currentTimeMillis(); 610 for (int i=0; i<ITERS; i++) { 611 test_ci_off(a1, 123); 612 } 613 end = System.currentTimeMillis(); 614 System.out.println("test_ci_off: " + (end - start)); 615 start = System.currentTimeMillis(); 616 for (int i=0; i<ITERS; i++) { 617 test_vi_off(a2, 123, 103); 618 } 619 end = System.currentTimeMillis(); 620 System.out.println("test_vi_off: " + (end - start)); 621 start = System.currentTimeMillis(); 622 for (int i=0; i<ITERS; i++) { 623 test_cp_off(a1, a2); 624 } 625 end = System.currentTimeMillis(); 626 System.out.println("test_cp_off: " + (end - start)); 627 start = System.currentTimeMillis(); 628 for (int i=0; i<ITERS; i++) { 629 test_2ci_off(a1, a2); 630 } 631 end = System.currentTimeMillis(); 632 System.out.println("test_2ci_off: " + (end - start)); 633 start = System.currentTimeMillis(); 634 for (int i=0; i<ITERS; i++) { 635 test_2vi_off(a1, a2, 123, 103); 636 } 637 end = System.currentTimeMillis(); 638 System.out.println("test_2vi_off: " + (end - start)); 639 640 start = System.currentTimeMillis(); 641 for (int i=0; i<ITERS; i++) { 642 test_ci_inv(a1, OFFSET, 123); 643 } 644 end = System.currentTimeMillis(); 645 System.out.println("test_ci_inv: " + (end - start)); 646 start = System.currentTimeMillis(); 647 for (int i=0; i<ITERS; i++) { 648 test_vi_inv(a2, 123, OFFSET, 103); 649 } 650 end = System.currentTimeMillis(); 651 System.out.println("test_vi_inv: " + (end - start)); 652 start = System.currentTimeMillis(); 653 for (int i=0; i<ITERS; i++) { 654 test_cp_inv(a1, a2, OFFSET); 655 } 656 end = System.currentTimeMillis(); 657 System.out.println("test_cp_inv: " + (end - start)); 658 start = System.currentTimeMillis(); 659 for (int i=0; i<ITERS; i++) { 660 test_2ci_inv(a1, a2, OFFSET); 661 } 662 end = System.currentTimeMillis(); 663 System.out.println("test_2ci_inv: " + (end - start)); 664 start = System.currentTimeMillis(); 665 for (int i=0; i<ITERS; i++) { 666 test_2vi_inv(a1, a2, 123, 103, OFFSET); 667 } 668 end = System.currentTimeMillis(); 669 System.out.println("test_2vi_inv: " + (end - start)); 670 671 start = System.currentTimeMillis(); 672 for (int i=0; i<ITERS; i++) { 673 test_ci_scl(a1, 123); 674 } 675 end = System.currentTimeMillis(); 676 System.out.println("test_ci_scl: " + (end - start)); 677 start = System.currentTimeMillis(); 678 for (int i=0; i<ITERS; i++) { 679 test_vi_scl(a2, 123, 103); 680 } 681 end = System.currentTimeMillis(); 682 System.out.println("test_vi_scl: " + (end - start)); 683 start = System.currentTimeMillis(); 684 for (int i=0; i<ITERS; i++) { 685 test_cp_scl(a1, a2); 686 } 687 end = System.currentTimeMillis(); 688 System.out.println("test_cp_scl: " + (end - start)); 689 start = System.currentTimeMillis(); 690 for (int i=0; i<ITERS; i++) { 691 test_2ci_scl(a1, a2); 692 } 693 end = System.currentTimeMillis(); 694 System.out.println("test_2ci_scl: " + (end - start)); 695 start = System.currentTimeMillis(); 696 for (int i=0; i<ITERS; i++) { 697 test_2vi_scl(a1, a2, 123, 103); 698 } 699 end = System.currentTimeMillis(); 700 System.out.println("test_2vi_scl: " + (end - start)); 701 702 start = System.currentTimeMillis(); 703 for (int i=0; i<ITERS; i++) { 704 test_cp_alndst(a1, a2); 705 } 706 end = System.currentTimeMillis(); 707 System.out.println("test_cp_alndst: " + (end - start)); 708 start = System.currentTimeMillis(); 709 for (int i=0; i<ITERS; i++) { 710 test_cp_alnsrc(a1, a2); 711 } 712 end = System.currentTimeMillis(); 713 System.out.println("test_cp_alnsrc: " + (end - start)); 714 start = System.currentTimeMillis(); 715 for (int i=0; i<ITERS; i++) { 716 test_2ci_aln(a1, a2); 717 } 718 end = System.currentTimeMillis(); 719 System.out.println("test_2ci_aln: " + (end - start)); 720 start = System.currentTimeMillis(); 721 for (int i=0; i<ITERS; i++) { 722 test_2vi_aln(a1, a2, 123, 103); 723 } 724 end = System.currentTimeMillis(); 725 System.out.println("test_2vi_aln: " + (end - start)); 726 727 start = System.currentTimeMillis(); 728 for (int i=0; i<ITERS; i++) { 729 test_cp_unalndst(a1, a2); 730 } 731 end = System.currentTimeMillis(); 732 System.out.println("test_cp_unalndst: " + (end - start)); 733 start = System.currentTimeMillis(); 734 for (int i=0; i<ITERS; i++) { 735 test_cp_unalnsrc(a1, a2); 736 } 737 end = System.currentTimeMillis(); 738 System.out.println("test_cp_unalnsrc: " + (end - start)); 739 start = System.currentTimeMillis(); 740 for (int i=0; i<ITERS; i++) { 741 test_2ci_unaln(a1, a2); 742 } 743 end = System.currentTimeMillis(); 744 System.out.println("test_2ci_unaln: " + (end - start)); 745 start = System.currentTimeMillis(); 746 for (int i=0; i<ITERS; i++) { 747 test_2vi_unaln(a1, a2, 123, 103); 748 } 749 end = System.currentTimeMillis(); 750 System.out.println("test_2vi_unaln: " + (end - start)); 751 752 return errn; 753 } 754 755 static void test_ci(AtomicIntegerArray a) { 756 for (int i = 0; i < ARRLEN; i+=1) { 757 a.set(i, -123); 758 } 759 } 760 static void test_vi(AtomicIntegerArray a, int b, int old) { 761 for (int i = 0; i < ARRLEN; i+=1) { 762 a.set(i, b); 763 } 764 } 765 static void test_cp(AtomicIntegerArray a, AtomicIntegerArray b) { 766 for (int i = 0; i < ARRLEN; i+=1) { 767 a.set(i, b.get(i)); 768 } 769 } 770 static void test_2ci(AtomicIntegerArray a, AtomicIntegerArray b) { 771 for (int i = 0; i < ARRLEN; i+=1) { 772 a.set(i, -123); 773 b.set(i, -103); 774 } 775 } 776 static void test_2vi(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 777 for (int i = 0; i < ARRLEN; i+=1) { 778 a.set(i, c); 779 b.set(i, d); 780 } 781 } 782 static void test_ci_neg(AtomicIntegerArray a, int old) { 783 for (int i = ARRLEN-1; i >= 0; i-=1) { 784 a.set(i,-123); 785 } 786 } 787 static void test_vi_neg(AtomicIntegerArray a, int b, int old) { 788 for (int i = ARRLEN-1; i >= 0; i-=1) { 789 a.set(i, b); 790 } 791 } 792 static void test_cp_neg(AtomicIntegerArray a, AtomicIntegerArray b) { 793 for (int i = ARRLEN-1; i >= 0; i-=1) { 794 a.set(i, b.get(i)); 795 } 796 } 797 static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) { 798 for (int i = ARRLEN-1; i >= 0; i-=1) { 799 a.set(i, -123); 800 b.set(i, -103); 801 } 802 } 803 static void test_2vi_neg(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 804 for (int i = ARRLEN-1; i >= 0; i-=1) { 805 a.set(i, c); 806 b.set(i, d); 807 } 808 } 809 static void test_ci_oppos(AtomicIntegerArray a, int old) { 810 int limit = ARRLEN-1; 811 for (int i = 0; i < ARRLEN; i+=1) { 812 a.set((limit-i), -123); 813 } 814 } 815 static void test_vi_oppos(AtomicIntegerArray a, int b, int old) { 816 int limit = ARRLEN-1; 817 for (int i = limit; i >= 0; i-=1) { 818 a.set((limit-i), b); 819 } 820 } 821 static void test_cp_oppos(AtomicIntegerArray a, AtomicIntegerArray b) { 822 int limit = ARRLEN-1; 823 for (int i = 0; i < ARRLEN; i+=1) { 824 a.set(i, b.get(limit-i)); 825 } 826 } 827 static void test_2ci_oppos(AtomicIntegerArray a, AtomicIntegerArray b) { 828 int limit = ARRLEN-1; 829 for (int i = 0; i < ARRLEN; i+=1) { 830 a.set((limit-i), -123); 831 b.set(i, -103); 832 } 833 } 834 static void test_2vi_oppos(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 835 int limit = ARRLEN-1; 836 for (int i = limit; i >= 0; i-=1) { 837 a.set(i, c); 838 b.set((limit-i), d); 839 } 840 } 841 static void test_ci_off(AtomicIntegerArray a, int old) { 842 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { 843 a.set((i+OFFSET), -123); 844 } 845 } 846 static void test_vi_off(AtomicIntegerArray a, int b, int old) { 847 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { 848 a.set((i+OFFSET), b); 849 } 850 } 851 static void test_cp_off(AtomicIntegerArray a, AtomicIntegerArray b) { 852 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { 853 a.set((i+OFFSET), b.get(i+OFFSET)); 854 } 855 } 856 static void test_2ci_off(AtomicIntegerArray a, AtomicIntegerArray b) { 857 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { 858 a.set((i+OFFSET), -123); 859 b.set((i+OFFSET), -103); 860 } 861 } 862 static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 863 for (int i = 0; i < ARRLEN-OFFSET; i+=1) { 864 a.set((i+OFFSET), c); 865 b.set((i+OFFSET), d); 866 } 867 } 868 static void test_ci_inv(AtomicIntegerArray a, int k, int old) { 869 for (int i = 0; i < ARRLEN-k; i+=1) { 870 a.set((i+k),-123); 871 } 872 } 873 static void test_vi_inv(AtomicIntegerArray a, int b, int k, int old) { 874 for (int i = 0; i < ARRLEN-k; i+=1) { 875 a.set((i+k), b); 876 } 877 } 878 static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) { 879 for (int i = 0; i < ARRLEN-k; i+=1) { 880 a.set((i+k), b.get(i+k)); 881 } 882 } 883 static void test_2ci_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) { 884 for (int i = 0; i < ARRLEN-k; i+=1) { 885 a.set((i+k), -123); 886 b.set((i+k), -103); 887 } 888 } 889 static void test_2vi_inv(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d, int k) { 890 for (int i = 0; i < ARRLEN-k; i+=1) { 891 a.set((i+k), c); 892 b.set((i+k), d); 893 } 894 } 895 static void test_ci_scl(AtomicIntegerArray a, int old) { 896 for (int i = 0; i*SCALE < ARRLEN; i+=1) { 897 a.set((i*SCALE), -123); 898 } 899 } 900 static void test_vi_scl(AtomicIntegerArray a, int b, int old) { 901 for (int i = 0; i*SCALE < ARRLEN; i+=1) { 902 a.set((i*SCALE), b); 903 } 904 } 905 static void test_cp_scl(AtomicIntegerArray a, AtomicIntegerArray b) { 906 for (int i = 0; i*SCALE < ARRLEN; i+=1) { 907 a.set((i*SCALE), b.get(i*SCALE)); 908 } 909 } 910 static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) { 911 for (int i = 0; i*SCALE < ARRLEN; i+=1) { 912 a.set((i*SCALE), -123); 913 b.set((i*SCALE), -103); 914 } 915 } 916 static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 917 for (int i = 0; i*SCALE < ARRLEN; i+=1) { 918 a.set((i*SCALE), c); 919 b.set((i*SCALE), d); 920 } 921 } 922 static void test_cp_alndst(AtomicIntegerArray a, AtomicIntegerArray b) { 923 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { 924 a.set((i+ALIGN_OFF), b.get(i)); 925 } 926 } 927 static void test_cp_alnsrc(AtomicIntegerArray a, AtomicIntegerArray b) { 928 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { 929 a.set(i, b.get(i+ALIGN_OFF)); 930 } 931 } 932 static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) { 933 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { 934 a.set((i+ALIGN_OFF), -123); 935 b.set(i, -103); 936 } 937 } 938 static void test_2vi_aln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 939 for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) { 940 a.set(i, c); 941 b.set((i+ALIGN_OFF), d); 942 } 943 } 944 static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) { 945 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { 946 a.set((i+UNALIGN_OFF), b.get(i)); 947 } 948 } 949 static void test_cp_unalnsrc(AtomicIntegerArray a, AtomicIntegerArray b) { 950 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { 951 a.set(i, b.get(i+UNALIGN_OFF)); 952 } 953 } 954 static void test_2ci_unaln(AtomicIntegerArray a, AtomicIntegerArray b) { 955 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { 956 a.set((i+UNALIGN_OFF), -123); 957 b.set(i, -103); 958 } 959 } 960 static void test_2vi_unaln(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) { 961 for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) { 962 a.set(i, c); 963 b.set((i+UNALIGN_OFF), d); 964 } 965 } 966 967 static int verify(String text, int i, int elem, int val) { 968 if (elem != val) { 969 System.err.println(text + "[" + i + "] = " + elem + " != " + val); 970 return 1; 971 } 972 return 0; 973 } 974} 975