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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 #endif | 214 #endif |
215 i::List<JoinableThread*> threads(kNThreads); | 215 i::List<JoinableThread*> threads(kNThreads); |
216 v8::Isolate* isolate = v8::Isolate::New(); | 216 v8::Isolate* isolate = v8::Isolate::New(); |
217 for (int i = 0; i < kNThreads; i++) { | 217 for (int i = 0; i < kNThreads; i++) { |
218 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); | 218 threads.Add(new IsolateLockingThreadWithLocalContext(isolate)); |
219 } | 219 } |
220 StartJoinAndDeleteThreads(threads); | 220 StartJoinAndDeleteThreads(threads); |
221 isolate->Dispose(); | 221 isolate->Dispose(); |
222 } | 222 } |
223 | 223 |
224 class IsolateNonlockingThread : public JoinableThread { | |
225 public: | |
226 IsolateNonlockingThread() : JoinableThread("IsolateNonlockingThread") {} | |
227 | |
228 virtual void Run() { | |
229 v8::Isolate* isolate = v8::Isolate::New(); | |
230 { | |
231 v8::Isolate::Scope isolate_scope(isolate); | |
232 v8::HandleScope handle_scope(isolate); | |
233 v8::Handle<v8::Context> context = v8::Context::New(isolate); | |
234 v8::Context::Scope context_scope(context); | |
235 CHECK_EQ(isolate, v8::internal::Isolate::Current()); | |
236 CalcFibAndCheck(); | |
237 } | |
238 isolate->Dispose(); | |
239 } | |
240 private: | |
241 }; | |
242 | |
243 | |
244 // Run many threads each accessing its own isolate without locking | |
245 TEST(MultithreadedParallelIsolates) { | |
246 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS | |
247 const int kNThreads = 10; | |
248 #elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT | |
249 const int kNThreads = 4; | |
250 #else | |
251 const int kNThreads = 50; | |
252 #endif | |
253 i::List<JoinableThread*> threads(kNThreads); | |
254 for (int i = 0; i < kNThreads; i++) { | |
255 threads.Add(new IsolateNonlockingThread()); | |
256 } | |
257 StartJoinAndDeleteThreads(threads); | |
258 } | |
259 | |
260 | 224 |
261 class IsolateNestedLockingThread : public JoinableThread { | 225 class IsolateNestedLockingThread : public JoinableThread { |
262 public: | 226 public: |
263 explicit IsolateNestedLockingThread(v8::Isolate* isolate) | 227 explicit IsolateNestedLockingThread(v8::Isolate* isolate) |
264 : JoinableThread("IsolateNestedLocking"), isolate_(isolate) { | 228 : JoinableThread("IsolateNestedLocking"), isolate_(isolate) { |
265 } | 229 } |
266 virtual void Run() { | 230 virtual void Run() { |
267 v8::Locker lock(isolate_); | 231 v8::Locker lock(isolate_); |
268 v8::Isolate::Scope isolate_scope(isolate_); | 232 v8::Isolate::Scope isolate_scope(isolate_); |
269 v8::HandleScope handle_scope(isolate_); | 233 v8::HandleScope handle_scope(isolate_); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 kSimpleExtensionSource)); | 700 kSimpleExtensionSource)); |
737 const char* extension_names[] = { "test0", "test1", | 701 const char* extension_names[] = { "test0", "test1", |
738 "test2", "test3", "test4", | 702 "test2", "test3", "test4", |
739 "test5", "test6", "test7" }; | 703 "test5", "test6", "test7" }; |
740 i::List<JoinableThread*> threads(kNThreads); | 704 i::List<JoinableThread*> threads(kNThreads); |
741 for (int i = 0; i < kNThreads; i++) { | 705 for (int i = 0; i < kNThreads; i++) { |
742 threads.Add(new IsolateGenesisThread(8, extension_names)); | 706 threads.Add(new IsolateGenesisThread(8, extension_names)); |
743 } | 707 } |
744 StartJoinAndDeleteThreads(threads); | 708 StartJoinAndDeleteThreads(threads); |
745 } | 709 } |
OLD | NEW |