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 10995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11006 RegisterThreadedTest::nth(current_)->fuzzer_->gate_->Signal(); | 11006 RegisterThreadedTest::nth(current_)->fuzzer_->gate_->Signal(); |
11007 return true; | 11007 return true; |
11008 } | 11008 } |
11009 | 11009 |
11010 | 11010 |
11011 void ApiTestFuzzer::Run() { | 11011 void ApiTestFuzzer::Run() { |
11012 // When it is our turn... | 11012 // When it is our turn... |
11013 gate_->Wait(); | 11013 gate_->Wait(); |
11014 { | 11014 { |
11015 // ... get the V8 lock and start running the test. | 11015 // ... get the V8 lock and start running the test. |
11016 v8::Locker locker; | 11016 v8::Locker locker(CcTest::default_isolate()); |
11017 CallTest(); | 11017 CallTest(); |
11018 } | 11018 } |
11019 // This test finished. | 11019 // This test finished. |
11020 active_ = false; | 11020 active_ = false; |
11021 active_tests_--; | 11021 active_tests_--; |
11022 // If it was the last then signal that fact. | 11022 // If it was the last then signal that fact. |
11023 if (active_tests_ == 0) { | 11023 if (active_tests_ == 0) { |
11024 all_tests_done_->Signal(); | 11024 all_tests_done_->Signal(); |
11025 } else { | 11025 } else { |
11026 // Otherwise select a new test and start that. | 11026 // Otherwise select a new test and start that. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11070 linear_congruential_generator += 1013904223u; | 11070 linear_congruential_generator += 1013904223u; |
11071 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_); | 11071 } while (!RegisterThreadedTest::nth(next_test)->fuzzer_->active_); |
11072 return next_test; | 11072 return next_test; |
11073 } | 11073 } |
11074 | 11074 |
11075 | 11075 |
11076 void ApiTestFuzzer::ContextSwitch() { | 11076 void ApiTestFuzzer::ContextSwitch() { |
11077 // If the new thread is the same as the current thread there is nothing to do. | 11077 // If the new thread is the same as the current thread there is nothing to do. |
11078 if (NextThread()) { | 11078 if (NextThread()) { |
11079 // Now it can start. | 11079 // Now it can start. |
11080 v8::Unlocker unlocker; | 11080 v8::Unlocker unlocker(CcTest::default_isolate()); |
11081 // Wait till someone starts us again. | 11081 // Wait till someone starts us again. |
11082 gate_->Wait(); | 11082 gate_->Wait(); |
11083 // And we're off. | 11083 // And we're off. |
11084 } | 11084 } |
11085 } | 11085 } |
11086 | 11086 |
11087 | 11087 |
11088 void ApiTestFuzzer::TearDown() { | 11088 void ApiTestFuzzer::TearDown() { |
11089 fuzzing_ = false; | 11089 fuzzing_ = false; |
11090 for (int i = 0; i < RegisterThreadedTest::count(); i++) { | 11090 for (int i = 0; i < RegisterThreadedTest::count(); i++) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11122 void ApiTestFuzzer::CallTest() { | 11122 void ApiTestFuzzer::CallTest() { |
11123 if (kLogThreading) | 11123 if (kLogThreading) |
11124 printf("Start test %d\n", test_number_); | 11124 printf("Start test %d\n", test_number_); |
11125 CallTestNumber(test_number_); | 11125 CallTestNumber(test_number_); |
11126 if (kLogThreading) | 11126 if (kLogThreading) |
11127 printf("End test %d\n", test_number_); | 11127 printf("End test %d\n", test_number_); |
11128 } | 11128 } |
11129 | 11129 |
11130 | 11130 |
11131 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) { | 11131 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) { |
11132 CHECK(v8::Locker::IsLocked()); | 11132 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); |
11133 ApiTestFuzzer::Fuzz(); | 11133 ApiTestFuzzer::Fuzz(); |
11134 v8::Unlocker unlocker; | 11134 v8::Unlocker unlocker(CcTest::default_isolate()); |
11135 const char* code = "throw 7;"; | 11135 const char* code = "throw 7;"; |
11136 { | 11136 { |
11137 v8::Locker nested_locker; | 11137 v8::Locker nested_locker(CcTest::default_isolate()); |
11138 v8::HandleScope scope; | 11138 v8::HandleScope scope; |
11139 v8::Handle<Value> exception; | 11139 v8::Handle<Value> exception; |
11140 { v8::TryCatch try_catch; | 11140 { v8::TryCatch try_catch; |
11141 v8::Handle<Value> value = CompileRun(code); | 11141 v8::Handle<Value> value = CompileRun(code); |
11142 CHECK(value.IsEmpty()); | 11142 CHECK(value.IsEmpty()); |
11143 CHECK(try_catch.HasCaught()); | 11143 CHECK(try_catch.HasCaught()); |
11144 // Make sure to wrap the exception in a new handle because | 11144 // Make sure to wrap the exception in a new handle because |
11145 // the handle returned from the TryCatch is destroyed | 11145 // the handle returned from the TryCatch is destroyed |
11146 // when the TryCatch is destroyed. | 11146 // when the TryCatch is destroyed. |
11147 exception = Local<Value>::New(try_catch.Exception()); | 11147 exception = Local<Value>::New(try_catch.Exception()); |
11148 } | 11148 } |
11149 return v8::ThrowException(exception); | 11149 return v8::ThrowException(exception); |
11150 } | 11150 } |
11151 } | 11151 } |
11152 | 11152 |
11153 | 11153 |
11154 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) { | 11154 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) { |
11155 CHECK(v8::Locker::IsLocked()); | 11155 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); |
11156 ApiTestFuzzer::Fuzz(); | 11156 ApiTestFuzzer::Fuzz(); |
11157 v8::Unlocker unlocker; | 11157 v8::Unlocker unlocker(CcTest::default_isolate()); |
11158 const char* code = "throw 7;"; | 11158 const char* code = "throw 7;"; |
11159 { | 11159 { |
11160 v8::Locker nested_locker; | 11160 v8::Locker nested_locker(CcTest::default_isolate()); |
11161 v8::HandleScope scope; | 11161 v8::HandleScope scope; |
11162 v8::Handle<Value> value = CompileRun(code); | 11162 v8::Handle<Value> value = CompileRun(code); |
11163 CHECK(value.IsEmpty()); | 11163 CHECK(value.IsEmpty()); |
11164 return v8_str("foo"); | 11164 return v8_str("foo"); |
11165 } | 11165 } |
11166 } | 11166 } |
11167 | 11167 |
11168 | 11168 |
11169 // These are locking tests that don't need to be run again | 11169 // These are locking tests that don't need to be run again |
11170 // as part of the locking aggregation tests. | 11170 // as part of the locking aggregation tests. |
11171 TEST(NestedLockers) { | 11171 TEST(NestedLockers) { |
11172 v8::Locker locker; | 11172 v8::Locker locker(CcTest::default_isolate()); |
11173 CHECK(v8::Locker::IsLocked()); | 11173 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); |
11174 v8::HandleScope scope; | 11174 v8::HandleScope scope; |
11175 LocalContext env; | 11175 LocalContext env; |
11176 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); | 11176 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); |
11177 Local<Function> fun = fun_templ->GetFunction(); | 11177 Local<Function> fun = fun_templ->GetFunction(); |
11178 env->Global()->Set(v8_str("throw_in_js"), fun); | 11178 env->Global()->Set(v8_str("throw_in_js"), fun); |
11179 Local<Script> script = v8_compile("(function () {" | 11179 Local<Script> script = v8_compile("(function () {" |
11180 " try {" | 11180 " try {" |
11181 " throw_in_js();" | 11181 " throw_in_js();" |
11182 " return 42;" | 11182 " return 42;" |
11183 " } catch (e) {" | 11183 " } catch (e) {" |
11184 " return e * 13;" | 11184 " return e * 13;" |
11185 " }" | 11185 " }" |
11186 "})();"); | 11186 "})();"); |
11187 CHECK_EQ(91, script->Run()->Int32Value()); | 11187 CHECK_EQ(91, script->Run()->Int32Value()); |
11188 } | 11188 } |
11189 | 11189 |
11190 | 11190 |
11191 // These are locking tests that don't need to be run again | 11191 // These are locking tests that don't need to be run again |
11192 // as part of the locking aggregation tests. | 11192 // as part of the locking aggregation tests. |
11193 TEST(NestedLockersNoTryCatch) { | 11193 TEST(NestedLockersNoTryCatch) { |
11194 v8::Locker locker; | 11194 v8::Locker locker(CcTest::default_isolate()); |
11195 v8::HandleScope scope; | 11195 v8::HandleScope scope; |
11196 LocalContext env; | 11196 LocalContext env; |
11197 Local<v8::FunctionTemplate> fun_templ = | 11197 Local<v8::FunctionTemplate> fun_templ = |
11198 v8::FunctionTemplate::New(ThrowInJSNoCatch); | 11198 v8::FunctionTemplate::New(ThrowInJSNoCatch); |
11199 Local<Function> fun = fun_templ->GetFunction(); | 11199 Local<Function> fun = fun_templ->GetFunction(); |
11200 env->Global()->Set(v8_str("throw_in_js"), fun); | 11200 env->Global()->Set(v8_str("throw_in_js"), fun); |
11201 Local<Script> script = v8_compile("(function () {" | 11201 Local<Script> script = v8_compile("(function () {" |
11202 " try {" | 11202 " try {" |
11203 " throw_in_js();" | 11203 " throw_in_js();" |
11204 " return 42;" | 11204 " return 42;" |
11205 " } catch (e) {" | 11205 " } catch (e) {" |
11206 " return e * 13;" | 11206 " return e * 13;" |
11207 " }" | 11207 " }" |
11208 "})();"); | 11208 "})();"); |
11209 CHECK_EQ(91, script->Run()->Int32Value()); | 11209 CHECK_EQ(91, script->Run()->Int32Value()); |
11210 } | 11210 } |
11211 | 11211 |
11212 | 11212 |
11213 THREADED_TEST(RecursiveLocking) { | 11213 THREADED_TEST(RecursiveLocking) { |
11214 v8::Locker locker; | 11214 v8::Locker locker(CcTest::default_isolate()); |
11215 { | 11215 { |
11216 v8::Locker locker2; | 11216 v8::Locker locker2(CcTest::default_isolate()); |
11217 CHECK(v8::Locker::IsLocked()); | 11217 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); |
11218 } | 11218 } |
11219 } | 11219 } |
11220 | 11220 |
11221 | 11221 |
11222 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) { | 11222 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) { |
11223 ApiTestFuzzer::Fuzz(); | 11223 ApiTestFuzzer::Fuzz(); |
11224 v8::Unlocker unlocker; | 11224 v8::Unlocker unlocker(CcTest::default_isolate()); |
11225 return v8::Undefined(); | 11225 return v8::Undefined(); |
11226 } | 11226 } |
11227 | 11227 |
11228 | 11228 |
11229 THREADED_TEST(LockUnlockLock) { | 11229 THREADED_TEST(LockUnlockLock) { |
11230 { | 11230 { |
11231 v8::Locker locker; | 11231 v8::Locker locker(CcTest::default_isolate()); |
11232 v8::HandleScope scope; | 11232 v8::HandleScope scope; |
11233 LocalContext env; | 11233 LocalContext env; |
11234 Local<v8::FunctionTemplate> fun_templ = | 11234 Local<v8::FunctionTemplate> fun_templ = |
11235 v8::FunctionTemplate::New(UnlockForAMoment); | 11235 v8::FunctionTemplate::New(UnlockForAMoment); |
11236 Local<Function> fun = fun_templ->GetFunction(); | 11236 Local<Function> fun = fun_templ->GetFunction(); |
11237 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 11237 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
11238 Local<Script> script = v8_compile("(function () {" | 11238 Local<Script> script = v8_compile("(function () {" |
11239 " unlock_for_a_moment();" | 11239 " unlock_for_a_moment();" |
11240 " return 42;" | 11240 " return 42;" |
11241 "})();"); | 11241 "})();"); |
11242 CHECK_EQ(42, script->Run()->Int32Value()); | 11242 CHECK_EQ(42, script->Run()->Int32Value()); |
11243 } | 11243 } |
11244 { | 11244 { |
11245 v8::Locker locker; | 11245 v8::Locker locker(CcTest::default_isolate()); |
11246 v8::HandleScope scope; | 11246 v8::HandleScope scope; |
11247 LocalContext env; | 11247 LocalContext env; |
11248 Local<v8::FunctionTemplate> fun_templ = | 11248 Local<v8::FunctionTemplate> fun_templ = |
11249 v8::FunctionTemplate::New(UnlockForAMoment); | 11249 v8::FunctionTemplate::New(UnlockForAMoment); |
11250 Local<Function> fun = fun_templ->GetFunction(); | 11250 Local<Function> fun = fun_templ->GetFunction(); |
11251 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 11251 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
11252 Local<Script> script = v8_compile("(function () {" | 11252 Local<Script> script = v8_compile("(function () {" |
11253 " unlock_for_a_moment();" | 11253 " unlock_for_a_moment();" |
11254 " return 42;" | 11254 " return 42;" |
11255 "})();"); | 11255 "})();"); |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12486 gc_count_ = 0; | 12486 gc_count_ = 0; |
12487 gc_during_regexp_ = 0; | 12487 gc_during_regexp_ = 0; |
12488 regexp_success_ = false; | 12488 regexp_success_ = false; |
12489 gc_success_ = false; | 12489 gc_success_ = false; |
12490 GCThread gc_thread(this); | 12490 GCThread gc_thread(this); |
12491 gc_thread.Start(); | 12491 gc_thread.Start(); |
12492 v8::Locker::StartPreemption(1); | 12492 v8::Locker::StartPreemption(1); |
12493 | 12493 |
12494 LongRunningRegExp(); | 12494 LongRunningRegExp(); |
12495 { | 12495 { |
12496 v8::Unlocker unlock; | 12496 v8::Unlocker unlock(CcTest::default_isolate()); |
12497 gc_thread.Join(); | 12497 gc_thread.Join(); |
12498 } | 12498 } |
12499 v8::Locker::StopPreemption(); | 12499 v8::Locker::StopPreemption(); |
12500 CHECK(regexp_success_); | 12500 CHECK(regexp_success_); |
12501 CHECK(gc_success_); | 12501 CHECK(gc_success_); |
12502 } | 12502 } |
12503 | 12503 |
12504 private: | 12504 private: |
12505 // Number of garbage collections required. | 12505 // Number of garbage collections required. |
12506 static const int kRequiredGCs = 5; | 12506 static const int kRequiredGCs = 5; |
12507 | 12507 |
12508 class GCThread : public i::Thread { | 12508 class GCThread : public i::Thread { |
12509 public: | 12509 public: |
12510 explicit GCThread(RegExpInterruptTest* test) | 12510 explicit GCThread(RegExpInterruptTest* test) |
12511 : Thread("GCThread"), test_(test) {} | 12511 : Thread("GCThread"), test_(test) {} |
12512 virtual void Run() { | 12512 virtual void Run() { |
12513 test_->CollectGarbage(); | 12513 test_->CollectGarbage(); |
12514 } | 12514 } |
12515 private: | 12515 private: |
12516 RegExpInterruptTest* test_; | 12516 RegExpInterruptTest* test_; |
12517 }; | 12517 }; |
12518 | 12518 |
12519 void CollectGarbage() { | 12519 void CollectGarbage() { |
12520 block_->Wait(); | 12520 block_->Wait(); |
12521 while (gc_during_regexp_ < kRequiredGCs) { | 12521 while (gc_during_regexp_ < kRequiredGCs) { |
12522 { | 12522 { |
12523 v8::Locker lock; | 12523 v8::Locker lock(CcTest::default_isolate()); |
12524 // TODO(lrn): Perhaps create some garbage before collecting. | 12524 // TODO(lrn): Perhaps create some garbage before collecting. |
12525 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12525 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
12526 gc_count_++; | 12526 gc_count_++; |
12527 } | 12527 } |
12528 i::OS::Sleep(1); | 12528 i::OS::Sleep(1); |
12529 } | 12529 } |
12530 gc_success_ = true; | 12530 gc_success_ = true; |
12531 } | 12531 } |
12532 | 12532 |
12533 void LongRunningRegExp() { | 12533 void LongRunningRegExp() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12573 int gc_count_; | 12573 int gc_count_; |
12574 int gc_during_regexp_; | 12574 int gc_during_regexp_; |
12575 bool regexp_success_; | 12575 bool regexp_success_; |
12576 bool gc_success_; | 12576 bool gc_success_; |
12577 }; | 12577 }; |
12578 | 12578 |
12579 | 12579 |
12580 // Test that a regular expression execution can be interrupted and | 12580 // Test that a regular expression execution can be interrupted and |
12581 // survive a garbage collection. | 12581 // survive a garbage collection. |
12582 TEST(RegExpInterruption) { | 12582 TEST(RegExpInterruption) { |
12583 v8::Locker lock; | 12583 v8::Locker lock(CcTest::default_isolate()); |
12584 v8::V8::Initialize(); | 12584 v8::V8::Initialize(); |
12585 v8::HandleScope scope; | 12585 v8::HandleScope scope; |
12586 Local<Context> local_env; | 12586 Local<Context> local_env; |
12587 { | 12587 { |
12588 LocalContext env; | 12588 LocalContext env; |
12589 local_env = env.local(); | 12589 local_env = env.local(); |
12590 } | 12590 } |
12591 | 12591 |
12592 // Local context should still be live. | 12592 // Local context should still be live. |
12593 CHECK(!local_env.IsEmpty()); | 12593 CHECK(!local_env.IsEmpty()); |
(...skipping 15 matching lines...) Expand all Loading... |
12609 gc_count_ = 0; | 12609 gc_count_ = 0; |
12610 gc_during_apply_ = 0; | 12610 gc_during_apply_ = 0; |
12611 apply_success_ = false; | 12611 apply_success_ = false; |
12612 gc_success_ = false; | 12612 gc_success_ = false; |
12613 GCThread gc_thread(this); | 12613 GCThread gc_thread(this); |
12614 gc_thread.Start(); | 12614 gc_thread.Start(); |
12615 v8::Locker::StartPreemption(1); | 12615 v8::Locker::StartPreemption(1); |
12616 | 12616 |
12617 LongRunningApply(); | 12617 LongRunningApply(); |
12618 { | 12618 { |
12619 v8::Unlocker unlock; | 12619 v8::Unlocker unlock(CcTest::default_isolate()); |
12620 gc_thread.Join(); | 12620 gc_thread.Join(); |
12621 } | 12621 } |
12622 v8::Locker::StopPreemption(); | 12622 v8::Locker::StopPreemption(); |
12623 CHECK(apply_success_); | 12623 CHECK(apply_success_); |
12624 CHECK(gc_success_); | 12624 CHECK(gc_success_); |
12625 } | 12625 } |
12626 | 12626 |
12627 private: | 12627 private: |
12628 // Number of garbage collections required. | 12628 // Number of garbage collections required. |
12629 static const int kRequiredGCs = 2; | 12629 static const int kRequiredGCs = 2; |
12630 | 12630 |
12631 class GCThread : public i::Thread { | 12631 class GCThread : public i::Thread { |
12632 public: | 12632 public: |
12633 explicit GCThread(ApplyInterruptTest* test) | 12633 explicit GCThread(ApplyInterruptTest* test) |
12634 : Thread("GCThread"), test_(test) {} | 12634 : Thread("GCThread"), test_(test) {} |
12635 virtual void Run() { | 12635 virtual void Run() { |
12636 test_->CollectGarbage(); | 12636 test_->CollectGarbage(); |
12637 } | 12637 } |
12638 private: | 12638 private: |
12639 ApplyInterruptTest* test_; | 12639 ApplyInterruptTest* test_; |
12640 }; | 12640 }; |
12641 | 12641 |
12642 void CollectGarbage() { | 12642 void CollectGarbage() { |
12643 block_->Wait(); | 12643 block_->Wait(); |
12644 while (gc_during_apply_ < kRequiredGCs) { | 12644 while (gc_during_apply_ < kRequiredGCs) { |
12645 { | 12645 { |
12646 v8::Locker lock; | 12646 v8::Locker lock(CcTest::default_isolate()); |
12647 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12647 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
12648 gc_count_++; | 12648 gc_count_++; |
12649 } | 12649 } |
12650 i::OS::Sleep(1); | 12650 i::OS::Sleep(1); |
12651 } | 12651 } |
12652 gc_success_ = true; | 12652 gc_success_ = true; |
12653 } | 12653 } |
12654 | 12654 |
12655 void LongRunningApply() { | 12655 void LongRunningApply() { |
12656 block_->Signal(); | 12656 block_->Signal(); |
(...skipping 25 matching lines...) Expand all Loading... |
12682 int gc_count_; | 12682 int gc_count_; |
12683 int gc_during_apply_; | 12683 int gc_during_apply_; |
12684 bool apply_success_; | 12684 bool apply_success_; |
12685 bool gc_success_; | 12685 bool gc_success_; |
12686 }; | 12686 }; |
12687 | 12687 |
12688 | 12688 |
12689 // Test that nothing bad happens if we get a preemption just when we were | 12689 // Test that nothing bad happens if we get a preemption just when we were |
12690 // about to do an apply(). | 12690 // about to do an apply(). |
12691 TEST(ApplyInterruption) { | 12691 TEST(ApplyInterruption) { |
12692 v8::Locker lock; | 12692 v8::Locker lock(CcTest::default_isolate()); |
12693 v8::V8::Initialize(); | 12693 v8::V8::Initialize(); |
12694 v8::HandleScope scope; | 12694 v8::HandleScope scope; |
12695 Local<Context> local_env; | 12695 Local<Context> local_env; |
12696 { | 12696 { |
12697 LocalContext env; | 12697 LocalContext env; |
12698 local_env = env.local(); | 12698 local_env = env.local(); |
12699 } | 12699 } |
12700 | 12700 |
12701 // Local context should still be live. | 12701 // Local context should still be live. |
12702 CHECK(!local_env.IsEmpty()); | 12702 CHECK(!local_env.IsEmpty()); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12920 *input_name, | 12920 *input_name, |
12921 *input_, | 12921 *input_, |
12922 NONE, | 12922 NONE, |
12923 i::kNonStrictMode)->ToObjectChecked(); | 12923 i::kNonStrictMode)->ToObjectChecked(); |
12924 | 12924 |
12925 MorphThread morph_thread(this); | 12925 MorphThread morph_thread(this); |
12926 morph_thread.Start(); | 12926 morph_thread.Start(); |
12927 v8::Locker::StartPreemption(1); | 12927 v8::Locker::StartPreemption(1); |
12928 LongRunningRegExp(); | 12928 LongRunningRegExp(); |
12929 { | 12929 { |
12930 v8::Unlocker unlock; | 12930 v8::Unlocker unlock(CcTest::default_isolate()); |
12931 morph_thread.Join(); | 12931 morph_thread.Join(); |
12932 } | 12932 } |
12933 v8::Locker::StopPreemption(); | 12933 v8::Locker::StopPreemption(); |
12934 CHECK(regexp_success_); | 12934 CHECK(regexp_success_); |
12935 CHECK(morph_success_); | 12935 CHECK(morph_success_); |
12936 } | 12936 } |
12937 | 12937 |
12938 private: | 12938 private: |
12939 // Number of string modifications required. | 12939 // Number of string modifications required. |
12940 static const int kRequiredModifications = 5; | 12940 static const int kRequiredModifications = 5; |
12941 static const int kMaxModifications = 100; | 12941 static const int kMaxModifications = 100; |
12942 | 12942 |
12943 class MorphThread : public i::Thread { | 12943 class MorphThread : public i::Thread { |
12944 public: | 12944 public: |
12945 explicit MorphThread(RegExpStringModificationTest* test) | 12945 explicit MorphThread(RegExpStringModificationTest* test) |
12946 : Thread("MorphThread"), test_(test) {} | 12946 : Thread("MorphThread"), test_(test) {} |
12947 virtual void Run() { | 12947 virtual void Run() { |
12948 test_->MorphString(); | 12948 test_->MorphString(); |
12949 } | 12949 } |
12950 private: | 12950 private: |
12951 RegExpStringModificationTest* test_; | 12951 RegExpStringModificationTest* test_; |
12952 }; | 12952 }; |
12953 | 12953 |
12954 void MorphString() { | 12954 void MorphString() { |
12955 block_->Wait(); | 12955 block_->Wait(); |
12956 while (morphs_during_regexp_ < kRequiredModifications && | 12956 while (morphs_during_regexp_ < kRequiredModifications && |
12957 morphs_ < kMaxModifications) { | 12957 morphs_ < kMaxModifications) { |
12958 { | 12958 { |
12959 v8::Locker lock; | 12959 v8::Locker lock(CcTest::default_isolate()); |
12960 // Swap string between ascii and two-byte representation. | 12960 // Swap string between ascii and two-byte representation. |
12961 i::String* string = *input_; | 12961 i::String* string = *input_; |
12962 MorphAString(string, &ascii_resource_, &uc16_resource_); | 12962 MorphAString(string, &ascii_resource_, &uc16_resource_); |
12963 morphs_++; | 12963 morphs_++; |
12964 } | 12964 } |
12965 i::OS::Sleep(1); | 12965 i::OS::Sleep(1); |
12966 } | 12966 } |
12967 morph_success_ = true; | 12967 morph_success_ = true; |
12968 } | 12968 } |
12969 | 12969 |
(...skipping 27 matching lines...) Expand all Loading... |
12997 bool morph_success_; | 12997 bool morph_success_; |
12998 i::Handle<i::String> input_; | 12998 i::Handle<i::String> input_; |
12999 AsciiVectorResource ascii_resource_; | 12999 AsciiVectorResource ascii_resource_; |
13000 UC16VectorResource uc16_resource_; | 13000 UC16VectorResource uc16_resource_; |
13001 }; | 13001 }; |
13002 | 13002 |
13003 | 13003 |
13004 // Test that a regular expression execution can be interrupted and | 13004 // Test that a regular expression execution can be interrupted and |
13005 // the string changed without failing. | 13005 // the string changed without failing. |
13006 TEST(RegExpStringModification) { | 13006 TEST(RegExpStringModification) { |
13007 v8::Locker lock; | 13007 v8::Locker lock(CcTest::default_isolate()); |
13008 v8::V8::Initialize(); | 13008 v8::V8::Initialize(); |
13009 v8::HandleScope scope; | 13009 v8::HandleScope scope; |
13010 Local<Context> local_env; | 13010 Local<Context> local_env; |
13011 { | 13011 { |
13012 LocalContext env; | 13012 LocalContext env; |
13013 local_env = env.local(); | 13013 local_env = env.local(); |
13014 } | 13014 } |
13015 | 13015 |
13016 // Local context should still be live. | 13016 // Local context should still be live. |
13017 CHECK(!local_env.IsEmpty()); | 13017 CHECK(!local_env.IsEmpty()); |
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15130 env->Global()->Set(v8_str("get_stack_limit"), fun); | 15130 env->Global()->Set(v8_str("get_stack_limit"), fun); |
15131 CompileRun("get_stack_limit();"); | 15131 CompileRun("get_stack_limit();"); |
15132 | 15132 |
15133 CHECK(stack_limit == set_limit); | 15133 CHECK(stack_limit == set_limit); |
15134 } | 15134 } |
15135 | 15135 |
15136 | 15136 |
15137 TEST(SetResourceConstraintsInThread) { | 15137 TEST(SetResourceConstraintsInThread) { |
15138 uint32_t* set_limit; | 15138 uint32_t* set_limit; |
15139 { | 15139 { |
15140 v8::Locker locker; | 15140 v8::Locker locker(CcTest::default_isolate()); |
15141 static const int K = 1024; | 15141 static const int K = 1024; |
15142 set_limit = ComputeStackLimit(128 * K); | 15142 set_limit = ComputeStackLimit(128 * K); |
15143 | 15143 |
15144 // Set stack limit. | 15144 // Set stack limit. |
15145 v8::ResourceConstraints constraints; | 15145 v8::ResourceConstraints constraints; |
15146 constraints.set_stack_limit(set_limit); | 15146 constraints.set_stack_limit(set_limit); |
15147 CHECK(v8::SetResourceConstraints(&constraints)); | 15147 CHECK(v8::SetResourceConstraints(&constraints)); |
15148 | 15148 |
15149 // Execute a script. | 15149 // Execute a script. |
15150 v8::HandleScope scope; | 15150 v8::HandleScope scope; |
15151 LocalContext env; | 15151 LocalContext env; |
15152 Local<v8::FunctionTemplate> fun_templ = | 15152 Local<v8::FunctionTemplate> fun_templ = |
15153 v8::FunctionTemplate::New(GetStackLimitCallback); | 15153 v8::FunctionTemplate::New(GetStackLimitCallback); |
15154 Local<Function> fun = fun_templ->GetFunction(); | 15154 Local<Function> fun = fun_templ->GetFunction(); |
15155 env->Global()->Set(v8_str("get_stack_limit"), fun); | 15155 env->Global()->Set(v8_str("get_stack_limit"), fun); |
15156 CompileRun("get_stack_limit();"); | 15156 CompileRun("get_stack_limit();"); |
15157 | 15157 |
15158 CHECK(stack_limit == set_limit); | 15158 CHECK(stack_limit == set_limit); |
15159 } | 15159 } |
15160 { | 15160 { |
15161 v8::Locker locker; | 15161 v8::Locker locker(CcTest::default_isolate()); |
15162 CHECK(stack_limit == set_limit); | 15162 CHECK(stack_limit == set_limit); |
15163 } | 15163 } |
15164 } | 15164 } |
15165 | 15165 |
15166 | 15166 |
15167 THREADED_TEST(GetHeapStatistics) { | 15167 THREADED_TEST(GetHeapStatistics) { |
15168 v8::HandleScope scope; | 15168 v8::HandleScope scope; |
15169 LocalContext c1; | 15169 LocalContext c1; |
15170 v8::HeapStatistics heap_statistics; | 15170 v8::HeapStatistics heap_statistics; |
15171 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); | 15171 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); |
(...skipping 2966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18138 | 18138 |
18139 i::Semaphore* sem_; | 18139 i::Semaphore* sem_; |
18140 volatile int sem_value_; | 18140 volatile int sem_value_; |
18141 }; | 18141 }; |
18142 | 18142 |
18143 | 18143 |
18144 THREADED_TEST(SemaphoreInterruption) { | 18144 THREADED_TEST(SemaphoreInterruption) { |
18145 ThreadInterruptTest().RunTest(); | 18145 ThreadInterruptTest().RunTest(); |
18146 } | 18146 } |
18147 #endif // WIN32 | 18147 #endif // WIN32 |
OLD | NEW |