diff options
author | 2019-06-13 10:52:32 +0100 | |
---|---|---|
committer | 2019-06-17 09:30:53 +0000 | |
commit | 024d69fb9936ca5a0031d35c9f248853cbc25d3f (patch) | |
tree | c1eeddf91ea15eda5d139d4592ac7f0df80e9be0 /runtime/class_linker.cc | |
parent | 43ae4acf219fe25a56e2055ebcebc4d08020a25d (diff) |
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
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 18 |
1 files changed, 9 insertions, 9 deletions
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<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 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { 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()); |