| OLD | NEW |
| 1 // Copyright 2007-2011 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2011 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 threads[i]->Join(); | 200 threads[i]->Join(); |
| 201 } | 201 } |
| 202 for (int i = 0; i < threads.length(); i++) { | 202 for (int i = 0; i < threads.length(); i++) { |
| 203 delete threads[i]; | 203 delete threads[i]; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| 208 // Run many threads all locking on the same isolate | 208 // Run many threads all locking on the same isolate |
| 209 TEST(IsolateLockingStress) { | 209 TEST(IsolateLockingStress) { |
| 210 #ifdef V8_TARGET_ARCH_MIPS | 210 #if V8_TARGET_ARCH_MIPS |
| 211 const int kNThreads = 50; | 211 const int kNThreads = 50; |
| 212 #else | 212 #else |
| 213 const int kNThreads = 100; | 213 const int kNThreads = 100; |
| 214 #endif | 214 #endif |
| 215 i::List<JoinableThread*> threads(kNThreads); | 215 i::List<JoinableThread*> threads(kNThreads); |
| 216 v8::Isolate* isolate = v8::Isolate::New(); | 216 v8::Isolate* isolate = v8::Isolate::New(); |
| 217 for (int i = 0; i < kNThreads; i++) { | 217 for (int i = 0; i < kNThreads; i++) { |
| 218 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); | 218 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); |
| 219 } | 219 } |
| 220 StartJoinAndDeleteThreads(threads); | 220 StartJoinAndDeleteThreads(threads); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 237 CHECK_EQ(isolate, v8::internal::Isolate::Current()); | 237 CHECK_EQ(isolate, v8::internal::Isolate::Current()); |
| 238 CalcFibAndCheck(); | 238 CalcFibAndCheck(); |
| 239 } | 239 } |
| 240 isolate->Dispose(); | 240 isolate->Dispose(); |
| 241 } | 241 } |
| 242 private: | 242 private: |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 // Run many threads each accessing its own isolate without locking | 245 // Run many threads each accessing its own isolate without locking |
| 246 TEST(MultithreadedParallelIsolates) { | 246 TEST(MultithreadedParallelIsolates) { |
| 247 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 247 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 248 const int kNThreads = 10; | 248 const int kNThreads = 10; |
| 249 #else | 249 #else |
| 250 const int kNThreads = 50; | 250 const int kNThreads = 50; |
| 251 #endif | 251 #endif |
| 252 i::List<JoinableThread*> threads(kNThreads); | 252 i::List<JoinableThread*> threads(kNThreads); |
| 253 for (int i = 0; i < kNThreads; i++) { | 253 for (int i = 0; i < kNThreads; i++) { |
| 254 threads.Add(new IsolateNonlockingThread()); | 254 threads.Add(new IsolateNonlockingThread()); |
| 255 } | 255 } |
| 256 StartJoinAndDeleteThreads(threads); | 256 StartJoinAndDeleteThreads(threads); |
| 257 } | 257 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 275 v8::Locker another_lock(isolate_); | 275 v8::Locker another_lock(isolate_); |
| 276 CalcFibAndCheck(); | 276 CalcFibAndCheck(); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 private: | 279 private: |
| 280 v8::Isolate* isolate_; | 280 v8::Isolate* isolate_; |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 // Run many threads with nested locks | 283 // Run many threads with nested locks |
| 284 TEST(IsolateNestedLocking) { | 284 TEST(IsolateNestedLocking) { |
| 285 #ifdef V8_TARGET_ARCH_MIPS | 285 #if V8_TARGET_ARCH_MIPS |
| 286 const int kNThreads = 50; | 286 const int kNThreads = 50; |
| 287 #else | 287 #else |
| 288 const int kNThreads = 100; | 288 const int kNThreads = 100; |
| 289 #endif | 289 #endif |
| 290 v8::Isolate* isolate = v8::Isolate::New(); | 290 v8::Isolate* isolate = v8::Isolate::New(); |
| 291 i::List<JoinableThread*> threads(kNThreads); | 291 i::List<JoinableThread*> threads(kNThreads); |
| 292 for (int i = 0; i < kNThreads; i++) { | 292 for (int i = 0; i < kNThreads; i++) { |
| 293 threads.Add(new IsolateNestedLockingThread(isolate)); | 293 threads.Add(new IsolateNestedLockingThread(isolate)); |
| 294 } | 294 } |
| 295 StartJoinAndDeleteThreads(threads); | 295 StartJoinAndDeleteThreads(threads); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 316 CalcFibAndCheck(); | 316 CalcFibAndCheck(); |
| 317 threadB.Join(); | 317 threadB.Join(); |
| 318 } | 318 } |
| 319 private: | 319 private: |
| 320 v8::Isolate* isolate1_; | 320 v8::Isolate* isolate1_; |
| 321 v8::Isolate* isolate2_; | 321 v8::Isolate* isolate2_; |
| 322 }; | 322 }; |
| 323 | 323 |
| 324 // Run parallel threads that lock and access different isolates in parallel | 324 // Run parallel threads that lock and access different isolates in parallel |
| 325 TEST(SeparateIsolatesLocksNonexclusive) { | 325 TEST(SeparateIsolatesLocksNonexclusive) { |
| 326 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 326 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 327 const int kNThreads = 50; | 327 const int kNThreads = 50; |
| 328 #else | 328 #else |
| 329 const int kNThreads = 100; | 329 const int kNThreads = 100; |
| 330 #endif | 330 #endif |
| 331 v8::Isolate* isolate1 = v8::Isolate::New(); | 331 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 332 v8::Isolate* isolate2 = v8::Isolate::New(); | 332 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 333 i::List<JoinableThread*> threads(kNThreads); | 333 i::List<JoinableThread*> threads(kNThreads); |
| 334 for (int i = 0; i < kNThreads; i++) { | 334 for (int i = 0; i < kNThreads; i++) { |
| 335 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, | 335 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, |
| 336 isolate2)); | 336 isolate2)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 CalcFibAndCheck(); | 392 CalcFibAndCheck(); |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 | 395 |
| 396 private: | 396 private: |
| 397 v8::Isolate* isolate_; | 397 v8::Isolate* isolate_; |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 // Use unlocker inside of a Locker, multiple threads. | 400 // Use unlocker inside of a Locker, multiple threads. |
| 401 TEST(LockerUnlocker) { | 401 TEST(LockerUnlocker) { |
| 402 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 402 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 403 const int kNThreads = 50; | 403 const int kNThreads = 50; |
| 404 #else | 404 #else |
| 405 const int kNThreads = 100; | 405 const int kNThreads = 100; |
| 406 #endif | 406 #endif |
| 407 i::List<JoinableThread*> threads(kNThreads); | 407 i::List<JoinableThread*> threads(kNThreads); |
| 408 v8::Isolate* isolate = v8::Isolate::New(); | 408 v8::Isolate* isolate = v8::Isolate::New(); |
| 409 for (int i = 0; i < kNThreads; i++) { | 409 for (int i = 0; i < kNThreads; i++) { |
| 410 threads.Add(new LockerUnlockerThread(isolate)); | 410 threads.Add(new LockerUnlockerThread(isolate)); |
| 411 } | 411 } |
| 412 StartJoinAndDeleteThreads(threads); | 412 StartJoinAndDeleteThreads(threads); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 CalcFibAndCheck(); | 445 CalcFibAndCheck(); |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 private: | 449 private: |
| 450 v8::Isolate* isolate_; | 450 v8::Isolate* isolate_; |
| 451 }; | 451 }; |
| 452 | 452 |
| 453 // Use Unlocker inside two Lockers. | 453 // Use Unlocker inside two Lockers. |
| 454 TEST(LockTwiceAndUnlock) { | 454 TEST(LockTwiceAndUnlock) { |
| 455 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 455 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 456 const int kNThreads = 50; | 456 const int kNThreads = 50; |
| 457 #else | 457 #else |
| 458 const int kNThreads = 100; | 458 const int kNThreads = 100; |
| 459 #endif | 459 #endif |
| 460 i::List<JoinableThread*> threads(kNThreads); | 460 i::List<JoinableThread*> threads(kNThreads); |
| 461 v8::Isolate* isolate = v8::Isolate::New(); | 461 v8::Isolate* isolate = v8::Isolate::New(); |
| 462 for (int i = 0; i < kNThreads; i++) { | 462 for (int i = 0; i < kNThreads; i++) { |
| 463 threads.Add(new LockTwiceAndUnlockThread(isolate)); | 463 threads.Add(new LockTwiceAndUnlockThread(isolate)); |
| 464 } | 464 } |
| 465 StartJoinAndDeleteThreads(threads); | 465 StartJoinAndDeleteThreads(threads); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 private: | 569 private: |
| 570 v8::Isolate* isolate_; | 570 v8::Isolate* isolate_; |
| 571 v8::Persistent<v8::Context> context_; | 571 v8::Persistent<v8::Context> context_; |
| 572 }; | 572 }; |
| 573 | 573 |
| 574 // Locker inside an Unlocker inside a Locker. | 574 // Locker inside an Unlocker inside a Locker. |
| 575 TEST(LockUnlockLockMultithreaded) { | 575 TEST(LockUnlockLockMultithreaded) { |
| 576 #ifdef V8_TARGET_ARCH_MIPS | 576 #if V8_TARGET_ARCH_MIPS |
| 577 const int kNThreads = 50; | 577 const int kNThreads = 50; |
| 578 #else | 578 #else |
| 579 const int kNThreads = 100; | 579 const int kNThreads = 100; |
| 580 #endif | 580 #endif |
| 581 v8::Isolate* isolate = v8::Isolate::New(); | 581 v8::Isolate* isolate = v8::Isolate::New(); |
| 582 i::List<JoinableThread*> threads(kNThreads); | 582 i::List<JoinableThread*> threads(kNThreads); |
| 583 { | 583 { |
| 584 v8::Locker locker_(isolate); | 584 v8::Locker locker_(isolate); |
| 585 v8::Isolate::Scope isolate_scope(isolate); | 585 v8::Isolate::Scope isolate_scope(isolate); |
| 586 v8::HandleScope handle_scope(isolate); | 586 v8::HandleScope handle_scope(isolate); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 | 624 |
| 625 private: | 625 private: |
| 626 v8::Persistent<v8::Context> context_; | 626 v8::Persistent<v8::Context> context_; |
| 627 }; | 627 }; |
| 628 | 628 |
| 629 // Locker inside an Unlocker inside a Locker for default isolate. | 629 // Locker inside an Unlocker inside a Locker for default isolate. |
| 630 TEST(LockUnlockLockDefaultIsolateMultithreaded) { | 630 TEST(LockUnlockLockDefaultIsolateMultithreaded) { |
| 631 #ifdef V8_TARGET_ARCH_MIPS | 631 #if V8_TARGET_ARCH_MIPS |
| 632 const int kNThreads = 50; | 632 const int kNThreads = 50; |
| 633 #else | 633 #else |
| 634 const int kNThreads = 100; | 634 const int kNThreads = 100; |
| 635 #endif | 635 #endif |
| 636 Local<v8::Context> context; | 636 Local<v8::Context> context; |
| 637 i::List<JoinableThread*> threads(kNThreads); | 637 i::List<JoinableThread*> threads(kNThreads); |
| 638 { | 638 { |
| 639 v8::Locker locker_(CcTest::default_isolate()); | 639 v8::Locker locker_(CcTest::default_isolate()); |
| 640 v8::HandleScope handle_scope(CcTest::default_isolate()); | 640 v8::HandleScope handle_scope(CcTest::default_isolate()); |
| 641 context = v8::Context::New(CcTest::default_isolate()); | 641 context = v8::Context::New(CcTest::default_isolate()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 isolate->Dispose(); | 692 isolate->Dispose(); |
| 693 } | 693 } |
| 694 private: | 694 private: |
| 695 int count_; | 695 int count_; |
| 696 const char** extension_names_; | 696 const char** extension_names_; |
| 697 }; | 697 }; |
| 698 | 698 |
| 699 // Test installing extensions in separate isolates concurrently. | 699 // Test installing extensions in separate isolates concurrently. |
| 700 // http://code.google.com/p/v8/issues/detail?id=1821 | 700 // http://code.google.com/p/v8/issues/detail?id=1821 |
| 701 TEST(ExtensionsRegistration) { | 701 TEST(ExtensionsRegistration) { |
| 702 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 702 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 703 const int kNThreads = 10; | 703 const int kNThreads = 10; |
| 704 #else | 704 #else |
| 705 const int kNThreads = 40; | 705 const int kNThreads = 40; |
| 706 #endif | 706 #endif |
| 707 v8::RegisterExtension(new v8::Extension("test0", | 707 v8::RegisterExtension(new v8::Extension("test0", |
| 708 kSimpleExtensionSource)); | 708 kSimpleExtensionSource)); |
| 709 v8::RegisterExtension(new v8::Extension("test1", | 709 v8::RegisterExtension(new v8::Extension("test1", |
| 710 kSimpleExtensionSource)); | 710 kSimpleExtensionSource)); |
| 711 v8::RegisterExtension(new v8::Extension("test2", | 711 v8::RegisterExtension(new v8::Extension("test2", |
| 712 kSimpleExtensionSource)); | 712 kSimpleExtensionSource)); |
| 713 v8::RegisterExtension(new v8::Extension("test3", | 713 v8::RegisterExtension(new v8::Extension("test3", |
| 714 kSimpleExtensionSource)); | 714 kSimpleExtensionSource)); |
| 715 v8::RegisterExtension(new v8::Extension("test4", | 715 v8::RegisterExtension(new v8::Extension("test4", |
| 716 kSimpleExtensionSource)); | 716 kSimpleExtensionSource)); |
| 717 v8::RegisterExtension(new v8::Extension("test5", | 717 v8::RegisterExtension(new v8::Extension("test5", |
| 718 kSimpleExtensionSource)); | 718 kSimpleExtensionSource)); |
| 719 v8::RegisterExtension(new v8::Extension("test6", | 719 v8::RegisterExtension(new v8::Extension("test6", |
| 720 kSimpleExtensionSource)); | 720 kSimpleExtensionSource)); |
| 721 v8::RegisterExtension(new v8::Extension("test7", | 721 v8::RegisterExtension(new v8::Extension("test7", |
| 722 kSimpleExtensionSource)); | 722 kSimpleExtensionSource)); |
| 723 const char* extension_names[] = { "test0", "test1", | 723 const char* extension_names[] = { "test0", "test1", |
| 724 "test2", "test3", "test4", | 724 "test2", "test3", "test4", |
| 725 "test5", "test6", "test7" }; | 725 "test5", "test6", "test7" }; |
| 726 i::List<JoinableThread*> threads(kNThreads); | 726 i::List<JoinableThread*> threads(kNThreads); |
| 727 for (int i = 0; i < kNThreads; i++) { | 727 for (int i = 0; i < kNThreads; i++) { |
| 728 threads.Add(new IsolateGenesisThread(8, extension_names)); | 728 threads.Add(new IsolateGenesisThread(8, extension_names)); |
| 729 } | 729 } |
| 730 StartJoinAndDeleteThreads(threads); | 730 StartJoinAndDeleteThreads(threads); |
| 731 } | 731 } |
| OLD | NEW |