Commit Graph

438 Commits

Author SHA1 Message Date
Matthias Güdemann c9a53f9111 Add regression tests for changes to JBMC enumeration support
Update regression tests
2018-08-02 08:52:08 +01:00
Matthias Güdemann 361469b8b8 Change source location of jump target in {table|lookup}switch
Before we considered the `code_switch_caset` to belong to the target instruction
which lead to uncoverable goals of the form:

   IF condition 1 then GOTO 1
   ...
1: GOTO 2
   ASSERT false // uncoverable block
   ...
2:
2018-08-02 08:52:08 +01:00
Chris Smowton 627096804a java-unwind-enum-static: also unwind clone loop in Enum.values()
If an enumeration type's values() method clones an array, we assume it is cloning the array of
enumeration values and therefore is bounded by the enumeration's size, similar to the existing
handling of enumeration static initializers.
2018-08-02 08:52:08 +01:00
Chris Smowton 714de0de54 Symex: expose call stack to unwinding decision making
This enables unwind handlers to use the calling context to decide when to unwind a particular loop,
the first use case being generic array clone methods called from enumeration type methods with known
bounds.
2018-08-02 08:52:08 +01:00
Peter Schrammel 1847066e05 Update jbmc/lib/java-models-library to java-models-library#8 (remove sun.* imports) 2018-08-01 18:17:31 +01:00
Chris Smowton fb239effba Fix jbmc-generic-symex-driven-lazy-loading test name 2018-08-01 15:41:58 +01:00
Daniel Kroening 80331d8a57
Merge pull request #2638 from diffblue/CBMC_VERSION_string
use a string instead of macro for version number
2018-08-01 11:55:33 +01:00
Daniel Kroening ad5c3755ca use a string instead of macro for version number 2018-07-31 22:05:27 +01:00
Thomas Kiley eb71a01e76
Merge pull request #2639 from thk123/array-element-type
Make array element type be not a comment
2018-07-31 18:24:25 +01:00
Vojtěch Forejt c5519ec830
Merge pull request #2640 from allredj/support-for-load-containing-class-only
Class loading utils
2018-07-31 17:54:45 +01:00
thk123 b827ea4a94 Use type equality check in unit tests
Now arrays differentiate by element type we need to check type equality
rather than full equality.
2018-07-31 17:15:29 +01:00
Joel Allred 1f4ef405ef Add class loader debug output 2018-07-31 15:12:49 +01:00
thk123 4fa99436dd Make array element type be not a comment 2018-07-31 12:08:22 +01:00
Jeannie Moulton 655248a0bd Add unit test for when there are no exceptions. 2018-07-31 11:17:49 +01:00
Jeannie Moulton a6e7c4be0d Refactors interface for exceptions to not use irepts. 2018-07-31 11:16:56 +01:00
Jeannie Moulton 1134bbacaf Creates java_method_typet which extends code_typet
This is so that we do not need to have java-specific fields and related methods, like those relating to throws exceptions, in std_types
2018-07-31 11:13:30 +01:00
Jeannie Moulton aa83622435 Unit tests method get_super_class 2018-07-31 11:13:30 +01:00
Jeannie Moulton 565c999742 Unit tests throws exceptions parsing. 2018-07-31 11:13:30 +01:00
Jeannie Moulton eb885099ec Use parsed information for thrown exceptions. 2018-07-31 11:13:30 +01:00
Jeannie Moulton 5c7dcacf40 Parses the exception attribute
4.7.5. The Exceptions Attribute
2018-07-31 11:13:30 +01:00
Jeannie Moulton 7fcc42dfe6 Adds const to get/set_outer_class 2018-07-31 11:13:30 +01:00
Jeannie Moulton 5994dd85ad Add method to get super class from java class type. 2018-07-31 11:13:29 +01:00
Jeannie Moulton fbad2d921a Rename variable extends to super_class
This better reflects the bytecode.
2018-07-31 11:12:45 +01:00
svorenova f3630f0b6a
Merge pull request #2612 from svorenova/multidim_arrays_tg3821_util
Add functions for checking (multi-dimensional) array types [TG-3821]
2018-07-27 09:29:40 +01:00
Chris Smowton a0e339d573 Disable broken string test
This currently breaks an assertion as described in the .desc file. It should be re-enabled
once string-refinement knows how to introduce sufficient indirection to overcome this.
2018-07-26 15:48:59 +01:00
Chris Smowton d0cf433d4d Strengthen local_safe_pointers to handle common Java operations
The local-safe-pointers analysis can already inform symex that certain pointers
are known not to be null at particular program points. This strengthens the analysis
to spot more cases such that it can determine no null pointer is dereferenced in the
new regression test `jbmc/clean_derefs`, which exercises many common Java operations
including array accesses.

