Oplægget blev holdt ved et seminar i InfinIT-interessegruppen højniveau sprog til indlejrede systemer den 11. november 2009.
Læs mere om interessegruppen på http://www.infinit.dk/dk/interessegrupper/hoejniveau_sprog_til_indlejrede_systemer/
Tools for static analyses of Java af Hans Søndergaard, ViaUC
1. Tools for static analyses of
Java
• Overview of tools
• Checking a program
• WALA, a tool for writing checkers
• Two examples
p
• Temporary conclusion
Infinit Højniveausprog, 11 November 2009
Hans Søndergaard
1
Workbench for Predictable Java
• Compliance checker
• Memory analyzer
• Execution time analyzer
• Schedulability analysis
2
1
2. Checking a program
• A positive list of allowable classes and methods
– not on positive list:
• class Thread, wait, finalize (?), ..
• synchronized: only synchronized methods allowed
– void method() {
..
synchronized(expr) { ..} // not allowed
..
}
• new
– after initialization, only allowed in handleEvent methods
• no GC
• private memory for each handler
3
Checking a program
• object references
– only from short life objects to long-life objects
short-life long life
• loops
– bounds on all loops
• recursion
– allowed only if it can be controlled
• exception handling
– controlled
t ll d
• ...
4
2
3. Implementation of a Checker
uses
• WALA provides static analysis capabilities for Java bytecode
• WALA features include:
Java type system and class hierarchy analysis
Interprocedural dataflow analysis
Pointer analysis and call graph construction
General framework for iterative dataflow
General analysis utilities and data structures
A dynamic load-time instrumentation library for Java
• open source license
• http://wala.sourceforge.net/wiki/index.php/Main_Page
5
About WALA
• Nearly no documentation
• Difficult to install and start
• Installed on Eclipse
When more familiar with WALA
• analyzing bytecode is an advantage
• many usefull packages
6
3
4. Program example 1
PositiveListChecker
• Scans a list of classes to be checked
• A positive list of classes with methods, must be available
• The result is written in a report file.
Generated report file:
Not on positive list
====================
(type, class, method)
(7, java/lang/Object, null)
(10, hello/NotPositiveClass, staticMethod1)
(7, hello/NotPositiveClass, null)
• 150 lines of code
7
Program example 2
• Check synchronization at block level
– source code
void method() {
..
synchronized(lock) { .. } // not allowed; can undermine the monitor-like
.. // mechanisms
}
– bytecode
monitorenter
...
monitorexit
– checker program
• class SynchBlockChecker
• 60 lines of code
8
4
5. Temporary conclusion
• To begin with WALA is quite difficult to use
• WALA has many features for static
analysis of Java bytecode
• Two examples show that WALA has very
usefull classes for accessing the Java
bytecode
• WALA with its packages seems to be a
good choice when writing a checker
9
5