Skip to content

Commit

Permalink
8264732: Clean up LinkResolver::vtable_index_of_interface_method()
Browse files Browse the repository at this point in the history
Reviewed-by: lfoltan, coleenp, dholmes
  • Loading branch information
Vladimir Ivanov committed Apr 9, 2021
1 parent b3782ea commit 33fa855
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
29 changes: 3 additions & 26 deletions src/hotspot/share/interpreter/linkResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS) {
kind = CallInfo::vtable_call;
} else if (!resolved_klass->is_interface()) {
// A default or miranda method. Compute the vtable index.
index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
_resolved_method);
index = LinkResolver::vtable_index_of_interface_method(resolved_klass, _resolved_method);
assert(index >= 0 , "we should have valid vtable index at this point");

kind = CallInfo::vtable_call;
Expand Down Expand Up @@ -405,31 +404,9 @@ Method* LinkResolver::lookup_instance_method_in_klasses(Klass* klass,
return result;
}

int LinkResolver::vtable_index_of_interface_method(Klass* klass,
const methodHandle& resolved_method) {

int vtable_index = Method::invalid_vtable_index;
Symbol* name = resolved_method->name();
Symbol* signature = resolved_method->signature();
int LinkResolver::vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method) {
InstanceKlass* ik = InstanceKlass::cast(klass);

// First check in default method array
if (!resolved_method->is_abstract() && ik->default_methods() != NULL) {
int index = InstanceKlass::find_method_index(ik->default_methods(),
name, signature,
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::find,
Klass::PrivateLookupMode::find);
if (index >= 0 ) {
vtable_index = ik->default_vtable_indices()->at(index);
}
}
if (vtable_index == Method::invalid_vtable_index) {
// get vtable_index for miranda methods
klassVtable vt = ik->vtable();
vtable_index = vt.index_of_miranda(name, signature);
}
return vtable_index;
return ik->vtable_index_of_interface_method(resolved_method());
}

Method* LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info) {
Expand Down
28 changes: 28 additions & 0 deletions src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,34 @@ Method* InstanceKlass::method_at_itable_or_null(InstanceKlass* holder, int index
return NULL; // offset entry not found
}

int InstanceKlass::vtable_index_of_interface_method(Method* intf_method) {
assert(is_linked(), "required");
assert(intf_method->method_holder()->is_interface(), "not an interface method");
assert(is_subtype_of(intf_method->method_holder()), "interface not implemented");

int vtable_index = Method::invalid_vtable_index;
Symbol* name = intf_method->name();
Symbol* signature = intf_method->signature();

// First check in default method array
if (!intf_method->is_abstract() && default_methods() != NULL) {
int index = find_method_index(default_methods(),
name, signature,
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::find,
Klass::PrivateLookupMode::find);
if (index >= 0) {
vtable_index = default_vtable_indices()->at(index);
}
}
if (vtable_index == Method::invalid_vtable_index) {
// get vtable_index for miranda methods
klassVtable vt = vtable();
vtable_index = vt.index_of_miranda(name, signature);
}
return vtable_index;
}

#if INCLUDE_JVMTI
// update default_methods for redefineclasses for methods that are
// not yet in the vtable due to concurrent subclass define and superinterface
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/oops/instanceKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ class InstanceKlass: public Klass {
klassItable itable() const; // return klassItable wrapper
Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
int vtable_index_of_interface_method(Method* method);

#if INCLUDE_JVMTI
void adjust_default_methods(bool* trace_name_printed);
Expand Down

1 comment on commit 33fa855

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.