Skip to content

Commit 8e38c0e

Browse files
committed
Add lazy conversion documentation
Also fix some trivial linting errors. No functional changes.
1 parent 145c2d4 commit 8e38c0e

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,8 +1742,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
17421742
const auto &field_name=arg0.get_string(ID_component_name);
17431743
symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name);
17441744
if(needed_classes && arg0.type().id()==ID_symbol)
1745+
{
17451746
needed_classes->insert(
17461747
to_symbol_type(arg0.type()).get_identifier());
1748+
}
17471749
c=code_assignt(symbol_expr, op[0]);
17481750
}
17491751
else if(statement==patternt("?2?")) // i2c etc.

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ bool java_bytecode_languaget::typecheck(
502502
// that are reachable from this entry point.
503503
if(lazy_methods_mode==LAZY_METHODS_MODE_CONTEXT_INSENSITIVE)
504504
{
505+
// ci: context-insensitive.
505506
if(do_ci_lazy_method_conversion(symbol_table, lazy_methods))
506507
return true;
507508
}
@@ -514,6 +515,32 @@ bool java_bytecode_languaget::typecheck(
514515
return false;
515516
}
516517

518+
/*******************************************************************\
519+
520+
Function: java_bytecode_languaget::do_ci_lazy_method_conversion
521+
522+
Inputs: `symbol_table`: global symbol table
523+
`lazy_methods`: map from method names to relevant symbol
524+
and parsed-method objects.
525+
526+
Outputs: Elaborates lazily-converted methods that may be reachable
527+
starting from the main entry point (usually provided with
528+
the --function command-line option) (side-effect on the
529+
symbol_table). Returns false on success.
530+
531+
Purpose: Uses a simple context-insensitive ('ci') analysis to
532+
determine which methods may be reachable from the main
533+
entry point. In brief, static methods are reachable if we
534+
find a callsite in another reachable site, while virtual
535+
methods are reachable if we find a virtual callsite
536+
targeting a compatible type *and* a constructor callsite
537+
indicating an object of that type may be instantiated (or
538+
evidence that an object of that type exists before the
539+
main function is entered, such as being passed as a
540+
parameter).
541+
542+
\*******************************************************************/
543+
517544
bool java_bytecode_languaget::do_ci_lazy_method_conversion(
518545
symbol_tablet &symbol_table,
519546
lazy_methodst &lazy_methods)
@@ -558,7 +585,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
558585
needed_classes);
559586

560587
std::set<irep_idt> methods_already_populated;
561-
std::vector<const code_function_callt*> virtual_callsites;
588+
std::vector<const code_function_callt *> virtual_callsites;
562589

563590
bool any_new_methods;
564591
do
@@ -586,8 +613,10 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
586613
get_message_handler(),
587614
disable_runtime_checks,
588615
max_user_array_length,
589-
safe_pointer<std::vector<irep_idt> >::create_non_null(&method_worklist2),
590-
safe_pointer<std::set<irep_idt> >::create_non_null(&needed_classes));
616+
safe_pointer<std::vector<irep_idt> >::create_non_null(
617+
&method_worklist2),
618+
safe_pointer<std::set<irep_idt> >::create_non_null(
619+
&needed_classes));
591620
gather_virtual_callsites(
592621
symbol_table.lookup(mname).value,
593622
virtual_callsites);
@@ -607,11 +636,15 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
607636
for(const auto &callsite : virtual_callsites)
608637
{
609638
// This will also create a stub if a virtual callsite has no targets.
610-
get_virtual_method_targets(*callsite, needed_classes, method_worklist2,
611-
symbol_table, ch);
639+
get_virtual_method_targets(
640+
*callsite,
641+
needed_classes,
642+
method_worklist2,
643+
symbol_table,
644+
ch);
612645
}
613-
614-
} while(any_new_methods);
646+
}
647+
while(any_new_methods);
615648

616649
// Remove symbols for methods that were declared but never used:
617650
symbol_tablet keep_symbols;
@@ -640,12 +673,49 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
640673
return false;
641674
}
642675

643-
void java_bytecode_languaget::lazy_methods_provided(std::set<irep_idt> &methods) const
676+
/*******************************************************************\
677+
678+
Function: java_bytecode_languaget::lazy_methods_provided
679+
680+
Inputs: None
681+
682+
Outputs: Populates `methods` with the complete list of lazy methods
683+
that are available to convert (those which are valid
684+
parameters for `convert_lazy_method`)
685+
686+
Purpose: Provide feedback to `language_filest` so that when asked
687+
for a lazy method, it can delegate to this instance of
688+
java_bytecode_languaget.
689+
690+
\*******************************************************************/
691+
692+
void java_bytecode_languaget::lazy_methods_provided(
693+
std::set<irep_idt> &methods) const
644694
{
645695
for(const auto &kv : lazy_methods)
646696
methods.insert(kv.first);
647697
}
648698

699+
/*******************************************************************\
700+
701+
Function: java_bytecode_languaget::convert_lazy_method
702+
703+
Inputs: `id`: method ID to convert
704+
`symtab`: global symbol table
705+
706+
Outputs: Amends the symbol table entry for function `id`, which
707+
should be a lazy method provided by this instance of
708+
`java_bytecode_languaget`. It should initially have a nil
709+
value. After this method completes, it will have a value
710+
representing the method body, identical to that produced
711+
using eager method conversion.
712+
713+
Purpose: Promote a lazy-converted method (one whose type is known
714+
but whose body hasn't been converted) into a fully-
715+
elaborated one.
716+
717+
\*******************************************************************/
718+
649719
void java_bytecode_languaget::convert_lazy_method(
650720
const irep_idt &id,
651721
symbol_tablet &symtab)

src/java_bytecode/java_bytecode_language.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ enum lazy_methods_modet
2424
};
2525

2626
typedef std::pair<
27-
const symbolt*,
28-
const java_bytecode_parse_treet::methodt*>
27+
const symbolt *,
28+
const java_bytecode_parse_treet::methodt *>
2929
lazy_method_valuet;
3030
typedef std::map<irep_idt, lazy_method_valuet>
3131
lazy_methodst;

0 commit comments

Comments
 (0)