Skip to content

Commit f6f2054

Browse files
Extract filter_symbol_table method
1 parent 0f8b714 commit f6f2054

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,27 @@ bool ci_lazy_methodst::operator()(
186186
}
187187

188188
// Remove symbols for methods that were declared but never used:
189-
symbol_tablet keep_symbols;
189+
symbol_tablet keep_symbols = filter_symbol_table(
190+
symbol_table, method_bytecode, methods_already_populated);
191+
190192
// Manually keep @inflight_exception, as it is unused at this stage
191193
// but will become used when the `remove_exceptions` pass is run:
192194
keep_symbols.add(symbol_table.lookup_ref(INFLIGHT_EXCEPTION_VARIABLE_NAME));
193195

196+
debug() << "CI lazy methods: removed "
197+
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
198+
<< " unreachable methods and globals" << eom;
199+
200+
symbol_table.swap(keep_symbols);
201+
return false;
202+
}
203+
204+
symbol_tablet ci_lazy_methodst::filter_symbol_table(
205+
const symbol_tablet &symbol_table,
206+
const method_bytecodet &method_bytecode,
207+
const std::unordered_set<irep_idt> &methods_already_populated)
208+
{
209+
symbol_tablet keep_symbols;
194210
for(const auto &sym : symbol_table.symbols)
195211
{
196212
// Don't keep global variables (unless they're gathered below from a
@@ -213,14 +229,7 @@ bool ci_lazy_methodst::operator()(
213229
}
214230
keep_symbols.add(sym.second);
215231
}
216-
217-
debug() << "CI lazy methods: removed "
218-
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
219-
<< " unreachable methods and globals" << eom;
220-
221-
symbol_table.swap(keep_symbols);
222-
223-
return false;
232+
return keep_symbols;
224233
}
225234

226235
/// Look for virtual callsites with no candidate targets. If we have

jbmc/src/java_bytecode/ci_lazy_methods.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class ci_lazy_methodst:public messaget
194194
std::unordered_set<irep_idt> &instantiated_classes,
195195
const std::unordered_set<exprt, irep_hash> &virtual_function_calls,
196196
symbol_tablet &symbol_table);
197+
198+
symbol_tablet filter_symbol_table(
199+
const symbol_tablet &symbol_table,
200+
const method_bytecodet &method_bytecode,
201+
const std::unordered_set<irep_idt> &methods_already_populated);
197202
};
198203

199204
#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

0 commit comments

Comments
 (0)