Skip to content

Commit

Permalink
Snapshot button on main UI windows
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Sep 26, 2017
1 parent 9221ff7 commit 7e542d6
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.properties
@@ -1 +1 @@
version=1.2.1
version=1.2.2
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.chrisnewland</groupId>
<artifactId>jitwatch-parent</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>

<artifactId>jitwatch-core</artifactId>
Expand Down
189 changes: 189 additions & 0 deletions core/src/main/resources/examples/LoopUnroll.java
@@ -0,0 +1,189 @@

public class LoopUnroll
{
private static final int MAX = 1_000_000;

private long[] data = new long[MAX];

public LoopUnroll()
{
createData();

long total = 0;

total += constantStride1Int();
total += constantStride2Int();
total += constantStride4Int();
total += constantStride8Int();
total += constantStride16Int();
total += variableStrideInt(1);
total += constantStride1Long();
total += constantStride1IntWithExit();
total += constantStride1IntWith2Exits();
total += constantStride1IntWith4Exits();

System.out.println("Total: " + total);
}

private void createData()
{
java.util.Random random = new java.util.Random();

for (int i = 0; i < MAX; i++)
{
data[i] = random.nextLong();
}
}

private long constantStride1Int()
{
long sum = 0;
for (int i = 0; i < MAX; i += 1)
{
sum += data[i];
}
return sum;
}

private long constantStride2Int()
{
long sum = 0;
for (int i = 0; i < MAX; i += 2)
{
sum += data[i];
}
return sum;
}

private long constantStride4Int()
{
long sum = 0;
for (int i = 0; i < MAX; i += 4)
{
sum += data[i];
}
return sum;
}

private long constantStride8Int()
{
long sum = 0;
for (int i = 0; i < MAX; i += 8)
{
sum += data[i];
}
return sum;
}

private long constantStride16Int()
{
long sum = 0;
for (int i = 0; i < MAX; i += 16)
{
sum += data[i];
}
return sum;
}

private long variableStrideInt(int stride)
{
long sum = 0;
for (int i = 0; i < MAX; i += stride)
{
sum += data[i];
}
return sum;
}

private long constantStride1Long()
{
long sum = 0;
for (long l = 0; l < MAX; l++)
{
// cast because array index can't be longer than int
sum += data[(int) l];
}
return sum;
}

// NICE !!! unrolls with test on each unroll :)
private long constantStride1IntWithExit()
{
long sum = 0;

for (int i = 0; i < MAX; i += 1)
{
if (data[i] == 0x1234)
{
break;
}
else
{
sum += data[i];
}
}

return sum;
}

// NICE !!! unrolls with test on each unroll :)
private long constantStride1IntWith2Exits()
{
long sum = 0;

for (int i = 0; i < MAX; i += 1)
{
if (data[i] == 0x1234)
{
break;
}
else if (data[i] == 0x5678)
{
break;
}
else
{
sum += data[i];
}
}

return sum;
}

// NICE !!! unrolls with test on each unroll :)
private long constantStride1IntWith4Exits()
{
long sum = 0;

for (int i = 0; i < MAX; i += 1)
{
if (data[i] == 0x1234)
{
break;
}
else if (data[i] == 0x5678)
{
break;
}
else if (data[i] == 0x9ABC)
{
break;
}
else if (data[i] == 0xDEF0)
{
break;
}
else
{
sum += data[i];
}
}

return sum;
}

public static void main(String[] args)
{
new LoopUnroll();
}
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@

<groupId>com.chrisnewland</groupId>
<artifactId>jitwatch-parent</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion ui/pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.chrisnewland</groupId>
<artifactId>jitwatch-parent</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</parent>

<artifactId>jitwatch-ui</artifactId>
Expand Down
Expand Up @@ -23,10 +23,14 @@

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;
Expand Down Expand Up @@ -80,12 +84,24 @@ public CompileChainStage(IMemberSelectedListener selectionListener, final IStage
scrollPane.setContent(pane);

compilationChooser = new CompilationChooser(selectionListener);

VBox verticalLayout = new VBox();

verticalLayout.getChildren().addAll(compilationChooser.getCombo(), scrollPane);


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);

Expand Down
Expand Up @@ -832,7 +832,9 @@ public void changed(ObservableValue<? extends CompilationTableRow> arg0, Compila

lblHeap.setStyle(labelStyle);
lblVmVersion.setStyle(labelStyle);


Button buttonSnapShot = UserInterfaceUtil.getSnapshotButton(scene, "JITWatch");

hboxBottom.setPadding(new Insets(4));
hboxBottom.setPrefHeight(statusBarHeight);
hboxBottom.setSpacing(4);
Expand All @@ -844,6 +846,7 @@ public void changed(ObservableValue<? extends CompilationTableRow> arg0, Compila
hboxBottom.getChildren().add(lblTweakLog);
hboxBottom.getChildren().add(springRight);
hboxBottom.getChildren().add(lblVmVersion);
hboxBottom.getChildren().add(buttonSnapShot);

borderPane.setTop(hboxTop);
borderPane.setCenter(spMain);
Expand Down
Expand Up @@ -65,6 +65,8 @@
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
Expand Down Expand Up @@ -299,7 +301,11 @@ public void handle(ActionEvent e)
showOutput(outputString);
}
});

BorderPane borderPane = new BorderPane();

Scene scene = UserInterfaceUtil.getScene(borderPane, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT);

HBox hBoxTools = new HBox();

hBoxTools.setSpacing(10);
Expand All @@ -312,7 +318,15 @@ public void handle(ActionEvent e)
hBoxTools.getChildren().add(btnResetSandbox);
hBoxTools.getChildren().add(comboBoxVMLanguage);
hBoxTools.getChildren().add(btnRun);
hBoxTools.getChildren().add(btnOutput);
hBoxTools.getChildren().add(btnOutput);

Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);

Button buttonSnapShot = UserInterfaceUtil.getSnapshotButton(scene, "Sandbox");

hBoxTools.getChildren().add(spacer);
hBoxTools.getChildren().add(buttonSnapShot);

splitVertical.getItems().add(tabPane);
splitVertical.getItems().add(taLog);
Expand All @@ -323,14 +337,11 @@ public void handle(ActionEvent e)
vBoxMain.getChildren().add(hBoxTools);
vBoxMain.getChildren().add(splitVertical);

BorderPane borderPane = new BorderPane();
borderPane.setTop(hBoxTools);
borderPane.setCenter(splitVertical);

initialiseLog();

Scene scene = UserInterfaceUtil.getScene(borderPane, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT);

setScene(scene);

setOnCloseRequest(new EventHandler<WindowEvent>()
Expand Down

0 comments on commit 7e542d6

Please sign in to comment.