Build it yourself
IntraJ is an open-source project, which means you can build it yourself and customize it to your specific needs. In this section, we will guide you through the process of building IntraJ from source and provide information on how to customize its configuration.
Prerequisites
We have run IntraJ on the following Java version:
- Java SDK version 8. (tested with SDK 8.0.292-zulu. 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
To install all the necessary Python dependencies, you can run the instruction described in the next section.
Build
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
Python Dependencies
To install Python dependencies, you can execute the following instruction:
cd resources
pip3 install - requirements.txt
Repository overview
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 evaluation folder
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
The jastadd folder
.
└── 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) ---
⚠️ Note |
---|
There is no subdirectory for java6 , since features introduced in Java 6 do not affect the construction of the CFG. |
Available options to IntraJ:
-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
Example of running IntraJ
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:
Related repository repositories/links 🔗
- 🗄 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.