| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 v8::Isolate* isolate_; | 94 v8::Isolate* isolate_; |
| 95 Persistent<v8::Context> context_; | 95 Persistent<v8::Context> context_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 | 98 |
| 99 // Migrates an isolate from one thread to another | 99 // Migrates an isolate from one thread to another |
| 100 TEST(KangarooIsolates) { | 100 TEST(KangarooIsolates) { |
| 101 v8::Isolate* isolate = v8::Isolate::New(); | 101 v8::Isolate::CreateParams create_params; |
| 102 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 103 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 102 i::SmartPointer<KangarooThread> thread1; | 104 i::SmartPointer<KangarooThread> thread1; |
| 103 { | 105 { |
| 104 v8::Locker locker(isolate); | 106 v8::Locker locker(isolate); |
| 105 v8::Isolate::Scope isolate_scope(isolate); | 107 v8::Isolate::Scope isolate_scope(isolate); |
| 106 v8::HandleScope handle_scope(isolate); | 108 v8::HandleScope handle_scope(isolate); |
| 107 v8::Local<v8::Context> context = v8::Context::New(isolate); | 109 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 108 v8::Context::Scope context_scope(context); | 110 v8::Context::Scope context_scope(context); |
| 109 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate), | 111 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate), |
| 110 v8::internal::Isolate::Current()); | 112 v8::internal::Isolate::Current()); |
| 111 CompileRun("function getValue() { return 30; }"); | 113 CompileRun("function getValue() { return 30; }"); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 211 |
| 210 // Run many threads all locking on the same isolate | 212 // Run many threads all locking on the same isolate |
| 211 TEST(IsolateLockingStress) { | 213 TEST(IsolateLockingStress) { |
| 212 i::FLAG_always_opt = false; | 214 i::FLAG_always_opt = false; |
| 213 #if V8_TARGET_ARCH_MIPS | 215 #if V8_TARGET_ARCH_MIPS |
| 214 const int kNThreads = 50; | 216 const int kNThreads = 50; |
| 215 #else | 217 #else |
| 216 const int kNThreads = 100; | 218 const int kNThreads = 100; |
| 217 #endif | 219 #endif |
| 218 i::List<JoinableThread*> threads(kNThreads); | 220 i::List<JoinableThread*> threads(kNThreads); |
| 219 v8::Isolate* isolate = v8::Isolate::New(); | 221 v8::Isolate::CreateParams create_params; |
| 222 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 223 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 220 for (int i = 0; i < kNThreads; i++) { | 224 for (int i = 0; i < kNThreads; i++) { |
| 221 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); | 225 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); |
| 222 } | 226 } |
| 223 StartJoinAndDeleteThreads(threads); | 227 StartJoinAndDeleteThreads(threads); |
| 224 isolate->Dispose(); | 228 isolate->Dispose(); |
| 225 } | 229 } |
| 226 | 230 |
| 227 | 231 |
| 228 class IsolateNestedLockingThread : public JoinableThread { | 232 class IsolateNestedLockingThread : public JoinableThread { |
| 229 public: | 233 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 250 | 254 |
| 251 | 255 |
| 252 // Run many threads with nested locks | 256 // Run many threads with nested locks |
| 253 TEST(IsolateNestedLocking) { | 257 TEST(IsolateNestedLocking) { |
| 254 i::FLAG_always_opt = false; | 258 i::FLAG_always_opt = false; |
| 255 #if V8_TARGET_ARCH_MIPS | 259 #if V8_TARGET_ARCH_MIPS |
| 256 const int kNThreads = 50; | 260 const int kNThreads = 50; |
| 257 #else | 261 #else |
| 258 const int kNThreads = 100; | 262 const int kNThreads = 100; |
| 259 #endif | 263 #endif |
| 260 v8::Isolate* isolate = v8::Isolate::New(); | 264 v8::Isolate::CreateParams create_params; |
| 265 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 266 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 261 i::List<JoinableThread*> threads(kNThreads); | 267 i::List<JoinableThread*> threads(kNThreads); |
| 262 for (int i = 0; i < kNThreads; i++) { | 268 for (int i = 0; i < kNThreads; i++) { |
| 263 threads.Add(new IsolateNestedLockingThread(isolate)); | 269 threads.Add(new IsolateNestedLockingThread(isolate)); |
| 264 } | 270 } |
| 265 StartJoinAndDeleteThreads(threads); | 271 StartJoinAndDeleteThreads(threads); |
| 266 isolate->Dispose(); | 272 isolate->Dispose(); |
| 267 } | 273 } |
| 268 | 274 |
| 269 | 275 |
| 270 class SeparateIsolatesLocksNonexclusiveThread : public JoinableThread { | 276 class SeparateIsolatesLocksNonexclusiveThread : public JoinableThread { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 293 | 299 |
| 294 | 300 |
| 295 // Run parallel threads that lock and access different isolates in parallel | 301 // Run parallel threads that lock and access different isolates in parallel |
| 296 TEST(SeparateIsolatesLocksNonexclusive) { | 302 TEST(SeparateIsolatesLocksNonexclusive) { |
| 297 i::FLAG_always_opt = false; | 303 i::FLAG_always_opt = false; |
| 298 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | 304 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 299 const int kNThreads = 50; | 305 const int kNThreads = 50; |
| 300 #else | 306 #else |
| 301 const int kNThreads = 100; | 307 const int kNThreads = 100; |
| 302 #endif | 308 #endif |
| 303 v8::Isolate* isolate1 = v8::Isolate::New(); | 309 v8::Isolate::CreateParams create_params; |
| 304 v8::Isolate* isolate2 = v8::Isolate::New(); | 310 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 311 v8::Isolate* isolate1 = v8::Isolate::New(create_params); |
| 312 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 305 i::List<JoinableThread*> threads(kNThreads); | 313 i::List<JoinableThread*> threads(kNThreads); |
| 306 for (int i = 0; i < kNThreads; i++) { | 314 for (int i = 0; i < kNThreads; i++) { |
| 307 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, | 315 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, |
| 308 isolate2)); | 316 isolate2)); |
| 309 } | 317 } |
| 310 StartJoinAndDeleteThreads(threads); | 318 StartJoinAndDeleteThreads(threads); |
| 311 isolate2->Dispose(); | 319 isolate2->Dispose(); |
| 312 isolate1->Dispose(); | 320 isolate1->Dispose(); |
| 313 } | 321 } |
| 314 | 322 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 380 |
| 373 // Use unlocker inside of a Locker, multiple threads. | 381 // Use unlocker inside of a Locker, multiple threads. |
| 374 TEST(LockerUnlocker) { | 382 TEST(LockerUnlocker) { |
| 375 i::FLAG_always_opt = false; | 383 i::FLAG_always_opt = false; |
| 376 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | 384 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 377 const int kNThreads = 50; | 385 const int kNThreads = 50; |
| 378 #else | 386 #else |
| 379 const int kNThreads = 100; | 387 const int kNThreads = 100; |
| 380 #endif | 388 #endif |
| 381 i::List<JoinableThread*> threads(kNThreads); | 389 i::List<JoinableThread*> threads(kNThreads); |
| 382 v8::Isolate* isolate = v8::Isolate::New(); | 390 v8::Isolate::CreateParams create_params; |
| 391 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 392 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 383 for (int i = 0; i < kNThreads; i++) { | 393 for (int i = 0; i < kNThreads; i++) { |
| 384 threads.Add(new LockerUnlockerThread(isolate)); | 394 threads.Add(new LockerUnlockerThread(isolate)); |
| 385 } | 395 } |
| 386 StartJoinAndDeleteThreads(threads); | 396 StartJoinAndDeleteThreads(threads); |
| 387 isolate->Dispose(); | 397 isolate->Dispose(); |
| 388 } | 398 } |
| 389 | 399 |
| 390 class LockTwiceAndUnlockThread : public JoinableThread { | 400 class LockTwiceAndUnlockThread : public JoinableThread { |
| 391 public: | 401 public: |
| 392 explicit LockTwiceAndUnlockThread(v8::Isolate* isolate) | 402 explicit LockTwiceAndUnlockThread(v8::Isolate* isolate) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 437 |
| 428 // Use Unlocker inside two Lockers. | 438 // Use Unlocker inside two Lockers. |
| 429 TEST(LockTwiceAndUnlock) { | 439 TEST(LockTwiceAndUnlock) { |
| 430 i::FLAG_always_opt = false; | 440 i::FLAG_always_opt = false; |
| 431 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | 441 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 432 const int kNThreads = 50; | 442 const int kNThreads = 50; |
| 433 #else | 443 #else |
| 434 const int kNThreads = 100; | 444 const int kNThreads = 100; |
| 435 #endif | 445 #endif |
| 436 i::List<JoinableThread*> threads(kNThreads); | 446 i::List<JoinableThread*> threads(kNThreads); |
| 437 v8::Isolate* isolate = v8::Isolate::New(); | 447 v8::Isolate::CreateParams create_params; |
| 448 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 449 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 438 for (int i = 0; i < kNThreads; i++) { | 450 for (int i = 0; i < kNThreads; i++) { |
| 439 threads.Add(new LockTwiceAndUnlockThread(isolate)); | 451 threads.Add(new LockTwiceAndUnlockThread(isolate)); |
| 440 } | 452 } |
| 441 StartJoinAndDeleteThreads(threads); | 453 StartJoinAndDeleteThreads(threads); |
| 442 isolate->Dispose(); | 454 isolate->Dispose(); |
| 443 } | 455 } |
| 444 | 456 |
| 445 class LockAndUnlockDifferentIsolatesThread : public JoinableThread { | 457 class LockAndUnlockDifferentIsolatesThread : public JoinableThread { |
| 446 public: | 458 public: |
| 447 LockAndUnlockDifferentIsolatesThread(v8::Isolate* isolate1, | 459 LockAndUnlockDifferentIsolatesThread(v8::Isolate* isolate1, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 501 } |
| 490 | 502 |
| 491 private: | 503 private: |
| 492 v8::Isolate* isolate1_; | 504 v8::Isolate* isolate1_; |
| 493 v8::Isolate* isolate2_; | 505 v8::Isolate* isolate2_; |
| 494 }; | 506 }; |
| 495 | 507 |
| 496 | 508 |
| 497 // Lock two isolates and unlock one of them. | 509 // Lock two isolates and unlock one of them. |
| 498 TEST(LockAndUnlockDifferentIsolates) { | 510 TEST(LockAndUnlockDifferentIsolates) { |
| 499 v8::Isolate* isolate1 = v8::Isolate::New(); | 511 v8::Isolate::CreateParams create_params; |
| 500 v8::Isolate* isolate2 = v8::Isolate::New(); | 512 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 513 v8::Isolate* isolate1 = v8::Isolate::New(create_params); |
| 514 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
| 501 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); | 515 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); |
| 502 thread.Start(); | 516 thread.Start(); |
| 503 thread.Join(); | 517 thread.Join(); |
| 504 isolate2->Dispose(); | 518 isolate2->Dispose(); |
| 505 isolate1->Dispose(); | 519 isolate1->Dispose(); |
| 506 } | 520 } |
| 507 | 521 |
| 508 class LockUnlockLockThread : public JoinableThread { | 522 class LockUnlockLockThread : public JoinableThread { |
| 509 public: | 523 public: |
| 510 LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) | 524 LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 }; | 563 }; |
| 550 | 564 |
| 551 | 565 |
| 552 // Locker inside an Unlocker inside a Locker. | 566 // Locker inside an Unlocker inside a Locker. |
| 553 TEST(LockUnlockLockMultithreaded) { | 567 TEST(LockUnlockLockMultithreaded) { |
| 554 #if V8_TARGET_ARCH_MIPS | 568 #if V8_TARGET_ARCH_MIPS |
| 555 const int kNThreads = 50; | 569 const int kNThreads = 50; |
| 556 #else | 570 #else |
| 557 const int kNThreads = 100; | 571 const int kNThreads = 100; |
| 558 #endif | 572 #endif |
| 559 v8::Isolate* isolate = v8::Isolate::New(); | 573 v8::Isolate::CreateParams create_params; |
| 574 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 575 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 560 i::List<JoinableThread*> threads(kNThreads); | 576 i::List<JoinableThread*> threads(kNThreads); |
| 561 { | 577 { |
| 562 v8::Locker locker_(isolate); | 578 v8::Locker locker_(isolate); |
| 563 v8::Isolate::Scope isolate_scope(isolate); | 579 v8::Isolate::Scope isolate_scope(isolate); |
| 564 v8::HandleScope handle_scope(isolate); | 580 v8::HandleScope handle_scope(isolate); |
| 565 v8::Handle<v8::Context> context = v8::Context::New(isolate); | 581 v8::Handle<v8::Context> context = v8::Context::New(isolate); |
| 566 for (int i = 0; i < kNThreads; i++) { | 582 for (int i = 0; i < kNThreads; i++) { |
| 567 threads.Add(new LockUnlockLockThread( | 583 threads.Add(new LockUnlockLockThread( |
| 568 isolate, context)); | 584 isolate, context)); |
| 569 } | 585 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 for (int i = 0; i < kNThreads; i++) { | 640 for (int i = 0; i < kNThreads; i++) { |
| 625 threads.Add(new LockUnlockLockDefaultIsolateThread(context)); | 641 threads.Add(new LockUnlockLockDefaultIsolateThread(context)); |
| 626 } | 642 } |
| 627 } | 643 } |
| 628 StartJoinAndDeleteThreads(threads); | 644 StartJoinAndDeleteThreads(threads); |
| 629 } | 645 } |
| 630 | 646 |
| 631 | 647 |
| 632 TEST(Regress1433) { | 648 TEST(Regress1433) { |
| 633 for (int i = 0; i < 10; i++) { | 649 for (int i = 0; i < 10; i++) { |
| 634 v8::Isolate* isolate = v8::Isolate::New(); | 650 v8::Isolate::CreateParams create_params; |
| 651 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 652 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 635 { | 653 { |
| 636 v8::Locker lock(isolate); | 654 v8::Locker lock(isolate); |
| 637 v8::Isolate::Scope isolate_scope(isolate); | 655 v8::Isolate::Scope isolate_scope(isolate); |
| 638 v8::HandleScope handle_scope(isolate); | 656 v8::HandleScope handle_scope(isolate); |
| 639 v8::Handle<Context> context = v8::Context::New(isolate); | 657 v8::Handle<Context> context = v8::Context::New(isolate); |
| 640 v8::Context::Scope context_scope(context); | 658 v8::Context::Scope context_scope(context); |
| 641 v8::Handle<String> source = v8::String::NewFromUtf8(isolate, "1+1"); | 659 v8::Handle<String> source = v8::String::NewFromUtf8(isolate, "1+1"); |
| 642 v8::Handle<Script> script = v8::Script::Compile(source); | 660 v8::Handle<Script> script = v8::Script::Compile(source); |
| 643 v8::Handle<Value> result = script->Run(); | 661 v8::Handle<Value> result = script->Run(); |
| 644 v8::String::Utf8Value utf8(result); | 662 v8::String::Utf8Value utf8(result); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 655 | 673 |
| 656 class IsolateGenesisThread : public JoinableThread { | 674 class IsolateGenesisThread : public JoinableThread { |
| 657 public: | 675 public: |
| 658 IsolateGenesisThread(int count, const char* extension_names[]) | 676 IsolateGenesisThread(int count, const char* extension_names[]) |
| 659 : JoinableThread("IsolateGenesisThread"), | 677 : JoinableThread("IsolateGenesisThread"), |
| 660 count_(count), | 678 count_(count), |
| 661 extension_names_(extension_names) | 679 extension_names_(extension_names) |
| 662 {} | 680 {} |
| 663 | 681 |
| 664 virtual void Run() { | 682 virtual void Run() { |
| 665 v8::Isolate* isolate = v8::Isolate::New(); | 683 v8::Isolate::CreateParams create_params; |
| 684 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 685 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 666 { | 686 { |
| 667 v8::Isolate::Scope isolate_scope(isolate); | 687 v8::Isolate::Scope isolate_scope(isolate); |
| 668 CHECK(!i::Isolate::Current()->has_installed_extensions()); | 688 CHECK(!i::Isolate::Current()->has_installed_extensions()); |
| 669 v8::ExtensionConfiguration extensions(count_, extension_names_); | 689 v8::ExtensionConfiguration extensions(count_, extension_names_); |
| 670 v8::HandleScope handle_scope(isolate); | 690 v8::HandleScope handle_scope(isolate); |
| 671 v8::Context::New(isolate, &extensions); | 691 v8::Context::New(isolate, &extensions); |
| 672 CHECK(i::Isolate::Current()->has_installed_extensions()); | 692 CHECK(i::Isolate::Current()->has_installed_extensions()); |
| 673 } | 693 } |
| 674 isolate->Dispose(); | 694 isolate->Dispose(); |
| 675 } | 695 } |
| 696 |
| 676 private: | 697 private: |
| 677 int count_; | 698 int count_; |
| 678 const char** extension_names_; | 699 const char** extension_names_; |
| 679 }; | 700 }; |
| 680 | 701 |
| 681 | 702 |
| 682 // Test installing extensions in separate isolates concurrently. | 703 // Test installing extensions in separate isolates concurrently. |
| 683 // http://code.google.com/p/v8/issues/detail?id=1821 | 704 // http://code.google.com/p/v8/issues/detail?id=1821 |
| 684 TEST(ExtensionsRegistration) { | 705 TEST(ExtensionsRegistration) { |
| 685 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | 706 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| (...skipping 21 matching lines...) Expand all Loading... |
| 707 kSimpleExtensionSource)); | 728 kSimpleExtensionSource)); |
| 708 const char* extension_names[] = { "test0", "test1", | 729 const char* extension_names[] = { "test0", "test1", |
| 709 "test2", "test3", "test4", | 730 "test2", "test3", "test4", |
| 710 "test5", "test6", "test7" }; | 731 "test5", "test6", "test7" }; |
| 711 i::List<JoinableThread*> threads(kNThreads); | 732 i::List<JoinableThread*> threads(kNThreads); |
| 712 for (int i = 0; i < kNThreads; i++) { | 733 for (int i = 0; i < kNThreads; i++) { |
| 713 threads.Add(new IsolateGenesisThread(8, extension_names)); | 734 threads.Add(new IsolateGenesisThread(8, extension_names)); |
| 714 } | 735 } |
| 715 StartJoinAndDeleteThreads(threads); | 736 StartJoinAndDeleteThreads(threads); |
| 716 } | 737 } |
| OLD | NEW |