# HG changeset patch # User Doug Simon # Date 1333443503 -7200 # Node ID c49f9f0b9aadf8fe3157aec9dad68c73b0d0de5d # Parent 9b8c0d1bc2dd6e2faf66fcebc1b4b56821e10a6b# Parent d5cf399e66374717d9bda8680c31b174a9867d30 Merge. diff -r 9b8c0d1bc2dd -r c49f9f0b9aad graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Tue Apr 03 10:56:40 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Tue Apr 03 10:58:23 2012 +0200 @@ -84,6 +84,7 @@ public static int MatureExecutionsTypeProfile = 1; // comilation queue + public static int TimedBootstrap = -1; public static boolean PriorityCompileQueue = ____; public static int SlowQueueCutoff = 100000; public static boolean SlowCompileThreads = ____; diff -r 9b8c0d1bc2dd -r c49f9f0b9aad graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Apr 03 10:56:40 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Tue Apr 03 10:58:23 2012 +0200 @@ -36,6 +36,15 @@ public final class CompilationTask implements Runnable, Comparable { + + public static final ThreadLocal withinEnqueue = new ThreadLocal() { + @Override + protected Boolean initialValue() { + return Boolean.valueOf(Thread.currentThread() instanceof CompilerThread); + } + }; + + private volatile boolean cancelled; private final Compiler compiler; @@ -73,16 +82,28 @@ // private static PrintStream out = System.out; public void run() { - if (cancelled) { - return; + withinEnqueue.set(Boolean.FALSE); + try { + if (cancelled) { + return; + } + if (GraalOptions.DynamicCompilePriority) { + int threadPriority = priority < GraalOptions.SlowQueueCutoff ? Thread.NORM_PRIORITY : Thread.MIN_PRIORITY; + if (Thread.currentThread().getPriority() != threadPriority) { + // out.print(threadPriority); + Thread.currentThread().setPriority(threadPriority); + } + } + runCompilation(); + if (method.currentTask() == this) { + method.setCurrentTask(null); + } + } finally { + withinEnqueue.set(Boolean.TRUE); } - if (GraalOptions.DynamicCompilePriority) { - int threadPriority = priority < GraalOptions.SlowQueueCutoff ? Thread.NORM_PRIORITY : Thread.MIN_PRIORITY; - if (Thread.currentThread().getPriority() != threadPriority) { -// out.print(threadPriority); - Thread.currentThread().setPriority(threadPriority); - } - } + } + + public void runCompilation() { CiCompilationStatistics stats = CiCompilationStatistics.create(method); try { final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed(); @@ -121,9 +142,6 @@ } } stats.finish(method); - if (method.currentTask() == this) { - method.setCurrentTask(null); - } } @Override diff -r 9b8c0d1bc2dd -r c49f9f0b9aad graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Tue Apr 03 10:56:40 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Tue Apr 03 10:58:23 2012 +0200 @@ -113,21 +113,11 @@ } // Create compilation queue. - final BlockingQueue queue; - if (GraalOptions.PriorityCompileQueue) { - queue = new PriorityBlockingQueue<>(); - } else { - queue = new LinkedBlockingQueue<>(); - } + BlockingQueue queue = GraalOptions.PriorityCompileQueue ? new PriorityBlockingQueue() : new LinkedBlockingQueue(); compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, queue, CompilerThread.FACTORY); if (GraalOptions.SlowCompileThreads) { - final BlockingQueue slowQueue; - if (GraalOptions.PriorityCompileQueue) { - slowQueue = new PriorityBlockingQueue<>(); - } else { - slowQueue = new LinkedBlockingQueue<>(); - } + BlockingQueue slowQueue = GraalOptions.PriorityCompileQueue ? new PriorityBlockingQueue() : new LinkedBlockingQueue(); slowCompileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, slowQueue, CompilerThread.LOW_PRIORITY_FACTORY); } @@ -171,23 +161,43 @@ TTY.flush(); long startTime = System.currentTimeMillis(); - // Initialize compile queue with a selected set of methods. - Class objectKlass = Object.class; - enqueue(getClass().getDeclaredMethod("compileWarmup")); - enqueue(objectKlass.getDeclaredMethod("equals", Object.class)); - enqueue(objectKlass.getDeclaredMethod("toString")); + boolean firstRun = true; + do { + // Initialize compile queue with a selected set of methods. + Class objectKlass = Object.class; + if (firstRun) { + enqueue(getClass().getDeclaredMethod("compileWarmup")); + enqueue(objectKlass.getDeclaredMethod("equals", Object.class)); + enqueue(objectKlass.getDeclaredMethod("toString")); + firstRun = false; + } else { + for (int i = 0; i < 100; i++) { + enqueue(getClass().getDeclaredMethod("bootstrap")); + } + } - // Compile until the queue is empty. - int z = 0; - while (compileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount()) || ( - slowCompileQueue != null && slowCompileQueue.getCompletedTaskCount() < Math.max(3, slowCompileQueue.getTaskCount()))) { - Thread.sleep(100); - while (z < compileQueue.getCompletedTaskCount() / 100) { - ++z; - TTY.print("."); - TTY.flush(); + // Compile until the queue is empty. + int z = 0; + if (slowCompileQueue == null) { + while (compileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount())) { + Thread.sleep(100); + while (z < compileQueue.getCompletedTaskCount() / 100) { + ++z; + TTY.print("."); + TTY.flush(); + } + } + } else { + while (compileQueue.getCompletedTaskCount() + slowCompileQueue.getCompletedTaskCount() < Math.max(3, compileQueue.getTaskCount() + slowCompileQueue.getTaskCount())) { + Thread.sleep(100); + while (z < (compileQueue.getCompletedTaskCount() + slowCompileQueue.getCompletedTaskCount()) / 100) { + ++z; + TTY.print("."); + TTY.flush(); + } + } } - } + } while ((System.currentTimeMillis() - startTime) <= GraalOptions.TimedBootstrap); CiCompilationStatistics.clear("bootstrap"); TTY.println(" in %d ms", System.currentTimeMillis() - startTime); @@ -306,46 +316,49 @@ @Override public boolean compileMethod(final HotSpotMethodResolved method, final int entryBCI, boolean blocking, int priority) throws Throwable { - if (Thread.currentThread() instanceof CompilerThread) { - if (method.holder().name().contains("java/util/concurrent")) { - // This is required to avoid deadlocking a compiler thread. The issue is that a - // java.util.concurrent.BlockingQueue is used to implement the compilation worker - // queues. If a compiler thread triggers a compilation, then it may be blocked trying - // to add something to its own queue. - return false; - } - } - - CompilationTask current = method.currentTask(); - if (current != null) { - if (GraalOptions.PriorityCompileQueue) { - // normally compilation tasks will only be re-queued when they get a priority boost, so cancel the old task and add a new one - current.cancel(); - } else { - // without a prioritizing compile queue it makes no sense to re-queue the compilation task - return true; - } + if (CompilationTask.withinEnqueue.get()) { + // This is required to avoid deadlocking a compiler thread. The issue is that a + // java.util.concurrent.BlockingQueue is used to implement the compilation worker + // queues. If a compiler thread triggers a compilation, then it may be blocked trying + // to add something to its own queue. + return false; } + CompilationTask.withinEnqueue.set(Boolean.TRUE); - final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method); - int id = compileTaskIds.incrementAndGet(); - CompilationTask task = CompilationTask.create(compiler, createHotSpotSpecificPhasePlan(optimisticOpts), optimisticOpts, method, id, priority); - if (blocking) { - task.run(); - } else { - try { - method.setCurrentTask(task); - if (GraalOptions.SlowCompileThreads && priority > GraalOptions.SlowQueueCutoff) { - slowCompileQueue.execute(task); + try { + CompilationTask current = method.currentTask(); + if (!blocking && current != null) { + if (GraalOptions.PriorityCompileQueue) { + // normally compilation tasks will only be re-queued when they get a priority boost, so cancel the old task and add a new one + current.cancel(); } else { - compileQueue.execute(task); + // without a prioritizing compile queue it makes no sense to re-queue the compilation task + return true; } - } catch (RejectedExecutionException e) { - // The compile queue was already shut down. - return false; } + + final OptimisticOptimizations optimisticOpts = new OptimisticOptimizations(method); + int id = compileTaskIds.incrementAndGet(); + CompilationTask task = CompilationTask.create(compiler, createHotSpotSpecificPhasePlan(optimisticOpts), optimisticOpts, method, id, priority); + if (blocking) { + task.runCompilation(); + } else { + try { + method.setCurrentTask(task); + if (GraalOptions.SlowCompileThreads && priority > GraalOptions.SlowQueueCutoff) { + slowCompileQueue.execute(task); + } else { + compileQueue.execute(task); + } + } catch (RejectedExecutionException e) { + // The compile queue was already shut down. + return false; + } + } + return true; + } finally { + CompilationTask.withinEnqueue.set(Boolean.FALSE); } - return true; } @Override diff -r 9b8c0d1bc2dd -r c49f9f0b9aad graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java Tue Apr 03 10:56:40 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/EscapeField.java Tue Apr 03 10:58:23 2012 +0200 @@ -26,9 +26,9 @@ public class EscapeField { - private String name; - private Object representation; - private RiType type; + private final String name; + private final Object representation; + private final RiType type; public EscapeField(String name, Object representation, RiType type) { this.name = name; diff -r 9b8c0d1bc2dd -r c49f9f0b9aad src/share/vm/interpreter/invocationCounter.cpp --- a/src/share/vm/interpreter/invocationCounter.cpp Tue Apr 03 10:56:40 2012 +0200 +++ b/src/share/vm/interpreter/invocationCounter.cpp Tue Apr 03 10:58:23 2012 +0200 @@ -47,11 +47,12 @@ // large value. Now reduce the value, so that the method can be // executed many more times before re-entering the VM. int old_count = count(); -#ifdef GRAAL - int new_count = 1; -#else - int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); -#endif + int new_count; + if (CompilationPolicyChoice == 4) { + new_count = 1; + } else { + new_count = MIN2(old_count, (int) (CompileThreshold / 2)); + } // prevent from going to zero, to distinguish from never-executed methods if (new_count == 0) new_count = 1; if (old_count != new_count) set(state(), new_count); diff -r 9b8c0d1bc2dd -r c49f9f0b9aad src/share/vm/runtime/globals.hpp