The specific improvements to local-safe-pointers:
 * Look through typecasts. This was already done for GOTO instructions, but now works
   for ASSUME as well.
 * Search for not-null expressions using base_type_eq instead of just irept::operator<.
   This means that when symex uses namespacet::follow to remove a symbol_typet that does
   not prevent local-safe-pointers from noting it is not null in a particular context.
2018-07-26 15:48:59 +01:00
svorenova c57286633b Use can_cast_type instead of raw type id check 2018-07-26 11:15:44 +01:00
svorenova a1ab7a6071 Improve documentation for java array types 2018-07-26 09:59:10 +01:00
svorenova b72b968a2e Remove unused function 2018-07-25 15:34:46 +01:00
svorenova e66f76f5a2 Add a check functions for (multi-dimensional) array types 2018-07-25 15:28:12 +01:00
Chris Smowton c98688b34f Fix stub string lengths
The --max-nondet-string-length parameter accidentally stopped applying to them when its name was changed.
2018-07-24 17:24:24 +01:00
Daniel Kroening 78b7119895
Merge pull request #2491 from diffblue/std_code_constructors
mark various 'partial constructors' as deprecated
2018-07-24 11:42:54 +01:00
Daniel Kroening a99c4ff327
Merge pull request #2497 from diffblue/simplify_byte_extract_fix
avoid non-termination of simplify_exprt::simplify_byte_extract(array_of(...))
2018-07-24 11:40:16 +01:00
Daniel Kroening c7457fbe6f
Merge pull request #2543 from tautschnig/vs-unsigned-byte-swap
Explicit unsigned -> uint16_t casts to avoid conversion warnings
2018-07-24 08:54:09 +01:00
Matthias Güdemann a63212e138 Add regression test for stack variables with typecasts
This regression test mimicks the bytecode that exhibited the error in Tika.
2018-07-20 11:13:51 +02:00
Matthias Güdemann 6f63050e05 Simplify stack element replacement loop 2018-07-20 11:13:50 +02:00
Matthias Güdemann 731c69e498 Keep expressions unchanged when adding temporary variables
Search recursively through expressions instead of only removing outer typecast
expressions.
2018-07-20 11:13:48 +02:00
Daniel Kroening 14dc11e2fc
Merge pull request #2495 from diffblue/aws-codebuild-windows-jbmc-tests
the jbmc tests now work on Windows
2018-07-19 11:34:51 +01:00
Peter Schrammel 38fe61e02e Trim JBMC help text width to 80 chars 2018-07-18 14:22:54 +01:00
Peter Schrammel ebae090e56 Deactivate smt1 option in JBMC
Replicates the same change already done in CBMC
2018-07-18 14:22:54 +01:00
Peter Schrammel 04fcc5b6bd Check that string options are used with strings turned on 2018-07-18 14:22:45 +01:00
Peter Schrammel 0520732a08 Use default options in JBMC
This replicates the pattern used in CBMC.
2018-07-18 14:15:45 +01:00
Peter Schrammel e4cfb0423f Remove built-in-assertions option from JBMC 2018-07-18 14:15:45 +01:00
Peter Schrammel 0d924ced5e Remove error-label option from JBMC 2018-07-18 14:15:45 +01:00
Peter Schrammel 35f69f0642 Remove GOTO_CHECK options from JBMC 2018-07-18 14:15:45 +01:00
Peter Schrammel 86d4fecba9 Remove --refine-strings from tests 2018-07-18 14:15:45 +01:00
Peter Schrammel 7ef8a0edbb Remove obsolete string-max-length option 2018-07-18 14:15:45 +01:00
Peter Schrammel f795ef9bac Remove trailing newlines that trip up regex on Windows 2018-07-17 19:15:01 +01:00
Matthias Güdemann 6ccce5bf19
Merge pull request #2521 from svorenova/array_element_type_util
Add functions to retrieve a reference to the element type of a java array [TG-3821]
2018-07-17 18:00:10 +02:00
Romain Brenguier 201ba8c4bc
Merge pull request #2581 from romainbrenguier/refactor/to_code
Remove unnecessary cast to_code
2018-07-17 16:57:30 +01:00
Romain Brenguier e4b8c4400e Clean-up in gen_nondet_instruction_info 2018-07-17 15:03:07 +01:00
svorenova f10badb255 Add functions to retrieve a reference to the java array element type 2018-07-17 12:24:32 +01:00
thk123 cb587a927f Adding unit test for checking bridge methods attribute is parsed correctly 2018-07-17 10:04:29 +01:00
thk123 efadba2d55 Read the bride flag for methods
This is used for compiler generated methods to deal with type erasure.
2018-07-17 10:04:29 +01:00
Romain Brenguier 26781a62ba Remove unnecessary cast to_code
These were casting expression that already had type codet.
2018-07-17 09:47:29 +01:00
Matthias Güdemann a18b32db7e
Merge pull request #2571 from jeannielynnmoulton/jeannie/InnerClassAccessibility
[TG-4099] Parse and capture outer class information for an inner class
2018-07-16 08:31:14 +02:00
Jeannie Moulton c959c3fba8 Tests get_outer_class with deeply nested classes. 2018-07-13 16:06:44 +01:00
Jeannie Moulton 8201c19e99 Parse and capture outer class for inner classes. 2018-07-13 16:06:38 +01:00
Owen Jones a1b9e07464 Fix whitespace errors and a typo from #2505 2018-07-13 12:14:57 +01:00
owen-jones-diffblue 45eae64c90
Merge pull request #2505 from owen-jones-diffblue/owen-jones-diffblue/fix/convert-nondet
Make convert_java_nondet more general
2018-07-13 11:55:25 +01:00
Owen 6d9e805474 Make convert_java_nondet more general 2018-07-13 09:38:10 +01:00
Daniel Kroening 70887e28ce
Merge pull request #2564 from tautschnig/vs-java-parse-tree
Cleanup java_bytecode_parse_treet: all members are public, no virtual tables required
2018-07-12 12:45:50 +01:00
John Nonweiler aad16926be Add minisat download to jbmc/README.md 2018-07-12 09:30:32 +01:00
John Nonweiler f7ddb02b85 Remove --recursive from git submodule update 2018-07-10 15:40:18 +01:00
John Nonweiler 206f7fb2db Include submodule update in jbmc/README.md 2018-07-10 15:37:34 +01:00
Michael Tautschnig 53baae6f7d
Merge pull request #2460 from tautschnig/vs-local-unused
Visual Studio: silence warnings about local variables assigned-but-not-used
2018-07-10 10:05:19 +01:00
Michael Tautschnig 0146874c73 Make all unicode operations use native endianness
We do not transfer data to another system, thus using architecture-native
endianness is sufficient.

