V8 Project
v8::internal::ThreadManager Class Reference

#include <v8threads.h>

+ Collaboration diagram for v8::internal::ThreadManager:

Public Member Functions

void Lock ()
 
void Unlock ()
 
void ArchiveThread ()
 
bool RestoreThread ()
 
void FreeThreadResources ()
 
bool IsArchived ()
 
void Iterate (ObjectVisitor *v)
 
void IterateArchivedThreads (ThreadVisitor *v)
 
bool IsLockedByCurrentThread ()
 
ThreadId CurrentId ()
 
void TerminateExecution (ThreadId thread_id)
 
ThreadStateFirstThreadStateInUse ()
 
ThreadStateGetFreeThreadState ()
 

Private Member Functions

 ThreadManager ()
 
 ~ThreadManager ()
 
void DeleteThreadStateList (ThreadState *anchor)
 
void EagerlyArchiveThread ()
 

Private Attributes

base::Mutex mutex_
 
ThreadId mutex_owner_
 
ThreadId lazily_archived_thread_
 
ThreadStatelazily_archived_thread_state_
 
ThreadStatefree_anchor_
 
ThreadStatein_use_anchor_
 
Isolateisolate_
 

Friends

class Isolate
 
class ThreadState
 

Detailed Description

Definition at line 67 of file v8threads.h.

Constructor & Destructor Documentation

◆ ThreadManager()

v8::internal::ThreadManager::ThreadManager ( )
private

Definition at line 245 of file v8threads.cc.

251  free_anchor_ = new ThreadState(this);
252  in_use_anchor_ = new ThreadState(this);
253 }
static ThreadId Invalid()
Definition: isolate.h:188
ThreadState * lazily_archived_thread_state_
Definition: v8threads.h:102
ThreadState * in_use_anchor_
Definition: v8threads.h:110
ThreadState * free_anchor_
Definition: v8threads.h:108
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References free_anchor_, in_use_anchor_, and ThreadState.

◆ ~ThreadManager()

v8::internal::ThreadManager::~ThreadManager ( )
private

Definition at line 256 of file v8threads.cc.

256  {
259 }
void DeleteThreadStateList(ThreadState *anchor)
Definition: v8threads.cc:262

References DeleteThreadStateList(), free_anchor_, and in_use_anchor_.

+ Here is the call graph for this function:

Member Function Documentation

◆ ArchiveThread()

void v8::internal::ThreadManager::ArchiveThread ( )

Definition at line 273 of file v8threads.cc.

273  {
275  DCHECK(!IsArchived());
277  ThreadState* state = GetFreeThreadState();
278  state->Unlink();
279  Isolate::PerIsolateThreadData* per_thread =
281  per_thread->set_thread_state(state);
284  DCHECK(state->id().Equals(ThreadId::Invalid()));
285  state->set_id(CurrentId());
286  DCHECK(!state->id().Equals(ThreadId::Invalid()));
287 }
PerIsolateThreadData * FindOrAllocatePerThreadDataForThisThread()
Definition: isolate.cc:119
static ThreadId Current()
Definition: isolate.h:185
ThreadState * GetFreeThreadState()
Definition: v8threads.cc:219
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::ThreadId::Current(), CurrentId(), DCHECK, v8::internal::Isolate::FindOrAllocatePerThreadDataForThisThread(), GetFreeThreadState(), v8::internal::ThreadState::id(), v8::internal::ThreadId::Invalid(), IsArchived(), IsLockedByCurrentThread(), isolate_, lazily_archived_thread_, lazily_archived_thread_state_, v8::internal::ThreadState::set_id(), and v8::internal::ThreadState::Unlink().

Referenced by v8::Unlocker::Initialize(), and v8::Locker::~Locker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CurrentId()

ThreadId v8::internal::ThreadManager::CurrentId ( )

Definition at line 353 of file v8threads.cc.

353  {
354  return ThreadId::Current();
355 }

References v8::internal::ThreadId::Current().

Referenced by ArchiveThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeleteThreadStateList()

void v8::internal::ThreadManager::DeleteThreadStateList ( ThreadState anchor)
private

Definition at line 262 of file v8threads.cc.

262  {
263  // The list starts and ends with the anchor.
264  for (ThreadState* current = anchor->next_; current != anchor;) {
265  ThreadState* next = current->next_;
266  delete current;
267  current = next;
268  }
269  delete anchor;
270 }

References v8::internal::ThreadState::next_.

Referenced by ~ThreadManager().

+ Here is the caller graph for this function:

