Skip to content

Commit 65df3ec

Browse files
committed
[GR-35827] Open source C1Visualizer
PullRequest: graal/22476
2 parents 925fe8e + 506672a commit 65df3ec

File tree

474 files changed

+41813
-668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

474 files changed

+41813
-668
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bench-results.json
5454
jmh_result.json
5555
/vm/src/installer/dist/
5656
visualizer/IdealGraphVisualizer/*/target/
57+
visualizer/C1Visualizer/*/target/
5758
/.src-rev
5859
*.interp
5960
*.tokens

compiler/mx.compiler/mx_graal_tools.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
from __future__ import print_function
2727

2828
import os
29-
import shutil
3029
import re
30+
import shutil
3131
import sys
32-
from os.path import join, exists
3332
from argparse import ArgumentParser, REMAINDER
33+
from os.path import join, exists
3434

3535
import mx
3636

@@ -41,7 +41,7 @@
4141

4242
_suite = mx.suite('compiler')
4343

44-
def run_netbeans_app(app_name, jdkhome, args=None, dist=None):
44+
def run_netbeans_app(app_name, jdkhome, args=None, dist=None, launch_message=None):
4545
args = [] if args is None else args
4646
if dist is None:
4747
dist = app_name.upper() + '_DIST'
@@ -75,12 +75,13 @@ def run_netbeans_app(app_name, jdkhome, args=None, dist=None):
7575
if mx.get_os() == 'linux':
7676
# Mitigates X server crashes on Linux
7777
launch.append('-J-Dsun.java2d.xrender=false')
78-
print('Consider flag -J-Dsun.java2d.uiScale=2 if on a high resolution display')
79-
print('Consider flag -J-Xms4g -J-Xmx8g if dealing with large graphs')
78+
if launch_message:
79+
launch_message()
8080
mx.run(launch+args)
8181