Fixes: #2559
2018-07-09 23:39:26 +01:00
Peter Schrammel b34e951e52 Use submodule to download java-models-library 2018-07-09 21:13:37 +01:00
Michael Tautschnig dce4afdba5 Make local-assigned-but-not-used annotation applicable to all compilers 2018-07-09 18:00:09 +01:00
Michael Tautschnig 0c15fed912 Cleanup java_bytecode_parse_treet: all members are public, no virtual tables required 2018-07-09 08:43:53 +01:00
Peter Schrammel 0a10bf372d Drop java prefix from throw-runtime-exceptions option
The 'java' prefix is not required anymore since JBMC and
CBMC do not share the same command line interface
anymore.
2018-07-08 22:04:41 +01:00
Peter Schrammel 548baea934 Improve naming of command line options
Drops the 'java' prefix from the most important
java command line options. The prefix is not
required anymore since JBMC and CBMC do not
share the same command line interface anymore.
2018-07-08 22:04:41 +01:00
Peter Schrammel 39bc7ea72e Make --lazy-methods and --refine-strings default
These options are always required in practical
use cases. They can be disabled with --no-lazy-methods
and --no-refine-strings if needed for regression tests.
2018-07-08 22:04:41 +01:00
Peter Schrammel eb9e3bbf17
Merge pull request #2561 from Degiorgio/get-current-thread-id-fix
JBMC: CProver.getCurrentThreadID:()I conversion fix
2018-07-08 22:01:56 +01:00
Peter Schrammel d98a39b443
Merge pull request #2556 from peterschrammel/run-string-smoke-tests
Run strings-smoke-tests
2018-07-08 22:01:29 +01:00
Kurt Degiorgio 4a8dc966a2 JBMC: removed camel-casing from function identifiers 2018-07-08 19:11:03 +01:00
Kurt Degiorgio 9059be7ec5 JBMC: CProver.getCurrentThreadID:()I conversion fix
The symbol table was being passed by-value instead of by-reference to
'instrument_getCurrentThreadID', causing an assertion violation in symex
due to missing symbols. This function is responsible for converting
calls to 'CProver.getCurrentThreadID:()I' into the appropriate codet.

