[heap] Read gc_state() only once for DCHECK

That DCHECK could fail even though GC was in the right state. It could
happen that the first load gets the old value NOT_IN_GC, since this
isn't TEAR_DOWN a second load needs to be performed. The load then
returns TEAR_DOWN but that doesn't match NOT_IN_GC either.

Fix this by only loading gc_state() once.

Bug: v8:10315
Change-Id: Ibcad540fa4d5f578c9936c472b294bbccebdc09a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2418719
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70021}
This commit is contained in:
Dominik Inführ 2020-09-19 00:02:59 +02:00 committed by Commit Bot
parent 3cb8b399fe
commit aec2874d99

View File

@ -15,13 +15,15 @@ namespace internal {
AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
AllocationOrigin origin,
AllocationAlignment alignment) {
#if DEBUG
DCHECK_EQ(LocalHeap::Current(), this);
DCHECK(AllowHandleAllocation::IsAllowed());
DCHECK(AllowHeapAllocation::IsAllowed());
DCHECK_IMPLIES(type == AllocationType::kCode,
alignment == AllocationAlignment::kCodeAligned);
DCHECK(heap()->gc_state() == Heap::TEAR_DOWN ||
heap()->gc_state() == Heap::NOT_IN_GC);
Heap::HeapState state = heap()->gc_state();
DCHECK(state == Heap::TEAR_DOWN || state == Heap::NOT_IN_GC);
#endif
bool large_object = size_in_bytes > kMaxRegularHeapObjectSize;
CHECK_EQ(type, AllocationType::kOld);