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/isolate.cc

Issue 21087012: Simplify implementation of Mutex. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix unit test. Created 7 years, 4 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.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 // 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 Mutex 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 ScopedLock lock(&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 ScopedLock lock(&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 }
372 per_thread = AllocatePerIsolateThreadData(thread_id); 372 if (per_thread == NULL) {
373 } 373 per_thread = AllocatePerIsolateThreadData(thread_id);
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 ScopedLock lock(&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 ScopedLock lock(&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 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 stack_trace_nesting_level_(0), 1742 stack_trace_nesting_level_(0),
1743 incomplete_message_(NULL), 1743 incomplete_message_(NULL),
1744 preallocated_memory_thread_(NULL), 1744 preallocated_memory_thread_(NULL),
1745 preallocated_message_space_(NULL), 1745 preallocated_message_space_(NULL),
1746 bootstrapper_(NULL), 1746 bootstrapper_(NULL),
1747 runtime_profiler_(NULL), 1747 runtime_profiler_(NULL),
1748 compilation_cache_(NULL), 1748 compilation_cache_(NULL),
1749 counters_(NULL), 1749 counters_(NULL),
1750 code_range_(NULL), 1750 code_range_(NULL),
1751 // Must be initialized early to allow v8::SetResourceConstraints calls. 1751 // Must be initialized early to allow v8::SetResourceConstraints calls.
1752 break_access_(OS::CreateMutex()),
1753 debugger_initialized_(false), 1752 debugger_initialized_(false),
1754 // Must be initialized early to allow v8::Debug calls. 1753 // Must be initialized early to allow v8::Debug calls.
1755 debugger_access_(OS::CreateMutex()),
1756 logger_(NULL), 1754 logger_(NULL),
1757 stats_table_(NULL), 1755 stats_table_(NULL),
1758 stub_cache_(NULL), 1756 stub_cache_(NULL),
1759 deoptimizer_data_(NULL), 1757 deoptimizer_data_(NULL),
1760 capture_stack_trace_for_uncaught_exceptions_(false), 1758 capture_stack_trace_for_uncaught_exceptions_(false),
1761 stack_trace_for_uncaught_exceptions_frame_limit_(0), 1759 stack_trace_for_uncaught_exceptions_frame_limit_(0),
1762 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), 1760 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview),
1763 transcendental_cache_(NULL), 1761 transcendental_cache_(NULL),
1764 memory_allocator_(NULL), 1762 memory_allocator_(NULL),
1765 keyed_lookup_cache_(NULL), 1763 keyed_lookup_cache_(NULL),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 // Temporarily set this isolate as current so that various parts of 1844 // Temporarily set this isolate as current so that various parts of
1847 // the isolate can access it in their destructors without having a 1845 // the isolate can access it in their destructors without having a
1848 // direct pointer. We don't use Enter/Exit here to avoid 1846 // direct pointer. We don't use Enter/Exit here to avoid
1849 // initializing the thread data. 1847 // initializing the thread data.
1850 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1848 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1851 Isolate* saved_isolate = UncheckedCurrent(); 1849 Isolate* saved_isolate = UncheckedCurrent();
1852 SetIsolateThreadLocals(this, NULL); 1850 SetIsolateThreadLocals(this, NULL);
1853 1851
1854 Deinit(); 1852 Deinit();
1855 1853
1856 { ScopedLock lock(process_wide_mutex_); 1854 { ScopedLock lock(&process_wide_mutex_);
1857 thread_data_table_->RemoveAllThreads(this); 1855 thread_data_table_->RemoveAllThreads(this);
1858 } 1856 }
1859 1857
1860 if (serialize_partial_snapshot_cache_ != NULL) { 1858 if (serialize_partial_snapshot_cache_ != NULL) {
1861 delete[] serialize_partial_snapshot_cache_; 1859 delete[] serialize_partial_snapshot_cache_;
1862 serialize_partial_snapshot_cache_ = NULL; 1860 serialize_partial_snapshot_cache_ = NULL;
1863 } 1861 }
1864 1862
1865 if (!IsDefaultIsolate()) { 1863 if (!IsDefaultIsolate()) {
1866 delete this; 1864 delete this;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 stats_table_ = NULL; 2015 stats_table_ = NULL;
2018 2016
2019 delete logger_; 2017 delete logger_;
2020 logger_ = NULL; 2018 logger_ = NULL;
2021 2019
2022 delete counters_; 2020 delete counters_;
2023 counters_ = NULL; 2021 counters_ = NULL;
2024 2022
2025 delete handle_scope_implementer_; 2023 delete handle_scope_implementer_;
2026 handle_scope_implementer_ = NULL; 2024 handle_scope_implementer_ = NULL;
2027 delete break_access_;
2028 break_access_ = NULL;
2029 delete debugger_access_;
2030 debugger_access_ = NULL;
2031 2025
2032 delete compilation_cache_; 2026 delete compilation_cache_;
2033 compilation_cache_ = NULL; 2027 compilation_cache_ = NULL;
2034 delete bootstrapper_; 2028 delete bootstrapper_;
2035 bootstrapper_ = NULL; 2029 bootstrapper_ = NULL;
2036 delete inner_pointer_to_code_cache_; 2030 delete inner_pointer_to_code_cache_;
2037 inner_pointer_to_code_cache_ = NULL; 2031 inner_pointer_to_code_cache_ = NULL;
2038 delete write_iterator_; 2032 delete write_iterator_;
2039 write_iterator_ = NULL; 2033 write_iterator_ = NULL;
2040 2034
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 logger_ = new Logger(this); 2114 logger_ = new Logger(this);
2121 } 2115 }
2122 if (counters_ == NULL) { 2116 if (counters_ == NULL) {
2123 counters_ = new Counters(this); 2117 counters_ = new Counters(this);
2124 } 2118 }
2125 } 2119 }
2126 2120
2127 2121
2128 void Isolate::InitializeDebugger() { 2122 void Isolate::InitializeDebugger() {
2129 #ifdef ENABLE_DEBUGGER_SUPPORT 2123 #ifdef ENABLE_DEBUGGER_SUPPORT
2130 ScopedLock lock(debugger_access_); 2124 ScopedLock lock(&debugger_access_);
2131 if (NoBarrier_Load(&debugger_initialized_)) return; 2125 if (NoBarrier_Load(&debugger_initialized_)) return;
2132 InitializeLoggingAndCounters(); 2126 InitializeLoggingAndCounters();
2133 debug_ = new Debug(this); 2127 debug_ = new Debug(this);
2134 debugger_ = new Debugger(this); 2128 debugger_ = new Debugger(this);
2135 Release_Store(&debugger_initialized_, true); 2129 Release_Store(&debugger_initialized_, true);
2136 #endif 2130 #endif
2137 } 2131 }
2138 2132
2139 2133
2140 bool Isolate::Init(Deserializer* des) { 2134 bool Isolate::Init(Deserializer* des) {
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 2516
2523 #ifdef DEBUG 2517 #ifdef DEBUG
2524 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2518 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2525 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2519 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2526 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2520 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2527 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2521 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2528 #undef ISOLATE_FIELD_OFFSET 2522 #undef ISOLATE_FIELD_OFFSET
2529 #endif 2523 #endif
2530 2524
2531 } } // namespace v8::internal 2525 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/log-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698