Index: test/cctest/heap/test-heap.cc |
diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc |
index d8c83f3b409d7aa7d861b52c8406461869b0e4d0..2992dc186b977e2fdf52ed9c6ecb7c045377c11f 100644 |
--- a/test/cctest/heap/test-heap.cc |
+++ b/test/cctest/heap/test-heap.cc |
@@ -6303,5 +6303,38 @@ HEAP_TEST(Regress5831) { |
CHECK(chunk->NeverEvacuate()); |
} |
+HEAP_TEST(RegressMissingWriteBarrierInAllocate) { |
+ if (!FLAG_incremental_marking) return; |
+ FLAG_black_allocation = true; |
+ CcTest::InitializeVM(); |
+ v8::HandleScope scope(CcTest::isolate()); |
+ Heap* heap = CcTest::heap(); |
+ Isolate* isolate = heap->isolate(); |
+ CcTest::CollectAllGarbage(); |
+ heap::SimulateIncrementalMarking(heap, false); |
+ Map* map; |
+ { |
+ AlwaysAllocateScope always_allocate(isolate); |
+ map = Map::cast(heap->AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize) |
+ .ToObjectChecked()); |
+ } |
+ heap->incremental_marking()->StartBlackAllocationForTesting(); |
+ Handle<HeapObject> object; |
+ { |
+ AlwaysAllocateScope always_allocate(isolate); |
+ object = Handle<HeapObject>( |
+ heap->Allocate(map, OLD_SPACE).ToObjectChecked(), isolate); |
+ } |
+ // The object is black. If Heap::Allocate sets the map without write-barrier, |
+ // then the map is white and will be freed prematurely. |
+ heap::SimulateIncrementalMarking(heap, true); |
+ CcTest::CollectAllGarbage(); |
+ MarkCompactCollector* collector = heap->mark_compact_collector(); |
+ if (collector->sweeping_in_progress()) { |
+ collector->EnsureSweepingCompleted(); |
+ } |
+ CHECK(object->map()->IsMap()); |
+} |
+ |
} // namespace internal |
} // namespace v8 |