| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_SAFEPOINT_H_ | 5 #ifndef VM_SAFEPOINT_H_ |
| 6 #define VM_SAFEPOINT_H_ | 6 #define VM_SAFEPOINT_H_ |
| 7 | 7 |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
| 10 #include "vm/thread.h" | 10 #include "vm/thread.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Implements handling of safepoint operations for all threads in an Isolate. | 27 // Implements handling of safepoint operations for all threads in an Isolate. |
| 28 class SafepointHandler { | 28 class SafepointHandler { |
| 29 public: | 29 public: |
| 30 explicit SafepointHandler(Isolate* I); | 30 explicit SafepointHandler(Isolate* I); |
| 31 ~SafepointHandler(); | 31 ~SafepointHandler(); |
| 32 | 32 |
| 33 void EnterSafepointUsingLock(Thread* T); | 33 void EnterSafepointUsingLock(Thread* T); |
| 34 void ExitSafepointUsingLock(Thread* T); | 34 void ExitSafepointUsingLock(Thread* T); |
| 35 | 35 |
| 36 void SafepointThreads(Thread* T); | |
| 37 void ResumeThreads(Thread* T); | |
| 38 | |
| 39 void BlockForSafepoint(Thread* T); | 36 void BlockForSafepoint(Thread* T); |
| 40 | 37 |
| 41 private: | 38 private: |
| 39 void SafepointThreads(Thread* T); |
| 40 void ResumeThreads(Thread* T); |
| 41 |
| 42 Isolate* isolate() const { return isolate_; } | 42 Isolate* isolate() const { return isolate_; } |
| 43 Monitor* threads_lock() const { return isolate_->threads_lock(); } | 43 Monitor* threads_lock() const { return isolate_->threads_lock(); } |
| 44 bool safepoint_in_progress() const { | 44 bool SafepointInProgress() const { |
| 45 ASSERT(threads_lock()->IsOwnedByCurrentThread()); | 45 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 46 return safepoint_in_progress_; | 46 return ((safepoint_operation_count_ > 0) && (owner_ != NULL)); |
| 47 } | 47 } |
| 48 void set_safepoint_in_progress(bool value) { | 48 void SetSafepointInProgress(Thread* T) { |
| 49 ASSERT(threads_lock()->IsOwnedByCurrentThread()); | 49 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 50 safepoint_in_progress_ = value; | 50 ASSERT(owner_ == NULL); |
| 51 ASSERT(safepoint_operation_count_ == 0); |
| 52 safepoint_operation_count_ = 1; |
| 53 owner_ = T; |
| 54 } |
| 55 void ResetSafepointInProgress(Thread* T) { |
| 56 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 57 ASSERT(owner_ == T); |
| 58 ASSERT(safepoint_operation_count_ == 1); |
| 59 safepoint_operation_count_ = 0; |
| 60 owner_ = NULL; |
| 61 } |
| 62 int32_t safepoint_operation_count() const { |
| 63 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 64 return safepoint_operation_count_; |
| 65 } |
| 66 void increment_safepoint_operation_count() { |
| 67 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 68 ASSERT(safepoint_operation_count_ < kMaxInt32); |
| 69 safepoint_operation_count_ += 1; |
| 70 } |
| 71 void decrement_safepoint_operation_count() { |
| 72 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
| 73 ASSERT(safepoint_operation_count_ > 0); |
| 74 safepoint_operation_count_ -= 1; |
| 51 } | 75 } |
| 52 | 76 |
| 53 Isolate* isolate_; | 77 Isolate* isolate_; |
| 54 | 78 |
| 55 // Monitor used by thread initiating a safepoint operation to track threads | 79 // Monitor used by thread initiating a safepoint operation to track threads |
| 56 // not at a safepoint and wait for these threads to reach a safepoint. | 80 // not at a safepoint and wait for these threads to reach a safepoint. |
| 57 Monitor* safepoint_lock_; | 81 Monitor* safepoint_lock_; |
| 58 int32_t number_threads_not_at_safepoint_; | 82 int32_t number_threads_not_at_safepoint_; |
| 59 | 83 |
| 60 // Flag to indicate if a safepoint operation is currently in progress. | 84 // Count that indicates if a safepoint operation is currently in progress |
| 61 bool safepoint_in_progress_; | 85 // and also tracks the number of recursive safepoint operations on the |
| 86 // same thread. |
| 87 int32_t safepoint_operation_count_; |
| 88 |
| 89 // If a safepoint operation is currently in progress, this field contains |
| 90 // the thread that initiated the safepoint operation, otherwise it is NULL. |
| 91 Thread* owner_; |
| 62 | 92 |
| 63 friend class Isolate; | 93 friend class Isolate; |
| 64 friend class SafepointOperationScope; | 94 friend class SafepointOperationScope; |
| 65 }; | 95 }; |
| 66 | 96 |
| 67 | 97 |
| 68 /* | 98 /* |
| 69 * Set of StackResource classes to track thread execution state transitions: | 99 * Set of StackResource classes to track thread execution state transitions: |
| 70 * | 100 * |
| 71 * kThreadInGenerated transitioning to | 101 * kThreadInGenerated transitioning to |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 378 } |
| 349 | 379 |
| 350 private: | 380 private: |
| 351 uint32_t execution_state_; | 381 uint32_t execution_state_; |
| 352 DISALLOW_COPY_AND_ASSIGN(TransitionToVM); | 382 DISALLOW_COPY_AND_ASSIGN(TransitionToVM); |
| 353 }; | 383 }; |
| 354 | 384 |
| 355 } // namespace dart | 385 } // namespace dart |
| 356 | 386 |
| 357 #endif // VM_SAFEPOINT_H_ | 387 #endif // VM_SAFEPOINT_H_ |
| OLD | NEW |