| 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 12346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12357 RegisterThreadedTest::nth(current_)->fuzzer_->gate_.Signal(); | 12357 RegisterThreadedTest::nth(current_)->fuzzer_->gate_.Signal(); |
| 12358 return true; | 12358 return true; |
| 12359 } | 12359 } |
| 12360 | 12360 |
| 12361 | 12361 |
| 12362 void ApiTestFuzzer::Run() { | 12362 void ApiTestFuzzer::Run() { |
| 12363 // When it is our turn... | 12363 // When it is our turn... |
| 12364 gate_.Wait(); | 12364 gate_.Wait(); |
| 12365 { | 12365 { |
| 12366 // ... get the V8 lock and start running the test. | 12366 // ... get the V8 lock and start running the test. |
| 12367 v8::Locker locker(CcTest::default_isolate()); | 12367 v8::Locker locker(CcTest::isolate()); |
| 12368 CallTest(); | 12368 CallTest(); |
| 12369 } | 12369 } |
| 12370 // This test finished. | 12370 // This test finished. |
| 12371 active_ = false; | 12371 active_ = false; |
| 12372 active_tests_--; | 12372 active_tests_--; |
| 12373 // If it was the last then signal that fact. | 12373 // If it was the last then signal that fact. |
| 12374 if (active_tests_ == 0) { | 12374 if (active_tests_ == 0) { |
| 12375 all_tests_done_.Signal(); | 12375 all_tests_done_.Signal(); |
| 12376 } else { | 12376 } else { |
| 12377 // Otherwise select a new test and start that. | 12377 // Otherwise select a new test and start that. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12421 linear_congruential_generator += 1013904223u; | 12421 linear_congruential_generator += 1013904223u; |
| 12422 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_); | 12422 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_); |
| 12423 return next_test; | 12423 return next_test; |
| 12424 } | 12424 } |
| 12425 | 12425 |
| 12426 | 12426 |
| 12427 void ApiTestFuzzer::ContextSwitch() { | 12427 void ApiTestFuzzer::ContextSwitch() { |
| 12428 // If the new thread is the same as the current thread there is nothing to do. | 12428 // If the new thread is the same as the current thread there is nothing to do. |
| 12429 if (NextThread()) { | 12429 if (NextThread()) { |
| 12430 // Now it can start. | 12430 // Now it can start. |
| 12431 v8::Unlocker unlocker(CcTest::default_isolate()); | 12431 v8::Unlocker unlocker(CcTest::isolate()); |
| 12432 // Wait till someone starts us again. | 12432 // Wait till someone starts us again. |
| 12433 gate_.Wait(); | 12433 gate_.Wait(); |
| 12434 // And we're off. | 12434 // And we're off. |
| 12435 } | 12435 } |
| 12436 } | 12436 } |
| 12437 | 12437 |
| 12438 | 12438 |
| 12439 void ApiTestFuzzer::TearDown() { | 12439 void ApiTestFuzzer::TearDown() { |
| 12440 fuzzing_ = false; | 12440 fuzzing_ = false; |
| 12441 for (int i = 0; i < RegisterThreadedTest::count(); i++) { | 12441 for (int i = 0; i < RegisterThreadedTest::count(); i++) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12477 void ApiTestFuzzer::CallTest() { | 12477 void ApiTestFuzzer::CallTest() { |
| 12478 if (kLogThreading) | 12478 if (kLogThreading) |
| 12479 printf("Start test %d\n", test_number_); | 12479 printf("Start test %d\n", test_number_); |
| 12480 CallTestNumber(test_number_); | 12480 CallTestNumber(test_number_); |
| 12481 if (kLogThreading) | 12481 if (kLogThreading) |
| 12482 printf("End test %d\n", test_number_); | 12482 printf("End test %d\n", test_number_); |
| 12483 } | 12483 } |
| 12484 | 12484 |
| 12485 | 12485 |
| 12486 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { | 12486 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 12487 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); | 12487 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
| 12488 ApiTestFuzzer::Fuzz(); | 12488 ApiTestFuzzer::Fuzz(); |
| 12489 v8::Unlocker unlocker(CcTest::default_isolate()); | 12489 v8::Unlocker unlocker(CcTest::isolate()); |
| 12490 const char* code = "throw 7;"; | 12490 const char* code = "throw 7;"; |
| 12491 { | 12491 { |
| 12492 v8::Locker nested_locker(CcTest::default_isolate()); | 12492 v8::Locker nested_locker(CcTest::isolate()); |
| 12493 v8::HandleScope scope(args.GetIsolate()); | 12493 v8::HandleScope scope(args.GetIsolate()); |
| 12494 v8::Handle<Value> exception; | 12494 v8::Handle<Value> exception; |
| 12495 { v8::TryCatch try_catch; | 12495 { v8::TryCatch try_catch; |
| 12496 v8::Handle<Value> value = CompileRun(code); | 12496 v8::Handle<Value> value = CompileRun(code); |
| 12497 CHECK(value.IsEmpty()); | 12497 CHECK(value.IsEmpty()); |
| 12498 CHECK(try_catch.HasCaught()); | 12498 CHECK(try_catch.HasCaught()); |
| 12499 // Make sure to wrap the exception in a new handle because | 12499 // Make sure to wrap the exception in a new handle because |
| 12500 // the handle returned from the TryCatch is destroyed | 12500 // the handle returned from the TryCatch is destroyed |
| 12501 // when the TryCatch is destroyed. | 12501 // when the TryCatch is destroyed. |
| 12502 exception = Local<Value>::New(try_catch.Exception()); | 12502 exception = Local<Value>::New(try_catch.Exception()); |
| 12503 } | 12503 } |
| 12504 v8::ThrowException(exception); | 12504 v8::ThrowException(exception); |
| 12505 } | 12505 } |
| 12506 } | 12506 } |
| 12507 | 12507 |
| 12508 | 12508 |
| 12509 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 12509 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 12510 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); | 12510 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
| 12511 ApiTestFuzzer::Fuzz(); | 12511 ApiTestFuzzer::Fuzz(); |
| 12512 v8::Unlocker unlocker(CcTest::default_isolate()); | 12512 v8::Unlocker unlocker(CcTest::isolate()); |
| 12513 const char* code = "throw 7;"; | 12513 const char* code = "throw 7;"; |
| 12514 { | 12514 { |
| 12515 v8::Locker nested_locker(CcTest::default_isolate()); | 12515 v8::Locker nested_locker(CcTest::isolate()); |
| 12516 v8::HandleScope scope(args.GetIsolate()); | 12516 v8::HandleScope scope(args.GetIsolate()); |
| 12517 v8::Handle<Value> value = CompileRun(code); | 12517 v8::Handle<Value> value = CompileRun(code); |
| 12518 CHECK(value.IsEmpty()); | 12518 CHECK(value.IsEmpty()); |
| 12519 args.GetReturnValue().Set(v8_str("foo")); | 12519 args.GetReturnValue().Set(v8_str("foo")); |
| 12520 } | 12520 } |
| 12521 } | 12521 } |
| 12522 | 12522 |
| 12523 | 12523 |
| 12524 // These are locking tests that don't need to be run again | 12524 // These are locking tests that don't need to be run again |
| 12525 // as part of the locking aggregation tests. | 12525 // as part of the locking aggregation tests. |
| 12526 TEST(NestedLockers) { | 12526 TEST(NestedLockers) { |
| 12527 v8::Locker locker(CcTest::default_isolate()); | 12527 v8::Locker locker(CcTest::isolate()); |
| 12528 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); | 12528 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
| 12529 LocalContext env; | 12529 LocalContext env; |
| 12530 v8::HandleScope scope(env->GetIsolate()); | 12530 v8::HandleScope scope(env->GetIsolate()); |
| 12531 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); | 12531 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); |
| 12532 Local<Function> fun = fun_templ->GetFunction(); | 12532 Local<Function> fun = fun_templ->GetFunction(); |
| 12533 env->Global()->Set(v8_str("throw_in_js"), fun); | 12533 env->Global()->Set(v8_str("throw_in_js"), fun); |
| 12534 Local<Script> script = v8_compile("(function () {" | 12534 Local<Script> script = v8_compile("(function () {" |
| 12535 " try {" | 12535 " try {" |
| 12536 " throw_in_js();" | 12536 " throw_in_js();" |
| 12537 " return 42;" | 12537 " return 42;" |
| 12538 " } catch (e) {" | 12538 " } catch (e) {" |
| 12539 " return e * 13;" | 12539 " return e * 13;" |
| 12540 " }" | 12540 " }" |
| 12541 "})();"); | 12541 "})();"); |
| 12542 CHECK_EQ(91, script->Run()->Int32Value()); | 12542 CHECK_EQ(91, script->Run()->Int32Value()); |
| 12543 } | 12543 } |
| 12544 | 12544 |
| 12545 | 12545 |
| 12546 // These are locking tests that don't need to be run again | 12546 // These are locking tests that don't need to be run again |
| 12547 // as part of the locking aggregation tests. | 12547 // as part of the locking aggregation tests. |
| 12548 TEST(NestedLockersNoTryCatch) { | 12548 TEST(NestedLockersNoTryCatch) { |
| 12549 v8::Locker locker(CcTest::default_isolate()); | 12549 v8::Locker locker(CcTest::isolate()); |
| 12550 LocalContext env; | 12550 LocalContext env; |
| 12551 v8::HandleScope scope(env->GetIsolate()); | 12551 v8::HandleScope scope(env->GetIsolate()); |
| 12552 Local<v8::FunctionTemplate> fun_templ = | 12552 Local<v8::FunctionTemplate> fun_templ = |
| 12553 v8::FunctionTemplate::New(ThrowInJSNoCatch); | 12553 v8::FunctionTemplate::New(ThrowInJSNoCatch); |
| 12554 Local<Function> fun = fun_templ->GetFunction(); | 12554 Local<Function> fun = fun_templ->GetFunction(); |
| 12555 env->Global()->Set(v8_str("throw_in_js"), fun); | 12555 env->Global()->Set(v8_str("throw_in_js"), fun); |
| 12556 Local<Script> script = v8_compile("(function () {" | 12556 Local<Script> script = v8_compile("(function () {" |
| 12557 " try {" | 12557 " try {" |
| 12558 " throw_in_js();" | 12558 " throw_in_js();" |
| 12559 " return 42;" | 12559 " return 42;" |
| 12560 " } catch (e) {" | 12560 " } catch (e) {" |
| 12561 " return e * 13;" | 12561 " return e * 13;" |
| 12562 " }" | 12562 " }" |
| 12563 "})();"); | 12563 "})();"); |
| 12564 CHECK_EQ(91, script->Run()->Int32Value()); | 12564 CHECK_EQ(91, script->Run()->Int32Value()); |
| 12565 } | 12565 } |
| 12566 | 12566 |
| 12567 | 12567 |
| 12568 THREADED_TEST(RecursiveLocking) { | 12568 THREADED_TEST(RecursiveLocking) { |
| 12569 v8::Locker locker(CcTest::default_isolate()); | 12569 v8::Locker locker(CcTest::isolate()); |
| 12570 { | 12570 { |
| 12571 v8::Locker locker2(CcTest::default_isolate()); | 12571 v8::Locker locker2(CcTest::isolate()); |
| 12572 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); | 12572 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
| 12573 } | 12573 } |
| 12574 } | 12574 } |
| 12575 | 12575 |
| 12576 | 12576 |
| 12577 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { | 12577 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 12578 ApiTestFuzzer::Fuzz(); | 12578 ApiTestFuzzer::Fuzz(); |
| 12579 v8::Unlocker unlocker(CcTest::default_isolate()); | 12579 v8::Unlocker unlocker(CcTest::isolate()); |
| 12580 } | 12580 } |
| 12581 | 12581 |
| 12582 | 12582 |
| 12583 THREADED_TEST(LockUnlockLock) { | 12583 THREADED_TEST(LockUnlockLock) { |
| 12584 { | 12584 { |
| 12585 v8::Locker locker(CcTest::default_isolate()); | 12585 v8::Locker locker(CcTest::isolate()); |
| 12586 v8::HandleScope scope(CcTest::default_isolate()); | 12586 v8::HandleScope scope(CcTest::isolate()); |
| 12587 LocalContext env; | 12587 LocalContext env; |
| 12588 Local<v8::FunctionTemplate> fun_templ = | 12588 Local<v8::FunctionTemplate> fun_templ = |
| 12589 v8::FunctionTemplate::New(UnlockForAMoment); | 12589 v8::FunctionTemplate::New(UnlockForAMoment); |
| 12590 Local<Function> fun = fun_templ->GetFunction(); | 12590 Local<Function> fun = fun_templ->GetFunction(); |
| 12591 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 12591 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
| 12592 Local<Script> script = v8_compile("(function () {" | 12592 Local<Script> script = v8_compile("(function () {" |
| 12593 " unlock_for_a_moment();" | 12593 " unlock_for_a_moment();" |
| 12594 " return 42;" | 12594 " return 42;" |
| 12595 "})();"); | 12595 "})();"); |
| 12596 CHECK_EQ(42, script->Run()->Int32Value()); | 12596 CHECK_EQ(42, script->Run()->Int32Value()); |
| 12597 } | 12597 } |
| 12598 { | 12598 { |
| 12599 v8::Locker locker(CcTest::default_isolate()); | 12599 v8::Locker locker(CcTest::isolate()); |
| 12600 v8::HandleScope scope(CcTest::default_isolate()); | 12600 v8::HandleScope scope(CcTest::isolate()); |
| 12601 LocalContext env; | 12601 LocalContext env; |
| 12602 Local<v8::FunctionTemplate> fun_templ = | 12602 Local<v8::FunctionTemplate> fun_templ = |
| 12603 v8::FunctionTemplate::New(UnlockForAMoment); | 12603 v8::FunctionTemplate::New(UnlockForAMoment); |
| 12604 Local<Function> fun = fun_templ->GetFunction(); | 12604 Local<Function> fun = fun_templ->GetFunction(); |
| 12605 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 12605 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
| 12606 Local<Script> script = v8_compile("(function () {" | 12606 Local<Script> script = v8_compile("(function () {" |
| 12607 " unlock_for_a_moment();" | 12607 " unlock_for_a_moment();" |
| 12608 " return 42;" | 12608 " return 42;" |
| 12609 "})();"); | 12609 "})();"); |
| 12610 CHECK_EQ(42, script->Run()->Int32Value()); | 12610 CHECK_EQ(42, script->Run()->Int32Value()); |
| (...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14222 gc_count_ = 0; | 14222 gc_count_ = 0; |
| 14223 gc_during_regexp_ = 0; | 14223 gc_during_regexp_ = 0; |
| 14224 regexp_success_ = false; | 14224 regexp_success_ = false; |
| 14225 gc_success_ = false; | 14225 gc_success_ = false; |
| 14226 GCThread gc_thread(this); | 14226 GCThread gc_thread(this); |
| 14227 gc_thread.Start(); | 14227 gc_thread.Start(); |
| 14228 v8::Locker::StartPreemption(1); | 14228 v8::Locker::StartPreemption(1); |
| 14229 | 14229 |
| 14230 LongRunningRegExp(); | 14230 LongRunningRegExp(); |
| 14231 { | 14231 { |
| 14232 v8::Unlocker unlock(CcTest::default_isolate()); | 14232 v8::Unlocker unlock(CcTest::isolate()); |
| 14233 gc_thread.Join(); | 14233 gc_thread.Join(); |
| 14234 } | 14234 } |
| 14235 v8::Locker::StopPreemption(); | 14235 v8::Locker::StopPreemption(); |
| 14236 CHECK(regexp_success_); | 14236 CHECK(regexp_success_); |
| 14237 CHECK(gc_success_); | 14237 CHECK(gc_success_); |
| 14238 } | 14238 } |
| 14239 | 14239 |
| 14240 private: | 14240 private: |
| 14241 // Number of garbage collections required. | 14241 // Number of garbage collections required. |
| 14242 static const int kRequiredGCs = 5; | 14242 static const int kRequiredGCs = 5; |
| 14243 | 14243 |
| 14244 class GCThread : public i::Thread { | 14244 class GCThread : public i::Thread { |
| 14245 public: | 14245 public: |
| 14246 explicit GCThread(RegExpInterruptTest* test) | 14246 explicit GCThread(RegExpInterruptTest* test) |
| 14247 : Thread("GCThread"), test_(test) {} | 14247 : Thread("GCThread"), test_(test) {} |
| 14248 virtual void Run() { | 14248 virtual void Run() { |
| 14249 test_->CollectGarbage(); | 14249 test_->CollectGarbage(); |
| 14250 } | 14250 } |
| 14251 private: | 14251 private: |
| 14252 RegExpInterruptTest* test_; | 14252 RegExpInterruptTest* test_; |
| 14253 }; | 14253 }; |
| 14254 | 14254 |
| 14255 void CollectGarbage() { | 14255 void CollectGarbage() { |
| 14256 block_.Wait(); | 14256 block_.Wait(); |
| 14257 while (gc_during_regexp_ < kRequiredGCs) { | 14257 while (gc_during_regexp_ < kRequiredGCs) { |
| 14258 { | 14258 { |
| 14259 v8::Locker lock(CcTest::default_isolate()); | 14259 v8::Locker lock(CcTest::isolate()); |
| 14260 // TODO(lrn): Perhaps create some garbage before collecting. | 14260 // TODO(lrn): Perhaps create some garbage before collecting. |
| 14261 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14261 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 14262 gc_count_++; | 14262 gc_count_++; |
| 14263 } | 14263 } |
| 14264 i::OS::Sleep(1); | 14264 i::OS::Sleep(1); |
| 14265 } | 14265 } |
| 14266 gc_success_ = true; | 14266 gc_success_ = true; |
| 14267 } | 14267 } |
| 14268 | 14268 |
| 14269 void LongRunningRegExp() { | 14269 void LongRunningRegExp() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14309 int gc_count_; | 14309 int gc_count_; |
| 14310 int gc_during_regexp_; | 14310 int gc_during_regexp_; |
| 14311 bool regexp_success_; | 14311 bool regexp_success_; |
| 14312 bool gc_success_; | 14312 bool gc_success_; |
| 14313 }; | 14313 }; |
| 14314 | 14314 |
| 14315 | 14315 |
| 14316 // Test that a regular expression execution can be interrupted and | 14316 // Test that a regular expression execution can be interrupted and |
| 14317 // survive a garbage collection. | 14317 // survive a garbage collection. |
| 14318 UNINITIALIZED_TEST(RegExpInterruption) { | 14318 UNINITIALIZED_TEST(RegExpInterruption) { |
| 14319 v8::Locker lock(CcTest::default_isolate()); | 14319 v8::Locker lock(CcTest::isolate()); |
| 14320 v8::V8::Initialize(); | 14320 v8::V8::Initialize(); |
| 14321 v8::HandleScope scope(CcTest::default_isolate()); | 14321 v8::HandleScope scope(CcTest::isolate()); |
| 14322 Local<Context> local_env; | 14322 Local<Context> local_env; |
| 14323 { | 14323 { |
| 14324 LocalContext env; | 14324 LocalContext env; |
| 14325 local_env = env.local(); | 14325 local_env = env.local(); |
| 14326 } | 14326 } |
| 14327 | 14327 |
| 14328 // Local context should still be live. | 14328 // Local context should still be live. |
| 14329 CHECK(!local_env.IsEmpty()); | 14329 CHECK(!local_env.IsEmpty()); |
| 14330 local_env->Enter(); | 14330 local_env->Enter(); |
| 14331 | 14331 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 14344 gc_count_ = 0; | 14344 gc_count_ = 0; |
| 14345 gc_during_apply_ = 0; | 14345 gc_during_apply_ = 0; |
| 14346 apply_success_ = false; | 14346 apply_success_ = false; |
| 14347 gc_success_ = false; | 14347 gc_success_ = false; |
| 14348 GCThread gc_thread(this); | 14348 GCThread gc_thread(this); |
| 14349 gc_thread.Start(); | 14349 gc_thread.Start(); |
| 14350 v8::Locker::StartPreemption(1); | 14350 v8::Locker::StartPreemption(1); |
| 14351 | 14351 |
| 14352 LongRunningApply(); | 14352 LongRunningApply(); |
| 14353 { | 14353 { |
| 14354 v8::Unlocker unlock(CcTest::default_isolate()); | 14354 v8::Unlocker unlock(CcTest::isolate()); |
| 14355 gc_thread.Join(); | 14355 gc_thread.Join(); |
| 14356 } | 14356 } |
| 14357 v8::Locker::StopPreemption(); | 14357 v8::Locker::StopPreemption(); |
| 14358 CHECK(apply_success_); | 14358 CHECK(apply_success_); |
| 14359 CHECK(gc_success_); | 14359 CHECK(gc_success_); |
| 14360 } | 14360 } |
| 14361 | 14361 |
| 14362 private: | 14362 private: |
| 14363 // Number of garbage collections required. | 14363 // Number of garbage collections required. |
| 14364 static const int kRequiredGCs = 2; | 14364 static const int kRequiredGCs = 2; |
| 14365 | 14365 |
| 14366 class GCThread : public i::Thread { | 14366 class GCThread : public i::Thread { |
| 14367 public: | 14367 public: |
| 14368 explicit GCThread(ApplyInterruptTest* test) | 14368 explicit GCThread(ApplyInterruptTest* test) |
| 14369 : Thread("GCThread"), test_(test) {} | 14369 : Thread("GCThread"), test_(test) {} |
| 14370 virtual void Run() { | 14370 virtual void Run() { |
| 14371 test_->CollectGarbage(); | 14371 test_->CollectGarbage(); |
| 14372 } | 14372 } |
| 14373 private: | 14373 private: |
| 14374 ApplyInterruptTest* test_; | 14374 ApplyInterruptTest* test_; |
| 14375 }; | 14375 }; |
| 14376 | 14376 |
| 14377 void CollectGarbage() { | 14377 void CollectGarbage() { |
| 14378 block_.Wait(); | 14378 block_.Wait(); |
| 14379 while (gc_during_apply_ < kRequiredGCs) { | 14379 while (gc_during_apply_ < kRequiredGCs) { |
| 14380 { | 14380 { |
| 14381 v8::Locker lock(CcTest::default_isolate()); | 14381 v8::Locker lock(CcTest::isolate()); |
| 14382 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 14382 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 14383 gc_count_++; | 14383 gc_count_++; |
| 14384 } | 14384 } |
| 14385 i::OS::Sleep(1); | 14385 i::OS::Sleep(1); |
| 14386 } | 14386 } |
| 14387 gc_success_ = true; | 14387 gc_success_ = true; |
| 14388 } | 14388 } |
| 14389 | 14389 |
| 14390 void LongRunningApply() { | 14390 void LongRunningApply() { |
| 14391 block_.Signal(); | 14391 block_.Signal(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 14417 int gc_count_; | 14417 int gc_count_; |
| 14418 int gc_during_apply_; | 14418 int gc_during_apply_; |
| 14419 bool apply_success_; | 14419 bool apply_success_; |
| 14420 bool gc_success_; | 14420 bool gc_success_; |
| 14421 }; | 14421 }; |
| 14422 | 14422 |
| 14423 | 14423 |
| 14424 // Test that nothing bad happens if we get a preemption just when we were | 14424 // Test that nothing bad happens if we get a preemption just when we were |
| 14425 // about to do an apply(). | 14425 // about to do an apply(). |
| 14426 UNINITIALIZED_TEST(ApplyInterruption) { | 14426 UNINITIALIZED_TEST(ApplyInterruption) { |
| 14427 v8::Locker lock(CcTest::default_isolate()); | 14427 v8::Locker lock(CcTest::isolate()); |
| 14428 v8::V8::Initialize(); | 14428 v8::V8::Initialize(); |
| 14429 v8::HandleScope scope(CcTest::default_isolate()); | 14429 v8::HandleScope scope(CcTest::isolate()); |
| 14430 Local<Context> local_env; | 14430 Local<Context> local_env; |
| 14431 { | 14431 { |
| 14432 LocalContext env; | 14432 LocalContext env; |
| 14433 local_env = env.local(); | 14433 local_env = env.local(); |
| 14434 } | 14434 } |
| 14435 | 14435 |
| 14436 // Local context should still be live. | 14436 // Local context should still be live. |
| 14437 CHECK(!local_env.IsEmpty()); | 14437 CHECK(!local_env.IsEmpty()); |
| 14438 local_env->Enter(); | 14438 local_env->Enter(); |
| 14439 | 14439 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14657 input_name, | 14657 input_name, |
| 14658 input_, | 14658 input_, |
| 14659 NONE, | 14659 NONE, |
| 14660 i::kNonStrictMode); | 14660 i::kNonStrictMode); |
| 14661 | 14661 |
| 14662 MorphThread morph_thread(this); | 14662 MorphThread morph_thread(this); |
| 14663 morph_thread.Start(); | 14663 morph_thread.Start(); |
| 14664 v8::Locker::StartPreemption(1); | 14664 v8::Locker::StartPreemption(1); |
| 14665 LongRunningRegExp(); | 14665 LongRunningRegExp(); |
| 14666 { | 14666 { |
| 14667 v8::Unlocker unlock(CcTest::default_isolate()); | 14667 v8::Unlocker unlock(CcTest::isolate()); |
| 14668 morph_thread.Join(); | 14668 morph_thread.Join(); |
| 14669 } | 14669 } |
| 14670 v8::Locker::StopPreemption(); | 14670 v8::Locker::StopPreemption(); |
| 14671 CHECK(regexp_success_); | 14671 CHECK(regexp_success_); |
| 14672 CHECK(morph_success_); | 14672 CHECK(morph_success_); |
| 14673 } | 14673 } |
| 14674 | 14674 |
| 14675 private: | 14675 private: |
| 14676 // Number of string modifications required. | 14676 // Number of string modifications required. |
| 14677 static const int kRequiredModifications = 5; | 14677 static const int kRequiredModifications = 5; |
| 14678 static const int kMaxModifications = 100; | 14678 static const int kMaxModifications = 100; |
| 14679 | 14679 |
| 14680 class MorphThread : public i::Thread { | 14680 class MorphThread : public i::Thread { |
| 14681 public: | 14681 public: |
| 14682 explicit MorphThread(RegExpStringModificationTest* test) | 14682 explicit MorphThread(RegExpStringModificationTest* test) |
| 14683 : Thread("MorphThread"), test_(test) {} | 14683 : Thread("MorphThread"), test_(test) {} |
| 14684 virtual void Run() { | 14684 virtual void Run() { |
| 14685 test_->MorphString(); | 14685 test_->MorphString(); |
| 14686 } | 14686 } |
| 14687 private: | 14687 private: |
| 14688 RegExpStringModificationTest* test_; | 14688 RegExpStringModificationTest* test_; |
| 14689 }; | 14689 }; |
| 14690 | 14690 |
| 14691 void MorphString() { | 14691 void MorphString() { |
| 14692 block_.Wait(); | 14692 block_.Wait(); |
| 14693 while (morphs_during_regexp_ < kRequiredModifications && | 14693 while (morphs_during_regexp_ < kRequiredModifications && |
| 14694 morphs_ < kMaxModifications) { | 14694 morphs_ < kMaxModifications) { |
| 14695 { | 14695 { |
| 14696 v8::Locker lock(CcTest::default_isolate()); | 14696 v8::Locker lock(CcTest::isolate()); |
| 14697 // Swap string between ascii and two-byte representation. | 14697 // Swap string between ascii and two-byte representation. |
| 14698 i::String* string = *input_; | 14698 i::String* string = *input_; |
| 14699 MorphAString(string, &ascii_resource_, &uc16_resource_); | 14699 MorphAString(string, &ascii_resource_, &uc16_resource_); |
| 14700 morphs_++; | 14700 morphs_++; |
| 14701 } | 14701 } |
| 14702 i::OS::Sleep(1); | 14702 i::OS::Sleep(1); |
| 14703 } | 14703 } |
| 14704 morph_success_ = true; | 14704 morph_success_ = true; |
| 14705 } | 14705 } |
| 14706 | 14706 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 14734 bool morph_success_; | 14734 bool morph_success_; |
| 14735 i::Handle<i::String> input_; | 14735 i::Handle<i::String> input_; |
| 14736 AsciiVectorResource ascii_resource_; | 14736 AsciiVectorResource ascii_resource_; |
| 14737 UC16VectorResource uc16_resource_; | 14737 UC16VectorResource uc16_resource_; |
| 14738 }; | 14738 }; |
| 14739 | 14739 |
| 14740 | 14740 |
| 14741 // Test that a regular expression execution can be interrupted and | 14741 // Test that a regular expression execution can be interrupted and |
| 14742 // the string changed without failing. | 14742 // the string changed without failing. |
| 14743 UNINITIALIZED_TEST(RegExpStringModification) { | 14743 UNINITIALIZED_TEST(RegExpStringModification) { |
| 14744 v8::Locker lock(CcTest::default_isolate()); | 14744 v8::Locker lock(CcTest::isolate()); |
| 14745 v8::V8::Initialize(); | 14745 v8::V8::Initialize(); |
| 14746 v8::HandleScope scope(CcTest::default_isolate()); | 14746 v8::HandleScope scope(CcTest::isolate()); |
| 14747 Local<Context> local_env; | 14747 Local<Context> local_env; |
| 14748 { | 14748 { |
| 14749 LocalContext env; | 14749 LocalContext env; |
| 14750 local_env = env.local(); | 14750 local_env = env.local(); |
| 14751 } | 14751 } |
| 14752 | 14752 |
| 14753 // Local context should still be live. | 14753 // Local context should still be live. |
| 14754 CHECK(!local_env.IsEmpty()); | 14754 CHECK(!local_env.IsEmpty()); |
| 14755 local_env->Enter(); | 14755 local_env->Enter(); |
| 14756 | 14756 |
| (...skipping 2336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17093 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17093 env->Global()->Set(v8_str("get_stack_limit"), fun); |
| 17094 CompileRun("get_stack_limit();"); | 17094 CompileRun("get_stack_limit();"); |
| 17095 | 17095 |
| 17096 CHECK(stack_limit == set_limit); | 17096 CHECK(stack_limit == set_limit); |
| 17097 } | 17097 } |
| 17098 | 17098 |
| 17099 | 17099 |
| 17100 TEST(SetResourceConstraintsInThread) { | 17100 TEST(SetResourceConstraintsInThread) { |
| 17101 uint32_t* set_limit; | 17101 uint32_t* set_limit; |
| 17102 { | 17102 { |
| 17103 v8::Locker locker(CcTest::default_isolate()); | 17103 v8::Locker locker(CcTest::isolate()); |
| 17104 set_limit = ComputeStackLimit(stack_breathing_room); | 17104 set_limit = ComputeStackLimit(stack_breathing_room); |
| 17105 | 17105 |
| 17106 // Set stack limit. | 17106 // Set stack limit. |
| 17107 v8::ResourceConstraints constraints; | 17107 v8::ResourceConstraints constraints; |
| 17108 constraints.set_stack_limit(set_limit); | 17108 constraints.set_stack_limit(set_limit); |
| 17109 CHECK(v8::SetResourceConstraints(&constraints)); | 17109 CHECK(v8::SetResourceConstraints(&constraints)); |
| 17110 | 17110 |
| 17111 // Execute a script. | 17111 // Execute a script. |
| 17112 v8::HandleScope scope(CcTest::default_isolate()); | 17112 v8::HandleScope scope(CcTest::isolate()); |
| 17113 LocalContext env; | 17113 LocalContext env; |
| 17114 Local<v8::FunctionTemplate> fun_templ = | 17114 Local<v8::FunctionTemplate> fun_templ = |
| 17115 v8::FunctionTemplate::New(GetStackLimitCallback); | 17115 v8::FunctionTemplate::New(GetStackLimitCallback); |
| 17116 Local<Function> fun = fun_templ->GetFunction(); | 17116 Local<Function> fun = fun_templ->GetFunction(); |
| 17117 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17117 env->Global()->Set(v8_str("get_stack_limit"), fun); |
| 17118 CompileRun("get_stack_limit();"); | 17118 CompileRun("get_stack_limit();"); |
| 17119 | 17119 |
| 17120 CHECK(stack_limit == set_limit); | 17120 CHECK(stack_limit == set_limit); |
| 17121 } | 17121 } |
| 17122 { | 17122 { |
| 17123 v8::Locker locker(CcTest::default_isolate()); | 17123 v8::Locker locker(CcTest::isolate()); |
| 17124 CHECK(stack_limit == set_limit); | 17124 CHECK(stack_limit == set_limit); |
| 17125 } | 17125 } |
| 17126 } | 17126 } |
| 17127 | 17127 |
| 17128 | 17128 |
| 17129 THREADED_TEST(GetHeapStatistics) { | 17129 THREADED_TEST(GetHeapStatistics) { |
| 17130 LocalContext c1; | 17130 LocalContext c1; |
| 17131 v8::HandleScope scope(c1->GetIsolate()); | 17131 v8::HandleScope scope(c1->GetIsolate()); |
| 17132 v8::HeapStatistics heap_statistics; | 17132 v8::HeapStatistics heap_statistics; |
| 17133 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); | 17133 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); |
| (...skipping 3459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20593 Local<Object> data2 = v8::Object::New(); | 20593 Local<Object> data2 = v8::Object::New(); |
| 20594 function_new_expected_env = data2; | 20594 function_new_expected_env = data2; |
| 20595 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 20595 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); |
| 20596 CHECK(!func2->IsNull()); | 20596 CHECK(!func2->IsNull()); |
| 20597 CHECK_NE(func, func2); | 20597 CHECK_NE(func, func2); |
| 20598 env->Global()->Set(v8_str("func2"), func2); | 20598 env->Global()->Set(v8_str("func2"), func2); |
| 20599 Local<Value> result2 = CompileRun("func2();"); | 20599 Local<Value> result2 = CompileRun("func2();"); |
| 20600 CHECK_EQ(v8::Integer::New(17, isolate), result2); | 20600 CHECK_EQ(v8::Integer::New(17, isolate), result2); |
| 20601 } | 20601 } |
| 20602 | 20602 |
| OLD | NEW |