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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 <memory> |
| 31 |
30 #include "src/v8.h" | 32 #include "src/v8.h" |
31 | 33 |
32 #include "src/api.h" | 34 #include "src/api.h" |
33 #include "src/base/platform/platform.h" | 35 #include "src/base/platform/platform.h" |
34 #include "src/base/smart-pointers.h" | |
35 #include "src/compilation-cache.h" | 36 #include "src/compilation-cache.h" |
36 #include "src/execution.h" | 37 #include "src/execution.h" |
37 #include "src/isolate.h" | 38 #include "src/isolate.h" |
38 #include "src/parsing/parser.h" | 39 #include "src/parsing/parser.h" |
39 #include "src/unicode-inl.h" | 40 #include "src/unicode-inl.h" |
40 #include "src/utils.h" | 41 #include "src/utils.h" |
41 #include "test/cctest/cctest.h" | 42 #include "test/cctest/cctest.h" |
42 | 43 |
43 using ::v8::Context; | 44 using ::v8::Context; |
44 using ::v8::Extension; | 45 using ::v8::Extension; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 v8::Isolate* isolate_; | 94 v8::Isolate* isolate_; |
94 Persistent<v8::Context> context_; | 95 Persistent<v8::Context> context_; |
95 }; | 96 }; |
96 | 97 |
97 | 98 |
98 // Migrates an isolate from one thread to another | 99 // Migrates an isolate from one thread to another |
99 TEST(KangarooIsolates) { | 100 TEST(KangarooIsolates) { |
100 v8::Isolate::CreateParams create_params; | 101 v8::Isolate::CreateParams create_params; |
101 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 102 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
102 v8::Isolate* isolate = v8::Isolate::New(create_params); | 103 v8::Isolate* isolate = v8::Isolate::New(create_params); |
103 v8::base::SmartPointer<KangarooThread> thread1; | 104 std::unique_ptr<KangarooThread> thread1; |
104 { | 105 { |
105 v8::Locker locker(isolate); | 106 v8::Locker locker(isolate); |
106 v8::Isolate::Scope isolate_scope(isolate); | 107 v8::Isolate::Scope isolate_scope(isolate); |
107 v8::HandleScope handle_scope(isolate); | 108 v8::HandleScope handle_scope(isolate); |
108 v8::Local<v8::Context> context = v8::Context::New(isolate); | 109 v8::Local<v8::Context> context = v8::Context::New(isolate); |
109 v8::Context::Scope context_scope(context); | 110 v8::Context::Scope context_scope(context); |
110 CHECK_EQ(isolate, v8::Isolate::GetCurrent()); | 111 CHECK_EQ(isolate, v8::Isolate::GetCurrent()); |
111 CompileRun("function getValue() { return 30; }"); | 112 CompileRun("function getValue() { return 30; }"); |
112 thread1.Reset(new KangarooThread(isolate, context)); | 113 thread1.reset(new KangarooThread(isolate, context)); |
113 } | 114 } |
114 thread1->Start(); | 115 thread1->Start(); |
115 thread1->Join(); | 116 thread1->Join(); |
116 } | 117 } |
117 | 118 |
118 | 119 |
119 static void CalcFibAndCheck(v8::Local<v8::Context> context) { | 120 static void CalcFibAndCheck(v8::Local<v8::Context> context) { |
120 Local<Value> v = CompileRun("function fib(n) {" | 121 Local<Value> v = CompileRun("function fib(n) {" |
121 " if (n <= 2) return 1;" | 122 " if (n <= 2) return 1;" |
122 " return fib(n-1) + fib(n-2);" | 123 " return fib(n-1) + fib(n-2);" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 class LockAndUnlockDifferentIsolatesThread : public JoinableThread { | 459 class LockAndUnlockDifferentIsolatesThread : public JoinableThread { |
459 public: | 460 public: |
460 LockAndUnlockDifferentIsolatesThread(v8::Isolate* isolate1, | 461 LockAndUnlockDifferentIsolatesThread(v8::Isolate* isolate1, |
461 v8::Isolate* isolate2) | 462 v8::Isolate* isolate2) |
462 : JoinableThread("LockAndUnlockDifferentIsolatesThread"), | 463 : JoinableThread("LockAndUnlockDifferentIsolatesThread"), |
463 isolate1_(isolate1), | 464 isolate1_(isolate1), |
464 isolate2_(isolate2) { | 465 isolate2_(isolate2) { |
465 } | 466 } |
466 | 467 |
467 virtual void Run() { | 468 virtual void Run() { |
468 v8::base::SmartPointer<LockIsolateAndCalculateFibSharedContextThread> | 469 std::unique_ptr<LockIsolateAndCalculateFibSharedContextThread> thread; |
469 thread; | |
470 v8::Locker lock1(isolate1_); | 470 v8::Locker lock1(isolate1_); |
471 CHECK(v8::Locker::IsLocked(isolate1_)); | 471 CHECK(v8::Locker::IsLocked(isolate1_)); |
472 CHECK(!v8::Locker::IsLocked(isolate2_)); | 472 CHECK(!v8::Locker::IsLocked(isolate2_)); |
473 { | 473 { |
474 v8::Isolate::Scope isolate_scope(isolate1_); | 474 v8::Isolate::Scope isolate_scope(isolate1_); |
475 v8::HandleScope handle_scope(isolate1_); | 475 v8::HandleScope handle_scope(isolate1_); |
476 v8::Local<v8::Context> context1 = v8::Context::New(isolate1_); | 476 v8::Local<v8::Context> context1 = v8::Context::New(isolate1_); |
477 { | 477 { |
478 v8::Context::Scope context_scope(context1); | 478 v8::Context::Scope context_scope(context1); |
479 CalcFibAndCheck(context1); | 479 CalcFibAndCheck(context1); |
480 } | 480 } |
481 thread.Reset(new LockIsolateAndCalculateFibSharedContextThread( | 481 thread.reset(new LockIsolateAndCalculateFibSharedContextThread(isolate1_, |
482 isolate1_, context1)); | 482 context1)); |
483 } | 483 } |
484 v8::Locker lock2(isolate2_); | 484 v8::Locker lock2(isolate2_); |
485 CHECK(v8::Locker::IsLocked(isolate1_)); | 485 CHECK(v8::Locker::IsLocked(isolate1_)); |
486 CHECK(v8::Locker::IsLocked(isolate2_)); | 486 CHECK(v8::Locker::IsLocked(isolate2_)); |
487 { | 487 { |
488 v8::Isolate::Scope isolate_scope(isolate2_); | 488 v8::Isolate::Scope isolate_scope(isolate2_); |
489 v8::HandleScope handle_scope(isolate2_); | 489 v8::HandleScope handle_scope(isolate2_); |
490 v8::Local<v8::Context> context2 = v8::Context::New(isolate2_); | 490 v8::Local<v8::Context> context2 = v8::Context::New(isolate2_); |
491 { | 491 { |
492 v8::Context::Scope context_scope(context2); | 492 v8::Context::Scope context_scope(context2); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 kSimpleExtensionSource)); | 733 kSimpleExtensionSource)); |
734 const char* extension_names[] = { "test0", "test1", | 734 const char* extension_names[] = { "test0", "test1", |
735 "test2", "test3", "test4", | 735 "test2", "test3", "test4", |
736 "test5", "test6", "test7" }; | 736 "test5", "test6", "test7" }; |
737 i::List<JoinableThread*> threads(kNThreads); | 737 i::List<JoinableThread*> threads(kNThreads); |
738 for (int i = 0; i < kNThreads; i++) { | 738 for (int i = 0; i < kNThreads; i++) { |
739 threads.Add(new IsolateGenesisThread(8, extension_names)); | 739 threads.Add(new IsolateGenesisThread(8, extension_names)); |
740 } | 740 } |
741 StartJoinAndDeleteThreads(threads); | 741 StartJoinAndDeleteThreads(threads); |
742 } | 742 } |
OLD | NEW |