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

Side by Side Diff: src/isolate.cc

Issue 23625003: Cleanup Mutex and related classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 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') | src/log-utils.h » ('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 // 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 storage->LinkTo(&free_list_); 336 storage->LinkTo(&free_list_);
337 } 337 }
338 338
339 Isolate* Isolate::default_isolate_ = NULL; 339 Isolate* Isolate::default_isolate_ = NULL;
340 Thread::LocalStorageKey Isolate::isolate_key_; 340 Thread::LocalStorageKey Isolate::isolate_key_;
341 Thread::LocalStorageKey Isolate::thread_id_key_; 341 Thread::LocalStorageKey Isolate::thread_id_key_;
342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; 342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
343 #ifdef DEBUG 343 #ifdef DEBUG
344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; 344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
345 #endif // DEBUG 345 #endif // DEBUG
346 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); 346 RecursiveMutex Isolate::process_wide_mutex_;
347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; 347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
348 Atomic32 Isolate::isolate_counter_ = 0; 348 Atomic32 Isolate::isolate_counter_ = 0;
349 349
350 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( 350 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
351 ThreadId thread_id) { 351 ThreadId thread_id) {
352 ASSERT(!thread_id.Equals(ThreadId::Invalid())); 352 ASSERT(!thread_id.Equals(ThreadId::Invalid()));
353 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id); 353 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id);
354 { 354 {
355 ScopedLock lock(process_wide_mutex_); 355 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
356 ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL); 356 ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL);
357 thread_data_table_->Insert(per_thread); 357 thread_data_table_->Insert(per_thread);
358 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); 358 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
359 } 359 }
360 return per_thread; 360 return per_thread;
361 } 361 }
362 362
363 363
364 Isolate::PerIsolateThreadData* 364 Isolate::PerIsolateThreadData*
365 Isolate::FindOrAllocatePerThreadDataForThisThread() { 365 Isolate::FindOrAllocatePerThreadDataForThisThread() {
366 ThreadId thread_id = ThreadId::Current(); 366 ThreadId thread_id = ThreadId::Current();
367 PerIsolateThreadData* per_thread = NULL; 367 PerIsolateThreadData* per_thread = NULL;
368 { 368 {
369 ScopedLock lock(process_wide_mutex_); 369 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
370 per_thread = thread_data_table_->Lookup(this, thread_id); 370 per_thread = thread_data_table_->Lookup(this, thread_id);
371 if (per_thread == NULL) { 371 if (per_thread == NULL) {
372 per_thread = AllocatePerIsolateThreadData(thread_id); 372 per_thread = AllocatePerIsolateThreadData(thread_id);
373 } 373 }
374 } 374 }
375 return per_thread; 375 return per_thread;
376 } 376 }
377 377
378 378
379 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { 379 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
380 ThreadId thread_id = ThreadId::Current(); 380 ThreadId thread_id = ThreadId::Current();
381 return FindPerThreadDataForThread(thread_id); 381 return FindPerThreadDataForThread(thread_id);
382 } 382 }
383 383
384 384
385 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( 385 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
386 ThreadId thread_id) { 386 ThreadId thread_id) {
387 PerIsolateThreadData* per_thread = NULL; 387 PerIsolateThreadData* per_thread = NULL;
388 { 388 {
389 ScopedLock lock(process_wide_mutex_); 389 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
390 per_thread = thread_data_table_->Lookup(this, thread_id); 390 per_thread = thread_data_table_->Lookup(this, thread_id);
391 } 391 }
392 return per_thread; 392 return per_thread;
393 } 393 }
394 394
395 395
396 void Isolate::EnsureDefaultIsolate() { 396 void Isolate::EnsureDefaultIsolate() {
397 ScopedLock lock(process_wide_mutex_); 397 LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
398 if (default_isolate_ == NULL) { 398 if (default_isolate_ == NULL) {
399 isolate_key_ = Thread::CreateThreadLocalKey(); 399 isolate_key_ = Thread::CreateThreadLocalKey();
400 thread_id_key_ = Thread::CreateThreadLocalKey(); 400 thread_id_key_ = Thread::CreateThreadLocalKey();
401 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); 401 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
402 #ifdef DEBUG 402 #ifdef DEBUG
403 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); 403 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey();
404 #endif // DEBUG 404 #endif // DEBUG
405 thread_data_table_ = new Isolate::ThreadDataTable(); 405 thread_data_table_ = new Isolate::ThreadDataTable();
406 default_isolate_ = new Isolate(); 406 default_isolate_ = new Isolate();
407 } 407 }
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 entry_stack_(NULL), 1743 entry_stack_(NULL),
1744 stack_trace_nesting_level_(0), 1744 stack_trace_nesting_level_(0),
1745 incomplete_message_(NULL), 1745 incomplete_message_(NULL),
1746 preallocated_memory_thread_(NULL), 1746 preallocated_memory_thread_(NULL),
1747 preallocated_message_space_(NULL), 1747 preallocated_message_space_(NULL),
1748 bootstrapper_(NULL), 1748 bootstrapper_(NULL),
1749 runtime_profiler_(NULL), 1749 runtime_profiler_(NULL),
1750 compilation_cache_(NULL), 1750 compilation_cache_(NULL),
1751 counters_(NULL), 1751 counters_(NULL),
1752 code_range_(NULL), 1752 code_range_(NULL),
1753 // Must be initialized early to allow v8::SetResourceConstraints calls.
1754 break_access_(OS::CreateMutex()),
1755 debugger_initialized_(false), 1753 debugger_initialized_(false),
1756 // Must be initialized early to allow v8::Debug calls.
1757 debugger_access_(OS::CreateMutex()),
1758 logger_(NULL), 1754 logger_(NULL),
1759 stats_table_(NULL), 1755 stats_table_(NULL),
1760 stub_cache_(NULL), 1756 stub_cache_(NULL),
1761 deoptimizer_data_(NULL), 1757 deoptimizer_data_(NULL),
1762 capture_stack_trace_for_uncaught_exceptions_(false), 1758 capture_stack_trace_for_uncaught_exceptions_(false),
1763 stack_trace_for_uncaught_exceptions_frame_limit_(0), 1759 stack_trace_for_uncaught_exceptions_frame_limit_(0),
1764 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), 1760 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
1765 transcendental_cache_(NULL), 1761 transcendental_cache_(NULL),
1766 memory_allocator_(NULL), 1762 memory_allocator_(NULL),
1767 keyed_lookup_cache_(NULL), 1763 keyed_lookup_cache_(NULL),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 // Temporarily set this isolate as current so that various parts of 1843 // Temporarily set this isolate as current so that various parts of
1848 // the isolate can access it in their destructors without having a 1844 // the isolate can access it in their destructors without having a
1849 // direct pointer. We don't use Enter/Exit here to avoid 1845 // direct pointer. We don't use Enter/Exit here to avoid
1850 // initializing the thread data. 1846 // initializing the thread data.
1851 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1847 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1852 Isolate* saved_isolate = UncheckedCurrent(); 1848 Isolate* saved_isolate = UncheckedCurrent();
1853 SetIsolateThreadLocals(this, NULL); 1849 SetIsolateThreadLocals(this, NULL);
1854 1850
1855 Deinit(); 1851 Deinit();
1856 1852
1857 { ScopedLock lock(process_wide_mutex_); 1853 { LockGuard<RecursiveMutex> lock_guard(&process_wide_mutex_);
1858 thread_data_table_->RemoveAllThreads(this); 1854 thread_data_table_->RemoveAllThreads(this);
1859 } 1855 }
1860 1856
1861 if (serialize_partial_snapshot_cache_ != NULL) { 1857 if (serialize_partial_snapshot_cache_ != NULL) {
1862 delete[] serialize_partial_snapshot_cache_; 1858 delete[] serialize_partial_snapshot_cache_;
1863 serialize_partial_snapshot_cache_ = NULL; 1859 serialize_partial_snapshot_cache_ = NULL;
1864 } 1860 }
1865 1861
1866 if (!IsDefaultIsolate()) { 1862 if (!IsDefaultIsolate()) {
1867 delete this; 1863 delete this;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 stats_table_ = NULL; 2014 stats_table_ = NULL;
2019 2015
2020 delete logger_; 2016 delete logger_;
2021 logger_ = NULL; 2017 logger_ = NULL;
2022 2018
2023 delete counters_; 2019 delete counters_;
2024 counters_ = NULL; 2020 counters_ = NULL;
2025 2021
2026 delete handle_scope_implementer_; 2022 delete handle_scope_implementer_;
2027 handle_scope_implementer_ = NULL; 2023 handle_scope_implementer_ = NULL;
2028 delete break_access_;
2029 break_access_ = NULL;
2030 delete debugger_access_;
2031 debugger_access_ = NULL;
2032 2024
2033 delete compilation_cache_; 2025 delete compilation_cache_;
2034 compilation_cache_ = NULL; 2026 compilation_cache_ = NULL;
2035 delete bootstrapper_; 2027 delete bootstrapper_;
2036 bootstrapper_ = NULL; 2028 bootstrapper_ = NULL;
2037 delete inner_pointer_to_code_cache_; 2029 delete inner_pointer_to_code_cache_;
2038 inner_pointer_to_code_cache_ = NULL; 2030 inner_pointer_to_code_cache_ = NULL;
2039 delete write_iterator_; 2031 delete write_iterator_;
2040 write_iterator_ = NULL; 2032 write_iterator_ = NULL;
2041 2033
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 logger_ = new Logger(this); 2112 logger_ = new Logger(this);
2121 } 2113 }
2122 if (counters_ == NULL) { 2114 if (counters_ == NULL) {
2123 counters_ = new Counters(this); 2115 counters_ = new Counters(this);
2124 } 2116 }
2125 } 2117 }
2126 2118
2127 2119
2128 void Isolate::InitializeDebugger() { 2120 void Isolate::InitializeDebugger() {
2129 #ifdef ENABLE_DEBUGGER_SUPPORT 2121 #ifdef ENABLE_DEBUGGER_SUPPORT
2130 ScopedLock lock(debugger_access_); 2122 LockGuard<RecursiveMutex> lock_guard(debugger_access());
2131 if (NoBarrier_Load(&debugger_initialized_)) return; 2123 if (NoBarrier_Load(&debugger_initialized_)) return;
2132 InitializeLoggingAndCounters(); 2124 InitializeLoggingAndCounters();
2133 debug_ = new Debug(this); 2125 debug_ = new Debug(this);
2134 debugger_ = new Debugger(this); 2126 debugger_ = new Debugger(this);
2135 Release_Store(&debugger_initialized_, true); 2127 Release_Store(&debugger_initialized_, true);
2136 #endif 2128 #endif
2137 } 2129 }
2138 2130
2139 2131
2140 bool Isolate::Init(Deserializer* des) { 2132 bool Isolate::Init(Deserializer* des) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 2516
2525 #ifdef DEBUG 2517 #ifdef DEBUG
2526 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2518 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2527 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2519 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2528 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2520 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2529 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2521 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2530 #undef ISOLATE_FIELD_OFFSET 2522 #undef ISOLATE_FIELD_OFFSET
2531 #endif 2523 #endif
2532 2524
2533 } } // namespace v8::internal 2525 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/log-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698