Skip to content

Commit 5fe44ed

Browse files
author
svorenova
committed
Pass information to clinit_wrapper constructors
Pass parameters necessary to nondet-initialize variables
1 parent 655978c commit 5fe44ed

File tree

3 files changed

+68
-14
lines changed

3 files changed

+68
-14
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,18 @@ bool java_bytecode_languaget::convert_single_method(
10311031
case synthetic_method_typet::STATIC_INITIALIZER_WRAPPER:
10321032
if(threading_support)
10331033
symbol.value = get_thread_safe_clinit_wrapper_body(
1034-
function_id, symbol_table);
1034+
function_id,
1035+
symbol_table,
1036+
nondet_static,
1037+
object_factory_parameters,
1038+
get_pointer_type_selector());
10351039
else
1036-
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
1040+
symbol.value = get_clinit_wrapper_body(
1041+
function_id,
1042+
symbol_table,
1043+
nondet_static,
1044+
object_factory_parameters,
1045+
get_pointer_type_selector());
10371046
break;
10381047
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
10391048
symbol.value =

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,19 @@ gen_clinit_eqexpr(const exprt &expr, const clinit_statest state)
184184
/// \param symbol_table: symbol table
185185
/// \param class_name: name of the class to generate clinit wrapper calls for
186186
/// \param [out] init_body: appended with calls to clinit wrapper
187+
/// \param nondet_static: true if nondet-static option was given
188+
/// \param object_factory_parameters: object factory parameters used to populate
189+
/// nondet-initialized globals and objects reachable from them (only needed
190+
/// if nondet-static is true)
191+
/// \param pointer_type_selector: used to choose concrete types for abstract-
192+
/// typed globals and fields (only needed if nondet-static is true)
187193
static void clinit_wrapper_do_recursive_calls(
188194
const symbol_tablet &symbol_table,
189195
const irep_idt &class_name,
190-
code_blockt &init_body)
196+
code_blockt &init_body,
197+
const bool nondet_static,
198+
const object_factory_parameterst &object_factory_parameters,
199+
const select_pointer_typet &pointer_type_selector)
191200
{
192201
const symbolt &class_symbol = symbol_table.lookup_ref(class_name);
193202
for(const auto &base : to_class_type(class_symbol.type).bases())
@@ -316,9 +325,9 @@ static void create_clinit_wrapper_symbols(
316325
"clinit wrapper");
317326
}
318327

319-
/// Thread safe version of the static initialiser.
328+
/// Thread safe version of the static initializer.
320329
///
321-
/// Produces the static initialiser wrapper body for the given function. This
330+
/// Produces the static initializer wrapper body for the given function. This
322331
/// static initializer implements (a simplification of) the algorithm defined
323332
/// in Section 5.5 of the JVM Specs. This function, or wrapper, checks whether
324333
/// static init has already taken place, calls the actual `<clinit>` method if
@@ -382,10 +391,19 @@ static void create_clinit_wrapper_symbols(
382391
/// \param function_id: clinit wrapper function id (the wrapper_method_symbol
383392
/// name created by `create_clinit_wrapper_symbols`)
384393
/// \param symbol_table: global symbol table
385-
/// \return the body of the static initialiser wrapper
394+
/// \param nondet_static: true if nondet-static option was given
395+
/// \param object_factory_parameters: object factory parameters used to populate
396+
/// nondet-initialized globals and objects reachable from them (only needed
397+
/// if nondet-static is true)
398+
/// \param pointer_type_selector: used to choose concrete types for abstract-
399+
/// typed globals and fields (only needed if nondet-static is true)
400+
/// \return the body of the static initializer wrapper
386401
codet get_thread_safe_clinit_wrapper_body(
387402
const irep_idt &function_id,
388-
symbol_table_baset &symbol_table)
403+
symbol_table_baset &symbol_table,
404+
const bool nondet_static,
405+
const object_factory_parameterst &object_factory_parameters,
406+
const select_pointer_typet &pointer_type_selector)
389407
{
390408
const symbolt &wrapper_method_symbol = symbol_table.lookup_ref(function_id);
391409
irep_idt class_name = wrapper_method_symbol.type.get(ID_C_class);
@@ -536,7 +554,13 @@ codet get_thread_safe_clinit_wrapper_body(
536554
//
537555
{
538556
code_blockt init_body;
539-
clinit_wrapper_do_recursive_calls(symbol_table, class_name, init_body);
557+
clinit_wrapper_do_recursive_calls(
558+
symbol_table,
559+
class_name,
560+
init_body,
561+
nondet_static,
562+
object_factory_parameters,
563+
pointer_type_selector);
540564
function_body.append(init_body);
541565
}
542566

@@ -557,15 +581,24 @@ codet get_thread_safe_clinit_wrapper_body(
557581
return function_body;
558582
}
559583

560-
/// Produces the static initialiser wrapper body for the given function.
584+
/// Produces the static initializer wrapper body for the given function.
561585
/// Note: this version of the clinit wrapper is not thread safe.
562586
/// \param function_id: clinit wrapper function id (the wrapper_method_symbol
563587
/// name created by `create_clinit_wrapper_symbols`)
564588
/// \param symbol_table: global symbol table
565-
/// \return the body of the static initialiser wrapper/
589+
/// \param nondet_static: true if nondet-static option was given
590+
/// \param object_factory_parameters: object factory parameters used to populate
591+
/// nondet-initialized globals and objects reachable from them (only needed
592+
/// if nondet-static is true)
593+
/// \param pointer_type_selector: used to choose concrete types for abstract-
594+
/// typed globals and fields (only needed if nondet-static is true)
595+
/// \return the body of the static initializer wrapper
566596
codet get_clinit_wrapper_body(
567597
const irep_idt &function_id,
568-
symbol_table_baset &symbol_table)
598+
symbol_table_baset &symbol_table,
599+
const bool nondet_static,
600+
const object_factory_parameterst &object_factory_parameters,
601+
const select_pointer_typet &pointer_type_selector)
569602
{
570603
// Assume that class C extends class C' and implements interfaces
571604
// I1, ..., In. We now create the following function (possibly recursively
@@ -609,7 +642,13 @@ codet get_clinit_wrapper_body(
609642
code_assignt set_already_run(already_run_symbol.symbol_expr(), true_exprt());
610643
init_body.move_to_operands(set_already_run);
611644

612-
clinit_wrapper_do_recursive_calls(symbol_table, class_name, init_body);
645+
clinit_wrapper_do_recursive_calls(
646+
symbol_table,
647+
class_name,
648+
init_body,
649+
nondet_static,
650+
object_factory_parameters,
651+
pointer_type_selector);
613652

614653
wrapper_body.then_case() = init_body;
615654

jbmc/src/java_bytecode/java_static_initializers.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ void create_static_initializer_wrappers(
2929

3030
codet get_thread_safe_clinit_wrapper_body(
3131
const irep_idt &function_id,
32-
symbol_table_baset &symbol_table);
32+
symbol_table_baset &symbol_table,
33+
const bool nondet_static,
34+
const object_factory_parameterst &object_factory_parameters,
35+
const select_pointer_typet &pointer_type_selector);
3336

3437
codet get_clinit_wrapper_body(
3538
const irep_idt &function_id,
36-
symbol_table_baset &symbol_table);
39+
symbol_table_baset &symbol_table,
40+
const bool nondet_static,
41+
const object_factory_parameterst &object_factory_parameters,
42+
const select_pointer_typet &pointer_type_selector);
3743

3844
class stub_global_initializer_factoryt
3945
{

0 commit comments

Comments
 (0)