Use cleared JNI weak sentinel from boot image.
We were already adding the sentinel to the boot image,
so we may as well reuse the boot image copy.
Also move pre-allocated objects from class roots to the
boot image live objects.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: aosp_taimen-userdebug boots.
Change-Id: I635dcdd146ca2c6b55d187e9a545a9990b0b35ca
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 1343b16..b2e7d99 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -951,12 +951,12 @@
gc::Heap* const heap = runtime->GetHeap();
std::vector<gc::space::ImageSpace*> spaces = heap->GetBootImageSpaces();
CHECK(!spaces.empty());
- uint32_t pointer_size_unchecked = spaces[0]->GetImageHeader().GetPointerSizeUnchecked();
+ const ImageHeader& image_header = spaces[0]->GetImageHeader();
+ uint32_t pointer_size_unchecked = image_header.GetPointerSizeUnchecked();
if (!ValidPointerSize(pointer_size_unchecked)) {
*error_msg = StringPrintf("Invalid image pointer size: %u", pointer_size_unchecked);
return false;
}
- const ImageHeader& image_header = spaces[0]->GetImageHeader();
image_pointer_size_ = image_header.GetPointerSize();
if (!runtime->IsAotCompiler()) {
// Only the Aot compiler supports having an image with a different pointer size than the
@@ -1057,15 +1057,15 @@
class_roots_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
ObjPtr<mirror::ObjectArray<mirror::Class>>::DownCast(
- spaces[0]->GetImageHeader().GetImageRoot(ImageHeader::kClassRoots)));
+ image_header.GetImageRoot(ImageHeader::kClassRoots)));
DCHECK_EQ(GetClassRoot<mirror::Class>(this)->GetClassFlags(), mirror::kClassFlagClass);
- ObjPtr<mirror::Class> java_lang_Object = GetClassRoot<mirror::Object>(this);
- java_lang_Object->SetObjectSize(sizeof(mirror::Object));
- // Allocate in non-movable so that it's possible to check if a JNI weak global ref has been
- // cleared without triggering the read barrier and unintentionally mark the sentinel alive.
- runtime->SetSentinel(heap->AllocNonMovableObject(
- self, java_lang_Object, java_lang_Object->GetObjectSize(), VoidFunctor()));
+ DCHECK_EQ(GetClassRoot<mirror::Object>(this)->GetObjectSize(), sizeof(mirror::Object));
+ ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects =
+ ObjPtr<mirror::ObjectArray<mirror::Object>>::DownCast(
+ image_header.GetImageRoot(ImageHeader::kBootImageLiveObjects));
+ runtime->SetSentinel(boot_image_live_objects->Get(ImageHeader::kClearedJniWeakSentinel));
+ DCHECK(runtime->GetSentinel().Read()->GetClass() == GetClassRoot<mirror::Object>(this));
const std::vector<std::string>& boot_class_path_locations = runtime->GetBootClassPathLocations();
CHECK_LE(spaces.size(), boot_class_path_locations.size());