[heap] Tie process-wide CodeRange lifetime to any remaining Heaps
Currently the process-wide CodeRange, once created, lives until process shutdown. This CL changes it to be alive as long as there is a Heap, when the last Heap is gone it gets destroyed and will be recreated the next time a Heap is created. This behavior is shared with SingleCopyReadOnlyArtifacts. Bug: v8:11929 Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng Change-Id: I8a545926c3a4122991f9682bd3fd90e72697ea5a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2989103 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Shu-yu Guo <syg@chromium.org> Cr-Commit-Position: refs/heads/master@{#75522}
This commit is contained in:
parent
4a13063eae
commit
1532f8ff92
@ -14,8 +14,11 @@ namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
DEFINE_LAZY_LEAKY_OBJECT_GETTER(std::shared_ptr<CodeRange>,
|
||||
GetProcessWideCodeRangeCage)
|
||||
// Weak pointer holding the process-wide CodeRange, if one has been created. All
|
||||
// Heaps hold a std::shared_ptr to this, so this is destroyed when no Heaps
|
||||
// remain.
|
||||
base::LazyInstance<std::weak_ptr<CodeRange>>::type process_wide_code_range_ =
|
||||
LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
DEFINE_LAZY_LEAKY_OBJECT_GETTER(CodeRangeAddressHint, GetCodeRangeAddressHint)
|
||||
|
||||
@ -153,19 +156,23 @@ uint8_t* CodeRange::RemapEmbeddedBuiltins(Isolate* isolate,
|
||||
}
|
||||
|
||||
// static
|
||||
void CodeRange::InitializeProcessWideCodeRangeOnce(
|
||||
std::shared_ptr<CodeRange> CodeRange::EnsureProcessWideCodeRange(
|
||||
v8::PageAllocator* page_allocator, size_t requested_size) {
|
||||
*GetProcessWideCodeRangeCage() = std::make_shared<CodeRange>();
|
||||
if (!GetProcessWideCodeRange()->InitReservation(page_allocator,
|
||||
requested_size)) {
|
||||
V8::FatalProcessOutOfMemory(
|
||||
nullptr, "Failed to reserve virtual memory for CodeRange");
|
||||
std::shared_ptr<CodeRange> code_range = process_wide_code_range_.Get().lock();
|
||||
if (!code_range) {
|
||||
code_range = std::make_shared<CodeRange>();
|
||||
if (!code_range->InitReservation(page_allocator, requested_size)) {
|
||||
V8::FatalProcessOutOfMemory(
|
||||
nullptr, "Failed to reserve virtual memory for CodeRange");
|
||||
}
|
||||
*process_wide_code_range_.Pointer() = code_range;
|
||||
}
|
||||
return code_range;
|
||||
}
|
||||
|
||||
// static
|
||||
std::shared_ptr<CodeRange> CodeRange::GetProcessWideCodeRange() {
|
||||
return *GetProcessWideCodeRangeCage();
|
||||
return process_wide_code_range_.Get().lock();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -120,7 +120,7 @@ class CodeRange final : public VirtualMemoryCage {
|
||||
const uint8_t* embedded_blob_code,
|
||||
size_t embedded_blob_code_size);
|
||||
|
||||
static void InitializeProcessWideCodeRangeOnce(
|
||||
static std::shared_ptr<CodeRange> EnsureProcessWideCodeRange(
|
||||
v8::PageAllocator* page_allocator, size_t requested_size);
|
||||
|
||||
// If InitializeProcessWideCodeRangeOnce has been called, returns the
|
||||
|
@ -5355,10 +5355,6 @@ HeapObject Heap::AllocateRawWithRetryOrFailSlowPath(
|
||||
FatalProcessOutOfMemory("CALL_AND_RETRY_LAST");
|
||||
}
|
||||
|
||||
namespace {
|
||||
V8_DECLARE_ONCE(initialize_shared_code_range_once);
|
||||
} // namespace
|
||||
|
||||
void Heap::SetUp() {
|
||||
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
|
||||
allocation_timeout_ = NextAllocationTimeout();
|
||||
@ -5391,10 +5387,8 @@ void Heap::SetUp() {
|
||||
// When sharing a pointer cage among Isolates, also share the
|
||||
// CodeRange. isolate_->page_allocator() is the process-wide pointer
|
||||
// compression cage's PageAllocator.
|
||||
base::CallOnce(&initialize_shared_code_range_once,
|
||||
&CodeRange::InitializeProcessWideCodeRangeOnce,
|
||||
isolate_->page_allocator(), requested_size);
|
||||
code_range_ = CodeRange::GetProcessWideCodeRange();
|
||||
code_range_ = CodeRange::EnsureProcessWideCodeRange(
|
||||
isolate_->page_allocator(), requested_size);
|
||||
} else {
|
||||
code_range_ = std::make_shared<CodeRange>();
|
||||
if (!code_range_->InitReservation(isolate_->page_allocator(),
|
||||
|
Loading…
Reference in New Issue
Block a user