CBMC
java_entry_point.h File Reference
#include <util/irep.h>
#include <util/symbol.h>
+ Include dependency graph for java_entry_point.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  main_function_resultt
 

Macros

#define JAVA_ENTRY_POINT_RETURN_SYMBOL   "return'"
 
#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL   "uncaught_exception'"
 

Typedefs

using build_argumentst = std::function< std::pair< code_blockt, std::vector< exprt > >(const symbolt &function, symbol_table_baset &symbol_table)>
 

Functions

bool java_entry_point (class symbol_table_baset &symbol_table, const irep_idt &main_class, class message_handlert &message_handler, bool assume_init_pointers_not_null, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, const build_argumentst &build_arguments)
 Given the symbol_table and the main_class to test, this function generates a new function __CPROVER__start that calls the method under tests. More...
 
irep_idt get_java_class_literal_initializer_signature ()
 Get the symbol name of java.lang.Class' initializer method. More...
 
main_function_resultt get_main_symbol (const symbol_table_baset &symbol_table, const irep_idt &main_class, message_handlert &)
 Figures out the entry point of the code to verify. More...
 
bool generate_java_start_function (const symbolt &symbol, class symbol_table_baset &symbol_table, class message_handlert &message_handler, bool assert_uncaught_exceptions, const java_object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, const build_argumentst &build_arguments)
 Generate a _start function for a specific function. More...
 
std::pair< code_blockt, std::vector< exprt > > java_build_arguments (const symbolt &function, symbol_table_baset &symbol_table, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, message_handlert &message_handler)
 
void create_java_initialize (symbol_table_baset &symbol_table)
 Adds __cprover_initialize to the symbol_table but does not generate code for it yet. More...
 
void java_static_lifetime_init (symbol_table_baset &symbol_table, const source_locationt &source_location, bool assume_init_pointers_not_null, java_object_factory_parameterst object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled, message_handlert &message_handler)
 Adds the body to __CPROVER_initialize. More...
 

Macro Definition Documentation

◆ JAVA_ENTRY_POINT_EXCEPTION_SYMBOL

#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL   "uncaught_exception'"

Definition at line 22 of file java_entry_point.h.

◆ JAVA_ENTRY_POINT_RETURN_SYMBOL

#define JAVA_ENTRY_POINT_RETURN_SYMBOL   "return'"

Definition at line 21 of file java_entry_point.h.

Typedef Documentation

◆ build_argumentst

using build_argumentst = std::function<std::pair<code_blockt, std::vector<exprt> >( const symbolt &function, symbol_table_baset &symbol_table)>

Definition at line 24 of file java_entry_point.h.

Function Documentation

◆ create_java_initialize()

void create_java_initialize ( symbol_table_baset symbol_table)

Adds __cprover_initialize to the symbol_table but does not generate code for it yet.

Definition at line 48 of file java_entry_point.cpp.

◆ generate_java_start_function()

bool generate_java_start_function ( const symbolt symbol,
class symbol_table_baset symbol_table,
class message_handlert message_handler,
bool  assert_uncaught_exceptions,
const java_object_factory_parameterst object_factory_parameters,
const select_pointer_typet pointer_type_selector,
const build_argumentst build_arguments 
)

Generate a _start function for a specific function.

See java_entry_point for more details.

Parameters
symbolThe symbol representing the function to call
symbol_tableGlobal symbol table
message_handlerWhere to write output to
assert_uncaught_exceptionsAdd an uncaught-exception check
object_factory_parametersParameters for creation of arguments
pointer_type_selectorLogic for substituting types of pointers
build_argumentsThe function which builds the codets which initialise the arguments for a function.
Returns
true if error occurred on entry point search, false otherwise

Definition at line 637 of file java_entry_point.cpp.

◆ get_java_class_literal_initializer_signature()

irep_idt get_java_class_literal_initializer_signature ( )

Get the symbol name of java.lang.Class' initializer method.

This method should initialize a Class instance with known properties of the type it represents, such as its name, whether it is abstract, or an enumeration, etc. The method may or may not exist in any particular symbol table; it is up to the caller to check. The method's Java signature is: void cproverInitializeClassLiteral( String name, boolean isAnnotation, boolean isArray, boolean isInterface, boolean isSynthetic, boolean isLocalClass, boolean isMemberClass, boolean isEnum);

Returns
Class initializer method's symbol name.

Definition at line 77 of file java_entry_point.cpp.

◆ get_main_symbol()

main_function_resultt get_main_symbol ( const symbol_table_baset symbol_table,
const irep_idt main_class,
message_handlert message_handler 
)

Figures out the entry point of the code to verify.

Definition at line 548 of file java_entry_point.cpp.

◆ java_build_arguments()

std::pair<code_blockt, std::vector<exprt> > java_build_arguments ( const symbolt function,
symbol_table_baset symbol_table,
bool  assume_init_pointers_not_null,
java_object_factory_parameterst  object_factory_parameters,
const select_pointer_typet pointer_type_selector,
message_handlert message_handler 
)
Parameters
functionThe function under test, for which to build the arguments.
symbol_tableFor the purposes of adding any local variables generated or any functions which are generated and called.
assume_init_pointers_not_nullIf this is true then any reference type parameters to the function under tests are assumed to be non-null.
object_factory_parametersConfiguration of the object factory.
pointer_type_selectorMeans of selecting the type of value constructed for reference types which are initialised by the code returned.
message_handlerlog
Returns
A pairing of the code to initialise the arguments and a std::vector of the expressions for these arguments. The vector contains one element per parameter of function. The vector of expressions can be used as arguments for function. The code returned allocates the objects used as test arguments for the function under test (function) and non-deterministically initializes them. This code returned must be placed into the code block of the function call, before the function call. Typically this code block would be __CPROVER__start.

Definition at line 321 of file java_entry_point.cpp.

◆ java_entry_point()

bool java_entry_point ( class symbol_table_baset symbol_table,
const irep_idt main_class,
class message_handlert message_handler,
bool  assume_init_pointers_not_null,
bool  assert_uncaught_exceptions,
const java_object_factory_parameterst object_factory_parameters,
const select_pointer_typet pointer_type_selector,
bool  string_refinement_enabled,
const build_argumentst build_arguments 
)

Given the symbol_table and the main_class to test, this function generates a new function __CPROVER__start that calls the method under tests.

If __CPROVER__start is already in the symbol_table, it silently returns. Otherwise it finds the method under test using get_main_symbol and constructs a body for __CPROVER__start which does as follows:

  1. Allocates and initializes the parameters of the method under test.
  2. Call it and save its return variable in the variable 'return'.
  3. Declare variable 'return' as an output variable using a code_outputt, together with other objects possibly altered by the execution of the method under test (in java_record_outputs)

When assume_init_pointers_not_null is false, the generated parameter initialization code will non-deterministically set input parameters to either null or a stack-allocated object. Observe that the null/non-null setting only applies to the parameter itself, and is not propagated to other pointers that it might be necessary to initialize in the object tree rooted at the parameter. Parameter max_nondet_array_length provides the maximum length for an array used as part of the input to the method under test, and max_nondet_tree_depth defines the maximum depth of the object tree created for such inputs. This maximum depth is used in conjunction with the so-called "recursive type set" (see field recursive_set in class java_object_factoryt) to bound the depth of the object tree for the parameter. Only when

  • the depth of the tree is >= max_nondet_tree_depth AND
  • the type of the object under initialization is already found in the recursive set then that object is not initalized and the reference pointing to it is (deterministically) set to null. This is a source of underapproximation in our approach to test generation, and should perhaps be fixed in the future.
Parameters
symbol_tableGlobal symbol table
main_classIdentifier of a class within which the main method to be analysed exists. This may be empty if the intention is not to analyse the main method.
message_handlerWhere to write output to.
assume_init_pointers_not_nullIf this is true then any reference type parameters to the function under tests are assumed to be non-null.
assert_uncaught_exceptionsAdd an uncaught-exception check.
object_factory_parametersParameters for creation of arguments.
pointer_type_selectorLogic for substituting types of pointers.
string_refinement_enabledIf true, string refinement's string data structure will also be initialised and added to the symbol table.
build_argumentsThe function which builds the codets which initialise the arguments for a function.
Returns
true if error occurred on entry point search

Definition at line 602 of file java_entry_point.cpp.

◆ java_static_lifetime_init()

void java_static_lifetime_init ( symbol_table_baset symbol_table,
const source_locationt source_location,
bool  assume_init_pointers_not_null,
java_object_factory_parameterst  object_factory_parameters,
const select_pointer_typet pointer_type_selector,
bool  string_refinement_enabled,
message_handlert message_handler 
)

Adds the body to __CPROVER_initialize.

Definition at line 227 of file java_entry_point.cpp.