Index: test/cctest/heap/test-array-buffer-tracker.cc |
diff --git a/test/cctest/heap/test-array-buffer-tracker.cc b/test/cctest/heap/test-array-buffer-tracker.cc |
index b331f6bf3a5a8a3eee261e14449ccf96a57a8ecc..d20798bdf31692a47d1f8a537a9d94f3ece3d77d 100644 |
--- a/test/cctest/heap/test-array-buffer-tracker.cc |
+++ b/test/cctest/heap/test-array-buffer-tracker.cc |
@@ -314,5 +314,65 @@ UNINITIALIZED_TEST(ArrayBuffer_SemiSpaceCopyMultipleTasks) { |
} |
} |
+TEST(ArrayBuffer_RetainedCounterPromotion) { |
+ // The test checks that retained counters on ArrayBufferTracker are consistent |
+ // with where the buffers are on the heap. |
+ CcTest::InitializeVM(); |
+ LocalContext env; |
+ v8::Isolate* isolate = env->GetIsolate(); |
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap(); |
+ ArrayBufferTracker* tracker = heap->array_buffer_tracker(); |
+ { |
+ v8::HandleScope handle_scope(isolate); |
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 100); |
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); |
+ CHECK(heap->InNewSpace(*buf)); |
+ CHECK_EQ(tracker->retained_from_new_space(), 100u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 0u); |
+ heap::GcAndSweep(heap, OLD_SPACE); |
+ CHECK(heap->InNewSpace(*buf)); |
+ CHECK_EQ(tracker->retained_from_new_space(), 100u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 0u); |
+ heap::GcAndSweep(heap, OLD_SPACE); |
+ CHECK(heap->InOldSpace(*buf)); |
+ CHECK_EQ(tracker->retained_from_new_space(), 0u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 100u); |
+ } |
+} |
+ |
+TEST(ArrayBuffer_RetainedCounterNewSpace) { |
+ // The test checks that retained counters on ArrayBufferTracker are consistent |
+ // with where the buffers are on the heap. |
+ CcTest::InitializeVM(); |
+ LocalContext env; |
+ v8::Isolate* isolate = env->GetIsolate(); |
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap(); |
+ ArrayBufferTracker* tracker = heap->array_buffer_tracker(); |
+ { |
+ v8::HandleScope handle_scope(isolate); |
+ { |
+ v8::HandleScope tmp_scope(isolate); |
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 100); |
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); |
+ CHECK(heap->InNewSpace(*buf)); |
+ } |
+ { |
+ v8::HandleScope tmp_scope(isolate); |
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 50); |
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); |
+ CHECK(heap->InNewSpace(*buf)); |
+ CHECK_EQ(tracker->retained_from_new_space(), 150u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 0u); |
+ heap::GcAndSweep(heap, NEW_SPACE); |
+ CHECK(heap->InNewSpace(*buf)); |
+ CHECK_EQ(tracker->retained_from_new_space(), 50u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 0u); |
+ } |
+ heap::GcAndSweep(heap, NEW_SPACE); |
+ CHECK_EQ(tracker->retained_from_new_space(), 0u); |
+ CHECK_EQ(tracker->retained_from_old_space(), 0u); |
+ } |
+} |
+ |
} // namespace internal |
} // namespace v8 |