Skip to content

sort bytecode_info table by bytecode #4670

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
May 30, 2019
Merged

sort bytecode_info table by bytecode #4670

merged 3 commits into from
May 30, 2019

Conversation

kroening
Copy link
Member

The bytecode_info table is now sorted by bytecode, instead of
alphabetically. This is enables direct lookup of bytecodes, and can replace
the table that is currently built at runtime. We do not have any use for
the alphabetic ordering.

Obtained from previous file with

sort -t, -k2 bytecode_info.cpp -b

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 5d8125e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/112355616

@kroening kroening force-pushed the sort_bytecode_info branch 2 times, most recently from 04c83d3 to ccab473 Compare May 20, 2019 08:23
i_it->statement!="jsr" &&
i_it->statement!="jsr_w" &&
i_it->statement!="ret")
const std::string statement = bytecode_info[i_it->bytecode].mnemonic;
Copy link
Contributor

Choose a reason for hiding this comment

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

Const ref?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is turning a const char * into a string, for comparison.
Won't fix now, since this will be replaced by bytecode comparisons.

const std::string statement = bytecode_info[i_it->bytecode].mnemonic;

if(
statement != "goto" && statement != "return" &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested followup -- create symbolic constants for these JAVA_BYTECODE_NOP and so on, and compare those instead of the mnemonics

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's the plan.

instruction.statement == "ldc2" ||
instruction.statement == "ldc_w" ||
instruction.statement == "ldc2_w")
const std::string statement =
Copy link
Contributor

Choose a reason for hiding this comment

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

const ref?

Copy link
Member Author

Choose a reason for hiding this comment

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

same here.

@@ -311,8 +311,9 @@ static void infer_opaque_type_fields(
for(const java_bytecode_parse_treet::instructiont &instruction :
method.instructions)
{
if(instruction.statement == "getfield" ||
instruction.statement == "putfield")
const std::string statement =
Copy link
Contributor

Choose a reason for hiding this comment

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

const ref?

@@ -584,8 +586,9 @@ static void create_stub_global_symbols(
for(const java_bytecode_parse_treet::instructiont &instruction :
method.instructions)
{
if(instruction.statement == "getstatic" ||
instruction.statement == "putstatic")
const std::string statement =
Copy link
Contributor

Choose a reason for hiding this comment

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

const ref?

@@ -15,86 +15,139 @@ Author: Daniel Kroening, [email protected]
// clang-format off
struct bytecode_infot const bytecode_info[]=
{
{ "aaload", 0x32, ' ', 2, 1, ' ' }, // arrayref, index → value; load onto the stack a reference from an array NOLINT(*)
{ "aastore", 0x53, ' ', 3, 0, ' ' }, // arrayref, index, value →; store into a reference in an array NOLINT(*)
{ "nop", 0x00, ' ', 0, 0, ' ' }, // [No change]; perform no operation NOLINT(*)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given anyone using this table already has a bytecode, the second field is useless now

Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping for audit!

{ "impdep1", 0xfe, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file NOLINT(*)
{ "impdep2", 0xff, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file NOLINT(*)
{ "wide", 0xc4, ' ', 0, 0, ' ' }, // modifier for others NOLINT(*)
{ nullptr, 0x00, '\0',0, 0, '\0'}, // zero-initialized NOLINT (*)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a magic terminator, but nothing about it is unique (0x00 is also nop, and a nullptr mnemonic is shared by the missing entries)-- suggest removing it

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: ccab473).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/112420225
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@kroening kroening force-pushed the sort_bytecode_info branch from ccab473 to 3b70661 Compare May 20, 2019 11:41
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 3b70661).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/112439621
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@kroening kroening force-pushed the sort_bytecode_info branch from 3b70661 to 46daf81 Compare May 20, 2019 16:09
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 46daf81).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/112482347
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@kroening kroening force-pushed the sort_bytecode_info branch from 46daf81 to c60a918 Compare May 26, 2019 22:05
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: c60a918).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/113236477

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Formatting grumbles only, otherwise lgtm

i_it->statement=="invokeinterface" ||
(threading_support && (i_it->statement=="monitorenter" ||
i_it->statement=="monitorexit")))
if(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest killing clang-format here to keep the nicer one-cndition-per-line format

Copy link
Member Author

Choose a reason for hiding this comment

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

done

i_it->statement=="ifnull" ||
i_it->statement=="jsr" ||
i_it->statement=="jsr_w")
if(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

const std::string statement =
bytecode_info[instruction.bytecode].mnemonic;
if(
statement == "ldc" || statement == "ldc2" || statement == "ldc_w" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

🚫 This will need a manual bump - I'll take care of this but please wait before merging
💡 I would add a unit test that verifies the table has the correct structure (e.g. that the position matches the bytecode, that there are no gaps etc)

@thk123
Copy link
Contributor

thk123 commented May 28, 2019

I will do the bump once rebased - please let me know when

@kroening kroening force-pushed the sort_bytecode_info branch from c60a918 to 7822fac Compare May 28, 2019 12:00
@kroening
Copy link
Member Author

@thk123 done!

@thk123
Copy link
Contributor

thk123 commented May 28, 2019

Sorry could I have one more rebase as I think #4705 is required for TG compatibility and this is just before it.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 7822fac).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/113427828

@thk123
Copy link
Contributor

thk123 commented May 29, 2019

@kroening sorry didn't tag you - can I have one more rebase as #4705 has been merged into TG submodule
#4670 (comment)

@kroening kroening force-pushed the sort_bytecode_info branch 2 times, most recently from 5023dd0 to 7cca038 Compare May 29, 2019 13:49
@tautschnig
Copy link
Collaborator

@kroening Please rebase now that #4729 is in to make CI happy.

Daniel Kroening added 3 commits May 30, 2019 10:01
The bytecode_info table is now sorted by bytecode, instead of
alphabetically.  This is enables direct lookup of bytecodes, and can replace
the table that is currently built at runtime.  We do not have any use for
the alphabetic ordering.

Obtained from previous file with

sort -t, -k2 bytecode_info.cpp -b
The run-time generated bytecode table is replaced by bytecode_info.  The
linear search for the mnemonic is replaced by an array access.
@kroening kroening force-pushed the sort_bytecode_info branch from 7cca038 to b149012 Compare May 30, 2019 09:01
@kroening kroening merged commit f117f25 into develop May 30, 2019
@kroening kroening deleted the sort_bytecode_info branch May 30, 2019 11:57
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: b149012).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/113731628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants