Skip to content

Java Bytecode parsing tidy #1796

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
merged 3 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Author: Daniel Kroening, [email protected]
#include <unordered_set>
#include <regex>

/// Given a string of the format '?blah?', will return true when compared
/// against a string that matches appart from any characters that are '?'
/// in the original string. Equivalent to doing a regex match on '.blah.'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it doesn't take to long I intend to remove this completely and replace its uses with std::regex unless anyone objects to that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Knock up a quick standalone benchmark before you do, as this is obviously a much simpler machine

class patternt
{
public:
Expand Down
7 changes: 7 additions & 0 deletions src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class java_bytecode_parsert:public parsert
if(index==0 || index>=constant_pool.size())
{
error() << "invalid constant pool index (" << index << ")" << eom;
error() << "constant pool size: " << constant_pool.size() << eom;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes still sense to output the accessed index, too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still done on the line above.

throw 0;
}

Expand Down Expand Up @@ -946,6 +947,12 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
{
u2 start_pc=read_u2();
u2 end_pc=read_u2();

INVARIANT(
Copy link
Contributor

Choose a reason for hiding this comment

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

would you mind adding that this invariant is from the class file format spec ("4.7.3. The Code Attribute" for Java8)

start_pc < end_pc,
"The start_pc must be less than the end_pc as this is the range the "
"exception is active");

u2 handler_pc=read_u2();
u2 catch_type=read_u2();
method.exception_table[e].start_pc=start_pc;
Expand Down