Skip to content

Commit f72bf95

Browse files
author
duke
committed
Automatic merge of jdk:master into master
2 parents 252d5c1 + fae68ff commit f72bf95

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,15 +2571,21 @@ void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handl
25712571
for (int index = 0; index < num_methods; ++index) {
25722572
methods->at(index)->restore_unshareable_info(CHECK);
25732573
}
2574+
#if INCLUDE_JVMTI
25742575
if (JvmtiExport::has_redefined_a_class()) {
25752576
// Reinitialize vtable because RedefineClasses may have changed some
25762577
// entries in this vtable for super classes so the CDS vtable might
25772578
// point to old or obsolete entries. RedefineClasses doesn't fix up
25782579
// vtables in the shared system dictionary, only the main one.
25792580
// It also redefines the itable too so fix that too.
2581+
// First fix any default methods that point to a super class that may
2582+
// have been redefined.
2583+
bool trace_name_printed = false;
2584+
adjust_default_methods(&trace_name_printed);
25802585
vtable().initialize_vtable(false, CHECK);
25812586
itable().initialize_itable(false, CHECK);
25822587
}
2588+
#endif
25832589

25842590
// restore constant pool resolved references
25852591
constants()->restore_unshareable_info(CHECK);

src/hotspot/share/oops/klassVtable.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,22 @@ void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) {
222222
assert(def_vtable_indices->length() == len, "reinit vtable len?");
223223
}
224224
for (int i = 0; i < len; i++) {
225-
methodHandle mh(THREAD, default_methods->at(i));
226-
assert(!mh->is_private(), "private interface method in the default method list");
227-
bool needs_new_entry = update_inherited_vtable(mh, super_vtable_len, i, checkconstraints, CHECK);
225+
bool needs_new_entry;
226+
{
227+
// Reduce the scope of this handle so that it is fetched again.
228+
// The methodHandle keeps it from being deleted by RedefineClasses while
229+
// we're using it.
230+
methodHandle mh(THREAD, default_methods->at(i));
231+
assert(!mh->is_private(), "private interface method in the default method list");
232+
needs_new_entry = update_inherited_vtable(mh, super_vtable_len, i, checkconstraints, CHECK);
233+
}
228234

229235
// needs new entry
230236
if (needs_new_entry) {
231-
put_method_at(mh(), initialized);
237+
// Refetch this default method in case of redefinition that might
238+
// happen during constraint checking in the update_inherited_vtable call above.
239+
Method* method = default_methods->at(i);
240+
put_method_at(method, initialized);
232241
if (is_preinitialized_vtable()) {
233242
// At runtime initialize_vtable is rerun for a shared class
234243
// (loaded by the non-boot loader) as part of link_class_impl().
@@ -494,6 +503,11 @@ bool klassVtable::update_inherited_vtable(const methodHandle& target_method,
494503
allocate_new = false;
495504
}
496505

506+
// Set the vtable index before the constraint check safepoint, which potentially
507+
// redefines this method if this method is a default method belonging to a
508+
// super class or interface.
509+
put_method_at(target_method(), i);
510+
497511
// Do not check loader constraints for overpass methods because overpass
498512
// methods are created by the jvm to throw exceptions.
499513
if (checkconstraints && !target_method->is_overpass()) {
@@ -531,7 +545,6 @@ bool klassVtable::update_inherited_vtable(const methodHandle& target_method,
531545
}
532546
}
533547

534-
put_method_at(target_method(), i);
535548
overrides = true;
536549
if (!is_default) {
537550
target_method->set_vtable_index(i);

0 commit comments

Comments
 (0)