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

Side by Side Diff: src/isolate.cc

Issue 15691017: Make assertion scopes thread safe. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ASSERT(storage->next_->previous_ == storage); 329 ASSERT(storage->next_->previous_ == storage);
330 ASSERT(storage->previous_->next_ == storage); 330 ASSERT(storage->previous_->next_ == storage);
331 storage->Unlink(); 331 storage->Unlink();
332 storage->LinkTo(&free_list_); 332 storage->LinkTo(&free_list_);
333 } 333 }
334 334
335 Isolate* Isolate::default_isolate_ = NULL; 335 Isolate* Isolate::default_isolate_ = NULL;
336 Thread::LocalStorageKey Isolate::isolate_key_; 336 Thread::LocalStorageKey Isolate::isolate_key_;
337 Thread::LocalStorageKey Isolate::thread_id_key_; 337 Thread::LocalStorageKey Isolate::thread_id_key_;
338 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; 338 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
339 #ifdef DEBUG
340 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
341 #endif // DEBUG
339 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); 342 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex();
340 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; 343 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
341 Atomic32 Isolate::isolate_counter_ = 0; 344 Atomic32 Isolate::isolate_counter_ = 0;
342 345
343 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( 346 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData(
344 ThreadId thread_id) { 347 ThreadId thread_id) {
345 ASSERT(!thread_id.Equals(ThreadId::Invalid())); 348 ASSERT(!thread_id.Equals(ThreadId::Invalid()));
346 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id); 349 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id);
347 { 350 {
348 ScopedLock lock(process_wide_mutex_); 351 ScopedLock lock(process_wide_mutex_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 return per_thread; 388 return per_thread;
386 } 389 }
387 390
388 391
389 void Isolate::EnsureDefaultIsolate() { 392 void Isolate::EnsureDefaultIsolate() {
390 ScopedLock lock(process_wide_mutex_); 393 ScopedLock lock(process_wide_mutex_);
391 if (default_isolate_ == NULL) { 394 if (default_isolate_ == NULL) {
392 isolate_key_ = Thread::CreateThreadLocalKey(); 395 isolate_key_ = Thread::CreateThreadLocalKey();
393 thread_id_key_ = Thread::CreateThreadLocalKey(); 396 thread_id_key_ = Thread::CreateThreadLocalKey();
394 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); 397 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
398 #ifdef DEBUG
399 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey();
400 #endif // DEBUG
395 thread_data_table_ = new Isolate::ThreadDataTable(); 401 thread_data_table_ = new Isolate::ThreadDataTable();
396 default_isolate_ = new Isolate(); 402 default_isolate_ = new Isolate();
397 } 403 }
398 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here 404 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here
399 // because a non-null thread data may be already set. 405 // because a non-null thread data may be already set.
400 if (Thread::GetThreadLocal(isolate_key_) == NULL) { 406 if (Thread::GetThreadLocal(isolate_key_) == NULL) {
401 Thread::SetThreadLocal(isolate_key_, default_isolate_); 407 Thread::SetThreadLocal(isolate_key_, default_isolate_);
402 } 408 }
403 } 409 }
404 410
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 888
883 void Isolate::PrintStack(StringStream* accumulator) { 889 void Isolate::PrintStack(StringStream* accumulator) {
884 if (!IsInitialized()) { 890 if (!IsInitialized()) {
885 accumulator->Add( 891 accumulator->Add(
886 "\n==== JS stack trace is not available =======================\n\n"); 892 "\n==== JS stack trace is not available =======================\n\n");
887 accumulator->Add( 893 accumulator->Add(
888 "\n==== Isolate for the thread is not initialized =============\n\n"); 894 "\n==== Isolate for the thread is not initialized =============\n\n");
889 return; 895 return;
890 } 896 }
891 // The MentionedObjectCache is not GC-proof at the moment. 897 // The MentionedObjectCache is not GC-proof at the moment.
892 AssertNoAllocation nogc; 898 DisallowHeapAllocation no_gc;
893 ASSERT(StringStream::IsMentionedObjectCacheClear()); 899 ASSERT(StringStream::IsMentionedObjectCacheClear());
894 900
895 // Avoid printing anything if there are no frames. 901 // Avoid printing anything if there are no frames.
896 if (c_entry_fp(thread_local_top()) == 0) return; 902 if (c_entry_fp(thread_local_top()) == 0) return;
897 903
898 accumulator->Add( 904 accumulator->Add(
899 "\n==== JS stack trace =========================================\n\n"); 905 "\n==== JS stack trace =========================================\n\n");
900 PrintFrames(this, accumulator, StackFrame::OVERVIEW); 906 PrintFrames(this, accumulator, StackFrame::OVERVIEW);
901 907
902 accumulator->Add( 908 accumulator->Add(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 973
968 return UNKNOWN; 974 return UNKNOWN;
969 } 975 }
970 976
971 977
972 bool Isolate::MayNamedAccess(JSObject* receiver, Object* key, 978 bool Isolate::MayNamedAccess(JSObject* receiver, Object* key,
973 v8::AccessType type) { 979 v8::AccessType type) {
974 ASSERT(receiver->IsAccessCheckNeeded()); 980 ASSERT(receiver->IsAccessCheckNeeded());
975 981
976 // The callers of this method are not expecting a GC. 982 // The callers of this method are not expecting a GC.
977 AssertNoAllocation no_gc; 983 DisallowHeapAllocation no_gc;
978 984
979 // Skip checks for hidden properties access. Note, we do not 985 // Skip checks for hidden properties access. Note, we do not
980 // require existence of a context in this case. 986 // require existence of a context in this case.
981 if (key == heap_.hidden_string()) return true; 987 if (key == heap_.hidden_string()) return true;
982 988
983 // Check for compatibility between the security tokens in the 989 // Check for compatibility between the security tokens in the
984 // current lexical context and the accessed object. 990 // current lexical context and the accessed object.
985 ASSERT(context()); 991 ASSERT(context());
986 992
987 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); 993 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type);
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 simulator_initialized_ = false; 1779 simulator_initialized_ = false;
1774 simulator_i_cache_ = NULL; 1780 simulator_i_cache_ = NULL;
1775 simulator_redirection_ = NULL; 1781 simulator_redirection_ = NULL;
1776 #endif 1782 #endif
1777 1783
1778 #ifdef DEBUG 1784 #ifdef DEBUG
1779 // heap_histograms_ initializes itself. 1785 // heap_histograms_ initializes itself.
1780 memset(&js_spill_information_, 0, sizeof(js_spill_information_)); 1786 memset(&js_spill_information_, 0, sizeof(js_spill_information_));
1781 memset(code_kind_statistics_, 0, 1787 memset(code_kind_statistics_, 0,
1782 sizeof(code_kind_statistics_[0]) * Code::NUMBER_OF_KINDS); 1788 sizeof(code_kind_statistics_[0]) * Code::NUMBER_OF_KINDS);
1783
1784 compiler_thread_handle_deref_state_ = HandleDereferenceGuard::ALLOW;
1785 execution_thread_handle_deref_state_ = HandleDereferenceGuard::ALLOW;
1786 #endif 1789 #endif
1787 1790
1788 #ifdef ENABLE_DEBUGGER_SUPPORT 1791 #ifdef ENABLE_DEBUGGER_SUPPORT
1789 debug_ = NULL; 1792 debug_ = NULL;
1790 debugger_ = NULL; 1793 debugger_ = NULL;
1791 #endif 1794 #endif
1792 1795
1793 handle_scope_data_.Initialize(); 1796 handle_scope_data_.Initialize();
1794 1797
1795 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \ 1798 #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 } 2401 }
2399 if (deferred->next_ != NULL) { 2402 if (deferred->next_ != NULL) {
2400 deferred->next_->previous_ = deferred->previous_; 2403 deferred->next_->previous_ = deferred->previous_;
2401 } 2404 }
2402 if (deferred->previous_ != NULL) { 2405 if (deferred->previous_ != NULL) {
2403 deferred->previous_->next_ = deferred->next_; 2406 deferred->previous_->next_ = deferred->next_;
2404 } 2407 }
2405 } 2408 }
2406 2409
2407 2410
2408 #ifdef DEBUG
2409 HandleDereferenceGuard::State Isolate::HandleDereferenceGuardState() {
2410 if (execution_thread_handle_deref_state_ == HandleDereferenceGuard::ALLOW &&
2411 compiler_thread_handle_deref_state_ == HandleDereferenceGuard::ALLOW) {
2412 // Short-cut to avoid polling thread id.
2413 return HandleDereferenceGuard::ALLOW;
2414 }
2415 if (FLAG_parallel_recompilation &&
2416 optimizing_compiler_thread()->IsOptimizerThread()) {
2417 return compiler_thread_handle_deref_state_;
2418 } else {
2419 return execution_thread_handle_deref_state_;
2420 }
2421 }
2422
2423
2424 void Isolate::SetHandleDereferenceGuardState(
2425 HandleDereferenceGuard::State state) {
2426 if (FLAG_parallel_recompilation &&
2427 optimizing_compiler_thread()->IsOptimizerThread()) {
2428 compiler_thread_handle_deref_state_ = state;
2429 } else {
2430 execution_thread_handle_deref_state_ = state;
2431 }
2432 }
2433 #endif
2434
2435
2436 HStatistics* Isolate::GetHStatistics() { 2411 HStatistics* Isolate::GetHStatistics() {
2437 if (hstatistics() == NULL) set_hstatistics(new HStatistics()); 2412 if (hstatistics() == NULL) set_hstatistics(new HStatistics());
2438 return hstatistics(); 2413 return hstatistics();
2439 } 2414 }
2440 2415
2441 2416
2442 HTracer* Isolate::GetHTracer() { 2417 HTracer* Isolate::GetHTracer() {
2443 if (htracer() == NULL) set_htracer(new HTracer(id())); 2418 if (htracer() == NULL) set_htracer(new HTracer(id()));
2444 return htracer(); 2419 return htracer();
2445 } 2420 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 2466
2492 #ifdef DEBUG 2467 #ifdef DEBUG
2493 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2468 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2494 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2469 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2495 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2470 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2496 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2471 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2497 #undef ISOLATE_FIELD_OFFSET 2472 #undef ISOLATE_FIELD_OFFSET
2498 #endif 2473 #endif
2499 2474
2500 } } // namespace v8::internal 2475 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/isolate.h ('k') | src/json-parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698