v8  9.0.257(node16.0.0)
V8 is Google's open source JavaScript engine
libplatform.h
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
6 #define V8_LIBPLATFORM_LIBPLATFORM_H_
7 
8 #include <memory>
9 
10 #include "libplatform/libplatform-export.h"
11 #include "libplatform/v8-tracing.h"
12 #include "v8-platform.h" // NOLINT(build/include_directory)
13 #include "v8config.h" // NOLINT(build/include_directory)
14 
15 namespace v8 {
16 namespace platform {
17 
20 
21 enum class MessageLoopBehavior : bool {
22  kDoNotWait = false,
23  kWaitForWork = true
24 };
25 
26 /**
27  * Returns a new instance of the default v8::Platform implementation.
28  *
29  * The caller will take ownership of the returned pointer. |thread_pool_size|
30  * is the number of worker threads to allocate for background jobs. If a value
31  * of zero is passed, a suitable default based on the current number of
32  * processors online will be chosen.
33  * If |idle_task_support| is enabled then the platform will accept idle
34  * tasks (IdleTasksEnabled will return true) and will rely on the embedder
35  * calling v8::platform::RunIdleTasks to process the idle tasks.
36  * If |tracing_controller| is nullptr, the default platform will create a
37  * v8::platform::TracingController instance and use it.
38  */
40  int thread_pool_size = 0,
41  IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
42  InProcessStackDumping in_process_stack_dumping =
44  std::unique_ptr<v8::TracingController> tracing_controller = {});
45 
46 /**
47  * The same as NewDefaultPlatform but disables the worker thread pool.
48  * It must be used with the --single-threaded V8 flag.
49  */
50 V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform>
52  IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
53  InProcessStackDumping in_process_stack_dumping =
55  std::unique_ptr<v8::TracingController> tracing_controller = {});
56 
57 /**
58  * Returns a new instance of the default v8::JobHandle implementation.
59  *
60  * The job will be executed by spawning up to |num_worker_threads| many worker
61  * threads on the provided |platform| with the given |priority|.
62  */
64  v8::Platform* platform, v8::TaskPriority priority,
65  std::unique_ptr<v8::JobTask> job_task, size_t num_worker_threads);
66 
67 /**
68  * Pumps the message loop for the given isolate.
69  *
70  * The caller has to make sure that this is called from the right thread.
71  * Returns true if a task was executed, and false otherwise. If the call to
72  * PumpMessageLoop is nested within another call to PumpMessageLoop, only
73  * nestable tasks may run. Otherwise, any task may run. Unless requested through
74  * the |behavior| parameter, this call does not block if no task is pending. The
75  * |platform| has to be created using |NewDefaultPlatform|.
76  */
78  v8::Platform* platform, v8::Isolate* isolate,
80 
81 /**
82  * Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
83  *
84  * The caller has to make sure that this is called from the right thread.
85  * This call does not block if no task is pending. The |platform| has to be
86  * created using |NewDefaultPlatform|.
87  */
89  v8::Isolate* isolate,
90  double idle_time_in_seconds);
91 
92 /**
93  * Attempts to set the tracing controller for the given platform.
94  *
95  * The |platform| has to be created using |NewDefaultPlatform|.
96  *
97  */
98 V8_DEPRECATE_SOON("Access the DefaultPlatform directly")
100  v8::Platform* platform,
101  v8::platform::tracing::TracingController* tracing_controller);
102 
103 /**
104  * Notifies the given platform about the Isolate getting deleted soon. Has to be
105  * called for all Isolates which are deleted - unless we're shutting down the
106  * platform.
107  *
108  * The |platform| has to be created using |NewDefaultPlatform|.
109  *
110  */
112  Isolate* isolate);
113 
114 } // namespace platform
115 } // namespace v8
116 
117 #endif // V8_LIBPLATFORM_LIBPLATFORM_H_
V8_DEPRECATE_SOON
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:425
v8::platform::MessageLoopBehavior
MessageLoopBehavior
Definition: libplatform.h:21
v8::platform::InProcessStackDumping::kDisabled
@ kDisabled
v8::platform::InProcessStackDumping::kEnabled
@ kEnabled
v8::platform::MessageLoopBehavior::kDoNotWait
@ kDoNotWait
v8::platform::IdleTaskSupport
IdleTaskSupport
Definition: libplatform.h:18
v8::platform
Definition: libplatform.h:16
v8::platform::PumpMessageLoop
V8_PLATFORM_EXPORT bool PumpMessageLoop(v8::Platform *platform, v8::Isolate *isolate, MessageLoopBehavior behavior=MessageLoopBehavior::kDoNotWait)
v8::TracingController
Definition: v8-platform.h:302
v8::platform::NotifyIsolateShutdown
V8_PLATFORM_EXPORT void NotifyIsolateShutdown(v8::Platform *platform, Isolate *isolate)
v8::Isolate
Definition: v8.h:8450
v8::JobTask
Definition: v8-platform.h:261
v8::platform::SetTracingController
V8_PLATFORM_EXPORT void SetTracingController(v8::Platform *platform, v8::platform::tracing::TracingController *tracing_controller)
v8
Definition: libplatform.h:15
v8::platform::tracing
Definition: v8-tracing.h:31
v8::TaskPriority
TaskPriority
Definition: v8-platform.h:21
v8::platform::RunIdleTasks
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform *platform, v8::Isolate *isolate, double idle_time_in_seconds)
v8::JobHandle
Definition: v8-platform.h:193
v8::Platform
Definition: v8-platform.h:522
V8_PLATFORM_EXPORT
#define V8_PLATFORM_EXPORT
Definition: libplatform-export.h:24
v8::platform::IdleTaskSupport::kEnabled
@ kEnabled
v8::platform::tracing::TracingController
Definition: v8-tracing.h:236
v8::platform::NewSingleThreadedDefaultPlatform
V8_PLATFORM_EXPORT std::unique_ptr< v8::Platform > NewSingleThreadedDefaultPlatform(IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping=InProcessStackDumping::kDisabled, std::unique_ptr< v8::TracingController > tracing_controller={})
v8::platform::NewDefaultJobHandle
V8_PLATFORM_EXPORT std::unique_ptr< v8::JobHandle > NewDefaultJobHandle(v8::Platform *platform, v8::TaskPriority priority, std::unique_ptr< v8::JobTask > job_task, size_t num_worker_threads)
v8::platform::IdleTaskSupport::kDisabled
@ kDisabled
v8::platform::InProcessStackDumping
InProcessStackDumping
Definition: libplatform.h:19
v8::platform::MessageLoopBehavior::kWaitForWork
@ kWaitForWork
v8::platform::NewDefaultPlatform
V8_PLATFORM_EXPORT std::unique_ptr< v8::Platform > NewDefaultPlatform(int thread_pool_size=0, IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping=InProcessStackDumping::kDisabled, std::unique_ptr< v8::TracingController > tracing_controller={})