@@ -112,6 +112,23 @@ static prefix_filtert get_context(const optionst &options)
112
112
return prefix_filtert (std::move (context_include), std::move (context_exclude));
113
113
}
114
114
115
+ std::unordered_multimap<irep_idt, symbolt> &
116
+ lazy_class_to_declared_symbols_mapt::get (const symbol_tablet &symbol_table)
117
+ {
118
+ if (!initialized)
119
+ {
120
+ map = class_to_declared_symbols (symbol_table);
121
+ initialized = true ;
122
+ }
123
+ return map;
124
+ }
125
+
126
+ void lazy_class_to_declared_symbols_mapt::reinitialize ()
127
+ {
128
+ initialized = false ;
129
+ map.clear ();
130
+ }
131
+
115
132
// / Consume options that are java bytecode specific.
116
133
void java_bytecode_languaget::set_language_options (const optionst &options)
117
134
{
@@ -868,6 +885,8 @@ bool java_bytecode_languaget::typecheck(
868
885
threading_support,
869
886
static_values_json.has_value ());
870
887
888
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
889
+
871
890
// Now incrementally elaborate methods
872
891
// that are reachable from this entry point.
873
892
switch (lazy_methods_mode)
@@ -889,18 +908,23 @@ bool java_bytecode_languaget::typecheck(
889
908
for (const auto &function_id_and_type : synthetic_methods)
890
909
{
891
910
convert_single_method (
892
- function_id_and_type.first , journalling_symbol_table);
911
+ function_id_and_type.first ,
912
+ journalling_symbol_table,
913
+ class_to_declared_symbols);
893
914
}
894
915
// Convert all methods for which we have bytecode now
895
916
for (const auto &method_sig : method_bytecode)
896
917
{
897
- convert_single_method (method_sig.first , journalling_symbol_table);
918
+ convert_single_method (
919
+ method_sig.first ,
920
+ journalling_symbol_table,
921
+ class_to_declared_symbols);
898
922
}
899
923
// Now convert all newly added string methods
900
924
for (const auto &fn_name : journalling_symbol_table.get_inserted ())
901
925
{
902
926
if (string_preprocess.implements_function (fn_name))
903
- convert_single_method (fn_name, symbol_table);
927
+ convert_single_method (fn_name, symbol_table, class_to_declared_symbols );
904
928
}
905
929
}
906
930
break ;
@@ -995,12 +1019,17 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
995
1019
symbol_table_buildert symbol_table_builder =
996
1020
symbol_table_buildert::wrap (symbol_table);
997
1021
1022
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
1023
+
998
1024
const method_convertert method_converter =
999
- [this , &symbol_table_builder](
1025
+ [this , &symbol_table_builder, &class_to_declared_symbols ](
1000
1026
const irep_idt &function_id,
1001
1027
ci_lazy_methods_neededt lazy_methods_needed) {
1002
1028
return convert_single_method (
1003
- function_id, symbol_table_builder, std::move (lazy_methods_needed));
1029
+ function_id,
1030
+ symbol_table_builder,
1031
+ std::move (lazy_methods_needed),
1032
+ class_to_declared_symbols);
1004
1033
};
1005
1034
1006
1035
ci_lazy_methodst method_gather (
@@ -1063,7 +1092,8 @@ void java_bytecode_languaget::convert_lazy_method(
1063
1092
journalling_symbol_tablet symbol_table=
1064
1093
journalling_symbol_tablet::wrap (symtab);
1065
1094
1066
- convert_single_method (function_id, symbol_table);
1095
+ lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
1096
+ convert_single_method (function_id, symbol_table, class_to_declared_symbols);
1067
1097
1068
1098
// Instrument runtime exceptions (unless symbol is a stub)
1069
1099
if (symbol.value .is_not_nil ())
@@ -1131,10 +1161,13 @@ static void notify_static_method_calls(
1131
1161
// / \param symbol_table: global symbol table
1132
1162
// / \param needed_lazy_methods: optionally a collection of needed methods to
1133
1163
// / update with any methods touched during the conversion
1164
+ // / \param class_to_declared_symbols: maps classes to the symbols that
1165
+ // / they declare.
1134
1166
bool java_bytecode_languaget::convert_single_method (
1135
1167
const irep_idt &function_id,
1136
1168
symbol_table_baset &symbol_table,
1137
- optionalt<ci_lazy_methods_neededt> needed_lazy_methods)
1169
+ optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
1170
+ lazy_class_to_declared_symbols_mapt &class_to_declared_symbols)
1138
1171
{
1139
1172
// Do not convert if method is not in context
1140
1173
if (method_in_context && !(*method_in_context)(id2string (function_id)))
@@ -1212,16 +1245,14 @@ bool java_bytecode_languaget::convert_single_method(
1212
1245
class_name, " user_specified_clinit must be declared by a class." );
1213
1246
INVARIANT (
1214
1247
static_values_json.has_value (), " static-values JSON must be available" );
1215
- const auto class_to_declared_symbols_map =
1216
- class_to_declared_symbols (symbol_table);
1217
1248
writable_symbol.value = get_user_specified_clinit_body (
1218
1249
*class_name,
1219
1250
*static_values_json,
1220
1251
symbol_table,
1221
1252
needed_lazy_methods,
1222
1253
max_user_array_length,
1223
1254
references,
1224
- class_to_declared_symbols_map );
1255
+ class_to_declared_symbols. get (symbol_table) );
1225
1256
break ;
1226
1257
}
1227
1258
case synthetic_method_typet::STUB_CLASS_STATIC_INITIALIZER:
0 commit comments