IntraJ is an application of the language independent framework IntraCFG for the Java language, build as an extension of the ExtendJ Java Compiler. More details can be found in the following paper:
- A Precise Framework for Source-Level Control-Flow Analysis, Idriss Riouak π, Christoph Reichenbach π, GΓΆrel Hedin π and Niklas Fors π. IEEE-SCAM 2021 π.
With IntraJ you can:
- construct intra-procedural Control Flow Graph,
- (DAA) detect Dead assignments in your codebase,
- (IMPDAA) detect Implicit dead assignments in your codebase, and
- (NPA) detect occurences of NullPointerException.
You can run IntraJ on other Java codebases (in Java-4, Java-5, Java-6, Java-7 and Java-8 (WIP)) in order to construct CFGs and get DAA and NPA analysis results.
We have run IntraJ on the following Java version:
- Java SDK version 8. (tested with Java OpenJDK 1.8.0_275. See sdkman).
It is possible to generate PDFs that show the CFGs visually. For this you need:
- Dot (graphiz) - PDF generation
- Vim - PDF generation
- Python3.x with the following dependencies:
- PyPDF2 v1.26.0 - PDF generation
- numpy v1.20.1 - Evaluation and Plots generation
- pandas v1.2.4 - Evaluation and Plots generation
- matplotlib v3.3.4 - Evaluation and Plots generation
- seaborn v0.11.1 - Evaluation and Plots generation
- ipython v7.26.0 - Evaluation and Plots generation
The evaluation script uses sdkman
.
To run the evaluation you need:
-
The scripts
eval.sh
andevaluation/run_eval.sh
usessdkman
. If you don't havesdkman
installed but have Java SDK 8 installed, you can comment all the lines starting withsdk
ineval.sh
and inevaluation/run_eval.sh
. You installsdkman
by running the following commands:curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 7.0.292-zulu sdk use java 7.0.292-zulu
To install all the necessary Python dependencies, you can run the instruction described in the next section.
To clone the IntraJ code, run, in your working directory:
git clone https://github.com/lu-cs-sde/IntraJ.git
Move to the IntraJ directory:
cd IntraJ
To generate all the JARs necessary for the evaluation, execute
./gradlew build
To run all the tests, execute:
./gradlew test
To install Python dependencies, you can execute the following instruction:
cd resources
pip3 install - requirements.txt
The top-level structure of the repository:
.
βββ build # Compiled files
βββ evaluation # Scripts and dependencies for evaluation
βββ extendj # ExtendJ source code
βββ resources # Scripts and logo
βββ src # IntraJ source code
| βββ jastadd
| | βββ CFG # CFG spec in Jastadd
| | βββ DataFlow # Data flow analyses spec
| βββ java
| βββ utils # General helpers for visualisation
| βββ
# JUnit test spec
βββ tools # IntraJ source code
| βββ jastadd-2.3.6-custom # Custom version of Jastadd
βββ testfiles # Automated test files
| βββ DataFlow
| βββ CFG
βββ eval.sh # Evaluation entry point
βββ LICENSE
βββ README.md
The entry point of IntraJ (main) is defined in:
extendj/src/fronted-main/org/extendj/IntraJ.java
.
The directory is structured as follow:
.
βββ antlr-2.7.2 # ANTLR Benchmark (Paper Β§5)
βββ pmd-4.2.5 # PMD Benchmark (Paper Β§5)
βββ jfreechar-1.0.0 # JFC Benchmark (Paper Β§5)
βββ fop-0.95 # FOP Benchmark (Paper Β§5)
βββ Results.xlsx # Analyses results in Excel (Paper Β§5)
βββ Results.htm # Analyses results in HTML
βββ plots.py # Script that generates plots
βββ run_eval.sh # Called by ../eval.sh
βββ YYYYMMDD_HHMMSS # Evaluation results
.
βββ jastadd
βββ CFG
| βββ IntraCFG
| | βββ CFG.ast # Lang-independent nodes
| | βββ IntraCFG.jrag # IntraCFG spec in Jastadd (Paper Β§2.b)
| βββ java4 # (Paper Β§3)
| | βββ Cache.jrag # Cache settings
| | βββ Exception.jrag # Exception spec (Paper Β§3.c)
| | βββ Initializer.jrag # Initializers spec (Paper Β§3.b)
| | βββ Java4.jrag # Java4 spec
| | βββ ImplictNodes.ast # Reified nodes
| βββ java5 # (Paper Β§3)
| | βββ Java5.jrag # Java5 spec
| βββ java7 # (Paper Β§3)
| βββ Java7.jrag # Java7 spec
βββ DataFlow # Data flow analyses spec (Paper Β§4)
βββ Analysis.jrag # Collection attributes
βββ DeadAssignment.jrag # DAA spec (Paper Β§4.c)
βββ LiveVariableAnalysis.jrag # LVA spec (Paper Β§4.b)
βββ NullAnalysis.jrag # NPE sepc (Paper Β§4.a)
There is no subdirectory for java6 , since features introduced in Java 6 do not affect the construction of the CFG. |
-help
: prints all the available options.-genpdf
: generates a pdf with AST structure of all the methods in the analysed files. It can be used combined with-succ
,-pred
.-succ
: generates a pdf with the successor relation for all the methods in the analysed files. It can be used combined with-pred
.-pred
: generates a pdf with the predecessor relation for all the methods in the analysed files. It can be used combined with-succ
.-statistics
: prints the number of CFGRoots, CFGNodes and CFGEdges in the analysed files.-nowarn
: the warning messages are not printed.
-------------- ANALYSIS OPTIONS --------------------
Available analyses:
DAA
: Detects unused dead assignmentsNPA
: Detects occurrences of Null Pointer Dereferencing
Options (where id
corresponds to one of the analyses above):
-Wid
: enable a given analysis, e.g.,-WDAA
-Wall
: enables all the available analyses-Wexcept=id
: enable all the available analyses exceptid
, e.g.,-Wexcept=DAA
Suppose you would like to analyze a file Example.java
located in your workspace:
public class Example {
int example() {
Integer m = null;
m.toString();
int x = 0;
x = 1;
return x;
}
}
By running the following command:
java -jar intraj.jar PATH/TO/Example.java -Wall -succ -statistics
IntraJ will print the following information
[NPA - PATH/TO/Example.java:4,4] The object 'm' may be null at this point.
[DAA - PATH/TO/Example.java:5,9] The value stored in 'x' is never read.
[INFO]: CFG rendering
[INFO]: DOT to PDF
[INFO]: PDF file generated correctly
[STATISTIC]: Elapsed time (CFG + Dataflow): 0.11s
[STATISTIC]: Total number
[STATISTIC]: Number roots:3
[STATISTIC]: Number CFGNodes:16
[STATISTIC]: Number Edges:13
[STATISTIC]: Largest CFG in terms of nodes:12
[STATISTIC]: Largest CFG in terms of edges:11
And the following PDF is generated:
- π **IntraJ-LSP: repository for the Language Server Protocol (LSP) implementation of IntraJ.
- π **CodeProber: live inspection of IntraJ's attributes in CodeProber.
- π IntraJSCAM2021: repository submitted for Artifact Evaluation (SCAM2021) (control-flow analysis for Java)
- π IntraCFG: main repository for IntraCFG (language-independent framework for control-flow analysis)
- π JastAdd: meta-compilation system that supports Reference Attribute Grammars. We used a custom JastAdd version which better supports interfaces.
- π ExtendJ: extensible Java compiler built using JastAdd. We built IntraJ as an Static Analysis Extension of ExtendJ. More can be found here.
- π SonarQube: platform developed by SonarSource for continuous inspection of code quality
- π JastAddJ-Intraflow: An earlier approach to implementing intra-procedural control flow, dataflow, and dead assignment analysis for Java, also using JastAdd.