OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 10 matching lines...) Expand all Loading... |
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 "src/v8.h" | 28 #include "src/v8.h" |
29 #include "test/cctest/cctest.h" | 29 #include "test/cctest/cctest.h" |
30 | 30 |
| 31 #include "src/base/platform/platform.h" |
31 #include "src/isolate.h" | 32 #include "src/isolate.h" |
32 #include "src/platform.h" | |
33 | 33 |
34 | 34 |
35 enum Turn { | 35 enum Turn { |
36 FILL_CACHE, | 36 FILL_CACHE, |
37 CLEAN_CACHE, | 37 CLEAN_CACHE, |
38 SECOND_TIME_FILL_CACHE, | 38 SECOND_TIME_FILL_CACHE, |
39 DONE | 39 DONE |
40 }; | 40 }; |
41 | 41 |
42 static Turn turn = FILL_CACHE; | 42 static Turn turn = FILL_CACHE; |
43 | 43 |
44 | 44 |
45 class ThreadA : public v8::internal::Thread { | 45 class ThreadA : public v8::base::Thread { |
46 public: | 46 public: |
47 ThreadA() : Thread("ThreadA") { } | 47 ThreadA() : Thread("ThreadA") { } |
48 void Run() { | 48 void Run() { |
49 v8::Isolate* isolate = CcTest::isolate(); | 49 v8::Isolate* isolate = CcTest::isolate(); |
50 v8::Locker locker(isolate); | 50 v8::Locker locker(isolate); |
51 v8::Isolate::Scope isolate_scope(isolate); | 51 v8::Isolate::Scope isolate_scope(isolate); |
52 v8::HandleScope scope(isolate); | 52 v8::HandleScope scope(isolate); |
53 v8::Handle<v8::Context> context = v8::Context::New(isolate); | 53 v8::Handle<v8::Context> context = v8::Context::New(isolate); |
54 v8::Context::Scope context_scope(context); | 54 v8::Context::Scope context_scope(context); |
55 | 55 |
(...skipping 19 matching lines...) Expand all Loading... |
75 } while (turn != SECOND_TIME_FILL_CACHE); | 75 } while (turn != SECOND_TIME_FILL_CACHE); |
76 | 76 |
77 // Rerun the script. | 77 // Rerun the script. |
78 CHECK(script->Run()->IsTrue()); | 78 CHECK(script->Run()->IsTrue()); |
79 | 79 |
80 turn = DONE; | 80 turn = DONE; |
81 } | 81 } |
82 }; | 82 }; |
83 | 83 |
84 | 84 |
85 class ThreadB : public v8::internal::Thread { | 85 class ThreadB : public v8::base::Thread { |
86 public: | 86 public: |
87 ThreadB() : Thread("ThreadB") { } | 87 ThreadB() : Thread("ThreadB") { } |
88 void Run() { | 88 void Run() { |
89 do { | 89 do { |
90 { | 90 { |
91 v8::Isolate* isolate = CcTest::isolate(); | 91 v8::Isolate* isolate = CcTest::isolate(); |
92 v8::Locker locker(isolate); | 92 v8::Locker locker(isolate); |
93 v8::Isolate::Scope isolate_scope(isolate); | 93 v8::Isolate::Scope isolate_scope(isolate); |
94 if (turn == CLEAN_CACHE) { | 94 if (turn == CLEAN_CACHE) { |
95 v8::HandleScope scope(isolate); | 95 v8::HandleScope scope(isolate); |
(...skipping 19 matching lines...) Expand all Loading... |
115 | 115 |
116 threadA.Start(); | 116 threadA.Start(); |
117 threadB.Start(); | 117 threadB.Start(); |
118 | 118 |
119 threadA.Join(); | 119 threadA.Join(); |
120 threadB.Join(); | 120 threadB.Join(); |
121 | 121 |
122 CHECK_EQ(DONE, turn); | 122 CHECK_EQ(DONE, turn); |
123 } | 123 } |
124 | 124 |
125 class ThreadIdValidationThread : public v8::internal::Thread { | 125 class ThreadIdValidationThread : public v8::base::Thread { |
126 public: | 126 public: |
127 ThreadIdValidationThread(i::Thread* thread_to_start, | 127 ThreadIdValidationThread(v8::base::Thread* thread_to_start, |
128 i::List<i::ThreadId>* refs, | 128 i::List<i::ThreadId>* refs, |
129 unsigned int thread_no, | 129 unsigned int thread_no, |
130 i::Semaphore* semaphore) | 130 v8::base::Semaphore* semaphore) |
131 : Thread("ThreadRefValidationThread"), | 131 : Thread("ThreadRefValidationThread"), |
132 refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start), | 132 refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start), |
133 semaphore_(semaphore) { | 133 semaphore_(semaphore) { |
134 } | 134 } |
135 | 135 |
136 void Run() { | 136 void Run() { |
137 i::ThreadId thread_id = i::ThreadId::Current(); | 137 i::ThreadId thread_id = i::ThreadId::Current(); |
138 for (int i = 0; i < thread_no_; i++) { | 138 for (int i = 0; i < thread_no_; i++) { |
139 CHECK(!(*refs_)[i].Equals(thread_id)); | 139 CHECK(!(*refs_)[i].Equals(thread_id)); |
140 } | 140 } |
141 CHECK(thread_id.IsValid()); | 141 CHECK(thread_id.IsValid()); |
142 (*refs_)[thread_no_] = thread_id; | 142 (*refs_)[thread_no_] = thread_id; |
143 if (thread_to_start_ != NULL) { | 143 if (thread_to_start_ != NULL) { |
144 thread_to_start_->Start(); | 144 thread_to_start_->Start(); |
145 } | 145 } |
146 semaphore_->Signal(); | 146 semaphore_->Signal(); |
147 } | 147 } |
148 | 148 |
149 private: | 149 private: |
150 i::List<i::ThreadId>* refs_; | 150 i::List<i::ThreadId>* refs_; |
151 int thread_no_; | 151 int thread_no_; |
152 i::Thread* thread_to_start_; | 152 v8::base::Thread* thread_to_start_; |
153 i::Semaphore* semaphore_; | 153 v8::base::Semaphore* semaphore_; |
154 }; | 154 }; |
155 | 155 |
156 | 156 |
157 TEST(ThreadIdValidation) { | 157 TEST(ThreadIdValidation) { |
158 const int kNThreads = 100; | 158 const int kNThreads = 100; |
159 i::List<ThreadIdValidationThread*> threads(kNThreads); | 159 i::List<ThreadIdValidationThread*> threads(kNThreads); |
160 i::List<i::ThreadId> refs(kNThreads); | 160 i::List<i::ThreadId> refs(kNThreads); |
161 i::Semaphore semaphore(0); | 161 v8::base::Semaphore semaphore(0); |
162 ThreadIdValidationThread* prev = NULL; | 162 ThreadIdValidationThread* prev = NULL; |
163 for (int i = kNThreads - 1; i >= 0; i--) { | 163 for (int i = kNThreads - 1; i >= 0; i--) { |
164 ThreadIdValidationThread* newThread = | 164 ThreadIdValidationThread* newThread = |
165 new ThreadIdValidationThread(prev, &refs, i, &semaphore); | 165 new ThreadIdValidationThread(prev, &refs, i, &semaphore); |
166 threads.Add(newThread); | 166 threads.Add(newThread); |
167 prev = newThread; | 167 prev = newThread; |
168 refs.Add(i::ThreadId::Invalid()); | 168 refs.Add(i::ThreadId::Invalid()); |
169 } | 169 } |
170 prev->Start(); | 170 prev->Start(); |
171 for (int i = 0; i < kNThreads; i++) { | 171 for (int i = 0; i < kNThreads; i++) { |
172 semaphore.Wait(); | 172 semaphore.Wait(); |
173 } | 173 } |
174 for (int i = 0; i < kNThreads; i++) { | 174 for (int i = 0; i < kNThreads; i++) { |
175 delete threads[i]; | 175 delete threads[i]; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 class ThreadC : public v8::internal::Thread { | 180 class ThreadC : public v8::base::Thread { |
181 public: | 181 public: |
182 ThreadC() : Thread("ThreadC") { } | 182 ThreadC() : Thread("ThreadC") { } |
183 void Run() { | 183 void Run() { |
184 Join(); | 184 Join(); |
185 } | 185 } |
186 }; | 186 }; |
187 | 187 |
188 | 188 |
189 TEST(ThreadJoinSelf) { | 189 TEST(ThreadJoinSelf) { |
190 ThreadC thread; | 190 ThreadC thread; |
191 thread.Start(); | 191 thread.Start(); |
192 thread.Join(); | 192 thread.Join(); |
193 } | 193 } |
OLD | NEW |