CiaoPP Demo
Pedro L ´opez-Garc´ıa
1, Edison Mera
2and Teresa Trigo
1(with Manuel Hermenegildo, 1,3,4 J. Navas 3 and M. M ´endez 3)
CLIP Group 1
Fac. Inform ´atica, U. Polit ´ecnica de Madrid 2Fac. Inform ´atica, U. Complutense de Madrid 3
CS and EECE Depts., U. of New Mexico, USA 4IMDEA SW Development Technology Institute
Index
ES PASS
Introduction to CiaoPP
O.S. and development environments Input & Output
CiaoPP under Emacs Graphic interface Examples
1. Fact.java & Fib.java 2. Files.java
3. CellPhone.java
ES PASS Staff
PhD:
Manuel Hermenegildo Salinas Pedro L ´opez-Garc´ıa
Francisco Bueno Carrillo Manuel Carro Linares Student:
Mar´ıa Teresa Trigo de la Vega Collaborator:
ES PASS Roadmap WP3
Main milestones:
T0 + 3 [Finished] D301 UPM Tool survey CiaoPP (initial description of CiaoPP capabilities and limitations).
T0 + 9 [Finished] D3.10.1 Report on the extension of the CiaoPP assertion language to express user-defined resources.
T0 + 15 [Ongoing] D3.10.2 Report on the extension of CiaoPP to infer functions which yield (upper and lower bounds on) execution times of procedures in a program as a function of input data size.
T0 + 15 [Ongoing] D3.10.3 Extended CiaoPP analyzer prototype.
T0 + 21 [Ongoing] D3.10.4 Report on the adaptation of the CiaoPP analyzers to infer both upper and lower bounds on usage of user-defined resources. [Ongoing]
ES PASS Roadmap WP5
Main milestones:
T0 + 24 [Ongoing] D5.1.1 Knowledge database on new static analysis tools and techniques.
T0 + 24 D5.1.2 Calendar of academic and industrial events.
T0 + 12 D5.6.1 b First version of the training material and documentation.
Introduction to CiaoPP
A preprocessor integrated in development environments (emacs, eclipse) Performs error detection, verification, and source-to-source transformations:
Input: program (optionally w/assertions) and libraries (interfaces) Output: error/warning messages + transformed program, with
Results of static checking of assertions / verification (and certificates for Abstraction Carrying Code)
Assertion run-time checking code
High-level optimizations (specialization, slicing, parallelization)
Results of analysis (as assertions): used for low-level optimizations Language support:
Ciao (our CLP-based multiparadigm language) + Java and Java bytecode Underlying technology:
Modular polyvariant abstract interpretation Modular abstract multiple specialization
Introduction. CiaoPP ES PASS Property Coverage
P1: Safe removal of unreachable code
Via (abstract) partial evaluation and slicing
P2: Absence of run-time errors
Null pointer detection Array bounds checking Type inference / checking
P4: Safe estimation for worst-case execution times (WCET)
Upper and lower bound on number of execution steps Upper and lower bounds on execution time
as functions of input data sizes
P6: User-defined functional or safety properties
Upper and lower bounds on usage of a wide class of user-defined resources E.g., bytes sent/received over the Internet, SMSs sent or received, monetary units spent, memory, stack usage, etc
O.S. & development environments
Operating Systems
Distributions for Linux / Unix (32 bits) Windows compatible (32 bits)
64 bits
32 bits Operating System Virtual Machine
• Virtual appliance with Ciao Development environments
Emacs
emacs21
Input & Output
Fibonacci:
Fib.java Fib.pl
package examples: :- module( fib, [ fib/2 ], [ assertions, regtypes, predefres( res arith ), res arith( res arith comp ) ] ).
import soot.resources.Resource;
import soot.resources.annotations.Resources;
@Resources(Resource.STEPS) :- entry fib( X, Y ) : num * var. public class Fib{ fib( 0, 0 ) :- !.
public int fib(int n){ fib( 1, 1 ) :- !. if (n == 0){ fib( M, N ) :-return 0; M1 is M-1, } M2 is M-2, else if (n == 1){ fib( M1, N1 ), return 1; fib( M2, N2 ), } N is N1 + N2 else{
return fib(n - 1) + fib(n - 2);
} } }
Input & Output
Input: program (optionally w/assertions) and libraries (interfaces) Examples of input assertions:
Ciao:
:- entry fib( X, Y ) : num * var. In general:
:- Status pred PredDesc [:PrecC] [=>PostC] [+Comp] Status = [check|true/false|trust|checked|entry]
Java:
import soot.resources.Resource;
import soot.resources.annotations.Resources; @Resources({Resource.STEPS})
Resources: ACCESSES_DB, BYTES_RECEIVED, CLOSED_FILES,
COST_IN_DOLLARS, DATA_STORED, ENERGY_CONSUMED, HEAP_USAGE, OPENED_FILES, SCREEN_WIDTH, SIZE, STACK_USAGE, STEPS
Input & Output
Output: transformed program Examples of output assertions:
Ciao:
:- true pred fib(X,Y) : ( num(X), var(Y) ) => ( num(X), int(Y), size(ub,X,int(X)), size(ub,Y,0.4472135954999579*exp(1.618033988749895,int(X)) -0.4472135954999579*exp(-0.6180339887498949,int(X))) ) + steps_ub(1.447213595499958*exp(1.618033988749895,int(X)) +0.5527864045000421*exp(-0.6180339887498949,int(X))-1.0). Java: /** * true
* if (arg(1)/top && this/top && ret/top) { * arg(1)/top && this/top && ret/top &&
* size(ub,ret,0.4472135954999579*exp(1.618033988749895, * int(arg(1)))-0.4472135954999579*exp(-0.6180339887498949, * int(arg(1)))) && size(ub,this,size(this)) &&
* size(ub,arg(1),int(arg(1))) * } * && cost(ub,STEPS,7.683281572999747*exp(1.618033988749895, * int(arg(1)))+2.316718427000253* * exp(-0.6180339887498949,int(arg(1)))-8.0) */
Input & Output
Input (Fib.java) Output (Fib resources co.java) package examples: package examples:
import soot.resources.Resource; import soot.resources.Resource;
import soot.resources.annotations.Resources; import soot.resources.annotations.Resources; @Resources(Resource.STEPS) @Resources(Resource.STEPS)
public class Fib{ public class Fib{
/** * true
* if (arg(1)/top1&& this/top && ret/top){
* arg(1)/top && this/top && ret/top &&
* size(ub,ret,0.4472135954999579*exp(1.618033988749895,int(arg(1))) * -0.4472135954999579*exp(-0.6180339887498949, int(arg(1)))) * && size(ub,this,size(this)) && size(ub,arg(1),int(arg(1)))
*}
* && cost(ub,STEPS,7.683281572999747*exp(1.618033988749895, int(arg(1))) * +2.316718427000253* exp(-0.6180339887498949,int(arg(1)))-8.0)
*/
public int fib(int n){ public int fib(int n){
if (n == 0){ if (n == 0){ return 0; return 0; } } else if (n == 1){ else if (n == 1){ return 1; return 1; } } else{ else{
return fib(n - 1) + fib(n - 2); return fib(n - 1) + fib(n - 2);
} }
} }
} }
CiaoPP under Emacs. Graphic interface
1. C-c M in the program’s buffer. It loads the graphic interface
2. Menu options:
Select Menu Level: [naive] (naive) ?
Select Action Group: [analyze] (analyze) ?
Select Aliasing-Mode Analysis: [none, java_nullity] (none) ? Select Shape-Type Analysis: [none, java_cha] (none) ?
Select Resource Analysis: [none, resources] (resources) ? Multivariant Success: [off, on] (off) ?
Print Program Point Info: [off, on] (off) ?
Collapse AI Info: [off, on] (on) ?
Note: Current Saved Menu Configurations: [] Menu Configuration Name: (none) ?
Examples: 1. Fact.java & Fib.java
Targets:
To illustrate the functioning of the analyzer To check the correctness of the results Complete modules (without interfaces) Resources: steps of execution
Examples: 2. Files.java
Targets:
To observe how the results depends on the program (change the program and take a look at the new output)
To discover another uses of the resources analysis Complete modules (without interfaces)
Resources: data stored, opened files and closed files
Examples: 3. CellPhone.java
Targets:
To illustrate the behaviour of the analyzer with a commercial example (which is also more complex)
To observe the use of user-defined resources Complete modules (with imported elements) Resources: cost in dollars
Examples: 3. CellPhone.java. Equations
Size: sizeret(Sr0, Sr1, Sr2, Sr3) ≤ 0 if Sr1 = 0 7× Sr1 − 6 + sizeret(Sr0, Sr1 − 1, Sr2, Sr3) if Sr1 > 0 sizeret(Sr0, Sr1, Sr2, Sr3) ≤ 3.5× S 2 r1 − 2.5 × Sr1 Resources: costsendSms(Sr0, Sr1, Sr2, Sr3) ≤ 0 if Sr1 = 0 12 × Sr1 − 12 + costsendSms(Sr0, Sr1 − 1, Sr2, Sr3) if Sr1 > 0 costsendSms(Sr0, Sr1, Sr2, Sr3) ≤ 6× S 2 r1 − 6 ×Sr1Examples: 4. SensorNetworkLoop.java
Targets:
To illustrate the behaviour of the analyzer with an incomplete example (a simple example)
Incomplete modules (with interfaces)
Sizes and costs that can’t be inferred by means of assertions Resources: energy consumed