OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13988 "\n" | 13988 "\n" |
13989 " bar();\n" | 13989 " bar();\n" |
13990 "}\n" | 13990 "}\n" |
13991 "foo();\n" | 13991 "foo();\n" |
13992 "}\n" | 13992 "}\n" |
13993 "eval('(' + outer +')()//@ sourceURL=eval_url');"; | 13993 "eval('(' + outer +')()//@ sourceURL=eval_url');"; |
13994 CHECK(CompileRun(source)->IsUndefined()); | 13994 CHECK(CompileRun(source)->IsUndefined()); |
13995 } | 13995 } |
13996 | 13996 |
13997 | 13997 |
13998 // Test that idle notification can be handled and eventually returns true. | 13998 static void CreateGarbageInOldSpace() { |
13999 // This just checks the contract of the IdleNotification() function, | |
14000 // and does not verify that it does reasonable work. | |
14001 THREADED_TEST(IdleNotification) { | |
14002 v8::HandleScope scope; | 13999 v8::HandleScope scope; |
14003 LocalContext env; | 14000 i::AlwaysAllocateScope always_allocate; |
14004 { | 14001 for (int i = 0; i < 1000; i++) { |
14005 // Create garbage in old-space to generate work for idle notification. | 14002 FACTORY->NewFixedArray(1000, i::TENURED); |
14006 i::AlwaysAllocateScope always_allocate; | |
14007 for (int i = 0; i < 100; i++) { | |
14008 FACTORY->NewFixedArray(1000, i::TENURED); | |
14009 } | |
14010 } | 14003 } |
14011 bool finshed_idle_work = false; | |
14012 for (int i = 0; i < 100 && !finshed_idle_work; i++) { | |
14013 finshed_idle_work = v8::V8::IdleNotification(); | |
14014 } | |
14015 CHECK(finshed_idle_work); | |
14016 } | 14004 } |
14017 | 14005 |
14018 // Test that idle notification can be handled and eventually returns true. | 14006 // Test that idle notification can be handled and eventually returns true. |
14019 // This just checks the contract of the IdleNotification() function, | 14007 TEST(IdleNotification) { |
14020 // and does not verify that it does reasonable work. | 14008 const intptr_t MB = 1024 * 1024; |
14021 TEST(IdleNotificationWithSmallHint) { | |
14022 v8::HandleScope scope; | 14009 v8::HandleScope scope; |
14023 LocalContext env; | 14010 LocalContext env; |
14024 { | 14011 intptr_t initial_size = HEAP->SizeOfObjects(); |
14025 // Create garbage in old-space to generate work for idle notification. | 14012 CreateGarbageInOldSpace(); |
14026 i::AlwaysAllocateScope always_allocate; | 14013 intptr_t size_with_garbage = HEAP->SizeOfObjects(); |
14027 for (int i = 0; i < 100; i++) { | 14014 CHECK_GT(size_with_garbage, initial_size + MB); |
14028 FACTORY->NewFixedArray(1000, i::TENURED); | 14015 bool finished = false; |
14029 } | 14016 for (int i = 0; i < 200 && !finished; i++) { |
| 14017 finished = v8::V8::IdleNotification(); |
14030 } | 14018 } |
14031 intptr_t old_size = HEAP->SizeOfObjects(); | 14019 intptr_t final_size = HEAP->SizeOfObjects(); |
14032 bool finshed_idle_work = false; | 14020 CHECK(finished); |
14033 bool no_idle_work = v8::V8::IdleNotification(10); | 14021 CHECK_LT(final_size, initial_size + 1); |
14034 for (int i = 0; i < 200 && !finshed_idle_work; i++) { | |
14035 finshed_idle_work = v8::V8::IdleNotification(10); | |
14036 } | |
14037 intptr_t new_size = HEAP->SizeOfObjects(); | |
14038 CHECK(finshed_idle_work); | |
14039 CHECK(no_idle_work || new_size < old_size); | |
14040 } | 14022 } |
14041 | 14023 |
14042 | 14024 |
14043 // This just checks the contract of the IdleNotification() function, | 14025 // Test that idle notification can be handled and eventually collects garbage. |
14044 // and does not verify that it does reasonable work. | 14026 TEST(IdleNotificationWithSmallHint) { |
14045 TEST(IdleNotificationWithLargeHint) { | 14027 const intptr_t MB = 1024 * 1024; |
| 14028 const int IdlePauseInMs = 900; |
14046 v8::HandleScope scope; | 14029 v8::HandleScope scope; |
14047 LocalContext env; | 14030 LocalContext env; |
14048 { | 14031 intptr_t initial_size = HEAP->SizeOfObjects(); |
14049 // Create garbage in old-space to generate work for idle notification. | 14032 CreateGarbageInOldSpace(); |
14050 i::AlwaysAllocateScope always_allocate; | 14033 intptr_t size_with_garbage = HEAP->SizeOfObjects(); |
14051 for (int i = 0; i < 100; i++) { | 14034 CHECK_GT(size_with_garbage, initial_size + MB); |
14052 FACTORY->NewFixedArray(1000, i::TENURED); | 14035 bool finished = false; |
14053 } | 14036 for (int i = 0; i < 200 && !finished; i++) { |
| 14037 finished = v8::V8::IdleNotification(IdlePauseInMs); |
14054 } | 14038 } |
14055 intptr_t old_size = HEAP->SizeOfObjects(); | 14039 intptr_t final_size = HEAP->SizeOfObjects(); |
14056 bool finshed_idle_work = false; | 14040 CHECK(finished); |
14057 bool no_idle_work = v8::V8::IdleNotification(900); | 14041 CHECK_LT(final_size, initial_size + 1); |
14058 for (int i = 0; i < 200 && !finshed_idle_work; i++) { | |
14059 finshed_idle_work = v8::V8::IdleNotification(900); | |
14060 } | |
14061 intptr_t new_size = HEAP->SizeOfObjects(); | |
14062 CHECK(finshed_idle_work); | |
14063 CHECK(no_idle_work || new_size < old_size); | |
14064 } | 14042 } |
14065 | 14043 |
14066 | 14044 |
| 14045 // Test that idle notification can be handled and eventually collects garbage. |
| 14046 TEST(IdleNotificationWithLargeHint) { |
| 14047 const intptr_t MB = 1024 * 1024; |
| 14048 const int IdlePauseInMs = 900; |
| 14049 v8::HandleScope scope; |
| 14050 LocalContext env; |
| 14051 intptr_t initial_size = HEAP->SizeOfObjects(); |
| 14052 CreateGarbageInOldSpace(); |
| 14053 intptr_t size_with_garbage = HEAP->SizeOfObjects(); |
| 14054 CHECK_GT(size_with_garbage, initial_size + MB); |
| 14055 bool finished = false; |
| 14056 for (int i = 0; i < 200 && !finished; i++) { |
| 14057 finished = v8::V8::IdleNotification(IdlePauseInMs); |
| 14058 } |
| 14059 intptr_t final_size = HEAP->SizeOfObjects(); |
| 14060 CHECK(finished); |
| 14061 CHECK_LT(final_size, initial_size + 1); |
| 14062 } |
| 14063 |
| 14064 |
| 14065 TEST(Regress2107) { |
| 14066 const intptr_t MB = 1024 * 1024; |
| 14067 const int kShortIdlePauseInMs = 100; |
| 14068 const int kLongIdlePauseInMs = 1000; |
| 14069 v8::HandleScope scope; |
| 14070 LocalContext env; |
| 14071 intptr_t initial_size = HEAP->SizeOfObjects(); |
| 14072 // Send idle notification to start a round of incremental GCs. |
| 14073 v8::V8::IdleNotification(kShortIdlePauseInMs); |
| 14074 // Emulate 7 page reloads. |
| 14075 for (int i = 0; i < 7; i++) { |
| 14076 v8::Persistent<v8::Context> ctx = v8::Context::New(); |
| 14077 ctx->Enter(); |
| 14078 CreateGarbageInOldSpace(); |
| 14079 ctx->Exit(); |
| 14080 ctx.Dispose(); |
| 14081 v8::V8::ContextDisposedNotification(); |
| 14082 v8::V8::IdleNotification(kLongIdlePauseInMs); |
| 14083 } |
| 14084 // Create garbage and check that idle notification still collects it. |
| 14085 CreateGarbageInOldSpace(); |
| 14086 intptr_t size_with_garbage = HEAP->SizeOfObjects(); |
| 14087 CHECK_GT(size_with_garbage, initial_size + MB); |
| 14088 bool finished = false; |
| 14089 for (int i = 0; i < 200 && !finished; i++) { |
| 14090 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); |
| 14091 } |
| 14092 intptr_t final_size = HEAP->SizeOfObjects(); |
| 14093 CHECK_LT(final_size, initial_size + 1); |
| 14094 } |
| 14095 |
14067 static uint32_t* stack_limit; | 14096 static uint32_t* stack_limit; |
14068 | 14097 |
14069 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { | 14098 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { |
14070 stack_limit = reinterpret_cast<uint32_t*>( | 14099 stack_limit = reinterpret_cast<uint32_t*>( |
14071 i::Isolate::Current()->stack_guard()->real_climit()); | 14100 i::Isolate::Current()->stack_guard()->real_climit()); |
14072 return v8::Undefined(); | 14101 return v8::Undefined(); |
14073 } | 14102 } |
14074 | 14103 |
14075 | 14104 |
14076 // Uses the address of a local variable to determine the stack top now. | 14105 // Uses the address of a local variable to determine the stack top now. |
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16533 v8::V8::SetFatalErrorHandler(CountingErrorCallback); | 16562 v8::V8::SetFatalErrorHandler(CountingErrorCallback); |
16534 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); | 16563 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); |
16535 i::Isolate::Current()->TearDown(); | 16564 i::Isolate::Current()->TearDown(); |
16536 CHECK(!i::Internals::IsInitialized(isolate)); | 16565 CHECK(!i::Internals::IsInitialized(isolate)); |
16537 CHECK_EQ(1, fatal_error_callback_counter); | 16566 CHECK_EQ(1, fatal_error_callback_counter); |
16538 CHECK(v8::String::Empty().IsEmpty()); | 16567 CHECK(v8::String::Empty().IsEmpty()); |
16539 CHECK_EQ(2, fatal_error_callback_counter); | 16568 CHECK_EQ(2, fatal_error_callback_counter); |
16540 CHECK(v8::String::Empty(isolate).IsEmpty()); | 16569 CHECK(v8::String::Empty(isolate).IsEmpty()); |
16541 CHECK_EQ(3, fatal_error_callback_counter); | 16570 CHECK_EQ(3, fatal_error_callback_counter); |
16542 } | 16571 } |
OLD | NEW |