Commit c334d7d6 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

Revert "[heap] Tie process-wide CodeRange lifetime to any remaining Heaps"

This reverts commit 1532f8ff.

Reason for revert: Race in initialization

Original change's description:
> [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}

Bug: v8:11929
Change-Id: Ie13a09fc07f8da8af3813de46298eceb7b18ba41
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3000960
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/master@{#75539}
parent 32f169f8
......@@ -14,11 +14,8 @@ namespace internal {
namespace {
// 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(std::shared_ptr<CodeRange>,
GetProcessWideCodeRangeCage)
DEFINE_LAZY_LEAKY_OBJECT_GETTER(CodeRangeAddressHint, GetCodeRangeAddressHint)
......@@ -156,23 +153,19 @@ uint8_t* CodeRange::RemapEmbeddedBuiltins(Isolate* isolate,
}
// static
std::shared_ptr<CodeRange> CodeRange::EnsureProcessWideCodeRange(
void CodeRange::InitializeProcessWideCodeRangeOnce(
v8::PageAllocator* page_allocator, size_t requested_size) {
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;
*GetProcessWideCodeRangeCage() = std::make_shared<CodeRange>();
if (!GetProcessWideCodeRange()->InitReservation(page_allocator,
requested_size)) {
V8::FatalProcessOutOfMemory(
nullptr, "Failed to reserve virtual memory for CodeRange");
}
return code_range;
}
// static
std::shared_ptr<CodeRange> CodeRange::GetProcessWideCodeRange() {
return process_wide_code_range_.Get().lock();
return *GetProcessWideCodeRangeCage();
}
} // namespace internal
......
......@@ -120,7 +120,7 @@ class CodeRange final : public VirtualMemoryCage {
const uint8_t* embedded_blob_code,
size_t embedded_blob_code_size);
static std::shared_ptr<CodeRange> EnsureProcessWideCodeRange(
static void InitializeProcessWideCodeRangeOnce(
v8::PageAllocator* page_allocator, size_t requested_size);
// If InitializeProcessWideCodeRangeOnce has been called, returns the
......
......@@ -5355,6 +5355,10 @@ 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();
......@@ -5387,8 +5391,10 @@ 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.
code_range_ = CodeRange::EnsureProcessWideCodeRange(
isolate_->page_allocator(), requested_size);
base::CallOnce(&initialize_shared_code_range_once,
&CodeRange::InitializeProcessWideCodeRangeOnce,
isolate_->page_allocator(), requested_size);
code_range_ = CodeRange::GetProcessWideCodeRange();
} else {
code_range_ = std::make_shared<CodeRange>();
if (!code_range_->InitReservation(isolate_->page_allocator(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment