Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
v8::Platform Class Referenceabstract

#include <v8-platform.h>

Public Types

typedef void(* StackTracePrinter) ()
 

Public Member Functions

virtual ~Platform ()=default
 
virtual PageAllocatorGetPageAllocator ()=0
 
virtual ThreadIsolatedAllocatorGetThreadIsolatedAllocator ()
 
virtual void OnCriticalMemoryPressure ()
 
virtual int NumberOfWorkerThreads ()=0
 
std::shared_ptr< v8::TaskRunnerGetForegroundTaskRunner (Isolate *isolate)
 
virtual std::shared_ptr< v8::TaskRunnerGetForegroundTaskRunner (Isolate *isolate, TaskPriority priority)=0
 
void CallOnWorkerThread (std::unique_ptr< Task > task, const SourceLocation &location=SourceLocation::Current())
 
void CallBlockingTaskOnWorkerThread (std::unique_ptr< Task > task, const SourceLocation &location=SourceLocation::Current())
 
void CallLowPriorityTaskOnWorkerThread (std::unique_ptr< Task > task, const SourceLocation &location=SourceLocation::Current())
 
void CallDelayedOnWorkerThread (std::unique_ptr< Task > task, double delay_in_seconds, const SourceLocation &location=SourceLocation::Current())
 
virtual bool IdleTasksEnabled (Isolate *isolate)
 
std::unique_ptr< JobHandlePostJob (TaskPriority priority, std::unique_ptr< JobTask > job_task, const SourceLocation &location=SourceLocation::Current())
 
std::unique_ptr< JobHandleCreateJob (TaskPriority priority, std::unique_ptr< JobTask > job_task, const SourceLocation &location=SourceLocation::Current())
 
virtual std::unique_ptr< ScopedBlockingCallCreateBlockingScope (BlockingType blocking_type)
 
virtual double MonotonicallyIncreasingTime ()=0
 
virtual int64_t CurrentClockTimeMilliseconds ()
 
virtual double CurrentClockTimeMillis ()=0
 
virtual double CurrentClockTimeMillisecondsHighResolution ()
 
virtual StackTracePrinter GetStackTracePrinter ()
 
virtual TracingControllerGetTracingController ()=0
 
virtual void DumpWithoutCrashing ()
 
virtual HighAllocationThroughputObserverGetHighAllocationThroughputObserver ()
 

Protected Member Functions

virtual std::unique_ptr< JobHandleCreateJobImpl (TaskPriority priority, std::unique_ptr< JobTask > job_task, const SourceLocation &location)=0
 
virtual void PostTaskOnWorkerThreadImpl (TaskPriority priority, std::unique_ptr< Task > task, const SourceLocation &location)=0
 
virtual void PostDelayedTaskOnWorkerThreadImpl (TaskPriority priority, std::unique_ptr< Task > task, double delay_in_seconds, const SourceLocation &location)=0
 

Static Protected Member Functions

static double SystemClockTimeMillis ()
 

Detailed Description

V8 Platform abstraction layer.

The embedder has to provide an implementation of this interface before initializing the rest of V8.

Examples
process.cc, and shell.cc.

Member Typedef Documentation

◆ StackTracePrinter

typedef void(* v8::Platform::StackTracePrinter) ()

Constructor & Destructor Documentation

◆ ~Platform()

virtual v8::Platform::~Platform ( )
virtualdefault

Member Function Documentation

◆ CallBlockingTaskOnWorkerThread()

void v8::Platform::CallBlockingTaskOnWorkerThread ( std::unique_ptr< Task task,
const SourceLocation location = SourceLocation::Current() 
)
inline

Schedules a task that blocks the main thread to be invoked with high-priority on a worker thread. Embedders should override PostTaskOnWorkerThreadImpl() instead of CallBlockingTaskOnWorkerThread().

Here is the call graph for this function:

◆ CallDelayedOnWorkerThread()

void v8::Platform::CallDelayedOnWorkerThread ( std::unique_ptr< Task task,
double  delay_in_seconds,
const SourceLocation location = SourceLocation::Current() 
)
inline

Schedules a task to be invoked on a worker thread after |delay_in_seconds| expires. Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of CallDelayedOnWorkerThread().

Here is the call graph for this function:

◆ CallLowPriorityTaskOnWorkerThread()

void v8::Platform::CallLowPriorityTaskOnWorkerThread ( std::unique_ptr< Task task,
const SourceLocation location = SourceLocation::Current() 
)
inline

Schedules a task to be invoked with low-priority on a worker thread. Embedders should override PostTaskOnWorkerThreadImpl() instead of CallLowPriorityTaskOnWorkerThread().

