Skip to content

Commit f4d9441

Browse files
author
svorenova
committed
Pass information to clinit_wrapper constructors
Pass parameters necessary to nondet-initialize variables
1 parent 8dcc5b2 commit f4d9441

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
@@ -1035,9 +1035,18 @@ bool java_bytecode_languaget::convert_single_method(
10351035
case synthetic_method_typet::STATIC_INITIALIZER_WRAPPER:
10361036
if(threading_support)
10371037
symbol.value = get_thread_safe_clinit_wrapper_body(
1038-
function_id, symbol_table);
1038+
function_id,
1039+
symbol_table,
1040+
nondet_static,
1041+
object_factory_parameters,
1042+
get_pointer_type_selector());
10391043
else
1040-
symbol.value = get_clinit_wrapper_body(function_id, symbol_table);
1044+
symbol.value = get_clinit_wrapper_body(
1045+
function_id,
1046+
symbol_table,
1047+
nondet_static,
1048+
object_factory_parameters,
1049+
get_pointer_type_selector());
10411050
break;
10421051
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
10431052
symbol.value =

jbmc/src/java_bytecode/java_static_initializers.cpp

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

318-
/// Thread safe version of the static initialiser.
327+
/// Thread safe version of the static initializer.
319328
///
320-
/// Produces the static initialiser wrapper body for the given function. This
329+
/// Produces the static initializer wrapper body for the given function. This
321330
/// static initializer implements (a simplification of) the algorithm defined
322331
/// in Section 5.5 of the JVM Specs. This function, or wrapper, checks whether
323332
/// static init has already taken place, calls the actual `<clinit>` method if
@@ -381,10 +390,19 @@ static void create_clinit_wrapper_symbols(
381390
/// \param function_id: clinit wrapper function id (the wrapper_method_symbol
382391
/// name created by `create_clinit_wrapper_symbols`)
383392
/// \param symbol_table: global symbol table
384-
/// \return the body of the static initialiser wrapper
393+
/// \param nondet_static: true if nondet-static option was given
394+
/// \param object_factory_parameters: object factory parameters used to populate
395+
/// nondet-initialized globals and objects reachable from them (only needed
396+
/// if nondet-static is true)
397+
/// \param pointer_type_selector: used to choose concrete types for abstract-
398+
/// typed globals and fields (only needed if nondet-static is true)
399+
/// \return the body of the static initializer wrapper
385400
codet get_thread_safe_clinit_wrapper_body(
386401
const irep_idt &function_id,
387-
symbol_table_baset &symbol_table)
402+
symbol_table_baset &symbol_table,
403+
const bool nondet_static,
404+
const object_factory_parameterst &object_factory_parameters,
405+
const select_pointer_typet &pointer_type_selector)
388406
{
389407
const symbolt &wrapper_method_symbol = symbol_table.lookup_ref(function_id);
390408
irep_idt class_name = wrapper_method_symbol.type.get(ID_C_class);
@@ -535,7 +553,13 @@ codet get_thread_safe_clinit_wrapper_body(
535553
//
536554
{
537555
code_blockt init_body;
538-
clinit_wrapper_do_recursive_calls(symbol_table, class_name, init_body);
556+
clinit_wrapper_do_recursive_calls(
557+
symbol_table,
558+
class_name,
559+
init_body,
560+
nondet_static,
561+
object_factory_parameters,
562+
pointer_type_selector);
539563
function_body.append(init_body);
540564
}
541565

@@ -556,15 +580,24 @@ codet get_thread_safe_clinit_wrapper_body(
556580
return function_body;
557581
}
558582

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

611-
clinit_wrapper_do_recursive_calls(symbol_table, class_name, init_body);
644+
clinit_wrapper_do_recursive_calls(
645+
symbol_table,
646+
class_name,
647+
init_body,
648+
nondet_static,
649+
object_factory_parameters,
650+
pointer_type_selector);
612651

613652
wrapper_body.then_case() = init_body;
614653

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)