OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 RUNTIME_VM_THREAD_H_ | 5 #ifndef RUNTIME_VM_THREAD_H_ |
6 #define RUNTIME_VM_THREAD_H_ | 6 #define RUNTIME_VM_THREAD_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/atomic.h" | 10 #include "vm/atomic.h" |
11 #include "vm/bitfield.h" | 11 #include "vm/bitfield.h" |
12 #include "vm/globals.h" | 12 #include "vm/globals.h" |
13 #include "vm/handles.h" | 13 #include "vm/handles.h" |
14 #include "vm/os_thread.h" | 14 #include "vm/os_thread.h" |
15 #include "vm/store_buffer.h" | 15 #include "vm/store_buffer.h" |
16 #include "vm/runtime_entry_list.h" | 16 #include "vm/runtime_entry_list.h" |
17 | |
18 namespace dart { | 17 namespace dart { |
19 | 18 |
20 class AbstractType; | 19 class AbstractType; |
21 class ApiLocalScope; | 20 class ApiLocalScope; |
22 class Array; | 21 class Array; |
23 class CHA; | 22 class CHA; |
24 class Class; | 23 class Class; |
25 class Code; | 24 class Code; |
26 class CompilerStats; | 25 class CompilerStats; |
27 class Error; | 26 class Error; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 259 |
261 // Monitor corresponding to this thread. | 260 // Monitor corresponding to this thread. |
262 Monitor* thread_lock() const { return thread_lock_; } | 261 Monitor* thread_lock() const { return thread_lock_; } |
263 | 262 |
264 // The topmost zone used for allocation in this thread. | 263 // The topmost zone used for allocation in this thread. |
265 Zone* zone() const { return zone_; } | 264 Zone* zone() const { return zone_; } |
266 | 265 |
267 bool ZoneIsOwnedByThread(Zone* zone) const; | 266 bool ZoneIsOwnedByThread(Zone* zone) const; |
268 | 267 |
269 void IncrementMemoryUsage(uintptr_t value) { | 268 void IncrementMemoryUsage(uintptr_t value) { |
270 current_thread_memory_ += value; | 269 current_zone_memory_usage_ += value; |
271 if (current_thread_memory_ > memory_high_watermark_) { | 270 ASSERT(current_zone_memory_usage_ <= current_zone_capacity_); |
272 memory_high_watermark_ = current_thread_memory_; | 271 } |
| 272 |
| 273 void DecrementMemoryUsage(uintptr_t value) { |
| 274 ASSERT(current_zone_memory_usage_ >= value); |
| 275 current_zone_memory_usage_ -= value; |
| 276 } |
| 277 |
| 278 uintptr_t current_zone_memory_usage() { return current_zone_memory_usage_; } |
| 279 |
| 280 void IncrementMemoryCapacity(uintptr_t value) { |
| 281 current_zone_capacity_ += value; |
| 282 if (current_zone_capacity_ > zone_high_watermark_) { |
| 283 zone_high_watermark_ = current_zone_capacity_; |
273 } | 284 } |
274 } | 285 } |
275 | 286 |
276 void DecrementMemoryUsage(uintptr_t value) { | 287 void DecrementMemoryCapacity(uintptr_t value) { |
277 ASSERT(current_thread_memory_ >= value); | 288 ASSERT(current_zone_capacity_ >= value); |
278 current_thread_memory_ -= value; | 289 current_zone_capacity_ -= value; |
| 290 ASSERT(current_zone_capacity_ >= current_zone_memory_usage_); |
279 } | 291 } |
280 | 292 |
281 uintptr_t memory_high_watermark() const { return memory_high_watermark_; } | 293 uintptr_t current_zone_capacity() { return current_zone_capacity_; } |
282 | 294 |
283 void ResetHighWatermark() { memory_high_watermark_ = current_thread_memory_; } | 295 uintptr_t zone_high_watermark() const { return zone_high_watermark_; } |
| 296 |
| 297 void ResetHighWatermark() { zone_high_watermark_ = current_zone_capacity_; } |
284 | 298 |
285 // The reusable api local scope for this thread. | 299 // The reusable api local scope for this thread. |
286 ApiLocalScope* api_reusable_scope() const { return api_reusable_scope_; } | 300 ApiLocalScope* api_reusable_scope() const { return api_reusable_scope_; } |
287 void set_api_reusable_scope(ApiLocalScope* value) { | 301 void set_api_reusable_scope(ApiLocalScope* value) { |
288 ASSERT(value == NULL || api_reusable_scope_ == NULL); | 302 ASSERT(value == NULL || api_reusable_scope_ == NULL); |
289 api_reusable_scope_ = value; | 303 api_reusable_scope_ = value; |
290 } | 304 } |
291 | 305 |
292 // The api local scope for this thread, this where all local handles | 306 // The api local scope for this thread, this where all local handles |
293 // are allocated. | 307 // are allocated. |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 #undef DECLARE_MEMBERS | 724 #undef DECLARE_MEMBERS |
711 | 725 |
712 #define DECLARE_MEMBERS(returntype, name, ...) uword name##_entry_point_; | 726 #define DECLARE_MEMBERS(returntype, name, ...) uword name##_entry_point_; |
713 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) | 727 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) |
714 #undef DECLARE_MEMBERS | 728 #undef DECLARE_MEMBERS |
715 | 729 |
716 TimelineStream* dart_stream_; | 730 TimelineStream* dart_stream_; |
717 OSThread* os_thread_; | 731 OSThread* os_thread_; |
718 Monitor* thread_lock_; | 732 Monitor* thread_lock_; |
719 Zone* zone_; | 733 Zone* zone_; |
720 uintptr_t current_thread_memory_; | 734 uintptr_t current_zone_memory_usage_; |
721 uintptr_t memory_high_watermark_; | 735 uintptr_t current_zone_capacity_; |
| 736 uintptr_t zone_high_watermark_; |
722 ApiLocalScope* api_reusable_scope_; | 737 ApiLocalScope* api_reusable_scope_; |
723 ApiLocalScope* api_top_scope_; | 738 ApiLocalScope* api_top_scope_; |
724 StackResource* top_resource_; | 739 StackResource* top_resource_; |
725 LongJumpScope* long_jump_base_; | 740 LongJumpScope* long_jump_base_; |
726 int32_t no_callback_scope_depth_; | 741 int32_t no_callback_scope_depth_; |
727 #if defined(DEBUG) | 742 #if defined(DEBUG) |
728 HandleScope* top_handle_scope_; | 743 HandleScope* top_handle_scope_; |
729 int32_t no_handle_scope_depth_; | 744 int32_t no_handle_scope_depth_; |
730 int32_t no_safepoint_scope_depth_; | 745 int32_t no_safepoint_scope_depth_; |
731 #endif | 746 #endif |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 #undef REUSABLE_FRIEND_DECLARATION | 811 #undef REUSABLE_FRIEND_DECLARATION |
797 | 812 |
798 friend class ApiZone; | 813 friend class ApiZone; |
799 friend class InterruptChecker; | 814 friend class InterruptChecker; |
800 friend class Isolate; | 815 friend class Isolate; |
801 friend class IsolateTestHelper; | 816 friend class IsolateTestHelper; |
802 friend class NoOOBMessageScope; | 817 friend class NoOOBMessageScope; |
803 friend class Simulator; | 818 friend class Simulator; |
804 friend class StackZone; | 819 friend class StackZone; |
805 friend class ThreadRegistry; | 820 friend class ThreadRegistry; |
806 | |
807 DISALLOW_COPY_AND_ASSIGN(Thread); | 821 DISALLOW_COPY_AND_ASSIGN(Thread); |
808 }; | 822 }; |
809 | 823 |
810 | 824 |
811 #if defined(HOST_OS_WINDOWS) | 825 #if defined(HOST_OS_WINDOWS) |
812 // Clears the state of the current thread and frees the allocation. | 826 // Clears the state of the current thread and frees the allocation. |
813 void WindowsThreadCleanUp(); | 827 void WindowsThreadCleanUp(); |
814 #endif | 828 #endif |
815 | 829 |
816 | 830 |
817 // Disable thread interrupts. | 831 // Disable thread interrupts. |
818 class DisableThreadInterruptsScope : public StackResource { | 832 class DisableThreadInterruptsScope : public StackResource { |
819 public: | 833 public: |
820 explicit DisableThreadInterruptsScope(Thread* thread); | 834 explicit DisableThreadInterruptsScope(Thread* thread); |
821 ~DisableThreadInterruptsScope(); | 835 ~DisableThreadInterruptsScope(); |
822 }; | 836 }; |
823 | 837 |
824 } // namespace dart | 838 } // namespace dart |
825 | 839 |
826 #endif // RUNTIME_VM_THREAD_H_ | 840 #endif // RUNTIME_VM_THREAD_H_ |
OLD | NEW |