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

8264732: Clean up LinkResolver::vtable_index_of_interface_method() #3346

Closed
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -149,7 +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;
@@ -404,30 +404,9 @@ Method* LinkResolver::lookup_instance_method_in_klasses(Klass* klass,
return result;
}

int LinkResolver::vtable_index_of_interface_method(Klass* klass, Method* 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) {
@@ -1389,7 +1368,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,

// do lookup based on receiver klass using the vtable index
if (resolved_method->method_holder()->is_interface()) { // default or miranda method
vtable_index = vtable_index_of_interface_method(resolved_klass, resolved_method());
vtable_index = vtable_index_of_interface_method(resolved_klass, resolved_method);
assert(vtable_index >= 0 , "we should have valid vtable index at this point");

selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index));
@@ -317,7 +317,7 @@ class LinkResolver: AllStatic {
static Method* resolve_static_call_or_null(const LinkInfo& link_info);
static Method* resolve_special_call_or_null(const LinkInfo& link_info);

static int vtable_index_of_interface_method(Klass* klass, Method* resolved_method);
static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);

// same as above for compile-time resolution; returns vtable_index if current_klass if linked
static int resolve_virtual_vtable_index (Klass* receiver_klass,
@@ -741,7 +741,7 @@ C2V_VMENTRY_0(jint, getVtableIndexForInterfaceMethod, (JNIEnv* env, jobject, job
if (!InstanceKlass::cast(klass)->is_linked()) {
JVMCI_THROW_MSG_0(InternalError, err_msg("Class %s must be linked", klass->external_name()));
}
return LinkResolver::vtable_index_of_interface_method(klass, method());
return LinkResolver::vtable_index_of_interface_method(klass, method);
C2V_END

C2V_VMENTRY_NULL(jobject, resolveMethod, (JNIEnv* env, jobject, jobject receiver_jvmci_type, jobject jvmci_method, jobject caller_jvmci_type))
@@ -3185,6 +3185,33 @@ Method* InstanceKlass::method_at_itable(Klass* holder, int index, TRAPS) {
return m;
}

int InstanceKlass::vtable_index_of_interface_method(Method* intf_method) {
assert(this->is_linked(), "required");
assert(intf_method->method_holder()->is_interface(), "not an interface method");
assert(this->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() && this->default_methods() != NULL) {
int index = InstanceKlass::find_method_index(this->default_methods(),

This comment has been minimized.

@coleenp

coleenp Apr 7, 2021

Yes, please, this looks a lot better! Then linkResolver can deal with methodHandle consistently so it doesn't go away with redefinition, and this function is nice here with the other like functions.
It doesn't need InstanceKlass:: before find_method_index, or the this->'s.

This comment has been minimized.

@iwanowww

iwanowww Apr 8, 2021
Author

It doesn't need InstanceKlass:: before find_method_index, or the this->'s.

Fixed. It looked clearer to me to explicitly refer to this.

name, signature,
Klass::OverpassLookupMode::find,
Klass::StaticLookupMode::find,
Klass::PrivateLookupMode::find);
if (index >= 0 ) {
vtable_index = this->default_vtable_indices()->at(index);
}
}
if (vtable_index == Method::invalid_vtable_index) {
// get vtable_index for miranda methods
klassVtable vt = this->vtable();
vtable_index = vt.index_of_miranda(name, signature);
}
return vtable_index;
}

#if INCLUDE_JVMTI
// update default_methods for redefineclasses for methods that are
@@ -1109,6 +1109,7 @@ class InstanceKlass: public Klass {
// Java itable
klassItable itable() const; // return klassItable wrapper
Method* method_at_itable(Klass* holder, int index, TRAPS);
int vtable_index_of_interface_method(Method* method);

#if INCLUDE_JVMTI
void adjust_default_methods(bool* trace_name_printed);
ProTip! Use n and p to navigate between commits in a pull request.