82-
def igv(args):
83-
"""run the Ideal Graph Visualizer
82+
83+
def netbeans_docstring(fullname, mxname):
84+
return f"""run the {fullname}
8485
8586
The current version is based on NetBeans 26 which officially supports JDK 17 through JDK 24. A
8687
supported JDK will be chosen from the JDKs known to mx but it will fall back to whatever is
@@ -90,19 +91,21 @@ def igv(args):
9091
9192
You can directly control which JDK is used to launch IGV using
9293
93-
mx igv --jdkhome /path/to/java/home
94+
mx {mxname} --jdkhome /path/to/java/home
9495
9596
This will completely ignore any JAVA_HOME settings in mx.
9697
97-
Extra NetBeans specific options can be passed as well. mx igv --help will show the
98+
Extra NetBeans specific options can be passed as well. mx {mxname} --help will show the
9899
help for the NetBeans launcher.
99100
100101
"""
102+
103+
def launch_netbeans_app(fullname, distname, mxname, args, launch_message=None):
101104
min_version = 17
102105
max_version = 24
103106
min_version_spec = mx.VersionSpec(str(min_version))
104107
next_version_spec = mx.VersionSpec(str(max_version + 1))
105-
def _igvJdkVersionCheck(version):
108+
def _netbeansJdkVersionCheck(version):
106109
return min_version_spec <= version < next_version_spec
107110

108111
jdkhome = None
@@ -111,29 +114,35 @@ def _do_not_abort(msg):
111114
pass
112115

113116
# try to find a fully supported version first
114-
jdk = mx.get_tools_jdk(versionCheck=_igvJdkVersionCheck, versionDescription=f'IGV prefers JDK {min_version} through JDK {max_version}', abortCallback=_do_not_abort)
117+
jdk = mx.get_tools_jdk(versionCheck=_netbeansJdkVersionCheck, versionDescription=f'{fullname} prefers JDK {min_version} through JDK {max_version}', abortCallback=_do_not_abort)
115118
if jdk is None:
116119
# try any JDK
117120
jdk = mx.get_jdk()
118121

119122
if jdk:
120123
jdkhome = jdk.home
121-
mx.log(f'Launching IGV with {jdkhome}')
122-
if not _igvJdkVersionCheck(jdk.version):
123-
mx.warn(f'{jdk.home} is not an officially supported JDK for IGV.')
124+
mx.log(f'Launching {fullname} with {jdkhome}')
125+
if not _netbeansJdkVersionCheck(jdk.version):
126+
mx.warn(f'{jdk.home} is not an officially supported JDK.')
124127
mx.warn(f'If you experience any problems try to use an LTS release between JDK {min_version} and JDK {max_version} instead.')
125-
mx.warn(f'mx help igv provides more details.')
128+
mx.warn(f'mx help {mxname} provides more details.')
126129

127-
run_netbeans_app('IdealGraphVisualizer', jdkhome, args=args, dist='IDEALGRAPHVISUALIZER_DIST')
130+
run_netbeans_app(distname, jdkhome, args=args, dist=f'{distname.upper()}_DIST', launch_message=launch_message)
131+
132+
def igv(args):
133+
def help_message():
134+
print('Consider flag -J-Dsun.java2d.uiScale=2 if on a high resolution display')
135+
print('Consider flag -J-Xms4g -J-Xmx8g if dealing with large graphs')
136+
137+
launch_netbeans_app('Ideal Graph Visualizer', 'IdealGraphVisualizer', 'igv', args, launch_message=help_message)
138+
139+
igv.__doc__ = netbeans_docstring('Ideal Graph Visualizer', 'igv')
128140

129141
def c1visualizer(args):
130-
"""run the C1 Compiler Visualizer"""
131-
v8u40 = mx.VersionSpec("1.8.0_40")
132-
v12 = mx.VersionSpec("12")
133-
def _c1vJdkVersionCheck(version):
134-
return v8u40 <= version < v12
135-
jdkhome = mx.get_jdk(_c1vJdkVersionCheck, versionDescription='(JDK that is >= 1.8.0u40 and <= 11 which can be specified via EXTRA_JAVA_HOMES or --extra-java-homes)', purpose="running C1 Visualizer").home
136-
run_netbeans_app('C1Visualizer', jdkhome, args() if callable(args) else args)
142+
launch_netbeans_app('C1 Visualizer', 'C1Visualizer', 'c1visualizer', args)
143+
144+
c1visualizer.__doc__ = netbeans_docstring('C1 Visualizer', 'c1visualizer')
145+
137146

138147
def hsdis(args, copyToDir=None):
139148
"""download the hsdis library and copy it to a specific dir or to the current JDK

compiler/mx.compiler/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
},
5959

6060
"C1VISUALIZER_DIST" : {
61-
"urls" : ["https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/c1visualizer/c1visualizer-1.10.zip"],
62-
"digest" : "sha512:40c505dd03ca0bb102f1091b89b90672126922f290bd8370eef9a7afc5d9c1e7b5db08c448a0948ef46bf57d850e166813e2d68bf7b1c88a46256d839b6b0201",
61+
"urls" : ["https://lafo.ssw.uni-linz.ac.at/pub/c1visualizer/c1visualizer-1.13-3413409cce0.zip"],
62+
"digest" : "sha512:176dcef9447f1760f70ec4da50b2f742e786fc3db6af9db9d699c303ecfe0e470deb3bb32120123cb93a0073f4f31cecffde2a7860edcf514dce9894d6df25c4",
6363
"packedResource": True,
6464
},
6565

