Skip to content

[v14.x backport] [deps] V8: cherry-pick 71736859756b2bd0444bdb0a87a #36074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions deps/v8/src/heap/heap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationType type,
IncrementObjectCounters();
#endif

bool large_object = size_in_bytes > kMaxRegularHeapObjectSize;
size_t large_object_threshold =
AllocationType::kCode == type
? std::min(kMaxRegularHeapObjectSize, code_space()->AreaSize())
: kMaxRegularHeapObjectSize;
bool large_object =
static_cast<size_t>(size_in_bytes) > large_object_threshold;

HeapObject object;
AllocationResult allocation;
Expand Down Expand Up @@ -225,10 +230,10 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationType type,
allocation = old_space_->AllocateRaw(size_in_bytes, alignment, origin);
}
} else if (AllocationType::kCode == type) {
if (size_in_bytes <= code_space()->AreaSize() && !large_object) {
allocation = code_space_->AllocateRawUnaligned(size_in_bytes);
} else {
if (large_object) {
allocation = code_lo_space_->AllocateRaw(size_in_bytes);
} else {
allocation = code_space_->AllocateRawUnaligned(size_in_bytes);
}
} else if (AllocationType::kMap == type) {
allocation = map_space_->AllocateRawUnaligned(size_in_bytes);
Expand Down
6 changes: 4 additions & 2 deletions deps/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1404,8 +1404,10 @@ class Heap {
// Heap object allocation tracking. ==========================================
// ===========================================================================

void AddHeapObjectAllocationTracker(HeapObjectAllocationTracker* tracker);
void RemoveHeapObjectAllocationTracker(HeapObjectAllocationTracker* tracker);
V8_EXPORT_PRIVATE void AddHeapObjectAllocationTracker(
HeapObjectAllocationTracker* tracker);
V8_EXPORT_PRIVATE void RemoveHeapObjectAllocationTracker(
HeapObjectAllocationTracker* tracker);
bool has_heap_object_allocation_tracker() const {
return !allocation_trackers_.empty();
}
Expand Down
1 change: 1 addition & 0 deletions deps/v8/test/cctest/heap/heap-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Tests that should have access to private methods of {v8::internal::Heap}.
// Those tests need to be defined using HEAP_TEST(Name) { ... }.
#define HEAP_TEST_METHODS(V) \
V(CodeLargeObjectSpace) \
V(CompactionFullAbortedPage) \
V(CompactionPartiallyAbortedPage) \
V(CompactionPartiallyAbortedPageIntraAbortedPointers) \
Expand Down
69 changes: 69 additions & 0 deletions deps/v8/test/cctest/heap/test-heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7002,6 +7002,75 @@ TEST(Regress978156) {
marking_state->GreyToBlack(filler);
}

TEST(GarbageCollectionWithLocalHeap) {
FLAG_local_heaps = true;
ManualGCScope manual_gc_scope;
CcTest::InitializeVM();

Heap* heap = CcTest::i_isolate()->heap();

LocalHeap local_heap(heap);
CcTest::CollectGarbage(OLD_SPACE);
{ ParkedScope parked_scope(&local_heap); }
CcTest::CollectGarbage(OLD_SPACE);
}

TEST(Regress10698) {
ManualGCScope manual_gc_scope;
CcTest::InitializeVM();
Heap* heap = CcTest::i_isolate()->heap();
Factory* factory = CcTest::i_isolate()->factory();
HandleScope handle_scope(CcTest::i_isolate());
// This is modeled after the manual allocation folding of heap numbers in
// JSON parser (See commit ba7b25e).
// Step 1. Allocate a byte array in the old space.
Handle<ByteArray> array =
factory->NewByteArray(kTaggedSize, AllocationType::kOld);
// Step 2. Start incremental marking.
SimulateIncrementalMarking(heap, false);
// Step 3. Allocate another byte array. It will be black.
factory->NewByteArray(kTaggedSize, AllocationType::kOld);
Address address = reinterpret_cast<Address>(array->GetDataStartAddress());
HeapObject filler = HeapObject::FromAddress(address);
// Step 4. Set the filler at the end of the first array.
// It will have an impossible markbit pattern because the second markbit
// will be taken from the second array.
filler.set_map_after_allocation(*factory->one_pointer_filler_map());
}
Comment on lines +7005 to +7039
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure if v8-ci will be happy with this tests, but if It's not, I can remove them.

BTW: If you can tell me how to run the v8 test suite, It'd awesome.


class TestAllocationTracker : public HeapObjectAllocationTracker {
public:
explicit TestAllocationTracker(int expected_size)
: expected_size_(expected_size) {}

void AllocationEvent(Address addr, int size) {
CHECK(expected_size_ == size);
address_ = addr;
}

Address address() { return address_; }

private:
int expected_size_;
Address address_;
};

HEAP_TEST(CodeLargeObjectSpace) {
Heap* heap = CcTest::heap();
int size_in_bytes = kMaxRegularHeapObjectSize + kSystemPointerSize;
TestAllocationTracker allocation_tracker{size_in_bytes};
heap->AddHeapObjectAllocationTracker(&allocation_tracker);

AllocationResult allocation = heap->AllocateRaw(
size_in_bytes, AllocationType::kCode, AllocationOrigin::kGeneratedCode,
AllocationAlignment::kCodeAligned);

CHECK(allocation.ToObjectChecked().address() == allocation_tracker.address());
heap->CreateFillerObjectAt(allocation.ToObjectChecked().address(),
size_in_bytes, ClearRecordedSlots::kNo);
heap->RemoveHeapObjectAllocationTracker(&allocation_tracker);
}

} // namespace heap
} // namespace internal
} // namespace v8
Expand Down