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

Side by Side Diff: third_party/WebKit/Source/platform/heap/ThreadState.h

Issue 2913303002: Avoid unsafe heap access from audio thread. (Closed)
Patch Set: Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 explicit GCForbiddenScope(ThreadState* thread_state) 313 explicit GCForbiddenScope(ThreadState* thread_state)
314 : thread_state_(thread_state) { 314 : thread_state_(thread_state) {
315 thread_state_->EnterGCForbiddenScope(); 315 thread_state_->EnterGCForbiddenScope();
316 } 316 }
317 ~GCForbiddenScope() { thread_state_->LeaveGCForbiddenScope(); } 317 ~GCForbiddenScope() { thread_state_->LeaveGCForbiddenScope(); }
318 318
319 private: 319 private:
320 ThreadState* const thread_state_; 320 ThreadState* const thread_state_;
321 }; 321 };
322 322
323 // Per-thread lock that's held while a GC runs; can be
324 // used by non-attached threads to safely coordinate access
325 // to the heap while it is in a non-GCing state.
hongchan 2017/06/01 16:08:55 From what I understand, this should not be abused
326 class GCLockScope final {
327 STACK_ALLOCATED();
328
329 public:
330 explicit GCLockScope(ThreadState* thread_state)
331 : thread_state_(thread_state) {
332 thread_state_->active_gc_mutex_.lock();
333 }
334 ~GCLockScope() { thread_state_->active_gc_mutex_.unlock(); }
335
336 private:
337 ThreadState* const thread_state_;
338 };
339
323 void FlushHeapDoesNotContainCacheIfNeeded(); 340 void FlushHeapDoesNotContainCacheIfNeeded();
324 341
325 // Safepoint related functionality. 342 // Safepoint related functionality.
326 // 343 //
327 // When a thread attempts to perform GC it needs to stop all other threads 344 // When a thread attempts to perform GC it needs to stop all other threads
328 // that use the heap or at least guarantee that they will not touch any 345 // that use the heap or at least guarantee that they will not touch any
329 // heap allocated object until GC is complete. 346 // heap allocated object until GC is complete.
330 // 347 //
331 // We say that a thread is at a safepoint if this thread is guaranteed to 348 // We say that a thread is at a safepoint if this thread is guaranteed to
332 // not touch any heap allocated object or any heap related functionality until 349 // not touch any heap allocated object or any heap related functionality until
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 void InvokePreFinalizers(); 639 void InvokePreFinalizers();
623 640
624 void TakeSnapshot(SnapshotType); 641 void TakeSnapshot(SnapshotType);
625 void ClearArenaAges(); 642 void ClearArenaAges();
626 int ArenaIndexOfVectorArenaLeastRecentlyExpanded(int begin_arena_index, 643 int ArenaIndexOfVectorArenaLeastRecentlyExpanded(int begin_arena_index,
627 int end_arena_index); 644 int end_arena_index);
628 645
629 void ReportMemoryToV8(); 646 void ReportMemoryToV8();
630 647
631 friend class SafePointScope; 648 friend class SafePointScope;
649 friend class GCLockScope;
632 650
633 static WTF::ThreadSpecific<ThreadState*>* thread_specific_; 651 static WTF::ThreadSpecific<ThreadState*>* thread_specific_;
634 652
635 // We can't create a static member of type ThreadState here 653 // We can't create a static member of type ThreadState here
636 // because it will introduce global constructor and destructor. 654 // because it will introduce global constructor and destructor.
637 // We would like to manage lifetime of the ThreadState attached 655 // We would like to manage lifetime of the ThreadState attached
638 // to the main thread explicitly instead and still use normal 656 // to the main thread explicitly instead and still use normal
639 // constructor and destructor for the ThreadState class. 657 // constructor and destructor for the ThreadState class.
640 // For this we reserve static storage for the main ThreadState 658 // For this we reserve static storage for the main ThreadState
641 // and lazily construct ThreadState in it using placement new. 659 // and lazily construct ThreadState in it using placement new.
642 static uint8_t main_thread_state_storage_[]; 660 static uint8_t main_thread_state_storage_[];
643 661
644 std::unique_ptr<ThreadHeap> heap_; 662 std::unique_ptr<ThreadHeap> heap_;
645 ThreadIdentifier thread_; 663 ThreadIdentifier thread_;
646 std::unique_ptr<PersistentRegion> persistent_region_; 664 std::unique_ptr<PersistentRegion> persistent_region_;
647 BlinkGC::StackState stack_state_; 665 BlinkGC::StackState stack_state_;
648 intptr_t* start_of_stack_; 666 intptr_t* start_of_stack_;
649 intptr_t* end_of_stack_; 667 intptr_t* end_of_stack_;
650 668
651 void* safe_point_scope_marker_; 669 void* safe_point_scope_marker_;
652 Vector<Address> safe_point_stack_copy_; 670 Vector<Address> safe_point_stack_copy_;
653 bool sweep_forbidden_; 671 bool sweep_forbidden_;
654 size_t no_allocation_count_; 672 size_t no_allocation_count_;
655 size_t gc_forbidden_count_; 673 size_t gc_forbidden_count_;
656 size_t mixins_being_constructed_count_; 674 size_t mixins_being_constructed_count_;
657 double accumulated_sweeping_time_; 675 double accumulated_sweeping_time_;
658 bool object_resurrection_forbidden_; 676 bool object_resurrection_forbidden_;
677 Mutex active_gc_mutex_;
659 678
660 BaseArena* arenas_[BlinkGC::kNumberOfArenas]; 679 BaseArena* arenas_[BlinkGC::kNumberOfArenas];
661 int vector_backing_arena_index_; 680 int vector_backing_arena_index_;
662 size_t arena_ages_[BlinkGC::kNumberOfArenas]; 681 size_t arena_ages_[BlinkGC::kNumberOfArenas];
663 size_t current_arena_ages_; 682 size_t current_arena_ages_;
664 683
665 GarbageCollectedMixinConstructorMarker* gc_mixin_marker_; 684 GarbageCollectedMixinConstructorMarker* gc_mixin_marker_;
666 685
667 bool should_flush_heap_does_not_contain_cache_; 686 bool should_flush_heap_does_not_contain_cache_;
668 GCState gc_state_; 687 GCState gc_state_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 class ThreadStateFor<kAnyThread> { 748 class ThreadStateFor<kAnyThread> {
730 STATIC_ONLY(ThreadStateFor); 749 STATIC_ONLY(ThreadStateFor);
731 750
732 public: 751 public:
733 static ThreadState* GetState() { return ThreadState::Current(); } 752 static ThreadState* GetState() { return ThreadState::Current(); }
734 }; 753 };
735 754
736 } // namespace blink 755 } // namespace blink
737 756
738 #endif // ThreadState_h 757 #endif // ThreadState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698