236 } else { |
236 } else { |
237 _method_ordering = Universe::the_empty_int_array(); |
237 _method_ordering = Universe::the_empty_int_array(); |
238 } |
238 } |
239 } |
239 } |
240 |
240 |
|
241 // create a new array of vtable_indices for default methods |
|
242 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) { |
|
243 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL); |
|
244 assert(default_vtable_indices() == NULL, "only create once"); |
|
245 set_default_vtable_indices(vtable_indices); |
|
246 return vtable_indices; |
|
247 } |
241 |
248 |
242 InstanceKlass::InstanceKlass(int vtable_len, |
249 InstanceKlass::InstanceKlass(int vtable_len, |
243 int itable_len, |
250 int itable_len, |
244 int static_field_size, |
251 int static_field_size, |
245 int nonstatic_oop_map_size, |
252 int nonstatic_oop_map_size, |
374 if (method_ordering() != Universe::the_empty_int_array()) { |
383 if (method_ordering() != Universe::the_empty_int_array()) { |
375 MetadataFactory::free_array<int>(loader_data, method_ordering()); |
384 MetadataFactory::free_array<int>(loader_data, method_ordering()); |
376 } |
385 } |
377 set_method_ordering(NULL); |
386 set_method_ordering(NULL); |
378 |
387 |
|
388 // default methods can be empty |
|
389 if (default_methods() != NULL && |
|
390 default_methods() != Universe::the_empty_method_array()) { |
|
391 MetadataFactory::free_array<Method*>(loader_data, default_methods()); |
|
392 } |
|
393 // Do NOT deallocate the default methods, they are owned by superinterfaces. |
|
394 set_default_methods(NULL); |
|
395 |
|
396 // default methods vtable indices can be empty |
|
397 if (default_vtable_indices() != NULL) { |
|
398 MetadataFactory::free_array<int>(loader_data, default_vtable_indices()); |
|
399 } |
|
400 set_default_vtable_indices(NULL); |
|
401 |
|
402 |
379 // This array is in Klass, but remove it with the InstanceKlass since |
403 // This array is in Klass, but remove it with the InstanceKlass since |
380 // this place would be the only caller and it can share memory with transitive |
404 // this place would be the only caller and it can share memory with transitive |
381 // interfaces. |
405 // interfaces. |
382 if (secondary_supers() != Universe::the_empty_klass_array() && |
406 if (secondary_supers() != Universe::the_empty_klass_array() && |
383 secondary_supers() != transitive_interfaces()) { |
407 secondary_supers() != transitive_interfaces()) { |
1352 } |
1376 } |
1353 } |
1377 } |
1354 return -1; |
1378 return -1; |
1355 } |
1379 } |
1356 |
1380 |
|
1381 // find_method looks up the name/signature in the local methods array |
1357 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1382 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1358 return InstanceKlass::find_method(methods(), name, signature); |
1383 return InstanceKlass::find_method(methods(), name, signature); |
1359 } |
1384 } |
1360 |
1385 |
|
1386 // find_method looks up the name/signature in the local methods array |
1361 Method* InstanceKlass::find_method( |
1387 Method* InstanceKlass::find_method( |
|
1388 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
|
1389 int hit = find_method_index(methods, name, signature); |
|
1390 return hit >= 0 ? methods->at(hit): NULL; |
|
1391 } |
|
1392 |
|
1393 // Used directly for default_methods to find the index into the |
|
1394 // default_vtable_indices, and indirectly by find_method |
|
1395 // find_method_index looks in the local methods array to return the index |
|
1396 // of the matching name/signature |
|
1397 int InstanceKlass::find_method_index( |
1362 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1398 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1363 int hit = binary_search(methods, name); |
1399 int hit = binary_search(methods, name); |
1364 if (hit != -1) { |
1400 if (hit != -1) { |
1365 Method* m = methods->at(hit); |
1401 Method* m = methods->at(hit); |
1366 // Do linear search to find matching signature. First, quick check |
1402 // Do linear search to find matching signature. First, quick check |
1367 // for common case |
1403 // for common case |
1368 if (m->signature() == signature) return m; |
1404 if (m->signature() == signature) return hit; |
1369 // search downwards through overloaded methods |
1405 // search downwards through overloaded methods |
1370 int i; |
1406 int i; |
1371 for (i = hit - 1; i >= 0; --i) { |
1407 for (i = hit - 1; i >= 0; --i) { |
1372 Method* m = methods->at(i); |
1408 Method* m = methods->at(i); |
1373 assert(m->is_method(), "must be method"); |
1409 assert(m->is_method(), "must be method"); |
1374 if (m->name() != name) break; |
1410 if (m->name() != name) break; |
1375 if (m->signature() == signature) return m; |
1411 if (m->signature() == signature) return i; |
1376 } |
1412 } |
1377 // search upwards |
1413 // search upwards |
1378 for (i = hit + 1; i < methods->length(); ++i) { |
1414 for (i = hit + 1; i < methods->length(); ++i) { |
1379 Method* m = methods->at(i); |
1415 Method* m = methods->at(i); |
1380 assert(m->is_method(), "must be method"); |
1416 assert(m->is_method(), "must be method"); |
1381 if (m->name() != name) break; |
1417 if (m->name() != name) break; |
1382 if (m->signature() == signature) return m; |
1418 if (m->signature() == signature) return i; |
1383 } |
1419 } |
1384 // not found |
1420 // not found |
1385 #ifdef ASSERT |
1421 #ifdef ASSERT |
1386 int index = linear_search(methods, name, signature); |
1422 int index = linear_search(methods, name, signature); |
1387 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1423 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1388 #endif |
1424 #endif |
1389 } |
1425 } |
1390 return NULL; |
1426 return -1; |
1391 } |
1427 } |
1392 |
|
1393 int InstanceKlass::find_method_by_name(Symbol* name, int* end) { |
1428 int InstanceKlass::find_method_by_name(Symbol* name, int* end) { |
1394 return find_method_by_name(methods(), name, end); |
1429 return find_method_by_name(methods(), name, end); |
1395 } |
1430 } |
1396 |
1431 |
1397 int InstanceKlass::find_method_by_name( |
1432 int InstanceKlass::find_method_by_name( |
1406 return start; |
1441 return start; |
1407 } |
1442 } |
1408 return -1; |
1443 return -1; |
1409 } |
1444 } |
1410 |
1445 |
|
1446 // lookup_method searches both the local methods array and all superclasses methods arrays |
1411 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1447 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1412 Klass* klass = const_cast<InstanceKlass*>(this); |
1448 Klass* klass = const_cast<InstanceKlass*>(this); |
1413 while (klass != NULL) { |
1449 while (klass != NULL) { |
1414 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); |
1450 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); |
1415 if (method != NULL) return method; |
1451 if (method != NULL) return method; |
1416 klass = InstanceKlass::cast(klass)->super(); |
1452 klass = InstanceKlass::cast(klass)->super(); |
1417 } |
1453 } |
1418 return NULL; |
1454 return NULL; |
|
1455 } |
|
1456 |
|
1457 // lookup a method in the default methods list then in all transitive interfaces |
|
1458 // Do NOT return private or static methods |
|
1459 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name, |
|
1460 Symbol* signature) const { |
|
1461 Method* m; |
|
1462 if (default_methods() != NULL) { |
|
1463 m = find_method(default_methods(), name, signature); |
|
1464 } |
|
1465 // Look up interfaces |
|
1466 if (m == NULL) { |
|
1467 m = lookup_method_in_all_interfaces(name, signature); |
|
1468 } |
|
1469 return m; |
1419 } |
1470 } |
1420 |
1471 |
1421 // lookup a method in all the interfaces that this class implements |
1472 // lookup a method in all the interfaces that this class implements |
1422 // Do NOT return private or static methods, new in JDK8 which are not externally visible |
1473 // Do NOT return private or static methods, new in JDK8 which are not externally visible |
1423 // They should only be found in the initial InterfaceMethodRef |
1474 // They should only be found in the initial InterfaceMethodRef |
2546 THROW_NULL(vmSymbols::java_lang_AbstractMethodError()); |
2597 THROW_NULL(vmSymbols::java_lang_AbstractMethodError()); |
2547 } |
2598 } |
2548 return m; |
2599 return m; |
2549 } |
2600 } |
2550 |
2601 |
|
2602 |
|
2603 #if INCLUDE_JVMTI |
|
2604 // update default_methods for redefineclasses for methods that are |
|
2605 // not yet in the vtable due to concurrent subclass define and superinterface |
|
2606 // redefinition |
|
2607 // Note: those in the vtable, should have been updated via adjust_method_entries |
|
2608 void InstanceKlass::adjust_default_methods(Method** old_methods, Method** new_methods, |
|
2609 int methods_length, bool* trace_name_printed) { |
|
2610 // search the default_methods for uses of either obsolete or EMCP methods |
|
2611 if (default_methods() != NULL) { |
|
2612 for (int j = 0; j < methods_length; j++) { |
|
2613 Method* old_method = old_methods[j]; |
|
2614 Method* new_method = new_methods[j]; |
|
2615 |
|
2616 for (int index = 0; index < default_methods()->length(); index ++) { |
|
2617 if (default_methods()->at(index) == old_method) { |
|
2618 default_methods()->at_put(index, new_method); |
|
2619 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { |
|
2620 if (!(*trace_name_printed)) { |
|
2621 // RC_TRACE_MESG macro has an embedded ResourceMark |
|
2622 RC_TRACE_MESG(("adjust: klassname=%s default methods from name=%s", |
|
2623 external_name(), |
|
2624 old_method->method_holder()->external_name())); |
|
2625 *trace_name_printed = true; |
|
2626 } |
|
2627 RC_TRACE(0x00100000, ("default method update: %s(%s) ", |
|
2628 new_method->name()->as_C_string(), |
|
2629 new_method->signature()->as_C_string())); |
|
2630 } |
|
2631 } |
|
2632 } |
|
2633 } |
|
2634 } |
|
2635 } |
|
2636 #endif // INCLUDE_JVMTI |
|
2637 |
2551 // On-stack replacement stuff |
2638 // On-stack replacement stuff |
2552 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2639 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2553 // only one compilation can be active |
2640 // only one compilation can be active |
2554 NEEDS_CLEANUP |
2641 NEEDS_CLEANUP |
2555 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2642 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2740 |
2827 |
2741 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); |
2828 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); |
2742 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); |
2829 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); |
2743 if (Verbose || WizardMode) { |
2830 if (Verbose || WizardMode) { |
2744 Array<Method*>* method_array = methods(); |
2831 Array<Method*>* method_array = methods(); |
2745 for(int i = 0; i < method_array->length(); i++) { |
2832 for (int i = 0; i < method_array->length(); i++) { |
2746 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
2833 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
2747 } |
2834 } |
2748 } |
2835 } |
2749 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr(); |
2836 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr(); |
|
2837 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr(); |
|
2838 if (Verbose && default_methods() != NULL) { |
|
2839 Array<Method*>* method_array = default_methods(); |
|
2840 for (int i = 0; i < method_array->length(); i++) { |
|
2841 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
|
2842 } |
|
2843 } |
|
2844 if (default_vtable_indices() != NULL) { |
|
2845 st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr(); |
|
2846 } |
2750 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); |
2847 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); |
2751 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); |
2848 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); |
2752 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr(); |
2849 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr(); |
2753 if (class_loader_data() != NULL) { |
2850 if (class_loader_data() != NULL) { |
2754 st->print(BULLET"class loader data: "); |
2851 st->print(BULLET"class loader data: "); |
3094 } |
3191 } |
3095 // Verify sum of indices 0,1,...,length-1 |
3192 // Verify sum of indices 0,1,...,length-1 |
3096 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); |
3193 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); |
3097 } else { |
3194 } else { |
3098 guarantee(length == 0, "invalid method ordering length"); |
3195 guarantee(length == 0, "invalid method ordering length"); |
|
3196 } |
|
3197 } |
|
3198 |
|
3199 // Verify default methods |
|
3200 if (default_methods() != NULL) { |
|
3201 Array<Method*>* methods = this->default_methods(); |
|
3202 for (int j = 0; j < methods->length(); j++) { |
|
3203 guarantee(methods->at(j)->is_method(), "non-method in methods array"); |
|
3204 } |
|
3205 for (int j = 0; j < methods->length() - 1; j++) { |
|
3206 Method* m1 = methods->at(j); |
|
3207 Method* m2 = methods->at(j + 1); |
|
3208 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly"); |
3099 } |
3209 } |
3100 } |
3210 } |
3101 |
3211 |
3102 // Verify JNI static field identifiers |
3212 // Verify JNI static field identifiers |
3103 if (jni_ids() != NULL) { |
3213 if (jni_ids() != NULL) { |