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

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

Issue 10209026: Make sure idle notifications perform a round of incremental GCs after context disposal. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test Created 8 years, 8 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 | « src/heap.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-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 87860f430fcf907281c1218018615b7f5778d96d..2cdc653aea494185d19eb49397a53395b7df16c3 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13995,75 +13995,104 @@ TEST(SourceURLInStackTrace) {
}
+static void CreateGarbageInOldSpace() {
+ v8::HandleScope scope;
+ i::AlwaysAllocateScope always_allocate;
+ for (int i = 0; i < 1000; i++) {
+ FACTORY->NewFixedArray(1000, i::TENURED);
+ }
+}
+
// 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.
-THREADED_TEST(IdleNotification) {
+TEST(IdleNotification) {
+ const intptr_t MB = 1024 * 1024;
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);
- }
- }
- bool finshed_idle_work = false;
- for (int i = 0; i < 100 && !finshed_idle_work; i++) {
- finshed_idle_work = v8::V8::IdleNotification();
+ intptr_t initial_size = HEAP->SizeOfObjects();
+ CreateGarbageInOldSpace();
+ intptr_t size_with_garbage = HEAP->SizeOfObjects();
+ CHECK_GT(size_with_garbage, initial_size + MB);
+ bool finished = false;
+ for (int i = 0; i < 200 && !finished; i++) {
+ finished = v8::V8::IdleNotification();
}
- CHECK(finshed_idle_work);
+ intptr_t final_size = HEAP->SizeOfObjects();
+ CHECK(finished);
+ CHECK_LT(final_size, initial_size + 1);
}
-// 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 that idle notification can be handled and eventually collects garbage.
TEST(IdleNotificationWithSmallHint) {
+ const intptr_t MB = 1024 * 1024;
+ const int IdlePauseInMs = 900;
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(10);
- for (int i = 0; i < 200 && !finshed_idle_work; i++) {
- finshed_idle_work = v8::V8::IdleNotification(10);
+ intptr_t initial_size = HEAP->SizeOfObjects();
+ CreateGarbageInOldSpace();
+ intptr_t size_with_garbage = HEAP->SizeOfObjects();
+ CHECK_GT(size_with_garbage, initial_size + MB);
+ bool finished = false;
+ for (int i = 0; i < 200 && !finished; i++) {
+ finished = v8::V8::IdleNotification(IdlePauseInMs);
}
- intptr_t new_size = HEAP->SizeOfObjects();
- CHECK(finshed_idle_work);
- CHECK(no_idle_work || new_size < old_size);
+ intptr_t final_size = HEAP->SizeOfObjects();
+ CHECK(finished);
+ CHECK_LT(final_size, initial_size + 1);
}
-// This just checks the contract of the IdleNotification() function,
-// and does not verify that it does reasonable work.
+// Test that idle notification can be handled and eventually collects garbage.
TEST(IdleNotificationWithLargeHint) {
+ const intptr_t MB = 1024 * 1024;
+ const int IdlePauseInMs = 900;
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 initial_size = HEAP->SizeOfObjects();
+ CreateGarbageInOldSpace();
+ intptr_t size_with_garbage = HEAP->SizeOfObjects();
+ CHECK_GT(size_with_garbage, initial_size + MB);
+ bool finished = false;
+ for (int i = 0; i < 200 && !finished; i++) {
+ finished = v8::V8::IdleNotification(IdlePauseInMs);
}
- intptr_t new_size = HEAP->SizeOfObjects();
- CHECK(finshed_idle_work);
- CHECK(no_idle_work || new_size < old_size);
+ intptr_t final_size = HEAP->SizeOfObjects();
+ CHECK(finished);
+ CHECK_LT(final_size, initial_size + 1);
}
+TEST(Regress2107) {
+ const intptr_t MB = 1024 * 1024;
+ const int kShortIdlePauseInMs = 100;
+ const int kLongIdlePauseInMs = 1000;
+ v8::HandleScope scope;
+ LocalContext env;
+ intptr_t initial_size = HEAP->SizeOfObjects();
+ // Send idle notification to start a round of incremental GCs.
+ v8::V8::IdleNotification(kShortIdlePauseInMs);
+ // Emulate 7 page reloads.
+ for (int i = 0; i < 7; i++) {
+ v8::Persistent<v8::Context> ctx = v8::Context::New();
+ ctx->Enter();
+ CreateGarbageInOldSpace();
+ ctx->Exit();
+ ctx.Dispose();
+ v8::V8::ContextDisposedNotification();
+ v8::V8::IdleNotification(kLongIdlePauseInMs);
+ }
+ // Create garbage and check that idle notification still collects it.
+ CreateGarbageInOldSpace();
+ intptr_t size_with_garbage = HEAP->SizeOfObjects();
+ CHECK_GT(size_with_garbage, initial_size + MB);
+ bool finished = false;
+ for (int i = 0; i < 200 && !finished; i++) {
+ finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
+ }
+ intptr_t final_size = HEAP->SizeOfObjects();
+ CHECK_LT(final_size, initial_size + 1);
+}
+
static uint32_t* stack_limit;
static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) {
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698