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