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

Side by Side Diff: src/d8.cc

Issue 1240553003: d8: Leak context_mutex_ so it will never be destroyed while locked (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « src/d8.h ('k') | no next file » | 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 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 #endif 195 #endif
196 return Shell::ReadFromStdin(isolate_); 196 return Shell::ReadFromStdin(isolate_);
197 } 197 }
198 198
199 199
200 #ifndef V8_SHARED 200 #ifndef V8_SHARED
201 CounterMap* Shell::counter_map_; 201 CounterMap* Shell::counter_map_;
202 base::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 202 base::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
203 CounterCollection Shell::local_counters_; 203 CounterCollection Shell::local_counters_;
204 CounterCollection* Shell::counters_ = &local_counters_; 204 CounterCollection* Shell::counters_ = &local_counters_;
205 base::Mutex Shell::context_mutex_; 205 base::LazyMutex Shell::context_mutex_;
206 const base::TimeTicks Shell::kInitialTicks = 206 const base::TimeTicks Shell::kInitialTicks =
207 base::TimeTicks::HighResolutionNow(); 207 base::TimeTicks::HighResolutionNow();
208 Persistent<Context> Shell::utility_context_; 208 Persistent<Context> Shell::utility_context_;
209 base::Mutex Shell::workers_mutex_; 209 base::LazyMutex Shell::workers_mutex_;
210 bool Shell::allow_new_workers_ = true; 210 bool Shell::allow_new_workers_ = true;
211 i::List<Worker*> Shell::workers_; 211 i::List<Worker*> Shell::workers_;
212 i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_; 212 i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_;
213 #endif // !V8_SHARED 213 #endif // !V8_SHARED
214 214
215 Persistent<Context> Shell::evaluation_context_; 215 Persistent<Context> Shell::evaluation_context_;
216 ArrayBuffer::Allocator* Shell::array_buffer_allocator; 216 ArrayBuffer::Allocator* Shell::array_buffer_allocator;
217 ShellOptions Shell::options; 217 ShellOptions Shell::options;
218 const char* Shell::kPrompt = "d8> "; 218 const char* Shell::kPrompt = "d8> ";
219 base::OnceType Shell::quit_once_ = V8_ONCE_INIT; 219 base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 #ifndef V8_SHARED 692 #ifndef V8_SHARED
693 void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) { 693 void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
694 Isolate* isolate = args.GetIsolate(); 694 Isolate* isolate = args.GetIsolate();
695 HandleScope handle_scope(isolate); 695 HandleScope handle_scope(isolate);
696 if (args.Length() < 1 || !args[0]->IsString()) { 696 if (args.Length() < 1 || !args[0]->IsString()) {
697 Throw(args.GetIsolate(), "1st argument must be string"); 697 Throw(args.GetIsolate(), "1st argument must be string");
698 return; 698 return;
699 } 699 }
700 700
701 { 701 {
702 base::LockGuard<base::Mutex> lock_guard(&workers_mutex_); 702 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
703 if (!allow_new_workers_) return; 703 if (!allow_new_workers_) return;
704 704
705 Worker* worker = new Worker; 705 Worker* worker = new Worker;
706 args.This()->SetInternalField(0, External::New(isolate, worker)); 706 args.This()->SetInternalField(0, External::New(isolate, worker));
707 workers_.Add(worker); 707 workers_.Add(worker);
708 708
709 String::Utf8Value script(args[0]); 709 String::Utf8Value script(args[0]);
710 if (!*script) { 710 if (!*script) {
711 Throw(args.GetIsolate(), "Can't get worker script"); 711 Throw(args.GetIsolate(), "Can't get worker script");
712 return; 712 return;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 printf("Failed to initialize debugger\n"); 1196 printf("Failed to initialize debugger\n");
1197 Shell::Exit(1); 1197 Shell::Exit(1);
1198 } 1198 }
1199 #endif // !V8_SHARED 1199 #endif // !V8_SHARED
1200 } 1200 }
1201 1201
1202 1202
1203 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { 1203 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
1204 #ifndef V8_SHARED 1204 #ifndef V8_SHARED
1205 // This needs to be a critical section since this is not thread-safe 1205 // This needs to be a critical section since this is not thread-safe
1206 base::LockGuard<base::Mutex> lock_guard(&context_mutex_); 1206 base::LockGuard<base::Mutex> lock_guard(context_mutex_.Pointer());
1207 #endif // !V8_SHARED 1207 #endif // !V8_SHARED
1208 // Initialize the global objects 1208 // Initialize the global objects
1209 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); 1209 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
1210 EscapableHandleScope handle_scope(isolate); 1210 EscapableHandleScope handle_scope(isolate);
1211 Local<Context> context = Context::New(isolate, NULL, global_template); 1211 Local<Context> context = Context::New(isolate, NULL, global_template);
1212 DCHECK(!context.IsEmpty()); 1212 DCHECK(!context.IsEmpty());
1213 Context::Scope scope(context); 1213 Context::Scope scope(context);
1214 1214
1215 #ifndef V8_SHARED 1215 #ifndef V8_SHARED
1216 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); 1216 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory();
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 return scope.Escape(result); 2245 return scope.Escape(result);
2246 } 2246 }
2247 2247
2248 2248
2249 void Shell::CleanupWorkers() { 2249 void Shell::CleanupWorkers() {
2250 // Make a copy of workers_, because we don't want to call Worker::Terminate 2250 // Make a copy of workers_, because we don't want to call Worker::Terminate
2251 // while holding the workers_mutex_ lock. Otherwise, if a worker is about to 2251 // while holding the workers_mutex_ lock. Otherwise, if a worker is about to
2252 // create a new Worker, it would deadlock. 2252 // create a new Worker, it would deadlock.
2253 i::List<Worker*> workers_copy; 2253 i::List<Worker*> workers_copy;
2254 { 2254 {
2255 base::LockGuard<base::Mutex> lock_guard(&workers_mutex_); 2255 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
2256 allow_new_workers_ = false; 2256 allow_new_workers_ = false;
2257 workers_copy.AddAll(workers_); 2257 workers_copy.AddAll(workers_);
2258 workers_.Clear(); 2258 workers_.Clear();
2259 } 2259 }
2260 2260
2261 for (int i = 0; i < workers_copy.length(); ++i) { 2261 for (int i = 0; i < workers_copy.length(); ++i) {
2262 Worker* worker = workers_copy[i]; 2262 Worker* worker = workers_copy[i];
2263 worker->WaitForThread(); 2263 worker->WaitForThread();
2264 delete worker; 2264 delete worker;
2265 } 2265 }
2266 2266
2267 // Now that all workers are terminated, we can re-enable Worker creation. 2267 // Now that all workers are terminated, we can re-enable Worker creation.
2268 { 2268 {
2269 base::LockGuard<base::Mutex> lock_guard(&workers_mutex_); 2269 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
2270 allow_new_workers_ = true; 2270 allow_new_workers_ = true;
2271 } 2271 }
2272 2272
2273 for (int i = 0; i < externalized_shared_contents_.length(); ++i) { 2273 for (int i = 0; i < externalized_shared_contents_.length(); ++i) {
2274 const SharedArrayBuffer::Contents& contents = 2274 const SharedArrayBuffer::Contents& contents =
2275 externalized_shared_contents_[i]; 2275 externalized_shared_contents_[i];
2276 Shell::array_buffer_allocator->Free(contents.Data(), contents.ByteLength()); 2276 Shell::array_buffer_allocator->Free(contents.Data(), contents.ByteLength());
2277 } 2277 }
2278 externalized_shared_contents_.Clear(); 2278 externalized_shared_contents_.Clear();
2279 } 2279 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 } 2470 }
2471 2471
2472 } // namespace v8 2472 } // namespace v8
2473 2473
2474 2474
2475 #ifndef GOOGLE3 2475 #ifndef GOOGLE3
2476 int main(int argc, char* argv[]) { 2476 int main(int argc, char* argv[]) {
2477 return v8::Shell::Main(argc, argv); 2477 return v8::Shell::Main(argc, argv);
2478 } 2478 }
2479 #endif 2479 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698