Fix jvmti bug when redefining a boot classpath class.
We were not using the right dex cache when registering the new dex file.
Test: test.py
Bug: 218984107
Change-Id: I43c581b46b4624ca9b1430dfe6164a04cb4089a1
diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc
index c234bd4..15cb6de 100644
--- a/openjdkjvmti/ti_redefine.cc
+++ b/openjdkjvmti/ti_redefine.cc
@@ -2477,10 +2477,11 @@
art::ClassLinker* cl = runtime_->GetClassLinker();
if (data.GetSourceClassLoader() == nullptr) {
// AppendToBootClassPath includes dex file registration.
- cl->AppendToBootClassPath(self_, &data.GetRedefinition().GetDexFile());
+ cl->AppendToBootClassPath(&data.GetRedefinition().GetDexFile(), data.GetNewDexCache());
} else {
cl->RegisterExistingDexCache(data.GetNewDexCache(), data.GetSourceClassLoader());
}
+ DCHECK_EQ(cl->FindDexCache(self_, data.GetRedefinition().GetDexFile()), data.GetNewDexCache());
}
UnregisterAllBreakpoints();
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 428136a..9d2755c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3753,6 +3753,7 @@
ObjPtr<mirror::DexCache> dex_cache) {
CHECK(dex_file != nullptr);
CHECK(dex_cache != nullptr) << dex_file->GetLocation();
+ CHECK_EQ(dex_cache->GetDexFile(), dex_file) << dex_file->GetLocation();
boot_class_path_.push_back(dex_file);
WriterMutexLock mu(Thread::Current(), *Locks::dex_lock_);
RegisterDexFileLocked(*dex_file, dex_cache, /* class_loader= */ nullptr);
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 2929ae9..06e6fca 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -766,6 +766,10 @@
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
+ void AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::dex_lock_);
+
// Visit all of the class loaders in the class linker.
void VisitClassLoaders(ClassLoaderVisitor* visitor) const
REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
@@ -961,10 +965,6 @@
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
- void AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache)
- REQUIRES_SHARED(Locks::mutator_lock_)
- REQUIRES(!Locks::dex_lock_);
-
// Precomputes size needed for Class, in the case of a non-temporary class this size must be
// sufficient to hold all static fields.
uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file,