Skip to content
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

Allow duplicate method names in JVM verification #884

Merged
merged 6 commits into from
Nov 2, 2020
Merged

Conversation

brianhuffman
Copy link
Contributor

This patch adds new functionality to crucible_jvm_verify where if the class you're working with contains multiple methods with the same name, you can select the one you want by appending a type descriptor string to the method name. For example "foo(II)Z" chooses a method named foo with two integer arguments and a boolean result. Type descriptors are optional if the base name is unambiguous. In case a method name is ambiguous, the error message prints all the valid type descriptors that could be used to disambiguate.

Fixes #212.

Brian Huffman added 5 commits October 31, 2020 14:27
Fixes #212.

Previously `crucible_jvm_verify` and related commands would fail
to verify methods whose names were not unique. However, JVM allows
multiple methods to coexist in the same class as long as their
types are distinct. This change now allows users to optionally
add a type descriptor to a method name to specify a particular
method with a given name. For example "foo(L)V" indicates method
"foo" with a long argument and void result type.
@weaversa
Copy link
Contributor

If you print the loaded module, does it display the names with these selectors?

@brianhuffman
Copy link
Contributor Author

I didn't touch the printing code for JavaClass values in saw-script, nor did I test it. I'll have to go check to see what it does.

@weaversa
Copy link
Contributor

I didn't touch the printing code for JavaClass values in saw-script, nor did I test it. I'll have to go check to see what it does.

Thanks! I think this feature would be quite helpful.

@brianhuffman
Copy link
Contributor Author

EDIT: Here's the output of printing the module Test.class from the test in this PR:

Class name: Test (super)
Superclass: java/lang/Object

Fields:
  default long val

Methods:
  void <init> ()
  void <init> (int)
  void <init> (long)
  long get ()
  void increment ()
  void increment (Test)
  void increment (int)
  void increment (long)

As you can see, it does list all the similarly-named methods separately, but it shows the types in pretty-printed form instead of the descriptor encoding.

@brianhuffman
Copy link
Contributor Author

I think some extra information would be nice to add to printed JavaClass values, but I think I'll open a separate ticket for that instead of adding pretty-printing changes to this PR.

These are referred to by the name "<init>", which is what they
are called in the JVM class file. Like other methods, they can
be used with type descriptors to disambiguate when constructors
are defined at multiple types.
Copy link
Contributor

@robdockins robdockins left a comment

Choose a reason for hiding this comment

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

This looks like a good improvement to me. It would definitely be good to have some method to discover the appropriate descriptor names other than from the ambiguity error message.

@brianhuffman brianhuffman merged commit 966a26f into master Nov 2, 2020
brianhuffman pushed a commit that referenced this pull request Nov 10, 2020
#884 redid jvm method verification so that it
would only perform method resolution (where it searches superclasses
to find the given method name) a single time. However, subsequent
method lookups were using the original class name instead of the
name of the superclass where the method was found. This caused method
handle lookups to fail in examples (like ecdsa) where methods were
defined in superclasses. This commit fixes that bug.
brianhuffman pushed a commit that referenced this pull request Nov 16, 2020
#884 redid jvm method verification so that it
would only perform method resolution (where it searches superclasses
to find the given method name) a single time. However, subsequent
method lookups were using the original class name instead of the
name of the superclass where the method was found. This caused method
handle lookups to fail in examples (like ecdsa) where methods were
defined in superclasses. This commit fixes that bug.
@brianhuffman brianhuffman deleted the issue212 branch November 18, 2020 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow duplicate method names in Java
3 participants