V8 Project
v8::platform::DefaultPlatform Class Reference

#include <default-platform.h>

+ Inheritance diagram for v8::platform::DefaultPlatform:
+ Collaboration diagram for v8::platform::DefaultPlatform:

Public Member Functions

 DefaultPlatform ()
 
virtual ~DefaultPlatform ()
 
void SetThreadPoolSize (int thread_pool_size)
 
void EnsureInitialized ()
 
bool PumpMessageLoop (v8::Isolate *isolate)
 
virtual void CallOnBackgroundThread (Task *task, ExpectedRuntime expected_runtime) OVERRIDE
 Schedules a task to be invoked on a background thread. More...
 
virtual void CallOnForegroundThread (v8::Isolate *isolate, Task *task) OVERRIDE
 Schedules a task to be invoked on a foreground thread wrt a specific |isolate|. More...
 
- Public Member Functions inherited from v8::Platform
virtual ~Platform ()
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (DefaultPlatform)
 

Private Attributes

base::Mutex lock_
 
bool initialized_
 
int thread_pool_size_
 
std::vector< WorkerThread * > thread_pool_
 
TaskQueue queue_
 
std::map< v8::Isolate *, std::queue< Task * > > main_thread_queue_
 

Static Private Attributes

static const int kMaxThreadPoolSize = 4
 

Additional Inherited Members

- Public Types inherited from v8::Platform
enum  ExpectedRuntime { kShortRunningTask , kLongRunningTask }
 This enum is used to indicate whether a task is potentially long running, or causes a long wait. More...
 

Detailed Description

Definition at line 24 of file default-platform.h.

Constructor & Destructor Documentation

◆ DefaultPlatform()

v8::platform::DefaultPlatform::DefaultPlatform ( )

◆ ~DefaultPlatform()

v8::platform::DefaultPlatform::~DefaultPlatform ( )
virtual

Definition at line 39 of file default-platform.cc.

39  {
40  base::LockGuard<base::Mutex> guard(&lock_);
41  queue_.Terminate();
42  if (initialized_) {
43  for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin();
44  i != thread_pool_.end(); ++i) {
45  delete *i;
46  }
47  }
48  for (std::map<v8::Isolate*, std::queue<Task*> >::iterator i =
49  main_thread_queue_.begin();
50  i != main_thread_queue_.end(); ++i) {
51  while (!i->second.empty()) {
52  delete i->second.front();
53  i->second.pop();
54  }
55  }
56 }
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
std::vector< WorkerThread * > thread_pool_
std::map< v8::Isolate *, std::queue< Task * > > main_thread_queue_
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 map

References initialized_, lock_, main_thread_queue_, map, queue_, v8::platform::TaskQueue::Terminate(), and thread_pool_.

+ Here is the call graph for this function:

Member Function Documentation

◆ CallOnBackgroundThread()

void v8::platform::DefaultPlatform::CallOnBackgroundThread ( Task task,
ExpectedRuntime  expected_runtime 
)
virtual

Schedules a task to be invoked on a background thread.

|expected_runtime| indicates that the task will run a long time. The Platform implementation takes ownership of |task|. There is no guarantee about order of execution of tasks wrt order of scheduling, nor is there a guarantee about the thread the task will be run on.

Implements v8::Platform.

Definition at line 97 of file default-platform.cc.

98  {
100  queue_.Append(task);
101 }
void Append(Task *task)
Definition: task-queue.cc:22

References v8::platform::TaskQueue::Append(), EnsureInitialized(), and queue_.

+ Here is the call graph for this function:

◆ CallOnForegroundThread()

void v8::platform::DefaultPlatform::CallOnForegroundThread ( v8::Isolate isolate,
Task task 
)
virtual

Schedules a task to be invoked on a foreground thread wrt a specific |isolate|.

Tasks posted for the same isolate should be execute in order of scheduling. The definition of "foreground" is opaque to V8.

Implements v8::Platform.

Definition at line 104 of file default-platform.cc.

