Skip to content
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

[deps] V8: cherry-pick 71736859756b2bd0444bdb0a87a #35205

Closed
wants to merge 4 commits into from
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
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.40',
'v8_embedder_string': '-node.41',

##### V8 defaults for Node.js #####

Expand Down
14 changes: 10 additions & 4 deletions deps/v8/src/heap/heap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ 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 @@ -200,10 +206,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 @@ -1262,8 +1262,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
32 changes: 32 additions & 0 deletions deps/v8/test/cctest/heap/test-heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6754,6 +6754,38 @@ TEST(CodeObjectRegistry) {
CHECK(MemoryChunk::FromAddress(code2_address)->Contains(code2_address));
}

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::kWordAligned);

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