@@ -115,6 +115,23 @@ static prefix_filtert get_context(const optionst &options)
115
115
return prefix_filtert (std::move (context_include), std::move (context_exclude));
116
116
}
117
117
118
+ std::unordered_multimap<irep_idt, symbolt> &
119
+ lazy_class_to_declared_symbols_mapt::get (const symbol_tablet &symbol_table)
120
+ {
121
+ if (!initialized)
122
+ {
123
+ map = class_to_declared_symbols (symbol_table);
124
+ initialized = true ;
125
+ }
126
+ return map;
127
+ }
128
+
129
+ void lazy_class_to_declared_symbols_mapt::reinitialize ()
130
+ {
131
+ initialized = false ;
132
+ map.clear ();
133
+ }
134
+
118
135
// / Consume options that are java bytecode specific.
119
136
void java_bytecode_languaget::set_language_options (const optionst &options)
120
137
{
@@ -874,6 +891,8 @@ bool java_bytecode_languaget::typecheck(
874
891
threading_support,
875
892
static_values_json.has_value ());
876
893
894
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
895
+
877
896
// Now incrementally elaborate methods
878
897
// that are reachable from this entry point.
879
898
switch (lazy_methods_mode)
@@ -895,18 +914,21 @@ bool java_bytecode_languaget::typecheck(
895
914
for (const auto &function_id_and_type : synthetic_methods)
896
915
{
897
916
convert_single_method (
898
- function_id_and_type.first , journalling_symbol_table);
917
+ function_id_and_type.first ,
918
+ journalling_symbol_table,
919
+ class_to_declared_symbols);
899
920
}
900
921
// Convert all methods for which we have bytecode now
901
922
for (const auto &method_sig : method_bytecode)
902
923
{
903
- convert_single_method (method_sig.first , journalling_symbol_table);
924
+ convert_single_method (
925
+ method_sig.first , journalling_symbol_table, class_to_declared_symbols);
904
926
}
905
927
// Now convert all newly added string methods
906
928
for (const auto &fn_name : journalling_symbol_table.get_inserted ())
907
929
{
908
930
if (string_preprocess.implements_function (fn_name))
909
- convert_single_method (fn_name, symbol_table);
931
+ convert_single_method (fn_name, symbol_table, class_to_declared_symbols );
910
932
}
911
933
}
912
934
break ;
@@ -1001,12 +1023,17 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
1001
1023
symbol_table_buildert symbol_table_builder =
1002
1024
symbol_table_buildert::wrap (symbol_table);
1003
1025
1026
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
1027
+
1004
1028
const method_convertert method_converter =
1005
- [this , &symbol_table_builder](
1029
+ [this , &symbol_table_builder, &class_to_declared_symbols ](
1006
1030
const irep_idt &function_id,
1007
1031
ci_lazy_methods_neededt lazy_methods_needed) {
1008
1032
return convert_single_method (
1009
- function_id, symbol_table_builder, std::move (lazy_methods_needed));
1033
+ function_id,
1034
+ symbol_table_builder,
1035
+ std::move (lazy_methods_needed),
1036
+ class_to_declared_symbols);
1010
1037
};
1011
1038
1012
1039
ci_lazy_methodst method_gather (
@@ -1069,7 +1096,8 @@ void java_bytecode_languaget::convert_lazy_method(
1069
1096
journalling_symbol_tablet symbol_table=
1070
1097
journalling_symbol_tablet::wrap (symtab);
1071
1098
1072
- convert_single_method (function_id, symbol_table);
1099
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
1100
+ convert_single_method (function_id, symbol_table, class_to_declared_symbols);
1073
1101
1074
1102
// Instrument runtime exceptions (unless symbol is a stub)
1075
1103
if (symbol.value .is_not_nil ())
@@ -1137,10 +1165,13 @@ static void notify_static_method_calls(
1137
1165
// / \param symbol_table: global symbol table
1138
1166
// / \param needed_lazy_methods: optionally a collection of needed methods to
1139
1167
// / update with any methods touched during the conversion
1168
+ // / \param class_to_declared_symbols: maps classes to the symbols that
1169
+ // / they declare.
1140
1170
bool java_bytecode_languaget::convert_single_method (
1141
1171
const irep_idt &function_id,
1142
1172
symbol_table_baset &symbol_table,
1143
- optionalt<ci_lazy_methods_neededt> needed_lazy_methods)
1173
+ optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
1174
+ lazy_class_to_declared_symbols_mapt &class_to_declared_symbols)
1144
1175
{
1145
1176
// Do not convert if method is not in context
1146
1177
if (method_in_context && !(*method_in_context)(id2string (function_id)))
@@ -1218,16 +1249,14 @@ bool java_bytecode_languaget::convert_single_method(
1218
1249
class_name, " user_specified_clinit must be declared by a class." );
1219
1250
INVARIANT (
1220
1251
static_values_json.has_value (), " static-values JSON must be available" );
1221
- const auto class_to_declared_symbols_map =
1222
- class_to_declared_symbols (symbol_table);
1223
1252
writable_symbol.value = get_user_specified_clinit_body (
1224
1253
*class_name,
1225
1254
*static_values_json,
1226
1255
symbol_table,
1227
1256
needed_lazy_methods,
1228
1257
max_user_array_length,
1229
1258
references,
1230
- class_to_declared_symbols_map );
1259
+ class_to_declared_symbols. get (symbol_table) );
1231
1260
break ;
1232
1261
}
1233
1262
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
0 commit comments