This bug was not detected by existing regression tests as in typical
scenarios the aforementioned function does not add new symbols.
2018-07-08 18:15:23 +01:00
Daniel Kroening 41863e775e
Merge pull request #2539 from tautschnig/vs-unsigned-constant
Mark integer constants as unsigned when lhs is unsigned
2018-07-07 17:29:14 +01:00
Peter Schrammel f1afbff02b Remove unnecessary PLATFORM_DIRS 2018-07-07 17:23:05 +01:00
Peter Schrammel 0c75b47288 Run strings-smoke-tests and janalyzer tests
There were typos in the test directory names,
2018-07-07 17:23:05 +01:00
Daniel Kroening 35ddf0bfce
Merge pull request #2533 from tautschnig/debian5
utf8 to utf16 conversion must use native endianness
2018-07-07 17:12:36 +01:00
Michael Tautschnig 1f237ff700
Merge pull request #2464 from tautschnig/vs-unused1
Remove unused parameters message_handler, ns
2018-07-07 12:31:38 +01:00
Michael Tautschnig 2598141ca8 Mark integer constants as unsigned when lhs is unsigned 2018-07-07 11:42:21 +01:00
Michael Tautschnig 96a70142f3 Explicit type cast to avoid signed/unsigned warning 2018-07-07 09:50:45 +01:00
Michael Tautschnig c6c1938de4 utf8 to utf16 conversion must use native endianness
There is no obvious reason why native endianness should not be used, and
tests failed on big-endian architectures.
2018-07-07 07:05:18 +01:00
Jeannie Moulton af0ce5a192 Captures anonymous inner class information. 2018-07-06 13:33:24 +01:00
Daniel Kroening 081f743cde use proper constructor for code_assertt 2018-07-06 09:58:56 +01:00
Jeannie Moulton fe739552af Captures information for static inner classes. 2018-07-05 11:22:14 +01:00
Thomas Kiley 819c683a18
Merge pull request #2493 from jeannielynnmoulton/jeannie/InnerClasses
[TG-3694] Parse and store inner class information
2018-07-05 10:45:57 +01:00
Daniel Kroening fc4aab3ffb avoid non-termination of simplify_exprt::simplify_byte_extract when given array_of 2018-07-04 18:25:35 +01:00
Jeannie Moulton 5350133c86 Refactor inner class parsing. 2018-07-04 15:00:25 +01:00
Daniel Kroening 6e554d9f0a
Merge pull request #2500 from diffblue/git-version-speedup
move version.h to util/
2018-07-04 11:39:34 +01:00
Chris Smowton f90ed9eef2
Merge pull request #2515 from NathanJPhillips/feature/ignored-methods
Add ability to mark methods as ignored (not loaded)
2018-07-03 18:25:56 +01:00
Jeannie Moulton 9ba55e20aa Marks anonymous classes as inner classes 2018-07-03 16:43:36 +01:00
Daniel Kroening b96c7ba857 move build commands for version.h from common to util/ 2018-07-03 16:20:32 +01:00
Nathan Phillips 4a12a29d94 Prevent crash when only instance of class is marked as an overlay 2018-07-03 14:33:04 +01:00
Nathan Phillips 841313daee Add ability to mark methods as ignored (not loaded) 2018-07-03 14:33:01 +01:00
Michael Tautschnig 0c20014e56
Merge pull request #2513 from tautschnig/clean
Regression test clean target and test.pl fix
2018-07-03 12:55:40 +01:00
Jeannie Moulton 6ce7b1331c Clarifies language in documentation. 2018-07-03 12:23:45 +01:00
Daniel Kroening 72b92a4830
Merge pull request #2471 from tautschnig/vs-non-static
Do not unnecessarily mark local variables static
2018-07-03 12:10:47 +01:00
Michael Tautschnig 2be11f37c4 Make "clean" target in regression tests do full cleanup 2018-07-03 10:56:05 +00:00
Jeannie Moulton c0c1029208 Fixes parsing for anonymous classes 2018-07-03 10:37:42 +01:00
Jeannie Moulton 1930aef720 Refactors parsing of inner classes attribute. 2018-07-03 10:37:13 +01:00
Jeannie Moulton b28562beaf Adds unit test for parsing inner classes. 2018-07-03 10:27:11 +01:00
Jeannie Moulton c3364557a4 Stores inner class data in java class types.
Though this data is stored, it will not be used in test-gen yet because test-gen is assuming all non-public inner classes are private.
2018-07-03 10:27:10 +01:00
Jeannie Moulton 457bac97fa Parses InnerClasses attribute of java bytecode.
In this commit, nothing is done with the data.
2018-07-03 10:19:58 +01:00
thk123 fd2f21e77c Use new method to set the name 2018-07-02 11:29:14 +01:00
thk123 190b4852ea Introduce method for getting the name of of java_class_type 2018-07-02 11:29:14 +01:00
thk123 dabc169dda Given string types an appropriate name
This is used when constructing a symbol_typet from a struct_typet
2018-06-29 17:00:59 +01:00
Chris Smowton 6fd77f4ad2
Merge pull request #2472 from smowton/smowton/fix/nondet-stringbuilders
Java object factory: initialize AbstractStringBuilder-derived types correctly
2018-06-28 10:22:03 +01:00
Chris Smowton a2a5662abb
Merge pull request #2263 from JohnDumbell/bugfix/nondet_direct_return
Fix for nondet replacement on a direct return pre-remove returns
2018-06-28 09:24:57 +01:00
Peter Schrammel bbf0d0288c
Merge pull request #2482 from antlechner/antonia/direct-children-of-class
Make direct children of a class publicly available
2018-06-27 13:28:29 -04:00
Thomas Kiley c982c21111
Merge pull request #2486 from Degiorgio/jbmc-synchronoization-asymmetry-fix
JBMC: Fixed asymmetry between synchronized blocks and methods.
2018-06-27 18:10:01 +01:00
Chris Smowton 8e7b6e7cdf Java object factory: initialize AbstractStringBuilder-derived types correctly
These are currently initialized as if they are directly derived from Object, which causes a crash due to the
type inconsistency between StringBuilder { AbstractStringBuilder { Object { } } } and StringBuilder { Object { } }

With this change they are initialised more like normal types, which has the side-effect that any fields they possess
that are *not* special-cased by `initialize_nondet_string_fields` are nondet-initialized as for any other type.

I add a test verifying this new behaviour, and a simpler test checking that Builder and Buffer are usable as
nondet arguments at all.
2018-06-27 17:12:07 +01:00
Antonia Lechner 9af7ef1356 Add tests for new class_hierarchy_grapht functions 2018-06-27 15:53:26 +01:00
Antonia Lechner 79cad15ba6 Fix existing class hierarchy test syntax
These two tests were previously never run because of a missing comma in
the SCENARIO line. The two scenarios also need to have different names.
2018-06-27 15:53:26 +01:00
Kurt Degiorgio da7650048d JBMC: Fixed asymmetry between synchronized blocks and methods.
Previously, the conversation of synchronized methods only took place if
the 'java-threading' flag is specified, while in the case of
synchronized blocks the conversation is undertaken with and without the
aforementioned flag. This commit fixes this asymmetry by replacing
the instructions 'monitorenter' and 'moinitorexit' with 'code_skipt' if
the 'java-threading' option is not specified (instead of instrumenting
calls to 'java::java.lang.Object.monitorexit/enter').

The 'monitorenter' and monitiorexit instructions are also replaced with
a 'code_skipt' if the Java-core-models library is not loaded. This
prevents JBMC from outputting missing function-body warnings.

Commit also modifies relevant regression tests.
2018-06-26 17:57:47 +01:00
Daniel Kroening 59186406bb
Merge pull request #2487 from JohnDumbell/bugfix/add_java_load_class
Adds --java-load-class to tests that require it
2018-06-26 17:56:26 +01:00
johndumbell 91e8b89b73 Fix for nondet replacement on a direct return (pre-remove returns)
If remove returns hasn't been run and the nondet method call was a direct return - return nondetWithoutNull() - an assertion was hit because it couldn't find the destination assignment to add the nondet value too. This change just adds that particular situation in, saying if we can't find an assignment it's likely to be a return and then attempts to look for that.

The logic is also very slightly modified to replace the code of the target instruction instead of destroying it, creating a new one and inserting that directly afterwards.
2018-06-26 16:25:38 +01:00
johndumbell e708bfb52f Adds --java-load-class to tests that require it
Passing .class files in the arguments list is (soon) to be deprecated, this just cleans up the last few places where this was happening in tests.
2018-06-26 15:52:49 +01:00
Michael Tautschnig 7191f2355b Do not unnecessarily mark local variables static 2018-06-25 17:30:58 +01:00
Michael Tautschnig 93300aaaa4 Use string2unsigned when reading/expecting an unsigned 2018-06-25 17:29:54 +01:00
Michael Tautschnig 4193f02b10 Remove unused parameters message_handler, ns 2018-06-25 17:14:40 +01:00
Michael Tautschnig cdb7e52355
Merge pull request #2453 from tautschnig/vs-deprected-uint
Deprecate get_unsigned_int
2018-06-25 17:09:08 +01:00
Daniel Kroening bdac907e67
Merge pull request #2459 from tautschnig/cmake-cleanup
Remove no-longer-existent-files from exclusion lists in CMake files
2018-06-25 15:31:49 +01:00
Michael Tautschnig ce6a297c7e Use auto to avoid unnecessary signed/unsigned conversion 2018-06-25 14:10:44 +01:00
Michael Tautschnig 79ef045994 Deprecate get_unsigned_int
Using "unsigned" is almost always wrong - the type is unrelated to both the
machine type the code is compiled on as well as the width of the platform we are
running an analysis for.

get_unsigned_int specifically was used inconsistently: the same entry (ID_width)
is set via APIs with a parameter of type size_t and several places already used
get_size_t.
2018-06-25 14:03:11 +01:00
Michael Tautschnig c528c2539a Remove no-longer-existent-files from exclusion lists in CMake files 2018-06-25 13:38:10 +01:00
Michael Tautschnig c2a8fb8b44 Do not use count() when returning a bool
Visual Studio complains about the conversion. Here, constructing an elaborate
container (including heap-allocated memory) is unnecessary.
2018-06-25 08:47:20 +01:00
Chris Smowton 62ec461a59
Merge pull request #2360 from smowton/smowton/fix/dont-deref-null-for-class-identifier-v2
SEC-472 Java instanceof: avoid dereferencing null pointer
2018-06-25 08:38:56 +01:00
Chris Smowton 0784f77539
Merge pull request #2125 from smowton/smowton/feature/symex-ignore-null-derefs
Symex: ignore null dereferences when targeting Java
2018-06-24 21:08:55 +01:00
Chris Smowton 2369df3221 Add message handler to remove_instanceof and _exceptions
This enables reporting errors from remove_instanceof usage of goto_convert.
2018-06-24 17:40:20 +01:00
Chris Smowton 419bc1b5fe Java instanceof: avoid dereferencing null pointer
Previously our code was of the form
tmp = x->@class_identifier
is_instanceof = x != null && tmp == "A" || tmp == "B" || ...

This was harmless as the value read from a null pointer was never used if it was null, but
would present a spurious dereference of a possibly-null pointer, introducing false uncertainty
about the vallue of `tmp`. Therefore we now generate:

if x == null:
  is_instanceof = false
else:
  tmp = x->@class_identifier
  is_instanceof = tmp == "A" || tmp == "B" || ...
2018-06-24 17:40:20 +01:00
Chris Smowton 9fd3434c96 Use local-safe-pointers analysis to improve Symex pointer resolution
This uses local_safe_pointerst to determine when symex dereferences a pointer
that cannot be null. When it does the null result is excluded from the possible
values, and therefore a $invalid_object reference may be excluded from the result
of dereferencing such a pointer. This can improve constant propagation.
2018-06-24 17:39:50 +01:00
Kurt Degiorgio 68ac56610f JBMC: Regression tests for synchronized methods 2018-06-24 15:35:03 +01:00
Kurt Degiorgio c0ee3161d9 JBMC: Support for synchronized methods
This commit adds support for synchronized methods by instrumenting all
methods marked with the synchronization flag with calls to
'monitorenter' and 'monitorexit'. These two methods are located in the
java models library and implement a critical section.

To this end the following changes are made:

1. New irep_id, 'is_synchronized', to represent the synchronized keyword
   and appropriate changes to 'java_byecode_convert_method.cpp' to set
   this flag when a synchronized method is encountered.
2. Setting of the 'is_static' flag when the method in question is static.
3. Functions to find and instrument synchronized methods. Specifically,
   calls to "java::java.lang.Object.monitorenter:(Ljava/lang/Object;)V"
   and "java::java.lang.Object.monitorexit:(Ljava/lang/Object;)V" are
   respectively instrumented at the start and end of a synchronized
   method . Note, the former is instrumented at every point where
   the execution of the synchronized methods terminates. Specifically
   out of order return statements and exceptions.

Static synchronized methods are not supported yet as the synchronization
semantics for static methods is different (locking on the class instead
the of the object). Upon encountering a static synchronized method the
current implementation will ignore the synchronized flag.  (showing a
warning in the process). This may obviously result in superfluous
interleavings.

Note: instrumentation of synchronized methods is only triggered if the
      '--java-threading' command line option is specified.

Note': instrumentation of synchronized methods requires the use of the
       java core models library as the locking mechanism is implemented
       in the model 'java.long.Object'.
2018-06-24 15:35:03 +01:00
Kurt Degiorgio 7efa7bf555 JBMC: Regression tests for multi-threaded java programs 2018-06-24 15:35:03 +01:00
Dario Cattaruzza 4d91aa5f17 JBMC: Modified the instrumentation of monitorexit/enter instructions
The monitorenter and monitorexit instructions are used by the JVM to
coordinate access to an object in the context of multiple threads.

We have previously added two methods to the object model that use a
counter to implement a reentrant lock. Calls to
'org.cprover.CProver.atomicBegin:()V"' and
'org.cprover.CProver.atomicEnd:()V' ensure that multiple threads do
not race in the access/modification of this counter.

In-order to support synchronization blocks, when the
monitorexit/moniitorenter bytecode instruction is executed JBMC must
call the aforementioned object model. To this end,  this commit makes
the following changes:

