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 13480 matching lines...) Loading... |
13491 TEST(DontLeakGlobalObjects) { | 13491 TEST(DontLeakGlobalObjects) { |
13492 // Regression test for issues 1139850 and 1174891. | 13492 // Regression test for issues 1139850 and 1174891. |
13493 | 13493 |
13494 i::FLAG_expose_gc = true; | 13494 i::FLAG_expose_gc = true; |
13495 v8::V8::Initialize(); | 13495 v8::V8::Initialize(); |
13496 | 13496 |
13497 for (int i = 0; i < 5; i++) { | 13497 for (int i = 0; i < 5; i++) { |
13498 { v8::HandleScope scope(CcTest::isolate()); | 13498 { v8::HandleScope scope(CcTest::isolate()); |
13499 LocalContext context; | 13499 LocalContext context; |
13500 } | 13500 } |
13501 v8::V8::ContextDisposedNotification(); | 13501 CcTest::isolate()->ContextDisposedNotification(); |
13502 CheckSurvivingGlobalObjectsCount(0); | 13502 CheckSurvivingGlobalObjectsCount(0); |
13503 | 13503 |
13504 { v8::HandleScope scope(CcTest::isolate()); | 13504 { v8::HandleScope scope(CcTest::isolate()); |
13505 LocalContext context; | 13505 LocalContext context; |
13506 v8_compile("Date")->Run(); | 13506 v8_compile("Date")->Run(); |
13507 } | 13507 } |
13508 v8::V8::ContextDisposedNotification(); | 13508 CcTest::isolate()->ContextDisposedNotification(); |
13509 CheckSurvivingGlobalObjectsCount(0); | 13509 CheckSurvivingGlobalObjectsCount(0); |
13510 | 13510 |
13511 { v8::HandleScope scope(CcTest::isolate()); | 13511 { v8::HandleScope scope(CcTest::isolate()); |
13512 LocalContext context; | 13512 LocalContext context; |
13513 v8_compile("/aaa/")->Run(); | 13513 v8_compile("/aaa/")->Run(); |
13514 } | 13514 } |
13515 v8::V8::ContextDisposedNotification(); | 13515 CcTest::isolate()->ContextDisposedNotification(); |
13516 CheckSurvivingGlobalObjectsCount(0); | 13516 CheckSurvivingGlobalObjectsCount(0); |
13517 | 13517 |
13518 { v8::HandleScope scope(CcTest::isolate()); | 13518 { v8::HandleScope scope(CcTest::isolate()); |
13519 const char* extension_list[] = { "v8/gc" }; | 13519 const char* extension_list[] = { "v8/gc" }; |
13520 v8::ExtensionConfiguration extensions(1, extension_list); | 13520 v8::ExtensionConfiguration extensions(1, extension_list); |
13521 LocalContext context(&extensions); | 13521 LocalContext context(&extensions); |
13522 v8_compile("gc();")->Run(); | 13522 v8_compile("gc();")->Run(); |
13523 } | 13523 } |
13524 v8::V8::ContextDisposedNotification(); | 13524 CcTest::isolate()->ContextDisposedNotification(); |
13525 CheckSurvivingGlobalObjectsCount(0); | 13525 CheckSurvivingGlobalObjectsCount(0); |
13526 } | 13526 } |
13527 } | 13527 } |
13528 | 13528 |
13529 | 13529 |
13530 TEST(CopyablePersistent) { | 13530 TEST(CopyablePersistent) { |
13531 LocalContext context; | 13531 LocalContext context; |
13532 v8::Isolate* isolate = context->GetIsolate(); | 13532 v8::Isolate* isolate = context->GetIsolate(); |
13533 i::GlobalHandles* globals = | 13533 i::GlobalHandles* globals = |
13534 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); | 13534 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); |
(...skipping 4058 matching lines...) Loading... |
17593 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 17593 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
17594 for (int i = 0; i < 1000; i++) { | 17594 for (int i = 0; i < 1000; i++) { |
17595 factory->NewFixedArray(1000, i::TENURED); | 17595 factory->NewFixedArray(1000, i::TENURED); |
17596 } | 17596 } |
17597 } | 17597 } |
17598 | 17598 |
17599 | 17599 |
17600 // Test that idle notification can be handled and eventually returns true. | 17600 // Test that idle notification can be handled and eventually returns true. |
17601 TEST(IdleNotification) { | 17601 TEST(IdleNotification) { |
17602 const intptr_t MB = 1024 * 1024; | 17602 const intptr_t MB = 1024 * 1024; |
| 17603 const int IdlePauseInMs = 1000; |
17603 LocalContext env; | 17604 LocalContext env; |
17604 v8::HandleScope scope(env->GetIsolate()); | 17605 v8::HandleScope scope(env->GetIsolate()); |
17605 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); | 17606 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); |
17606 CreateGarbageInOldSpace(); | 17607 CreateGarbageInOldSpace(); |
17607 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); | 17608 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); |
17608 CHECK_GT(size_with_garbage, initial_size + MB); | 17609 CHECK_GT(size_with_garbage, initial_size + MB); |
17609 bool finished = false; | 17610 bool finished = false; |
17610 for (int i = 0; i < 200 && !finished; i++) { | 17611 for (int i = 0; i < 200 && !finished; i++) { |
17611 finished = v8::V8::IdleNotification(); | 17612 finished = env->GetIsolate()->IdleNotification(IdlePauseInMs); |
17612 } | 17613 } |
17613 intptr_t final_size = CcTest::heap()->SizeOfObjects(); | 17614 intptr_t final_size = CcTest::heap()->SizeOfObjects(); |
17614 CHECK(finished); | 17615 CHECK(finished); |
17615 CHECK_LT(final_size, initial_size + 1); | 17616 CHECK_LT(final_size, initial_size + 1); |
17616 } | 17617 } |
17617 | 17618 |
17618 | 17619 |
17619 // Test that idle notification can be handled and eventually collects garbage. | 17620 // Test that idle notification can be handled and eventually collects garbage. |
17620 TEST(IdleNotificationWithSmallHint) { | 17621 TEST(IdleNotificationWithSmallHint) { |
17621 const intptr_t MB = 1024 * 1024; | 17622 const intptr_t MB = 1024 * 1024; |
17622 const int IdlePauseInMs = 900; | 17623 const int IdlePauseInMs = 900; |
17623 LocalContext env; | 17624 LocalContext env; |
17624 v8::HandleScope scope(env->GetIsolate()); | 17625 v8::HandleScope scope(env->GetIsolate()); |
17625 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); | 17626 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); |
17626 CreateGarbageInOldSpace(); | 17627 CreateGarbageInOldSpace(); |
17627 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); | 17628 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); |
17628 CHECK_GT(size_with_garbage, initial_size + MB); | 17629 CHECK_GT(size_with_garbage, initial_size + MB); |
17629 bool finished = false; | 17630 bool finished = false; |
17630 for (int i = 0; i < 200 && !finished; i++) { | 17631 for (int i = 0; i < 200 && !finished; i++) { |
17631 finished = v8::V8::IdleNotification(IdlePauseInMs); | 17632 finished = env->GetIsolate()->IdleNotification(IdlePauseInMs); |
17632 } | 17633 } |
17633 intptr_t final_size = CcTest::heap()->SizeOfObjects(); | 17634 intptr_t final_size = CcTest::heap()->SizeOfObjects(); |
17634 CHECK(finished); | 17635 CHECK(finished); |
17635 CHECK_LT(final_size, initial_size + 1); | 17636 CHECK_LT(final_size, initial_size + 1); |
17636 } | 17637 } |
17637 | 17638 |
17638 | 17639 |
17639 // Test that idle notification can be handled and eventually collects garbage. | 17640 // Test that idle notification can be handled and eventually collects garbage. |
17640 TEST(IdleNotificationWithLargeHint) { | 17641 TEST(IdleNotificationWithLargeHint) { |
17641 const intptr_t MB = 1024 * 1024; | 17642 const intptr_t MB = 1024 * 1024; |
17642 const int IdlePauseInMs = 900; | 17643 const int IdlePauseInMs = 900; |
17643 LocalContext env; | 17644 LocalContext env; |
17644 v8::HandleScope scope(env->GetIsolate()); | 17645 v8::HandleScope scope(env->GetIsolate()); |
17645 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); | 17646 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); |
17646 CreateGarbageInOldSpace(); | 17647 CreateGarbageInOldSpace(); |
17647 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); | 17648 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); |
17648 CHECK_GT(size_with_garbage, initial_size + MB); | 17649 CHECK_GT(size_with_garbage, initial_size + MB); |
17649 bool finished = false; | 17650 bool finished = false; |
17650 for (int i = 0; i < 200 && !finished; i++) { | 17651 for (int i = 0; i < 200 && !finished; i++) { |
17651 finished = v8::V8::IdleNotification(IdlePauseInMs); | 17652 finished = env->GetIsolate()->IdleNotification(IdlePauseInMs); |
17652 } | 17653 } |
17653 intptr_t final_size = CcTest::heap()->SizeOfObjects(); | 17654 intptr_t final_size = CcTest::heap()->SizeOfObjects(); |
17654 CHECK(finished); | 17655 CHECK(finished); |
17655 CHECK_LT(final_size, initial_size + 1); | 17656 CHECK_LT(final_size, initial_size + 1); |
17656 } | 17657 } |
17657 | 17658 |
17658 | 17659 |
17659 TEST(Regress2107) { | 17660 TEST(Regress2107) { |
17660 const intptr_t MB = 1024 * 1024; | 17661 const intptr_t MB = 1024 * 1024; |
17661 const int kShortIdlePauseInMs = 100; | 17662 const int kShortIdlePauseInMs = 100; |
17662 const int kLongIdlePauseInMs = 1000; | 17663 const int kLongIdlePauseInMs = 1000; |
17663 LocalContext env; | 17664 LocalContext env; |
17664 v8::Isolate* isolate = env->GetIsolate(); | 17665 v8::Isolate* isolate = env->GetIsolate(); |
17665 v8::HandleScope scope(env->GetIsolate()); | 17666 v8::HandleScope scope(env->GetIsolate()); |
17666 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); | 17667 intptr_t initial_size = CcTest::heap()->SizeOfObjects(); |
17667 // Send idle notification to start a round of incremental GCs. | 17668 // Send idle notification to start a round of incremental GCs. |
17668 v8::V8::IdleNotification(kShortIdlePauseInMs); | 17669 env->GetIsolate()->IdleNotification(kShortIdlePauseInMs); |
17669 // Emulate 7 page reloads. | 17670 // Emulate 7 page reloads. |
17670 for (int i = 0; i < 7; i++) { | 17671 for (int i = 0; i < 7; i++) { |
17671 { | 17672 { |
17672 v8::HandleScope inner_scope(env->GetIsolate()); | 17673 v8::HandleScope inner_scope(env->GetIsolate()); |
17673 v8::Local<v8::Context> ctx = v8::Context::New(isolate); | 17674 v8::Local<v8::Context> ctx = v8::Context::New(isolate); |
17674 ctx->Enter(); | 17675 ctx->Enter(); |
17675 CreateGarbageInOldSpace(); | 17676 CreateGarbageInOldSpace(); |
17676 ctx->Exit(); | 17677 ctx->Exit(); |
17677 } | 17678 } |
17678 v8::V8::ContextDisposedNotification(); | 17679 env->GetIsolate()->ContextDisposedNotification(); |
17679 v8::V8::IdleNotification(kLongIdlePauseInMs); | 17680 env->GetIsolate()->IdleNotification(kLongIdlePauseInMs); |
17680 } | 17681 } |
17681 // Create garbage and check that idle notification still collects it. | 17682 // Create garbage and check that idle notification still collects it. |
17682 CreateGarbageInOldSpace(); | 17683 CreateGarbageInOldSpace(); |
17683 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); | 17684 intptr_t size_with_garbage = CcTest::heap()->SizeOfObjects(); |
17684 CHECK_GT(size_with_garbage, initial_size + MB); | 17685 CHECK_GT(size_with_garbage, initial_size + MB); |
17685 bool finished = false; | 17686 bool finished = false; |
17686 for (int i = 0; i < 200 && !finished; i++) { | 17687 for (int i = 0; i < 200 && !finished; i++) { |
17687 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); | 17688 finished = env->GetIsolate()->IdleNotification(kShortIdlePauseInMs); |
17688 } | 17689 } |
17689 intptr_t final_size = CcTest::heap()->SizeOfObjects(); | 17690 intptr_t final_size = CcTest::heap()->SizeOfObjects(); |
17690 CHECK_LT(final_size, initial_size + 1); | 17691 CHECK_LT(final_size, initial_size + 1); |
17691 } | 17692 } |
17692 | 17693 |
17693 | 17694 |
17694 TEST(Regress2333) { | 17695 TEST(Regress2333) { |
17695 LocalContext env; | 17696 LocalContext env; |
17696 for (int i = 0; i < 3; i++) { | 17697 for (int i = 0; i < 3; i++) { |
17697 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 17698 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
(...skipping 455 matching lines...) Loading... |
18153 { | 18154 { |
18154 v8::HandleScope scope(isolate); | 18155 v8::HandleScope scope(isolate); |
18155 v8::Local<Context> context = Context::New(isolate); | 18156 v8::Local<Context> context = Context::New(isolate); |
18156 | 18157 |
18157 context->Enter(); | 18158 context->Enter(); |
18158 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); | 18159 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); |
18159 context->SetEmbedderData(0, obj); | 18160 context->SetEmbedderData(0, obj); |
18160 CompileRun(source_simple); | 18161 CompileRun(source_simple); |
18161 context->Exit(); | 18162 context->Exit(); |
18162 } | 18163 } |
18163 v8::V8::ContextDisposedNotification(); | 18164 isolate->ContextDisposedNotification(); |
18164 for (gc_count = 1; gc_count < 10; gc_count++) { | 18165 for (gc_count = 1; gc_count < 10; gc_count++) { |
18165 other_context->Enter(); | 18166 other_context->Enter(); |
18166 CompileRun(source_simple); | 18167 CompileRun(source_simple); |
18167 other_context->Exit(); | 18168 other_context->Exit(); |
18168 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 18169 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
18169 if (GetGlobalObjectsCount() == 1) break; | 18170 if (GetGlobalObjectsCount() == 1) break; |
18170 } | 18171 } |
18171 CHECK_GE(2, gc_count); | 18172 CHECK_GE(2, gc_count); |
18172 CHECK_EQ(1, GetGlobalObjectsCount()); | 18173 CHECK_EQ(1, GetGlobalObjectsCount()); |
18173 | 18174 |
18174 // Eval in a function creates reference from the compilation cache to the | 18175 // Eval in a function creates reference from the compilation cache to the |
18175 // global object. | 18176 // global object. |
18176 const char* source_eval = "function f(){eval('1')}; f()"; | 18177 const char* source_eval = "function f(){eval('1')}; f()"; |
18177 { | 18178 { |
18178 v8::HandleScope scope(isolate); | 18179 v8::HandleScope scope(isolate); |
18179 v8::Local<Context> context = Context::New(isolate); | 18180 v8::Local<Context> context = Context::New(isolate); |
18180 | 18181 |
18181 context->Enter(); | 18182 context->Enter(); |
18182 CompileRun(source_eval); | 18183 CompileRun(source_eval); |
18183 context->Exit(); | 18184 context->Exit(); |
18184 } | 18185 } |
18185 v8::V8::ContextDisposedNotification(); | 18186 isolate->ContextDisposedNotification(); |
18186 for (gc_count = 1; gc_count < 10; gc_count++) { | 18187 for (gc_count = 1; gc_count < 10; gc_count++) { |
18187 other_context->Enter(); | 18188 other_context->Enter(); |
18188 CompileRun(source_eval); | 18189 CompileRun(source_eval); |
18189 other_context->Exit(); | 18190 other_context->Exit(); |
18190 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 18191 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
18191 if (GetGlobalObjectsCount() == 1) break; | 18192 if (GetGlobalObjectsCount() == 1) break; |
18192 } | 18193 } |
18193 CHECK_GE(2, gc_count); | 18194 CHECK_GE(2, gc_count); |
18194 CHECK_EQ(1, GetGlobalObjectsCount()); | 18195 CHECK_EQ(1, GetGlobalObjectsCount()); |
18195 | 18196 |
18196 // Looking up the line number for an exception creates reference from the | 18197 // Looking up the line number for an exception creates reference from the |
18197 // compilation cache to the global object. | 18198 // compilation cache to the global object. |
18198 const char* source_exception = "function f(){throw 1;} f()"; | 18199 const char* source_exception = "function f(){throw 1;} f()"; |
18199 { | 18200 { |
18200 v8::HandleScope scope(isolate); | 18201 v8::HandleScope scope(isolate); |
18201 v8::Local<Context> context = Context::New(isolate); | 18202 v8::Local<Context> context = Context::New(isolate); |
18202 | 18203 |
18203 context->Enter(); | 18204 context->Enter(); |
18204 v8::TryCatch try_catch; | 18205 v8::TryCatch try_catch; |
18205 CompileRun(source_exception); | 18206 CompileRun(source_exception); |
18206 CHECK(try_catch.HasCaught()); | 18207 CHECK(try_catch.HasCaught()); |
18207 v8::Handle<v8::Message> message = try_catch.Message(); | 18208 v8::Handle<v8::Message> message = try_catch.Message(); |
18208 CHECK(!message.IsEmpty()); | 18209 CHECK(!message.IsEmpty()); |
18209 CHECK_EQ(1, message->GetLineNumber()); | 18210 CHECK_EQ(1, message->GetLineNumber()); |
18210 context->Exit(); | 18211 context->Exit(); |
18211 } | 18212 } |
18212 v8::V8::ContextDisposedNotification(); | 18213 isolate->ContextDisposedNotification(); |
18213 for (gc_count = 1; gc_count < 10; gc_count++) { | 18214 for (gc_count = 1; gc_count < 10; gc_count++) { |
18214 other_context->Enter(); | 18215 other_context->Enter(); |
18215 CompileRun(source_exception); | 18216 CompileRun(source_exception); |
18216 other_context->Exit(); | 18217 other_context->Exit(); |
18217 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 18218 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
18218 if (GetGlobalObjectsCount() == 1) break; | 18219 if (GetGlobalObjectsCount() == 1) break; |
18219 } | 18220 } |
18220 CHECK_GE(2, gc_count); | 18221 CHECK_GE(2, gc_count); |
18221 CHECK_EQ(1, GetGlobalObjectsCount()); | 18222 CHECK_EQ(1, GetGlobalObjectsCount()); |
18222 | 18223 |
18223 v8::V8::ContextDisposedNotification(); | 18224 isolate->ContextDisposedNotification(); |
18224 } | 18225 } |
18225 | 18226 |
18226 | 18227 |
18227 THREADED_TEST(ScriptOrigin) { | 18228 THREADED_TEST(ScriptOrigin) { |
18228 LocalContext env; | 18229 LocalContext env; |
18229 v8::HandleScope scope(env->GetIsolate()); | 18230 v8::HandleScope scope(env->GetIsolate()); |
18230 v8::ScriptOrigin origin = | 18231 v8::ScriptOrigin origin = |
18231 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 18232 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); |
18232 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | 18233 v8::Handle<v8::String> script = v8::String::NewFromUtf8( |
18233 env->GetIsolate(), "function f() {}\n\nfunction g() {}"); | 18234 env->GetIsolate(), "function f() {}\n\nfunction g() {}"); |
(...skipping 4594 matching lines...) Loading... |
22828 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); | 22829 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); |
22829 Local<Function> set = | 22830 Local<Function> set = |
22830 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); | 22831 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); |
22831 Local<Function> get = | 22832 Local<Function> get = |
22832 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); | 22833 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); |
22833 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); | 22834 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); |
22834 Handle<Value> args[] = { v8_num(14) }; | 22835 Handle<Value> args[] = { v8_num(14) }; |
22835 set->Call(x, 1, args); | 22836 set->Call(x, 1, args); |
22836 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); | 22837 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); |
22837 } | 22838 } |
OLD | NEW |