graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File GRAAL-213 Sdiff graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot

graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.hotspot;
  24 
  25 import static com.oracle.graal.nodes.StructuredGraph.*;
  26 import static com.oracle.graal.phases.common.InliningUtil.*;
  27 

  28 import java.util.concurrent.*;
  29 
  30 import com.oracle.graal.api.code.*;
  31 import com.oracle.graal.api.meta.*;
  32 import com.oracle.graal.compiler.*;
  33 import com.oracle.graal.debug.*;
  34 import com.oracle.graal.debug.internal.*;
  35 import com.oracle.graal.hotspot.meta.*;
  36 import com.oracle.graal.nodes.*;
  37 import com.oracle.graal.nodes.spi.*;
  38 import com.oracle.graal.phases.*;
  39 
  40 public final class CompilationTask implements Runnable, Comparable<CompilationTask> {
  41 
  42     public static final ThreadLocal<Boolean> withinEnqueue = new ThreadLocal<Boolean>() {
  43 
  44         @Override
  45         protected Boolean initialValue() {
  46             return Boolean.valueOf(Thread.currentThread() instanceof CompilerThread);
  47         }


 116             }
 117             graalRuntime.getCompilerToVM().clearQueuedForCompilation(method);
 118             inProgress = false;
 119             withinEnqueue.set(Boolean.TRUE);
 120         }
 121     }
 122 
 123     /**
 124      * Time spent in compilation.
 125      */
 126     public static final DebugTimer CompilationTime = Debug.timer("CompilationTime");
 127 
 128     public void runCompilation() {
 129         CompilationStatistics stats = CompilationStatistics.create(method, entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI);
 130         try (TimerCloseable a = CompilationTime.start()) {
 131             final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
 132             if (printCompilation) {
 133                 TTY.println(String.format("%-6d Graal %-70s %-45s %-50s %s...", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature(),
 134                                 entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "));
 135             }



 136 
 137             CompilationResult result = null;
 138             TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method);
 139             long start = System.currentTimeMillis();
 140             try {
 141                 result = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true), new Callable<CompilationResult>() {
 142 
 143                     @Override
 144                     public CompilationResult call() throws Exception {
 145                         graalRuntime.evictDeoptedGraphs();
 146                         Replacements replacements = graalRuntime.getReplacements();
 147                         StructuredGraph graph = replacements.getMethodSubstitution(method);
 148                         if (graph == null || entryBCI != INVOCATION_ENTRY_BCI) {
 149                             graph = new StructuredGraph(method, entryBCI);
 150                         } else {
 151                             // Compiling method substitution - must clone the graph
 152                             graph = graph.copy();
 153                         }
 154                         InlinedBytecodes.add(method.getCodeSize());
 155                         return GraalCompiler.compileMethod(graalRuntime.getRuntime(), replacements, graalRuntime.getBackend(), graalRuntime.getTarget(), method, graph, graalRuntime.getCache(), plan,


 166             installMethod(result);
 167         } catch (BailoutException bailout) {
 168             Debug.metric("Bailouts").increment();
 169             if (GraalOptions.ExitVMOnBailout) {
 170                 TTY.cachedOut.println(MetaUtil.format("Bailout in %H.%n(%p)", method));
 171                 bailout.printStackTrace(TTY.cachedOut);
 172                 System.exit(-1);
 173             } else if (GraalOptions.PrintBailout) {
 174                 TTY.cachedOut.println(MetaUtil.format("Bailout in %H.%n(%p)", method));
 175                 bailout.printStackTrace(TTY.cachedOut);
 176             }
 177         } catch (Throwable t) {
 178             if (GraalOptions.ExitVMOnException) {
 179                 t.printStackTrace(TTY.cachedOut);
 180                 System.exit(-1);
 181             }
 182         }
 183         stats.finish(method);
 184     }
 185 

















 186     private void installMethod(final CompilationResult compResult) {
 187         Debug.scope("CodeInstall", new Object[]{new DebugDumpScope(String.valueOf(id), true), graalRuntime.getRuntime(), method}, new Runnable() {
 188 
 189             @Override
 190             public void run() {
 191                 HotSpotInstalledCode installedCode = graalRuntime.getRuntime().installMethod(method, entryBCI, compResult);
 192                 if (Debug.isDumpEnabled()) {
 193                     Debug.dump(new Object[]{compResult, installedCode}, "After code installation");
 194                 }
 195             }
 196 
 197         });
 198     }
 199 
 200     @Override
 201     public int compareTo(CompilationTask o) {
 202         if (priority < o.priority) {
 203             return -1;
 204         }
 205         if (priority > o.priority) {


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.hotspot;
  24 
  25 import static com.oracle.graal.nodes.StructuredGraph.*;
  26 import static com.oracle.graal.phases.common.InliningUtil.*;
  27 
  28 import java.lang.reflect.Modifier;
  29 import java.util.concurrent.*;
  30 
  31 import com.oracle.graal.api.code.*;
  32 import com.oracle.graal.api.meta.*;
  33 import com.oracle.graal.compiler.*;
  34 import com.oracle.graal.debug.*;
  35 import com.oracle.graal.debug.internal.*;
  36 import com.oracle.graal.hotspot.meta.*;
  37 import com.oracle.graal.nodes.*;
  38 import com.oracle.graal.nodes.spi.*;
  39 import com.oracle.graal.phases.*;
  40 
  41 public final class CompilationTask implements Runnable, Comparable<CompilationTask> {
  42 
  43     public static final ThreadLocal<Boolean> withinEnqueue = new ThreadLocal<Boolean>() {
  44 
  45         @Override
  46         protected Boolean initialValue() {
  47             return Boolean.valueOf(Thread.currentThread() instanceof CompilerThread);
  48         }


 117             }
 118             graalRuntime.getCompilerToVM().clearQueuedForCompilation(method);
 119             inProgress = false;
 120             withinEnqueue.set(Boolean.TRUE);
 121         }
 122     }
 123 
 124     /**
 125      * Time spent in compilation.
 126      */
 127     public static final DebugTimer CompilationTime = Debug.timer("CompilationTime");
 128 
 129     public void runCompilation() {
 130         CompilationStatistics stats = CompilationStatistics.create(method, entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI);
 131         try (TimerCloseable a = CompilationTime.start()) {
 132             final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
 133             if (printCompilation) {
 134                 TTY.println(String.format("%-6d Graal %-70s %-45s %-50s %s...", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature(),
 135                                 entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "));
 136             }
 137             if (GraalOptions.HotSpotPrintCompilation) {
 138                 printCompilation();
 139             }
 140 
 141             CompilationResult result = null;
 142             TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method);
 143             long start = System.currentTimeMillis();
 144             try {
 145                 result = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true), new Callable<CompilationResult>() {
 146 
 147                     @Override
 148                     public CompilationResult call() throws Exception {
 149                         graalRuntime.evictDeoptedGraphs();
 150                         Replacements replacements = graalRuntime.getReplacements();
 151                         StructuredGraph graph = replacements.getMethodSubstitution(method);
 152                         if (graph == null || entryBCI != INVOCATION_ENTRY_BCI) {
 153                             graph = new StructuredGraph(method, entryBCI);
 154                         } else {
 155                             // Compiling method substitution - must clone the graph
 156                             graph = graph.copy();
 157                         }
 158                         InlinedBytecodes.add(method.getCodeSize());
 159                         return GraalCompiler.compileMethod(graalRuntime.getRuntime(), replacements, graalRuntime.getBackend(), graalRuntime.getTarget(), method, graph, graalRuntime.getCache(), plan,


 170             installMethod(result);
 171         } catch (BailoutException bailout) {
 172             Debug.metric("Bailouts").increment();
 173             if (GraalOptions.ExitVMOnBailout) {
 174                 TTY.cachedOut.println(MetaUtil.format("Bailout in %H.%n(%p)", method));
 175                 bailout.printStackTrace(TTY.cachedOut);
 176                 System.exit(-1);
 177             } else if (GraalOptions.PrintBailout) {
 178                 TTY.cachedOut.println(MetaUtil.format("Bailout in %H.%n(%p)", method));
 179                 bailout.printStackTrace(TTY.cachedOut);
 180             }
 181         } catch (Throwable t) {
 182             if (GraalOptions.ExitVMOnException) {
 183                 t.printStackTrace(TTY.cachedOut);
 184                 System.exit(-1);
 185             }
 186         }
 187         stats.finish(method);
 188     }
 189 
 190     /**
 191      * Print a HotSpot-style compilation message to the console.
 192      */
 193     private void printCompilation() {
 194         final boolean isOSR = entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI;
 195         final int mod = method.getModifiers();
 196         TTY.println(String.format("%7d %4d %c%c%c%c%c       %s %s(%d bytes)",
 197                     0, id,
 198                     isOSR ? '%' : ' ',
 199                     Modifier.isSynchronized(mod) ? 's' : ' ',
 200                     ' ',
 201                     ' ',
 202                     Modifier.isNative(mod) ? 'n' : ' ',
 203                     MetaUtil.format("%H::%n(%p)", method),
 204                     isOSR ? "@ " + entryBCI + " " : "", method.getCodeSize()));
 205     }
 206 
 207     private void installMethod(final CompilationResult compResult) {
 208         Debug.scope("CodeInstall", new Object[]{new DebugDumpScope(String.valueOf(id), true), graalRuntime.getRuntime(), method}, new Runnable() {
 209 
 210             @Override
 211             public void run() {
 212                 HotSpotInstalledCode installedCode = graalRuntime.getRuntime().installMethod(method, entryBCI, compResult);
 213                 if (Debug.isDumpEnabled()) {
 214                     Debug.dump(new Object[]{compResult, installedCode}, "After code installation");
 215                 }
 216             }
 217 
 218         });
 219     }
 220 
 221     @Override
 222     public int compareTo(CompilationTask o) {
 223         if (priority < o.priority) {
 224             return -1;
 225         }
 226         if (priority > o.priority) {
graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File