Skip to content

Exception edges for live range analysis master #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/java_bytecode/java_bytecode_convert_method_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class java_bytecode_convert_methodt:public messaget

public:
typedef std::map<unsigned, converted_instructiont> address_mapt;
typedef cfg_dominators_templatet<const address_mapt, unsigned, false>
typedef std::pair<const methodt&, const address_mapt&> method_with_amapt;
typedef cfg_dominators_templatet<method_with_amapt, unsigned, false>
java_cfg_dominatorst;

protected:
Expand Down
6 changes: 5 additions & 1 deletion src/java_bytecode/java_bytecode_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ class java_bytecode_parse_treet
return instructions.back();
}

class exceptiont
struct exceptiont
{
std::size_t start_pc;
std::size_t end_pc;
std::size_t handler_pc;
symbol_typet catch_type;
};

typedef std::vector<exceptiont> exception_tablet;
Expand Down
15 changes: 11 additions & 4 deletions src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,20 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
rbytecode(method.instructions);

u2 exception_table_length=read_u2();
method.exception_table.resize(exception_table_length);

for(std::size_t e=0; e<exception_table_length; e++)
{
u2 UNUSED start_pc=read_u2();
u2 UNUSED end_pc=read_u2();
u2 UNUSED handler_pc=read_u2();
u2 UNUSED catch_type=read_u2();
u2 start_pc=read_u2();
u2 end_pc=read_u2();
u2 handler_pc=read_u2();
u2 catch_type=read_u2();
method.exception_table[e].start_pc=start_pc;
method.exception_table[e].end_pc=end_pc;
method.exception_table[e].handler_pc=handler_pc;
if(catch_type!=0)
method.exception_table[e].catch_type=
to_symbol_type(pool_entry(catch_type).expr.type());
}

u2 attributes_count=read_u2();
Expand Down
48 changes: 38 additions & 10 deletions src/java_bytecode/java_local_variable_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ Author: Chris Smowton, [email protected]
template<class T>
struct procedure_local_cfg_baset<
T,
const java_bytecode_convert_methodt::address_mapt,
java_bytecode_convert_methodt::method_with_amapt,
unsigned> :
public graph<cfg_base_nodet<T, unsigned> >
{
typedef java_bytecode_convert_methodt::address_mapt address_mapt;
typedef java_bytecode_convert_methodt::method_with_amapt method_with_amapt;
typedef std::map<unsigned, unsigned> entry_mapt;
entry_mapt entry_map;

procedure_local_cfg_baset() {}

void operator()(const address_mapt& amap)
void operator()(const method_with_amapt& args)
{
const auto &method=args.first;
const auto& amap=args.second;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto &amap

for(const auto& inst : amap)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto &inst

{
// Map instruction PCs onto node indices:
Expand All @@ -44,19 +46,44 @@ struct procedure_local_cfg_baset<
for(auto succ : inst.second.successors)
this->add_edge(entry_map.at(inst.first), entry_map.at(succ));
}
// Add edges declared in the exception table, which don't figure
// in the address map successors/predecessors as yet.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment refer to, as it's at the end of a block?

for(const auto& table_entry : method.exception_table)
{
auto findit=amap.find(table_entry.start_pc);
assert(findit!=amap.end() &&
"Exception table entry doesn't point to an instruction?");
for(; findit->first<table_entry.end_pc; ++findit)
{
// For now just assume any non-branch
// instruction could potentially throw.
auto succit=findit;
++succit;
if(succit==amap.end())
continue;
const auto& thisinst=findit->second;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit picking: "&" goes with "thisinst"

if(thisinst.successors.size()==1 &&
*thisinst.successors.begin()==succit->first)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use thisinst.successors.front() instead of *...begin() ? (But maybe I'm considering the wrong container type.)

{
this->add_edge(
entry_map.at(findit->first),
entry_map.at(table_entry.handler_pc));
}
}
}
}

unsigned get_first_node(const address_mapt& amap) const
unsigned get_first_node(const method_with_amapt& args) const
{
return amap.begin()->first;
return args.second.begin()->first;
}
unsigned get_last_node(const address_mapt& amap) const
unsigned get_last_node(const method_with_amapt& args) const
{
return (--amap.end())->first;
return (--args.second.end())->first;
}
unsigned nodes_empty(const address_mapt& amap) const
unsigned nodes_empty(const method_with_amapt& args) const
{
return amap.empty();
return args.second.empty();
}
};

Expand Down Expand Up @@ -744,7 +771,8 @@ void java_bytecode_convert_methodt::setup_local_variables(
{
// Compute CFG dominator tree
java_cfg_dominatorst dominator_analysis;
dominator_analysis(amap);
method_with_amapt dominator_args(m,amap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after ","

dominator_analysis(dominator_args);

// Find out which local variable table entries should be merged:
// Wrap each entry so we have somewhere to record live ranges with holes:
Expand Down