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

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

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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 | « test/cctest/test-liveedit.cc ('k') | test/cctest/test-log.cc » ('j') | 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 namespace i = ::i; 57 namespace i = ::i;
58 58
59 59
60 60
61 61
62 // Migrating an isolate 62 // Migrating an isolate
63 class KangarooThread : public v8::internal::Thread { 63 class KangarooThread : public v8::internal::Thread {
64 public: 64 public:
65 KangarooThread(v8::Isolate* isolate, 65 KangarooThread(v8::Isolate* isolate,
66 v8::Handle<v8::Context> context, int value) 66 v8::Handle<v8::Context> context, int value)
67 : Thread(NULL, "KangarooThread"), 67 : Thread("KangarooThread"),
68 isolate_(isolate), context_(context), value_(value) { 68 isolate_(isolate), context_(context), value_(value) {
69 } 69 }
70 70
71 void Run() { 71 void Run() {
72 { 72 {
73 v8::Locker locker(isolate_); 73 v8::Locker locker(isolate_);
74 v8::Isolate::Scope isolate_scope(isolate_); 74 v8::Isolate::Scope isolate_scope(isolate_);
75 CHECK_EQ(isolate_, v8::internal::Isolate::Current()); 75 CHECK_EQ(isolate_, v8::internal::Isolate::Current());
76 v8::HandleScope scope; 76 v8::HandleScope scope;
77 v8::Context::Scope context_scope(context_); 77 v8::Context::Scope context_scope(context_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 void Join() { 144 void Join() {
145 semaphore_->Wait(); 145 semaphore_->Wait();
146 } 146 }
147 147
148 virtual void Run() = 0; 148 virtual void Run() = 0;
149 private: 149 private:
150 class ThreadWithSemaphore : public i::Thread { 150 class ThreadWithSemaphore : public i::Thread {
151 public: 151 public:
152 explicit ThreadWithSemaphore(JoinableThread* joinable_thread) 152 explicit ThreadWithSemaphore(JoinableThread* joinable_thread)
153 : Thread(NULL, joinable_thread->name_), 153 : Thread(joinable_thread->name_),
154 joinable_thread_(joinable_thread) { 154 joinable_thread_(joinable_thread) {
155 } 155 }
156 156
157 virtual void Run() { 157 virtual void Run() {
158 joinable_thread_->Run(); 158 joinable_thread_->Run();
159 joinable_thread_->semaphore_->Signal(); 159 joinable_thread_->semaphore_->Signal();
160 } 160 }
161 161
162 private: 162 private:
163 JoinableThread* joinable_thread_; 163 JoinableThread* joinable_thread_;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 CalcFibAndCheck(); 307 CalcFibAndCheck();
308 threadB.Join(); 308 threadB.Join();
309 } 309 }
310 private: 310 private:
311 v8::Isolate* isolate1_; 311 v8::Isolate* isolate1_;
312 v8::Isolate* isolate2_; 312 v8::Isolate* isolate2_;
313 }; 313 };
314 314
315 // Run parallel threads that lock and access different isolates in parallel 315 // Run parallel threads that lock and access different isolates in parallel
316 TEST(SeparateIsolatesLocksNonexclusive) { 316 TEST(SeparateIsolatesLocksNonexclusive) {
317 #ifdef V8_TARGET_ARCH_ARM
318 const int kNThreads = 50;
319 #else
317 const int kNThreads = 100; 320 const int kNThreads = 100;
321 #endif
318 v8::Isolate* isolate1 = v8::Isolate::New(); 322 v8::Isolate* isolate1 = v8::Isolate::New();
319 v8::Isolate* isolate2 = v8::Isolate::New(); 323 v8::Isolate* isolate2 = v8::Isolate::New();
320 i::List<JoinableThread*> threads(kNThreads); 324 i::List<JoinableThread*> threads(kNThreads);
321 for (int i = 0; i < kNThreads; i++) { 325 for (int i = 0; i < kNThreads; i++) {
322 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1, 326 threads.Add(new SeparateIsolatesLocksNonexclusiveThread(isolate1,
323 isolate2)); 327 isolate2));
324 } 328 }
325 StartJoinAndDeleteThreads(threads); 329 StartJoinAndDeleteThreads(threads);
326 isolate2->Dispose(); 330 isolate2->Dispose();
327 isolate1->Dispose(); 331 isolate1->Dispose();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 v8::Context::Scope context_scope(context); 380 v8::Context::Scope context_scope(context);
377 CalcFibAndCheck(); 381 CalcFibAndCheck();
378 } 382 }
379 } 383 }
380 private: 384 private:
381 v8::Isolate* isolate_; 385 v8::Isolate* isolate_;
382 }; 386 };
383 387
384 // Use unlocker inside of a Locker, multiple threads. 388 // Use unlocker inside of a Locker, multiple threads.
385 TEST(LockerUnlocker) { 389 TEST(LockerUnlocker) {
390 #ifdef V8_TARGET_ARCH_ARM
391 const int kNThreads = 50;
392 #else
386 const int kNThreads = 100; 393 const int kNThreads = 100;
394 #endif
387 i::List<JoinableThread*> threads(kNThreads); 395 i::List<JoinableThread*> threads(kNThreads);
388 v8::Isolate* isolate = v8::Isolate::New(); 396 v8::Isolate* isolate = v8::Isolate::New();
389 for (int i = 0; i < kNThreads; i++) { 397 for (int i = 0; i < kNThreads; i++) {
390 threads.Add(new LockerUnlockerThread(isolate)); 398 threads.Add(new LockerUnlockerThread(isolate));
391 } 399 }
392 StartJoinAndDeleteThreads(threads); 400 StartJoinAndDeleteThreads(threads);
393 isolate->Dispose(); 401 isolate->Dispose();
394 } 402 }
395 403
396 class LockTwiceAndUnlockThread : public JoinableThread { 404 class LockTwiceAndUnlockThread : public JoinableThread {
(...skipping 27 matching lines...) Expand all
424 v8::Context::Scope context_scope(context); 432 v8::Context::Scope context_scope(context);
425 CalcFibAndCheck(); 433 CalcFibAndCheck();
426 } 434 }
427 } 435 }
428 private: 436 private:
429 v8::Isolate* isolate_; 437 v8::Isolate* isolate_;
430 }; 438 };
431 439
432 // Use Unlocker inside two Lockers. 440 // Use Unlocker inside two Lockers.
433 TEST(LockTwiceAndUnlock) { 441 TEST(LockTwiceAndUnlock) {
442 #ifdef V8_TARGET_ARCH_ARM
443 const int kNThreads = 50;
444 #else
434 const int kNThreads = 100; 445 const int kNThreads = 100;
446 #endif
435 i::List<JoinableThread*> threads(kNThreads); 447 i::List<JoinableThread*> threads(kNThreads);
436 v8::Isolate* isolate = v8::Isolate::New(); 448 v8::Isolate* isolate = v8::Isolate::New();
437 for (int i = 0; i < kNThreads; i++) { 449 for (int i = 0; i < kNThreads; i++) {
438 threads.Add(new LockTwiceAndUnlockThread(isolate)); 450 threads.Add(new LockTwiceAndUnlockThread(isolate));
439 } 451 }
440 StartJoinAndDeleteThreads(threads); 452 StartJoinAndDeleteThreads(threads);
441 isolate->Dispose(); 453 isolate->Dispose();
442 } 454 }
443 455
444 class LockAndUnlockDifferentIsolatesThread : public JoinableThread { 456 class LockAndUnlockDifferentIsolatesThread : public JoinableThread {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 v8::Locker locker_; 612 v8::Locker locker_;
601 v8::HandleScope handle_scope; 613 v8::HandleScope handle_scope;
602 context = v8::Context::New(); 614 context = v8::Context::New();
603 } 615 }
604 i::List<JoinableThread*> threads(kNThreads); 616 i::List<JoinableThread*> threads(kNThreads);
605 for (int i = 0; i < kNThreads; i++) { 617 for (int i = 0; i < kNThreads; i++) {
606 threads.Add(new LockUnlockLockDefaultIsolateThread(context)); 618 threads.Add(new LockUnlockLockDefaultIsolateThread(context));
607 } 619 }
608 StartJoinAndDeleteThreads(threads); 620 StartJoinAndDeleteThreads(threads);
609 } 621 }
622
623
624 TEST(Regress1433) {
625 for (int i = 0; i < 10; i++) {
626 v8::Isolate* isolate = v8::Isolate::New();
627 {
628 v8::Locker lock(isolate);
629 v8::Isolate::Scope isolate_scope(isolate);
630 v8::HandleScope handle_scope;
631 v8::Persistent<Context> context = v8::Context::New();
632 v8::Context::Scope context_scope(context);
633 v8::Handle<String> source = v8::String::New("1+1");
634 v8::Handle<Script> script = v8::Script::Compile(source);
635 v8::Handle<Value> result = script->Run();
636 v8::String::AsciiValue ascii(result);
637 context.Dispose();
638 }
639 isolate->Dispose();
640 }
641 }
OLDNEW
« no previous file with comments | « test/cctest/test-liveedit.cc ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698