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 // TODO(jochen): Remove this after the setting is turned on globally. |
| 29 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 30 |
28 #include <limits.h> | 31 #include <limits.h> |
29 | 32 |
30 #include "src/v8.h" | 33 #include "src/v8.h" |
31 | 34 |
32 #include "src/api.h" | 35 #include "src/api.h" |
33 #include "src/base/platform/platform.h" | 36 #include "src/base/platform/platform.h" |
34 #include "src/base/smart-pointers.h" | 37 #include "src/base/smart-pointers.h" |
35 #include "src/compilation-cache.h" | 38 #include "src/compilation-cache.h" |
36 #include "src/execution.h" | 39 #include "src/execution.h" |
37 #include "src/isolate.h" | 40 #include "src/isolate.h" |
(...skipping 12 matching lines...) Expand all Loading... |
50 using ::v8::Persistent; | 53 using ::v8::Persistent; |
51 using ::v8::Script; | 54 using ::v8::Script; |
52 using ::v8::String; | 55 using ::v8::String; |
53 using ::v8::Value; | 56 using ::v8::Value; |
54 using ::v8::V8; | 57 using ::v8::V8; |
55 | 58 |
56 | 59 |
57 // Migrating an isolate | 60 // Migrating an isolate |
58 class KangarooThread : public v8::base::Thread { | 61 class KangarooThread : public v8::base::Thread { |
59 public: | 62 public: |
60 KangarooThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) | 63 KangarooThread(v8::Isolate* isolate, v8::Local<v8::Context> context) |
61 : Thread(Options("KangarooThread")), | 64 : Thread(Options("KangarooThread")), |
62 isolate_(isolate), | 65 isolate_(isolate), |
63 context_(isolate, context) {} | 66 context_(isolate, context) {} |
64 | 67 |
65 void Run() { | 68 void Run() { |
66 { | 69 { |
67 v8::Locker locker(isolate_); | 70 v8::Locker locker(isolate_); |
68 v8::Isolate::Scope isolate_scope(isolate_); | 71 v8::Isolate::Scope isolate_scope(isolate_); |
69 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate_), | 72 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate_), |
70 v8::internal::Isolate::Current()); | 73 v8::internal::Isolate::Current()); |
71 v8::HandleScope scope(isolate_); | 74 v8::HandleScope scope(isolate_); |
72 v8::Local<v8::Context> context = | 75 v8::Local<v8::Context> context = |
73 v8::Local<v8::Context>::New(isolate_, context_); | 76 v8::Local<v8::Context>::New(isolate_, context_); |
74 v8::Context::Scope context_scope(context); | 77 v8::Context::Scope context_scope(context); |
75 Local<Value> v = CompileRun("getValue()"); | 78 Local<Value> v = CompileRun("getValue()"); |
76 CHECK(v->IsNumber()); | 79 CHECK(v->IsNumber()); |
77 CHECK_EQ(30, static_cast<int>(v->NumberValue())); | 80 CHECK_EQ(30, static_cast<int>(v->NumberValue(context).FromJust())); |
78 } | 81 } |
79 { | 82 { |
80 v8::Locker locker(isolate_); | 83 v8::Locker locker(isolate_); |
81 v8::Isolate::Scope isolate_scope(isolate_); | 84 v8::Isolate::Scope isolate_scope(isolate_); |
82 v8::HandleScope scope(isolate_); | 85 v8::HandleScope scope(isolate_); |
83 v8::Local<v8::Context> context = | 86 v8::Local<v8::Context> context = |
84 v8::Local<v8::Context>::New(isolate_, context_); | 87 v8::Local<v8::Context>::New(isolate_, context_); |
85 v8::Context::Scope context_scope(context); | 88 v8::Context::Scope context_scope(context); |
86 Local<Value> v = CompileRun("getValue()"); | 89 Local<Value> v = CompileRun("getValue()"); |
87 CHECK(v->IsNumber()); | 90 CHECK(v->IsNumber()); |
88 CHECK_EQ(30, static_cast<int>(v->NumberValue())); | 91 CHECK_EQ(30, static_cast<int>(v->NumberValue(context).FromJust())); |
89 } | 92 } |
90 isolate_->Dispose(); | 93 isolate_->Dispose(); |
91 } | 94 } |
92 | 95 |
93 private: | 96 private: |
94 v8::Isolate* isolate_; | 97 v8::Isolate* isolate_; |
95 Persistent<v8::Context> context_; | 98 Persistent<v8::Context> context_; |
96 }; | 99 }; |
97 | 100 |
98 | 101 |
(...skipping 12 matching lines...) Expand all Loading... |
111 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate), | 114 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate), |
112 v8::internal::Isolate::Current()); | 115 v8::internal::Isolate::Current()); |
113 CompileRun("function getValue() { return 30; }"); | 116 CompileRun("function getValue() { return 30; }"); |
114 thread1.Reset(new KangarooThread(isolate, context)); | 117 thread1.Reset(new KangarooThread(isolate, context)); |
115 } | 118 } |
116 thread1->Start(); | 119 thread1->Start(); |
117 thread1->Join(); | 120 thread1->Join(); |
118 } | 121 } |
119 | 122 |
120 | 123 |
121 static void CalcFibAndCheck() { | 124 static void CalcFibAndCheck(v8::Local<v8::Context> context) { |
122 Local<Value> v = CompileRun("function fib(n) {" | 125 Local<Value> v = CompileRun("function fib(n) {" |
123 " if (n <= 2) return 1;" | 126 " if (n <= 2) return 1;" |
124 " return fib(n-1) + fib(n-2);" | 127 " return fib(n-1) + fib(n-2);" |
125 "}" | 128 "}" |
126 "fib(10)"); | 129 "fib(10)"); |
127 CHECK(v->IsNumber()); | 130 CHECK(v->IsNumber()); |
128 CHECK_EQ(55, static_cast<int>(v->NumberValue())); | 131 CHECK_EQ(55, static_cast<int>(v->NumberValue(context).FromJust())); |
129 } | 132 } |
130 | 133 |
131 class JoinableThread { | 134 class JoinableThread { |
132 public: | 135 public: |
133 explicit JoinableThread(const char* name) | 136 explicit JoinableThread(const char* name) |
134 : name_(name), | 137 : name_(name), |
135 semaphore_(0), | 138 semaphore_(0), |
136 thread_(this) { | 139 thread_(this) { |
137 } | 140 } |
138 | 141 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 isolate_(isolate) { | 185 isolate_(isolate) { |
183 } | 186 } |
184 | 187 |
185 virtual void Run() { | 188 virtual void Run() { |
186 v8::Locker locker(isolate_); | 189 v8::Locker locker(isolate_); |
187 v8::Isolate::Scope isolate_scope(isolate_); | 190 v8::Isolate::Scope isolate_scope(isolate_); |
188 v8::HandleScope handle_scope(isolate_); | 191 v8::HandleScope handle_scope(isolate_); |
189 LocalContext local_context(isolate_); | 192 LocalContext local_context(isolate_); |
190 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate_), | 193 CHECK_EQ(reinterpret_cast<v8::internal::Isolate*>(isolate_), |
191 v8::internal::Isolate::Current()); | 194 v8::internal::Isolate::Current()); |
192 CalcFibAndCheck(); | 195 CalcFibAndCheck(local_context.local()); |
193 } | 196 } |
194 private: | 197 private: |
195 v8::Isolate* isolate_; | 198 v8::Isolate* isolate_; |
196 }; | 199 }; |
197 | 200 |
198 | 201 |
199 static void StartJoinAndDeleteThreads(const i::List<JoinableThread*>& threads) { | 202 static void StartJoinAndDeleteThreads(const i::List<JoinableThread*>& threads) { |
200 for (int i = 0; i < threads.length(); i++) { | 203 for (int i = 0; i < threads.length(); i++) { |
201 threads[i]->Start(); | 204 threads[i]->Start(); |
202 } | 205 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 explicit IsolateNestedLockingThread(v8::Isolate* isolate) | 237 explicit IsolateNestedLockingThread(v8::Isolate* isolate) |
235 : JoinableThread("IsolateNestedLocking"), isolate_(isolate) { | 238 : JoinableThread("IsolateNestedLocking"), isolate_(isolate) { |
236 } | 239 } |
237 virtual void Run() { | 240 virtual void Run() { |
238 v8::Locker lock(isolate_); | 241 v8::Locker lock(isolate_); |
239 v8::Isolate::Scope isolate_scope(isolate_); | 242 v8::Isolate::Scope isolate_scope(isolate_); |
240 v8::HandleScope handle_scope(isolate_); | 243 v8::HandleScope handle_scope(isolate_); |
241 LocalContext local_context(isolate_); | 244 LocalContext local_context(isolate_); |
242 { | 245 { |
243 v8::Locker another_lock(isolate_); | 246 v8::Locker another_lock(isolate_); |
244 CalcFibAndCheck(); | 247 CalcFibAndCheck(local_context.local()); |
245 } | 248 } |
246 { | 249 { |
247 v8::Locker another_lock(isolate_); | 250 v8::Locker another_lock(isolate_); |
248 CalcFibAndCheck(); | 251 CalcFibAndCheck(local_context.local()); |
249 } | 252 } |
250 } | 253 } |
251 private: | 254 private: |
252 v8::Isolate* isolate_; | 255 v8::Isolate* isolate_; |
253 }; | 256 }; |
254 | 257 |
255 | 258 |
256 // Run many threads with nested locks | 259 // Run many threads with nested locks |
257 TEST(IsolateNestedLocking) { | 260 TEST(IsolateNestedLocking) { |
258 i::FLAG_always_opt = false; | 261 i::FLAG_always_opt = false; |
(...skipping 23 matching lines...) Expand all Loading... |
282 } | 285 } |
283 | 286 |
284 virtual void Run() { | 287 virtual void Run() { |
285 v8::Locker lock(isolate1_); | 288 v8::Locker lock(isolate1_); |
286 v8::Isolate::Scope isolate_scope(isolate1_); | 289 v8::Isolate::Scope isolate_scope(isolate1_); |
287 v8::HandleScope handle_scope(isolate1_); | 290 v8::HandleScope handle_scope(isolate1_); |
288 LocalContext local_context(isolate1_); | 291 LocalContext local_context(isolate1_); |
289 | 292 |
290 IsolateLockingThreadWithLocalContext threadB(isolate2_); | 293 IsolateLockingThreadWithLocalContext threadB(isolate2_); |
291 threadB.Start(); | 294 threadB.Start(); |
292 CalcFibAndCheck(); | 295 CalcFibAndCheck(local_context.local()); |
293 threadB.Join(); | 296 threadB.Join(); |
294 } | 297 } |
295 private: | 298 private: |
296 v8::Isolate* isolate1_; | 299 v8::Isolate* isolate1_; |
297 v8::Isolate* isolate2_; | 300 v8::Isolate* isolate2_; |
298 }; | 301 }; |
299 | 302 |
300 | 303 |
301 // Run parallel threads that lock and access different isolates in parallel | 304 // Run parallel threads that lock and access different isolates in parallel |
302 TEST(SeparateIsolatesLocksNonexclusive) { | 305 TEST(SeparateIsolatesLocksNonexclusive) { |
(...skipping 13 matching lines...) Expand all Loading... |
316 isolate2)); | 319 isolate2)); |
317 } | 320 } |
318 StartJoinAndDeleteThreads(threads); | 321 StartJoinAndDeleteThreads(threads); |
319 isolate2->Dispose(); | 322 isolate2->Dispose(); |
320 isolate1->Dispose(); | 323 isolate1->Dispose(); |
321 } | 324 } |
322 | 325 |
323 class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread { | 326 class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread { |
324 public: | 327 public: |
325 explicit LockIsolateAndCalculateFibSharedContextThread( | 328 explicit LockIsolateAndCalculateFibSharedContextThread( |
326 v8::Isolate* isolate, v8::Handle<v8::Context> context) | 329 v8::Isolate* isolate, v8::Local<v8::Context> context) |
327 : JoinableThread("LockIsolateAndCalculateFibThread"), | 330 : JoinableThread("LockIsolateAndCalculateFibThread"), |
328 isolate_(isolate), | 331 isolate_(isolate), |
329 context_(isolate, context) { | 332 context_(isolate, context) {} |
330 } | |
331 | 333 |
332 virtual void Run() { | 334 virtual void Run() { |
333 v8::Locker lock(isolate_); | 335 v8::Locker lock(isolate_); |
334 v8::Isolate::Scope isolate_scope(isolate_); | 336 v8::Isolate::Scope isolate_scope(isolate_); |
335 HandleScope handle_scope(isolate_); | 337 HandleScope handle_scope(isolate_); |
336 v8::Local<v8::Context> context = | 338 v8::Local<v8::Context> context = |
337 v8::Local<v8::Context>::New(isolate_, context_); | 339 v8::Local<v8::Context>::New(isolate_, context_); |
338 v8::Context::Scope context_scope(context); | 340 v8::Context::Scope context_scope(context); |
339 CalcFibAndCheck(); | 341 CalcFibAndCheck(context); |
340 } | 342 } |
341 private: | 343 private: |
342 v8::Isolate* isolate_; | 344 v8::Isolate* isolate_; |
343 Persistent<v8::Context> context_; | 345 Persistent<v8::Context> context_; |
344 }; | 346 }; |
345 | 347 |
346 class LockerUnlockerThread : public JoinableThread { | 348 class LockerUnlockerThread : public JoinableThread { |
347 public: | 349 public: |
348 explicit LockerUnlockerThread(v8::Isolate* isolate) | 350 explicit LockerUnlockerThread(v8::Isolate* isolate) |
349 : JoinableThread("LockerUnlockerThread"), | 351 : JoinableThread("LockerUnlockerThread"), |
350 isolate_(isolate) { | 352 isolate_(isolate) { |
351 } | 353 } |
352 | 354 |
353 virtual void Run() { | 355 virtual void Run() { |
354 v8::Locker lock(isolate_); | 356 v8::Locker lock(isolate_); |
355 v8::Isolate::Scope isolate_scope(isolate_); | 357 v8::Isolate::Scope isolate_scope(isolate_); |
356 v8::HandleScope handle_scope(isolate_); | 358 v8::HandleScope handle_scope(isolate_); |
357 v8::Local<v8::Context> context = v8::Context::New(isolate_); | 359 v8::Local<v8::Context> context = v8::Context::New(isolate_); |
358 { | 360 { |
359 v8::Context::Scope context_scope(context); | 361 v8::Context::Scope context_scope(context); |
360 CalcFibAndCheck(); | 362 CalcFibAndCheck(context); |
361 } | 363 } |
362 { | 364 { |
363 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); | 365 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
364 isolate_->Exit(); | 366 isolate_->Exit(); |
365 v8::Unlocker unlocker(isolate_); | 367 v8::Unlocker unlocker(isolate_); |
366 thread.Start(); | 368 thread.Start(); |
367 thread.Join(); | 369 thread.Join(); |
368 } | 370 } |
369 isolate_->Enter(); | 371 isolate_->Enter(); |
370 { | 372 { |
371 v8::Context::Scope context_scope(context); | 373 v8::Context::Scope context_scope(context); |
372 CalcFibAndCheck(); | 374 CalcFibAndCheck(context); |
373 } | 375 } |
374 } | 376 } |
375 | 377 |
376 private: | 378 private: |
377 v8::Isolate* isolate_; | 379 v8::Isolate* isolate_; |
378 }; | 380 }; |
379 | 381 |
380 | 382 |
381 // Use unlocker inside of a Locker, multiple threads. | 383 // Use unlocker inside of a Locker, multiple threads. |
382 TEST(LockerUnlocker) { | 384 TEST(LockerUnlocker) { |
(...skipping 21 matching lines...) Expand all Loading... |
404 isolate_(isolate) { | 406 isolate_(isolate) { |
405 } | 407 } |
406 | 408 |
407 virtual void Run() { | 409 virtual void Run() { |
408 v8::Locker lock(isolate_); | 410 v8::Locker lock(isolate_); |
409 v8::Isolate::Scope isolate_scope(isolate_); | 411 v8::Isolate::Scope isolate_scope(isolate_); |
410 v8::HandleScope handle_scope(isolate_); | 412 v8::HandleScope handle_scope(isolate_); |
411 v8::Local<v8::Context> context = v8::Context::New(isolate_); | 413 v8::Local<v8::Context> context = v8::Context::New(isolate_); |
412 { | 414 { |
413 v8::Context::Scope context_scope(context); | 415 v8::Context::Scope context_scope(context); |
414 CalcFibAndCheck(); | 416 CalcFibAndCheck(context); |
415 } | 417 } |
416 { | 418 { |
417 v8::Locker second_lock(isolate_); | 419 v8::Locker second_lock(isolate_); |
418 { | 420 { |
419 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); | 421 LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
420 isolate_->Exit(); | 422 isolate_->Exit(); |
421 v8::Unlocker unlocker(isolate_); | 423 v8::Unlocker unlocker(isolate_); |
422 thread.Start(); | 424 thread.Start(); |
423 thread.Join(); | 425 thread.Join(); |
424 } | 426 } |
425 } | 427 } |
426 isolate_->Enter(); | 428 isolate_->Enter(); |
427 { | 429 { |
428 v8::Context::Scope context_scope(context); | 430 v8::Context::Scope context_scope(context); |
429 CalcFibAndCheck(); | 431 CalcFibAndCheck(context); |
430 } | 432 } |
431 } | 433 } |
432 | 434 |
433 private: | 435 private: |
434 v8::Isolate* isolate_; | 436 v8::Isolate* isolate_; |
435 }; | 437 }; |
436 | 438 |
437 | 439 |
438 // Use Unlocker inside two Lockers. | 440 // Use Unlocker inside two Lockers. |
439 TEST(LockTwiceAndUnlock) { | 441 TEST(LockTwiceAndUnlock) { |
(...skipping 25 matching lines...) Expand all Loading... |
465 | 467 |
466 virtual void Run() { | 468 virtual void Run() { |
467 v8::base::SmartPointer<LockIsolateAndCalculateFibSharedContextThread> | 469 v8::base::SmartPointer<LockIsolateAndCalculateFibSharedContextThread> |
468 thread; | 470 thread; |
469 v8::Locker lock1(isolate1_); | 471 v8::Locker lock1(isolate1_); |
470 CHECK(v8::Locker::IsLocked(isolate1_)); | 472 CHECK(v8::Locker::IsLocked(isolate1_)); |
471 CHECK(!v8::Locker::IsLocked(isolate2_)); | 473 CHECK(!v8::Locker::IsLocked(isolate2_)); |
472 { | 474 { |
473 v8::Isolate::Scope isolate_scope(isolate1_); | 475 v8::Isolate::Scope isolate_scope(isolate1_); |
474 v8::HandleScope handle_scope(isolate1_); | 476 v8::HandleScope handle_scope(isolate1_); |
475 v8::Handle<v8::Context> context1 = v8::Context::New(isolate1_); | 477 v8::Local<v8::Context> context1 = v8::Context::New(isolate1_); |
476 { | 478 { |
477 v8::Context::Scope context_scope(context1); | 479 v8::Context::Scope context_scope(context1); |
478 CalcFibAndCheck(); | 480 CalcFibAndCheck(context1); |
479 } | 481 } |
480 thread.Reset(new LockIsolateAndCalculateFibSharedContextThread( | 482 thread.Reset(new LockIsolateAndCalculateFibSharedContextThread( |
481 isolate1_, context1)); | 483 isolate1_, context1)); |
482 } | 484 } |
483 v8::Locker lock2(isolate2_); | 485 v8::Locker lock2(isolate2_); |
484 CHECK(v8::Locker::IsLocked(isolate1_)); | 486 CHECK(v8::Locker::IsLocked(isolate1_)); |
485 CHECK(v8::Locker::IsLocked(isolate2_)); | 487 CHECK(v8::Locker::IsLocked(isolate2_)); |
486 { | 488 { |
487 v8::Isolate::Scope isolate_scope(isolate2_); | 489 v8::Isolate::Scope isolate_scope(isolate2_); |
488 v8::HandleScope handle_scope(isolate2_); | 490 v8::HandleScope handle_scope(isolate2_); |
489 v8::Handle<v8::Context> context2 = v8::Context::New(isolate2_); | 491 v8::Local<v8::Context> context2 = v8::Context::New(isolate2_); |
490 { | 492 { |
491 v8::Context::Scope context_scope(context2); | 493 v8::Context::Scope context_scope(context2); |
492 CalcFibAndCheck(); | 494 CalcFibAndCheck(context2); |
493 } | 495 } |
494 v8::Unlocker unlock1(isolate1_); | 496 v8::Unlocker unlock1(isolate1_); |
495 CHECK(!v8::Locker::IsLocked(isolate1_)); | 497 CHECK(!v8::Locker::IsLocked(isolate1_)); |
496 CHECK(v8::Locker::IsLocked(isolate2_)); | 498 CHECK(v8::Locker::IsLocked(isolate2_)); |
497 v8::Context::Scope context_scope(context2); | 499 v8::Context::Scope context_scope(context2); |
498 thread->Start(); | 500 thread->Start(); |
499 CalcFibAndCheck(); | 501 CalcFibAndCheck(context2); |
500 thread->Join(); | 502 thread->Join(); |
501 } | 503 } |
502 } | 504 } |
503 | 505 |
504 private: | 506 private: |
505 v8::Isolate* isolate1_; | 507 v8::Isolate* isolate1_; |
506 v8::Isolate* isolate2_; | 508 v8::Isolate* isolate2_; |
507 }; | 509 }; |
508 | 510 |
509 | 511 |
510 // Lock two isolates and unlock one of them. | 512 // Lock two isolates and unlock one of them. |
511 TEST(LockAndUnlockDifferentIsolates) { | 513 TEST(LockAndUnlockDifferentIsolates) { |
512 v8::Isolate::CreateParams create_params; | 514 v8::Isolate::CreateParams create_params; |
513 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 515 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
514 v8::Isolate* isolate1 = v8::Isolate::New(create_params); | 516 v8::Isolate* isolate1 = v8::Isolate::New(create_params); |
515 v8::Isolate* isolate2 = v8::Isolate::New(create_params); | 517 v8::Isolate* isolate2 = v8::Isolate::New(create_params); |
516 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); | 518 LockAndUnlockDifferentIsolatesThread thread(isolate1, isolate2); |
517 thread.Start(); | 519 thread.Start(); |
518 thread.Join(); | 520 thread.Join(); |
519 isolate2->Dispose(); | 521 isolate2->Dispose(); |
520 isolate1->Dispose(); | 522 isolate1->Dispose(); |
521 } | 523 } |
522 | 524 |
523 class LockUnlockLockThread : public JoinableThread { | 525 class LockUnlockLockThread : public JoinableThread { |
524 public: | 526 public: |
525 LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) | 527 LockUnlockLockThread(v8::Isolate* isolate, v8::Local<v8::Context> context) |
526 : JoinableThread("LockUnlockLockThread"), | 528 : JoinableThread("LockUnlockLockThread"), |
527 isolate_(isolate), | 529 isolate_(isolate), |
528 context_(isolate, context) { | 530 context_(isolate, context) {} |
529 } | |
530 | 531 |
531 virtual void Run() { | 532 virtual void Run() { |
532 v8::Locker lock1(isolate_); | 533 v8::Locker lock1(isolate_); |
533 CHECK(v8::Locker::IsLocked(isolate_)); | 534 CHECK(v8::Locker::IsLocked(isolate_)); |
534 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); | 535 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); |
535 { | 536 { |
536 v8::Isolate::Scope isolate_scope(isolate_); | 537 v8::Isolate::Scope isolate_scope(isolate_); |
537 v8::HandleScope handle_scope(isolate_); | 538 v8::HandleScope handle_scope(isolate_); |
538 v8::Local<v8::Context> context = | 539 v8::Local<v8::Context> context = |
539 v8::Local<v8::Context>::New(isolate_, context_); | 540 v8::Local<v8::Context>::New(isolate_, context_); |
540 v8::Context::Scope context_scope(context); | 541 v8::Context::Scope context_scope(context); |
541 CalcFibAndCheck(); | 542 CalcFibAndCheck(context); |
542 } | 543 } |
543 { | 544 { |
544 v8::Unlocker unlock1(isolate_); | 545 v8::Unlocker unlock1(isolate_); |
545 CHECK(!v8::Locker::IsLocked(isolate_)); | 546 CHECK(!v8::Locker::IsLocked(isolate_)); |
546 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); | 547 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); |
547 { | 548 { |
548 v8::Locker lock2(isolate_); | 549 v8::Locker lock2(isolate_); |
549 v8::Isolate::Scope isolate_scope(isolate_); | 550 v8::Isolate::Scope isolate_scope(isolate_); |
550 v8::HandleScope handle_scope(isolate_); | 551 v8::HandleScope handle_scope(isolate_); |
551 CHECK(v8::Locker::IsLocked(isolate_)); | 552 CHECK(v8::Locker::IsLocked(isolate_)); |
552 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); | 553 CHECK(!v8::Locker::IsLocked(CcTest::isolate())); |
553 v8::Local<v8::Context> context = | 554 v8::Local<v8::Context> context = |
554 v8::Local<v8::Context>::New(isolate_, context_); | 555 v8::Local<v8::Context>::New(isolate_, context_); |
555 v8::Context::Scope context_scope(context); | 556 v8::Context::Scope context_scope(context); |
556 CalcFibAndCheck(); | 557 CalcFibAndCheck(context); |
557 } | 558 } |
558 } | 559 } |
559 } | 560 } |
560 | 561 |
561 private: | 562 private: |
562 v8::Isolate* isolate_; | 563 v8::Isolate* isolate_; |
563 v8::Persistent<v8::Context> context_; | 564 v8::Persistent<v8::Context> context_; |
564 }; | 565 }; |
565 | 566 |
566 | 567 |
567 // Locker inside an Unlocker inside a Locker. | 568 // Locker inside an Unlocker inside a Locker. |
568 TEST(LockUnlockLockMultithreaded) { | 569 TEST(LockUnlockLockMultithreaded) { |
569 #if V8_TARGET_ARCH_MIPS | 570 #if V8_TARGET_ARCH_MIPS |
570 const int kNThreads = 50; | 571 const int kNThreads = 50; |
571 #else | 572 #else |
572 const int kNThreads = 100; | 573 const int kNThreads = 100; |
573 #endif | 574 #endif |
574 v8::Isolate::CreateParams create_params; | 575 v8::Isolate::CreateParams create_params; |
575 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 576 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
576 v8::Isolate* isolate = v8::Isolate::New(create_params); | 577 v8::Isolate* isolate = v8::Isolate::New(create_params); |
577 i::List<JoinableThread*> threads(kNThreads); | 578 i::List<JoinableThread*> threads(kNThreads); |
578 { | 579 { |
579 v8::Locker locker_(isolate); | 580 v8::Locker locker_(isolate); |
580 v8::Isolate::Scope isolate_scope(isolate); | 581 v8::Isolate::Scope isolate_scope(isolate); |
581 v8::HandleScope handle_scope(isolate); | 582 v8::HandleScope handle_scope(isolate); |
582 v8::Handle<v8::Context> context = v8::Context::New(isolate); | 583 v8::Local<v8::Context> context = v8::Context::New(isolate); |
583 for (int i = 0; i < kNThreads; i++) { | 584 for (int i = 0; i < kNThreads; i++) { |
584 threads.Add(new LockUnlockLockThread( | 585 threads.Add(new LockUnlockLockThread( |
585 isolate, context)); | 586 isolate, context)); |
586 } | 587 } |
587 } | 588 } |
588 StartJoinAndDeleteThreads(threads); | 589 StartJoinAndDeleteThreads(threads); |
589 isolate->Dispose(); | 590 isolate->Dispose(); |
590 } | 591 } |
591 | 592 |
592 class LockUnlockLockDefaultIsolateThread : public JoinableThread { | 593 class LockUnlockLockDefaultIsolateThread : public JoinableThread { |
593 public: | 594 public: |
594 explicit LockUnlockLockDefaultIsolateThread(v8::Handle<v8::Context> context) | 595 explicit LockUnlockLockDefaultIsolateThread(v8::Local<v8::Context> context) |
595 : JoinableThread("LockUnlockLockDefaultIsolateThread"), | 596 : JoinableThread("LockUnlockLockDefaultIsolateThread"), |
596 context_(CcTest::isolate(), context) {} | 597 context_(CcTest::isolate(), context) {} |
597 | 598 |
598 virtual void Run() { | 599 virtual void Run() { |
599 v8::Locker lock1(CcTest::isolate()); | 600 v8::Locker lock1(CcTest::isolate()); |
600 { | 601 { |
601 v8::Isolate::Scope isolate_scope(CcTest::isolate()); | 602 v8::Isolate::Scope isolate_scope(CcTest::isolate()); |
602 v8::HandleScope handle_scope(CcTest::isolate()); | 603 v8::HandleScope handle_scope(CcTest::isolate()); |
603 v8::Local<v8::Context> context = | 604 v8::Local<v8::Context> context = |
604 v8::Local<v8::Context>::New(CcTest::isolate(), context_); | 605 v8::Local<v8::Context>::New(CcTest::isolate(), context_); |
605 v8::Context::Scope context_scope(context); | 606 v8::Context::Scope context_scope(context); |
606 CalcFibAndCheck(); | 607 CalcFibAndCheck(context); |
607 } | 608 } |
608 { | 609 { |
609 v8::Unlocker unlock1(CcTest::isolate()); | 610 v8::Unlocker unlock1(CcTest::isolate()); |
610 { | 611 { |
611 v8::Locker lock2(CcTest::isolate()); | 612 v8::Locker lock2(CcTest::isolate()); |
612 v8::Isolate::Scope isolate_scope(CcTest::isolate()); | 613 v8::Isolate::Scope isolate_scope(CcTest::isolate()); |
613 v8::HandleScope handle_scope(CcTest::isolate()); | 614 v8::HandleScope handle_scope(CcTest::isolate()); |
614 v8::Local<v8::Context> context = | 615 v8::Local<v8::Context> context = |
615 v8::Local<v8::Context>::New(CcTest::isolate(), context_); | 616 v8::Local<v8::Context>::New(CcTest::isolate(), context_); |
616 v8::Context::Scope context_scope(context); | 617 v8::Context::Scope context_scope(context); |
617 CalcFibAndCheck(); | 618 CalcFibAndCheck(context); |
618 } | 619 } |
619 } | 620 } |
620 } | 621 } |
621 | 622 |
622 private: | 623 private: |
623 v8::Persistent<v8::Context> context_; | 624 v8::Persistent<v8::Context> context_; |
624 }; | 625 }; |
625 | 626 |
626 | 627 |
627 // Locker inside an Unlocker inside a Locker for default isolate. | 628 // Locker inside an Unlocker inside a Locker for default isolate. |
(...skipping 20 matching lines...) Expand all Loading... |
648 | 649 |
649 TEST(Regress1433) { | 650 TEST(Regress1433) { |
650 for (int i = 0; i < 10; i++) { | 651 for (int i = 0; i < 10; i++) { |
651 v8::Isolate::CreateParams create_params; | 652 v8::Isolate::CreateParams create_params; |
652 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 653 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
653 v8::Isolate* isolate = v8::Isolate::New(create_params); | 654 v8::Isolate* isolate = v8::Isolate::New(create_params); |
654 { | 655 { |
655 v8::Locker lock(isolate); | 656 v8::Locker lock(isolate); |
656 v8::Isolate::Scope isolate_scope(isolate); | 657 v8::Isolate::Scope isolate_scope(isolate); |
657 v8::HandleScope handle_scope(isolate); | 658 v8::HandleScope handle_scope(isolate); |
658 v8::Handle<Context> context = v8::Context::New(isolate); | 659 v8::Local<Context> context = v8::Context::New(isolate); |
659 v8::Context::Scope context_scope(context); | 660 v8::Context::Scope context_scope(context); |
660 v8::Handle<String> source = v8::String::NewFromUtf8(isolate, "1+1"); | 661 v8::Local<String> source = v8_str("1+1"); |
661 v8::Handle<Script> script = v8::Script::Compile(source); | 662 v8::Local<Script> script = |
662 v8::Handle<Value> result = script->Run(); | 663 v8::Script::Compile(context, source).ToLocalChecked(); |
| 664 v8::Local<Value> result = script->Run(context).ToLocalChecked(); |
663 v8::String::Utf8Value utf8(result); | 665 v8::String::Utf8Value utf8(result); |
664 } | 666 } |
665 isolate->Dispose(); | 667 isolate->Dispose(); |
666 } | 668 } |
667 } | 669 } |
668 | 670 |
669 | 671 |
670 static const char* kSimpleExtensionSource = | 672 static const char* kSimpleExtensionSource = |
671 "(function Foo() {" | 673 "(function Foo() {" |
672 " return 4;" | 674 " return 4;" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 kSimpleExtensionSource)); | 731 kSimpleExtensionSource)); |
730 const char* extension_names[] = { "test0", "test1", | 732 const char* extension_names[] = { "test0", "test1", |
731 "test2", "test3", "test4", | 733 "test2", "test3", "test4", |
732 "test5", "test6", "test7" }; | 734 "test5", "test6", "test7" }; |
733 i::List<JoinableThread*> threads(kNThreads); | 735 i::List<JoinableThread*> threads(kNThreads); |
734 for (int i = 0; i < kNThreads; i++) { | 736 for (int i = 0; i < kNThreads; i++) { |
735 threads.Add(new IsolateGenesisThread(8, extension_names)); | 737 threads.Add(new IsolateGenesisThread(8, extension_names)); |
736 } | 738 } |
737 StartJoinAndDeleteThreads(threads); | 739 StartJoinAndDeleteThreads(threads); |
738 } | 740 } |
OLD | NEW |