summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/class_linker.cc18
-rw-r--r--runtime/image.cc2
-rw-r--r--runtime/image.h13
-rw-r--r--runtime/runtime.cc13
-rw-r--r--runtime/runtime.h2
5 files changed, 28 insertions, 20 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());
diff --git a/runtime/image.cc b/runtime/image.cc
index 64046d025d..0209a2955b 100644
--- a/runtime/image.cc
+++ b/runtime/image.cc
@@ -29,7 +29,7 @@
namespace art {
const uint8_t ImageHeader::kImageMagic[] = { 'a', 'r', 't', '\n' };
-const uint8_t ImageHeader::kImageVersion[] = { '0', '7', '6', '\0' }; // SBAppend simplification.
+const uint8_t ImageHeader::kImageVersion[] = { '0', '7', '7', '\0' }; // Use boot image sentinel.
ImageHeader::ImageHeader(uint32_t image_reservation_size,
uint32_t component_count,
diff --git a/runtime/image.h b/runtime/image.h
index 88bba13e19..46260552db 100644
--- a/runtime/image.h
+++ b/runtime/image.h
@@ -222,10 +222,6 @@ class PACKED(8) ImageHeader {
enum ImageRoot {
kDexCaches,
kClassRoots,
- kOomeWhenThrowingException, // Pre-allocated OOME when throwing exception.
- kOomeWhenThrowingOome, // Pre-allocated OOME when throwing OOME.
- kOomeWhenHandlingStackOverflow, // Pre-allocated OOME when handling StackOverflowError.
- kNoClassDefFoundError, // Pre-allocated NoClassDefFoundError.
kSpecialRoots, // Different for boot image and app image, see aliases below.
kImageRootsMax,
@@ -234,6 +230,15 @@ class PACKED(8) ImageHeader {
kBootImageLiveObjects = kSpecialRoots, // Array of boot image objects that must be kept live.
};
+ enum BootImageLiveObjects {
+ kOomeWhenThrowingException, // Pre-allocated OOME when throwing exception.
+ kOomeWhenThrowingOome, // Pre-allocated OOME when throwing OOME.
+ kOomeWhenHandlingStackOverflow, // Pre-allocated OOME when handling StackOverflowError.
+ kNoClassDefFoundError, // Pre-allocated NoClassDefFoundError.
+ kClearedJniWeakSentinel, // Pre-allocated sentinel for cleared weak JNI references.
+ kIntrinsicObjectsStart
+ };
+
/*
* This describes the number and ordering of sections inside of Boot
* and App Images. It is very important that changes to this struct
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index cda1fd9d5b..3ba888f8bb 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1094,7 +1094,7 @@ static size_t OpenBootDexFiles(ArrayRef<const std::string> dex_filenames,
return failure_count;
}
-void Runtime::SetSentinel(mirror::Object* sentinel) {
+void Runtime::SetSentinel(ObjPtr<mirror::Object> sentinel) {
CHECK(sentinel_.Read() == nullptr);
CHECK(sentinel != nullptr);
CHECK(!heap_->IsMovableObject(sentinel));
@@ -1612,20 +1612,23 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
if (GetHeap()->HasBootImageSpace()) {
const ImageHeader& image_header = GetHeap()->GetBootImageSpaces()[0]->GetImageHeader();
+ ObjPtr<mirror::ObjectArray<mirror::Object>> boot_image_live_objects =
+ ObjPtr<mirror::ObjectArray<mirror::Object>>::DownCast(
+ image_header.GetImageRoot(ImageHeader::kBootImageLiveObjects));
pre_allocated_OutOfMemoryError_when_throwing_exception_ = GcRoot<mirror::Throwable>(
- image_header.GetImageRoot(ImageHeader::kOomeWhenThrowingException)->AsThrowable());
+ boot_image_live_objects->Get(ImageHeader::kOomeWhenThrowingException)->AsThrowable());
DCHECK(pre_allocated_OutOfMemoryError_when_throwing_exception_.Read()->GetClass()
->DescriptorEquals("Ljava/lang/OutOfMemoryError;"));
pre_allocated_OutOfMemoryError_when_throwing_oome_ = GcRoot<mirror::Throwable>(
- image_header.GetImageRoot(ImageHeader::kOomeWhenThrowingOome)->AsThrowable());
+ boot_image_live_objects->Get(ImageHeader::kOomeWhenThrowingOome)->AsThrowable());
DCHECK(pre_allocated_OutOfMemoryError_when_throwing_oome_.Read()->GetClass()
->DescriptorEquals("Ljava/lang/OutOfMemoryError;"));
pre_allocated_OutOfMemoryError_when_handling_stack_overflow_ = GcRoot<mirror::Throwable>(
- image_header.GetImageRoot(ImageHeader::kOomeWhenHandlingStackOverflow)->AsThrowable());
+ boot_image_live_objects->Get(ImageHeader::kOomeWhenHandlingStackOverflow)->AsThrowable());
DCHECK(pre_allocated_OutOfMemoryError_when_handling_stack_overflow_.Read()->GetClass()
->DescriptorEquals("Ljava/lang/OutOfMemoryError;"));
pre_allocated_NoClassDefFoundError_ = GcRoot<mirror::Throwable>(
- image_header.GetImageRoot(ImageHeader::kNoClassDefFoundError)->AsThrowable());
+ boot_image_live_objects->Get(ImageHeader::kNoClassDefFoundError)->AsThrowable());
DCHECK(pre_allocated_NoClassDefFoundError_.Read()->GetClass()
->DescriptorEquals("Ljava/lang/NoClassDefFoundError;"));
} else {
diff --git a/runtime/runtime.h b/runtime/runtime.h
index dd66b8568a..7050fd23b6 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -719,7 +719,7 @@ class Runtime {
}
// Called from class linker.
- void SetSentinel(mirror::Object* sentinel) REQUIRES_SHARED(Locks::mutator_lock_);
+ void SetSentinel(ObjPtr<mirror::Object> sentinel) REQUIRES_SHARED(Locks::mutator_lock_);
// For testing purpose only.
// TODO: Remove this when this is no longer needed (b/116087961).
GcRoot<mirror::Object> GetSentinel() REQUIRES_SHARED(Locks::mutator_lock_);