v8 10.2.154 (node 18.16.0)
V8 is Google's open source JavaScript engine
|
#include <v8-platform.h>
Public Types | |
typedef void(* | StackTracePrinter) () |
Static Protected Member Functions | |
static V8_EXPORT double | SystemClockTimeMillis () |
V8 Platform abstraction layer.
The embedder has to provide an implementation of this interface before initializing the rest of V8.
Definition at line 886 of file v8-platform.h.
typedef void(* StackTracePrinter) () |
Definition at line 1052 of file v8-platform.h.
|
virtualdefault |
|
inlinevirtual |
Schedules a task that blocks the main thread to be invoked with high-priority on a worker thread.
Definition at line 955 of file v8-platform.h.
References Platform::CallOnWorkerThread().
|
pure virtual |
Schedules a task to be invoked on a worker thread after |delay_in_seconds| expires.
|
inlinevirtual |
Schedules a task to be invoked with low-priority on a worker thread.
Definition at line 964 of file v8-platform.h.
References Platform::CallOnWorkerThread().
|
pure virtual |
Schedules a task to be invoked on a worker thread.
Referenced by Platform::CallBlockingTaskOnWorkerThread(), and Platform::CallLowPriorityTaskOnWorkerThread().
|
pure virtual |
Current wall-clock time in milliseconds since epoch. This function is expected to return at least millisecond-precision values.
|
inlinevirtual |
Tells the embedder to generate and upload a crashdump during an unexpected but non-critical scenario.
Definition at line 1069 of file v8-platform.h.
|
pure virtual |
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.
|
inlinevirtual |
Allows the embedder to observe sections with high throughput allocation operations.
Definition at line 1076 of file v8-platform.h.
|
inlinevirtual |
Allows the embedder to manage memory page allocations.
Definition at line 893 of file v8-platform.h.
|
inlinevirtual |
Returns a function pointer that print a stack trace of the current stack on invocation. Disables printing of the stack trace if nullptr.
Definition at line 1058 of file v8-platform.h.
|
pure virtual |
Returns an instance of a v8::TracingController. This must be non-nullptr.
|
inlinevirtual |
Allows the embedder to specify a custom allocator used for zones.
Definition at line 901 of file v8-platform.h.
|
inlinevirtual |
Returns true if idle tasks are enabled for the given |isolate|.
Definition at line 980 of file v8-platform.h.
|
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.
|
pure virtual |
Gets the number of worker threads used by Call(BlockingTask)OnWorkerThread(). 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|.
|
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.
Definition at line 913 of file v8-platform.h.
|
inlinevirtual |
Enables the embedder to respond in cases where V8 can't allocate large memory regions. The |length| parameter is the amount of memory needed. Returns true if memory is now available. Returns false if no memory could be made available. V8 will retry allocations until this method returns false.
Embedder overrides of this function must NOT call back into V8.
Definition at line 927 of file v8-platform.h.
|
pure virtual |
Posts |job_task| to run in parallel. Returns a JobHandle associated with the Job, which can be joined or canceled. This avoids degenerate cases:
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).
A sufficient PostJob() implementation that uses the default Job provided in libplatform looks like: std::unique_ptr<JobHandle> PostJob( TaskPriority priority, std::unique_ptr<JobTask> job_task) override { return v8::platform::NewDefaultJobHandle( this, priority, std::move(job_task), NumberOfWorkerThreads()); }
Default implementation of current wall-clock time in milliseconds since epoch. Useful for implementing |CurrentClockTimeMillis| if nothing special needed.