Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: test/cctest/test-lockers.cc

Issue 14150017: Change cctest/test-lockers to not copy persistent handles around. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <limits.h> 28 #include <limits.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "api.h" 32 #include "api.h"
33 #include "isolate.h" 33 #include "isolate.h"
34 #include "compilation-cache.h" 34 #include "compilation-cache.h"
35 #include "execution.h" 35 #include "execution.h"
36 #include "smart-pointers.h"
36 #include "snapshot.h" 37 #include "snapshot.h"
37 #include "platform.h" 38 #include "platform.h"
38 #include "utils.h" 39 #include "utils.h"
39 #include "cctest.h" 40 #include "cctest.h"
40 #include "parser.h" 41 #include "parser.h"
41 #include "unicode-inl.h" 42 #include "unicode-inl.h"
42 43
43 using ::v8::AccessorInfo; 44 using ::v8::AccessorInfo;
44 using ::v8::Context; 45 using ::v8::Context;
45 using ::v8::Extension; 46 using ::v8::Extension;
46 using ::v8::Function; 47 using ::v8::Function;
47 using ::v8::HandleScope; 48 using ::v8::HandleScope;
48 using ::v8::Local; 49 using ::v8::Local;
49 using ::v8::Object; 50 using ::v8::Object;
50 using ::v8::ObjectTemplate; 51 using ::v8::ObjectTemplate;
51 using ::v8::Persistent; 52 using ::v8::Persistent;
52 using ::v8::Script; 53 using ::v8::Script;
53 using ::v8::String; 54 using ::v8::String;
54 using ::v8::Value; 55 using ::v8::Value;
55 using ::v8::V8; 56 using ::v8::V8;
56 57
57 58
58 // Migrating an isolate 59 // Migrating an isolate
59 class KangarooThread : public v8::internal::Thread { 60 class KangarooThread : public v8::internal::Thread {
60 public: 61 public:
61 KangarooThread(v8::Isolate* isolate, 62 KangarooThread(v8::Isolate* isolate, v8::Handle<v8::Context> context)
62 v8::Handle<v8::Context> context)
63 : Thread("KangarooThread"), 63 : Thread("KangarooThread"),
64 isolate_(isolate), context_(context) { 64 isolate_(isolate),
65 } 65 context_(isolate, context) {}
66 66
67 void Run() { 67 void Run() {
68 { 68 {
69 v8::Locker locker(isolate_); 69 v8::Locker locker(isolate_);
70 v8::Isolate::Scope isolate_scope(isolate_); 70 v8::Isolate::Scope isolate_scope(isolate_);
71 CHECK_EQ(isolate_, v8::internal::Isolate::Current()); 71 CHECK_EQ(isolate_, v8::internal::Isolate::Current());
72 v8::HandleScope scope(isolate_); 72 v8::HandleScope scope(isolate_);
73 v8::Context::Scope context_scope(context_); 73 v8::Context::Scope context_scope(context_);
74 Local<Value> v = CompileRun("getValue()"); 74 Local<Value> v = CompileRun("getValue()");
75 CHECK(v->IsNumber()); 75 CHECK(v->IsNumber());
(...skipping 12 matching lines...) Expand all
88 } 88 }
89 89
90 private: 90 private:
91 v8::Isolate* isolate_; 91 v8::Isolate* isolate_;
92 Persistent<v8::Context> context_; 92 Persistent<v8::Context> context_;
93 }; 93 };
94 94
95 // Migrates an isolate from one thread to another 95 // Migrates an isolate from one thread to another
96 TEST(KangarooIsolates) { 96 TEST(KangarooIsolates) {
97 v8::Isolate* isolate = v8::Isolate::New(); 97 v8::Isolate* isolate = v8::Isolate::New();
98 Persistent<v8::Context> context; 98 i::SmartPointer<KangarooThread> thread1;
99 { 99 {
100 v8::Locker locker(isolate); 100 v8::Locker locker(isolate);
101 v8::Isolate::Scope isolate_scope(isolate); 101 v8::Isolate::Scope isolate_scope(isolate);
102 v8::HandleScope handle_scope(isolate); 102 v8::HandleScope handle_scope(isolate);
103 context = v8::Context::New(); 103 v8::Local<v8::Context> context = v8::Context::New(isolate);
104 v8::Context::Scope context_scope(context); 104 v8::Context::Scope context_scope(context);
105 CHECK_EQ(isolate, v8::internal::Isolate::Current()); 105 CHECK_EQ(isolate, v8::internal::Isolate::Current());
106 CompileRun("function getValue() { return 30; }"); 106 CompileRun("function getValue() { return 30; }");
107 thread1.Reset(new KangarooThread(isolate, context));
107 } 108 }
108 KangarooThread thread1(isolate, context); 109 thread1->Start();
109 thread1.Start(); 110 thread1->Join();
110 thread1.Join();
111 } 111 }
112 112
113 static void CalcFibAndCheck() { 113 static void CalcFibAndCheck() {
114 Local<Value> v = CompileRun("function fib(n) {" 114 Local<Value> v = CompileRun("function fib(n) {"
115 " if (n <= 2) return 1;" 115 " if (n <= 2) return 1;"
116 " return fib(n-1) + fib(n-2);" 116 " return fib(n-1) + fib(n-2);"
117 "}" 117 "}"
118 "fib(10)"); 118 "fib(10)");
119 CHECK(v->IsNumber()); 119 CHECK(v->IsNumber());
120 CHECK_EQ(55, static_cast<int>(v->NumberValue())); 120 CHECK_EQ(55, static_cast<int>(v->NumberValue()));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 isolate2->Dispose(); 335 isolate2->Dispose();
336 isolate1->Dispose(); 336 isolate1->Dispose();
337 } 337 }
338 338
339 class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread { 339 class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread {
340 public: 340 public:
341 explicit LockIsolateAndCalculateFibSharedContextThread( 341 explicit LockIsolateAndCalculateFibSharedContextThread(
342 v8::Isolate* isolate, v8::Handle<v8::Context> context) 342 v8::Isolate* isolate, v8::Handle<v8::Context> context)
343 : JoinableThread("LockIsolateAndCalculateFibThread"), 343 : JoinableThread("LockIsolateAndCalculateFibThread"),
344 isolate_(isolate), 344 isolate_(isolate),
345 context_(context) { 345 context_(isolate, context) {
346 } 346 }
347 347
348 virtual void Run() { 348 virtual void Run() {
349 v8::Locker lock(isolate_); 349 v8::Locker lock(isolate_);
350 v8::Isolate::Scope isolate_scope(isolate_); 350 v8::Isolate::Scope isolate_scope(isolate_);
351 HandleScope handle_scope(isolate_); 351 HandleScope handle_scope(isolate_);
352 v8::Context::Scope context_scope(context_); 352 v8::Context::Scope context_scope(context_);
353 CalcFibAndCheck(); 353 CalcFibAndCheck();
354 } 354 }
355 private: 355 private:
356 v8::Isolate* isolate_; 356 v8::Isolate* isolate_;
357 Persistent<v8::Context> context_; 357 Persistent<v8::Context> context_;
358 }; 358 };
359 359
360 class LockerUnlockerThread : public JoinableThread { 360 class LockerUnlockerThread : public JoinableThread {
361 public: 361 public:
362 explicit LockerUnlockerThread(v8::Isolate* isolate) 362 explicit LockerUnlockerThread(v8::Isolate* isolate)
363 : JoinableThread("LockerUnlockerThread"), 363 : JoinableThread("LockerUnlockerThread"),
364 isolate_(isolate) { 364 isolate_(isolate) {
365 } 365 }
366 366
367 virtual void Run() { 367 virtual void Run() {
368 v8::Locker lock(isolate_); 368 v8::Locker lock(isolate_);
369 v8::Isolate::Scope isolate_scope(isolate_); 369 v8::Isolate::Scope isolate_scope(isolate_);
370 v8::HandleScope handle_scope(isolate_); 370 v8::HandleScope handle_scope(isolate_);
371 v8::Handle<v8::Context> context = v8::Context::New(); 371 v8::Local<v8::Context> context = v8::Context::New(isolate_);
372 { 372 {
373 v8::Context::Scope context_scope(context); 373 v8::Context::Scope context_scope(context);
374 CalcFibAndCheck(); 374 CalcFibAndCheck();
375 } 375 }
376 { 376 {
377 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
377 isolate_->Exit(); 378 isolate_->Exit();
378 v8::Unlocker unlocker(isolate_); 379 v8::Unlocker unlocker(isolate_);
379 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
380 thread.Start(); 380 thread.Start();
381 thread.Join(); 381 thread.Join();
382 } 382 }
383 isolate_->Enter(); 383 isolate_->Enter();
384 { 384 {
385 v8::Context::Scope context_scope(context); 385 v8::Context::Scope context_scope(context);
386 CalcFibAndCheck(); 386 CalcFibAndCheck();
387 } 387 }
388 } 388 }
389 389
(...skipping 21 matching lines...) Expand all
411 public: 411 public:
412 explicit LockTwiceAndUnlockThread(v8::Isolate* isolate) 412 explicit LockTwiceAndUnlockThread(v8::Isolate* isolate)
413 : JoinableThread("LockTwiceAndUnlockThread"), 413 : JoinableThread("LockTwiceAndUnlockThread"),
414 isolate_(isolate) { 414 isolate_(isolate) {
415 } 415 }
416 416
417 virtual void Run() { 417 virtual void Run() {
418 v8::Locker lock(isolate_); 418 v8::Locker lock(isolate_);
419 v8::Isolate::Scope isolate_scope(isolate_); 419 v8::Isolate::Scope isolate_scope(isolate_);
420 v8::HandleScope handle_scope(isolate_); 420 v8::HandleScope handle_scope(isolate_);
421 v8::Handle<v8::Context> context = v8::Context::New(); 421 v8::Local<v8::Context> context = v8::Context::New(isolate_);
422 { 422 {
423 v8::Context::Scope context_scope(context); 423 v8::Context::Scope context_scope(context);
424 CalcFibAndCheck(); 424 CalcFibAndCheck();
425 } 425 }
426 { 426 {
427 v8::Locker second_lock(isolate_); 427 v8::Locker second_lock(isolate_);
428 { 428 {
429 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
429 isolate_->Exit(); 430 isolate_->Exit();
430 v8::Unlocker unlocker(isolate_); 431 v8::Unlocker unlocker(isolate_);
431 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
432 thread.Start(); 432 thread.Start();
433 thread.Join(); 433 thread.Join();
434 } 434 }
435 } 435 }
436 isolate_->Enter(); 436 isolate_->Enter();
437 { 437 {
438 v8::Context::Scope context_scope(context); 438 v8::Context::Scope context_scope(context);
439 CalcFibAndCheck(); 439 CalcFibAndCheck();
440 } 440 }
441 } 441 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 { 490 {
491 v8::Isolate::Scope isolate_scope(isolate2_); 491 v8::Isolate::Scope isolate_scope(isolate2_);
492 v8::HandleScope handle_scope(isolate2_); 492 v8::HandleScope handle_scope(isolate2_);
493 context2 = v8::Context::New(); 493 context2 = v8::Context::New();
494 { 494 {
495 v8::Context::Scope context_scope(context2); 495 v8::Context::Scope context_scope(context2);
496 CalcFibAndCheck(); 496 CalcFibAndCheck();
497 } 497 }
498 } 498 }
499 { 499 {
500 i::SmartPointer<LockIsolateAndCalculateFibSharedContextThread> thread;
501 {
502 CHECK(v8::Locker::IsLocked(isolate1_));
503 v8::Isolate::Scope isolate_scope(isolate1_);
504 v8::HandleScope handle_scope(isolate1_);
505 thread.Reset(new LockIsolateAndCalculateFibSharedContextThread(
506 isolate1_, v8::Local<v8::Context>::New(isolate1_, context1)));
507 }
500 v8::Unlocker unlock1(isolate1_); 508 v8::Unlocker unlock1(isolate1_);
501 CHECK(!v8::Locker::IsLocked(isolate1_)); 509 CHECK(!v8::Locker::IsLocked(isolate1_));
502 CHECK(v8::Locker::IsLocked(isolate2_)); 510 CHECK(v8::Locker::IsLocked(isolate2_));
503 v8::Isolate::Scope isolate_scope(isolate2_); 511 v8::Isolate::Scope isolate_scope(isolate2_);
504 v8::HandleScope handle_scope(isolate2_); 512 v8::HandleScope handle_scope(isolate2_);
505 v8::Context::Scope context_scope(context2); 513 v8::Context::Scope context_scope(context2);
506 LockIsolateAndCalculateFibSharedContextThread thread(isolate1_, context1); 514 thread->Start();
507 thread.Start();
508 CalcFibAndCheck(); 515 CalcFibAndCheck();
509 thread.Join(); 516 thread->Join();
510 } 517 }
511 } 518 }
512 519
513 private: 520 private:
514 v8::Isolate* isolate1_; 521 v8::Isolate* isolate1_;
515 v8::Isolate* isolate2_; 522 v8::Isolate* isolate2_;
516 }; 523 };
517 524
518 // Lock two isolates and unlock one of them. 525 // Lock two isolates and unlock one of them.
519 TEST(LockAndUnlockDifferentIsolates) { 526 TEST(LockAndUnlockDifferentIsolates) {
520 v8::Isolate* isolate1 = v8::Isolate::New(); 527 v8::Isolate* isolate1 = v8::Isolate::New();
521 v8::Isolate* isolate2 = v8::Isolate::New(); 528 v8::Isolate* isolate2 = v8::Isolate::New();
522 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); 529 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2);
523 thread.Start(); 530 thread.Start();
524 thread.Join(); 531 thread.Join();
525 isolate2->Dispose(); 532 isolate2->Dispose();
526 isolate1->Dispose(); 533 isolate1->Dispose();
527 } 534 }
528 535
529 class LockUnlockLockThread : public JoinableThread { 536 class LockUnlockLockThread : public JoinableThread {
530 public: 537 public:
531 LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) 538 LockUnlockLockThread(v8::Isolate* isolate, v8::Local<v8::Context> context)
532 : JoinableThread("LockUnlockLockThread"), 539 : JoinableThread("LockUnlockLockThread"),
533 isolate_(isolate), 540 isolate_(isolate),
534 context_(context) { 541 context_(isolate, context) {
535 } 542 }
536 543
537 virtual void Run() { 544 virtual void Run() {
538 v8::Locker lock1(isolate_); 545 v8::Locker lock1(isolate_);
539 CHECK(v8::Locker::IsLocked(isolate_)); 546 CHECK(v8::Locker::IsLocked(isolate_));
540 CHECK(!v8::Locker::IsLocked(CcTest::default_isolate())); 547 CHECK(!v8::Locker::IsLocked(CcTest::default_isolate()));
541 { 548 {
542 v8::Isolate::Scope isolate_scope(isolate_); 549 v8::Isolate::Scope isolate_scope(isolate_);
543 v8::HandleScope handle_scope(isolate_); 550 v8::HandleScope handle_scope(isolate_);
544 v8::Context::Scope context_scope(context_); 551 v8::Context::Scope context_scope(context_);
(...skipping 22 matching lines...) Expand all
567 574
568 // Locker inside an Unlocker inside a Locker. 575 // Locker inside an Unlocker inside a Locker.
569 TEST(LockUnlockLockMultithreaded) { 576 TEST(LockUnlockLockMultithreaded) {
570 #ifdef V8_TARGET_ARCH_MIPS 577 #ifdef V8_TARGET_ARCH_MIPS
571 const int kNThreads = 50; 578 const int kNThreads = 50;
572 #else 579 #else
573 const int kNThreads = 100; 580 const int kNThreads = 100;
574 #endif 581 #endif
575 v8::Isolate* isolate = v8::Isolate::New(); 582 v8::Isolate* isolate = v8::Isolate::New();
576 Persistent<v8::Context> context; 583 Persistent<v8::Context> context;
584 i::List<JoinableThread*> threads(kNThreads);
577 { 585 {
578 v8::Locker locker_(isolate); 586 v8::Locker locker_(isolate);
579 v8::Isolate::Scope isolate_scope(isolate); 587 v8::Isolate::Scope isolate_scope(isolate);
580 v8::HandleScope handle_scope(isolate); 588 v8::HandleScope handle_scope(isolate);
581 context = v8::Context::New(); 589 context = v8::Context::New();
582 } 590 for (int i = 0; i < kNThreads; i++) {
583 i::List<JoinableThread*> threads(kNThreads); 591 threads.Add(new LockUnlockLockThread(
584 for (int i = 0; i < kNThreads; i++) { 592 isolate, v8::Local<v8::Context>::New(isolate, context)));
585 threads.Add(new LockUnlockLockThread(isolate, context)); 593 }
586 } 594 }
587 StartJoinAndDeleteThreads(threads); 595 StartJoinAndDeleteThreads(threads);
588 isolate->Dispose(); 596 isolate->Dispose();
589 } 597 }
590 598
591 class LockUnlockLockDefaultIsolateThread : public JoinableThread { 599 class LockUnlockLockDefaultIsolateThread : public JoinableThread {
592 public: 600 public:
593 explicit LockUnlockLockDefaultIsolateThread(v8::Handle<v8::Context> context) 601 explicit LockUnlockLockDefaultIsolateThread(v8::Local<v8::Context> context)
594 : JoinableThread("LockUnlockLockDefaultIsolateThread"), 602 : JoinableThread("LockUnlockLockDefaultIsolateThread"),
595 context_(context) { 603 context_(CcTest::default_isolate(), context) {}
596 }
597 604
598 virtual void Run() { 605 virtual void Run() {
599 v8::Locker lock1(CcTest::default_isolate()); 606 v8::Locker lock1(CcTest::default_isolate());
600 { 607 {
601 v8::HandleScope handle_scope(CcTest::default_isolate()); 608 v8::HandleScope handle_scope(CcTest::default_isolate());
602 v8::Context::Scope context_scope(context_); 609 v8::Context::Scope context_scope(context_);
603 CalcFibAndCheck(); 610 CalcFibAndCheck();
604 } 611 }
605 { 612 {
606 v8::Unlocker unlock1(CcTest::default_isolate()); 613 v8::Unlocker unlock1(CcTest::default_isolate());
(...skipping 11 matching lines...) Expand all
618 }; 625 };
619 626
620 // Locker inside an Unlocker inside a Locker for default isolate. 627 // Locker inside an Unlocker inside a Locker for default isolate.
621 TEST(LockUnlockLockDefaultIsolateMultithreaded) { 628 TEST(LockUnlockLockDefaultIsolateMultithreaded) {
622 #ifdef V8_TARGET_ARCH_MIPS 629 #ifdef V8_TARGET_ARCH_MIPS
623 const int kNThreads = 50; 630 const int kNThreads = 50;
624 #else 631 #else
625 const int kNThreads = 100; 632 const int kNThreads = 100;
626 #endif 633 #endif
627 Persistent<v8::Context> context; 634 Persistent<v8::Context> context;
635 i::List<JoinableThread*> threads(kNThreads);
628 { 636 {
629 v8::Locker locker_(CcTest::default_isolate()); 637 v8::Locker locker_(CcTest::default_isolate());
630 v8::HandleScope handle_scope(CcTest::default_isolate()); 638 v8::HandleScope handle_scope(CcTest::default_isolate());
631 context = v8::Context::New(); 639 context = v8::Context::New();
632 } 640 for (int i = 0; i < kNThreads; i++) {
633 i::List<JoinableThread*> threads(kNThreads); 641 threads.Add(new LockUnlockLockDefaultIsolateThread(
634 for (int i = 0; i < kNThreads; i++) { 642 v8::Local<v8::Context>::New(CcTest::default_isolate(), context)));
635 threads.Add(new LockUnlockLockDefaultIsolateThread(context)); 643 }
636 } 644 }
637 StartJoinAndDeleteThreads(threads); 645 StartJoinAndDeleteThreads(threads);
638 } 646 }
639 647
640 648
641 TEST(Regress1433) { 649 TEST(Regress1433) {
642 for (int i = 0; i < 10; i++) { 650 for (int i = 0; i < 10; i++) {
643 v8::Isolate* isolate = v8::Isolate::New(); 651 v8::Isolate* isolate = v8::Isolate::New();
644 { 652 {
645 v8::Locker lock(isolate); 653 v8::Locker lock(isolate);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 kSimpleExtensionSource)); 722 kSimpleExtensionSource));
715 const char* extension_names[] = { "test0", "test1", 723 const char* extension_names[] = { "test0", "test1",
716 "test2", "test3", "test4", 724 "test2", "test3", "test4",
717 "test5", "test6", "test7" }; 725 "test5", "test6", "test7" };
718 i::List<JoinableThread*> threads(kNThreads); 726 i::List<JoinableThread*> threads(kNThreads);
719 for (int i = 0; i < kNThreads; i++) { 727 for (int i = 0; i < kNThreads; i++) {
720 threads.Add(new IsolateGenesisThread(8, extension_names)); 728 threads.Add(new IsolateGenesisThread(8, extension_names));
721 } 729 }
722 StartJoinAndDeleteThreads(threads); 730 StartJoinAndDeleteThreads(threads);
723 } 731 }
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698