42 *
43 * @param paths paths to jar/zip, dir contains classes, or to .lst file
44 * contains list of classes to compile
45 */
46 public static void main(String[] paths) {
47 if (paths.length == 0) {
48 throw new IllegalArgumentException("Expect a path to a compile target.");
49 }
50 String logfile = Utils.LOG_FILE;
51 PrintStream os = null;
52 if (logfile != null) {
53 try {
54 os = new PrintStream(Files.newOutputStream(Paths.get(logfile)));
55 } catch (IOException io) {
56 }
57 }
58 if (os != null) {
59 OUT = os;
60 }
61
62 try {
63 try {
64 if (ManagementFactory.getCompilationMXBean() == null) {
65 throw new RuntimeException(
66 "CTW can not work in interpreted mode");
67 }
68 } catch (java.lang.NoClassDefFoundError e) {
69 // compact1, compact2 support
70 }
71 ExecutorService executor = createExecutor();
72 long start = System.currentTimeMillis();
73 try {
74 String path;
75 for (int i = 0, n = paths.length; i < n
76 && !PathHandler.isFinished(); ++i) {
77 path = paths[i];
78 PathHandler.create(path, executor).process();
79 }
80 } finally {
81 await(executor);
82 }
83 CompileTheWorld.OUT.printf("Done (%d classes, %d methods, %d ms)%n",
84 PathHandler.getClassCount(),
85 Compiler.getMethodCount(),
86 System.currentTimeMillis() - start);
87 } finally {
88 if (os != null) {
89 os.close();
90 }
91 }
92 }
93
94 private static ExecutorService createExecutor() {
95 final int threadsCount = Math.min(
96 Runtime.getRuntime().availableProcessors(),
97 Utils.CI_COMPILER_COUNT);
98 ExecutorService result;
99 if (threadsCount > 1) {
100 result = new ThreadPoolExecutor(threadsCount, threadsCount,
101 /* keepAliveTime */ 0L, TimeUnit.MILLISECONDS,
102 new ArrayBlockingQueue<>(threadsCount),
103 new ThreadPoolExecutor.CallerRunsPolicy());
104 } else {
105 result = new CurrentThreadExecutor();
106 }
107 return result;
108 }
109
110 private static void await(ExecutorService executor) {
|
42 *
43 * @param paths paths to jar/zip, dir contains classes, or to .lst file
44 * contains list of classes to compile
45 */
46 public static void main(String[] paths) {
47 if (paths.length == 0) {
48 throw new IllegalArgumentException("Expect a path to a compile target.");
49 }
50 String logfile = Utils.LOG_FILE;
51 PrintStream os = null;
52 if (logfile != null) {
53 try {
54 os = new PrintStream(Files.newOutputStream(Paths.get(logfile)));
55 } catch (IOException io) {
56 }
57 }
58 if (os != null) {
59 OUT = os;
60 }
61
62 boolean passed = false;
63
64 try {
65 try {
66 if (ManagementFactory.getCompilationMXBean() == null) {
67 throw new RuntimeException(
68 "CTW can not work in interpreted mode");
69 }
70 } catch (java.lang.NoClassDefFoundError e) {
71 // compact1, compact2 support
72 }
73 ExecutorService executor = createExecutor();
74 long start = System.currentTimeMillis();
75 try {
76 String path;
77 for (int i = 0, n = paths.length; i < n
78 && !PathHandler.isFinished(); ++i) {
79 path = paths[i];
80 PathHandler.create(path, executor).process();
81 }
82 } finally {
83 await(executor);
84 }
85 CompileTheWorld.OUT.printf("Done (%d classes, %d methods, %d ms)%n",
86 PathHandler.getClassCount(),
87 Compiler.getMethodCount(),
88 System.currentTimeMillis() - start);
89 passed = true;
90 } finally {
91 // <clinit> might have started new threads
92 System.exit(passed ? 0 : 1);
93 }
94 }
95
96 private static ExecutorService createExecutor() {
97 final int threadsCount = Math.min(
98 Runtime.getRuntime().availableProcessors(),
99 Utils.CI_COMPILER_COUNT);
100 ExecutorService result;
101 if (threadsCount > 1) {
102 result = new ThreadPoolExecutor(threadsCount, threadsCount,
103 /* keepAliveTime */ 0L, TimeUnit.MILLISECONDS,
104 new ArrayBlockingQueue<>(threadsCount),
105 new ThreadPoolExecutor.CallerRunsPolicy());
106 } else {
107 result = new CurrentThreadExecutor();
108 }
109 return result;
110 }
111
112 private static void await(ExecutorService executor) {
|