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

Side by Side Diff: src/v8threads.cc

Issue 637263002: Fix data races and leaks related to v8::Lockers (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | « src/isolate.h ('k') | test/cctest/test-lockers.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/debug.h" 9 #include "src/debug.h"
10 #include "src/execution.h" 10 #include "src/execution.h"
11 #include "src/regexp-stack.h" 11 #include "src/regexp-stack.h"
12 #include "src/v8threads.h" 12 #include "src/v8threads.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 15
16 16
17 namespace {
18
17 // Track whether this V8 instance has ever called v8::Locker. This allows the 19 // Track whether this V8 instance has ever called v8::Locker. This allows the
18 // API code to verify that the lock is always held when V8 is being entered. 20 // API code to verify that the lock is always held when V8 is being entered.
19 bool Locker::active_ = false; 21 base::Atomic32 g_locker_was_ever_used_ = 0;
22
23 } // namespace
20 24
21 25
22 // Once the Locker is initialized, the current thread will be guaranteed to have 26 // Once the Locker is initialized, the current thread will be guaranteed to have
23 // the lock for a given isolate. 27 // the lock for a given isolate.
24 void Locker::Initialize(v8::Isolate* isolate) { 28 void Locker::Initialize(v8::Isolate* isolate) {
25 DCHECK(isolate != NULL); 29 DCHECK(isolate != NULL);
26 has_lock_= false; 30 has_lock_= false;
27 top_level_ = true; 31 top_level_ = true;
28 isolate_ = reinterpret_cast<i::Isolate*>(isolate); 32 isolate_ = reinterpret_cast<i::Isolate*>(isolate);
29 // Record that the Locker has been used at least once. 33 // Record that the Locker has been used at least once.
30 active_ = true; 34 base::NoBarrier_Store(&g_locker_was_ever_used_, 1);
31 // Get the big lock if necessary. 35 // Get the big lock if necessary.
32 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) { 36 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) {
33 isolate_->thread_manager()->Lock(); 37 isolate_->thread_manager()->Lock();
34 has_lock_ = true; 38 has_lock_ = true;
35 39
36 // Make sure that V8 is initialized. Archiving of threads interferes 40 // Make sure that V8 is initialized. Archiving of threads interferes
37 // with deserialization by adding additional root pointers, so we must 41 // with deserialization by adding additional root pointers, so we must
38 // initialize here, before anyone can call ~Locker() or Unlocker(). 42 // initialize here, before anyone can call ~Locker() or Unlocker().
39 if (!isolate_->IsInitialized()) { 43 if (!isolate_->IsInitialized()) {
40 isolate_->Enter(); 44 isolate_->Enter();
(...skipping 16 matching lines...) Expand all
57 61
58 62
59 bool Locker::IsLocked(v8::Isolate* isolate) { 63 bool Locker::IsLocked(v8::Isolate* isolate) {
60 DCHECK(isolate != NULL); 64 DCHECK(isolate != NULL);
61 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 65 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
62 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); 66 return internal_isolate->thread_manager()->IsLockedByCurrentThread();
63 } 67 }
64 68
65 69
66 bool Locker::IsActive() { 70 bool Locker::IsActive() {
67 return active_; 71 return !!base::NoBarrier_Load(&g_locker_was_ever_used_);
68 } 72 }
69 73
70 74
71 Locker::~Locker() { 75 Locker::~Locker() {
72 DCHECK(isolate_->thread_manager()->IsLockedByCurrentThread()); 76 DCHECK(isolate_->thread_manager()->IsLockedByCurrentThread());
73 if (has_lock_) { 77 if (has_lock_) {
74 if (top_level_) { 78 if (top_level_) {
75 isolate_->thread_manager()->FreeThreadResources(); 79 isolate_->thread_manager()->FreeThreadResources();
76 } else { 80 } else {
77 isolate_->thread_manager()->ArchiveThread(); 81 isolate_->thread_manager()->ArchiveThread();
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 state = state->Next()) { 365 state = state->Next()) {
362 if (thread_id.Equals(state->id())) { 366 if (thread_id.Equals(state->id())) {
363 state->set_terminate_on_restore(true); 367 state->set_terminate_on_restore(true);
364 } 368 }
365 } 369 }
366 } 370 }
367 371
368 372
369 } // namespace internal 373 } // namespace internal
370 } // namespace v8 374 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698