Escolar Documentos
Profissional Documentos
Cultura Documentos
Deadline: Nov 9
System Setup
We will test your code in the following setup:
Ubuntu 16.04
Intro
In this assignment, you will implement the Locktree algorithm in Java.
>
<!–
ReentrantLock
(see vt.locktree.CustomLock ).
In the second task, we will then take a first step towards making your
In the third task, you will analyse a “real-world program” using the
algoirh
–>
Let’s Run It
I assume you pulled all changes from repository “tutors” and are now
expected_test_outputs
lib
src
src_tests
build.xml
export_classpath.sh
run_ftp_test_X.sh
run_ftp_test_Y.sh
test_task1_single.sh
build.xml ,
ant clean
target/classes/src
target/classes/src_tests
(located src_tests/vt/locktree/test/task1/HelloWorld.java ).
The method main runs two threads, thread 1 and thread 2 , one
after another,
Execute:
ant compile
java -classpath ./target/classes/src:./target/classes/src
_tests/ \
vt.locktree.test.task1.HelloWorld
lines)
Hello World!
ExampleThread 1
ExampleThread 2
checkTrees: implement me
No deadlocks found.
The pre-last line has checkTrees: implement me and this method you
will need to implement.
Note about -classpath
Note that in the above command we use argument -classpath to tell
Java where to find
export_classpath.sh .
Now you can skip specifying -classpath and simply execute (in the
same terminal window!):
java vt.locktree.test.task1.HelloWorld
in the paper)
/**
and tree2.
*/
e tree2) {
// TODO: implement me
Note that some pairs can appear more than once—this means that
T1 T2
| / \
6 4 4
| / \
4 6 6
then the pair (4,6) should appear twice in the resulting list.
Gate locks.
We use a slightly different notion of gate locks than what was given in
the lecture.
Given a pair of locks (l1, l2) that appear reversed in two trees,
above the node with l2 in the first tree and above the node with l1
in the second tree.
First example:
t1 t2
| |
2 3
| |
3 2
Second example:
t1 t2
1 3 (1,3) is DL
| |
2 1
| |
3 2
Third example:
t1 t2
2 2
| |
3 1
Checking Task 1
The package vt.locktree.test.task1 (in the folder
src_tests/vt/locktree/test/task1 )
contains some tests that you can directly run using java .
The expected output for those tests is inside folder
expected_test_outputs/task1 .
it the output differs, the script opens meld with the differing output.
we will run a hundreds of tests and check your output with the correct
output.
Task 2: Instrumentation with
javassist [30 points]
In the previous task we used CustomLock to track lock and unlock
calls.
and then it should instrument the code of that class and inject calls:
java.util.concurrent.locks.ReentrantLock or
an instance of a class derived from
java.util.concurrent.locks.ReentrantLock .
Testing Task 2
Let us look at the class vt.locktree.test.task2.HelloWorld (in
folder src_tests ).
You can run it directly by calling
java vt.locktree.test.task2.HelloWorld
HelloWorld
at the end of the execution, and you will get something like:
Hello World!
No deadlocks found.
and then call the previous command, then we will get something like
Hello World!
ExampleThread 1
...ReentrantLock@6155e22[Unlocked] [HelloWorld.java: 15
...ReentrantLock@5e719166[Unlocked] [HelloWorld.java:
16]
ExampleThread 2
...ReentrantLock@5e719166[Unlocked] [HelloWorld.java: 2
8]
...ReentrantLock@6155e22[Unlocked] [HelloWorld.java:
29]
Thread 2)
(java.util.concurrent.locks.ReentrantLock@5e719166[Unlock
ed],
java.util.concurrent.locks.ReentrantLock@6155e22[Unlocke
d])
For more details, see class Instrumenter and LockTreeExecuter
I use IDE IntelliJ and when double-click on the class file—it then
decompiles it
and then I can see whether the call was injected or not.)
The first mistake is to intercept calls to all methods named lock and
unlock ,
constructors.
As in task 2, in the final evaluation we run tests and check your output
(YES/NO):
ftp_test_X_short_answer.txt
happens,
explanation,
client-1 connects
creates Thread-1
starts execution
client-2 conn
ects
ftp_test_Y_long_answer.txt ,
and proceed answering the same questions as in the previous task.
Literature
W. Visser, K. Havelund, G. Brat, S. Park and F. Lerda, Model Checking
ASE’00 conference