Mercurial > hg > graal-jvmci-8
comparison graal/Compiler/src/com/sun/c1x/debug/BlockPrinter.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
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.sun.c1x.debug; | |
24 | |
25 import com.sun.c1x.graph.*; | |
26 import com.sun.c1x.ir.*; | |
27 import com.sun.c1x.util.*; | |
28 import com.sun.c1x.value.*; | |
29 | |
30 /** | |
31 * Prints a listing for a {@linkplain BlockBegin block}. | |
32 * | |
33 * @author Doug Simon | |
34 */ | |
35 public class BlockPrinter implements BlockClosure { | |
36 | |
37 private final InstructionPrinter ip; | |
38 private final boolean cfgOnly; | |
39 private final boolean liveOnly; | |
40 | |
41 public BlockPrinter(IR ir, InstructionPrinter ip, boolean cfgOnly, boolean liveOnly) { | |
42 this.ip = ip; | |
43 this.cfgOnly = cfgOnly; | |
44 this.liveOnly = liveOnly; | |
45 } | |
46 | |
47 public void apply(BlockBegin block) { | |
48 if (cfgOnly) { | |
49 ip.printInstruction(block); | |
50 ip.out().println(); | |
51 } else { | |
52 printBlock(block, liveOnly); | |
53 } | |
54 } | |
55 | |
56 public void printBlock(BlockBegin block, boolean liveOnly) { | |
57 ip.printInstruction(block); | |
58 LogStream out = ip.out(); | |
59 out.println(); | |
60 printFrameState(block.stateBefore(), out); | |
61 out.println(); | |
62 | |
63 out.println("inlining depth " + block.stateBefore().scope().level); | |
64 | |
65 ip.printInstructionListingHeader(); | |
66 | |
67 for (Instruction i = block.next(); i != null; i = i.next()) { | |
68 if (!liveOnly || i.isLive()) { | |
69 ip.printInstructionListing(i); | |
70 } | |
71 } | |
72 out.println(); | |
73 | |
74 } | |
75 | |
76 private static void printFrameState(FrameState newFrameState, LogStream out) { | |
77 int startPosition = out.position(); | |
78 if (newFrameState.stackEmpty()) { | |
79 out.print("empty stack"); | |
80 } else { | |
81 out.print("stack ["); | |
82 int i = 0; | |
83 while (i < newFrameState.stackSize()) { | |
84 if (i > 0) { | |
85 out.print(", "); | |
86 } | |
87 Value value = newFrameState.stackAt(i); | |
88 out.print(i + ":" + Util.valueString(value)); | |
89 if (value == null) { | |
90 i++; | |
91 } else { | |
92 i += value.kind.sizeInSlots(); | |
93 if (value instanceof Phi) { | |
94 Phi phi = (Phi) value; | |
95 if (phi.operand() != null) { | |
96 out.print(" "); | |
97 out.print(phi.operand().toString()); | |
98 } | |
99 } | |
100 } | |
101 } | |
102 out.print(']'); | |
103 } | |
104 if (newFrameState.locksSize() != 0) { | |
105 // print out the lines on the line below this | |
106 // one at the same indentation level. | |
107 out.println(); | |
108 out.fillTo(startPosition, ' '); | |
109 out.print("locks ["); | |
110 for (int i = 0; i < newFrameState.locksSize(); i++) { | |
111 Value value = newFrameState.lockAt(i); | |
112 if (i > 0) { | |
113 out.print(", "); | |
114 } | |
115 out.print(i + ":"); | |
116 if (value == null) { | |
117 // synchronized methods push null on the lock stack | |
118 out.print("this"); | |
119 } else { | |
120 out.print(Util.valueString(value)); | |
121 } | |
122 } | |
123 out.print("]"); | |
124 } | |
125 } | |
126 } |