-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
CompileChainStage.java
373 lines (279 loc) · 8.92 KB
/
CompileChainStage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
* Copyright (c) 2013-2017 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/
package org.adoptopenjdk.jitwatch.ui.compilechain;
import static org.adoptopenjdk.jitwatch.util.UserInterfaceUtil.fix;
import org.adoptopenjdk.jitwatch.chain.CompileChainWalker;
import org.adoptopenjdk.jitwatch.chain.CompileNode;
import org.adoptopenjdk.jitwatch.model.Compilation;
import org.adoptopenjdk.jitwatch.model.IMetaMember;
import org.adoptopenjdk.jitwatch.model.IReadOnlyJITDataModel;
import org.adoptopenjdk.jitwatch.ui.compilationchooser.CompilationChooser;
import org.adoptopenjdk.jitwatch.ui.main.ICompilationChangeListener;
import org.adoptopenjdk.jitwatch.ui.main.IMemberSelectedListener;
import org.adoptopenjdk.jitwatch.ui.main.IStageAccessProxy;
import org.adoptopenjdk.jitwatch.ui.main.JITWatchUI;
import org.adoptopenjdk.jitwatch.ui.resize.IRedrawable;
import org.adoptopenjdk.jitwatch.ui.resize.RateLimitedResizeListener;
import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class CompileChainStage extends Stage implements ICompilationChangeListener, IRedrawable
{
private ScrollPane scrollPane;
private Pane pane;
private IStageAccessProxy stageAccess;
private CompilationChooser compilationChooser;
private CompileNode rootNode;
private static final double X_OFFSET = 16;
private static final double Y_OFFSET = 16;
private double y;
private static final double X_GAP = 25;
private static final int STROKE_WIDTH = 3;
private static final double RECT_HEIGHT = 25;
private static final double RECT_Y_GAP = 16;
class PlotNode
{
public Rectangle rect;
public Text text;
}
private IReadOnlyJITDataModel model;
public CompileChainStage(IMemberSelectedListener selectionListener, final IStageAccessProxy stageAccess,
IReadOnlyJITDataModel model)
{
initStyle(StageStyle.DECORATED);
this.stageAccess = stageAccess;
this.model = model;
scrollPane = new ScrollPane();
pane = new Pane();
scrollPane.setContent(pane);
compilationChooser = new CompilationChooser(selectionListener);
VBox verticalLayout = new VBox();
Scene scene = UserInterfaceUtil.getScene(verticalLayout, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT);
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
Button buttonSnapShot = UserInterfaceUtil.getSnapshotButton(scene, "CompileChain");
HBox hBox = new HBox();
hBox.getChildren().add(compilationChooser.getCombo());
hBox.getChildren().add(spacer);
hBox.getChildren().add(buttonSnapShot);
verticalLayout.getChildren().addAll(hBox, scrollPane);
RateLimitedResizeListener resizeListener = new RateLimitedResizeListener(this, 200);
pane.widthProperty().addListener(resizeListener);
pane.heightProperty().addListener(resizeListener);
setScene(scene);
}
@Override
public void compilationChanged(IMetaMember member)
{
compilationChooser.compilationChanged(member);
if (member != null)
{
buildTree(member);
}
else
{
rootNode = null;
redraw();
}
}
private void clear()
{
y = Y_OFFSET;
pane.getChildren().clear();
showKey();
}
@Override
public void redraw()
{
if (rootNode != null)
{
clear();
show(rootNode, X_OFFSET, Y_OFFSET, 0);
if (rootNode.getChildren().isEmpty())
{
Text text = new Text("No method calls made by " + rootNode.getMemberName() + " were inlined or JIT compiled");
text.setX(fix(X_OFFSET));
text.setY(fix(y));
text.setStrokeWidth(1.0);
pane.getChildren().add(text);
}
}
}
private void showKey()
{
double keyX = scrollPane.getWidth() - 220;
double keyY = 10;
Rectangle roundedRect = new Rectangle(keyX - 20, keyY, 210, 180);
roundedRect.setArcHeight(30);
roundedRect.setArcWidth(30);
roundedRect.setStroke(Color.BLACK);
roundedRect.setFill(Color.TRANSPARENT);
pane.getChildren().add(roundedRect);
keyY += 20;
Text text = new Text("Key");
text.setX(fix(keyX + 75));
text.setY(fix(keyY));
pane.getChildren().add(text);
keyY += 15;
buildNode("Inlined", keyX, keyY, true, false, false);
keyY += 35;
buildNode("Compiled", keyX, keyY, false, true, false);
keyY += 35;
buildNode("Virtual Call", keyX, keyY, false, false, true);
keyY += 35;
buildNode("Not Compiled", keyX, keyY, false, false, false);
keyY += 35;
}
private void show(CompileNode node, double x, double parentY, int depth)
{
double lastX = x;
lastX = plotNode(node, x, parentY, depth);
y += RECT_HEIGHT + STROKE_WIDTH + RECT_Y_GAP;
parentY = y - RECT_Y_GAP;
for (CompileNode child : node.getChildren())
{
show(child, lastX, parentY, depth + 1);
}
}
private String getLabelText(CompileNode node)
{
IMetaMember member = node.getMember();
String result = null;
if (member == null)
{
result = "Unknown";
}
else if (member.isConstructor())
{
result = member.getMetaClass().getAbbreviatedFullyQualifiedName() + "()";
}
else
{
result = member.getAbbreviatedFullyQualifiedMemberName() + "()";
}
return result;
}
private double plotNode(final CompileNode node, final double x, final double parentY, final int depth)
{
String labelText = getLabelText(node);
PlotNode plotNode = buildNode(labelText, x, y, node.isInlined(), node.isCompiled(), node.isVirtualCall());
if (depth > 0)
{
double connectX = x - X_GAP;
double connectY = y + RECT_HEIGHT / 2;
double upLineY = y + RECT_HEIGHT / 2;
Line lineUp = new Line(connectX, upLineY, connectX, parentY);
lineUp.setStrokeWidth(STROKE_WIDTH);
pane.getChildren().add(lineUp);
Line lineLeft = new Line(connectX, connectY, x, connectY);
lineLeft.setStrokeWidth(STROKE_WIDTH);
pane.getChildren().add(lineLeft);
}
double nextX = x + plotNode.rect.getWidth() / 2;
nextX += X_GAP;
initialiseRectWithOnMouseClickedEventHandler(node, plotNode.rect);
initialiseRectWithOnMouseClickedEventHandler(node, plotNode.text);
Tooltip tip = new Tooltip(node == this.rootNode ? "Root node" : node.getTooltipText());
Tooltip.install(plotNode.rect, tip);
Tooltip.install(plotNode.text, tip);
return nextX;
}
private PlotNode buildNode(String labelText, double x, double y, boolean inlined, boolean compiled, boolean virtualCall)
{
Text text = new Text(labelText);
text.snapshot(null, null);
double textWidth = text.getLayoutBounds().getWidth();
double textHeight = text.getLayoutBounds().getHeight();
double rectWidth = textWidth + 20;
Rectangle rect = new Rectangle(x, y, rectWidth, RECT_HEIGHT);
rect.setArcWidth(16);
rect.setArcHeight(16);
text.setX(fix(x + (rectWidth / 2 - textWidth / 2)));
text.setY(fix(y + RECT_HEIGHT - STROKE_WIDTH - (RECT_HEIGHT - textHeight) / 2));
text.setStrokeWidth(0.5);
text.setFill(Color.WHITE);
text.setStroke(Color.WHITE);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(STROKE_WIDTH);
rect.setFill(getColourForCompilation(compiled, inlined, virtualCall));
pane.getChildren().add(rect);
pane.getChildren().add(text);
PlotNode result = new PlotNode();
result.rect = rect;
result.text = text;
return result;
}
private Color getColourForCompilation(boolean isCompiled, boolean isInlined, boolean isVirtual)
{
if (isInlined)
{
return Color.GREEN;
}
else if (isVirtual)
{
return Color.PURPLE;
}
else if (isCompiled)
{
return Color.RED;
}
else
{
return Color.GRAY;
}
}
private void initialiseRectWithOnMouseClickedEventHandler(final CompileNode node, Shape shape)
{
shape.setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent arg0)
{
stageAccess.openTriView(node.getMember(), true);
}
});
}
private void buildTree(IMetaMember member)
{
Compilation selectedCompilation = member.getSelectedCompilation();
String title = "Compile Chain: ";
if (selectedCompilation != null)
{
CompileChainWalker walker = new CompileChainWalker(model);
CompileNode root = walker.buildCallTree(selectedCompilation);
this.rootNode = root;
title += root.getMemberName() + " " + root.getCompilation().getSignature();
setTitle(title);
}
else
{
rootNode = null;
clear();
Text text = new Text(member.toString() + " was not JIT compiled");
text.setX(fix(X_OFFSET));
text.setY(fix(y));
text.setStrokeWidth(1.0);
pane.getChildren().add(text);
}
redraw();
}
}