Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1755)

Unified Diff: test/cctest/test-heap.cc

Issue 640303006: Weak Cells (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/objects-inl.h ('K') | « src/serialize.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index ee476db6cdc4729b1a65a560fe03734a65f2bfdb..193b617ee8f44fb01cc800a02b8d352ea52a4d71 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -4241,6 +4241,61 @@ TEST(WeakMapInMonomorphicCompareNilIC) {
}
+TEST(WeakCell) {
+ CcTest::InitializeVM();
+ Isolate* isolate = CcTest::i_isolate();
+ v8::internal::Heap* heap = CcTest::heap();
+ v8::internal::Factory* factory = isolate->factory();
+
+ HandleScope outer_scope(isolate);
+ Handle<WeakCell> weak_cell;
+ {
+ HandleScope inner_scope(isolate);
+ Handle<HeapObject> value = factory->NewFixedArray(1, NOT_TENURED);
+ weak_cell = inner_scope.CloseAndEscape(factory->NewWeakCell(value));
+ }
+ CHECK(weak_cell->value()->IsFixedArray());
+ heap->CollectGarbage(NEW_SPACE);
+ CHECK(weak_cell->value()->IsFixedArray());
+ heap->CollectGarbage(NEW_SPACE);
+ CHECK(weak_cell->value()->IsFixedArray());
+ heap->CollectAllAvailableGarbage();
Erik Corry 2014/10/13 15:56:17 The tests should also test that the weak cell is u
ulan 2014/10/14 10:17:22 Done.
+ CHECK(weak_cell->value()->IsUndefined());
+}
+
+
+TEST(WeakCellsWithIncrementalMarking) {
+ CcTest::InitializeVM();
+ Isolate* isolate = CcTest::i_isolate();
+ v8::internal::Heap* heap = CcTest::heap();
+ v8::internal::Factory* factory = isolate->factory();
+
+ const int N = 16;
+ HandleScope outer_scope(isolate);
+ Handle<FixedArray> survivor = factory->NewFixedArray(1, NOT_TENURED);
+ Handle<WeakCell> weak_cells[N];
+
+ for (int i = 0; i < N; i++) {
+ HandleScope inner_scope(isolate);
+ Handle<HeapObject> value =
+ i == 0 ? survivor : factory->NewFixedArray(1, NOT_TENURED);
+ Handle<WeakCell> weak_cell = factory->NewWeakCell(value);
+ CHECK(weak_cell->value()->IsFixedArray());
+ IncrementalMarking* marking = heap->incremental_marking();
+ if (marking->IsStopped()) marking->Start();
+ marking->Step(128, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
+ heap->CollectGarbage(NEW_SPACE);
+ CHECK(weak_cell->value()->IsFixedArray());
+ weak_cells[i] = inner_scope.CloseAndEscape(weak_cell);
+ }
+ heap->CollectAllGarbage(Heap::kNoGCFlags);
+ CHECK_EQ(*survivor, weak_cells[0]->value());
+ for (int i = 1; i < N; i++) {
+ CHECK(weak_cells[i]->value()->IsUndefined());
+ }
+}
+
+
#ifdef DEBUG
TEST(AddInstructionChangesNewSpacePromotion) {
i::FLAG_allow_natives_syntax = true;
« src/objects-inl.h ('K') | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698