Skip to content

Commit 3dd9cbf

Browse files
committed
---
yaml --- r: 30432 b: refs/heads/master c: 89daba5 h: refs/heads/master v: v3
1 parent 5258c3a commit 3dd9cbf

File tree

11 files changed

+105
-63
lines changed

11 files changed

+105
-63
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b4a53727f47d789724e0cbe94e8b1b2f7312b004
2+
refs/heads/master: 89daba54544de1150c66ba72da078b9f113feb51

trunk/runtime/vm/base_isolate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef VM_BASE_ISOLATE_H_
66
#define VM_BASE_ISOLATE_H_
77

8+
#include "platform/assert.h"
89
#include "vm/globals.h"
910

1011
namespace dart {

trunk/runtime/vm/compiler.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ DEFINE_RUNTIME_ENTRY(CompileFunction, 1) {
178178

179179

180180
RawError* Compiler::Compile(const Library& library, const Script& script) {
181-
Isolate* isolate = Isolate::Current();
181+
Isolate* volatile isolate = Isolate::Current();
182182
StackZone zone(isolate);
183183
LongJumpScope jump;
184184
if (setjmp(*jump.Set()) == 0) {
@@ -279,7 +279,7 @@ RawError* Compiler::CompileClass(const Class& cls) {
279279
}
280280
}
281281

282-
Isolate* isolate = Isolate::Current();
282+
Isolate* volatile isolate = Isolate::Current();
283283
// We remember all the classes that are being compiled in these lists. This
284284
// also allows us to reset the marked_for_parsing state in case we see an
285285
// error.
@@ -374,9 +374,9 @@ static bool CompileParsedFunctionHelper(CompilationPipeline* pipeline,
374374
}
375375
TimerScope timer(FLAG_compiler_stats, &CompilerStats::codegen_timer);
376376
bool is_compiled = false;
377-
Thread* thread = Thread::Current();
378-
Zone* zone = thread->zone();
379-
Isolate* isolate = thread->isolate();
377+
Thread* volatile thread = Thread::Current();
378+
Zone* volatile zone = thread->zone();
379+
Isolate* volatile isolate = thread->isolate();
380380
HANDLESCOPE(isolate);
381381

382382
// We may reattempt compilation if the function needs to be assembled using
@@ -964,10 +964,10 @@ static RawError* CompileFunctionHelper(CompilationPipeline* pipeline,
964964
const Function& function,
965965
bool optimized,
966966
intptr_t osr_id) {
967-
Thread* thread = Thread::Current();
968-
Isolate* isolate = thread->isolate();
967+
Thread* volatile thread = Thread::Current();
968+
Isolate* volatile isolate = thread->isolate();
969969
StackZone stack_zone(isolate);
970-
Zone* zone = stack_zone.GetZone();
970+
Zone* volatile zone = stack_zone.GetZone();
971971
LongJumpScope jump;
972972
if (setjmp(*jump.Set()) == 0) {
973973
TIMERSCOPE(isolate, time_compilation);
@@ -1065,7 +1065,7 @@ RawError* Compiler::CompileOptimizedFunction(Thread* thread,
10651065
// This is only used from unit tests.
10661066
RawError* Compiler::CompileParsedFunction(
10671067
ParsedFunction* parsed_function) {
1068-
Isolate* isolate = Isolate::Current();
1068+
Isolate* volatile isolate = Isolate::Current();
10691069
LongJumpScope jump;
10701070
if (setjmp(*jump.Set()) == 0) {
10711071
// Non-optimized code generator.
@@ -1142,7 +1142,7 @@ RawObject* Compiler::EvaluateStaticInitializer(const Field& field) {
11421142
// The VM sets the field's value to transiton_sentinel prior to
11431143
// evaluating the initializer value.
11441144
ASSERT(field.value() == Object::transition_sentinel().raw());
1145-
Isolate* isolate = Isolate::Current();
1145+
Isolate* volatile isolate = Isolate::Current();
11461146
StackZone zone(isolate);
11471147
LongJumpScope jump;
11481148
if (setjmp(*jump.Set()) == 0) {
@@ -1175,8 +1175,8 @@ RawObject* Compiler::EvaluateStaticInitializer(const Field& field) {
11751175

11761176

11771177
RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) {
1178-
Thread* thread = Thread::Current();
1179-
Isolate* isolate = thread->isolate();
1178+
Thread* volatile thread = Thread::Current();
1179+
Isolate* volatile isolate = thread->isolate();
11801180
LongJumpScope jump;
11811181
if (setjmp(*jump.Set()) == 0) {
11821182
if (FLAG_trace_compiler) {

trunk/runtime/vm/dart.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const char* Dart::InitOnce(Dart_IsolateCreateCallback create,
9292
Isolate::SetEntropySourceCallback(entropy_source);
9393
OS::InitOnce();
9494
VirtualMemory::InitOnce();
95+
Thread::InitOnce();
9596
Isolate::InitOnce();
9697
PortMap::InitOnce();
9798
FreeListElement::InitOnce();

trunk/runtime/vm/isolate.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
536536
object##_handle_(NULL),
537537

538538
Isolate::Isolate()
539-
: vm_tag_(0),
539+
: mutator_thread_(new Thread(this)),
540+
vm_tag_(0),
540541
store_buffer_(),
541542
message_notify_callback_(NULL),
542543
name_(NULL),
@@ -584,7 +585,6 @@ Isolate::Isolate()
584585
stack_frame_index_(-1),
585586
last_allocationprofile_accumulator_reset_timestamp_(0),
586587
last_allocationprofile_gc_timestamp_(0),
587-
cha_(NULL),
588588
object_id_ring_(NULL),
589589
trace_buffer_(NULL),
590590
profiler_data_(NULL),
@@ -603,7 +603,8 @@ Isolate::Isolate()
603603
}
604604

605605
Isolate::Isolate(Isolate* original)
606-
: vm_tag_(0),
606+
: mutator_thread_(new Thread(this)),
607+
vm_tag_(0),
607608
store_buffer_(true),
608609
class_table_(original->class_table()),
609610
message_notify_callback_(NULL),
@@ -647,7 +648,6 @@ Isolate::Isolate(Isolate* original)
647648
stack_frame_index_(-1),
648649
last_allocationprofile_accumulator_reset_timestamp_(0),
649650
last_allocationprofile_gc_timestamp_(0),
650-
cha_(NULL),
651651
object_id_ring_(NULL),
652652
trace_buffer_(NULL),
653653
profiler_data_(NULL),
@@ -682,18 +682,26 @@ Isolate::~Isolate() {
682682
delete spawn_state_;
683683
delete log_;
684684
log_ = NULL;
685+
delete mutator_thread_;
685686
}
686687

687688

689+
#if defined(DEBUG)
690+
bool Isolate::IsIsolateOf(Thread* thread) {
691+
return this == thread->isolate();
692+
}
693+
#endif // DEBUG
694+
695+
688696
void Isolate::SetCurrent(Isolate* current) {
689697
Isolate* old_current = Current();
690698
if (old_current != NULL) {
691699
old_current->set_vm_tag(VMTag::kIdleTagId);
692700
old_current->set_thread_state(NULL);
693701
Profiler::EndExecution(old_current);
694702
}
695-
OSThread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
696703
if (current != NULL) {
704+
Thread::SetCurrent(current->mutator_thread());
697705
ASSERT(current->thread_state() == NULL);
698706
InterruptableThreadState* thread_state =
699707
ThreadInterrupter::GetCurrentThreadState();
@@ -704,21 +712,13 @@ void Isolate::SetCurrent(Isolate* current) {
704712
Profiler::BeginExecution(current);
705713
current->set_thread_state(thread_state);
706714
current->set_vm_tag(VMTag::kVMTagId);
715+
} else {
716+
Thread::SetCurrent(NULL);
707717
}
708718
}
709719

710720

711-
// The single thread local key which stores all the thread local data
712-
// for a thread. Since an Isolate is the central repository for
713-
// storing all isolate specific information a single thread local key
714-
// is sufficient.
715-
ThreadLocalKey Isolate::isolate_key = OSThread::kUnsetThreadLocalKey;
716-
717-
718721
void Isolate::InitOnce() {
719-
ASSERT(isolate_key == OSThread::kUnsetThreadLocalKey);
720-
isolate_key = OSThread::CreateThreadLocal();
721-
ASSERT(isolate_key != OSThread::kUnsetThreadLocalKey);
722722
create_callback_ = NULL;
723723
isolates_list_monitor_ = new Monitor();
724724
ASSERT(isolates_list_monitor_ != NULL);

trunk/runtime/vm/isolate.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "vm/random.h"
1717
#include "vm/store_buffer.h"
1818
#include "vm/tags.h"
19+
#include "vm/thread.h"
1920
#include "vm/os_thread.h"
2021
#include "vm/trace_buffer.h"
2122
#include "vm/timer.h"
@@ -118,9 +119,9 @@ class Isolate : public BaseIsolate {
118119
~Isolate();
119120

120121
static inline Isolate* Current() {
121-
return reinterpret_cast<Isolate*>(OSThread::GetThreadLocal(isolate_key));
122+
Thread* thread = Thread::Current();
123+
return thread == NULL ? NULL : thread->isolate();
122124
}
123-
124125
static void SetCurrent(Isolate* isolate);
125126

126127
static void InitOnce();
@@ -165,7 +166,19 @@ class Isolate : public BaseIsolate {
165166
message_notify_callback_ = value;
166167
}
167168

169+
// A thread that operates on this isolate and may execute Dart code.
170+
// No other threads operating on this isolate may execute Dart code.
171+
// TODO(koda): Remove after caching current thread in generated code.
172+
Thread* mutator_thread() {
173+
DEBUG_ASSERT(IsIsolateOf(mutator_thread_));
174+
return mutator_thread_;
175+
}
176+
#if defined(DEBUG)
177+
bool IsIsolateOf(Thread* thread);
178+
#endif // DEBUG
179+
168180
const char* name() const { return name_; }
181+
// TODO(koda): Move to Thread.
169182
class Log* Log() const;
170183

171184
int64_t start_time() const { return start_time_; }
@@ -667,13 +680,9 @@ class Isolate : public BaseIsolate {
667680
user_tag_ = tag;
668681
}
669682

670-
CHA* cha() const { return cha_; }
671-
void set_cha(CHA* value) { cha_ = value; }
672-
673683
template<class T> T* AllocateReusableHandle();
674684

675-
static ThreadLocalKey isolate_key;
676-
685+
Thread* mutator_thread_;
677686
uword vm_tag_;
678687
StoreBuffer store_buffer_;
679688
ClassTable class_table_;
@@ -731,8 +740,6 @@ class Isolate : public BaseIsolate {
731740
int64_t last_allocationprofile_accumulator_reset_timestamp_;
732741
int64_t last_allocationprofile_gc_timestamp_;
733742

734-
CHA* cha_;
735-
736743
// Ring buffer of objects assigned an id.
737744
ObjectIdRing* object_id_ring_;
738745

trunk/runtime/vm/native_entry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ typedef void (*NativeFunction)(NativeArguments* arguments);
5353
{ \
5454
Isolate* isolate = arguments->isolate(); \
5555
/* TODO(koda): Pivot from Isolate to Thread in NativeArguments. */ \
56-
Thread* thread = Thread::CurrentFromCurrentIsolate(isolate); \
56+
Thread* thread = isolate->mutator_thread(); \
57+
ASSERT(thread == Thread::Current()); \
5758
StackZone zone(isolate); \
5859
SET_NATIVE_RETVAL(arguments, \
5960
DN_Helper##name(isolate, \

trunk/runtime/vm/runtime_entry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class RuntimeEntry : public ValueObject {
7878
if (FLAG_trace_runtime_calls) OS::Print("Runtime call: %s\n", ""#name); \
7979
{ \
8080
Isolate* isolate = arguments.isolate(); \
81-
Thread* thread = Thread::CurrentFromCurrentIsolate(isolate); \
81+
Thread* thread = isolate->mutator_thread(); \
82+
ASSERT(thread == Thread::Current()); \
8283
StackZone zone(isolate); \
8384
HANDLESCOPE(isolate); \
8485
DRT_Helper##name(isolate, thread, zone.GetZone(), arguments); \

trunk/runtime/vm/thread.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
#include "vm/thread.h"
6+
7+
#include "vm/isolate.h"
8+
#include "vm/os_thread.h"
9+
10+
11+
namespace dart {
12+
13+
// The single thread local key which stores all the thread local data
14+
// for a thread.
15+
// TODO(koda): Can we merge this with ThreadInterrupter::thread_state_key_?
16+
ThreadLocalKey Thread::thread_key = OSThread::kUnsetThreadLocalKey;
17+
18+
19+
void Thread::InitOnce() {
20+
ASSERT(thread_key == OSThread::kUnsetThreadLocalKey);
21+
thread_key = OSThread::CreateThreadLocal();
22+
ASSERT(thread_key != OSThread::kUnsetThreadLocalKey);
23+
}
24+
25+
26+
void Thread::SetCurrent(Thread* current) {
27+
OSThread::SetThreadLocal(thread_key, reinterpret_cast<uword>(current));
28+
}
29+
30+
} // namespace dart

trunk/runtime/vm/thread.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
#ifndef VM_THREAD_H_
66
#define VM_THREAD_H_
77

8-
#include "vm/isolate.h"
8+
#include "vm/base_isolate.h"
9+
#include "vm/globals.h"
10+
#include "vm/os_thread.h"
911

1012
namespace dart {
1113

14+
class CHA;
15+
class Isolate;
16+
1217
// A VM thread; may be executing Dart code or performing helper tasks like
1318
// garbage collection or compilation.
1419
class Thread {
1520
public:
21+
explicit Thread(Isolate* isolate)
22+
: isolate_(isolate),
23+
cha_(NULL) {}
24+
25+
static void InitOnce();
26+
1627
static Thread* Current() {
17-
// For now, there is still just one thread per isolate, and the Thread
18-
// class just aliases the Isolate*. Once all interfaces and uses have been
19-
// updated to distinguish between isolates and threads, Thread will get its
20-
// own thread-local storage key and fields.
21-
return reinterpret_cast<Thread*>(Isolate::Current());
22-
}
23-
// TODO(koda): Remove after pivoting to Thread* in native/runtime entries.
24-
static Thread* CurrentFromCurrentIsolate(BaseIsolate* isolate) {
25-
ASSERT(Isolate::Current() == isolate);
26-
return reinterpret_cast<Thread*>(isolate);
28+
return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key));
2729
}
30+
static void SetCurrent(Thread* current);
2831

2932
// The topmost zone used for allocation in this thread.
3033
Zone* zone() {
31-
return reinterpret_cast<BaseIsolate*>(this)->current_zone();
34+
return reinterpret_cast<BaseIsolate*>(isolate())->current_zone();
3235
}
3336

34-
// The isolate that this thread is operating on.
35-
Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
36-
const Isolate* isolate() const {
37-
return reinterpret_cast<const Isolate*>(this);
38-
}
39-
40-
// The log for this thread.
41-
class Log* Log() {
42-
return reinterpret_cast<Isolate*>(this)->Log();
43-
}
37+
// The isolate that this thread is operating on, or NULL if none.
38+
Isolate* isolate() const { return isolate_; }
4439

4540
// The (topmost) CHA for the compilation in this thread.
46-
CHA* cha() const { return isolate()->cha(); }
47-
void set_cha(CHA* value) { isolate()->set_cha(value); }
41+
CHA* cha() const { return cha_; }
42+
void set_cha(CHA* value) { cha_ = value; }
4843

4944
private:
45+
static ThreadLocalKey thread_key;
46+
47+
Isolate* isolate_;
48+
CHA* cha_;
49+
5050
DISALLOW_COPY_AND_ASSIGN(Thread);
5151
};
5252

trunk/runtime/vm/vm_sources.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@
432432
'symbols.h',
433433
'tags.cc',
434434
'tags.h',
435+
'thread.cc',
435436
'thread.h',
436437
'thread_interrupter.cc',
437438
'thread_interrupter.h',

0 commit comments

Comments
 (0)