Skip to content

Java concurrency support #2179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions regression/cbmc-java-concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_test_pl_tests(
"$<TARGET_FILE:jbmc>"
)
32 changes: 32 additions & 0 deletions regression/cbmc-java-concurrency/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
default: tests.log

test:
@../test.pl -p -c ../../../src/jbmc/jbmc

tests.log: ../test.pl
@../test.pl -p -c ../../../src/jbmc/jbmc

show:
@for dir in *; do \
if [ -d "$$dir" ]; then \
vim -o "$$dir/*.java" "$$dir/*.out"; \
fi; \
done;

clean:
find -name '*.out' -execdir $(RM) '{}' \;
find -name '*.gb' -execdir $(RM) '{}' \;
$(RM) tests.log

%.class: %.java ../../src/org.cprover.jar
javac -g -cp ../../src/org.cprover.jar:. $<

nondet_java_files := $(shell find . -name "Nondet*.java")
nondet_class_files := $(patsubst %.java, %.class, $(nondet_java_files))

.PHONY: nondet-class-files
nondet-class-files: $(nondet_class_files)

.PHONY: clean-nondet-class-files
clean-nondet-class-files:
-rm $(nondet_class_files)
Binary file not shown.
61 changes: 61 additions & 0 deletions regression/cbmc-java-concurrency/explicit_thread_blocks/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.lang.Thread;
import org.cprover.CProver;

public class A
{
static int x = 0;

// verification success
public void me()
{
x = 5;
CProver.startThread(333);
x = 10;
CProver.endThread(333);
assert(x == 5 || x == 10);
}

// verification failed
public void me2()
{
x = 5;
CProver.startThread(333);
x = 10;
CProver.endThread(333);
assert(x == 10);
}

// Known-bug, thread id mismatch, this should be detected by the conversation
// process. It is currently not and thus will result in an assertion violation
// during symbolic execution.
public void me3()
{
x = 5;
CProver.startThread(22333);
x = 10;
CProver.endThread(333);
assert(x == 10);
}

// Known-bug, see: https://github.com/diffblue/cbmc/issues/1630
public void me4()
{
int x2 = 10;
CProver.startThread(22333);
x = x2;
assert(x == 10);
CProver.endThread(333);
}

// Known-bug, symex cannot handle nested thread-blocks
public void me5()
{
CProver.startThread(333);
x = 5;
CProver.startThread(222);
x = 8;
CProver.endThread(222);
CProver.endThread(333);
assert(x == 5 || x == 0 || x == 8);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
A.class
--function "A.me:()V" --lazy-methods --java-threading

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
A.class
--function "A.me2:()V" --lazy-methods --java-threading

^SIGNAL=0$
^VERIFICATION FAILED
1 change: 1 addition & 0 deletions src/java_bytecode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SRC = bytecode_info.cpp \
jar_file.cpp \
java_bytecode_convert_class.cpp \
java_bytecode_convert_method.cpp \
java_bytecode_convert_threadblock.cpp \
java_bytecode_instrument.cpp \
java_bytecode_internal_additions.cpp \
java_bytecode_language.cpp \
Expand Down
5 changes: 5 additions & 0 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,11 @@ void java_bytecode_convert_method(
"nondetWithNull",
"nondetWithoutNull",
"notModelled",
"atomicBegin",
"atomicEnd",
"startThread",
"endThread",
"getCurrentThreadID"
};

if(std::regex_match(
Expand Down
Loading