Here is the call graph for this function:

◆ CallOnWorkerThread()

void v8::Platform::CallOnWorkerThread ( std::unique_ptr< Task task,
const SourceLocation location = SourceLocation::Current() 
)
inline

Schedules a task to be invoked on a worker thread. Embedders should override PostTaskOnWorkerThreadImpl() instead of CallOnWorkerThread().

Here is the call graph for this function:

◆ CreateBlockingScope()

virtual std::unique_ptr< ScopedBlockingCall > v8::Platform::CreateBlockingScope ( BlockingType  blocking_type)
inlinevirtual

Instantiates a ScopedBlockingCall to annotate a scope that may/will block.

◆ CreateJob()

std::unique_ptr< JobHandle > v8::Platform::CreateJob ( TaskPriority  priority,
std::unique_ptr< JobTask job_task,
const SourceLocation location = SourceLocation::Current() 
)
inline

Creates and returns a JobHandle associated with a Job. Unlike PostJob(), this doesn't immediately schedules |worker_task| to run; the Job is then scheduled by calling either NotifyConcurrencyIncrease() or Join().

A sufficient CreateJob() implementation that uses the default Job provided in libplatform looks like: std::unique_ptr<JobHandle> CreateJob( TaskPriority priority, std::unique_ptr<JobTask> job_task) override { return v8::platform::NewDefaultJobHandle( this, priority, std::move(job_task), NumberOfWorkerThreads()); }

Embedders should override CreateJobImpl() instead of CreateJob().

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

◆ CreateJobImpl()

virtual std::unique_ptr< JobHandle > v8::Platform::CreateJobImpl ( TaskPriority  priority,
std::unique_ptr< JobTask job_task,
const SourceLocation location 
)
protectedpure virtual

Creates and returns a JobHandle associated with a Job.

Here is the caller graph for this function:

◆ CurrentClockTimeMillis()

virtual double v8::Platform::CurrentClockTimeMillis ( )
pure virtual

This function is deprecated and will be deleted. Use either CurrentClockTimeMilliseconds() or CurrentClockTimeMillisecondsHighResolution().

Here is the caller graph for this function:

◆ CurrentClockTimeMilliseconds()

virtual int64_t v8::Platform::CurrentClockTimeMilliseconds ( )
inlinevirtual

Current wall-clock time in milliseconds since epoch. Use CurrentClockTimeMillisHighResolution() when higher precision is required.

Here is the call graph for this function:

◆ CurrentClockTimeMillisecondsHighResolution()

virtual double v8::Platform::CurrentClockTimeMillisecondsHighResolution ( )
inlinevirtual

Same as CurrentClockTimeMilliseconds(), but with more precision.

Here is the call graph for this function:

◆ DumpWithoutCrashing()

virtual void v8::Platform::DumpWithoutCrashing ( )
inlinevirtual

Tells the embedder to generate and upload a crashdump during an unexpected but non-critical scenario.

◆ GetForegroundTaskRunner() [1/2]

std::shared_ptr< v8::TaskRunner > v8::Platform::GetForegroundTaskRunner ( Isolate isolate)
inline

Returns a TaskRunner which can be used to post a task on the foreground. The TaskRunner's NonNestableTasksEnabled() must be true. This function should only be called from a foreground thread.

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

◆ GetForegroundTaskRunner() [2/2]

virtual std::shared_ptr< v8::TaskRunner > v8::Platform::GetForegroundTaskRunner ( Isolate isolate,
TaskPriority  priority 
)
pure virtual

Returns a TaskRunner with a specific |priority| which can be used to post a task on the foreground thread. The TaskRunner's NonNestableTasksEnabled() must be true. This function should only be called from a foreground thread.

◆ GetHighAllocationThroughputObserver()

virtual HighAllocationThroughputObserver * v8::Platform::GetHighAllocationThroughputObserver ( )
inlinevirtual

Allows the embedder to observe sections with high throughput allocation operations.

◆ GetPageAllocator()

virtual PageAllocator * v8::Platform::GetPageAllocator ( )
pure virtual

Allows the embedder to manage memory page allocations. Returning nullptr will cause V8 to use the default page allocator.

◆ GetStackTracePrinter()

virtual StackTracePrinter v8::Platform::GetStackTracePrinter ( )
inlinevirtual

Returns a function pointer that print a stack trace of the current stack on invocation. Disables printing of the stack trace if nullptr.

◆ GetThreadIsolatedAllocator()

virtual ThreadIsolatedAllocator * v8::Platform::GetThreadIsolatedAllocator ( )
inlinevirtual

Allows the embedder to provide an allocator that uses per-thread memory permissions to protect allocations. Returning nullptr will cause V8 to disable protections that rely on this feature.

