annotate agent/src/share/classes/sun/jvm/hotspot/ui/AnnotatedMemoryPanel.java @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents c70a245cad3a
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 152
diff changeset
2 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.math.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.font.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.awt.geom.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import javax.swing.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.debugger.dummy.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 /** A subclass of JPanel which displays a hex dump of memory along
a61af66fc99e Initial load
duke
parents:
diff changeset
42 with annotations describing the significance of various
a61af66fc99e Initial load
duke
parents:
diff changeset
43 pieces. This can be used to implement either a stack or heap
a61af66fc99e Initial load
duke
parents:
diff changeset
44 inspector. */
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public class AnnotatedMemoryPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private boolean is64Bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private Debugger debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private long addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private HighPrecisionJScrollBar scrollBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private Font font;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private int bytesPerLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private int paintCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private String unmappedAddrString;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Type of this is an IntervalTree indexed by Interval<Address> and
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // with user data of type Annotation
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private IntervalTree annotations =
a61af66fc99e Initial load
duke
parents:
diff changeset
58 new IntervalTree(new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 Address a1 = (Address) o1;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 Address a2 = (Address) o2;
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 if ((a1 == null) && (a2 == null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } else if (a1 == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else if (a2 == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (a1.equals(a2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } else if (a1.lessThan(a2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 });
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Keep track of the last start address at which we painted, so we
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // can scroll annotations
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private Address lastStartAddr;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // This contains the list of currently-visible IntervalNodes, in
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // sorted order by their low endpoint, in the form of a
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // List<Annotation>. These annotations have already been laid out.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 private java.util.List visibleAnnotations;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Darker colors than defaults for better readability
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private static Color[] colors = {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 new Color(0.0f, 0.0f, 0.6f), // blue
a61af66fc99e Initial load
duke
parents:
diff changeset
89 new Color(0.6f, 0.0f, 0.6f), // magenta
a61af66fc99e Initial load
duke
parents:
diff changeset
90 new Color(0.0f, 0.8f, 0.0f), // green
a61af66fc99e Initial load
duke
parents:
diff changeset
91 new Color(0.8f, 0.3f, 0.0f), // orange
a61af66fc99e Initial load
duke
parents:
diff changeset
92 new Color(0.0f, 0.6f, 0.8f), // cyan
a61af66fc99e Initial load
duke
parents:
diff changeset
93 new Color(0.2f, 0.2f, 0.2f), // dark gray
a61af66fc99e Initial load
duke
parents:
diff changeset
94 };
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 /** Default is 32-bit mode */
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public AnnotatedMemoryPanel(Debugger debugger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 this(debugger, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public AnnotatedMemoryPanel(Debugger debugger, boolean is64Bit, Address addrValue, Address addrLow, Address addrHigh) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 init(debugger, is64Bit, addressToBigInt(addrValue), addressToBigInt(addrLow), addressToBigInt(addrHigh));
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public AnnotatedMemoryPanel(Debugger debugger, boolean is64Bit ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 init(debugger, is64Bit, defaultMemoryLocation(is64Bit), defaultMemoryLow(is64Bit), defaultMemoryHigh(is64Bit));
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 static class AnnoX {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int lineX;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 Address highBound;
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public AnnoX(int lineX, Address highBound) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 this.lineX = lineX;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 this.highBound = highBound;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public synchronized void paintComponent(Graphics g) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // System.err.println("AnnotatedMemoryPanel.paintComponent() " + ++paintCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 super.paintComponent(g);
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Clone the Graphics so we don't screw up its state for Swing
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // drawing (as this code otherwise does)
a61af66fc99e Initial load
duke
parents:
diff changeset
127 g = g.create();
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 g.setFont(font);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 g.setColor(Color.black);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Rectangle rect = new Rectangle();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 getBounds(rect);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 String firstAddressString = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int lineHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int addrWidth;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Rectangle2D bounds = GraphicsUtilities.getStringBounds(unmappedAddrString, g);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 lineHeight = (int) bounds.getHeight();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 addrWidth = (int) bounds.getWidth();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 int addrX = (int) (0.25 * addrWidth);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 int dataX = (int) (addrX + (1.5 * addrWidth));
a61af66fc99e Initial load
duke
parents:
diff changeset
143 int lineStartX = dataX + addrWidth + 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 int annoStartX = (int) (lineStartX + (0.75 * addrWidth));
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 int numLines = rect.height / lineHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 BigInteger startVal = scrollBar.getValueHP();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 BigInteger perLine = new BigInteger(Integer.toString((int) addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // lineCount and maxLines are both 1 less than expected
a61af66fc99e Initial load
duke
parents:
diff changeset
151 BigInteger lineCount = new BigInteger(Integer.toString((int) (numLines - 1)));
a61af66fc99e Initial load
duke
parents:
diff changeset
152 BigInteger maxLines = scrollBar.getMaximumHP().subtract(scrollBar.getMinimumHP()).divide(perLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (lineCount.compareTo(maxLines) > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 lineCount = maxLines;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 BigInteger offsetVal = lineCount.multiply(perLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 BigInteger endVal = startVal.add(offsetVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (endVal.compareTo(scrollBar.getMaximumHP()) > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 startVal = scrollBar.getMaximumHP().subtract(offsetVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 endVal = scrollBar.getMaximumHP();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Sure seems like this call will cause us to immediately redraw...
a61af66fc99e Initial load
duke
parents:
diff changeset
162 scrollBar.setValueHP(startVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 scrollBar.setVisibleAmountHP(offsetVal.add(perLine));
a61af66fc99e Initial load
duke
parents:
diff changeset
165 scrollBar.setBlockIncrementHP(offsetVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 Address startAddr = bigIntToAddress(startVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 Address endAddr = bigIntToAddress(endVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Scroll last-known annotations
a61af66fc99e Initial load
duke
parents:
diff changeset
171 int scrollOffset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (lastStartAddr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 scrollOffset = (int) lastStartAddr.minus(startAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (startAddr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 scrollOffset = (int) (-1 * startAddr.minus(lastStartAddr));
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 scrollOffset = scrollOffset * lineHeight / (int) addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 scrollAnnotations(scrollOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 lastStartAddr = startAddr;
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 int curY = lineHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 Address curAddr = startAddr;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 for (int i = 0; i < numLines; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 String s = bigIntToHexString(startVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 g.drawString(s, addrX, curY);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 s = addressToString(startAddr.getAddressAt(i * addressSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 catch (UnmappedAddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 s = unmappedAddrString;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 g.drawString(s, dataX, curY);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 curY += lineHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 startVal = startVal.add(perLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Query for visible annotations (little slop to ensure we get the
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // top and bottom)
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // FIXME: it would be nice to have a more static layout; that is,
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // if something scrolls off the bottom of the screen, other
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // annotations still visible shouldn't change position
a61af66fc99e Initial load
duke
parents:
diff changeset
204 java.util.List va =
a61af66fc99e Initial load
duke
parents:
diff changeset
205 annotations.findAllNodesIntersecting(new Interval(startAddr.addOffsetTo(-addressSize),
a61af66fc99e Initial load
duke
parents:
diff changeset
206 endAddr.addOffsetTo(2 * addressSize)));
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Render them
a61af66fc99e Initial load
duke
parents:
diff changeset
209 int curLineX = lineStartX;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 int curTextX = annoStartX;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 int curColorIdx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (g instanceof Graphics2D) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 Stroke stroke = new BasicStroke(3.0f);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 ((Graphics2D) g).setStroke(stroke);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 Stack drawStack = new Stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 layoutAnnotations(va, g, curTextX, startAddr, lineHeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 for (Iterator iter = visibleAnnotations.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 Annotation anno = (Annotation) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
223 Interval interval = anno.getInterval();
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (!drawStack.empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // See whether we can pop any items off the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
227 boolean shouldContinue = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 AnnoX annoX = (AnnoX) drawStack.peek();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (annoX.highBound.lessThanOrEqual((Address) interval.getLowEndpoint())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 curLineX = annoX.lineX;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 drawStack.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 shouldContinue = !drawStack.empty();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 shouldContinue = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 } while (shouldContinue);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // Draw a line covering the interval
a61af66fc99e Initial load
duke
parents:
diff changeset
241 Address lineStartAddr = (Address) interval.getLowEndpoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // Give it a little slop
a61af66fc99e Initial load
duke
parents:
diff changeset
243 int lineStartY = (int) (lineStartAddr.minus(startAddr) * lineHeight / addressSize) +
a61af66fc99e Initial load
duke
parents:
diff changeset
244 (lineHeight / 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 Address lineEndAddr = (Address) interval.getHighEndpoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 drawStack.push(new AnnoX(curLineX, lineEndAddr));
a61af66fc99e Initial load
duke
parents:
diff changeset
247 int lineEndY = (int) (lineEndAddr.minus(startAddr) * lineHeight / addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 g.setColor(anno.getColor());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 g.drawLine(curLineX, lineStartY, curLineX, lineEndY);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Draw line to text
a61af66fc99e Initial load
duke
parents:
diff changeset
251 g.drawLine(curLineX, lineStartY, curTextX - 10, anno.getY() - (lineHeight / 2));
a61af66fc99e Initial load
duke
parents:
diff changeset
252 curLineX += 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 anno.draw(g);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 ++curColorIdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 /** Add an annotation covering the address range [annotation.lowAddress,
a61af66fc99e Initial load
duke
parents:
diff changeset
259 annotation.highAddress); that is, it includes the low address and does not
a61af66fc99e Initial load
duke
parents:
diff changeset
260 include the high address. */
a61af66fc99e Initial load
duke
parents:
diff changeset
261 public synchronized void addAnnotation(Annotation annotation) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 annotations.insert(annotation.getInterval(), annotation);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 /** Makes the given address visible somewhere in the window */
a61af66fc99e Initial load
duke
parents:
diff changeset
266 public synchronized void makeVisible(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 BigInteger bi = addressToBigInt(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 scrollBar.setValueHP(bi);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 printOn(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 annotations.printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
281 //
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 private void init(Debugger debugger, boolean is64Bit, BigInteger addrValue, BigInteger addrLow, BigInteger addrHigh) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 this.is64Bit = is64Bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 this.debugger = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 addressSize = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 unmappedAddrString = "??????????????????";
a61af66fc99e Initial load
duke
parents:
diff changeset
289 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 addressSize = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 unmappedAddrString = "??????????";
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
294 setupScrollBar(addrValue, addrLow, addrHigh);
a61af66fc99e Initial load
duke
parents:
diff changeset
295 add(scrollBar, BorderLayout.EAST);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 visibleAnnotations = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 setBackground(Color.white);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 addHierarchyBoundsListener(new HierarchyBoundsListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 public void ancestorMoved(HierarchyEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 public void ancestorResized(HierarchyEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // FIXME: should perform incremental layout
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // System.err.println("Ancestor resized");
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 });
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (font == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 font = GraphicsUtilities.lookupFont("Courier");
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (font == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 throw new RuntimeException("Error looking up monospace font Courier");
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PageDown");
a61af66fc99e Initial load
duke
parents:
diff changeset
315 getActionMap().put("PageDown", new AbstractAction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 scrollBar.setValueHP(scrollBar.getValueHP().add(scrollBar.getBlockIncrementHP()));
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 });
a61af66fc99e Initial load
duke
parents:
diff changeset
320 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PageUp");
a61af66fc99e Initial load
duke
parents:
diff changeset
321 getActionMap().put("PageUp", new AbstractAction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 scrollBar.setValueHP(scrollBar.getValueHP().subtract(scrollBar.getBlockIncrementHP()));
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 });
a61af66fc99e Initial load
duke
parents:
diff changeset
326 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "Down");
a61af66fc99e Initial load
duke
parents:
diff changeset
327 getActionMap().put("Down", new AbstractAction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 scrollBar.setValueHP(scrollBar.getValueHP().add(scrollBar.getUnitIncrementHP()));
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 });
a61af66fc99e Initial load
duke
parents:
diff changeset
332 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "Up");
a61af66fc99e Initial load
duke
parents:
diff changeset
333 getActionMap().put("Up", new AbstractAction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 scrollBar.setValueHP(scrollBar.getValueHP().subtract(scrollBar.getUnitIncrementHP()));
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 });
a61af66fc99e Initial load
duke
parents:
diff changeset
338 setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 private void setupScrollBar(BigInteger value, BigInteger min, BigInteger max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 scrollBar = new HighPrecisionJScrollBar( Scrollbar.VERTICAL, value, min, max);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 bytesPerLine = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // 64-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
346 scrollBar.setUnitIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
348 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08}));
a61af66fc99e Initial load
duke
parents:
diff changeset
349 scrollBar.setBlockIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
351 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40}));
a61af66fc99e Initial load
duke
parents:
diff changeset
352 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // 32-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
354 bytesPerLine = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 scrollBar.setUnitIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04}));
a61af66fc99e Initial load
duke
parents:
diff changeset
357 scrollBar.setBlockIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20}));
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 scrollBar.addChangeListener(new ChangeListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 public void stateChanged(ChangeEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 HighPrecisionJScrollBar h = (HighPrecisionJScrollBar) e.getSource();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 });
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 private static BigInteger defaultMemoryLocation(boolean is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 return new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
372 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00});
a61af66fc99e Initial load
duke
parents:
diff changeset
373 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 return new BigInteger(1, new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00});
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 private static BigInteger defaultMemoryLow(boolean is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 return new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
382 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00});
a61af66fc99e Initial load
duke
parents:
diff changeset
383 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 return new BigInteger(1, new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00});
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 private static BigInteger defaultMemoryHigh(boolean is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
a61af66fc99e Initial load
duke
parents:
diff changeset
392 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFC});
a61af66fc99e Initial load
duke
parents:
diff changeset
393 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return new BigInteger(1, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFC});
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 private void setupScrollBar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 setupScrollBar(defaultMemoryLocation(is64Bit),
a61af66fc99e Initial load
duke
parents:
diff changeset
400 defaultMemoryLow(is64Bit),
a61af66fc99e Initial load
duke
parents:
diff changeset
401 defaultMemoryHigh(is64Bit));
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 private String bigIntToHexString(BigInteger bi) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
406 buf.append("0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
407 String val = bi.toString(16);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 for (int i = 0; i < ((2 * addressSize) - val.length()); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 buf.append('0');
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 buf.append(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
412 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 private Address bigIntToAddress(BigInteger i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 String s = bigIntToHexString(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
417 return debugger.parseAddress(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 private BigInteger addressToBigInt(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 String s = addressToString(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (!s.startsWith("0x")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 throw new NumberFormatException(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425 return new BigInteger(s.substring(2), 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 private String addressToString(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (a == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 return "0x0000000000000000";
a61af66fc99e Initial load
duke
parents:
diff changeset
432 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return "0x00000000";
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 return a.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 /** Scrolls the visible annotations by the given Y amount */
a61af66fc99e Initial load
duke
parents:
diff changeset
440 private void scrollAnnotations(int y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 for (Iterator iter = visibleAnnotations.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 Annotation anno = (Annotation) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
443 anno.setY(anno.getY() + y);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 /** Takes the list of currently-visible annotations (in the form of
a61af66fc99e Initial load
duke
parents:
diff changeset
448 a List<IntervalNode>) and lays them out given the current
a61af66fc99e Initial load
duke
parents:
diff changeset
449 visible position and the already-visible annotations. Does not
a61af66fc99e Initial load
duke
parents:
diff changeset
450 perturb the layouts of the currently-visible annotations. */
a61af66fc99e Initial load
duke
parents:
diff changeset
451 private void layoutAnnotations(java.util.List va,
a61af66fc99e Initial load
duke
parents:
diff changeset
452 Graphics g,
a61af66fc99e Initial load
duke
parents:
diff changeset
453 int x,
a61af66fc99e Initial load
duke
parents:
diff changeset
454 Address startAddr,
a61af66fc99e Initial load
duke
parents:
diff changeset
455 int lineHeight) {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // Handle degenerate case early: no visible annotations.
a61af66fc99e Initial load
duke
parents:
diff changeset
457 if (va.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
458 visibleAnnotations.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // We have two ranges of visible annotations: the one from the
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // last repaint and the currently visible set. We want to preserve
a61af66fc99e Initial load
duke
parents:
diff changeset
464 // the layouts of the previously-visible annotations that are
a61af66fc99e Initial load
duke
parents:
diff changeset
465 // currently visible (to avoid color flashing, jumping, etc.)
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // while making the coloring of the new annotations fit as well as
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // possible. Note that annotations may appear and disappear from
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // any point in the previously-visible list, but the ordering of
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // the visible annotations is always the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // This is really a constrained graph-coloring problem. This
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // simple algorithm only takes into account half of the
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // constraints (for example, the layout of the previous
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // annotation, where it should be taking into account the layout
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // of the previous and next annotations that were in the
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // previously-visible list). There are situations where it can
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // generate overlapping annotations and adjacent annotations with
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // the same color; generally visible when scrolling line-by-line
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // rather than page-by-page. In some of these situations, will
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // have to move previously laid-out annotations. FIXME: revisit
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // this.
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // Index of last annotation which we didn't know how to lay out
a61af66fc99e Initial load
duke
parents:
diff changeset
484 int deferredIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // We "lay out after" this one
a61af66fc99e Initial load
duke
parents:
diff changeset
486 Annotation constraintAnnotation = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // The first constraint annotation
a61af66fc99e Initial load
duke
parents:
diff changeset
488 Annotation firstConstraintAnnotation = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // The index from which we search forward in the
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // visibleAnnotations list. This reduces the amount of work we do.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 int searchIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // The new set of annotations
a61af66fc99e Initial load
duke
parents:
diff changeset
493 java.util.List newAnnos = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495 for (Iterator iter = va.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 Annotation anno = (Annotation) ((IntervalNode) iter.next()).getData();
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // Search forward for this one
a61af66fc99e Initial load
duke
parents:
diff changeset
499 boolean found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 for (int i = searchIndex; i < visibleAnnotations.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 Annotation el = (Annotation) visibleAnnotations.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // See whether we can abort the search unsuccessfully because
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // we went forward too far
a61af66fc99e Initial load
duke
parents:
diff changeset
504 if (el.getLowAddress().greaterThan(anno.getLowAddress())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (el == anno) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // Found successfully.
a61af66fc99e Initial load
duke
parents:
diff changeset
509 found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
510 searchIndex = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 constraintAnnotation = anno;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 if (firstConstraintAnnotation == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 firstConstraintAnnotation = constraintAnnotation;
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 if (!found) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (constraintAnnotation != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 layoutAfter(anno, constraintAnnotation, g, x, startAddr, lineHeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 constraintAnnotation = anno;
a61af66fc99e Initial load
duke
parents:
diff changeset
523 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // Defer layout of this annotation until later
a61af66fc99e Initial load
duke
parents:
diff changeset
525 ++deferredIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 newAnnos.add(anno);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (firstConstraintAnnotation != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // Go back and lay out deferred annotations
a61af66fc99e Initial load
duke
parents:
diff changeset
534 for (int i = deferredIndex; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 Annotation anno = (Annotation) newAnnos.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 layoutBefore(anno, firstConstraintAnnotation, g, x, startAddr, lineHeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
537 firstConstraintAnnotation = anno;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // Didn't find any overlap between the old and new annotations.
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Lay out in a feed-forward fashion.
a61af66fc99e Initial load
duke
parents:
diff changeset
542 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 Assert.that(constraintAnnotation == null, "logic error in layout code");
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545 for (Iterator iter = newAnnos.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 Annotation anno = (Annotation) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
547 layoutAfter(anno, constraintAnnotation, g, x, startAddr, lineHeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
548 constraintAnnotation = anno;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 visibleAnnotations = newAnnos;
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 /** Lays out the given annotation before the optional constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
556 annotation, obeying constraints imposed by that annotation if it
a61af66fc99e Initial load
duke
parents:
diff changeset
557 is specified. */
a61af66fc99e Initial load
duke
parents:
diff changeset
558 private void layoutBefore(Annotation anno, Annotation constraintAnno,
a61af66fc99e Initial load
duke
parents:
diff changeset
559 Graphics g, int x,
a61af66fc99e Initial load
duke
parents:
diff changeset
560 Address startAddr, int lineHeight) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 anno.computeWidthAndHeight(g);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 // Color
a61af66fc99e Initial load
duke
parents:
diff changeset
563 if (constraintAnno != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 anno.setColor(prevColor(constraintAnno.getColor()));
a61af66fc99e Initial load
duke
parents:
diff changeset
565 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 anno.setColor(colors[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // X
a61af66fc99e Initial load
duke
parents:
diff changeset
569 anno.setX(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // Tentative Y
a61af66fc99e Initial load
duke
parents:
diff changeset
571 anno.setY((int) (((Address) anno.getInterval().getLowEndpoint()).minus(startAddr) * lineHeight / addressSize) +
a61af66fc99e Initial load
duke
parents:
diff changeset
572 (5 * lineHeight / 6));
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // See whether Y overlaps with last anno's Y; if so, move this one up
a61af66fc99e Initial load
duke
parents:
diff changeset
574 if ((constraintAnno != null) && (anno.getY() + anno.getHeight() > constraintAnno.getY())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 anno.setY(constraintAnno.getY() - anno.getHeight());
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 /** Lays out the given annotation after the optional constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
580 annotation, obeying constraints imposed by that annotation if it
a61af66fc99e Initial load
duke
parents:
diff changeset
581 is specified. */
a61af66fc99e Initial load
duke
parents:
diff changeset
582 private void layoutAfter(Annotation anno, Annotation constraintAnno,
a61af66fc99e Initial load
duke
parents:
diff changeset
583 Graphics g, int x,
a61af66fc99e Initial load
duke
parents:
diff changeset
584 Address startAddr, int lineHeight) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 anno.computeWidthAndHeight(g);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // Color
a61af66fc99e Initial load
duke
parents:
diff changeset
587 if (constraintAnno != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 anno.setColor(nextColor(constraintAnno.getColor()));
a61af66fc99e Initial load
duke
parents:
diff changeset
589 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
590 anno.setColor(colors[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // X
a61af66fc99e Initial load
duke
parents:
diff changeset
593 anno.setX(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // Tentative Y
a61af66fc99e Initial load
duke
parents:
diff changeset
595 anno.setY((int) (((Address) anno.getInterval().getLowEndpoint()).minus(startAddr) * lineHeight / addressSize) +
a61af66fc99e Initial load
duke
parents:
diff changeset
596 (5 * lineHeight / 6));
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // See whether Y overlaps with last anno's Y; if so, move this one down
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if ((constraintAnno != null) && (anno.getY() < (constraintAnno.getY() + constraintAnno.getHeight()))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 anno.setY(constraintAnno.getY() + constraintAnno.getHeight());
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 /** Returns previous color in our color palette */
a61af66fc99e Initial load
duke
parents:
diff changeset
604 private Color prevColor(Color c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 int i = findColorIndex(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
606 if (i == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 return colors[colors.length - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
608 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 return colors[i - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 /** Returns next color in our color palette */
a61af66fc99e Initial load
duke
parents:
diff changeset
614 private Color nextColor(Color c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 return colors[(findColorIndex(c) + 1) % colors.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
616 }
a61af66fc99e Initial load
duke
parents:
diff changeset
617
a61af66fc99e Initial load
duke
parents:
diff changeset
618 private int findColorIndex(Color c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 for (int i = 0; i < colors.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
620 if (colors[i] == c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
624 throw new IllegalArgumentException();
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
628 JFrame frame = new JFrame();
a61af66fc99e Initial load
duke
parents:
diff changeset
629 DummyDebugger debugger = new DummyDebugger(new MachineDescriptionIntelX86());
a61af66fc99e Initial load
duke
parents:
diff changeset
630 AnnotatedMemoryPanel anno = new AnnotatedMemoryPanel(debugger);
a61af66fc99e Initial load
duke
parents:
diff changeset
631 frame.getContentPane().add(anno);
a61af66fc99e Initial load
duke
parents:
diff changeset
632 anno.addAnnotation(new Annotation(debugger.parseAddress("0x80000000"),
a61af66fc99e Initial load
duke
parents:
diff changeset
633 debugger.parseAddress("0x80000040"),
a61af66fc99e Initial load
duke
parents:
diff changeset
634 "Stack Frame for \"foo\""));
a61af66fc99e Initial load
duke
parents:
diff changeset
635 anno.addAnnotation(new Annotation(debugger.parseAddress("0x80000010"),
a61af66fc99e Initial load
duke
parents:
diff changeset
636 debugger.parseAddress("0x80000020"),
a61af66fc99e Initial load
duke
parents:
diff changeset
637 "Locals for \"foo\""));
a61af66fc99e Initial load
duke
parents:
diff changeset
638 anno.addAnnotation(new Annotation(debugger.parseAddress("0x80000020"),
a61af66fc99e Initial load
duke
parents:
diff changeset
639 debugger.parseAddress("0x80000030"),
a61af66fc99e Initial load
duke
parents:
diff changeset
640 "Expression stack for \"foo\""));
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 frame.setSize(400, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 frame.addWindowListener(new WindowAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
644 public void windowClosed(WindowEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 }
a61af66fc99e Initial load
duke
parents:
diff changeset
647 public void windowClosing(WindowEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 });
152
c70a245cad3a 6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents: 0
diff changeset
651 frame.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }