annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java @ 5137:09f66048738e

Added new decorate methods to the Debug class.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 21 Mar 2012 13:49:34 +0100
parents 8f4f0ebffca2
children 4d8ebb0fc484
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5136
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.concurrent.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.compiler.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.compiler.phases.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.compiler.phases.PhasePlan.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.debug.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.java.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.max.cri.ci.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.oracle.max.cri.ri.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.max.criutils.*;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 public final class CompilationTask implements Runnable {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private final Compiler compiler;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 private final PhasePlan plan;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 private final RiResolvedMethod method;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 public static CompilationTask create(Compiler compiler, PhasePlan plan, RiResolvedMethod method) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 return new CompilationTask(compiler, plan, method);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 private CompilationTask(Compiler compiler, PhasePlan plan, RiResolvedMethod method) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 this.compiler = compiler;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 this.plan = plan;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 this.method = method;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 public void run() {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 try {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime());
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed();
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 if (printCompilation) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 TTY.println(String.format("Graal %-70s %-45s %-50s ...", method.holder().name(), method.name(), method.signature().asString()));
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 CiTargetMethod result = null;
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 try {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 result = Debug.scope("Compiling", new Callable<CiTargetMethod>() {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 @Override
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 public CiTargetMethod call() throws Exception {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 return compiler.getCompiler().compileMethod(method, -1, plan);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 });
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 } finally {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 filter.remove();
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 if (printCompilation) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 TTY.println(String.format("Graal %-70s %-45s %-50s | %4dnodes %5dB", "", "", "", 0, (result != null ? result.targetCodeSize() : -1)));
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 compiler.getRuntime().installMethod(method, result);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 } catch (CiBailout bailout) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 Debug.metric("Bailouts").increment();
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 if (GraalOptions.ExitVMOnBailout) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 bailout.printStackTrace(TTY.cachedOut);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 System.exit(-1);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 } catch (Throwable t) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 if (GraalOptions.ExitVMOnException) {
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 t.printStackTrace(TTY.cachedOut);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 System.exit(-1);
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 }
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92
8f4f0ebffca2 Move compilation task logic to separate class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }