cprover
java_entry_point.h File Reference
#include "java_bytecode_language.h"
#include "select_pointer_type.h"
#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'"
 

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 object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, bool string_refinement_enabled)
 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 assume_init_pointers_not_null, bool assert_uncaught_exceptions, const object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector)
 Generate a _start function for a specific function. More...
 

Macro Definition Documentation

◆ JAVA_ENTRY_POINT_EXCEPTION_SYMBOL

#define JAVA_ENTRY_POINT_EXCEPTION_SYMBOL   "uncaught_exception'"

Definition at line 20 of file java_entry_point.h.

Referenced by generate_java_start_function(), and java_record_outputs().

◆ JAVA_ENTRY_POINT_RETURN_SYMBOL

#define JAVA_ENTRY_POINT_RETURN_SYMBOL   "return'"

Definition at line 19 of file java_entry_point.h.

Referenced by generate_java_start_function(), and java_record_outputs().

Function Documentation

◆ generate_java_start_function()

bool generate_java_start_function ( const symbolt symbol,
symbol_table_baset symbol_table,
message_handlert message_handler,
bool  assume_init_pointers_not_null,
bool  assert_uncaught_exceptions,
const object_factory_parameterst object_factory_parameters,
const select_pointer_typet pointer_type_selector 
)

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
assume_init_pointers_not_nullWhen creating pointers, assume they always take a non-null value.
max_nondet_array_lengthThe length of the arrays to create when filling them
max_nondet_tree_depthdefines the maximum depth of the object tree (see java_entry_points documentation for details)
pointer_type_selectorLogic for substituting types of pointers
Returns
true if error occurred on entry point search, false otherwise

Definition at line 577 of file java_entry_point.cpp.

References symbol_table_baset::add(), exprt::add_source_location(), code_function_callt::arguments(), symbolt::base_name, exprt::copy_to_operands(), goto_functionst::entry_point(), messaget::eom(), messaget::error(), code_function_callt::function(), code_labelt::get_label(), INITIALIZE_FUNCTION, symbol_table_baset::insert(), symbolt::is_static_lifetime, java_build_arguments(), java_bytecode_instrument_uncaught_exceptions(), JAVA_ENTRY_POINT_EXCEPTION_SYMBOL, JAVA_ENTRY_POINT_RETURN_SYMBOL, java_record_outputs(), java_reference_type(), code_function_callt::lhs(), loc, symbolt::location, irept::make_nil(), message_handler, symbolt::mode, exprt::move_to_operands(), symbolt::name, code_typet::return_type(), irept::swap(), symbolt::symbol_expr(), symbol_table_baset::symbols, to_code_type(), to_pointer_type(), symbolt::type, and symbolt::value.

Referenced by java_entry_point().

◆ 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 88 of file java_entry_point.cpp.

Referenced by ci_lazy_methodst::convert_and_analyze_method(), and get_class_literal_initializer().

◆ get_main_symbol()

◆ java_entry_point()

bool java_entry_point ( symbol_table_baset symbol_table,
const irep_idt main_class,
message_handlert message_handler,
bool  assume_init_pointers_not_null,
bool  assert_uncaught_exceptions,
const object_factory_parameterst object_factory_parameters,
const select_pointer_typet pointer_type_selector,
bool  string_refinement_enabled 
)

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 (codet with id ID_output), together with other objects possibly altered by the execution 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.
Returns
true if error occurred on entry point search

Definition at line 519 of file java_entry_point.cpp.

References create_initialize(), goto_functionst::entry_point(), generate_java_start_function(), get_main_symbol(), irept::id(), main_function_resultt::is_success(), java_static_lifetime_init(), symbolt::location, main_function_resultt::main_function, message_handler, symbol_table_baset::symbols, and symbolt::type.

Referenced by java_bytecode_languaget::generate_support_functions().