Mercurial > hg > truffle
comparison graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java @ 13197:8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 30 Nov 2013 01:16:55 +0100 |
parents | 43301f080126 |
children | 210f58e992a1 7086a2fe7370 |
comparison
equal
deleted
inserted
replaced
13196:e343d4623e47 | 13197:8569b9e047cd |
---|---|
25 import static com.oracle.graal.compiler.GraalCompiler.Options.*; | 25 import static com.oracle.graal.compiler.GraalCompiler.Options.*; |
26 import static com.oracle.graal.compiler.MethodFilter.*; | 26 import static com.oracle.graal.compiler.MethodFilter.*; |
27 import static com.oracle.graal.phases.GraalOptions.*; | 27 import static com.oracle.graal.phases.GraalOptions.*; |
28 | 28 |
29 import java.util.*; | 29 import java.util.*; |
30 import java.util.concurrent.*; | |
31 | 30 |
32 import com.oracle.graal.alloc.*; | 31 import com.oracle.graal.alloc.*; |
33 import com.oracle.graal.api.code.*; | 32 import com.oracle.graal.api.code.*; |
34 import com.oracle.graal.api.meta.*; | 33 import com.oracle.graal.api.meta.*; |
35 import com.oracle.graal.compiler.alloc.*; | 34 import com.oracle.graal.compiler.alloc.*; |
36 import com.oracle.graal.compiler.gen.*; | 35 import com.oracle.graal.compiler.gen.*; |
37 import com.oracle.graal.compiler.target.*; | 36 import com.oracle.graal.compiler.target.*; |
38 import com.oracle.graal.debug.*; | 37 import com.oracle.graal.debug.*; |
38 import com.oracle.graal.debug.Debug.Scope; | |
39 import com.oracle.graal.debug.internal.*; | 39 import com.oracle.graal.debug.internal.*; |
40 import com.oracle.graal.lir.*; | 40 import com.oracle.graal.lir.*; |
41 import com.oracle.graal.lir.asm.*; | 41 import com.oracle.graal.lir.asm.*; |
42 import com.oracle.graal.nodes.*; | 42 import com.oracle.graal.nodes.*; |
43 import com.oracle.graal.nodes.cfg.*; | 43 import com.oracle.graal.nodes.cfg.*; |
130 * @param installedCodeOwner the method the compiled code will be | 130 * @param installedCodeOwner the method the compiled code will be |
131 * {@linkplain InstalledCode#getMethod() associated} with once installed. This | 131 * {@linkplain InstalledCode#getMethod() associated} with once installed. This |
132 * argument can be null. | 132 * argument can be null. |
133 * @return the result of the compilation | 133 * @return the result of the compilation |
134 */ | 134 */ |
135 public static <T extends CompilationResult> T compileGraph(final StructuredGraph graph, final CallingConvention cc, final ResolvedJavaMethod installedCodeOwner, final Providers providers, | 135 public static <T extends CompilationResult> T compileGraph(StructuredGraph graph, CallingConvention cc, ResolvedJavaMethod installedCodeOwner, Providers providers, Backend backend, |
136 final Backend backend, final TargetDescription target, final GraphCache cache, final PhasePlan plan, final OptimisticOptimizations optimisticOpts, | 136 TargetDescription target, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts, SpeculationLog speculationLog, Suites suites, T compilationResult) { |
137 final SpeculationLog speculationLog, final Suites suites, final T compilationResult) { | 137 try (Scope s = Debug.scope("GraalCompiler", graph, providers.getCodeCache())) { |
138 Debug.scope("GraalCompiler", new Object[]{graph, providers.getCodeCache()}, new Runnable() { | 138 compileGraphNoScope(graph, cc, installedCodeOwner, providers, backend, target, cache, plan, optimisticOpts, speculationLog, suites, compilationResult); |
139 | 139 } catch (Throwable e) { |
140 public void run() { | 140 throw Debug.handle(e); |
141 compileGraphNoScope(graph, cc, installedCodeOwner, providers, backend, target, cache, plan, optimisticOpts, speculationLog, suites, compilationResult); | 141 } |
142 } | |
143 }); | |
144 | |
145 return compilationResult; | 142 return compilationResult; |
146 } | 143 } |
147 | 144 |
148 /** | 145 /** |
149 * Same as {@link #compileGraph} but without entering a | 146 * Same as {@link #compileGraph} but without entering a |
150 * {@linkplain Debug#scope(String, Object[], Runnable) debug scope}. | 147 * {@linkplain Debug#scope(String, Object...) debug scope}. |
151 */ | 148 */ |
152 public static <T extends CompilationResult> T compileGraphNoScope(final StructuredGraph graph, final CallingConvention cc, final ResolvedJavaMethod installedCodeOwner, final Providers providers, | 149 public static <T extends CompilationResult> T compileGraphNoScope(StructuredGraph graph, CallingConvention cc, ResolvedJavaMethod installedCodeOwner, Providers providers, Backend backend, |
153 final Backend backend, final TargetDescription target, final GraphCache cache, final PhasePlan plan, final OptimisticOptimizations optimisticOpts, | 150 TargetDescription target, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts, SpeculationLog speculationLog, Suites suites, T compilationResult) { |
154 final SpeculationLog speculationLog, final Suites suites, final T compilationResult) { | 151 Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); |
155 final Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); | 152 |
156 final LIR lir = Debug.scope("FrontEnd", new Callable<LIR>() { | 153 LIR lir = null; |
157 | 154 try (Scope s = Debug.scope("FrontEnd"); TimerCloseable a = FrontEnd.start()) { |
158 public LIR call() { | 155 lir = emitHIR(providers, target, graph, assumptions, cache, plan, optimisticOpts, speculationLog, suites); |
159 try (TimerCloseable a = FrontEnd.start()) { | 156 } catch (Throwable e) { |
160 return emitHIR(providers, target, graph, assumptions, cache, plan, optimisticOpts, speculationLog, suites); | 157 throw Debug.handle(e); |
161 } | 158 } |
162 } | |
163 }); | |
164 try (TimerCloseable a = BackEnd.start()) { | 159 try (TimerCloseable a = BackEnd.start()) { |
165 final LIRGenerator lirGen = Debug.scope("BackEnd", lir, new Callable<LIRGenerator>() { | 160 LIRGenerator lirGen = null; |
166 | 161 try (Scope s = Debug.scope("BackEnd", lir)) { |
167 public LIRGenerator call() { | 162 lirGen = emitLIR(backend, target, lir, graph, cc); |
168 return emitLIR(backend, target, lir, graph, cc); | 163 } catch (Throwable e) { |
169 } | 164 throw Debug.handle(e); |
170 }); | 165 } |
171 Debug.scope("CodeGen", lirGen, new Runnable() { | 166 try (Scope s = Debug.scope("CodeGen", lirGen)) { |
172 | 167 emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner); |
173 public void run() { | 168 } catch (Throwable e) { |
174 emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner); | 169 throw Debug.handle(e); |
175 } | 170 } |
176 | 171 } catch (Throwable e) { |
177 }); | 172 throw Debug.handle(e); |
178 } | 173 } |
179 | 174 |
180 return compilationResult; | 175 return compilationResult; |
181 } | 176 } |
182 | 177 |
191 } | 186 } |
192 | 187 |
193 /** | 188 /** |
194 * Builds the graph, optimizes it. | 189 * Builds the graph, optimizes it. |
195 */ | 190 */ |
196 public static LIR emitHIR(Providers providers, TargetDescription target, final StructuredGraph graph, Assumptions assumptions, GraphCache cache, PhasePlan plan, | 191 public static LIR emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts, |
197 OptimisticOptimizations optimisticOpts, final SpeculationLog speculationLog, final Suites suites) { | 192 SpeculationLog speculationLog, Suites suites) { |
198 | 193 |
199 if (speculationLog != null) { | 194 if (speculationLog != null) { |
200 speculationLog.snapshot(); | 195 speculationLog.snapshot(); |
201 } | 196 } |
202 | 197 |
222 // we do not want to store statistics about OSR compilations because it may prevent inlining | 217 // we do not want to store statistics about OSR compilations because it may prevent inlining |
223 if (!graph.isOSR()) { | 218 if (!graph.isOSR()) { |
224 InliningPhase.storeStatisticsAfterLowTier(graph); | 219 InliningPhase.storeStatisticsAfterLowTier(graph); |
225 } | 220 } |
226 | 221 |
227 final SchedulePhase schedule = new SchedulePhase(); | 222 SchedulePhase schedule = new SchedulePhase(); |
228 schedule.apply(graph); | 223 schedule.apply(graph); |
229 Debug.dump(schedule, "final schedule"); | 224 Debug.dump(schedule, "final schedule"); |
230 | 225 |
231 final Block[] blocks = schedule.getCFG().getBlocks(); | 226 Block[] blocks = schedule.getCFG().getBlocks(); |
232 final Block startBlock = schedule.getCFG().getStartBlock(); | 227 Block startBlock = schedule.getCFG().getStartBlock(); |
233 assert startBlock != null; | 228 assert startBlock != null; |
234 assert startBlock.getPredecessorCount() == 0; | 229 assert startBlock.getPredecessorCount() == 0; |
235 | 230 |
236 return Debug.scope("ComputeLinearScanOrder", new Callable<LIR>() { | 231 try (Scope s = Debug.scope("ComputeLinearScanOrder")) { |
237 | 232 NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); |
238 @Override | 233 List<Block> codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock, nodeProbabilities); |
239 public LIR call() { | 234 List<Block> linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock, nodeProbabilities); |
240 NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); | 235 |
241 List<Block> codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock, nodeProbabilities); | 236 LIR lir = new LIR(schedule.getCFG(), schedule.getBlockToNodesMap(), linearScanOrder, codeEmittingOrder); |
242 List<Block> linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock, nodeProbabilities); | 237 Debug.dump(lir, "After linear scan order"); |
243 | 238 return lir; |
244 LIR lir = new LIR(schedule.getCFG(), schedule.getBlockToNodesMap(), linearScanOrder, codeEmittingOrder); | 239 } catch (Throwable e) { |
245 Debug.dump(lir, "After linear scan order"); | 240 throw Debug.handle(e); |
246 return lir; | 241 } |
247 | 242 |
248 } | 243 } |
249 }); | 244 |
250 | 245 private static void emitBlock(LIRGenerator lirGen, Block b) { |
251 } | 246 if (lirGen.lir.lir(b) == null) { |
252 | 247 for (Block pred : b.getPredecessors()) { |
253 public static LIRGenerator emitLIR(final Backend backend, final TargetDescription target, final LIR lir, StructuredGraph graph, CallingConvention cc) { | 248 if (!b.isLoopHeader() || !pred.isLoopEnd()) { |
254 final FrameMap frameMap = backend.newFrameMap(); | 249 emitBlock(lirGen, pred); |
255 final LIRGenerator lirGen = backend.newLIRGenerator(graph, frameMap, cc, lir); | |
256 | |
257 Debug.scope("LIRGen", lirGen, new Runnable() { | |
258 | |
259 public void run() { | |
260 for (Block b : lir.linearScanOrder()) { | |
261 emitBlock(b); | |
262 } | 250 } |
263 | 251 } |
264 Debug.dump(lir, "After LIR generation"); | 252 lirGen.doBlock(b); |
265 } | 253 } |
266 | 254 } |
267 private void emitBlock(Block b) { | 255 |
268 if (lir.lir(b) == null) { | 256 public static LIRGenerator emitLIR(Backend backend, TargetDescription target, LIR lir, StructuredGraph graph, CallingConvention cc) { |
269 for (Block pred : b.getPredecessors()) { | 257 FrameMap frameMap = backend.newFrameMap(); |
270 if (!b.isLoopHeader() || !pred.isLoopEnd()) { | 258 LIRGenerator lirGen = backend.newLIRGenerator(graph, frameMap, cc, lir); |
271 emitBlock(pred); | 259 |
272 } | 260 try (Scope s = Debug.scope("LIRGen", lirGen)) { |
273 } | 261 for (Block b : lir.linearScanOrder()) { |
274 lirGen.doBlock(b); | 262 emitBlock(lirGen, b); |
275 } | 263 } |
276 } | 264 |
277 }); | 265 Debug.dump(lir, "After LIR generation"); |
266 } catch (Throwable e) { | |
267 throw Debug.handle(e); | |
268 } | |
278 | 269 |
279 lirGen.beforeRegisterAllocation(); | 270 lirGen.beforeRegisterAllocation(); |
280 | 271 |
281 Debug.scope("Allocator", new Runnable() { | 272 try (Scope s = Debug.scope("Allocator")) { |
282 | 273 if (backend.shouldAllocateRegisters()) { |
283 public void run() { | 274 new LinearScan(target, lir, lirGen, frameMap).allocate(); |
284 if (backend.shouldAllocateRegisters()) { | 275 } |
285 new LinearScan(target, lir, lirGen, frameMap).allocate(); | 276 } catch (Throwable e) { |
286 } | 277 throw Debug.handle(e); |
287 } | 278 } |
288 }); | |
289 return lirGen; | 279 return lirGen; |
290 } | 280 } |
291 | 281 |
292 public static void emitCode(Backend backend, long[] leafGraphIds, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner) { | 282 public static void emitCode(Backend backend, long[] leafGraphIds, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner) { |
293 TargetMethodAssembler tasm = backend.newAssembler(lirGen, compilationResult); | 283 TargetMethodAssembler tasm = backend.newAssembler(lirGen, compilationResult); |