[heap] Fix disabling of map space with --no-use-map-space flag

HeapAllocator didn't fall back to old space allocation when the
heap had no map space.

Bug: v8:12578, chromium:1313119
Change-Id: Ic02334f42f9fb80a8a9dcf99a94a7ac16da24053
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3570423
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79776}
This commit is contained in:
Dominik Inführ 2022-04-05 14:29:38 +02:00 committed by V8 LUCI CQ
parent 3eeea13cf7
commit 1b17e087a8
4 changed files with 24 additions and 6 deletions

View File

@ -30,9 +30,7 @@ OldLargeObjectSpace* HeapAllocator::lo_space() const {
return static_cast<OldLargeObjectSpace*>(spaces_[LO_SPACE]);
}
PagedSpace* HeapAllocator::map_space() const {
return static_cast<PagedSpace*>(spaces_[MAP_SPACE]);
}
PagedSpace* HeapAllocator::space_for_maps() const { return space_for_maps_; }
NewSpace* HeapAllocator::new_space() const {
return static_cast<NewSpace*>(spaces_[NEW_SPACE]);
@ -111,7 +109,7 @@ V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult HeapAllocator::AllocateRaw(
break;
case AllocationType::kMap:
DCHECK_EQ(alignment, AllocationAlignment::kTaggedAligned);
allocation = map_space()->AllocateRawUnaligned(size_in_bytes);
allocation = space_for_maps()->AllocateRawUnaligned(size_in_bytes);
break;
case AllocationType::kReadOnly:
DCHECK(read_only_space()->writable());

View File

@ -22,8 +22,15 @@ void HeapAllocator::Setup() {
for (int i = FIRST_SPACE; i <= LAST_SPACE; ++i) {
spaces_[i] = heap_->space(i);
}
space_for_maps_ = spaces_[MAP_SPACE]
? static_cast<PagedSpace*>(spaces_[MAP_SPACE])
: static_cast<PagedSpace*>(spaces_[OLD_SPACE]);
shared_old_allocator_ = heap_->shared_old_allocator_.get();
shared_map_allocator_ = heap_->shared_map_allocator_.get();
shared_map_allocator_ = heap_->shared_map_allocator_
? heap_->shared_map_allocator_.get()
: shared_old_allocator_;
}
void HeapAllocator::SetReadOnlySpace(ReadOnlySpace* read_only_space) {

View File

@ -75,7 +75,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
private:
V8_INLINE PagedSpace* code_space() const;
V8_INLINE CodeLargeObjectSpace* code_lo_space() const;
V8_INLINE PagedSpace* map_space() const;
V8_INLINE PagedSpace* space_for_maps() const;
V8_INLINE NewSpace* new_space() const;
V8_INLINE NewLargeObjectSpace* new_lo_space() const;
V8_INLINE OldLargeObjectSpace* lo_space() const;
@ -100,6 +100,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
Heap* const heap_;
Space* spaces_[LAST_SPACE + 1];
PagedSpace* space_for_maps_;
ReadOnlySpace* read_only_space_;
ConcurrentAllocator* shared_old_allocator_;

View File

@ -0,0 +1,12 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --no-use-map-space --harmony-struct
"use strict";
// Test ensures that deserialization works without map space and
// that we can allocate maps in the shared heap.
let SomeStruct = new SharedStructType(['field1', 'field2']);