test/tools/javac/lib/JavacTestingAbstractThreadedTest.java

changeset 1528
cbcd9b484759
parent 1520
5c956be64b9e
child 2525
2eb010b6cb22
equal deleted inserted replaced
1522:09f65aad4759 1528:cbcd9b484759
39 * The property can be provided by passing this option to jtreg: 39 * The property can be provided by passing this option to jtreg:
40 * -javaoption:-Dtest.concurrency=# 40 * -javaoption:-Dtest.concurrency=#
41 * 41 *
42 * If the property is not set the class will use a heuristic to determine the 42 * If the property is not set the class will use a heuristic to determine the
43 * maximum number of threads that can be fired to execute a given test. 43 * maximum number of threads that can be fired to execute a given test.
44 *
45 * This code will have to be revisited if jprt starts using concurrency for
46 * for running jtreg tests.
44 */ 47 */
45 public abstract class JavacTestingAbstractThreadedTest { 48 public abstract class JavacTestingAbstractThreadedTest {
49
50 protected static AtomicInteger numberOfThreads = new AtomicInteger();
46 51
47 protected static int getThreadPoolSize() { 52 protected static int getThreadPoolSize() {
48 Integer testConc = Integer.getInteger("test.concurrency"); 53 Integer testConc = Integer.getInteger("test.concurrency");
49 if (testConc != null) return testConc; 54 if (testConc != null) return testConc;
50 int cores = Runtime.getRuntime().availableProcessors(); 55 int cores = Runtime.getRuntime().availableProcessors();
51 return Math.max(2, Math.min(8, cores / 2)); 56 numberOfThreads.set(Math.max(2, Math.min(8, cores / 2)));
57 return numberOfThreads.get();
52 } 58 }
53 59
54 protected static void checkAfterExec() throws InterruptedException { 60 protected static void checkAfterExec() throws InterruptedException {
55 checkAfterExec(true); 61 checkAfterExec(true);
56 }; 62 };
80 String.format("%d errors found", errCount.get())); 86 String.format("%d errors found", errCount.get()));
81 } 87 }
82 } else if (printCheckCount) { 88 } else if (printCheckCount) {
83 outWriter.println("Total check executed: " + checkCount.get()); 89 outWriter.println("Total check executed: " + checkCount.get());
84 } 90 }
91 /*
92 * This output is for supporting debugging. It does not mean that a given
93 * test had executed that number of threads concurrently. The value printed
94 * here is the maximum possible amount.
95 */
85 closePrinters(); 96 closePrinters();
86 if (printAll) { 97 if (printAll) {
87 System.out.println(errSWriter.toString()); 98 System.out.println(errSWriter.toString());
88 System.out.println(outSWriter.toString()); 99 System.out.println(outSWriter.toString());
89 } 100 }
101 System.out.println("Total number of threads in thread pool: " +
102 numberOfThreads.get());
90 } 103 }
91 104
92 protected static void closePrinters() { 105 protected static void closePrinters() {
93 errWriter.close(); 106 errWriter.close();
94 outWriter.close(); 107 outWriter.close();

mercurial