1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
/*
* Copyright (c) 2018, 2020, Red Hat, Inc. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* common code to run and validate tests of code generation for
* volatile ops on AArch64
*
* incoming args are <testclass> <testtype>
*
* where <testclass> in {TestVolatileLoad,
* TestVolatileStore,
* TestUnsafeVolatileLoad,
* TestUnsafeVolatileStore,
* TestUnsafeVolatileCAS,
* TestUnsafeVolatileWeakCAS,
* TestUnsafeVolatileCAE,
* TestUnsafeVolatileGAS}
* and <testtype> in {G1,
* Serial,
* Parallel,
* Shenandoah}
*/
package compiler.c2.aarch64;
import java.util.List;
import java.util.ListIterator;
import java.util.Iterator;
import java.util.regex.Pattern;
import java.io.*;
import jdk.test.lib.Asserts;
import jdk.test.lib.compiler.InMemoryJavaCompiler;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.whitebox.WhiteBox;
// runner class that spawns a new JVM to exercises a combination of
// volatile MemOp and GC. The ops are compiled with the dmb -->
// ldar/stlr transforms either enabled or disabled. this runner parses
// the PrintOptoAssembly output checking that the generated code is
// correct.
public class TestVolatiles {
public void runtest(String classname, String testType) throws Throwable {
// n.b. clients omit the package name for the class
String fullclassname = "compiler.c2.aarch64." + classname;
// build up a command line for the spawned JVM
String[] procArgs;
int argcount;
// add one or two extra arguments according to test type
// i.e. GC type plus GC conifg
switch(testType) {
case "G1":
argcount = 9;
procArgs = new String[argcount];
procArgs[argcount - 2] = "-XX:+UseG1GC";
break;
case "Parallel":
argcount = 9;
procArgs = new String[argcount];
procArgs[argcount - 2] = "-XX:+UseParallelGC";
break;
case "Serial":
argcount = 9;
procArgs = new String[argcount];
procArgs[argcount - 2] = "-XX:+UseSerialGC";
break;
case "Shenandoah":
argcount = 10;
procArgs = new String[argcount];
procArgs[argcount - 3] = "-XX:+UnlockExperimentalVMOptions";
procArgs[argcount - 2] = "-XX:+UseShenandoahGC";
break;
default:
throw new RuntimeException("unexpected test type " + testType);
}
// fill in arguments common to all cases
// the first round of test enables transform of barriers to
// use acquiring loads and releasing stores by setting arg
// zero appropriately. this arg is reset in the second run to
// disable the transform.
procArgs[0] = "-XX:+UseCompressedOops";
procArgs[1] = "-XX:-BackgroundCompilation";
procArgs[2] = "-XX:-TieredCompilation";
procArgs[3] = "-XX:+PrintOptoAssembly";
procArgs[4] = "-XX:CompileCommand=compileonly," + fullclassname + "::" + "test*";
procArgs[5] = "--add-exports";
procArgs[6] = "java.base/jdk.internal.misc=ALL-UNNAMED";
procArgs[argcount - 1] = fullclassname;
runtest(classname, testType, true, procArgs);
if (!classname.equals("TestUnsafeVolatileGAA")) {
procArgs[0] = "-XX:-UseCompressedOops";
runtest(classname, testType, false, procArgs);
}
}
public void runtest(String classname, String testType, boolean useCompressedOops, String[] procArgs) throws Throwable {
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(procArgs);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.stderrShouldBeEmptyIgnoreVMWarnings();
output.stdoutShouldNotBeEmpty();
output.shouldHaveExitValue(0);
// check the output for the correct asm sequence as
// appropriate to test class, test type and whether transform
// was applied
checkoutput(output, classname, testType, useCompressedOops);
}
// skip through output returning a line containing the desireed
// substring or null
private String skipTo(Iterator<String> iter, String substring)
{
while (iter.hasNext()) {
String nextLine = iter.next();
if (nextLine.matches(".*" + substring + ".*")) {
return nextLine;
}
}
return null;
}
// locate the start of compiler output for the desired method and
// then check that each expected instruction occurs in the output
// in the order supplied. throw an excpetion if not found.
// n.b. the spawned JVM's output is included in the exception
// message to make it easeir to identify what is missing.
private boolean checkCompile(Iterator<String> iter, String methodname, String[] expected, OutputAnalyzer output, boolean do_throw)
{
// trace call to allow eyeball check of what we are checking against
System.out.println("checkCompile(" + methodname + ",");
String sepr = " { ";
for (String s : expected) {
System.out.print(sepr);
System.out.print(s);
sepr = ",\n ";
}
System.out.println(" })");
// look for the start of an opto assembly print block
String match = skipTo(iter, Pattern.quote("{method}"));
if (match == null) {
if (do_throw) {
throw new RuntimeException("Missing compiler output for " + methodname + "!\n\n" + output.getOutput());
}
return false;
}
// check the compiled method name is right
match = skipTo(iter, Pattern.quote("- name:"));
if (match == null) {
if (do_throw) {
throw new RuntimeException("Missing compiled method name!\n\n" + output.getOutput());
}
return false;
}
if (!match.contains(methodname)) {
if (do_throw) {
throw new RuntimeException("Wrong method " + match + "!\n -- expecting " + methodname + "\n\n" + output.getOutput());
}
return false;
}
// make sure we can match each expected term in order
for (String s : expected) {
match = skipTo(iter, s);
if (match == null) {
if (do_throw) {
throw new RuntimeException("Missing expected output " + s + "!\n\n" + output.getOutput());
}
return false;
}
}
return true;
}
// check for expected asm output from a volatile load
private void checkload(OutputAnalyzer output, String testType, boolean useCompressedOops) throws Throwable
{
Iterator<String> iter = output.asLines().listIterator();
// we shoud see this same sequence for normal or unsafe volatile load
// for both int and Object fields
String[] matches;
matches = new String[] {
"ldarw",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, "testInt", matches, output, true);
matches = new String[] {
useCompressedOops ? "ldarw?" : "ldar",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, "testObj", matches, output, true);
}
// check for expected asm output from a volatile store
private void checkstore(OutputAnalyzer output, String testType, boolean useCompressedOops) throws Throwable
{
Iterator<String> iter = output.asLines().listIterator();
String[] matches;
// non object stores are straightforward
// this is the sequence of instructions for all cases
matches = new String[] {
"membar_release \\(elided\\)",
"stlrw",
"membar_volatile \\(elided\\)",
"ret"
};
checkCompile(iter, "testInt", matches, output, true);
// object stores will be as above except for when the GC
// introduces barriers for card marking
switch (testType) {
default:
// this is the basic sequence of instructions
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "stlrw?" : "stlr",
"membar_volatile \\(elided\\)",
"ret"
};
break;
case "G1":
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "stlrw?" : "stlr",
"membar_volatile \\(elided\\)",
"ret"
};
break;
case "Shenandoah":
// Shenandoah generates normal object graphs for
// volatile stores
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "stlrw?" : "stlr",
"membar_volatile \\(elided\\)",
"ret"
};
break;
}
checkCompile(iter, "testObj", matches, output, true);
}
// check for expected asm output from a volatile cas
private void checkcas(OutputAnalyzer output, String testType, boolean useCompressedOops) throws Throwable
{
Iterator<String> iter = output.asLines().listIterator();
String[] matches;
String[][] tests = {
{ "testInt", "cmpxchgw" },
{ "testLong", "cmpxchg" },
{ "testByte", "cmpxchgb" },
{ "testShort", "cmpxchgs" },
};
for (String[] test : tests) {
// non object stores are straightforward
// this is the sequence of instructions for all cases
matches = new String[] {
"membar_release \\(elided\\)",
test[1] + "_acq",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, test[0], matches, output, true);
}
// object stores will be as above except for when the GC
// introduces barriers for card marking
switch (testType) {
default:
// this is the basic sequence of instructions
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq",
"strb",
"membar_acquire \\(elided\\)",
"ret"
};
break;
case "G1":
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq",
"membar_acquire \\(elided\\)",
"ret"
};
break;
case "Shenandoah":
// For volatile CAS, Shenanodoah generates normal
// graphs with a shenandoah-specific cmpxchg
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq_shenandoah" : "cmpxchg_acq_shenandoah",
"membar_acquire \\(elided\\)",
"ret"
};
break;
}
checkCompile(iter, "testObj", matches, output, true);
}
private void checkcae(OutputAnalyzer output, String testType, boolean useCompressedOops) throws Throwable
{
ListIterator<String> iter = output.asLines().listIterator();
String[] matches;
String[][] tests = {
{ "testInt", "cmpxchgw" },
{ "testLong", "cmpxchg" },
{ "testByte", "cmpxchgb" },
{ "testShort", "cmpxchgs" },
};
for (String[] test : tests) {
// non object stores are straightforward
// this is the sequence of instructions for all cases
matches = new String[] {
"membar_release \\(elided\\)",
test[1] + "_acq",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, test[0], matches, output, true);
}
// object stores will be as above except for when the GC
// introduces barriers for card marking
switch (testType) {
default:
// this is the basic sequence of instructions
matches = new String[] {
"membar_release \\(elided\\)",
"strb",
useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq",
"membar_acquire \\(elided\\)",
"ret"
};
// card marking store may be scheduled before or after
// the cmpxchg so try both sequences.
int idx = iter.nextIndex();
if (!checkCompile(iter, "testObj", matches, output, false)) {
iter = output.asLines().listIterator(idx);
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq",
"strb",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, "testObj", matches, output, true);
}
return;
case "G1":
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq",
"membar_acquire \\(elided\\)",
"ret"
};
break;
case "Shenandoah":
// For volatile CAS, Shenanodoah generates normal
// graphs with a shenandoah-specific cmpxchg
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "cmpxchgw?_acq_shenandoah" : "cmpxchg_acq_shenandoah",
"membar_acquire \\(elided\\)",
"ret"
};
break;
}
checkCompile(iter, "testObj", matches, output, true);
}
private void checkgas(OutputAnalyzer output, String testType, boolean useCompressedOops) throws Throwable
{
Iterator<String> iter = output.asLines().listIterator();
String[] matches;
String[][] tests = {
{ "testInt", "atomic_xchgw" },
{ "testLong", "atomic_xchg" },
};
for (String[] test : tests) {
// non object stores are straightforward
// this is the sequence of instructions for all cases
matches = new String[] {
"membar_release \\(elided\\)",
test[1] + "_acq",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, test[0], matches, output, true);
}
// object stores will be as above except for when the GC
// introduces barriers for card marking
switch (testType) {
default:
// this is the basic sequence of instructions
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "atomic_xchgw?_acq" : "atomic_xchg_acq",
"strb",
"membar_acquire \\(elided\\)",
"ret"
};
break;
case "G1":
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "atomic_xchgw?_acq" : "atomic_xchg_acq",
"membar_acquire \\(elided\\)",
"ret"
};
break;
case "Shenandoah":
matches = new String[] {
"membar_release \\(elided\\)",
useCompressedOops ? "atomic_xchgw?_acq" : "atomic_xchg_acq",
"membar_acquire \\(elided\\)",
"ret"
};
break;
}
checkCompile(iter, "testObj", matches, output, true);
}
private void checkgaa(OutputAnalyzer output, String testType) throws Throwable
{
Iterator<String> iter = output.asLines().listIterator();
String[] matches;
String[][] tests = {
{ "testInt", "get_and_addI" },
{ "testLong", "get_and_addL" },
};
for (String[] test : tests) {
// non object stores are straightforward
// this is the sequence of instructions for all cases
matches = new String[] {
"membar_release \\(elided\\)",
test[1] + "_acq",
"membar_acquire \\(elided\\)",
"ret"
};
checkCompile(iter, test[0], matches, output, true);
}
}
// perform a check appropriate to the classname
private void checkoutput(OutputAnalyzer output, String classname, String testType, boolean useCompressedOops) throws Throwable
{
// trace call to allow eyeball check of what is being checked
System.out.println("checkoutput(" +
classname + ", " +
testType + ")\n" +
output.getOutput());
switch (classname) {
case "TestVolatileLoad":
checkload(output, testType, useCompressedOops);
break;
case "TestVolatileStore":
checkstore(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileLoad":
checkload(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileStore":
checkstore(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileCAS":
case "TestUnsafeVolatileWeakCAS":
checkcas(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileCAE":
checkcae(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileGAS":
checkgas(output, testType, useCompressedOops);
break;
case "TestUnsafeVolatileGAA":
checkgaa(output, testType);
break;
}
}
}
|