◆ EagerlyArchiveThread()

void v8::internal::ThreadManager::EagerlyArchiveThread ( )
private

Definition at line 290 of file v8threads.cc.

290  {
294  char* to = state->data();
295  // Ensure that data containing GC roots are archived first, and handle them
296  // in ThreadManager::Iterate(ObjectVisitor*).
299  to = Relocatable::ArchiveState(isolate_, to);
301  to = isolate_->stack_guard()->ArchiveStackGuard(to);
303  to = isolate_->bootstrapper()->ArchiveState(to);
306 }
char * ArchiveDebug(char *to)
Definition: debug.cc:571
char * ArchiveThread(char *to)
Definition: api.cc:7529
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:901
StackGuard * stack_guard()
Definition: isolate.h:872
char * ArchiveThread(char *to)
Definition: isolate.cc:1369
RegExpStack * regexp_stack()
Definition: isolate.h:960
Bootstrapper * bootstrapper()
Definition: isolate.h:856
char * ArchiveStack(char *to)
Definition: regexp-stack.cc:35
void LinkInto(List list)
Definition: v8threads.cc:208
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file

References v8::internal::Debug::ArchiveDebug(), v8::internal::RegExpStack::ArchiveStack(), v8::internal::HandleScopeImplementer::ArchiveThread(), v8::internal::Isolate::ArchiveThread(), v8::internal::Isolate::bootstrapper(), v8::internal::ThreadState::data(), DCHECK, v8::internal::Isolate::debug(), v8::internal::Isolate::handle_scope_implementer(), v8::internal::ThreadState::IN_USE_LIST, v8::internal::ThreadId::Invalid(), IsLockedByCurrentThread(), isolate_, lazily_archived_thread_, lazily_archived_thread_state_, v8::internal::ThreadState::LinkInto(), NULL, v8::internal::Isolate::regexp_stack(), v8::internal::Isolate::stack_guard(), and to().

Referenced by RestoreThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FirstThreadStateInUse()

ThreadState * v8::internal::ThreadManager::FirstThreadStateInUse ( )

Definition at line 231 of file v8threads.cc.

231  {
232  return in_use_anchor_->Next();
233 }
ThreadState * Next()
Definition: v8threads.cc:236

References in_use_anchor_, and v8::internal::ThreadState::Next().

Referenced by v8::internal::Deserializer::Deserialize(), Iterate(), IterateArchivedThreads(), v8::internal::StartupSerializer::SerializeStrongReferences(), and TerminateExecution().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FreeThreadResources()

void v8::internal::ThreadManager::FreeThreadResources ( )

Definition at line 309 of file v8threads.cc.

309  {
311  DCHECK(!isolate_->external_caught_exception());
316  isolate_->stack_guard()->FreeThreadResources();
318  isolate_->bootstrapper()->FreeThreadResources();
319 }
void FreeThreadResources()
Definition: debug.h:452
void FreeThreadResources()
Definition: isolate.h:684
v8::TryCatch * try_catch_handler()
Definition: isolate.h:593
bool has_pending_exception()
Definition: isolate.h:581

References v8::internal::Isolate::bootstrapper(), DCHECK, v8::internal::Isolate::debug(), v8::internal::HandleScopeImplementer::FreeThreadResources(), v8::internal::Debug::FreeThreadResources(), v8::internal::Isolate::FreeThreadResources(), v8::internal::RegExpStack::FreeThreadResources(), v8::internal::Isolate::handle_scope_implementer(), v8::internal::Isolate::has_pending_exception(), isolate_, NULL, v8::internal::Isolate::regexp_stack(), v8::internal::Isolate::stack_guard(), and v8::internal::Isolate::try_catch_handler().

Referenced by v8::Locker::~Locker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetFreeThreadState()

ThreadState * v8::internal::ThreadManager::GetFreeThreadState ( )

Definition at line 219 of file v8threads.cc.

219  {
220  ThreadState* gotten = free_anchor_->next_;
221  if (gotten == free_anchor_) {
222  ThreadState* new_thread_state = new ThreadState(this);
223  new_thread_state->AllocateSpace();
224  return new_thread_state;
225  }
226  return gotten;
227 }
ThreadState * next_
Definition: v8threads.h:44

References v8::internal::ThreadState::AllocateSpace(), free_anchor_, v8::internal::ThreadState::next_, and ThreadState.

Referenced by ArchiveThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsArchived()

bool v8::internal::ThreadManager::IsArchived ( )

Definition at line 322 of file v8threads.cc.

