Skip to content

Commit a383aa3

Browse files
hannespayerCommit Bot
authored and
Commit Bot
committed
Reland "[heap] Adds a young generation large object space"
Bug: chromium:852420 Change-Id: I44d0bde25283ac8c00155344f879eb1143b43bc9 Reviewed-on: https://chromium-review.googlesource.com/1119688 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Hannes Payer <hpayer@chromium.org> Cr-Commit-Position: refs/heads/master@{#54130}
1 parent 83f5b8d commit a383aa3

11 files changed

+74
-10
lines changed

src/flag-definitions.h

+4
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ DEFINE_NEG_NEG_IMPLICATION(optimize_ephemerons, parallel_ephemeron_visiting)
787787

788788
DEFINE_BOOL(clear_free_memory, true, "initialize free memory with 0")
789789

790+
DEFINE_BOOL(young_generation_large_objects, false,
791+
"allocates large objects by default in the young generation large "
792+
"object space")
793+
790794
// assembler-ia32.cc / assembler-arm.cc / assembler-x64.cc
791795
DEFINE_BOOL(debug_code, DEBUG_BOOL,
792796
"generate extra code (assertions) for debugging")

src/globals.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ class MapSpace;
536536
class MarkCompactCollector;
537537
class MaybeObject;
538538
class NewSpace;
539+
class NewLargeObjectSpace;
539540
class Object;
540541
class OldSpace;
541542
class ParameterCount;
@@ -570,14 +571,16 @@ typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
570571
enum AllocationSpace {
571572
// TODO(v8:7464): Actually map this space's memory as read-only.
572573
RO_SPACE, // Immortal, immovable and immutable objects,
573-
NEW_SPACE, // Semispaces collected with copying collector.
574-
OLD_SPACE, // May contain pointers to new space.
575-
CODE_SPACE, // No pointers to new space, marked executable.
576-
MAP_SPACE, // Only and all map objects.
577-
LO_SPACE, // Promoted large objects.
574+
NEW_SPACE, // Young generation semispaces for regular objects collected with
575+
// Scavenger.
576+
OLD_SPACE, // Old generation regular object space.
577+
CODE_SPACE, // Old generation code object space, marked executable.
578+
MAP_SPACE, // Old generation map object space, non-movable.
579+
LO_SPACE, // Old generation large object space.
580+
NEW_LO_SPACE, // Young generation large object space.
578581

579582
FIRST_SPACE = RO_SPACE,
580-
LAST_SPACE = LO_SPACE,
583+
LAST_SPACE = NEW_LO_SPACE,
581584
FIRST_GROWABLE_PAGED_SPACE = OLD_SPACE,
582585
LAST_GROWABLE_PAGED_SPACE = MAP_SPACE
583586
};

