Mercurial > hg > truffle
comparison graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java @ 20014:dab7f071220a
Wait until all classes are loaded before compiling in multithreaded CTW
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 23 Mar 2015 12:21:25 -0700 |
parents | 83539d28f95c |
children | 926850b25c65 |
comparison
equal
deleted
inserted
replaced
20013:8ea3dde07ff7 | 20014:dab7f071220a |
---|---|
158 private AtomicLong memoryUsed = new AtomicLong(); | 158 private AtomicLong memoryUsed = new AtomicLong(); |
159 | 159 |
160 private boolean verbose; | 160 private boolean verbose; |
161 private final Config config; | 161 private final Config config; |
162 | 162 |
163 /** | |
164 * Signal that the threads should start compiling in multithreaded mode. | |
165 */ | |
166 private boolean running; | |
167 | |
163 private ThreadPoolExecutor threadPool; | 168 private ThreadPoolExecutor threadPool; |
164 | 169 |
165 /** | 170 /** |
166 * Creates a compile-the-world instance. | 171 * Creates a compile-the-world instance. |
167 * | 172 * |
325 jarFile.close(); | 330 jarFile.close(); |
326 } | 331 } |
327 } | 332 } |
328 | 333 |
329 if (threadPool != null) { | 334 if (threadPool != null) { |
335 startThreads(); | |
330 while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { | 336 while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { |
331 System.out.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); | 337 System.out.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); |
332 try { | 338 try { |
333 threadPool.awaitTermination(15, TimeUnit.SECONDS); | 339 threadPool.awaitTermination(15, TimeUnit.SECONDS); |
334 } catch (InterruptedException e) { | 340 } catch (InterruptedException e) { |
340 long elapsedTime = System.currentTimeMillis() - start; | 346 long elapsedTime = System.currentTimeMillis() - start; |
341 | 347 |
342 println(); | 348 println(); |
343 println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, | 349 println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, |
344 compileTime.get(), memoryUsed.get()); | 350 compileTime.get(), memoryUsed.get()); |
351 } | |
352 | |
353 private synchronized void startThreads() { | |
354 running = true; | |
355 // Wake up any waiting threads | |
356 notifyAll(); | |
357 } | |
358 | |
359 private synchronized void waitToRun() { | |
360 while (!running) { | |
361 try { | |
362 wait(); | |
363 } catch (InterruptedException e) { | |
364 } | |
365 } | |
345 } | 366 } |
346 | 367 |
347 class CTWCompilationTask extends CompilationTask { | 368 class CTWCompilationTask extends CompilationTask { |
348 | 369 |
349 CTWCompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method) { | 370 CTWCompilationTask(HotSpotBackend backend, HotSpotResolvedJavaMethod method) { |
362 | 383 |
363 private void compileMethod(HotSpotResolvedJavaMethod method) { | 384 private void compileMethod(HotSpotResolvedJavaMethod method) { |
364 if (threadPool != null) { | 385 if (threadPool != null) { |
365 threadPool.submit(new Runnable() { | 386 threadPool.submit(new Runnable() { |
366 public void run() { | 387 public void run() { |
388 waitToRun(); | |
367 try (OverrideScope s = config.apply()) { | 389 try (OverrideScope s = config.apply()) { |
368 compileMethod(method, classFileCounter); | 390 compileMethod(method, classFileCounter); |
369 } | 391 } |
370 } | 392 } |
371 }); | 393 }); |