Modularizing Error Recovery Jeeva Paudel, Christopher Dutchyn Department of Computer Science September 23, 2009
UNIVERSITY OF SASKATCHEWAN
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
1
Error Handling
Introduction
Error Handling
U of S
Defines behavior in unintended situations Difficulties identifying all potential sources of errors new sources of errors emerge as software development progresses as requirements change
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
2
Error Handling
Introduction
Error Handling in Compilers
U of S
Current compiler implementations fail to: explicitly identify the error-related control dependencies separately characterize the actions to take when programming errors are detected
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
3
Error Handling
Structure
Poor Modularity in Error Handling
U of S
+),#-%'()*%' 0*1%+
?%B=/($+C&($3D%-+
23#%45($.('*-67+8+ +++9+ ++:($.%45($.('*-67+8+
;(-E%-+
+++9+
4--*-+>(&1$=&@+E/(<%-E++ 'J-*.@J*.'+1=K%-%&'+ "*1.$%E++
;-%<3;-=&'%-67+8+ 4--*-+ >(&1$%-+
,%"(&)/+ C&($3D%-+
,3"A*$+2(A$%+ ?*(1%-+
!&'%-"%1=('%+6!F7+ G*1%+H%&%-('*-+ !F+G*1%+ I#)"=D%-+ 2(-@%'+G*1%+ H%&%-('*-+
++9+
,."0*1%+ 23#%45($.('*-67+8+
;-*1./'0*1%+ 23#%45($.('*-67+8+
+++9+ :($.%45($.('*-67+8+
+++9+
+++9+
+++9+ ;-%<3;-=&'%-67+8+
;-%<3;-=&'%-67+8+ ++9+
:($.%45($.('*-67+8+
+9+
4--*-++ >(&1$%-+ ,3"A*$+2(A$%+ ?*(1%-+ ?*@@%-+
!"#$%&'()*%'
?*@=/($+,'-./'.-%+ Jeeva Paudel, ICSM’09, Edmonton
!"#$%"%&'()*&+,'-./'.-%+ Modularizing Error Recovery
4
Error Handling
Structure
Poor Modularity in Error Handling
U of S
+),#-%'()*%' 0*1%+
?%B=/($+C&($3D%-+
23#%45($.('*-67+8+ +++9+ ++:($.%45($.('*-67+8+
;(-E%-+
+++9+
4--*-+>(&1$=&@+'(&@$%E+ J='K+E3"A*$+'(A$%+ $*(1=&@+*#%-()*&+
;-%<3;-=&'%-67+8+ 4--*-+ >(&1$%-+
,%"(&)/+ C&($3D%-+
,3"A*$+2(A$%+ ?*(1%-+
!&'%-"%1=('%+6!F7+ G*1%+H%&%-('*-+ !F+G*1%+ I#)"=D%-+ 2(-@%'+G*1%+ H%&%-('*-+
++9+
,."0*1%+ 23#%45($.('*-67+8+
;-*1./'0*1%+ 23#%45($.('*-67+8+
+++9+ :($.%45($.('*-67+8+
+++9+
+++9+
+++9+ ;-%<3;-=&'%-67+8+
;-%<3;-=&'%-67+8+ ++9+
:($.%45($.('*-67+8+
+9+
4--*-++ >(&1$%-+ ,3"A*$+2(A$%+ ?*(1%-+ ?*@@%-+
!"#$%&'()*%'
?*@=/($+,'-./'.-%+ Jeeva Paudel, ICSM’09, Edmonton
!"#$%"%&'()*&+,'-./'.-%+ Modularizing Error Recovery
5
Error Handling
Problems
Problems
U of S
Problem – 1 cross-cutting code scattering tangling
Jeeva Paudel, ICSM’09, Edmonton
Problem – 2 Non-intuitive information sites control dependencies
Modularizing Error Recovery
6
Error Handling
Problems
Problems
U of S
Problem – 1 cross-cutting code scattering tangling
Jeeva Paudel, ICSM’09, Edmonton
Problem – 2 Non-intuitive information sites control dependencies
Modularizing Error Recovery
6
Error Handling
Related Work
Other Approaches
U of S
Aspects
Compartments Robillard et al. (2000)
Lopes et al. (2000) Colyer et al. (2003)
Filho et al. (2006, 2007)
Exception Flow Channels Cacho et al (2008)
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
7
Error Handling
Plans and Goals
Research Plans and Goals
U of S
Plan Modularize error handling not only exception handling
explicitly identify sites contexts control flows
Goals improved comprehensibility increased re-usability
=⇒ extension points for error recovery
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
8
Error Handling
Plans and Goals
Errors vs. Exceptions
Errors Expected but undesired Never propagated Usually fatal
U of S
Exceptions Runtime errors Assist the flow of an application Not unconditionally fatal
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
9
Tool Support
Needs For Improved Modularity
U of S
Mechanisms to capture cross-cutting concerns declare control dependencies Aspect Oriented Programming (AOP)
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
10
Tool Support
Needs For Improved Modularity
U of S
Mechanisms to capture cross-cutting concerns declare control dependencies Aspect Oriented Programming (AOP)
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
10
Tool Support
AOP
Aspect Oriented Programming Components
U of S
!"#$%&' !-23%$' 1
Join point model join points pointcuts advices
2
()&$*+&,#$' -$%./*/01)'
413)&%5&' !"#$%&'()"*'
$45'6'7'89' :'
Inter-type declarations
3)$4'1)$45' +,)-'./012'
:'
Figure: AOP Components
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
11
Tool Support
AspectJ Constructs
Modularity with AOP: Pointcuts and Advice /∗ P o i n t c l a s s ∗/ class Point { ... v o i d setX ( i n t x ) { this .x = x; D i s p l a y . update ( ) ; } v o i d setY ( i n t y ) { this .y = y; D i s p l a y . update ( ) ; } } /∗ L i n e c l a s s ∗/ class Line { P o i n t p1 , p2 ; ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; D i s p l a y . update ( ) ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; D i s p l a y . update ( ) ; } }
/∗ T r i a n g l e c l a s s ∗/ class Triangle { P o i n t p1 , p2 , p3 ; ... ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; D i s p l a y . update ( ) ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; D i s p l a y . update ( ) ; } v o i d setP3 ( P o i n t p3 ) { t h i s . p3 = p3 ; D i s p l a y . update ( ) ; } v o i d moveBy ( i n t dx , i n t dy ) { ... i f ( dx ! = 0 && dy ! = 0 ) { D i s p l a y . update ( ) ; } } }
Jeeva Paudel, ICSM’09, Edmonton
U of S
aspect D i s p l a y U p d a t e r { /∗∗ ∗ Pointcuts i d e n t i f y i n g places ∗ f o r d i s p l a y update ∗/ pointcut displayUpdateSites ( ) : c a l l ( v o i d T r i a n g l e . setP1 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP2 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP3 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP1 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP2 ( P o i n t ) ) | | c a l l ( v o i d P o i n t . setX ( i n t ) ) | | c a l l ( v o i d P o i n t . setY ( i n t ) ) ) ;
}
Modularizing Error Recovery
12
Tool Support
AspectJ Constructs
Modularity with AOP: Pointcuts and Advice /∗ P o i n t c l a s s ∗/ class Point { ... v o i d setX ( i n t x ) { this .x = x; D i s p l a y . update ( ) ; } v o i d setY ( i n t y ) { this .y = y; D i s p l a y . update ( ) ; } } /∗ L i n e c l a s s ∗/ class Line { P o i n t p1 , p2 ; ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; D i s p l a y . update ( ) ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; D i s p l a y . update ( ) ; } }
/∗ T r i a n g l e c l a s s ∗/ class Triangle { P o i n t p1 , p2 , p3 ; ... ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; D i s p l a y . update ( ) ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; D i s p l a y . update ( ) ; } v o i d setP3 ( P o i n t p3 ) { t h i s . p3 = p3 ; D i s p l a y . update ( ) ; } v o i d moveBy ( i n t dx , i n t dy ) { ... i f ( dx ! = 0 && dy ! = 0 ) { D i s p l a y . update ( ) ; } } }
Jeeva Paudel, ICSM’09, Edmonton
U of S
aspect D i s p l a y U p d a t e r { /∗∗ ∗ Pointcuts i d e n t i f y i n g places ∗ f o r d i s p l a y update ∗/ pointcut displayUpdateSites ( ) : c a l l ( v o i d T r i a n g l e . setP1 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP2 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP3 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP1 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP2 ( P o i n t ) ) | | c a l l ( v o i d P o i n t . setX ( i n t ) ) | | c a l l ( v o i d P o i n t . setY ( i n t ) ) ) ;
}
Modularizing Error Recovery
12
Tool Support
Modularity with AOP
Modularity with AOP: Pointcuts and Advice /∗ P o i n t c l a s s ∗/ class Point { ... v o i d setX ( i n t x ) { this .x = x; } v o i d setY ( i n t y ) { this .y = y; }
/∗ T r i a n g l e c l a s s ∗/ class Triangle { P o i n t p1 , p2 , p3 ; ... ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ;
} v o i d setP3 ( P o i n t p3 ) { t h i s . p3 = p3 ;
/∗ L i n e c l a s s ∗/ class Line { P o i n t p1 , p2 ; ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; }
}
aspect D i s p l a y U p d a t e r { /∗∗ ∗ Pointcuts i d e n t i f y i n g places ∗ f o r d i s p l a y update ∗/ pointcut displayUpdateSites ( ) : c a l l ( v o i d T r i a n g l e . setP1 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP2 ( P o i n t ) ) | | c a l l ( v o i d T r i a n g l e . setP3 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP1 ( P o i n t ) ) | | c a l l ( v o i d L i n e . setP2 ( P o i n t ) ) | | c a l l ( v o i d P o i n t . setX ( i n t ) ) | | c a l l ( v o i d P o i n t . setY ( i n t ) ) ) ;
} v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ;
}
}
} v o i d moveBy ( i n t dx , i n t dy ) { ... i f ( dx ! = 0 && dy ! = 0 ) { D i s p l a y . update ( ) ; } }
Jeeva Paudel, ICSM’09, Edmonton
U of S
}
/∗∗ ∗ Advice e x e c u t i n g d i s p l a y update ∗ a c t i o n a t chosen s i t e s ∗/ a f t e r ( ) returning : displayUpdateSites ( ) { D i s p l a y . update ( ) ; }
Modularizing Error Recovery
13
Tool Support
Modularity with AOP
Modularity with AOP: Capturing Context /∗ P o i n t c l a s s ∗/ class Point { ... v o i d setX ( i n t x ) { this .x = x; } v o i d setY ( i n t y ) { this .y = y; }
/∗ T r i a n g l e c l a s s ∗/ class Triangle { P o i n t p1 , p2 , p3 ; ... ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ; } v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ;
}
} v o i d setP3 ( P o i n t p3 ) { t h i s . p3 = p3 ;
/∗ L i n e c l a s s ∗/ class Line { P o i n t p1 , p2 ; ... v o i d setP1 ( P o i n t p1 ) { t h i s . p1 = p1 ;
} v o i d moveBy ( i n t dx , i n t dy ) { ... i f ( dx ! = 0 && dy ! = 0 ) {
} v o i d setP2 ( P o i n t p2 ) { t h i s . p2 = p2 ; }
}
}
}
U of S
aspect DisplayUpdaterForMoveBy { /∗∗ ∗ Pointcuts i d e n t i f y i n g c a l l to ∗ d i s p l a y update w i t h i n T r i a n g l e ∗/ p o i n t c u t moveBySite ( i n t dx , i n t dy ) : c a l l ( v o i d T r i a n g l e . moveBy ( i n t , i n t ) ) && args ( dx , dy ) && i f ( dx ! = 0 && dy ! = 0 ) ;
}
/∗∗ ∗ Advice t o execute d i s p l a y update ∗ a c t i o n f o r chosen s i t e ∗/ a f t e r ( i n t dx , i n t dy ) r e t u r n i n g : moveBySite ( dx , dy ) { D i s p l a y . update ( ) ; }
}
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
14
Error Handling
Implementation
Error Recovery Aspects
U of S
1
Parsing of AspectJ constructs
2
Creation of shadows for type mungers
3
Type resolution
4
Enforcement of type munging rules
5
Context bindings in pointcuts
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
15
Error Handling Modularization
An Example
Example: IncompatibleReturnType Error /∗ Simple P o i n t c l a s s ∗/ class Point { i n t x = 0 , y = 0; v o i d move ( i n t dx , i n t dy ) { x += dx ; y += dy ; } i n t getX ( ) { return x ; } i n t getY ( ) { return y ; } } /∗∗ Simple P o i n t c l a s s s u p p o r t i n g ∗ r e a l v a l u e s f o r x and y ∗/ class RealPoint { f l o a t x = 0.0 f , y = 0.0 f ; v o i d move ( f l o a t dx , dy ) { x += dx ; y += dy ; } }
U of S
/∗∗ Aspect t h a t i n t r o d u c e s R e a l P o i n t ∗ as a sub−t y p e o f P o i n t ∗/ p u b l i c aspect ClassExtender { declare parents : R e a l P o i n t extends P o i n t ; p u b l i c f l o a t R e a l P o i n t . getX ( ) { return x ; } p u b l i c f l o a t R e a l P o i n t . getY ( ) { return y ; } }
Error can’t override java.lang.int Point.getX() with java.lang.float RealPoint.getX() – return types don’t match
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
16
Error Handling Modularization
An Example
Example: IncompatibleReturnType Error /∗ Simple P o i n t c l a s s ∗/ class Point { i n t x = 0 , y = 0; v o i d move ( i n t dx , i n t dy ) { x += dx ; y += dy ; } i n t getX ( ) { return x ; } i n t getY ( ) { return y ; } } /∗∗ Simple P o i n t c l a s s s u p p o r t i n g ∗ r e a l v a l u e s f o r x and y ∗/ class RealPoint { f l o a t x = 0.0 f , y = 0.0 f ; v o i d move ( f l o a t dx , dy ) { x += dx ; y += dy ; } }
U of S
/∗∗ Aspect t h a t i n t r o d u c e s R e a l P o i n t ∗ as a sub−t y p e o f P o i n t ∗/ p u b l i c aspect ClassExtender { declare parents : R e a l P o i n t extends P o i n t ; p u b l i c f l o a t R e a l P o i n t . getX ( ) { return x ; } p u b l i c f l o a t R e a l P o i n t . getY ( ) { return y ; } }
Error can’t override java.lang.int Point.getX() with java.lang.float RealPoint.getX() – return types don’t match
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
16
Error Handling Modularization
Modularization Example
Pointcut: IncompatibleReturnType Error Handling
U of S
aspect I n c o r r e c t S u b T y p e D e t e c t o r { /∗∗ ∗ P o i n t c u t s i d e n t i f y i n g p l a c e s which ∗ handle I n c omp at i ble Ret u r n Typ e e r r o r ∗/ p o i n t c u t c h e c k C o m p a t i b i l i t y O f R e t u r n T y p e s ( BcelWeaver weaver , ResolvedMember superMethod , LazyMethodGen subMethod ) : e x e c u t i o n (∗ ∗. enforceDecpRule4_compatibleReturnTypes ( BcelWeaver , ResolvedMember , LazyMethodGen ) ) && args ( weaver , superMethod , subMethod ) ;
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
17
Error Handling Modularization
Modularization Example
Advice: IncompatibleReturnType Error Handling
U of S
/∗∗ ∗ Advice t o handle I nc omp ati b le Re tu r n T yp e e r r o r ∗/ O b j e c t around ( BcelWeaver weaver , ResolvedMember superMethod , LazyMethodGen subMethod ) : c h e c k C o m p a t i b i l i t y O f R e t u r n T y p e s ( weaver , superMethod , subMethod ) { ResolvedType subRetType = subMethod . getReturnType ( ) ; ResolvedType superRetType = superMethod . getReturnType ( ) ; if
( ! superRetType . equals ( subRetType ) ) { ResolvedType subType = weaver . getWorld ( ) . r e s o l v e ( subRetType ) ; ResolvedType superType = weaver . getWorld ( ) . r e s o l v e ( superRetType ) ; i f ( ! superType . isAssignableFrom ( subType ) ) { / / Generate e r r o r message S t r i n g msg = generateLocalizedMessage ( "..." , . . . ) ;
}
}
r e t u r n msg ; } } r e t u r n proceed ( weaver , superMethod , subMethod ) ;
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
18
Error Handling Modularization
Reuse and Evolution
Recovery from IncompatibleReturnType Error
U of S
/∗∗ ∗ Advice t o r e c o v e r from I nc o m p a ti b le Re tu r n T yp e e r r o r ∗/ O b j e c t around ( BcelWeaver weaver , ResolvedMember superMethod , LazyMethodGen subMethod ) : c h e c k C o m p a t i b i l i t y O f R e t u r n T y p e s ( weaver , superMethod , subMethod ) { ResolvedType subRetType = subMethod . getReturnType ( ) ; ResolvedType superRetType = superMethod . getReturnType ( ) ; if
( ! superRetType . equals ( subRetType ) ) { ResolvedType subType = weaver . getWorld ( ) . r e s o l v e ( subRetType ) ; ResolvedType superType = weaver . getWorld ( ) . r e s o l v e ( superRetType ) ; i f ( ! superType . isAssignableFrom ( subType ) ) { / / Acceptable D e f a u l t ResolvedMember newSubMethod = new Method ( . . . ) ;
}
}
r e t u r n proceed ( weaver , superMethod , newSubMethod ) ; } } r e t u r n proceed ( weaver , superMethod , subMethod ) ;
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
19
Error Handling Modularization
Evaluation
Error Handling Modularity: Before
U of S
"&
% #$
!" '()(*+,& •!!-./0&/1-12(+&314(5&.2(&/-.55(5& •!61-12(+&57289(5&.2(&+8:(2(*7& )21;95&1<&2(-.7(+&(22125&
Overall, 0.5 – 2% increase in compilation time. Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
20
Error Handling Modularization
Evaluation
Error Handling Modularity: After
U of S
%&
#$ !" '&
?&13+1)4+7&4)@0:+& #3&5)&@3,=/04:A),&
'& ?&
'&
?&13+1)4+7&04)& 7);0409),&3=9& ()*)+,-& •!./012&13/34),&536)7&04)&1/077)7& •!83/34),&794:;)7&04)&,:<)4)+9& *43=;7&3>&4)/09),&)44347&
Overall, 0.5 – 2% increase in compilation time. Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
21
Error Handling Modularization
Evaluation
Error Handling Modularity: After
U of S
%&
#$ !" '&
?&13+1)4+7&4)@0:+& #3&5)&@3,=/04:A),&
'& ?&
'&
?&13+1)4+7&04)& 7);0409),&3=9& ()*)+,-& •!./012&13/34),&536)7&04)&1/077)7& •!83/34),&794:;)7&04)&,:<)4)+9& *43=;7&3>&4)/09),&)44347&
Overall, 0.5 – 2% increase in compilation time. Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
21
Summary
Summary
U of S
Explicitly identified the source and location of error handlers Extracted error handlers scattered and tangled across different classes into aspects Developed easy extension points for error recovery without any significant performance overhead with increased re-usability and comprehensibility
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
22
Summary
Future Work
U of S
Exposing join points access local contexts nested within loops and branches
Implement further recovery tasks
Questions?
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
23
Summary
Future Work
U of S
Exposing join points access local contexts nested within loops and branches
Implement further recovery tasks
Questions?
Jeeva Paudel, ICSM’09, Edmonton
Modularizing Error Recovery
23