8234735: InstanceKlass:find_method_index regression after JDK-8231610

Reviewed-by: iklam, coleenp
This commit is contained in:
Claes Redestad 2019-12-09 16:46:29 +01:00
parent 22e26b2a81
commit 3cccc62e56
2 changed files with 18 additions and 11 deletions

View file

@ -1595,17 +1595,10 @@ static int linear_search(const Array<Method*>* methods,
bool InstanceKlass::_disable_method_binary_search = false; bool InstanceKlass::_disable_method_binary_search = false;
int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* name) { NOINLINE int linear_search(const Array<Method*>* methods, const Symbol* name) {
int len = methods->length(); int len = methods->length();
int l = 0; int l = 0;
int h = len - 1; int h = len - 1;
if (_disable_method_binary_search) {
// At the final stage of dynamic dumping, the methods array may not be sorted
// by ascending addresses of their names, so we can't use binary search anymore.
// However, methods with the same name are still laid out consecutively inside the
// methods array, so let's look for the first one that matches.
assert(DynamicDumpSharedSpaces, "must be");
while (l <= h) { while (l <= h) {
Method* m = methods->at(l); Method* m = methods->at(l);
if (m->name() == name) { if (m->name() == name) {
@ -1616,6 +1609,20 @@ int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* nam
return -1; return -1;
} }
inline int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* name) {
if (_disable_method_binary_search) {
assert(DynamicDumpSharedSpaces, "must be");
// At the final stage of dynamic dumping, the methods array may not be sorted
// by ascending addresses of their names, so we can't use binary search anymore.
// However, methods with the same name are still laid out consecutively inside the
// methods array, so let's look for the first one that matches.
return linear_search(methods, name);
}
int len = methods->length();
int l = 0;
int h = len - 1;
// methods are sorted by ascending addresses of their names, so do binary search // methods are sorted by ascending addresses of their names, so do binary search
while (l <= h) { while (l <= h) {
int mid = (l + h) >> 1; int mid = (l + h) >> 1;

View file

@ -579,7 +579,7 @@ public:
bool find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const; bool find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const;
private: private:
static int quick_search(const Array<Method*>* methods, const Symbol* name); inline static int quick_search(const Array<Method*>* methods, const Symbol* name);
public: public:
static void disable_method_binary_search() { static void disable_method_binary_search() {