Skip to content

Commit e8ff243

Browse files
authored
Merge pull request diffblue#2225 from cesaro/extended-java-models
JBMC: Added java-models-library dependency
2 parents 5242dc9 + c6d2dba commit e8ff243

19 files changed

+79
-257
lines changed

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ src/ansi-c/gcc_builtin_headers_mips.inc
4949
src/ansi-c/gcc_builtin_headers_power.inc
5050
src/ansi-c/gcc_builtin_headers_ubsan.inc
5151
src/ansi-c/windows_builtin_headers.inc
52-
jbmc/src/java_bytecode/java_core_models.inc
5352

5453
# regression/test files
5554
*.out
@@ -122,9 +121,13 @@ src/ansi-c/file_converter
122121
src/ansi-c/file_converter.exe
123122
src/ansi-c/library/converter
124123
src/ansi-c/library/converter.exe
125-
jbmc/src/java_bytecode/converter
126-
jbmc/src/java_bytecode/converter.exe
124+
jbmc/src/java_bytecode/library/converter.exe
125+
jbmc/src/java_bytecode/library/converter
126+
jbmc/src/java_bytecode/library/core-models.jar
127+
jbmc/src/java_bytecode/library/classes
128+
jbmc/src/java_bytecode/library/src
127129
build/
130+
dist/
128131

129132
*.pyc
130133

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ jobs:
238238
name: "diffblue/cbmc"
239239
description: "Travis build of ${TRAVIS_COMMIT}"
240240
notification_email: "[email protected]"
241+
build_command_prepend: "make -C jbmc/src java-models-library-download"
241242
build_command_prepend: "make -C src minisat2-download"
242243
build_command: "make -C src -j2; make -C jbmc/src -j2"
243244
branch_pattern: "develop"
@@ -264,6 +265,7 @@ jobs:
264265
install:
265266
- ccache -z
266267
- ccache --max-size=1G
268+
- make -C jbmc/src java-models-library-download
267269
- make -C src minisat2-download
268270
- make -C src/ansi-c library_check
269271
- make -C src "CXX=${COMPILER} ${EXTRA_CXXFLAGS}" -j3
@@ -291,4 +293,3 @@ notifications:
291293
on_start: never
292294
on_cancel: never
293295
on_error: always
294-

COMPILING.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ We assume that you have a Debian/Ubuntu or Red Hat-like distribution.
2929
```
3030
Note that you need g++ version 4.9 or newer.
3131

32-
To compile JBMC, you additionally need the JDK:
33-
On Debian-like distributions, do
32+
To compile JBMC, you additionally need the JDK and the java-models-library.
33+
34+
For the JDK, on Debian-like distributions, do
3435
```
3536
apt-get install openjdk-7-jdk
3637
```
3738
On Red Hat/Fedora or derivates, do
3839
```
3940
yum install java-1.7.0-openjdk-devel
4041
```
42+
For the models library, do
43+
```
44+
make -C jbmc/src java-models-library-download
45+
```
4146

4247
2. As a user, get the CBMC source via
4348
```

appveyor.yml

+5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ install:
4242
& 7z x minisat2_2.2.1.orig.tar.gz
4343
&7z x minisat2_2.2.1.orig.tar
4444
}
45+
if (!(Test-Path jml)) {
46+
& appveyor downloadfile https://github.com/diffblue/java-models-library/archive/master.zip -FileName jml.zip
47+
& 7z x jml.zip
48+
}
4549
cd ..
4650
4751
cache: deps
4852

4953
build_script:
5054
- cmd: |
55+
cp -r deps/java-models-library-master/src jbmc/src/java_bytecode/library
5156
cp -r deps/minisat2-2.2.1 minisat-2.2.1
5257
patch -d minisat-2.2.1 -p1 < scripts/minisat-2.2.1-patch
5358
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64

buildspec.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ phases:
1313
build:
1414
commands:
1515
- echo Build started on `date`
16+
- make -C jbmc/src java-models-library-download
1617
- (cd src ; make minisat2-download)
1718
- (cd src ; make CXX="ccache g++" -j2)
1819
- (cd regression ; make test)

jbmc/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ Compilation
3030
To compile you need to run the command:
3131

3232
```bash
33+
make -C jbmc/src java-models-library-download
3334
make -C jbmc/src
3435
```
36+
3537
Output
3638
======
3739

jbmc/regression/jbmc-strings/java_append_char/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
test_append_char.class
3-
--refine-strings --string-max-length 1000 --no-core-models --function test_append_char.main
3+
--refine-strings --string-max-length 1000 --function test_append_char.main
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$

jbmc/regression/jbmc/coreModels/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
test.class
3-
--show-symbol-table
3+
--show-symbol-table --cp ../../../src/java_bytecode/library/core-models.jar:.
44
^EXIT=0$
55
^SIGNAL=0$
66
^Symbol\s*\.*\: java\:\:org\.cprover\.CProver\.\<clinit\>\:\(\)V$

jbmc/src/Makefile

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
DIRS = janalyzer jbmc jdiff java_bytecode miniz
2+
ROOT = ../
23

34
include config.inc
45

@@ -40,11 +41,33 @@ generated_files: $(patsubst %, %_generated_files, $(DIRS))
4041
# cleaning
4142

4243
.PHONY: clean
43-
clean: $(patsubst %, %_clean, $(DIRS)) cprover_clean
44+
clean: $(patsubst %, %_clean, $(DIRS)) cprover_clean dist_clean
4445

4546
$(patsubst %, %_clean, $(DIRS)):
4647
$(MAKE) $(MAKEARGS) -C $(patsubst %_clean, %, $@) clean ; \
4748

4849
.PHONY: cprover_clean
4950
cprover_clean:
5051
$(MAKE) $(MAKEARGS) -C $(CPROVER_DIR)/src clean
52+
53+
.PHONY: dist_clean
54+
dist_clean:
55+
rm -rf $(ROOT)dist
56+
57+
# extended JBMC models download, for your convenience
58+
java-models-library-download:
59+
@echo "Downloading java models library"
60+
@wget https://github.com/diffblue/java-models-library/archive/master.zip -O java-models-library.zip
61+
@unzip java-models-library.zip
62+
@rm java-models-library.zip
63+
@cp -r java-models-library-master/src java_bytecode/library
64+
@rm -r java-models-library-master
65+
66+
.PHONY: dist
67+
dist: java-models-library-download all
68+
mkdir -p $(ROOT)dist/lib
69+
cp java_bytecode/library/core-models.jar $(ROOT)dist/lib
70+
mkdir -p $(ROOT)dist/bin
71+
cp jbmc/jbmc $(ROOT)dist/bin
72+
cp janalyzer/janalyzer $(ROOT)dist/bin
73+
cp jdiff/jdiff $(ROOT)dist/bin

jbmc/src/java_bytecode/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ add_library(java_bytecode ${sources} ${headers})
1010
# targets wishing to depend on the target 'java_bytecode' may want to use
1111
generic_includes(java_bytecode)
1212

13-
# target 'java-core-models-inc' is defined in library/
14-
add_dependencies(java_bytecode java-core-models-inc)
15-
1613
# if you link java_bytecode.a in, then you also need to link other .a libraries
1714
# in
1815
target_link_libraries(java_bytecode util goto-programs miniz json)

jbmc/src/java_bytecode/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ include ../$(CPROVER_DIR)/src/common
4949

5050
CLEANFILES = java_bytecode$(LIBEXT)
5151

52-
all: java_bytecode$(LIBEXT)
52+
all: library java_bytecode$(LIBEXT)
5353

5454
clean: clean_library
5555

5656
.PHONY: clean_library
5757
clean_library:
5858
$(MAKE) clean -C library
5959

60-
library/java_core_models.inc:
61-
$(MAKE) -C library java_core_models.inc
60+
.PHONY: library
61+
library:
62+
$(MAKE) -C library
6263

63-
java_class_loader$(OBJEXT): library/java_core_models.inc
6464
###############################################################################
6565

6666
java_bytecode$(LIBEXT): $(OBJ)

