From 024d69fb9936ca5a0031d35c9f248853cbc25d3f Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Thu, 13 Jun 2019 10:52:32 +0100 Subject: 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 --- runtime/class_linker.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'runtime/class_linker.cc') diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 1343b16193..b2e7d99497 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -951,12 +951,12 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { gc::Heap* const heap = runtime->GetHeap(); std::vector 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 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { class_roots_ = GcRoot>( ObjPtr>::DownCast( - spaces[0]->GetImageHeader().GetImageRoot(ImageHeader::kClassRoots))); + image_header.GetImageRoot(ImageHeader::kClassRoots))); DCHECK_EQ(GetClassRoot(this)->GetClassFlags(), mirror::kClassFlagClass); - ObjPtr java_lang_Object = GetClassRoot(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(this)->GetObjectSize(), sizeof(mirror::Object)); + ObjPtr> boot_image_live_objects = + ObjPtr>::DownCast( + image_header.GetImageRoot(ImageHeader::kBootImageLiveObjects)); + runtime->SetSentinel(boot_image_live_objects->Get(ImageHeader::kClearedJniWeakSentinel)); + DCHECK(runtime->GetSentinel().Read()->GetClass() == GetClassRoot(this)); const std::vector& boot_class_path_locations = runtime->GetBootClassPathLocations(); CHECK_LE(spaces.size(), boot_class_path_locations.size()); -- cgit v1.2.3-59-g8ed1b