Skip to content

Commit 5b3cde5

Browse files
committed
Use a common instance of class_hierarchyt in get_inherited_component
This avoids constructing a fresh class_hierarchyt with a consequent sweep of the complete symbol table every time inheritence is queried.
1 parent e73e756 commit 5b3cde5

7 files changed

+42
-14
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,8 @@ void java_bytecode_convert_method(
27642764
message_handlert &message_handler,
27652765
size_t max_array_length,
27662766
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
2767-
java_string_library_preprocesst &string_preprocess)
2767+
java_string_library_preprocesst &string_preprocess,
2768+
const class_hierarchyt &class_hierarchy)
27682769
{
27692770
static const std::unordered_set<std::string> methods_to_ignore
27702771
{
@@ -2795,19 +2796,28 @@ void java_bytecode_convert_method(
27952796
message_handler,
27962797
max_array_length,
27972798
needed_lazy_methods,
2798-
string_preprocess);
2799+
string_preprocess,
2800+
class_hierarchy);
27992801

28002802
java_bytecode_convert_method(class_symbol, method);
28012803
}
28022804

28032805
/// Returns true iff method \p methodid from class \p classname is
28042806
/// a method inherited from a class (and not an interface!) from which
28052807
/// \p classname inherits, either directly or indirectly.
2808+
/// \param classname: class whose method is referenced
2809+
/// \param methodid: method basename
28062810
bool java_bytecode_convert_methodt::is_method_inherited(
2807-
const irep_idt &classname, const irep_idt &methodid) const
2811+
const irep_idt &classname,
2812+
const irep_idt &methodid) const
28082813
{
28092814
resolve_inherited_componentt::inherited_componentt inherited_method =
2810-
get_inherited_component(classname, methodid, classname, symbol_table);
2815+
get_inherited_component(
2816+
classname,
2817+
methodid,
2818+
classname,
2819+
symbol_table,
2820+
class_hierarchy);
28112821
return inherited_method.is_valid();
28122822
}
28132823

src/java_bytecode/java_bytecode_convert_method.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void java_bytecode_convert_method(
3434
message_handlert &message_handler,
3535
size_t max_array_length,
3636
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
37-
java_string_library_preprocesst &string_preprocess);
37+
java_string_library_preprocesst &string_preprocess,
38+
const class_hierarchyt &class_hierarchy);
3839

3940
void java_bytecode_convert_method_lazy(
4041
const symbolt &class_symbol,

src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ class java_bytecode_convert_methodt:public messaget
3535
message_handlert &_message_handler,
3636
size_t _max_array_length,
3737
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
38-
java_string_library_preprocesst &_string_preprocess)
38+
java_string_library_preprocesst &_string_preprocess,
39+
const class_hierarchyt &class_hierarchy)
3940
: messaget(_message_handler),
4041
symbol_table(symbol_table),
4142
max_array_length(_max_array_length),
4243
needed_lazy_methods(std::move(needed_lazy_methods)),
4344
string_preprocess(_string_preprocess),
4445
slots_for_parameters(0),
45-
method_has_this(false)
46+
method_has_this(false),
47+
class_hierarchy(class_hierarchy)
4648
{
4749
}
4850

@@ -116,6 +118,7 @@ class java_bytecode_convert_methodt:public messaget
116118
bool method_has_this;
117119
std::map<irep_idt, bool> class_has_clinit_method;
118120
std::map<irep_idt, bool> any_superclass_has_clinit_method;
121+
class_hierarchyt class_hierarchy;
119122

120123
enum instruction_sizet
121124
{

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,11 @@ static void create_stub_global_symbol(
426426
/// static fields, and nondet-initialised for primitives.
427427
/// \param parse_tree: class bytecode
428428
/// \param symbol_table: symbol table; may gain new symbols
429+
/// \param class_hierarchy: global class hierarchy
429430
static void create_stub_global_symbols(
430431
const java_bytecode_parse_treet &parse_tree,
431-
symbol_table_baset &symbol_table)
432+
symbol_table_baset &symbol_table,
433+
const class_hierarchyt &class_hierarchy)
432434
{
433435
namespacet ns(symbol_table);
434436
for(const auto &method : parse_tree.parsed_class.methods)
@@ -454,7 +456,8 @@ static void create_stub_global_symbols(
454456
class_id,
455457
component,
456458
"java::" + id2string(parse_tree.parsed_class.name),
457-
symbol_table);
459+
symbol_table,
460+
class_hierarchy);
458461
if(!referred_component.is_valid())
459462
{
460463
irep_idt identifier =
@@ -523,6 +526,10 @@ bool java_bytecode_languaget::typecheck(
523526
return true;
524527
}
525528

529+
// Now that all classes have been created in the symbol table we can populate
530+
// the class hierarchy:
531+
class_hierarchy(symbol_table);
532+
526533
// find and mark all implicitly generic class types
527534
// this can only be done once all the class symbols have been created
528535
for(const auto &c : java_class_loader.class_map)
@@ -582,7 +589,8 @@ bool java_bytecode_languaget::typecheck(
582589
journalling_symbol_tablet::wrap(symbol_table);
583590
for(const auto &c : java_class_loader.class_map)
584591
{
585-
create_stub_global_symbols(c.second, symbol_table_journal);
592+
create_stub_global_symbols(
593+
c.second, symbol_table_journal, class_hierarchy);
586594
}
587595

588596
stub_global_initializer_factory.create_stub_global_initializer_symbols(
@@ -875,7 +883,8 @@ bool java_bytecode_languaget::convert_single_method(
875883
get_message_handler(),
876884
max_user_array_length,
877885
std::move(needed_lazy_methods),
878-
string_preprocess);
886+
string_preprocess,
887+
class_hierarchy);
879888
return false;
880889
}
881890

src/java_bytecode/java_bytecode_language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class java_bytecode_languaget:public languaget
174174
const std::unique_ptr<const select_pointer_typet> pointer_type_selector;
175175
synthetic_methods_mapt synthetic_methods;
176176
stub_global_initializer_factoryt stub_global_initializer_factory;
177+
class_hierarchyt class_hierarchy;
177178
};
178179

179180
std::unique_ptr<languaget> new_java_bytecode_language();

src/java_bytecode/java_utils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,18 @@ std::string pretty_print_java_type(const std::string &fqn_java_type)
336336
/// component. The user class is relevant when determining whether package-
337337
/// scoped components are visible from a particular use site.
338338
/// \param symbol_table: global symbol table.
339+
/// \param class_hierarchy: global class hierarchy.
339340
/// \return the concrete component referred to if any is found, or an invalid
340341
/// resolve_inherited_componentt::inherited_componentt otherwise.
341342
resolve_inherited_componentt::inherited_componentt get_inherited_component(
342343
const irep_idt &component_class_id,
343344
const irep_idt &component_name,
344345
const irep_idt &user_class_id,
345-
const symbol_tablet &symbol_table)
346+
const symbol_tablet &symbol_table,
347+
const class_hierarchyt &class_hierarchy)
346348
{
347-
resolve_inherited_componentt component_resolver(symbol_table);
349+
resolve_inherited_componentt component_resolver(
350+
symbol_table, class_hierarchy);
348351
const resolve_inherited_componentt::inherited_componentt resolved_component =
349352
component_resolver(component_class_id, component_name);
350353

src/java_bytecode/java_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ resolve_inherited_componentt::inherited_componentt get_inherited_component(
102102
const irep_idt &component_class_id,
103103
const irep_idt &component_name,
104104
const irep_idt &user_class_id,
105-
const symbol_tablet &symbol_table);
105+
const symbol_tablet &symbol_table,
106+
const class_hierarchyt &class_hierarchy);
106107

107108
#endif // CPROVER_JAVA_BYTECODE_JAVA_UTILS_H

0 commit comments

Comments
 (0)