104  {
105  base::LockGuard<base::Mutex> guard(&lock_);
106  main_thread_queue_[isolate].push(task);
107 }

References lock_, and main_thread_queue_.

Referenced by v8::platform::TEST().

+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::platform::DefaultPlatform::DISALLOW_COPY_AND_ASSIGN ( DefaultPlatform  )
private

◆ EnsureInitialized()

void v8::platform::DefaultPlatform::EnsureInitialized ( )

Definition at line 70 of file default-platform.cc.

70  {
71  base::LockGuard<base::Mutex> guard(&lock_);
72  if (initialized_) return;
73  initialized_ = true;
74 
75  for (int i = 0; i < thread_pool_size_; ++i)
76  thread_pool_.push_back(new WorkerThread(&queue_));
77 }

References initialized_, lock_, queue_, thread_pool_, and thread_pool_size_.

Referenced by CallOnBackgroundThread(), and v8::platform::CreateDefaultPlatform().

+ Here is the caller graph for this function:

◆ PumpMessageLoop()

bool v8::platform::DefaultPlatform::PumpMessageLoop ( v8::Isolate isolate)

Definition at line 80 of file default-platform.cc.

80  {
81  Task* task = NULL;
82  {
83  base::LockGuard<base::Mutex> guard(&lock_);
84  std::map<v8::Isolate*, std::queue<Task*> >::iterator it =
85  main_thread_queue_.find(isolate);
86  if (it == main_thread_queue_.end() || it->second.empty()) {
87  return false;
88  }
89  task = it->second.front();
90  it->second.pop();
91  }
92  task->Run();
93  delete task;
94  return true;
95 }
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 lock_, main_thread_queue_, NULL, and v8::Task::Run().

Referenced by v8::platform::TEST().

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

◆ SetThreadPoolSize()

void v8::platform::DefaultPlatform::SetThreadPoolSize ( int  thread_pool_size)

Definition at line 59 of file default-platform.cc.

59  {
60  base::LockGuard<base::Mutex> guard(&lock_);
61  DCHECK(thread_pool_size >= 0);
62  if (thread_pool_size < 1) {
63  thread_pool_size = base::SysInfo::NumberOfProcessors();
64  }
66  std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1);
67 }
static const int kMaxThreadPoolSize
#define DCHECK(condition)
Definition: logging.h:205
static int min(int a, int b)
Definition: liveedit.cc:273

References DCHECK, kMaxThreadPoolSize, lock_, v8::internal::min(), and thread_pool_size_.

Referenced by v8::platform::CreateDefaultPlatform().

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

Member Data Documentation

◆ initialized_

bool v8::platform::DefaultPlatform::initialized_
private

Definition at line 45 of file default-platform.h.

Referenced by EnsureInitialized(), and ~DefaultPlatform().

◆ kMaxThreadPoolSize

const int v8::platform::DefaultPlatform::kMaxThreadPoolSize = 4
staticprivate

Definition at line 42 of file default-platform.h.

Referenced by SetThreadPoolSize().

◆ lock_

base::Mutex v8::platform::DefaultPlatform::lock_
private

◆ main_thread_queue_

std::map<v8::Isolate*, std::queue<Task*> > v8::platform::DefaultPlatform::main_thread_queue_
private

Definition at line 49 of file default-platform.h.

Referenced by CallOnForegroundThread(), PumpMessageLoop(), and ~DefaultPlatform().

◆ queue_

TaskQueue v8::platform::DefaultPlatform::queue_
private

Definition at line 48 of file default-platform.h.

Referenced by CallOnBackgroundThread(), EnsureInitialized(), and ~DefaultPlatform().

◆ thread_pool_

std::vector<WorkerThread*> v8::platform::DefaultPlatform::thread_pool_
private

Definition at line 47 of file default-platform.h.

Referenced by EnsureInitialized(), and ~DefaultPlatform().

◆ thread_pool_size_

int v8::platform::DefaultPlatform::thread_pool_size_
private

Definition at line 46 of file default-platform.h.

Referenced by EnsureInitialized(), and SetThreadPoolSize().


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