| 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 VM_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
| 6 #define VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
| 7 | 7 |
| 8 #include "vm/base_isolate.h" | 8 #include "vm/base_isolate.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
| 11 #include "vm/store_buffer.h" | 11 #include "vm/store_buffer.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 class CHA; | 15 class CHA; |
| 16 class Isolate; | 16 class Isolate; |
| 17 class RawBool; |
| 18 class RawObject; |
| 19 class Object; |
| 20 |
| 21 |
| 22 // List of VM-global objects/addresses cached in each Thread object. |
| 23 #define CACHED_VM_OBJECTS_LIST(V) \ |
| 24 V(RawObject*, object_null_, Object::null(), NULL) \ |
| 25 V(RawBool*, bool_true_, Object::bool_true().raw(), NULL) \ |
| 26 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ |
| 27 |
| 28 #define CACHED_ADDRESSES_LIST(V) \ |
| 29 V(uword, update_store_buffer_entry_point_, \ |
| 30 StubCode::UpdateStoreBufferEntryPoint(), 0) |
| 31 |
| 32 #define CACHED_CONSTANTS_LIST(V) \ |
| 33 CACHED_VM_OBJECTS_LIST(V) \ |
| 34 CACHED_ADDRESSES_LIST(V) |
| 35 |
| 17 | 36 |
| 18 // A VM thread; may be executing Dart code or performing helper tasks like | 37 // A VM thread; may be executing Dart code or performing helper tasks like |
| 19 // garbage collection or compilation. The Thread structure associated with | 38 // garbage collection or compilation. The Thread structure associated with |
| 20 // a thread is allocated by EnsureInit before entering an isolate, and destroyed | 39 // a thread is allocated by EnsureInit before entering an isolate, and destroyed |
| 21 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp | 40 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
| 22 // must currently be called manually (issue 23474). | 41 // must currently be called manually (issue 23474). |
| 23 class Thread { | 42 class Thread { |
| 24 public: | 43 public: |
| 25 // The currently executing thread, or NULL if not yet initialized. | 44 // The currently executing thread, or NULL if not yet initialized. |
| 26 static Thread* Current() { | 45 static Thread* Current() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 // Empties the store buffer block into the isolate. | 65 // Empties the store buffer block into the isolate. |
| 47 // TODO(koda): Always run GC in separate thread. | 66 // TODO(koda): Always run GC in separate thread. |
| 48 static void PrepareForGC(); | 67 static void PrepareForGC(); |
| 49 | 68 |
| 50 #if defined(TARGET_OS_WINDOWS) | 69 #if defined(TARGET_OS_WINDOWS) |
| 51 // Clears the state of the current thread and frees the allocation. | 70 // Clears the state of the current thread and frees the allocation. |
| 52 static void CleanUp(); | 71 static void CleanUp(); |
| 53 #endif | 72 #endif |
| 54 | 73 |
| 55 // Called at VM startup. | 74 // Called at VM startup. |
| 56 static void InitOnce(); | 75 static void InitOnceBeforeIsolate(); |
| 76 static void InitOnceAfterObjectAndStubCode(); |
| 57 | 77 |
| 58 // The topmost zone used for allocation in this thread. | 78 // The topmost zone used for allocation in this thread. |
| 59 Zone* zone() { | 79 Zone* zone() { |
| 60 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); | 80 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); |
| 61 } | 81 } |
| 62 | 82 |
| 63 // The isolate that this thread is operating on, or NULL if none. | 83 // The isolate that this thread is operating on, or NULL if none. |
| 64 Isolate* isolate() const { return isolate_; } | 84 Isolate* isolate() const { return isolate_; } |
| 65 static intptr_t isolate_offset() { | 85 static intptr_t isolate_offset() { |
| 66 return OFFSET_OF(Thread, isolate_); | 86 return OFFSET_OF(Thread, isolate_); |
| 67 } | 87 } |
| 68 | 88 |
| 69 // The (topmost) CHA for the compilation in the isolate of this thread. | 89 // The (topmost) CHA for the compilation in the isolate of this thread. |
| 70 // TODO(23153): Move this out of Isolate/Thread. | 90 // TODO(23153): Move this out of Isolate/Thread. |
| 71 CHA* cha() const; | 91 CHA* cha() const; |
| 72 void set_cha(CHA* value); | 92 void set_cha(CHA* value); |
| 73 | 93 |
| 74 void StoreBufferAddObject(RawObject* obj); | 94 void StoreBufferAddObject(RawObject* obj); |
| 75 void StoreBufferAddObjectGC(RawObject* obj); | 95 void StoreBufferAddObjectGC(RawObject* obj); |
| 76 #if defined(TESTING) | 96 #if defined(TESTING) |
| 77 bool StoreBufferContains(RawObject* obj) const { | 97 bool StoreBufferContains(RawObject* obj) const { |
| 78 return store_buffer_block_->Contains(obj); | 98 return store_buffer_block_->Contains(obj); |
| 79 } | 99 } |
| 80 #endif | 100 #endif |
| 81 void StoreBufferBlockProcess(bool check_threshold); | 101 void StoreBufferBlockProcess(bool check_threshold); |
| 82 static intptr_t store_buffer_block_offset() { | 102 static intptr_t store_buffer_block_offset() { |
| 83 return OFFSET_OF(Thread, store_buffer_block_); | 103 return OFFSET_OF(Thread, store_buffer_block_); |
| 84 } | 104 } |
| 85 | 105 |
| 106 #define DEFINE_OFFSET_METHOD(type_name, member_name, expr, default_init_value) \ |
| 107 static intptr_t member_name##offset() { \ |
| 108 return OFFSET_OF(Thread, member_name); \ |
| 109 } |
| 110 CACHED_CONSTANTS_LIST(DEFINE_OFFSET_METHOD) |
| 111 #undef DEFINE_OFFSET_METHOD |
| 112 |
| 113 static bool CanLoadFromThread(const Object& object); |
| 114 static intptr_t OffsetFromThread(const Object& object); |
| 115 |
| 86 private: | 116 private: |
| 87 static ThreadLocalKey thread_key_; | 117 static ThreadLocalKey thread_key_; |
| 88 | 118 |
| 89 Isolate* isolate_; | 119 Isolate* isolate_; |
| 90 StoreBufferBlock* store_buffer_block_; | 120 StoreBufferBlock* store_buffer_block_; |
| 121 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
| 122 type_name member_name; |
| 123 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
| 124 #undef DECLARE_MEMBERS |
| 91 | 125 |
| 92 Thread() | 126 explicit Thread(bool init_vm_constants = true); |
| 93 : isolate_(NULL), store_buffer_block_(NULL) {} | 127 |
| 128 void InitVMConstants(); |
| 94 | 129 |
| 95 static void SetCurrent(Thread* current); | 130 static void SetCurrent(Thread* current); |
| 96 | 131 |
| 97 DISALLOW_COPY_AND_ASSIGN(Thread); | 132 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 98 }; | 133 }; |
| 99 | 134 |
| 100 } // namespace dart | 135 } // namespace dart |
| 101 | 136 |
| 102 #endif // VM_THREAD_H_ | 137 #endif // VM_THREAD_H_ |
| OLD | NEW |