322  {
323  Isolate::PerIsolateThreadData* data =
325  return data != NULL && data->thread_state() != NULL;
326 }
PerIsolateThreadData * FindPerThreadDataForThisThread()
Definition: isolate.cc:135

References v8::internal::Isolate::FindPerThreadDataForThisThread(), isolate_, and NULL.

Referenced by ArchiveThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsLockedByCurrentThread()

bool v8::internal::ThreadManager::IsLockedByCurrentThread ( )
inline

Definition at line 79 of file v8threads.h.

79  {
80  return mutex_owner_.Equals(ThreadId::Current());
81  }

References v8::internal::ThreadId::Current(), and mutex_owner_.

Referenced by ArchiveThread(), EagerlyArchiveThread(), v8::HandleScope::Initialize(), v8::Unlocker::Initialize(), v8::Locker::Initialize(), v8::Locker::IsLocked(), Lock(), RestoreThread(), v8::Locker::~Locker(), and v8::Unlocker::~Unlocker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Iterate()

void v8::internal::ThreadManager::Iterate ( ObjectVisitor v)

Definition at line 329 of file v8threads.cc.

329  {
330  // Expecting no threads during serialization/deserialization
331  for (ThreadState* state = FirstThreadStateInUse();
332  state != NULL;
333  state = state->Next()) {
334  char* data = state->data();
335  data = HandleScopeImplementer::Iterate(v, data);
336  data = isolate_->Iterate(v, data);
337  data = Relocatable::Iterate(v, data);
338  }
339 }
void Iterate(v8::internal::ObjectVisitor *v)
Definition: api.cc:7590
void Iterate(ObjectVisitor *v)
Definition: isolate.cc:206
ThreadState * FirstThreadStateInUse()
Definition: v8threads.cc:231

References FirstThreadStateInUse(), isolate_, v8::internal::Isolate::Iterate(), v8::internal::HandleScopeImplementer::Iterate(), and NULL.

Referenced by v8::internal::Heap::IterateStrongRoots().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IterateArchivedThreads()

void v8::internal::ThreadManager::IterateArchivedThreads ( ThreadVisitor v)

Definition at line 342 of file v8threads.cc.

342  {
343  for (ThreadState* state = FirstThreadStateInUse();
344  state != NULL;
345  state = state->Next()) {
346  char* data = state->data();
348  isolate_->IterateThread(v, data);
349  }
350 }
void IterateThread(ThreadVisitor *v, char *t)
Definition: isolate.cc:174

References v8::internal::HandleScopeImplementer::ArchiveSpacePerThread(), FirstThreadStateInUse(), isolate_, v8::internal::Isolate::IterateThread(), and NULL.

Referenced by v8::internal::LiveEdit::CheckAndDropActivations(), v8::internal::Debug::PrepareForBreakPoints(), and v8::internal::MarkCompactCollector::PrepareForCodeFlushing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Lock()

void v8::internal::ThreadManager::Lock ( )

Definition at line 158 of file v8threads.cc.

158  {
159  mutex_.Lock();
162 }

References v8::internal::ThreadId::Current(), DCHECK, IsLockedByCurrentThread(), mutex_, and mutex_owner_.

Referenced by v8::Locker::Initialize(), and v8::Unlocker::~Unlocker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RestoreThread()

bool v8::internal::ThreadManager::RestoreThread ( )

Definition at line 103 of file v8threads.cc.

103  {
105  // First check whether the current thread has been 'lazily archived', i.e.
106  // not archived at all. If that is the case we put the state storage we
107  // had prepared back in the free list, since we didn't need it after all.
110  Isolate::PerIsolateThreadData* per_thread =
112  DCHECK(per_thread != NULL);
113  DCHECK(per_thread->thread_state() == lazily_archived_thread_state_);
117  per_thread->set_thread_state(NULL);
118  return true;
119  }
120 
121  // Make sure that the preemption thread cannot modify the thread state while
122  // it is being archived or restored.
123  ExecutionAccess access(isolate_);
124 
125  // If there is another thread that was lazily archived then we have to really
126  // archive it now.
127  if (lazily_archived_thread_.IsValid()) {
129  }
130  Isolate::PerIsolateThreadData* per_thread =
132  if (per_thread == NULL || per_thread->thread_state() == NULL) {
133  // This is a new thread.
134  isolate_->stack_guard()->InitThread(access);
135  return false;
136  }
137  ThreadState* state = per_thread->thread_state();
138  char* from = state->data();
140  from = isolate_->RestoreThread(from);
141  from = Relocatable::RestoreState(isolate_, from);
142  from = isolate_->debug()->RestoreDebug(from);
143  from = isolate_->stack_guard()->RestoreStackGuard(from);
144  from = isolate_->regexp_stack()->RestoreStack(from);
145  from = isolate_->bootstrapper()->RestoreState(from);
146  per_thread->set_thread_state(NULL);
147  if (state->terminate_on_restore()) {
148  isolate_->stack_guard()->RequestTerminateExecution();
149  state->set_terminate_on_restore(false);
150  }
151  state->set_id(ThreadId::Invalid());
152  state->Unlink();
153  state->LinkInto(ThreadState::FREE_LIST);
154  return true;
155 }
char * RestoreDebug(char *from)
Definition: debug.cc:579
char * RestoreThread(char *from)
Definition: api.cc:7546
char * RestoreThread(char *from)
Definition: isolate.cc:1380
char * RestoreStack(char *from)
Definition: regexp-stack.cc:43
void set_id(ThreadId id)
Definition: v8threads.h:23

