Handle allocation failure in AddPreResolvedStringsArray
Might fail on 32 bits if the address space is fragmented.
Regression test is infeasible to add.
Bug: 134652205
Test: test-art-host
Change-Id: I8a254a27275be4e0ff39fdb72715771f4f77cf36
diff --git a/runtime/mirror/dex_cache.cc b/runtime/mirror/dex_cache.cc
index 7e79ebe..f97f521 100644
--- a/runtime/mirror/dex_cache.cc
+++ b/runtime/mirror/dex_cache.cc
@@ -172,19 +172,25 @@
dex_file->NumCallSiteIds());
}
-void DexCache::AddPreResolvedStringsArray() {
+bool DexCache::AddPreResolvedStringsArray() {
DCHECK_EQ(NumPreResolvedStrings(), 0u);
Thread* const self = Thread::Current();
LinearAlloc* linear_alloc = Runtime::Current()->GetLinearAlloc();
const size_t num_strings = GetDexFile()->NumStringIds();
- SetField32<false>(NumPreResolvedStringsOffset(), num_strings);
GcRoot<mirror::String>* strings =
linear_alloc->AllocArray<GcRoot<mirror::String>>(self, num_strings);
+ if (strings == nullptr) {
+ // Failed to allocate pre-resolved string array (probably due to address fragmentation), bail.
+ return false;
+ }
+ SetField32<false>(NumPreResolvedStringsOffset(), num_strings);
+
CHECK(strings != nullptr);
SetPreResolvedStrings(strings);
for (size_t i = 0; i < GetDexFile()->NumStringIds(); ++i) {
CHECK(GetPreResolvedStrings()[i].Read() == nullptr);
}
+ return true;
}
void DexCache::Init(const DexFile* dex_file,