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

Side by Side Diff: runtime/vm/thread.cc

Issue 1210033007: Cache some global constants in Thread, to allow access via THR register. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove unused define. Created 5 years, 5 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
« no previous file with comments | « runtime/vm/thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/thread.h" 5 #include "vm/thread.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h"
8 #include "vm/os_thread.h" 9 #include "vm/os_thread.h"
9 #include "vm/profiler.h" 10 #include "vm/profiler.h"
11 #include "vm/stub_code.h"
10 #include "vm/thread_interrupter.h" 12 #include "vm/thread_interrupter.h"
11 13
12 14
13 namespace dart { 15 namespace dart {
14 16
15 // The single thread local key which stores all the thread local data 17 // The single thread local key which stores all the thread local data
16 // for a thread. 18 // for a thread.
17 // TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_? 19 // TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_?
18 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey; 20 ThreadLocalKey Thread::thread_key_ = OSThread::kUnsetThreadLocalKey;
19 21
20 22
21 static void DeleteThread(void* thread) { 23 static void DeleteThread(void* thread) {
22 delete reinterpret_cast<Thread*>(thread); 24 delete reinterpret_cast<Thread*>(thread);
23 } 25 }
24 26
25 27
26 void Thread::InitOnce() { 28 void Thread::InitOnceBeforeIsolate() {
27 ASSERT(thread_key_ == OSThread::kUnsetThreadLocalKey); 29 ASSERT(thread_key_ == OSThread::kUnsetThreadLocalKey);
28 thread_key_ = OSThread::CreateThreadLocal(DeleteThread); 30 thread_key_ = OSThread::CreateThreadLocal(DeleteThread);
29 ASSERT(thread_key_ != OSThread::kUnsetThreadLocalKey); 31 ASSERT(thread_key_ != OSThread::kUnsetThreadLocalKey);
32 ASSERT(Thread::Current() == NULL);
33 // Postpone initialization of VM constants for this first thread.
34 SetCurrent(new Thread(false));
30 } 35 }
31 36
32 37
38 void Thread::InitOnceAfterObjectAndStubCode() {
39 Thread* thread = Thread::Current();
40 ASSERT(thread != NULL);
41 ASSERT(thread->isolate() == Dart::vm_isolate());
42 thread->InitVMConstants();
43 }
44
45
33 void Thread::SetCurrent(Thread* current) { 46 void Thread::SetCurrent(Thread* current) {
34 OSThread::SetThreadLocal(thread_key_, reinterpret_cast<uword>(current)); 47 OSThread::SetThreadLocal(thread_key_, reinterpret_cast<uword>(current));
35 } 48 }
36 49
37 50
38 void Thread::EnsureInit() { 51 void Thread::EnsureInit() {
39 if (Thread::Current() == NULL) { 52 if (Thread::Current() == NULL) {
40 SetCurrent(new Thread()); 53 SetCurrent(new Thread());
41 } 54 }
42 } 55 }
43 56
44 57
45 #if defined(TARGET_OS_WINDOWS) 58 #if defined(TARGET_OS_WINDOWS)
46 void Thread::CleanUp() { 59 void Thread::CleanUp() {
47 Thread* current = Current(); 60 Thread* current = Current();
48 if (current != NULL) { 61 if (current != NULL) {
49 delete current; 62 delete current;
50 } 63 }
51 SetCurrent(NULL); 64 SetCurrent(NULL);
52 } 65 }
53 #endif 66 #endif
54 67
55 68
69 Thread::Thread(bool init_vm_constants)
70 : isolate_(NULL),
71 store_buffer_block_(NULL),
72 object_null_(NULL),
73 bool_true_(NULL),
74 bool_false_(NULL),
75 update_store_buffer_entry_point_(0) {
76 if (init_vm_constants) {
77 InitVMConstants();
78 }
79 }
80
81
82 void Thread::InitVMConstants() {
83 ASSERT(object_null_ == NULL);
84 object_null_ = Object::null();
85 ASSERT(bool_true_ == NULL);
86 bool_true_ = Object::bool_true().raw();
87 ASSERT(bool_false_ == NULL);
88 bool_false_ = Object::bool_false().raw();
89 ASSERT(update_store_buffer_entry_point_ == 0);
90 update_store_buffer_entry_point_ = StubCode::UpdateStoreBufferEntryPoint();
91 }
92
93
56 void Thread::EnterIsolate(Isolate* isolate) { 94 void Thread::EnterIsolate(Isolate* isolate) {
57 Thread* thread = Thread::Current(); 95 Thread* thread = Thread::Current();
58 ASSERT(thread != NULL); 96 ASSERT(thread != NULL);
59 ASSERT(thread->isolate() == NULL); 97 ASSERT(thread->isolate() == NULL);
60 ASSERT(isolate->mutator_thread() == NULL); 98 ASSERT(isolate->mutator_thread() == NULL);
61 thread->isolate_ = isolate; 99 thread->isolate_ = isolate;
62 isolate->set_mutator_thread(thread); 100 isolate->set_mutator_thread(thread);
63 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow 101 // TODO(koda): Migrate thread_state_ and profile_data_ to Thread, to allow
64 // helper threads concurrent with mutator. 102 // helper threads concurrent with mutator.
65 ASSERT(isolate->thread_state() == NULL); 103 ASSERT(isolate->thread_state() == NULL);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return isolate_->cha_; 200 return isolate_->cha_;
163 } 201 }
164 202
165 203
166 void Thread::set_cha(CHA* value) { 204 void Thread::set_cha(CHA* value) {
167 ASSERT(isolate_ != NULL); 205 ASSERT(isolate_ != NULL);
168 isolate_->cha_ = value; 206 isolate_->cha_ = value;
169 } 207 }
170 208
171 } // namespace dart 209 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698