References v8::internal::Isolate::bootstrapper(), v8::internal::ThreadId::Current(), v8::internal::ThreadState::data(), DCHECK, v8::internal::Isolate::debug(), EagerlyArchiveThread(), v8::internal::Isolate::FindPerThreadDataForThisThread(), v8::internal::ThreadState::FREE_LIST, v8::internal::Isolate::handle_scope_implementer(), v8::internal::ThreadId::Invalid(), IsLockedByCurrentThread(), isolate_, lazily_archived_thread_, lazily_archived_thread_state_, v8::internal::ThreadState::LinkInto(), NULL, v8::internal::Isolate::regexp_stack(), v8::internal::Debug::RestoreDebug(), v8::internal::RegExpStack::RestoreStack(), v8::internal::HandleScopeImplementer::RestoreThread(), v8::internal::Isolate::RestoreThread(), v8::internal::ThreadState::set_id(), v8::internal::ThreadState::set_terminate_on_restore(), v8::internal::Isolate::stack_guard(), v8::internal::ThreadState::terminate_on_restore(), and v8::internal::ThreadState::Unlink().

Referenced by v8::Locker::Initialize(), and v8::Unlocker::~Unlocker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TerminateExecution()

void v8::internal::ThreadManager::TerminateExecution ( ThreadId  thread_id)

Definition at line 358 of file v8threads.cc.

358  {
359  for (ThreadState* state = FirstThreadStateInUse();
360  state != NULL;
361  state = state->Next()) {
362  if (thread_id.Equals(state->id())) {
363  state->set_terminate_on_restore(true);
364  }
365  }
366 }

References FirstThreadStateInUse(), and NULL.

+ Here is the call graph for this function:

◆ Unlock()

void v8::internal::ThreadManager::Unlock ( )

Definition at line 165 of file v8threads.cc.

165  {
167  mutex_.Unlock();
168 }

References v8::internal::ThreadId::Invalid(), mutex_, and mutex_owner_.

Referenced by v8::Unlocker::Initialize(), and v8::Locker::~Locker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Isolate

friend class Isolate
friend

Definition at line 114 of file v8threads.h.

◆ ThreadState

friend class ThreadState
friend

Definition at line 115 of file v8threads.h.

Referenced by GetFreeThreadState(), and ThreadManager().

Member Data Documentation

◆ free_anchor_

ThreadState* v8::internal::ThreadManager::free_anchor_
private

◆ in_use_anchor_

ThreadState* v8::internal::ThreadManager::in_use_anchor_
private

◆ isolate_

◆ lazily_archived_thread_

ThreadId v8::internal::ThreadManager::lazily_archived_thread_
private

Definition at line 101 of file v8threads.h.

Referenced by ArchiveThread(), EagerlyArchiveThread(), and RestoreThread().

◆ lazily_archived_thread_state_

ThreadState* v8::internal::ThreadManager::lazily_archived_thread_state_
private

Definition at line 102 of file v8threads.h.

Referenced by ArchiveThread(), EagerlyArchiveThread(), and RestoreThread().

◆ mutex_

base::Mutex v8::internal::ThreadManager::mutex_
private

Definition at line 99 of file v8threads.h.

Referenced by Lock(), and Unlock().

◆ mutex_owner_

ThreadId v8::internal::ThreadManager::mutex_owner_
private

Definition at line 100 of file v8threads.h.

Referenced by IsLockedByCurrentThread(), Lock(), and Unlock().


The documentation for this class was generated from the following files: