-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8338471: Refactor Method::get_new_method() for better NoSuchMethodError handling #20874
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
|
|
||
| #include "code/compressedStream.hpp" | ||
| #include "compiler/compilerDefinitions.hpp" | ||
| #include "memory/universe.hpp" | ||
| #include "oops/annotations.hpp" | ||
| #include "oops/constantPool.hpp" | ||
| #include "oops/methodFlags.hpp" | ||
|
|
@@ -847,12 +848,11 @@ class Method : public Metadata { | |
| void release_C_heap_structures(); | ||
|
|
||
| Method* get_new_method() const { | ||
| InstanceKlass* holder = method_holder(); | ||
| Method* new_method = holder->method_with_idnum(orig_method_idnum()); | ||
|
|
||
| assert(new_method != nullptr, "method_with_idnum() should not be null"); | ||
| assert(is_old(), "must be"); | ||
| Method* new_method = method_holder()->method_with_idnum(orig_method_idnum()); | ||
| assert(this != new_method, "sanity check"); | ||
| return new_method; | ||
| assert(new_method != nullptr || is_deleted(), "must be"); | ||
| return (new_method == nullptr || is_deleted()) ? Universe::throw_no_such_method_error() : new_method; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still confused by the different possibilities here. Under what conditions will we get nullptr? Is it the case that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To answer some of my own questions:
I remain unclear how nullptr can appear here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This redefine code is really complicated. Obsolete methods, which includes deleted methods get an incremented idnum in check_methods_and_mark_as_obsolete. When get_new_method() is called it compares InstanceKlass::_methods[idnum], then compares the Method at that index to the idnum that the method has stored. For deleted methods, this will return nullptr because the idnum comparison in method_with_idnum will not match, or idnum for the deleted method is greater than InstanceKlass::_methods.length(). I think it is sufficient to check for nullptr in get_new_method() for deleted methods but also the explicit is_deleted() comparison is much easier to understand that it's the right answer. Yes, there could be an assert in get_new_method(), the method passed in is_old(). All redefined methods are marked as is_old(). I believe all callers test this before making this call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coleen is correct, all the callers do indeed check that the method As the comment suggests, the caller should handle nullptr, which in this case is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is it the case that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that implies that you trust my reading of this code. It is complicated enough that testing both seems like a safe thing to do and somewhat clarifying, or else adding an assert like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assert works for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert the stronger statement: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I like that better too. |
||
| } | ||
|
|
||
| // Printing | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.