362 Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
363 if (default_methods != NULL) {
364 result = InstanceKlass::find_method(default_methods, name, signature);
365 assert(result == NULL || !result->is_static(), "static defaults not allowed");
366 }
367 }
368 return methodHandle(THREAD, result);
369 }
370
371 int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
372 const methodHandle& resolved_method) {
373
374 int vtable_index = Method::invalid_vtable_index;
375 Symbol* name = resolved_method->name();
376 Symbol* signature = resolved_method->signature();
377
378 // First check in default method array
379 if (!resolved_method->is_abstract() &&
380 (InstanceKlass::cast(klass())->default_methods() != NULL)) {
381 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(),
382 name, signature, Klass::find_overpass, Klass::find_static);
383 if (index >= 0 ) {
384 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
385 }
386 }
387 if (vtable_index == Method::invalid_vtable_index) {
388 // get vtable_index for miranda methods
389 ResourceMark rm;
390 klassVtable *vt = InstanceKlass::cast(klass())->vtable();
391 vtable_index = vt->index_of_miranda(name, signature);
392 }
393 return vtable_index;
394 }
395
396 methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) {
397 InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()());
398
399 // Specify 'true' in order to skip default methods when searching the
400 // interfaces. Function lookup_method_in_klasses() already looked for
401 // the method in the default methods table.
402 return methodHandle(THREAD,
1172 bool check_null_and_abstract,
1173 TRAPS) {
1174
1175 // setup default return values
1176 int vtable_index = Method::invalid_vtable_index;
1177 methodHandle selected_method;
1178
1179 assert(recv.is_null() || recv->is_oop(), "receiver is not an oop");
1180
1181 // runtime method resolution
1182 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
1183 THROW(vmSymbols::java_lang_NullPointerException());
1184 }
1185
1186 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
1187 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
1188 // a missing receiver might result in a bogus lookup.
1189 assert(resolved_method->method_holder()->is_linked(), "must be linked");
1190
1191 // do lookup based on receiver klass using the vtable index
1192 if (resolved_method->method_holder()->is_interface()) { // miranda method
1193 vtable_index = vtable_index_of_interface_method(resolved_klass,
1194 resolved_method);
1195 assert(vtable_index >= 0 , "we should have valid vtable index at this point");
1196
1197 InstanceKlass* inst = InstanceKlass::cast(recv_klass());
1198 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
1199 } else {
1200 // at this point we are sure that resolved_method is virtual and not
1201 // a miranda method; therefore, it must have a valid vtable index.
1202 assert(!resolved_method->has_itable_index(), "");
1203 vtable_index = resolved_method->vtable_index();
1204 // We could get a negative vtable_index for final methods,
1205 // because as an optimization they are they are never put in the vtable,
1206 // unless they override an existing method.
1207 // If we do get a negative, it means the resolved method is the the selected
1208 // method, and it can never be changed by an override.
1209 if (vtable_index == Method::nonvirtual_vtable_index) {
1210 assert(resolved_method->can_be_statically_bound(), "cannot override this method");
1211 selected_method = resolved_method;
1212 } else {
1213 // recv_klass might be an arrayKlassOop but all vtables start at
1214 // the same place. The cast is to avoid virtual call and assertion.
1215 InstanceKlass* inst = (InstanceKlass*)recv_klass();
1216 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
1217 }
1218 }
1219
1220 // check if method exists
1221 if (selected_method.is_null()) {
|
362 Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
363 if (default_methods != NULL) {
364 result = InstanceKlass::find_method(default_methods, name, signature);
365 assert(result == NULL || !result->is_static(), "static defaults not allowed");
366 }
367 }
368 return methodHandle(THREAD, result);
369 }
370
371 int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
372 const methodHandle& resolved_method) {
373
374 int vtable_index = Method::invalid_vtable_index;
375 Symbol* name = resolved_method->name();
376 Symbol* signature = resolved_method->signature();
377
378 // First check in default method array
379 if (!resolved_method->is_abstract() &&
380 (InstanceKlass::cast(klass())->default_methods() != NULL)) {
381 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(),
382 name, signature, Klass::find_overpass,
383 Klass::find_static, Klass::find_private);
384 if (index >= 0 ) {
385 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
386 }
387 }
388 if (vtable_index == Method::invalid_vtable_index) {
389 // get vtable_index for miranda methods
390 ResourceMark rm;
391 klassVtable *vt = InstanceKlass::cast(klass())->vtable();
392 vtable_index = vt->index_of_miranda(name, signature);
393 }
394 return vtable_index;
395 }
396
397 methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) {
398 InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()());
399
400 // Specify 'true' in order to skip default methods when searching the
401 // interfaces. Function lookup_method_in_klasses() already looked for
402 // the method in the default methods table.
403 return methodHandle(THREAD,
1173 bool check_null_and_abstract,
1174 TRAPS) {
1175
1176 // setup default return values
1177 int vtable_index = Method::invalid_vtable_index;
1178 methodHandle selected_method;
1179
1180 assert(recv.is_null() || recv->is_oop(), "receiver is not an oop");
1181
1182 // runtime method resolution
1183 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
1184 THROW(vmSymbols::java_lang_NullPointerException());
1185 }
1186
1187 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
1188 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
1189 // a missing receiver might result in a bogus lookup.
1190 assert(resolved_method->method_holder()->is_linked(), "must be linked");
1191
1192 // do lookup based on receiver klass using the vtable index
1193 if (resolved_method->method_holder()->is_interface()) { // default or miranda method
1194 vtable_index = vtable_index_of_interface_method(resolved_klass,
1195 resolved_method);
1196 assert(vtable_index >= 0 , "we should have valid vtable index at this point");
1197
1198 InstanceKlass* inst = InstanceKlass::cast(recv_klass());
1199 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
1200 } else {
1201 // at this point we are sure that resolved_method is virtual and not
1202 // a default or miranda method; therefore, it must have a valid vtable index.
1203 assert(!resolved_method->has_itable_index(), "");
1204 vtable_index = resolved_method->vtable_index();
1205 // We could get a negative vtable_index for final methods,
1206 // because as an optimization they are they are never put in the vtable,
1207 // unless they override an existing method.
1208 // If we do get a negative, it means the resolved method is the the selected
1209 // method, and it can never be changed by an override.
1210 if (vtable_index == Method::nonvirtual_vtable_index) {
1211 assert(resolved_method->can_be_statically_bound(), "cannot override this method");
1212 selected_method = resolved_method;
1213 } else {
1214 // recv_klass might be an arrayKlassOop but all vtables start at
1215 // the same place. The cast is to avoid virtual call and assertion.
1216 InstanceKlass* inst = (InstanceKlass*)recv_klass();
1217 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
1218 }
1219 }
1220
1221 // check if method exists
1222 if (selected_method.is_null()) {
|