EXAM

System Validation
(192140122)
13:45 - 17:15
02-07-2012
• The exercises are worth a total of 100 points.
The final grade for the course is
(hw
1
+hw
2
)/2+exam/10
2
, provided that you obtain at least 50
points for the exam (otherwise, the final grade for the course is a 4).
• The exam is open book: all paper copies of slides, papers, notes etc. are allowed.
Exercise 1: Formal Tools and Techniques (10 points)
Suppose you are asked to be a consultant for a team developing a flight control system for a space
craft. The team has 1 engineer who is well-trained in the use of formal methods. This person has
practical experience with many different formal techniques. The other team members are well-skilled
programmers, with a good understanding of the application domain, but without any knowledge of
formal methods.
A prototype for the flight control system exists, but has not been tested yet, and it is likely to
contain bugs. The deadline for the completion of the flight control system is in a month from now
(and no extensions are possible). The flight control system has to fulfill strong requirements. In
particular, the space craft should always remain controllable, so that the astronauts can get back to
Earth.
Give a short description (no more than 200-250 words) of your advice to this team.
Exercise 2: Specification (15 points)
Write formal specifications for the following informal requirements in an appropriate specification
formalism of your choice (3 points per item). You may assume that appropriate atomic propositions,
query methods and classes exist.
a You can only open a file when it is closed.
b All doors of a plane must be closed when the plane is flying.
c If you role a dice, the outcome is always between 1 and 6.
d You are only allowed to live in a country as long as your passport is valid.
e For a calendar system : the month always follow the sequence January → February → March
. . . December → January → February . . ..
NB There is no need to spell out all 12 cases, as long as the general idea of your specification
is clear.
1
Exercise 3: Abstraction (8 points)
Consider interface GameCharacter and two classes implementing this interface: Giant and Growing-
Dwarf (on the next page).
The interface GameCharacter is intended to model a character that can move along a horizontal
axis. Initially it starts at position 0, and then it can move left or right. (NB, it is thus okay that
position becomes negative).
Different game character implementations can make steps of different sizes, i.e., a giant always
makes steps of 10 units, while the step size of the growing dwarf increases with every step he makes.
Write an abstract specification for GameCharacter, modelling the intended behaviour of stepLeft
and stepRight. Then add sufficient specifications to Giant and GrowingDwarf in order to show
that these implementations respect your specification of GameCharacter.
2
1 package a b s t r a c t i o n ;
2
3 p u b l i c i n t e r f a c e GameCharacter {
4
5 p u b l i c voi d s t e p Le f t ( ) ;
6
7 p u b l i c voi d s t e pRi ght ( ) ;
8 }
1 package a b s t r a c t i o n ;
2
3 p u b l i c c l a s s Gi ant i mpl ement s GameCharacter {
4
5 p r i v a t e i n t pos = 0;
6
7 p u b l i c voi d s t e p Le f t ( ) {
8 pos = pos − 10;
9 }
10
11 p u b l i c voi d s t e pRi ght ( ) {
12 pos = pos + 10;
13 }
14 }
1 package a b s t r a c t i o n ;
2
3 p u b l i c c l a s s Growi ngDwarf i mpl ement s GameCharacter {
4
5 p r i v a t e i n t pos = 0;
6 p r i v a t e i n t s t e ps t a k e n = 0;
7
8 p u b l i c voi d s t e p Le f t ( ) {
9 pos = pos − s t e ps t a k e n ;
10 s t e ps t a k e n++;
11 }
12
13 p u b l i c voi d s t e pRi ght ( ) {
14 pos = pos + s t e ps t a k e n ;
15 s t e ps t a k e n++;
16 }
17 }
3
Exercise 4: Run-time Checking (15 points)
Each subquestion is worth 3 points. Explain your answers (without explanation no points will be
awarded).
a Consider class Computation. What will happen when the JML run-time checker is used to
validate this class?
1 package r c ;
2
3 p u b l i c c l a s s Computati on {
4
5 /∗@ s p e c p u b l i c ∗/ p r i v a t e i n t v a l ;
6
7 /∗@ e ns ur e s v a l == \ ol d ( v a l ) ∗ \ ol d ( v a l ) ;
8 ∗/
9 p u b l i c voi d compute ( ) {
10 v a l = 2 ∗ v a l ;
11 }
12
13 p u b l i c s t a t i c voi d mai n ( St r i ng [ ] ar gs ) {
14 Computati on c = new Computati on ( ) ;
15 c . compute ( ) ;
16 }
17 }
4
b Consider class Screen. What will happen when the JML run-time checker is used to validate
this class?
1 package r c ;
2
3 p u b l i c c l a s s Scr een {
4
5 /∗@ s p e c p u b l i c ∗/ i n t x s i z e ;
6 /∗@ s p e c p u b l i c ∗/ i n t y s i z e ;
7
8 //@ i n v a r i a n t ( x s i z e % 2) == 0;
9 //@ i n v a r i a n t ( y s i z e % 2) == 0;
10
11 p u b l i c voi d updat eScr een ( ) {
12 }
13
14 p u b l i c voi d updat e Hor i z ont al ( ) {
15 x s i z e ++;
16 updat eScr een ( ) ;
17 x s i z e ++;
18 updat eScr een ( ) ;
19 }
20
21 p u b l i c s t a t i c voi d mai n ( St r i ng [ ] ar gs ) {
22 Scr een s = new Scr een ( ) ;
23 s . updat eScr een ( ) ;
24 s . updat e Hor i z ont al ( ) ;
25 }
26 }
5
c Consider class Game. What will happen when the JML run-time checker is used to validate
this class?
1 package r c ;
2
3 c l a s s Pl ay e r {}
4
5 p u b l i c c l a s s Game {
6
7 /∗@ s p e c p u b l i c ∗/ p r i v a t e Pl ay e r pl a y e r 1 = new Pl ay e r ( ) ;
8 /∗@ s p e c p u b l i c ∗/ p r i v a t e Pl ay e r pl a y e r 2 = new Pl ay e r ( ) ;
9
10 //@ i n v a r i a n t pl a y e r 1 != pl a y e r 2 ;
11
12 p u b l i c voi d b a t t l e ( ) {
13 warmUp( pl a y e r 1 ) ;
14 warmUp( pl a y e r 2 ) ;
15 f i g h t ( ) ;
16 }
17
18 /∗@ r e q u i r e s pl a y e r 1 != pl a y e r 2 ;
19 e ns ur e s f a l s e ;
20 s i g n a l s ( Except i on ) f a l s e ;
21 ∗/
22 p u b l i c voi d f i g h t ( ) {
23 }
24
25 p u b l i c voi d warmUp( Pl ay e r p){
26 }
27
28 p u b l i c s t a t i c voi d mai n ( St r i ng [ ] ar gs ) {
29 Game g = new Game ( ) ;
30 g . b a t t l e ( ) ;
31 }
32 }
6
d Consider class Student. What will happen when the JML run-time checker is used to validate
this class?
1 package r c ;
2 i mpor t j av a . u t i l . HashMap ;
3 i mpor t j av a . u t i l . Map;
4
5 p u b l i c c l a s s St udent {
6
7 p u b l i c s t a t i c f i n a l i n t numCourses = 35;
8 /∗@ s p e c p u b l i c ∗/ p r i v a t e i n t [ ] gr ade s = new i n t [ numCourses ] ;
9
10 //@ i n v a r i a n t gr ade s != n u l l ;
11 /∗@ i n v a r i a n t (\ f o r a l l i n t i ; 0 <= i && i < numCourses ;
12 0 <= gr ade s [ i ] && gr ade s [ i ] <= 10) ;
13 ∗/
14
15 /∗@ r e q u i r e s 0 <= gr ade && gr ade <= 10;
16 r e q u i r e s 0 <= c our s e && c our s e < numCourses ;
17 e ns ur e s gr ade s [ c our s e ] == gr ade ;
18 ∗/
19 p u b l i c voi d newRes ul t ( i n t cour s e , i n t gr ade ) {
20 gr ade s [ c our s e ] = gr ade ;
21 }
22
23 p u b l i c s t a t i c voi d mai n ( St r i ng [ ] ar gs ) {
24 St udent s = new St udent ( ) ;
25 s . newRes ul t ( 22 , 86) ;
26 }
27 }
7
e Consider class Resources. What will happen when the JML run-time checker is used to
validate this class?
1 package r c ;
2
3 c l a s s Thi ng {
4 //@ p u b l i c s t a t i c ghos t i n t count Thi ngs= 0;
5
6 //@ e ns ur e s count Thi ngs == \ ol d ( count Thi ngs ) + 1;
7 p u b l i c Thi ng ( ) {
8 //@ s e t count Thi ngs = count Thi ngs + 1;
9 }
10
11 }
12
13 p u b l i c c l a s s Res our ces {
14
15 p u b l i c s t a t i c f i n a l i n t MAX = 26;
16
17 //@ i n v a r i a n t Thi ng . count Thi ngs <= MAX;
18
19 /∗@ r e q u i r e s p > 0;
20 e ns ur e s Thi ng . count Thi ngs == \ ol d ( Thi ng . count Thi ngs ) + p ;
21 ∗/
22 p u b l i c voi d makeThi ngs ( i n t p) {
23 Thi ng [ ] s t or a ge = new Thi ng [ p ] ;
24 //@ l o o p i n v a r i a n t 0 <= i && i <= s t or a ge . l e ngt h ;
25 /∗@ l o o p i n v a r i a n t Thi ng . count Thi ngs ==
26 \ ol d ( Thi ng . count Thi ngs ) + i ;
27 ∗/
28 f o r ( i n t i = 0; i < s t or a ge . l e ngt h ; i ++) {
29 new Thi ng ( ) ;
30 }
31 }
32
33 p u b l i c s t a t i c voi d mai n ( St r i ng [ ] ar gs ) {
34 Res our ces r= new Res our ces ( ) ;
35 r . makeThi ngs ( 1 3 ) ;
36 }
37 }
8
Exercise 5: Static Checking (15 points)
Subquestions a, b, c are worth 3 points, subquestion d is worth 6 points. Explain your answers
(without explanation no points will be awarded).
a Consider again class Resources from exercise 4e. What will happen when ESC/Java is used
to validate this class.
9
b Consider class Channel. Add a loop invariant.
1 package s c ;
2
3 c l a s s I nput Ex c e pt i on e xt e nds Except i on {}
4 c l a s s Not EnoughI nput Except i on e xt e nds Except i on {}
5
6 c l a s s Token{}
7
8 p u b l i c c l a s s Channel {
9
10 /∗@ s p e c p u b l i c ∗/ p r i v a t e Token [ ] channel = new Token [ 4 ] ;
11 /∗@ s p e c p u b l i c ∗/ p r i v a t e i n t [ ] pr oc e s s e d = new i n t [ 4 ] ;
12
13 //@ i n v a r i a n t channel != n u l l ;
14 //@ i n v a r i a n t pr oc e s s e d != n u l l ;
15
16 /∗@ pur e ∗/ p u b l i c bool ean i l l e g a l To k e n ( Token s ) {
17 r e t ur n f a l s e ;
18 }
19
20 /∗@ pur e ∗/ p u b l i c i n t pr oc e s s ( Token s ) {
21 r e t ur n 0;
22 }
23
24 /∗@ r e q u i r e s n > 0;
25 e ns ur e s (\ f o r a l l i n t i ; 0 <= i && i < n ;
26 pr oc e s s e d [ i ] == pr oc e s s ( channel [ i ] ) ) ;
27 s i g n a l s ( Not EnoughI nput Except i on ) f a l s e ;
28 s i g n a l s ( I nput Ex c e pt i on ) f a l s e ;
29 ∗/
30 p u b l i c voi d r eadTokens ( i n t n) t hr ows Not EnoughI nput Except i on ,
31 I nput Ex c e pt i on {
32 i f ( n > channel . l e ngt h ) {
33 throw new Not EnoughI nput Except i on ( ) ;
34 }
35 pr oc e s s e d = new i n t [ n ] ;
36 f o r ( i n t i = 0; i < pr oc e s s e d . l e ngt h ; i ++) {
37 i f ( i l l e g a l To k e n ( channel [ i ] ) ) {
38 throw new I nput Ex c e pt i on ( ) ;
39 }
40 e l s e pr oc e s s e d [ i ] = pr oc e s s ( channel [ i ] ) ;
41 }
42 }
43 }
10
c Assuming that your loop invariant is correct, what will happen when ESC/Java is applied on
Channel?
d Consider class GenderBalance. When using ESC/Java to validate this class, two different
errors will be signalled. What are these errors, and what causes them (3 points per error).
1 package s c ;
2
3 p u b l i c c l a s s Gender Bal ance {
4
5 /∗@ s p e c p u b l i c ∗/ p r i v a t e i n t nr of men ;
6 /∗@ s p e c p u b l i c ∗/ p r i v a t e i n t nr of women ;
7
8 //@ i n v a r i a n t nr of men <= nr of women ;
9
10 p u b l i c i n t addMen( i n t m) {
11 r e t ur n nr of men + m;
12 }
13
14 p u b l i c i n t addWomen( i n t w) {
15 r e t ur n nr of women + w;
16 }
17
18 /∗@ r e q u i r e s m <= w;
19 e ns ur e s nr of men == \ ol d ( nr of men ) + m;
20 e ns ur e s nr of women == \ ol d ( nr of women ) + m;
21 ∗/
22 p u b l i c voi d r e c r ui t me nt ( i n t m, i n t w) {
23 nr of men = addMen(m) ;
24 nr of women = addWomen(w) ;
25 }
26 }
11
Exercise 6: Modeling (22 points)
Consider the Bean Can Game.
You and a friend are given a can containing N black beans and M white beans initially. The
can is emptied according to the following repeated process:
• Select two beans from the can
• If the beans are:
– the same color: put a black bean back in the can
– different colors: put a white bean back in the can
The player who chooses the color of the remaining bean wins the game.
-- Bean Can Algorithm pseudocode
while (num-beans-in-can > 1) do {
pick 2 beans randomly
if bean1-color == bean2-color
then put-back black bean
else put-back white bean
}
a (12 pnts.) Write a NuSMV model for this game.
b (3 pnts.) Write a property to specify that the game always terminates.
c (3 pnts.) Write a property to specify that black always is able to win the game.
d (4 pnts.) Suppose you want to be sure that the model has no executions where it always picks
only black beans. What change would you have to make to the model to ensure this.
12
Exercise 7: Traces (15 points)
Consider the following Java program:
1 i mpor t gov . nasa . j p f . jvm . Ve r i f y ;
2 p u b l i c c l a s s Workers {
3 p u b l i c s t a t i c Ba r r i e r b a r r i e r ;
4 p u b l i c s t a t i c Obj ect l oc k1=new Obj ect ( ) ;
5 p u b l i c s t a t i c Obj ect l oc k2=new Obj ect ( ) ;
6
7 p u b l i c s t a t i c voi d mai n ( St r i ng ar gs [ ] ) t hr ows Except i on {
8 b a r r i e r=new Ba r r i e r ( 2) ;
9 Thread t 1 = new Thread ( new Runner ( ) ) ;
10 Thread t 2 = new Thread ( new Runner ( ) ) ;
11 Thread t 3 = new Thread ( new Runner ( ) ) ;
12 Ve r i f y . begi nAt omi c ( ) ;
13 t 1 . s t a r t ( ) ;
14 t 2 . s t a r t ( ) ;
15 t 3 . s t a r t ( ) ;
16 Ve r i f y . endAtomi c ( ) ;
17 t 1 . j o i n ( ) ;
18 t 2 . j o i n ( ) ;
19 t 3 . j o i n ( ) ;
20 }
21
22 p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
23 p u b l i c voi d r un ( ) {
24 s y nc hr oni z e d ( l oc k1 ) {
25 s y nc hr oni z e d ( l oc k2 ) {
26 // do some work .
27 }
28 }
29 b a r r i e r . s ync ( ) ;
30 s y nc hr oni z e d ( l oc k2 ) {
31 s y nc hr oni z e d ( l oc k1 ) {
32 // do more work .
33 }
34 }
35 }
36 }
37 }
13
The code for the barrier used is:
1 /∗∗
2 A b a r r i e r i s a way of s y n c h r o n i z i n g N t hr e ads .
3 I t makes a gr oup of t hr e ads wai t u n t i l t he l a s t one
4 has r eached t he b a r r i e r ( c a l l e d s ync ) .
5 ∗/
6
7 p u b l i c c l a s s Ba r r i e r {
8
9 p r i v a t e i n t t hr e ads ;
10 p r i v a t e i n t bl ocked ;
11 p r i v a t e bool ean round ;
12
13 p u b l i c Ba r r i e r ( i n t t hr e ads ) {
14 t h i s . t hr e a ds = t hr e a ds ;
15 bl ocked = 0;
16 }
17
18 p u b l i c s y nc hr oni z e d voi d s ync ( ) {
19 bl ocked++;
20 i f ( bl ocked < t hr e ads ) {
21 bool ean e xpec t = ! round ;
22 whi l e ( round != e xpe ct ) {
23 t r y { wai t ( ) ; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
24 }
25 } e l s e {
26 round = ! round ;
27 bl ocked = 0;
28 n o t i f y Al l ( ) ;
29 }
30 }
31
32 }
To analyse the presence of deadlocks for this program, we have used JPF. The input for JPF is:
1 # c l a s s t o v e r i f y
2 t a r g e t = Workers
3
4 # where t o f i n d byt e code and s our c e
5 c l a s s p a t h =.
6 s our c e pat h =.
7
8 # s e t h e u r i s t i c
9 s e ar c h . c l a s s = . s e ar c h . h e u r i s t i c . BFSHe ur i s t i c
10 s e ar c h . mu l t i p l e e r r o r s = t r ue
11
12 # how do we want t he r e s u l t ?
13 r e p o r t . c ons ol e . p r o p e r t y v i o l a t i o n=e r r or , s napshot , t r a c e
14
14
15 # what ar e we l o o k i ng f o r ?
16 l i s t e n e r =. l i s t e n e r . Deadl ockAnal yzer
17
18 # how t o d i s p l a y de adl oc ks
19 deadl ock . f or mat=e s s e n t i a l
JPF signals that there is a problem with this code. Analyse the counter example (starting on the
next page) and explain why the assertion was triggered.
When you describe the scenario, it is important to state which thread is running and precisely
what the first and/or last action of the running thread during its turn is. (for example: “thread 37
starts by reading 7 from variable x and stops just before reading variable y.”) The description of the
other things a thread does during its turn can and should be much less detailed.
15
1 ====================================================== e r r o r #71
2 gov . nasa . j p f . jvm . Not Deadl ockedPr oper t y
3 deadl ock encount er ed :
4 t hr e ad j av a . l ang . Thread : { i d : 0 , name : main , s t a t u s : WAITING, p r i o r i t y : 5 , l ockCount : 0 ,
suspendCount : 0}
5 t hr e ad j av a . l ang . Thread : { i d : 1 , name : Thread −1, s t a t u s : WAITING, p r i o r i t y : 5 , l ockCount : 1 ,
suspendCount : 0}
6 t hr e ad j av a . l ang . Thread : { i d : 2 , name : Thread −2, s t a t u s : TERMINATED, p r i o r i t y : 5 , l ockCount : 0 ,
suspendCount : 0}
7 t hr e ad j av a . l ang . Thread : { i d : 3 , name : Thread −3, s t a t u s : TERMINATED, p r i o r i t y : 5 , l ockCount : 0 ,
suspendCount : 0}
8
9
10 ====================================================== s naps hot #71
11 t hr e ad j av a . l ang . Thread : { i d : 0 , name : main , s t a t u s : WAITING, p r i o r i t y : 5 , l ockCount : 0 ,
suspendCount : 0}
12 wa i t i ng on : j av a . l ang . Thread@143
13 c a l l s t ac k :
14 at j av a . l ang . Thread . j o i n ( Thread . j av a : −1)
15 at Workers . mai n ( Workers . j av a : 17)
16
17 t hr e ad j av a . l ang . Thread : { i d : 1 , name : Thread −1, s t a t u s : WAITING, p r i o r i t y : 5 , l ockCount : 1 ,
suspendCount : 0}
18 wa i t i ng on : Bar r i er @142
19 c a l l s t ac k :
20 at j av a . l ang . Obj ect . wai t ( Obj ect . j av a : −1)
21 at Ba r r i e r . s ync ( Ba r r i e r . j av a : 23)
22 at Workers$Runner . r un ( Workers . j av a : 28)
23
24
25 ====================================================== t r a c e #71
26 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #0 t hr e ad : 0
27 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d :”<r oot >” , 1/1 , i s Cas c ade d : f a l s e }
28 [ 2895 i ns n w/o s our c e s ]
29 Workers . j av a : 4 : p u b l i c s t a t i c Obj ect l oc k1=new Obj ect ( ) ;
30 [ 1 i ns n w/o s our c e s ]
31 Workers . j av a : 4 : p u b l i c s t a t i c Obj ect l oc k1=new Obj ect ( ) ;
32 Workers . j av a : 5 : p u b l i c s t a t i c Obj ect l oc k2=new Obj ect ( ) ;
33 [ 1 i ns n w/o s our c e s ]
34 Workers . j av a : 5 : p u b l i c s t a t i c Obj ect l oc k2=new Obj ect ( ) ;
35 [ 2 i ns n w/o s our c e s ]
36 Workers . j av a : 8 : b a r r i e r=new Ba r r i e r ( 2) ;
37 Ba r r i e r . j av a : 13 : p u b l i c Ba r r i e r ( i n t t hr e a ds ) {
38 [ 1 i ns n w/o s our c e s ]
39 Ba r r i e r . j av a : 14 : t h i s . t hr e a ds=t hr e a ds ;
40 Ba r r i e r . j av a : 15 : bl ocked =0;
41 Ba r r i e r . j av a : 16 : }
42 Workers . j av a : 8 : b a r r i e r=new Ba r r i e r ( 2) ;
43 Workers . j av a : 9 : Thread t 1=new Thread ( new Runner ( ) ) ;
44 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
45 [ 1 i ns n w/o s our c e s ]
46 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
47 Workers . j av a : 9 : Thread t 1=new Thread ( new Runner ( ) ) ;
48 [ 188 i ns n w/o s our c e s ]
49 Workers . j av a : 9 : Thread t 1=new Thread ( new Runner ( ) ) ;
50 Workers . j av a : 10 : Thread t 2=new Thread ( new Runner ( ) ) ;
51 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
52 [ 1 i ns n w/o s our c e s ]
53 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
54 Workers . j av a : 10 : Thread t 2=new Thread ( new Runner ( ) ) ;
55 [ 141 i ns n w/o s our c e s ]
56 Workers . j av a : 10 : Thread t 2=new Thread ( new Runner ( ) ) ;
57 Workers . j av a : 11 : Thread t 3=new Thread ( new Runner ( ) ) ;
58 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
59 [ 1 i ns n w/o s our c e s ]
60 Workers . j av a : 21 : p u b l i c s t a t i c c l a s s Runner i mpl ement s Runnabl e {
61 Workers . j av a : 11 : Thread t 3=new Thread ( new Runner ( ) ) ;
62 [ 141 i ns n w/o s our c e s ]
63 Workers . j av a : 11 : Thread t 3=new Thread ( new Runner ( ) ) ;
64 Workers . j av a : 12 : Ve r i f y . begi nAt omi c ( ) ;
16
65 [ 2 i ns n w/o s our c e s ]
66 Workers . j av a : 13 : t 1 . s t a r t ( ) ;
67 [ 2 i ns n w/o s our c e s ]
68 Workers . j av a : 14 : t 2 . s t a r t ( ) ;
69 [ 2 i ns n w/o s our c e s ]
70 Workers . j av a : 15 : t 3 . s t a r t ( ) ;
71 [ 2 i ns n w/o s our c e s ]
72 Workers . j av a : 16 : Ve r i f y . endAtomi c ( ) ;
73 [ 1 i ns n w/o s our c e s ]
74 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #1 t hr e ad : 0
75 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” end at omi c ” , 1/4 , i s Cas c ade d : f a l s e }
76 [ 2 i ns n w/o s our c e s ]
77 Workers . j av a : 17 : t 1 . j o i n ( ) ;
78 [ 1 i ns n w/o s our c e s ]
79 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #2 t hr e ad : 3
80 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” wai t ” , 3/3 , i s Cas c ade d : f a l s e }
81 [ 2 i ns n w/o s our c e s ]
82 Workers . j av a : 23 : s y nc hr oni z e d ( l oc k1 ) {
83 Workers . j av a : 24 : s y nc hr oni z e d ( l oc k2 ) {
84 Workers . j av a : 26 : }
85 Workers . j av a : 27 : }
86 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #3 t hr e ad : 3
87 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” s h a r e d Fi e l d ” , 3/3 , i s Cas c ade d : f a l s e }
88 Workers . j av a : 28 : b a r r i e r . s ync ( ) ;
89 Ba r r i e r . j av a : 19 : bl ocked++;
90 Ba r r i e r . j av a : 20 : i f ( bl ocked<t hr e a ds ) {
91 Ba r r i e r . j av a : 21 : bool ean expect =! round ;
92 Ba r r i e r . j av a : 22 : whi l e ( round!=expect ) {
93 Ba r r i e r . j av a : 23 : t r y { wai t ( ) ; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
94 [ 1 i ns n w/o s our c e s ]
95 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #4 t hr e ad : 1
96 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” wai t ” , 1/2 , i s Cas c ade d : f a l s e }
97 [ 2 i ns n w/o s our c e s ]
98 Workers . j av a : 23 : s y nc hr oni z e d ( l oc k1 ) {
99 Workers . j av a : 24 : s y nc hr oni z e d ( l oc k2 ) {
100 Workers . j av a : 26 : }
101 Workers . j av a : 27 : }
102 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #5 t hr e ad : 2
103 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” s h a r e d Fi e l d ” , 2/2 , i s Cas c ade d : f a l s e }
104 [ 2 i ns n w/o s our c e s ]
105 Workers . j av a : 23 : s y nc hr oni z e d ( l oc k1 ) {
106 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #6 t hr e ad : 2
107 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” moni t or Ent er ” , 2/2 , i s Cas c ade d : f a l s e }
108 Workers . j av a : 23 : s y nc hr oni z e d ( l oc k1 ) {
109 Workers . j av a : 24 : s y nc hr oni z e d ( l oc k2 ) {
110 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #7 t hr e ad : 2
111 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” moni t or Ent er ” , 2/2 , i s Cas c ade d : f a l s e }
112 Workers . j av a : 24 : s y nc hr oni z e d ( l oc k2 ) {
113 Workers . j av a : 26 : }
114 Workers . j av a : 27 : }
115 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #8 t hr e ad : 2
116 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” s h a r e d Fi e l d ” , 2/2 , i s Cas c ade d : f a l s e }
117 Workers . j av a : 28 : b a r r i e r . s ync ( ) ;
118 Ba r r i e r . j av a : 19 : bl ocked++;
119 Ba r r i e r . j av a : 20 : i f ( bl ocked<t hr e a ds ) {
120 Ba r r i e r . j av a : 26 : round=! round ;
121 Ba r r i e r . j av a : 27 : bl ocked =0;
122 Ba r r i e r . j av a : 28 : n o t i f y Al l ( ) ;
123 [ 2 i ns n w/o s our c e s ]
124 Ba r r i e r . j av a : 30 : }
125 Workers . j av a : 29 : s y nc hr oni z e d ( l oc k2 ) {
126 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #9 t hr e ad : 1
127 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” moni t or Ent er ” , 1/3 , i s Cas c ade d : f a l s e }
128 Workers . j av a : 28 : b a r r i e r . s ync ( ) ;
129 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #10 t hr e ad : 1
130 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” moni t or Ent er ” , 1/3 , i s Cas c ade d : f a l s e }
131 Workers . j av a : 28 : b a r r i e r . s ync ( ) ;
132 Ba r r i e r . j av a : 19 : bl ocked++;
133 Ba r r i e r . j av a : 20 : i f ( bl ocked<t hr e a ds ) {
134 Ba r r i e r . j av a : 21 : bool ean expect =! round ;
17
135 Ba r r i e r . j av a : 22 : whi l e ( round!=expect ) {
136 Ba r r i e r . j av a : 23 : t r y { wai t ( ) ; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
137 [ 1 i ns n w/o s our c e s ]
138 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #11 t hr e ad : 2
139 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” wai t ” , 1/2 , i s Cas c ade d : f a l s e }
140 Workers . j av a : 29 : s y nc hr oni z e d ( l oc k2 ) {
141 Workers . j av a : 30 : s y nc hr oni z e d ( l oc k1 ) {
142 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #12 t hr e ad : 2
143 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” moni t or Ent er ” , 1/2 , i s Cas c ade d : f a l s e }
144 Workers . j av a : 30 : s y nc hr oni z e d ( l oc k1 ) {
145 Workers . j av a : 32 : }
146 Workers . j av a : 33 : }
147 Workers . j av a : 34 : }
148 [ 1 i ns n w/o s our c e s ]
149 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− t r a n s i t i o n #13 t hr e ad : 3
150 gov . nasa . j p f . jvm . c hoi c e . ThreadChoi ceFr omSet { i d : ” t e r mi nat e ” , 1/1 , i s Cas c ade d : f a l s e }
151 [ 2 i ns n w/o s our c e s ]
152 Ba r r i e r . j av a : 23 : t r y { wai t ( ) ; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
153 Ba r r i e r . j av a : 22 : whi l e ( round!=expect ) {
154 Ba r r i e r . j av a : 25 : } e l s e {
155 Ba r r i e r . j av a : 30 : }
156 Workers . j av a : 29 : s y nc hr oni z e d ( l oc k2 ) {
157 Workers . j av a : 30 : s y nc hr oni z e d ( l oc k1 ) {
158 Workers . j av a : 32 : }
159 Workers . j av a : 33 : }
160 Workers . j av a : 34 : }
161 [ 1 i ns n w/o s our c e s ]
162
163 ====================================================== t hr e ad ops #71
164 1 3 2 0 t r a ns i ns n l o c : stmt
165 −−−−−−− −−−−−−− −−−−−−− −−−−−−− −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
166 | | T | 1354 d i r e c t c a l l r e t u r n [ s y n t h e t i c ] [ r un ]
167 W: 322 | | | 930 i n v o k e v i r t u a l Ba r r i e r . j av a : 23 : t r y { wai t ( )
; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
168 | B: 322 | | 930 i n v o k e v i r t u a l Ba r r i e r . j av a : 23 : t r y { wai t ( )
; } cat ch ( I n t e r r u p t e d Ex c e p t i o n e ) {}
169 L: 322 | | | 930 i n v o k e v i r t u a l Workers . j av a : 28 : b a r r i e r . s ync
( ) ;
170 | | A: 322 | 507 i n v o k e v i r t u a l Ba r r i e r . j av a : 28 : n o t i f y Al l ( ) ;
171 | | | W: 323 1 i n v o k e v i r t u a l Workers . j av a : 17 : t 1 . j o i n ( ) ;
172 | S | | 0
173 | | S | 0
174 S | | | 0
18