◆ GetTracingController()

virtual TracingController * v8::Platform::GetTracingController ( )
pure virtual

Returns an instance of a v8::TracingController. This must be non-nullptr.

◆ IdleTasksEnabled()

virtual bool v8::Platform::IdleTasksEnabled ( Isolate isolate)
inlinevirtual

Returns true if idle tasks are enabled for the given |isolate|.

◆ MonotonicallyIncreasingTime()

virtual double v8::Platform::MonotonicallyIncreasingTime ( )
pure virtual

Monotonically increasing time in seconds from an arbitrary fixed point in the past. This function is expected to return at least millisecond-precision values. For this reason, it is recommended that the fixed point be no further in the past than the epoch.

◆ NumberOfWorkerThreads()

virtual int v8::Platform::NumberOfWorkerThreads ( )
pure virtual

Gets the max number of worker threads that may be used to execute concurrent work scheduled for any single TaskPriority by Call(BlockingTask)OnWorkerThread() or PostJob(). This can be used to estimate the number of tasks a work package should be split into. A return value of 0 means that there are no worker threads available. Note that a value of 0 won't prohibit V8 from posting tasks using |CallOnWorkerThread|.

◆ OnCriticalMemoryPressure()

virtual void v8::Platform::OnCriticalMemoryPressure ( )
inlinevirtual

Enables the embedder to respond in cases where V8 can't allocate large blocks of memory. V8 retries the failed allocation once after calling this method. On success, execution continues; otherwise V8 exits with a fatal error. Embedder overrides of this function must NOT call back into V8.

◆ PostDelayedTaskOnWorkerThreadImpl()

virtual void v8::Platform::PostDelayedTaskOnWorkerThreadImpl ( TaskPriority  priority,
std::unique_ptr< Task task,
double  delay_in_seconds,
const SourceLocation location 
)
protectedpure virtual

Schedules a task with |priority| to be invoked on a worker thread after |delay_in_seconds| expires.

Here is the caller graph for this function:

◆ PostJob()

std::unique_ptr< JobHandle > v8::Platform::PostJob ( TaskPriority  priority,
std::unique_ptr< JobTask job_task,
const SourceLocation location = SourceLocation::Current() 
)
inline

Posts |job_task| to run in parallel. Returns a JobHandle associated with the Job, which can be joined or canceled. This avoids degenerate cases:

  • Calling CallOnWorkerThread() for each work item, causing significant overhead.
  • Fixed number of CallOnWorkerThread() calls that split the work and might run for a long time. This is problematic when many components post "num cores" tasks and all expect to use all the cores. In these cases, the scheduler lacks context to be fair to multiple same-priority requests and/or ability to request lower priority work to yield when high priority work comes in. A canonical implementation of |job_task| looks like: class MyJobTask : public JobTask { public: MyJobTask(...) : worker_queue_(...) {} // JobTask: void Run(JobDelegate* delegate) override { while (!delegate->ShouldYield()) { // Smallest unit of work. auto work_item = worker_queue_.TakeWorkItem(); // Thread safe. if (!work_item) return; ProcessWork(work_item); } }

    size_t GetMaxConcurrency() const override { return worker_queue_.GetSize(); // Thread safe. } }; auto handle = PostJob(TaskPriority::kUserVisible, std::make_unique<MyJobTask>(...)); handle->Join();

PostJob() and methods of the returned JobHandle/JobDelegate, must never be called while holding a lock that could be acquired by JobTask::Run or JobTask::GetMaxConcurrency – that could result in a deadlock. This is because [1] JobTask::GetMaxConcurrency may be invoked while holding internal lock (A), hence JobTask::GetMaxConcurrency can only use a lock (B) if that lock is never held while calling back into JobHandle from any thread (A=>B/B=>A deadlock) and [2] JobTask::Run or JobTask::GetMaxConcurrency may be invoked synchronously from JobHandle (B=>JobHandle::foo=>B deadlock). Embedders should override CreateJobImpl() instead of PostJob().

Here is the call graph for this function:

◆ PostTaskOnWorkerThreadImpl()

virtual void v8::Platform::PostTaskOnWorkerThreadImpl ( TaskPriority  priority,
std::unique_ptr< Task task,
const SourceLocation location 
)
protectedpure virtual

Schedules a task with |priority| to be invoked on a worker thread.

Here is the caller graph for this function:

◆ SystemClockTimeMillis()

static double v8::Platform::SystemClockTimeMillis ( )
staticprotected

Default implementation of current wall-clock time in milliseconds since epoch. Useful for implementing |CurrentClockTimeMillis| if nothing special needed.


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