Fix ClassLinker::InitializeStaticStorageFromCode
Previously the code computed the storage and returned the pointer to
it, but it forgot to set the value into the table for future
callers. Added a test to confirm the correct behavior.
Change-Id: I48717a3d4926f5ddc0ad09d065f75d031eb5b8fb
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 583c280..92b3fca 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -565,4 +565,20 @@
EXPECT_EQ(Aj2, A->FindVirtualMethodForVirtualOrInterface(Jj2));
}
+TEST_F(ClassLinkerTest, InitializeStaticStorageFromCode) {
+ // pretend we are trying to ensure we have initilized storage for Static from Statics.<clinit>
+ const ClassLoader* class_loader = LoadDex("Statics");
+ const DexFile* dex_file = ClassLoader::GetClassPath(class_loader)[0];
+ CHECK(dex_file != NULL);
+
+ Class* Statics = class_linker_->FindClass("LStatics;", class_loader);
+ Method* clinit = Statics->FindDirectMethod("<clinit>", "()V");
+ uint32_t type_idx = FindTypeIdxByDescriptor(*dex_file, "LStatics;");
+
+ EXPECT_TRUE(clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx) == NULL);
+ StaticStorageBase* storage = class_linker_->InitializeStaticStorageFromCode(type_idx, clinit);
+ EXPECT_TRUE(storage != NULL);
+ EXPECT_EQ(storage, clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx));
+}
+
} // namespace art