All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.adoptopenjdk.jitwatch.ui.triview.bytecode.ViewerBytecode Maven / Gradle / Ivy

/*
 * 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 static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_SEMICOLON;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE;

import java.util.ArrayList;
import java.util.List;

import org.adoptopenjdk.jitwatch.model.AnnotationException;
import org.adoptopenjdk.jitwatch.model.Compilation;
import org.adoptopenjdk.jitwatch.model.IMetaMember;
import org.adoptopenjdk.jitwatch.model.IReadOnlyJITDataModel;
import org.adoptopenjdk.jitwatch.model.bytecode.BCAnnotationType;
import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeAnnotationBuilder;
import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeAnnotationList;
import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeAnnotations;
import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeInstruction;
import org.adoptopenjdk.jitwatch.model.bytecode.LineAnnotation;
import org.adoptopenjdk.jitwatch.model.bytecode.MemberBytecode;
import org.adoptopenjdk.jitwatch.model.bytecode.Opcode;
import org.adoptopenjdk.jitwatch.report.Report;
import org.adoptopenjdk.jitwatch.report.ReportType;
import org.adoptopenjdk.jitwatch.ui.main.IStageAccessProxy;
import org.adoptopenjdk.jitwatch.ui.triview.ILineListener;
import org.adoptopenjdk.jitwatch.ui.triview.ILineListener.LineType;
import org.adoptopenjdk.jitwatch.ui.triview.TriViewNavigationStack;
import org.adoptopenjdk.jitwatch.ui.triview.Viewer;
import org.adoptopenjdk.jitwatch.util.JVMSUtil;
import org.adoptopenjdk.jitwatch.util.ParseUtil;
import org.adoptopenjdk.jitwatch.util.StringUtil;
import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil;

import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;

public class ViewerBytecode extends Viewer
{
	private List instructions = new ArrayList<>();

	private boolean offsetMismatchDetected = false;
	private IReadOnlyJITDataModel model;
	private TriViewNavigationStack navigationStack;
	private Report lastSuggestion = null;

	public ViewerBytecode(IStageAccessProxy stageAccessProxy, TriViewNavigationStack navigationStack, IReadOnlyJITDataModel model,
			ILineListener lineListener, LineType lineType)
	{
		super(stageAccessProxy, lineListener, lineType, true);
		this.model = model;
		this.navigationStack = navigationStack;
	}

	public void highlightBytecodeForSuggestion(Report report)
	{
		lastSuggestion = report;

		int bytecodeOffset = report.getBytecodeOffset();

		int index = getLineIndexForBytecodeOffset(bytecodeOffset);

		logger.info("highlightBytecodeForSuggestion bci {} index {}", bytecodeOffset, index);

		BytecodeLabel labelAtIndex = (BytecodeLabel) getLabelAtIndex(index);

		if (labelAtIndex != null)
		{
			StringBuilder ttBuilder = new StringBuilder();

			Tooltip tooltip = labelAtIndex.getTooltip();

			if (tooltip != null)
			{
				Tooltip.uninstall(labelAtIndex, tooltip);

				ttBuilder.append(tooltip.getText()).append(S_NEWLINE).append(S_NEWLINE);
			}

			if (report.getType() != ReportType.ELIMINATED_ALLOCATION_DIRECT
					&& report.getType() != ReportType.ELIMINATED_ALLOCATION_INLINE)
			{
				ttBuilder.append("Suggestion:\n");

				String text = report.getText();

				if (report.getType() == ReportType.BRANCH)
				{
					text = StringUtil.wordWrap(text, 50);
				}

				ttBuilder.append(text);
			}

			String toolTipString = ttBuilder.toString();

			toolTipString = StringUtil.replaceXMLEntities(toolTipString);

			tooltip = new Tooltip(toolTipString);

			labelAtIndex.setTooltip(tooltip);
		}

		highlightLine(index);
	}

	public void highlightBytecodeOffset(int bci)
	{
		int index = getLineIndexForBytecodeOffset(bci);
		highlightLine(index);
	}

	public void setContent(final IMetaMember member)
	{
		offsetMismatchDetected = false;
		instructions.clear();

		MemberBytecode memberBytecode = member.getMemberBytecode();

		if (memberBytecode != null)
		{
			instructions.addAll(memberBytecode.getInstructions());
		}

		BytecodeAnnotations bcAnnotations = null;

		lineAnnotations.clear();
		lastScrollIndex = -1;

		List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy