Skip to content

Commit

Permalink
Fixed missing bytecode annotations on OSR-highlighted region
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Oct 23, 2017
1 parent 95123ae commit 7a8a992
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 104 deletions.
@@ -0,0 +1,30 @@
/*
* Copyright (c) 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.triview;

import javafx.scene.control.Label;

public class InstructionLabel extends Label
{
private String unhighlightedStyle = Viewer.STYLE_UNHIGHLIGHTED;

public InstructionLabel(String text)
{
super(text);
}

public void setUnhighlightedStyle(String style)
{
unhighlightedStyle = style;

setStyle(unhighlightedStyle);
}

public String getUnhighlightedStyle()
{
return unhighlightedStyle;
}
}
Expand Up @@ -857,24 +857,21 @@ public void lineHighlighted(int index, LineType lineType)
}

@Override
public void setRange(LineType lineType, int startIndex, int endIndex)
public void setRange(LineType lineType, int rangeStart, int rangeEnd)
{
switch (lineType)
{
case SOURCE:
viewerSource.setStartRange(startIndex);
viewerSource.setEndRange(endIndex);
viewerSource.setRange(rangeStart, rangeEnd);
viewerSource.clearAllHighlighting();
break;
case BYTECODE:
case BYTECODE_BCI:
viewerBytecode.setStartRange(startIndex);
viewerBytecode.setEndRange(endIndex);
viewerBytecode.setRange(rangeStart, rangeEnd);
viewerBytecode.clearAllHighlighting();
break;
case ASSEMBLY:
viewerAssembly.setStartRange(startIndex);
viewerAssembly.setEndRange(endIndex);
viewerAssembly.setRange(rangeStart, rangeEnd);
viewerAssembly.clearAllHighlighting();
break;
default:
Expand Down
63 changes: 22 additions & 41 deletions ui/src/main/java/org/adoptopenjdk/jitwatch/ui/triview/Viewer.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2016 Chris Newland.
* Copyright (c) 2013-2017 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/
Expand Down Expand Up @@ -45,8 +45,6 @@
import org.adoptopenjdk.jitwatch.model.bytecode.LineAnnotation;
import org.adoptopenjdk.jitwatch.ui.main.IStageAccessProxy;
import org.adoptopenjdk.jitwatch.ui.triview.ILineListener.LineType;
import org.adoptopenjdk.jitwatch.ui.triview.assembly.AssemblyLabel;
import org.adoptopenjdk.jitwatch.ui.triview.bytecode.BytecodeLabel;
import org.adoptopenjdk.jitwatch.util.ParseUtil;
import org.adoptopenjdk.jitwatch.util.StringUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -86,10 +84,10 @@ public class Viewer extends VBox
protected ILineListener lineListener;
protected LineType lineType = LineType.PLAIN;

private boolean isHighlighting;
protected boolean isHighlighting;

protected int startRange = -1;
protected int endRange = -1;
protected int rangeStart = -1;
protected int rangeEnd = -1;

public Viewer(IStageAccessProxy stageAccessProxy, boolean highlighting)
{
Expand All @@ -111,38 +109,27 @@ public Viewer(IStageAccessProxy stageAccessProxy, ILineListener lineListener, Li
setup();
}

private void highlightRange()
public void setRange(int rangeStart, int rangeEnd)
{
if (startRange != -1 && endRange != -1)
this.rangeStart = rangeStart;
this.rangeEnd = rangeEnd;

int lineCount = vBoxRows.getChildren().size();

if (rangeStart >= 0 && rangeEnd <= lineCount)
{
for (int i = startRange; i <= endRange; i++)
for (int i = rangeStart; i <= rangeEnd; i++)
{
Label label = (Label) vBoxRows.getChildren().get(i);
label.setStyle(STYLE_HIGHLIGHTED_RANGE);
Node node = vBoxRows.getChildren().get(i);

if (node instanceof InstructionLabel)
{
((InstructionLabel) node).setUnhighlightedStyle(STYLE_HIGHLIGHTED_RANGE);
}
}
}
}

public int getStartRange()
{
return startRange;
}

public void setStartRange(int startRange)
{
this.startRange = startRange;
}

public int getEndRange()
{
return endRange;
}

public void setEndRange(int endRange)
{
this.endRange = endRange;
}

public void clear()
{
lineAnnotations.clear();
Expand Down Expand Up @@ -523,7 +510,7 @@ public void jumpToMemberSource(IMetaMember member)
}

public void clearAllHighlighting()
{
{
for (Node item : vBoxRows.getChildren())
{
unhighlightLabel(item);
Expand All @@ -532,20 +519,14 @@ public void clearAllHighlighting()

protected void unhighlightLabel(Node node)
{
if (node instanceof BytecodeLabel)
{
node.setStyle(((BytecodeLabel) node).getUnhighlightedStyle());
}
else if (node instanceof AssemblyLabel)
{
node.setStyle(((AssemblyLabel) node).getUnhighlightedStyle());
if (node instanceof InstructionLabel)
{
node.setStyle(((InstructionLabel) node).getUnhighlightedStyle());
}
else
{
node.setStyle(STYLE_UNHIGHLIGHTED);
}

highlightRange();
}

public void unhighlightPrevious()
Expand Down
@@ -1,16 +1,14 @@
/*
* Copyright (c) 2013-2015 Chris Newland.
* 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.triview.assembly;

import javafx.scene.control.Label;

import org.adoptopenjdk.jitwatch.model.assembly.AssemblyInstruction;
import org.adoptopenjdk.jitwatch.ui.triview.Viewer;
import org.adoptopenjdk.jitwatch.ui.triview.InstructionLabel;

public class AssemblyLabel extends Label
public class AssemblyLabel extends InstructionLabel
{
private AssemblyInstruction instruction;

Expand All @@ -24,16 +22,4 @@ public AssemblyInstruction getInstruction()
{
return instruction;
}

public String getUnhighlightedStyle()
{
if (instruction.isSafePoint())
{
return Viewer.STYLE_SAFEPOINT;
}
else
{
return Viewer.STYLE_UNHIGHLIGHTED;
}
}
}
Expand Up @@ -46,8 +46,8 @@
public class ViewerAssembly extends Viewer
{
private DecimalFormat formatThousandsUnderscore;
private IAssemblyParser parser; //TODO choose parser

private IAssemblyParser parser; // TODO choose parser

public ViewerAssembly(IStageAccessProxy stageAccessProxy, ILineListener lineListener, LineType lineType)
{
Expand All @@ -65,7 +65,7 @@ public ViewerAssembly(IStageAccessProxy stageAccessProxy, ILineListener lineList
public void setAssemblyMethod(AssemblyMethod asmMethod, boolean showLocalLabels)
{
parser = AssemblyUtil.getParserForArchitecture(asmMethod.getArchitecture());

lastScrollIndex = -1;

List<Label> labels = new ArrayList<>();
Expand Down Expand Up @@ -147,7 +147,7 @@ private String getToolTip(AssemblyInstruction instruction)
builder.append("operand ").append(pos).append(": ");

decodeOperand(mnemonic, operand, builder);

builder.append(S_NEWLINE);

pos++;
Expand Down Expand Up @@ -186,12 +186,12 @@ private String getConstantLabel(String operand)
{
operand = operand.substring(1);
}

if (operand.endsWith(S_HEX_POSTFIX))
{
operand = S_HEX_PREFIX + operand.substring(0, operand.length()-1);
operand = S_HEX_PREFIX + operand.substring(0, operand.length() - 1);
}

long decimal = Long.decode(operand);

builder.append(S_SPACE).append(S_OPEN_PARENTHESES).append("Decimal: ").append(formatThousandsUnderscore.format(decimal))
Expand All @@ -213,7 +213,7 @@ private String decodeRegister(String input)
// http://www.x86-64.org/documentation/assembly.html

String regName = parser.extractRegisterName(input);

if (regName.startsWith("e"))
{
builder.append("32-bit register ").append(regName);
Expand Down Expand Up @@ -267,7 +267,7 @@ else if (regName.endsWith("sp"))
{
builder.append(" (stack pointer)");
}

if (input.startsWith("*"))
{
builder.append(" (indirect)");
Expand All @@ -289,7 +289,10 @@ private AssemblyLabel createLabel(AssemblyInstruction instruction, int annoWidth
{
AssemblyLabel lbl = new AssemblyLabel(instruction, annoWidth, line, showLocalLabels);

lbl.setStyle(lbl.getUnhighlightedStyle());
if (instruction.isSafePoint())
{
lbl.setUnhighlightedStyle(STYLE_SAFEPOINT);
}

return lbl;
}
Expand Down
@@ -1,36 +1,23 @@
/*
* Copyright (c) 2013-2015 Chris Newland.
* 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.triview.bytecode;

import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeInstruction;
import org.adoptopenjdk.jitwatch.ui.triview.InstructionLabel;

import javafx.scene.control.Label;

public class BytecodeLabel extends Label
public class BytecodeLabel extends InstructionLabel
{
private BytecodeInstruction instruction;
private String unhighlightedStyle;

public BytecodeLabel(BytecodeInstruction instr, int maxOffset, int line)
{
setText(instr.toString(maxOffset, line));
super(instr.toString(maxOffset, line));
instruction = instr;
}

public void setUnhighlightedStyle(String style)
{
unhighlightedStyle = style;
setStyle(unhighlightedStyle);
}

public String getUnhighlightedStyle()
{
return unhighlightedStyle;
}


public BytecodeInstruction getInstruction()
{
return instruction;
Expand Down

0 comments on commit 7a8a992

Please sign in to comment.