jbmc/src/java_bytecode/java_bytecode_language.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Author: Daniel Kroening, [email protected]
4444
void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
4545
{
4646
assume_inputs_non_null=cmd.isset("java-assume-inputs-non-null");
47-
java_class_loader.set_use_core_models(!cmd.isset("no-core-models"));
4847
string_refinement_enabled=cmd.isset("refine-strings");
4948
throw_runtime_exceptions=cmd.isset("java-throw-runtime-exceptions");
5049
if(cmd.isset("java-max-input-array-length"))

jbmc/src/java_bytecode/java_bytecode_language.h

-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Author: Daniel Kroening, [email protected]
2727
#include <langapi/language.h>
2828

2929
#define JAVA_BYTECODE_LANGUAGE_OPTIONS /*NOLINT*/ \
30-
"(no-core-models)" \
3130
"(java-assume-inputs-non-null)" \
3231
"(java-throw-runtime-exceptions)" \
3332
"(java-max-input-array-length):" \
@@ -40,8 +39,6 @@ Author: Daniel Kroening, [email protected]
4039
"(java-no-load-class):"
4140

4241
#define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP /*NOLINT*/ \
43-
" --no-core-models don't load internally provided models for core classes in\n"/* NOLINT(*) */ \
44-
" the Java Class Library\n" /* NOLINT(*) */ \
4542
" --java-assume-inputs-non-null never initialize reference-typed parameter to the\n" /* NOLINT(*) */ \
4643
" entry point with null\n" /* NOLINT(*) */ \
4744
" --java-throw-runtime-exceptions make implicit runtime exceptions explicit\n" /* NOLINT(*) */ \

jbmc/src/java_bytecode/java_class_loader.cpp

-30
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include "java_bytecode_parser.h"
1919

20-
#include "library/java_core_models.inc"
21-
22-
/// This variable stores the data of the file core-models.jar. The macro
23-
/// JAVA_CORE_MODELS_SIZE is defined in the header java_core_models.inc, which
24-
/// gets generated at compile time by running a small utility (converter.cpp) on
25-
/// actual .jar file. The number of bytes in the variable is
26-
/// JAVA_CORE_MODELS_SIZE, another macro defined in java_core_models.inc.
27-
unsigned char java_core_models[] = { JAVA_CORE_MODELS_DATA };
28-
2920
java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
3021
const irep_idt &class_name)
3122
{
@@ -137,27 +128,6 @@ java_class_loadert::get_parse_tree(
137128
parse_trees.emplace_back(std::move(*parse_tree));
138129
}
139130

140-
// Then add core models
141-
if(use_core_models)
142-
{
143-
// Add internal jar file. The name is used to load it once only and
144-
// reference it later.
145-
std::string core_models = "core-models.jar";
146-
jar_pool(
147-
class_loader_limit, core_models, java_core_models, JAVA_CORE_MODELS_SIZE);
148-
149-
// This does not read from the jar file but from the jar_filet object we
150-
// just created
151-
jar_index_optcreft index = read_jar_file(class_loader_limit, core_models);
152-
if(index)
153-
{
154-
optionalt<java_bytecode_parse_treet> parse_tree =
155-
get_class_from_jar(class_name, core_models, *index, class_loader_limit);
156-
if(parse_tree)
157-
parse_trees.emplace_back(std::move(*parse_tree));
158-
}
159-
}
160-
161131
// Then add everything on the class path
162132
for(const auto &cp_entry : config.java.classpath)
163133
{

jbmc/src/java_bytecode/java_class_loader.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class java_class_loadert:public messaget
3636
typedef std::function<std::vector<irep_idt>(const irep_idt &)>
3737
get_extra_class_refs_functiont;
3838

39-
// Default constructor does not use core models
40-
// for backward compatibility of unit tests
41-
java_class_loadert() : use_core_models(true)
39+
java_class_loadert()
4240
{
4341
}
4442

@@ -79,10 +77,6 @@ class java_class_loadert:public messaget
7977
{
8078
jar_files.push_back(f);
8179
}
82-
void set_use_core_models(bool use_core_models)
83-
{
84-
this->use_core_models = use_core_models;
85-
}
8680

8781
static std::string file_to_class_name(const std::string &);
8882
static std::string class_name_to_file(const irep_idt &);
@@ -137,9 +131,6 @@ class java_class_loadert:public messaget
137131
/// get_parse_tree).
138132
std::list<std::string> jar_files;
139133

140-
/// Indicates that the core models should be loaded
141-
bool use_core_models;
142-
143134
/// Classes to be explicitly loaded
144135
std::vector<irep_idt> java_load_classes;
145136
get_extra_class_refs_functiont get_extra_class_refs;
+21-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
message(STATUS "Downloading java-models-library...")
2+
include("${CBMC_SOURCE_DIR}/../cmake/DownloadProject.cmake")
3+
4+
# Note: 'PATCH_COMMAND' is being used instead of 'COMMAND' as
5+
# 'download_project' does not work as expected if called without
6+
# 'PATCH_COMMAND'.
7+
download_project(PROJ java_models_library
8+
URL https://github.com/diffblue/java-models-library/archive/master.zip
9+
PATCH_COMMAND cmake -E copy_directory "${CMAKE_BINARY_DIR}/java_models_library-src/src"
10+
"${JBMC_SOURCE_DIR}/java_bytecode/library/src"
11+
)
12+
113
find_package(Java REQUIRED)
214
include(UseJava)
15+
316
set(CMAKE_JAVA_COMPILE_FLAGS -sourcepath "src" -d "classes" -XDignore.symbol.file)
417

518
# create a target for the executable performing the .jar -> .inc conversion
@@ -9,16 +22,11 @@ add_executable(java-converter converter.cpp)
922
file(GLOB_RECURSE java_sources "src/*.java")
1023
add_jar("core-models" ${java_sources})
1124

12-
# define a cmake variable with the full path of the .inc file
13-
set(JAVA_CORE_MODELS_INC "${CMAKE_CURRENT_BINARY_DIR}/java_core_models.inc")
14-
15-
# define a rule telling cmake how to generate the file ${JAVA_CORE_MODELS_INC} from
16-
# the .jar file by running the java-converter; the output file depends on the
17-
# .jar file but also on the converter (!)
18-
add_custom_command(OUTPUT ${JAVA_CORE_MODELS_INC}
19-
COMMAND java-converter "JAVA_CORE_MODELS" "core-models.jar" > ${JAVA_CORE_MODELS_INC}
20-
DEPENDS "core-models.jar" java-converter)
21-
22-
# create a target 'core-models-inc' that depends on the .inc file
23-
add_custom_target(java-core-models-inc
24-
DEPENDS ${JAVA_CORE_MODELS_INC})
25+
# copy 'core-models.jar' to '<PROJECT_ROOT>/jbmc/src/java_bytecode/library'.
26+
# This is needed to deal with unit tests that make use of the core-models
27+
# library. So that they can find the 'core-models.jar' in the same place as
28+
# if the project had been compiled with 'make'.
29+
add_custom_command(TARGET core-models
30+
POST_BUILD
31+
COMMAND ${CMAKE_COMMAND} -E copy "core-models.jar" ${PROJECT_SOURCE_DIR}/java_bytecode/library
32+
)

jbmc/src/java_bytecode/library/Makefile

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
#javac compiles multiple classes for each source as it will compile dependent sources.
33
#Thus we do not allow the make to run concurrently.
44

5-
SRC = converter.cpp
6-
75
include ../../config.inc
86
include ../../$(CPROVER_DIR)/src/config.inc
97
include ../../$(CPROVER_DIR)/src/common
108

11-
SOURCE_DIR := src
9+
SOURCE_DIR := src/main/java
1210
BINARY_DIR := classes
1311

1412
FIND := find
@@ -35,17 +33,11 @@ JARFLAGS := -cf
3533
core-models.jar: $(ALL_CLASSES)
3634
$(JAR) $(JARFLAGS) $@ -C $(BINARY_DIR) .
3735

38-
CLEANFILES = core-models.jar converter$(EXEEXT) java_core_models.inc
36+
CLEANFILES = core-models.jar
3937

40-
all: java_core_models.inc
38+
all: core-models.jar
4139

4240
clean: clean_
4341

4442
clean_:
4543
$(RM) -Rf $(BINARY_DIR)
46-
47-
converter$(EXEEXT): converter.cpp
48-
$(LINKNATIVE)
49-
50-
java_core_models.inc: converter$(EXEEXT) core-models.jar
51-
./converter$(EXEEXT) JAVA_CORE_MODELS core-models.jar > $@

jbmc/src/java_bytecode/library/converter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
6666
printf("\n");
6767
}
6868

69-
std::cout << "\n#define " << varname << "_SIZE " << size << "\n\n";
69+
std::cout << "\n#define " << varname << "_SIZE " << size << "\n";
7070
src.close();
7171
return 0;
7272
}

0 commit comments

Comments
 (0)