From bc7e01534d924ff68acfa0702bf54ed0cb903087 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Wed, 15 Feb 2012 15:42:50 +0000 Subject: [PATCH] Cleanup idle notification tests. R=ulan@chromium.org TEST=cctest/test-api/IdleNotification Review URL: https://chromiumcodereview.appspot.com/9403014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10713 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/cctest/test-api.cc | 81 ++++++++++++++++++++++------------------ test/cctest/test-heap.cc | 29 -------------- 2 files changed, 44 insertions(+), 66 deletions(-) diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 87d5453756..c91e4f95b3 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -13711,58 +13711,65 @@ TEST(SourceURLInStackTrace) { THREADED_TEST(IdleNotification) { v8::HandleScope scope; LocalContext env; - CompileRun("function binom(n, m) {" - " var C = [[1]];" - " for (var i = 1; i <= n; ++i) {" - " C[i] = [1];" - " for (var j = 1; j < i; ++j) {" - " C[i][j] = C[i-1][j-1] + C[i-1][j];" - " }" - " C[i][i] = 1;" - " }" - " return C[n][m];" - "};" - "binom(1000, 500)"); - bool rv = false; - for (int i = 0; i < 100; i++) { - rv = v8::V8::IdleNotification(); - if (rv) - break; + { + // Create garbage in old-space to generate work for idle notification. + i::AlwaysAllocateScope always_allocate; + for (int i = 0; i < 100; i++) { + FACTORY->NewFixedArray(1000, i::TENURED); + } } - CHECK(rv == true); + bool finshed_idle_work = false; + for (int i = 0; i < 100 && !finshed_idle_work; i++) { + finshed_idle_work = v8::V8::IdleNotification(); + } + CHECK(finshed_idle_work); } // Test that idle notification can be handled and eventually returns true. // This just checks the contract of the IdleNotification() function, // and does not verify that it does reasonable work. -TEST(IdleNotificationWithHint) { +TEST(IdleNotificationWithSmallHint) { v8::HandleScope scope; LocalContext env; { + // Create garbage in old-space to generate work for idle notification. i::AlwaysAllocateScope always_allocate; - CompileRun("function binom(n, m) {" - " var C = [[1]];" - " for (var i = 1; i <= n; ++i) {" - " C[i] = [1];" - " for (var j = 1; j < i; ++j) {" - " C[i][j] = C[i-1][j-1] + C[i-1][j];" - " }" - " C[i][i] = 1;" - " }" - " return C[n][m];" - "};" - "binom(1000, 500)"); + for (int i = 0; i < 100; i++) { + FACTORY->NewFixedArray(1000, i::TENURED); + } } - bool rv = false; intptr_t old_size = HEAP->SizeOfObjects(); + bool finshed_idle_work = false; bool no_idle_work = v8::V8::IdleNotification(10); - for (int i = 0; i < 200; i++) { - rv = v8::V8::IdleNotification(10); - if (rv) - break; + for (int i = 0; i < 200 && !finshed_idle_work; i++) { + finshed_idle_work = v8::V8::IdleNotification(10); } - CHECK(rv == true); intptr_t new_size = HEAP->SizeOfObjects(); + CHECK(finshed_idle_work); + CHECK(no_idle_work || new_size < old_size); +} + + +// This just checks the contract of the IdleNotification() function, +// and does not verify that it does reasonable work. +TEST(IdleNotificationWithLargeHint) { + v8::HandleScope scope; + LocalContext env; + { + // Create garbage in old-space to generate work for idle notification. + i::AlwaysAllocateScope always_allocate; + for (int i = 0; i < 100; i++) { + FACTORY->NewFixedArray(1000, i::TENURED); + } + } + intptr_t old_size = HEAP->SizeOfObjects(); + bool finshed_idle_work = false; + bool no_idle_work = v8::V8::IdleNotification(900); + for (int i = 0; i < 200 && !finshed_idle_work; i++) { + finshed_idle_work = v8::V8::IdleNotification(900); + } + intptr_t new_size = HEAP->SizeOfObjects(); + CHECK(finshed_idle_work); CHECK(no_idle_work || new_size < old_size); } diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index a4d4be4816..a6dd83054b 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -1328,35 +1328,6 @@ TEST(CollectingAllAvailableGarbageShrinksNewSpace) { CHECK(old_capacity == new_capacity); } -// This just checks the contract of the IdleNotification() function, -// and does not verify that it does reasonable work. -TEST(IdleNotificationAdvancesIncrementalMarking) { - if (!FLAG_incremental_marking || !FLAG_incremental_marking_steps) return; - InitializeVM(); - v8::HandleScope scope; - const char* source = "function binom(n, m) {" - " var C = [[1]];" - " for (var i = 1; i <= n; ++i) {" - " C[i] = [1];" - " for (var j = 1; j < i; ++j) {" - " C[i][j] = C[i-1][j-1] + C[i-1][j];" - " }" - " C[i][i] = 1;" - " }" - " return C[n][m];" - "};" - "binom(1000, 500)"; - { - AlwaysAllocateScope aa_scope; - CompileRun(source); - } - intptr_t old_size = HEAP->SizeOfObjects(); - bool no_idle_work = v8::V8::IdleNotification(900); - while (!v8::V8::IdleNotification(900)) ; - intptr_t new_size = HEAP->SizeOfObjects(); - CHECK(no_idle_work || new_size < old_size); -} - static int NumberOfGlobalObjects() { int count = 0;