1. Transforms the monitorenter and monitorexit bytecode instructions
   into function-calls to the object model. Specifically,
   'java.lang.Object.monitorenter:(Ljava/lang/Object;)V' and
   'java.lang.Object.monitorexit:(Ljava/lang/Object;)V'.

2.  Transforms 'org.cprover.CProver.atomicBegin:()V"' and
    'org.cprover.CProver.atomicEnd:()V' into the appropriate
    codet instructions.

Added the appropriate target-handlers if monitorenter or monitorexit
are in the context of a try-catch block.
2018-06-24 15:35:02 +01:00
Kurt Degiorgio 0691f030bc JBMC: Zero-initialized 'cproverMonitorCount' component and removed
'@lock' field (fixes #2307)

The 'cproverMonitorCount' field is a counter in the 'java.lang.Object'
model (part of the java core models library). This field is used to
implement a critical section and is thus necessary to support
concurrency.

This commit makes sure that this field (if present) is always zero
initialized as it is not meant to be non-deterministic.

This field is present only if the java core models library is loaded.

Additionally, the commit removes '@lock' field from root class
(usually: 'java.lang.Object') as it has been superseded by a locking
mechanism implemented in the java core models library.

Modified relevant unit/regression tests to reflect this change.
2018-06-24 15:35:02 +01:00
Kurt Degiorgio 0b90c17a8c JBMC: Moved format_classpath.sh to scripts/format_classpath.sh
'format_classpath.sh' is used in regression tests that make use of the
'classpath' option. This script is needed to deal with the fact that
classpath syntex is OS-dependent.

The java concurrency regression tests make heavy use of this option as
such this commit moves 'format_classpath.sh' to
'scripts/format_classpath.sh'.

Furthermore, this commit makes a very small change to 'appveyor.yml'
that enables existing java concurrency regression tests to run on
Windows.
2018-06-24 15:35:02 +01:00
Michael Tautschnig 475fe2049e
Merge pull request #2393 from tautschnig/git-info-cmake-fixes
CBMC_VERSION: Use generated include files instead of command-line defines
2018-06-24 08:34:23 +01:00
Michael Tautschnig 0498da913d
Merge pull request #2400 from tautschnig/vs-return-type
Fix return type of nodes_empty
2018-06-23 23:53:06 +01:00
Michael Tautschnig 2eb9156abc
Merge pull request #2406 from tautschnig/vs-sizet1
Use std::size_t instead of int to match types at callsites
2018-06-23 23:23:16 +01:00
Michael Tautschnig e638f72c8f CBMC_VERSION: Use generated include files instead of command-line defines
Also fixes a number of shortcomings of the earlier approach as far as CMake is
concerned:
- Adds --dirty to the git command line (as is done for Makefiles).
- Does not require a rebuild when there are no changes to the version string.
- CBMC release number updates will be reflected and trigger a rebuild (even when
  no other changes have taken place).
2018-06-23 20:41:45 +00:00
Michael Tautschnig 6256290240 Fix return type of nodes_empty 2018-06-23 19:17:07 +01:00
Michael Tautschnig bd4faad628 Use std::size_t instead of int to match types at callsites 2018-06-23 19:15:00 +01:00
Michael Tautschnig 2afa919e4e Explicitly compare int to zero to avoid Visual Studio warning 2018-06-23 19:09:08 +01:00
Michael Tautschnig d7ef0bc201 Fix coreModels test to match latest java models library
As of the update in https://github.com/diffblue/java-models-library/pull/5
cprover.CProver no longer has a static initializer.
2018-06-23 15:09:12 +00:00
Thomas Kiley 8f6dab8c92
Merge pull request #2261 from thk123/bugfix/TG-3652/wrong-generic-type-two-params
Don't store generic values as comments [TG-3652]
2018-06-22 08:02:40 +01:00
Thomas Kiley 262affba78
Merge pull request #2350 from thk123/feature/TG-3813/load-specified-methods
[TG-3813] Allow specifying specific methods by regex to be loaded by lazy methods
2018-06-22 07:44:27 +01:00