Skip to content

Commit e53acb9

Browse files
committed
Generate INITIALIZE_FUNCTION from convert_single_method
This allows for an external lazy methods driver to control when the `INITIALIZE_FUNCTION` is generated.
1 parent aca06bd commit e53acb9

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <string>
1212

13+
#include <linking/static_lifetime_init.h>
14+
1315
#include <util/cmdline.h>
1416
#include <util/config.h>
1517
#include <util/expr_iterator.h>
@@ -757,6 +759,7 @@ bool java_bytecode_languaget::typecheck(
757759
"the Java front-end should only be used with an empty symbol table");
758760

759761
java_internal_additions(symbol_table);
762+
create_java_initialize(symbol_table);
760763

761764
if(language_options->string_refinement_enabled)
762765
string_preprocess.initialize_conversion_table();
@@ -942,6 +945,8 @@ bool java_bytecode_languaget::typecheck(
942945
convert_single_method(
943946
method_sig.first, journalling_symbol_table, class_to_declared_symbols);
944947
}
948+
convert_single_method(
949+
INITIALIZE_FUNCTION, journalling_symbol_table, class_to_declared_symbols);
945950
// Now convert all newly added string methods
946951
for(const auto &fn_name : journalling_symbol_table.get_inserted())
947952
{
@@ -1095,6 +1100,7 @@ void java_bytecode_languaget::methods_provided(
10951100
// Add all synthetic methods to map
10961101
for(const auto &kv : synthetic_methods)
10971102
methods.insert(kv.first);
1103+
methods.insert(INITIALIZE_FUNCTION);
10981104
}
10991105

11001106
/// \brief Promote a lazy-converted method (one whose type is known but whose
@@ -1120,7 +1126,7 @@ void java_bytecode_languaget::convert_lazy_method(
11201126
convert_single_method(function_id, symbol_table, class_to_declared_symbols);
11211127

11221128
// Instrument runtime exceptions (unless symbol is a stub)
1123-
if(symbol.value.is_not_nil())
1129+
if(symbol.value.is_not_nil() && function_id != INITIALIZE_FUNCTION)
11241130
{
11251131
java_bytecode_instrument_symbol(
11261132
symbol_table,
@@ -1201,6 +1207,20 @@ bool java_bytecode_languaget::convert_single_method(
12011207
// Nothing to do if body is already loaded
12021208
if(symbol.value.is_not_nil())
12031209
return false;
1210+
1211+
if(function_id == INITIALIZE_FUNCTION)
1212+
{
1213+
java_static_lifetime_init(
1214+
symbol_table,
1215+
symbol.location,
1216+
language_options->assume_inputs_non_null,
1217+
object_factory_parameters,
1218+
*pointer_type_selector,
1219+
language_options->string_refinement_enabled,
1220+
get_message_handler());
1221+
return false;
1222+
}
1223+
12041224
INVARIANT(declaring_class(symbol), "Method must have a declaring class.");
12051225

12061226
bool ret = convert_single_method_code(

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void create_java_initialize(symbol_table_baset &symbol_table)
5353
initialize.mode=ID_java;
5454

5555
initialize.type = java_method_typet({}, java_void_type());
56-
5756
symbol_table.add(initialize);
5857
}
5958

@@ -104,7 +103,7 @@ static constant_exprt constant_bool(bool val)
104103
return from_integer(val ? 1 : 0, java_boolean_type());
105104
}
106105

107-
static void java_static_lifetime_init(
106+
void java_static_lifetime_init(
108107
symbol_table_baset &symbol_table,
109108
const source_locationt &source_location,
110109
bool assume_init_pointers_not_null,
@@ -115,6 +114,7 @@ static void java_static_lifetime_init(
115114
{
116115
symbolt &initialize_symbol =
117116
symbol_table.get_writeable_ref(INITIALIZE_FUNCTION);
117+
PRECONDITION(initialize_symbol.value.is_nil());
118118
code_blockt code_block;
119119

120120
const symbol_exprt rounding_mode =
@@ -590,17 +590,6 @@ bool java_entry_point(
590590

591591
assert(symbol.type.id()==ID_code);
592592

593-
create_java_initialize(symbol_table);
594-
595-
java_static_lifetime_init(
596-
symbol_table,
597-
symbol.location,
598-
assume_init_pointers_not_null,
599-
object_factory_parameters,
600-
pointer_type_selector,
601-
string_refinement_enabled,
602-
message_handler);
603-
604593
return generate_java_start_function(
605594
symbol,
606595
symbol_table,

jbmc/src/java_bytecode/java_entry_point.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
190190
/// code for it yet.
191191
void create_java_initialize(symbol_table_baset &symbol_table);
192192

193+
/// Adds the body to __CPROVER_initialize
194+
void java_static_lifetime_init(
195+
symbol_table_baset &symbol_table,
196+
const source_locationt &source_location,
197+
bool assume_init_pointers_not_null,
198+
java_object_factory_parameterst object_factory_parameters,
199+
const select_pointer_typet &pointer_type_selector,
200+
bool string_refinement_enabled,
201+
message_handlert &message_handler);
202+
193203
#endif // CPROVER_JAVA_BYTECODE_JAVA_ENTRY_POINT_H

0 commit comments

Comments
 (0)