src/heap/heap-inl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space,
183183
}
184184
} else if (LO_SPACE == space) {
185185
DCHECK(large_object);
186-
allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE);
186+
if (FLAG_young_generation_large_objects) {
187+
allocation = new_lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE);
188+
} else {
189+
allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE);
190+
}
187191
} else if (MAP_SPACE == space) {
188192
allocation = map_space_->AllocateRawUnaligned(size_in_bytes);
189193
} else if (RO_SPACE == space) {

src/heap/heap.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Heap::Heap()
165165
code_space_(nullptr),
166166
map_space_(nullptr),
167167
lo_space_(nullptr),
168+
new_lo_space_(nullptr),
168169
read_only_space_(nullptr),
169170
write_protect_code_memory_(false),
170171
code_space_memory_modification_scope_depth_(0),
@@ -673,6 +674,8 @@ const char* Heap::GetSpaceName(int idx) {
673674
return "code_space";
674675
case LO_SPACE:
675676
return "large_object_space";
677+
case NEW_LO_SPACE:
678+
return "new_large_object_space";
676679
case RO_SPACE:
677680
return "read_only_space";
678681
default:
@@ -3646,6 +3649,8 @@ bool Heap::InSpace(HeapObject* value, AllocationSpace space) {
36463649
return map_space_->Contains(value);
36473650
case LO_SPACE:
36483651
return lo_space_->Contains(value);
3652+
case NEW_LO_SPACE:
3653+
return new_lo_space_->Contains(value);
36493654
case RO_SPACE:
36503655
return read_only_space_->Contains(value);
36513656
}
@@ -3669,20 +3674,22 @@ bool Heap::InSpaceSlow(Address addr, AllocationSpace space) {
36693674
return map_space_->ContainsSlow(addr);
36703675
case LO_SPACE:
36713676
return lo_space_->ContainsSlow(addr);
3677+
case NEW_LO_SPACE:
3678+
return new_lo_space_->ContainsSlow(addr);
36723679
case RO_SPACE:
36733680
return read_only_space_->ContainsSlow(addr);
36743681
}
36753682
UNREACHABLE();
36763683
}
36773684

3678-
36793685
bool Heap::IsValidAllocationSpace(AllocationSpace space) {
36803686
switch (space) {
36813687
case NEW_SPACE:
36823688
case OLD_SPACE:
36833689
case CODE_SPACE:
36843690
case MAP_SPACE:
36853691
case LO_SPACE:
3692+
case NEW_LO_SPACE:
36863693
case RO_SPACE:
36873694
return true;
36883695
default:
@@ -4591,6 +4598,7 @@ void Heap::SetUp() {
45914598
space_[CODE_SPACE] = code_space_ = new CodeSpace(this);
45924599
space_[MAP_SPACE] = map_space_ = new MapSpace(this);
45934600
space_[LO_SPACE] = lo_space_ = new LargeObjectSpace(this);
4601+
space_[NEW_LO_SPACE] = new_lo_space_ = new NewLargeObjectSpace(this);
45944602

45954603
// Set up the seed that is used to randomize the string hash function.
45964604
DCHECK_EQ(Smi::kZero, hash_seed());
@@ -5525,6 +5533,8 @@ const char* AllocationSpaceName(AllocationSpace space) {
55255533
return "MAP_SPACE";
55265534
case LO_SPACE:
55275535
return "LO_SPACE";
5536+
case NEW_LO_SPACE:
5537+
return "NEW_LO_SPACE";
55285538
case RO_SPACE:
55295539
return "RO_SPACE";
55305540
default:
@@ -5598,6 +5608,7 @@ bool Heap::AllowedToBeMigrated(HeapObject* obj, AllocationSpace dst) {
55985608
return dst == CODE_SPACE && type == CODE_TYPE;
55995609
case MAP_SPACE:
56005610
case LO_SPACE:
5611+
case NEW_LO_SPACE:
56015612
case RO_SPACE:
56025613
return false;
56035614
}

src/heap/heap.h

+2
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ class Heap {
10161016
CodeSpace* code_space() { return code_space_; }
10171017
MapSpace* map_space() { return map_space_; }
10181018
LargeObjectSpace* lo_space() { return lo_space_; }
1019+
NewLargeObjectSpace* new_lo_space() { return new_lo_space_; }
10191020
ReadOnlySpace* read_only_space() { return read_only_space_; }
10201021

10211022
inline PagedSpace* paged_space(int idx);
@@ -2294,6 +2295,7 @@ class Heap {
22942295
CodeSpace* code_space_;
22952296
MapSpace* map_space_;
22962297
LargeObjectSpace* lo_space_;
2298+
NewLargeObjectSpace* new_lo_space_;
22972299
ReadOnlySpace* read_only_space_;
22982300
// Map from the space id to the space.
22992301
Space* space_[LAST_SPACE + 1];

src/heap/spaces.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,10 @@ HeapObject* LargeObjectIterator::Next() {
33403340
// LargeObjectSpace
33413341

33423342
LargeObjectSpace::LargeObjectSpace(Heap* heap)
3343-
: Space(heap, LO_SPACE), // Managed on a per-allocation basis
3343+
: LargeObjectSpace(heap, LO_SPACE) {}
3344+
3345+
LargeObjectSpace::LargeObjectSpace(Heap* heap, AllocationSpace id)
3346+
: Space(heap, id),
33443347
size_(0),
33453348
page_count_(0),
33463349
objects_size_(0),
@@ -3651,5 +3654,13 @@ void Page::Print() {
36513654
}
36523655

36533656
#endif // DEBUG
3657+
3658+
NewLargeObjectSpace::NewLargeObjectSpace(Heap* heap)
3659+
: LargeObjectSpace(heap, NEW_LO_SPACE) {}
3660+
3661+
size_t NewLargeObjectSpace::Available() {
3662+
// TODO(hpayer): Update as soon as we have a growing strategy.
3663+
return 0;
3664+
}
36543665
} // namespace internal
36553666
} // namespace v8

src/heap/spaces.h

+9
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,8 @@ class LargeObjectSpace : public Space {
29412941
typedef LargePageIterator iterator;
29422942

29432943
explicit LargeObjectSpace(Heap* heap);
2944+
LargeObjectSpace(Heap* heap, AllocationSpace id);
2945+
29442946
~LargeObjectSpace() override { TearDown(); }
29452947

29462948
// Releases internal resources, frees objects in this space.
@@ -3034,6 +3036,13 @@ class LargeObjectSpace : public Space {
30343036
friend class LargeObjectIterator;
30353037
};
30363038

3039+
class NewLargeObjectSpace : public LargeObjectSpace {
3040+
public:
3041+
explicit NewLargeObjectSpace(Heap* heap);
3042+
3043+
// Available bytes for objects in this space.
3044+
size_t Available() override;
3045+
};
30373046

30383047
class LargeObjectIterator : public ObjectIterator {
30393048
public:

src/snapshot/serializer-common.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ class SerializerDeserializer : public RootVisitor {
105105
// No reservation for large object space necessary.
106106
// We also handle map space differenly.
107107
STATIC_ASSERT(MAP_SPACE == CODE_SPACE + 1);
108+
109+
// We do not support young generation large objects.
110+
STATIC_ASSERT(LAST_SPACE == NEW_LO_SPACE);
111+
STATIC_ASSERT(LAST_SPACE - 1 == LO_SPACE);
108112
static const int kNumberOfPreallocatedSpaces = CODE_SPACE + 1;
109-
static const int kNumberOfSpaces = LAST_SPACE + 1;
113+
static const int kNumberOfSpaces = LO_SPACE + 1;
110114

111115
protected:
112116
static bool CanBeDeferred(HeapObject* o);

src/snapshot/serializer.cc

+1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeObject() {
647647
Map* map = object_->map();
648648
AllocationSpace space =
649649
MemoryChunk::FromAddress(object_->address())->owner()->identity();
650+
DCHECK(space != NEW_LO_SPACE);
650651
SerializePrologue(space, size, map);
651652

652653
// Serialize the rest of the object.

test/cctest/heap/test-heap.cc

+12
Original file line numberDiff line numberDiff line change
@@ -5656,6 +5656,18 @@ TEST(Regress618958) {
56565656
!heap->incremental_marking()->IsStopped()));
56575657
}
56585658

5659+
TEST(YoungGenerationLargeObjectAllocation) {
5660+
FLAG_young_generation_large_objects = true;
5661+
CcTest::InitializeVM();
5662+
v8::HandleScope scope(CcTest::isolate());
5663+
Heap* heap = CcTest::heap();
5664+
Isolate* isolate = heap->isolate();
5665+
5666+
Handle<FixedArray> array = isolate->factory()->NewFixedArray(200000);
5667+
MemoryChunk* chunk = MemoryChunk::FromAddress(array->address());
5668+
CHECK(chunk->owner()->identity() == NEW_LO_SPACE);
5669+
}
5670+
56595671
TEST(UncommitUnusedLargeObjectMemory) {
56605672
CcTest::InitializeVM();
56615673
v8::HandleScope scope(CcTest::isolate());

test/cctest/test-api.cc

+3
Original file line numberDiff line numberDiff line change
@@ -18922,6 +18922,9 @@ TEST(GetHeapSpaceStatistics) {
1892218922
v8::HeapSpaceStatistics space_statistics;
1892318923
isolate->GetHeapSpaceStatistics(&space_statistics, i);
1892418924
CHECK_NOT_NULL(space_statistics.space_name());
18925+
if (strcmp(space_statistics.space_name(), "new_large_object_space") == 0) {
18926+
continue;
18927+
}
1892518928
CHECK_GT(space_statistics.space_size(), 0u);
1892618929
total_size += space_statistics.space_size();
1892718930
CHECK_GT(space_statistics.space_used_size(), 0u);

0 commit comments

Comments
 (0)