visualizer/C1Visualizer.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Readme for C1Visualizer
2+
3+
4+
# Developing the C1Visualizer
5+
6+
C1Visualizer is based on Netbeans 26 but can be often be worked on with later releases or with any
7+
IDE that supports Maven. Care must be taken not to commmit anything that would keep it from working
8+
with 26 so any automatic changes to property file updates by later NetBeans versions shouldn't be
9+
pushed. The packaged product is built by:
10+
```
11+
cd C1Visualizer
12+
mvn package
13+
```
14+
15+
# Regenerating the cfg file parser
16+
17+
The cfg file parser is based on CoCo/R which hasn't been updated since 2018 and doesn't support
18+
large files. For simplicity, it has been checked in and some bugs with handling of large files were
19+
fixed. It can be regenerated by getting Coco.jar from https://ssw.jku.at/Research/Projects/Coco and
20+
running the following command line. Note that still will overwrite any locals fixes but this should
21+
never be necessary.
22+
23+
```
24+
java -jar Coco.jar -o CompilationModel/src/main/java/at/ssw/visualizer/parser \
25+
-package at.ssw.visualizer.parser CompilationModel/src/main/java/at/ssw/visualizer/parser/CompilerOutput.atg
26+
```
27+
28+
# Releasing a new version
29+
30+
As this is now maven based, `mvn -B release:prepare` is used to update to new versions which will automatically bump the module versions.
31+
32+
The resulting zip file will be in `C1Visualizer/application/target`.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<artifactId>C1Visualizer-parent</artifactId>
5+
<groupId>at.ssw.visualizer</groupId>
6+
<version>1.14-SNAPSHOT</version>
7+
</parent>
8+
<groupId>at.ssw.visualizer</groupId>
9+
<artifactId>BlockView</artifactId>
10+
<version>1.14-SNAPSHOT</version>
11+
<packaging>nbm</packaging>
12+
<name>BlockView</name>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>at.ssw.visualizer</groupId>
19+
<artifactId>VisualizerUI</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>at.ssw.visualizer</groupId>
24+
<artifactId>CompilationModel</artifactId>
25+
<version>${project.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.netbeans.api</groupId>
29+
<artifactId>org-openide-explorer</artifactId>
30+
<version>${netbeans.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.netbeans.api</groupId>
34+
<artifactId>org-openide-loaders</artifactId>
35+
<version>${netbeans.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.netbeans.api</groupId>
39+
<artifactId>org-openide-nodes</artifactId>
40+
<version>${netbeans.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.netbeans.api</groupId>
44+
<artifactId>org-openide-util</artifactId>
45+
<version>${netbeans.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.netbeans.api</groupId>
49+
<artifactId>org-openide-util-lookup</artifactId>
50+
<version>${netbeans.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.netbeans.api</groupId>
54+
<artifactId>org-openide-windows</artifactId>
55+
<version>${netbeans.version}</version>
56+
</dependency>
57+
</dependencies>
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.apache.netbeans.utilities</groupId>
62+
<artifactId>nbm-maven-plugin</artifactId>
63+
<version>${nbmmvnplugin.version}</version>
64+
<extensions>true</extensions>
65+
<configuration>
66+
<publicPackages>
67+
<publicPackage>at.ssw.visualizer.BlockView</publicPackage>
68+
</publicPackages>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-compiler-plugin</artifactId>
74+
<version>${mvncompilerplugin.version}</version>
75+
<configuration>
76+
<source>1.8</source>
77+
<target>1.8</target>
78+
</configuration>
79+
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-jar-plugin</artifactId>
83+
<version>${mvnjarplugin.version}</version>
84+
<configuration>
85+
<!-- to have the jar plugin pickup the nbm generated manifest -->
86+
<archive>
87+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
88+
</archive>
89+
</configuration>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-enforcer-plugin</artifactId>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package at.ssw.visualizer.block.view;
24+
25+
import at.ssw.visualizer.model.cfg.BasicBlock;
26+
import at.ssw.visualizer.model.cfg.ControlFlowGraph;
27+
import java.util.Collections;
28+
import java.util.List;
29+
import javax.swing.table.AbstractTableModel;
30+
31+
/**
32+
* TableModel containing the blocks of the currently selected view
33+
*
34+
* @author Bernhard Stiftner
35+
* @author Christian Wimmer
36+
*/
37+
public class BlockTableModel extends AbstractTableModel {
38+
39+
public static final int BLOCK_TABLE_NAME_COL_IDX = 0;
40+
public static final int BLOCK_TABLE_BCI_COL_IDX = 1;
41+
public static final int BLOCK_TABLE_FLAGS_COL_IDX = 2;
42+
public static final int BLOCK_TABLE_LOOP_DEPTH_COL_IDX = 3;
43+
public static final int BLOCK_TABLE_LOOP_INDEX_COL_IDX = 4;
44+
public static final int BLOCK_TABLE_DOMINATOR_COL_IDX = 5;
45+
public static final int BLOCK_TABLE_PREDECESSORS_COL_IDX = 6;
46+
public static final int BLOCK_TABLE_SUCCESSORS_COL_IDX = 7;
47+
public static final int BLOCK_TABLE_XHANDLERS_COL_IDX = 8;
48+
public static final int BLOCK_TABLE_PROBABILITY_COL_IDX = 9;
49+
50+
public static final String[] COLUMN_NAMES = new String[]{"Name", "BCI", "Flags", "Loop Depth", "Loop Index", "Dominator", "Predecessors", "Successors", "XHandlers", "Probability"};
51+
public static final int[] COLUMN_WIDTHS = new int[]{60, 60, 60, 80, 80, 60, 120, 120, 120};
52+
53+
private List<BasicBlock> blocks = Collections.emptyList();
54+
55+
public void setControlFlowGraph(ControlFlowGraph cfg) {
56+
if (cfg == null) {
57+
blocks = Collections.emptyList();
58+
} else {
59+
blocks = cfg.getBasicBlocks();
60+
}
61+
fireTableDataChanged();
62+
}
63+
64+
public int getRowCount() {
65+
return blocks.size();
66+
}
67+
68+
public int getColumnCount() {
69+
return COLUMN_NAMES.length;
70+
}
71+
72+
@Override
73+
public String getColumnName(int column) {
74+
return COLUMN_NAMES[column];
75+
}
76+
77+
public Object getValueAt(int row, int column) {
78+
BasicBlock block = blocks.get(row);
79+
switch (column) {
80+
case BLOCK_TABLE_NAME_COL_IDX:
81+
return block.getName();
82+
case BLOCK_TABLE_BCI_COL_IDX:
83+
return "[" + block.getFromBci() + ", " + block.getToBci() + "]";
84+
case BLOCK_TABLE_FLAGS_COL_IDX:
85+
return formatFlags(block.getFlags());
86+
case BLOCK_TABLE_LOOP_DEPTH_COL_IDX:
87+
return Integer.toString(block.getLoopDepth());
88+
case BLOCK_TABLE_LOOP_INDEX_COL_IDX:
89+
return block.getLoopDepth() > 0 ? Integer.toString(block.getLoopIndex()) : "";
90+
case BLOCK_TABLE_DOMINATOR_COL_IDX:
91+
return block.getDominator() != null ? block.getDominator().getName() : "";
92+
case BLOCK_TABLE_PREDECESSORS_COL_IDX:
93+
return formatBlocks(block.getPredecessors());
94+
case BLOCK_TABLE_SUCCESSORS_COL_IDX:
95+
return formatBlocks(block.getSuccessors());
96+
case BLOCK_TABLE_XHANDLERS_COL_IDX:
97+
return formatBlocks(block.getXhandlers());
98+
case BLOCK_TABLE_PROBABILITY_COL_IDX:
99+
return Double.isNaN(block.getProbability()) ? "" : (Double)block.getProbability();
100+
default:
101+
throw new Error("invalid column");
102+
}
103+
}
104+
105+
@Override
106+
public Class<?> getColumnClass(int columnIndex) {
107+
if (blocks.isEmpty()) {
108+
return Object.class;
109+
}
110+
return getValueAt(0, columnIndex).getClass();
111+
}
112+
113+
private String formatFlags(List<String> flags) {
114+
StringBuilder sb = new StringBuilder();
115+
String prefix = "";
116+
for (String flag : flags) {
117+
sb.append(prefix).append(flag);
118+
prefix = ", ";
119+
}
120+
return sb.toString();
121+
}
122+
123+
private String formatBlocks(List<BasicBlock> blocks) {
124+
StringBuilder sb = new StringBuilder();
125+
String prefix = "";
126+
for (BasicBlock block : blocks) {
127+
sb.append(prefix).append(block.getName());
128+
prefix = ", ";
129+
}
130+
return sb.toString();
131+
}
132+
}

0 commit comments

Comments
 (0)