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