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

Unified Diff: test/cctest/heap/test-array-buffer-tracker.cc

Issue 1936233002: [heap] Fine-grained JSArrayBuffer tracking (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comment Created 4 years, 7 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
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/heap/utils-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..81d98a5a4ebe85184abf6f14677ba6473dd83c94
--- /dev/null
+++ b/test/cctest/heap/test-array-buffer-tracker.cc
@@ -0,0 +1,178 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/heap/array-buffer-tracker.h"
+#include "test/cctest/cctest.h"
+#include "test/cctest/heap/utils-inl.h"
+
+namespace {
+
+typedef i::ArrayBufferTracker Tracker;
+
+void VerifyTrackedInNewSpace(Tracker* tracker, i::JSArrayBuffer* buf) {
+ CHECK(tracker->IsTrackedInYoungGenForTesting(buf));
+ CHECK(!tracker->IsTrackedInOldGenForTesting(buf));
+}
+
+void VerifyTrackedInOldSpace(Tracker* tracker, i::JSArrayBuffer* buf) {
+ CHECK(!tracker->IsTrackedInYoungGenForTesting(buf));
+ CHECK(tracker->IsTrackedInOldGenForTesting(buf));
+}
+
+void VerifyUntracked(Tracker* tracker, i::JSArrayBuffer* buf) {
+ CHECK(!tracker->IsTrackedInYoungGenForTesting(buf));
+ CHECK(!tracker->IsTrackedInOldGenForTesting(buf));
+}
+
+} // namespace
+
+namespace v8 {
+namespace internal {
+
+// The following tests make sure that JSArrayBuffer tracking works expected when
+// moving the objects through various spaces during GC phases.
+
+TEST(ArrayBuffer_OnlyMC) {
+ CcTest::InitializeVM();
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap();
+ Tracker* tracker = heap->array_buffer_tracker();
+
+ JSArrayBuffer* raw_ab = nullptr;
+ {
+ v8::HandleScope handle_scope(isolate);
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(OLD_SPACE);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(OLD_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ raw_ab = *buf;
+ }
+ heap->CollectGarbage(OLD_SPACE);
+ VerifyUntracked(tracker, raw_ab);
+}
+
+TEST(ArrayBuffer_OnlyScavenge) {
+ CcTest::InitializeVM();
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap();
+ Tracker* tracker = heap->array_buffer_tracker();
+
+ JSArrayBuffer* raw_ab = nullptr;
+ {
+ v8::HandleScope handle_scope(isolate);
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ raw_ab = *buf;
+ }
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, raw_ab);
+}
+
+TEST(ArrayBuffer_ScavengeAndMC) {
+ CcTest::InitializeVM();
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap();
+ Tracker* tracker = heap->array_buffer_tracker();
+
+ JSArrayBuffer* raw_ab = nullptr;
+ {
+ v8::HandleScope handle_scope(isolate);
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInNewSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ heap->CollectGarbage(OLD_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf);
+ raw_ab = *buf;
+ }
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, raw_ab);
+ heap->CollectGarbage(OLD_SPACE);
+ VerifyUntracked(tracker, raw_ab);
+}
+
+TEST(ArrayBuffer_IterateNotYetDiscoveredEntries) {
+ CcTest::InitializeVM();
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap();
+ Tracker* tracker = heap->array_buffer_tracker();
+
+ v8::HandleScope handle_scope(isolate);
+ Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf1 = v8::Utils::OpenHandle(*ab1);
+ VerifyTrackedInNewSpace(tracker, *buf1);
+ heap->CollectGarbage(NEW_SPACE);
+ heap->CollectGarbage(NEW_SPACE);
+ VerifyTrackedInOldSpace(tracker, *buf1);
+
+ Local<v8::ArrayBuffer> ab2 = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf2 = v8::Utils::OpenHandle(*ab2);
+ Page* interesting_page = Page::FromAddress(buf2->address());
+ bool found_ab1 = false;
+ bool found_ab2 = false;
+ tracker->IterateNotYetDiscoveredEntries(
+ Tracker::kNewSpace, reinterpret_cast<Tracker::Key>(interesting_page),
+ reinterpret_cast<Tracker::Key>(interesting_page + Page::kPageSize),
+ [buf1, buf2, &found_ab1, &found_ab2](Tracker::Key key) {
+ if (key == buf1->address()) {
+ found_ab1 = true;
+ }
+ if (key == buf2->address()) {
+ found_ab2 = true;
+ }
+ return Tracker::kKeepEntry;
+ });
+ CHECK(!found_ab1);
+ CHECK(found_ab2);
+}
+
+TEST(ArrayBuffer_Compaction) {
+ FLAG_manual_evacuation_candidates_selection = true;
+ CcTest::InitializeVM();
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ Heap* heap = reinterpret_cast<Isolate*>(isolate)->heap();
+ AbandonCurrentlyFreeMemory(heap->old_space());
+ Tracker* tracker = heap->array_buffer_tracker();
+
+ v8::HandleScope handle_scope(isolate);
+ Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(isolate, 100);
+ Handle<JSArrayBuffer> buf1 = v8::Utils::OpenHandle(*ab1);
+ VerifyTrackedInNewSpace(tracker, *buf1);
+ heap->CollectGarbage(NEW_SPACE);
+ heap->CollectGarbage(NEW_SPACE);
+
+ Page* page_before_gc = Page::FromAddress(buf1->address());
+ page_before_gc->SetFlag(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING);
+ VerifyTrackedInOldSpace(tracker, *buf1);
+
+ heap->CollectAllGarbage();
+
+ Page* page_after_gc = Page::FromAddress(buf1->address());
+ VerifyTrackedInOldSpace(tracker, *buf1);
+
+ CHECK_NE(page_before_gc, page_after_gc);
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/heap/utils-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698