@kungfu-tech/libnode-win32-x64 0.0.0-bootstrap.0 → 22.22.3-kf.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/dist/node/include/acorn_version.h +6 -0
  4. package/dist/node/include/aliased_buffer-inl.h +244 -0
  5. package/dist/node/include/aliased_buffer.h +206 -0
  6. package/dist/node/include/aliased_struct-inl.h +54 -0
  7. package/dist/node/include/aliased_struct.h +63 -0
  8. package/dist/node/include/amaro_version.h +6 -0
  9. package/dist/node/include/async_context_frame.h +33 -0
  10. package/dist/node/include/async_wrap-inl.h +96 -0
  11. package/dist/node/include/async_wrap.h +243 -0
  12. package/dist/node/include/base_object-inl.h +335 -0
  13. package/dist/node/include/base_object.h +342 -0
  14. package/dist/node/include/base_object_types.h +74 -0
  15. package/dist/node/include/blob_serializer_deserializer-inl.h +385 -0
  16. package/dist/node/include/blob_serializer_deserializer.h +132 -0
  17. package/dist/node/include/callback_queue-inl.h +97 -0
  18. package/dist/node/include/callback_queue.h +79 -0
  19. package/dist/node/include/cares_wrap.h +447 -0
  20. package/dist/node/include/cjs_module_lexer_version.h +6 -0
  21. package/dist/node/include/cleanup_queue-inl.h +36 -0
  22. package/dist/node/include/cleanup_queue.h +79 -0
  23. package/dist/node/include/compile_cache.h +104 -0
  24. package/dist/node/include/connect_wrap.h +26 -0
  25. package/dist/node/include/connection_wrap.h +30 -0
  26. package/dist/node/include/cppgc/allocation.h +310 -0
  27. package/dist/node/include/cppgc/common.h +28 -0
  28. package/dist/node/include/cppgc/cross-thread-persistent.h +466 -0
  29. package/dist/node/include/cppgc/custom-space.h +97 -0
  30. package/dist/node/include/cppgc/default-platform.h +67 -0
  31. package/dist/node/include/cppgc/ephemeron-pair.h +30 -0
  32. package/dist/node/include/cppgc/explicit-management.h +100 -0
  33. package/dist/node/include/cppgc/garbage-collected.h +106 -0
  34. package/dist/node/include/cppgc/heap-consistency.h +309 -0
  35. package/dist/node/include/cppgc/heap-handle.h +48 -0
  36. package/dist/node/include/cppgc/heap-state.h +82 -0
  37. package/dist/node/include/cppgc/heap-statistics.h +120 -0
  38. package/dist/node/include/cppgc/heap.h +202 -0
  39. package/dist/node/include/cppgc/internal/api-constants.h +87 -0
  40. package/dist/node/include/cppgc/internal/atomic-entry-flag.h +48 -0
  41. package/dist/node/include/cppgc/internal/base-page-handle.h +45 -0
  42. package/dist/node/include/cppgc/internal/caged-heap-local-data.h +121 -0
  43. package/dist/node/include/cppgc/internal/caged-heap.h +68 -0
  44. package/dist/node/include/cppgc/internal/compiler-specific.h +38 -0
  45. package/dist/node/include/cppgc/internal/finalizer-trait.h +93 -0
  46. package/dist/node/include/cppgc/internal/gc-info.h +148 -0
  47. package/dist/node/include/cppgc/internal/logging.h +50 -0
  48. package/dist/node/include/cppgc/internal/member-storage.h +256 -0
  49. package/dist/node/include/cppgc/internal/name-trait.h +137 -0
  50. package/dist/node/include/cppgc/internal/persistent-node.h +214 -0
  51. package/dist/node/include/cppgc/internal/pointer-policies.h +243 -0
  52. package/dist/node/include/cppgc/internal/write-barrier.h +487 -0
  53. package/dist/node/include/cppgc/liveness-broker.h +78 -0
  54. package/dist/node/include/cppgc/macros.h +35 -0
  55. package/dist/node/include/cppgc/member.h +629 -0
  56. package/dist/node/include/cppgc/name-provider.h +65 -0
  57. package/dist/node/include/cppgc/object-size-trait.h +58 -0
  58. package/dist/node/include/cppgc/persistent.h +377 -0
  59. package/dist/node/include/cppgc/platform.h +163 -0
  60. package/dist/node/include/cppgc/prefinalizer.h +75 -0
  61. package/dist/node/include/cppgc/process-heap-statistics.h +36 -0
  62. package/dist/node/include/cppgc/sentinel-pointer.h +39 -0
  63. package/dist/node/include/cppgc/source-location.h +16 -0
  64. package/dist/node/include/cppgc/testing.h +106 -0
  65. package/dist/node/include/cppgc/trace-trait.h +128 -0
  66. package/dist/node/include/cppgc/type-traits.h +271 -0
  67. package/dist/node/include/cppgc/visitor.h +504 -0
  68. package/dist/node/include/crypto/crypto_aes.h +88 -0
  69. package/dist/node/include/crypto/crypto_bio.h +193 -0
  70. package/dist/node/include/crypto/crypto_cipher.h +293 -0
  71. package/dist/node/include/crypto/crypto_clienthello-inl.h +90 -0
  72. package/dist/node/include/crypto/crypto_clienthello.h +131 -0
  73. package/dist/node/include/crypto/crypto_common.h +64 -0
  74. package/dist/node/include/crypto/crypto_context.h +171 -0
  75. package/dist/node/include/crypto/crypto_dh.h +126 -0
  76. package/dist/node/include/crypto/crypto_dsa.h +52 -0
  77. package/dist/node/include/crypto/crypto_ec.h +164 -0
  78. package/dist/node/include/crypto/crypto_hash.h +91 -0
  79. package/dist/node/include/crypto/crypto_hkdf.h +61 -0
  80. package/dist/node/include/crypto/crypto_hmac.h +92 -0
  81. package/dist/node/include/crypto/crypto_keygen.h +299 -0
  82. package/dist/node/include/crypto/crypto_keys.h +392 -0
  83. package/dist/node/include/crypto/crypto_pbkdf2.h +74 -0
  84. package/dist/node/include/crypto/crypto_random.h +124 -0
  85. package/dist/node/include/crypto/crypto_rsa.h +136 -0
  86. package/dist/node/include/crypto/crypto_scrypt.h +85 -0
  87. package/dist/node/include/crypto/crypto_sig.h +165 -0
  88. package/dist/node/include/crypto/crypto_spkac.h +21 -0
  89. package/dist/node/include/crypto/crypto_timing.h +20 -0
  90. package/dist/node/include/crypto/crypto_tls.h +305 -0
  91. package/dist/node/include/crypto/crypto_util.h +725 -0
  92. package/dist/node/include/crypto/crypto_x509.h +140 -0
  93. package/dist/node/include/dataqueue/queue.h +306 -0
  94. package/dist/node/include/debug_utils-inl.h +278 -0
  95. package/dist/node/include/debug_utils.h +196 -0
  96. package/dist/node/include/diagnosticfilename-inl.h +33 -0
  97. package/dist/node/include/embedded_data.h +17 -0
  98. package/dist/node/include/encoding_binding.h +61 -0
  99. package/dist/node/include/env-inl.h +984 -0
  100. package/dist/node/include/env.h +1287 -0
  101. package/dist/node/include/env_properties.h +540 -0
  102. package/dist/node/include/handle_wrap.h +123 -0
  103. package/dist/node/include/histogram-inl.h +107 -0
  104. package/dist/node/include/histogram.h +279 -0
  105. package/dist/node/include/inspector/io_agent.h +30 -0
  106. package/dist/node/include/inspector/main_thread_interface.h +116 -0
  107. package/dist/node/include/inspector/network_agent.h +94 -0
  108. package/dist/node/include/inspector/network_inspector.h +45 -0
  109. package/dist/node/include/inspector/network_requests_buffer.h +195 -0
  110. package/dist/node/include/inspector/network_resource_manager.h +29 -0
  111. package/dist/node/include/inspector/node_json.h +24 -0
  112. package/dist/node/include/inspector/node_string.h +101 -0
  113. package/dist/node/include/inspector/protocol_helper.h +27 -0
  114. package/dist/node/include/inspector/runtime_agent.h +41 -0
  115. package/dist/node/include/inspector/target_agent.h +75 -0
  116. package/dist/node/include/inspector/tracing_agent.h +43 -0
  117. package/dist/node/include/inspector/worker_agent.h +40 -0
  118. package/dist/node/include/inspector/worker_inspector.h +124 -0
  119. package/dist/node/include/inspector_agent.h +165 -0
  120. package/dist/node/include/inspector_io.h +78 -0
  121. package/dist/node/include/inspector_profiler.h +149 -0
  122. package/dist/node/include/inspector_socket.h +60 -0
  123. package/dist/node/include/inspector_socket_server.h +110 -0
  124. package/dist/node/include/js_native_api.h +607 -0
  125. package/dist/node/include/js_native_api_types.h +226 -0
  126. package/dist/node/include/js_native_api_v8.h +485 -0
  127. package/dist/node/include/js_native_api_v8_internals.h +45 -0
  128. package/dist/node/include/js_stream.h +52 -0
  129. package/dist/node/include/json_utils.h +172 -0
  130. package/dist/node/include/large_pages/node_large_page.h +34 -0
  131. package/dist/node/include/libplatform/libplatform-export.h +29 -0
  132. package/dist/node/include/libplatform/libplatform.h +112 -0
  133. package/dist/node/include/libplatform/v8-tracing.h +333 -0
  134. package/dist/node/include/memory_tracker-inl.h +359 -0
  135. package/dist/node/include/memory_tracker.h +289 -0
  136. package/dist/node/include/module_wrap.h +216 -0
  137. package/dist/node/include/node.h +1593 -0
  138. package/dist/node/include/node_api.h +265 -0
  139. package/dist/node/include/node_api_internals.h +48 -0
  140. package/dist/node/include/node_api_types.h +56 -0
  141. package/dist/node/include/node_binding.h +161 -0
  142. package/dist/node/include/node_blob.h +159 -0
  143. package/dist/node/include/node_bob-inl.h +36 -0
  144. package/dist/node/include/node_bob.h +107 -0
  145. package/dist/node/include/node_buffer.h +92 -0
  146. package/dist/node/include/node_builtins.h +220 -0
  147. package/dist/node/include/node_config_file.h +46 -0
  148. package/dist/node/include/node_constants.h +82 -0
  149. package/dist/node/include/node_context_data.h +168 -0
  150. package/dist/node/include/node_contextify.h +204 -0
  151. package/dist/node/include/node_crypto.h +56 -0
  152. package/dist/node/include/node_debug.h +30 -0
  153. package/dist/node/include/node_dir.h +52 -0
  154. package/dist/node/include/node_dotenv.h +45 -0
  155. package/dist/node/include/node_errors.h +380 -0
  156. package/dist/node/include/node_exit_code.h +54 -0
  157. package/dist/node/include/node_external_reference.h +165 -0
  158. package/dist/node/include/node_file-inl.h +406 -0
  159. package/dist/node/include/node_file.h +537 -0
  160. package/dist/node/include/node_http2.h +1177 -0
  161. package/dist/node/include/node_http2_state.h +159 -0
  162. package/dist/node/include/node_http_common-inl.h +202 -0
  163. package/dist/node/include/node_http_common.h +535 -0
  164. package/dist/node/include/node_i18n.h +132 -0
  165. package/dist/node/include/node_internals.h +483 -0
  166. package/dist/node/include/node_main_instance.h +67 -0
  167. package/dist/node/include/node_mem-inl.h +113 -0
  168. package/dist/node/include/node_mem.h +45 -0
  169. package/dist/node/include/node_messaging.h +389 -0
  170. package/dist/node/include/node_metadata.h +164 -0
  171. package/dist/node/include/node_modules.h +91 -0
  172. package/dist/node/include/node_mutex.h +323 -0
  173. package/dist/node/include/node_object_wrap.h +132 -0
  174. package/dist/node/include/node_options-inl.h +490 -0
  175. package/dist/node/include/node_options.h +615 -0
  176. package/dist/node/include/node_perf.h +166 -0
  177. package/dist/node/include/node_perf_common.h +102 -0
  178. package/dist/node/include/node_platform.h +238 -0
  179. package/dist/node/include/node_process-inl.h +26 -0
  180. package/dist/node/include/node_process.h +112 -0
  181. package/dist/node/include/node_realm-inl.h +151 -0
  182. package/dist/node/include/node_realm.h +183 -0
  183. package/dist/node/include/node_report.h +43 -0
  184. package/dist/node/include/node_revert.h +82 -0
  185. package/dist/node/include/node_root_certs.h +3520 -0
  186. package/dist/node/include/node_sea.h +74 -0
  187. package/dist/node/include/node_shadow_realm.h +46 -0
  188. package/dist/node/include/node_snapshot_builder.h +57 -0
  189. package/dist/node/include/node_snapshotable.h +174 -0
  190. package/dist/node/include/node_sockaddr-inl.h +257 -0
  191. package/dist/node/include/node_sockaddr.h +394 -0
  192. package/dist/node/include/node_sqlite.h +270 -0
  193. package/dist/node/include/node_stat_watcher.h +73 -0
  194. package/dist/node/include/node_task_runner.h +92 -0
  195. package/dist/node/include/node_threadsafe_cow-inl.h +54 -0
  196. package/dist/node/include/node_threadsafe_cow.h +105 -0
  197. package/dist/node/include/node_union_bytes.h +81 -0
  198. package/dist/node/include/node_url.h +96 -0
  199. package/dist/node/include/node_v8.h +77 -0
  200. package/dist/node/include/node_v8_platform-inl.h +185 -0
  201. package/dist/node/include/node_version.h +110 -0
  202. package/dist/node/include/node_wasi.h +184 -0
  203. package/dist/node/include/node_wasm_web_api.h +55 -0
  204. package/dist/node/include/node_watchdog.h +154 -0
  205. package/dist/node/include/node_webstorage.h +60 -0
  206. package/dist/node/include/node_worker.h +158 -0
  207. package/dist/node/include/path.h +33 -0
  208. package/dist/node/include/permission/addon_permission.h +31 -0
  209. package/dist/node/include/permission/child_process_permission.h +31 -0
  210. package/dist/node/include/permission/fs_permission.h +167 -0
  211. package/dist/node/include/permission/inspector_permission.h +31 -0
  212. package/dist/node/include/permission/permission.h +138 -0
  213. package/dist/node/include/permission/permission_base.h +65 -0
  214. package/dist/node/include/permission/wasi_permission.h +31 -0
  215. package/dist/node/include/permission/worker_permission.h +31 -0
  216. package/dist/node/include/pipe_wrap.h +80 -0
  217. package/dist/node/include/quic/application.h +159 -0
  218. package/dist/node/include/quic/bindingdata.h +272 -0
  219. package/dist/node/include/quic/cid.h +127 -0
  220. package/dist/node/include/quic/data.h +148 -0
  221. package/dist/node/include/quic/defs.h +245 -0
  222. package/dist/node/include/quic/endpoint.h +458 -0
  223. package/dist/node/include/quic/http3.h +15 -0
  224. package/dist/node/include/quic/logstream.h +81 -0
  225. package/dist/node/include/quic/packet.h +152 -0
  226. package/dist/node/include/quic/preferredaddress.h +72 -0
  227. package/dist/node/include/quic/session.h +443 -0
  228. package/dist/node/include/quic/sessionticket.h +108 -0
  229. package/dist/node/include/quic/streams.h +232 -0
  230. package/dist/node/include/quic/tlscontext.h +227 -0
  231. package/dist/node/include/quic/tokens.h +256 -0
  232. package/dist/node/include/quic/transportparams.h +165 -0
  233. package/dist/node/include/req_wrap-inl.h +171 -0
  234. package/dist/node/include/req_wrap.h +77 -0
  235. package/dist/node/include/spawn_sync.h +243 -0
  236. package/dist/node/include/stream_base-inl.h +173 -0
  237. package/dist/node/include/stream_base.h +478 -0
  238. package/dist/node/include/stream_pipe.h +76 -0
  239. package/dist/node/include/stream_wrap.h +132 -0
  240. package/dist/node/include/string_bytes.h +113 -0
  241. package/dist/node/include/string_decoder-inl.h +31 -0
  242. package/dist/node/include/string_decoder.h +49 -0
  243. package/dist/node/include/tcp_wrap.h +105 -0
  244. package/dist/node/include/threadpoolwork-inl.h +70 -0
  245. package/dist/node/include/timer_wrap-inl.h +32 -0
  246. package/dist/node/include/timer_wrap.h +85 -0
  247. package/dist/node/include/timers.h +70 -0
  248. package/dist/node/include/tracing/agent.h +195 -0
  249. package/dist/node/include/tracing/node_trace_buffer.h +83 -0
  250. package/dist/node/include/tracing/node_trace_writer.h +75 -0
  251. package/dist/node/include/tracing/trace_event.h +722 -0
  252. package/dist/node/include/tracing/trace_event_common.h +1109 -0
  253. package/dist/node/include/tracing/traced_value.h +129 -0
  254. package/dist/node/include/tty_wrap.h +65 -0
  255. package/dist/node/include/udp_wrap.h +230 -0
  256. package/dist/node/include/undici_version.h +6 -0
  257. package/dist/node/include/util-inl.h +700 -0
  258. package/dist/node/include/util.h +1021 -0
  259. package/dist/node/include/uv/aix.h +32 -0
  260. package/dist/node/include/uv/bsd.h +34 -0
  261. package/dist/node/include/uv/darwin.h +61 -0
  262. package/dist/node/include/uv/errno.h +483 -0
  263. package/dist/node/include/uv/linux.h +34 -0
  264. package/dist/node/include/uv/os390.h +33 -0
  265. package/dist/node/include/uv/posix.h +31 -0
  266. package/dist/node/include/uv/sunos.h +44 -0
  267. package/dist/node/include/uv/threadpool.h +37 -0
  268. package/dist/node/include/uv/tree.h +521 -0
  269. package/dist/node/include/uv/unix.h +512 -0
  270. package/dist/node/include/uv/version.h +43 -0
  271. package/dist/node/include/uv/win.h +698 -0
  272. package/dist/node/include/uv.h +1990 -0
  273. package/dist/node/include/v8-array-buffer.h +525 -0
  274. package/dist/node/include/v8-callbacks.h +462 -0
  275. package/dist/node/include/v8-container.h +183 -0
  276. package/dist/node/include/v8-context.h +485 -0
  277. package/dist/node/include/v8-cppgc.h +245 -0
  278. package/dist/node/include/v8-data.h +80 -0
  279. package/dist/node/include/v8-date.h +48 -0
  280. package/dist/node/include/v8-debug.h +168 -0
  281. package/dist/node/include/v8-embedder-heap.h +82 -0
  282. package/dist/node/include/v8-embedder-state-scope.h +52 -0
  283. package/dist/node/include/v8-exception.h +223 -0
  284. package/dist/node/include/v8-extension.h +62 -0
  285. package/dist/node/include/v8-external.h +37 -0
  286. package/dist/node/include/v8-fast-api-calls.h +984 -0
  287. package/dist/node/include/v8-forward.h +82 -0
  288. package/dist/node/include/v8-function-callback.h +607 -0
  289. package/dist/node/include/v8-function.h +140 -0
  290. package/dist/node/include/v8-handle-base.h +137 -0
  291. package/dist/node/include/v8-initialization.h +289 -0
  292. package/dist/node/include/v8-inspector-protocol.h +13 -0
  293. package/dist/node/include/v8-inspector.h +419 -0
  294. package/dist/node/include/v8-internal.h +1397 -0
  295. package/dist/node/include/v8-isolate.h +1767 -0
  296. package/dist/node/include/v8-json.h +47 -0
  297. package/dist/node/include/v8-local-handle.h +758 -0
  298. package/dist/node/include/v8-locker.h +138 -0
  299. package/dist/node/include/v8-maybe.h +160 -0
  300. package/dist/node/include/v8-memory-span.h +198 -0
  301. package/dist/node/include/v8-message.h +233 -0
  302. package/dist/node/include/v8-metrics.h +264 -0
  303. package/dist/node/include/v8-microtask-queue.h +157 -0
  304. package/dist/node/include/v8-microtask.h +28 -0
  305. package/dist/node/include/v8-object.h +824 -0
  306. package/dist/node/include/v8-persistent-handle.h +582 -0
  307. package/dist/node/include/v8-platform.h +1358 -0
  308. package/dist/node/include/v8-primitive-object.h +118 -0
  309. package/dist/node/include/v8-primitive.h +877 -0
  310. package/dist/node/include/v8-profiler.h +1302 -0
  311. package/dist/node/include/v8-promise.h +174 -0
  312. package/dist/node/include/v8-proxy.h +50 -0
  313. package/dist/node/include/v8-regexp.h +106 -0
  314. package/dist/node/include/v8-script.h +904 -0
  315. package/dist/node/include/v8-snapshot.h +266 -0
  316. package/dist/node/include/v8-source-location.h +92 -0
  317. package/dist/node/include/v8-statistics.h +238 -0
  318. package/dist/node/include/v8-template.h +1297 -0
  319. package/dist/node/include/v8-traced-handle.h +432 -0
  320. package/dist/node/include/v8-typed-array.h +390 -0
  321. package/dist/node/include/v8-unwinder-state.h +31 -0
  322. package/dist/node/include/v8-unwinder.h +132 -0
  323. package/dist/node/include/v8-util.h +665 -0
  324. package/dist/node/include/v8-value-serializer-version.h +24 -0
  325. package/dist/node/include/v8-value-serializer.h +316 -0
  326. package/dist/node/include/v8-value.h +655 -0
  327. package/dist/node/include/v8-version-string.h +38 -0
  328. package/dist/node/include/v8-version.h +20 -0
  329. package/dist/node/include/v8-wasm-trap-handler-posix.h +31 -0
  330. package/dist/node/include/v8-wasm-trap-handler-win.h +28 -0
  331. package/dist/node/include/v8-wasm.h +201 -0
  332. package/dist/node/include/v8-weak-callback-info.h +80 -0
  333. package/dist/node/include/v8.h +88 -0
  334. package/dist/node/include/v8config.h +981 -0
  335. package/dist/node/include/zlib_version.h +6 -0
  336. package/dist/node/libnode.dll +0 -0
  337. package/dist/node/libnode.lib +0 -0
  338. package/dist/node/libnodebuildinfo.json +10 -0
  339. package/dist/node/link_node.lib +0 -0
  340. package/dist/node/link_node.node +0 -0
  341. package/index.js +5 -0
  342. package/libnode.release.json +8 -0
  343. package/package.json +29 -1
@@ -0,0 +1,1358 @@
1
+ // Copyright 2013 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_V8_PLATFORM_H_
6
+ #define V8_V8_PLATFORM_H_
7
+
8
+ #include <math.h>
9
+ #include <stddef.h>
10
+ #include <stdint.h>
11
+ #include <stdlib.h> // For abort.
12
+
13
+ #include <memory>
14
+ #include <string>
15
+
16
+ #include "v8-source-location.h" // NOLINT(build/include_directory)
17
+ #include "v8config.h" // NOLINT(build/include_directory)
18
+
19
+ namespace v8 {
20
+
21
+ class Isolate;
22
+
23
+ // Valid priorities supported by the task scheduling infrastructure.
24
+ enum class TaskPriority : uint8_t {
25
+ /**
26
+ * Best effort tasks are not critical for performance of the application. The
27
+ * platform implementation should preempt such tasks if higher priority tasks
28
+ * arrive.
29
+ */
30
+ kBestEffort,
31
+ /**
32
+ * User visible tasks are long running background tasks that will
33
+ * improve performance and memory usage of the application upon completion.
34
+ * Example: background compilation and garbage collection.
35
+ */
36
+ kUserVisible,
37
+ /**
38
+ * User blocking tasks are highest priority tasks that block the execution
39
+ * thread (e.g. major garbage collection). They must be finished as soon as
40
+ * possible.
41
+ */
42
+ kUserBlocking,
43
+ kMaxPriority = kUserBlocking
44
+ };
45
+
46
+ /**
47
+ * A Task represents a unit of work.
48
+ */
49
+ class Task {
50
+ public:
51
+ virtual ~Task() = default;
52
+
53
+ virtual void Run() = 0;
54
+ };
55
+
56
+ /**
57
+ * An IdleTask represents a unit of work to be performed in idle time.
58
+ * The Run method is invoked with an argument that specifies the deadline in
59
+ * seconds returned by MonotonicallyIncreasingTime().
60
+ * The idle task is expected to complete by this deadline.
61
+ */
62
+ class IdleTask {
63
+ public:
64
+ virtual ~IdleTask() = default;
65
+ virtual void Run(double deadline_in_seconds) = 0;
66
+ };
67
+
68
+ /**
69
+ * A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to
70
+ * post tasks after the isolate gets destructed, but these tasks may not get
71
+ * executed anymore. All tasks posted to a given TaskRunner will be invoked in
72
+ * sequence. Tasks can be posted from any thread.
73
+ */
74
+ class TaskRunner {
75
+ public:
76
+ /**
77
+ * Schedules a task to be invoked by this TaskRunner. The TaskRunner
78
+ * implementation takes ownership of |task|.
79
+ *
80
+ * Embedders should override PostTaskImpl instead of this.
81
+ */
82
+ virtual void PostTask(std::unique_ptr<Task> task) {
83
+ PostTaskImpl(std::move(task), SourceLocation::Current());
84
+ }
85
+
86
+ /**
87
+ * Schedules a task to be invoked by this TaskRunner. The TaskRunner
88
+ * implementation takes ownership of |task|. The |task| cannot be nested
89
+ * within other task executions.
90
+ *
91
+ * Tasks which shouldn't be interleaved with JS execution must be posted with
92
+ * |PostNonNestableTask| or |PostNonNestableDelayedTask|. This is because the
93
+ * embedder may process tasks in a callback which is called during JS
94
+ * execution.
95
+ *
96
+ * In particular, tasks which execute JS must be non-nestable, since JS
97
+ * execution is not allowed to nest.
98
+ *
99
+ * Requires that |TaskRunner::NonNestableTasksEnabled()| is true.
100
+ *
101
+ * Embedders should override PostNonNestableTaskImpl instead of this.
102
+ */
103
+ virtual void PostNonNestableTask(std::unique_ptr<Task> task) {
104
+ PostNonNestableTaskImpl(std::move(task), SourceLocation::Current());
105
+ }
106
+
107
+ /**
108
+ * Schedules a task to be invoked by this TaskRunner. The task is scheduled
109
+ * after the given number of seconds |delay_in_seconds|. The TaskRunner
110
+ * implementation takes ownership of |task|.
111
+ *
112
+ * Embedders should override PostDelayedTaskImpl instead of this.
113
+ */
114
+ virtual void PostDelayedTask(std::unique_ptr<Task> task,
115
+ double delay_in_seconds) {
116
+ PostDelayedTaskImpl(std::move(task), delay_in_seconds,
117
+ SourceLocation::Current());
118
+ }
119
+
120
+ /**
121
+ * Schedules a task to be invoked by this TaskRunner. The task is scheduled
122
+ * after the given number of seconds |delay_in_seconds|. The TaskRunner
123
+ * implementation takes ownership of |task|. The |task| cannot be nested
124
+ * within other task executions.
125
+ *
126
+ * Tasks which shouldn't be interleaved with JS execution must be posted with
127
+ * |PostNonNestableTask| or |PostNonNestableDelayedTask|. This is because the
128
+ * embedder may process tasks in a callback which is called during JS
129
+ * execution.
130
+ *
131
+ * In particular, tasks which execute JS must be non-nestable, since JS
132
+ * execution is not allowed to nest.
133
+ *
134
+ * Requires that |TaskRunner::NonNestableDelayedTasksEnabled()| is true.
135
+ *
136
+ * Embedders should override PostNonNestableDelayedTaskImpl instead of this.
137
+ */
138
+ virtual void PostNonNestableDelayedTask(std::unique_ptr<Task> task,
139
+ double delay_in_seconds) {
140
+ PostNonNestableDelayedTaskImpl(std::move(task), delay_in_seconds,
141
+ SourceLocation::Current());
142
+ }
143
+
144
+ /**
145
+ * Schedules an idle task to be invoked by this TaskRunner. The task is
146
+ * scheduled when the embedder is idle. Requires that
147
+ * |TaskRunner::IdleTasksEnabled()| is true. Idle tasks may be reordered
148
+ * relative to other task types and may be starved for an arbitrarily long
149
+ * time if no idle time is available. The TaskRunner implementation takes
150
+ * ownership of |task|.
151
+ *
152
+ * Embedders should override PostIdleTaskImpl instead of this.
153
+ */
154
+ virtual void PostIdleTask(std::unique_ptr<IdleTask> task) {
155
+ PostIdleTaskImpl(std::move(task), SourceLocation::Current());
156
+ }
157
+
158
+ /**
159
+ * Returns true if idle tasks are enabled for this TaskRunner.
160
+ */
161
+ virtual bool IdleTasksEnabled() = 0;
162
+
163
+ /**
164
+ * Returns true if non-nestable tasks are enabled for this TaskRunner.
165
+ */
166
+ virtual bool NonNestableTasksEnabled() const { return false; }
167
+
168
+ /**
169
+ * Returns true if non-nestable delayed tasks are enabled for this TaskRunner.
170
+ */
171
+ virtual bool NonNestableDelayedTasksEnabled() const { return false; }
172
+
173
+ TaskRunner() = default;
174
+ virtual ~TaskRunner() = default;
175
+
176
+ TaskRunner(const TaskRunner&) = delete;
177
+ TaskRunner& operator=(const TaskRunner&) = delete;
178
+
179
+ protected:
180
+ /**
181
+ * Implementation of above methods with an additional `location` argument.
182
+ */
183
+ virtual void PostTaskImpl(std::unique_ptr<Task> task,
184
+ const SourceLocation& location) {}
185
+ virtual void PostNonNestableTaskImpl(std::unique_ptr<Task> task,
186
+ const SourceLocation& location) {}
187
+ virtual void PostDelayedTaskImpl(std::unique_ptr<Task> task,
188
+ double delay_in_seconds,
189
+ const SourceLocation& location) {}
190
+ virtual void PostNonNestableDelayedTaskImpl(std::unique_ptr<Task> task,
191
+ double delay_in_seconds,
192
+ const SourceLocation& location) {}
193
+ virtual void PostIdleTaskImpl(std::unique_ptr<IdleTask> task,
194
+ const SourceLocation& location) {}
195
+ };
196
+
197
+ /**
198
+ * Delegate that's passed to Job's worker task, providing an entry point to
199
+ * communicate with the scheduler.
200
+ */
201
+ class JobDelegate {
202
+ public:
203
+ /**
204
+ * Returns true if this thread *must* return from the worker task on the
205
+ * current thread ASAP. Workers should periodically invoke ShouldYield (or
206
+ * YieldIfNeeded()) as often as is reasonable.
207
+ * After this method returned true, ShouldYield must not be called again.
208
+ */
209
+ virtual bool ShouldYield() = 0;
210
+
211
+ /**
212
+ * Notifies the scheduler that max concurrency was increased, and the number
213
+ * of worker should be adjusted accordingly. See Platform::PostJob() for more
214
+ * details.
215
+ */
216
+ virtual void NotifyConcurrencyIncrease() = 0;
217
+
218
+ /**
219
+ * Returns a task_id unique among threads currently running this job, such
220
+ * that GetTaskId() < worker count. To achieve this, the same task_id may be
221
+ * reused by a different thread after a worker_task returns.
222
+ */
223
+ virtual uint8_t GetTaskId() = 0;
224
+
225
+ /**
226
+ * Returns true if the current task is called from the thread currently
227
+ * running JobHandle::Join().
228
+ */
229
+ virtual bool IsJoiningThread() const = 0;
230
+ };
231
+
232
+ /**
233
+ * Handle returned when posting a Job. Provides methods to control execution of
234
+ * the posted Job.
235
+ */
236
+ class JobHandle {
237
+ public:
238
+ virtual ~JobHandle() = default;
239
+
240
+ /**
241
+ * Notifies the scheduler that max concurrency was increased, and the number
242
+ * of worker should be adjusted accordingly. See Platform::PostJob() for more
243
+ * details.
244
+ */
245
+ virtual void NotifyConcurrencyIncrease() = 0;
246
+
247
+ /**
248
+ * Contributes to the job on this thread. Doesn't return until all tasks have
249
+ * completed and max concurrency becomes 0. When Join() is called and max
250
+ * concurrency reaches 0, it should not increase again. This also promotes
251
+ * this Job's priority to be at least as high as the calling thread's
252
+ * priority.
253
+ */
254
+ virtual void Join() = 0;
255
+
256
+ /**
257
+ * Forces all existing workers to yield ASAP. Waits until they have all
258
+ * returned from the Job's callback before returning.
259
+ */
260
+ virtual void Cancel() = 0;
261
+
262
+ /*
263
+ * Forces all existing workers to yield ASAP but doesn’t wait for them.
264
+ * Warning, this is dangerous if the Job's callback is bound to or has access
265
+ * to state which may be deleted after this call.
266
+ */
267
+ virtual void CancelAndDetach() = 0;
268
+
269
+ /**
270
+ * Returns true if there's any work pending or any worker running.
271
+ */
272
+ virtual bool IsActive() = 0;
273
+
274
+ /**
275
+ * Returns true if associated with a Job and other methods may be called.
276
+ * Returns false after Join() or Cancel() was called. This may return true
277
+ * even if no workers are running and IsCompleted() returns true
278
+ */
279
+ virtual bool IsValid() = 0;
280
+
281
+ /**
282
+ * Returns true if job priority can be changed.
283
+ */
284
+ virtual bool UpdatePriorityEnabled() const { return false; }
285
+
286
+ /**
287
+ * Update this Job's priority.
288
+ */
289
+ virtual void UpdatePriority(TaskPriority new_priority) {}
290
+ };
291
+
292
+ /**
293
+ * A JobTask represents work to run in parallel from Platform::PostJob().
294
+ */
295
+ class JobTask {
296
+ public:
297
+ virtual ~JobTask() = default;
298
+
299
+ virtual void Run(JobDelegate* delegate) = 0;
300
+
301
+ /**
302
+ * Controls the maximum number of threads calling Run() concurrently, given
303
+ * the number of threads currently assigned to this job and executing Run().
304
+ * Run() is only invoked if the number of threads previously running Run() was
305
+ * less than the value returned. In general, this should return the latest
306
+ * number of incomplete work items (smallest unit of work) left to process,
307
+ * including items that are currently in progress. |worker_count| is the
308
+ * number of threads currently assigned to this job which some callers may
309
+ * need to determine their return value. Since GetMaxConcurrency() is a leaf
310
+ * function, it must not call back any JobHandle methods.
311
+ */
312
+ virtual size_t GetMaxConcurrency(size_t worker_count) const = 0;
313
+ };
314
+
315
+ /**
316
+ * A "blocking call" refers to any call that causes the calling thread to wait
317
+ * off-CPU. It includes but is not limited to calls that wait on synchronous
318
+ * file I/O operations: read or write a file from disk, interact with a pipe or
319
+ * a socket, rename or delete a file, enumerate files in a directory, etc.
320
+ * Acquiring a low contention lock is not considered a blocking call.
321
+ */
322
+
323
+ /**
324
+ * BlockingType indicates the likelihood that a blocking call will actually
325
+ * block.
326
+ */
327
+ enum class BlockingType {
328
+ // The call might block (e.g. file I/O that might hit in memory cache).
329
+ kMayBlock,
330
+ // The call will definitely block (e.g. cache already checked and now pinging
331
+ // server synchronously).
332
+ kWillBlock
333
+ };
334
+
335
+ /**
336
+ * This class is instantiated with CreateBlockingScope() in every scope where a
337
+ * blocking call is made and serves as a precise annotation of the scope that
338
+ * may/will block. May be implemented by an embedder to adjust the thread count.
339
+ * CPU usage should be minimal within that scope. ScopedBlockingCalls can be
340
+ * nested.
341
+ */
342
+ class ScopedBlockingCall {
343
+ public:
344
+ virtual ~ScopedBlockingCall() = default;
345
+ };
346
+
347
+ /**
348
+ * The interface represents complex arguments to trace events.
349
+ */
350
+ class ConvertableToTraceFormat {
351
+ public:
352
+ virtual ~ConvertableToTraceFormat() = default;
353
+
354
+ /**
355
+ * Append the class info to the provided |out| string. The appended
356
+ * data must be a valid JSON object. Strings must be properly quoted, and
357
+ * escaped. There is no processing applied to the content after it is
358
+ * appended.
359
+ */
360
+ virtual void AppendAsTraceFormat(std::string* out) const = 0;
361
+ };
362
+
363
+ /**
364
+ * V8 Tracing controller.
365
+ *
366
+ * Can be implemented by an embedder to record trace events from V8.
367
+ *
368
+ * Will become obsolete in Perfetto SDK build (v8_use_perfetto = true).
369
+ */
370
+ class TracingController {
371
+ public:
372
+ virtual ~TracingController() = default;
373
+
374
+ // In Perfetto mode, trace events are written using Perfetto's Track Event
375
+ // API directly without going through the embedder. However, it is still
376
+ // possible to observe tracing being enabled and disabled.
377
+ #if !defined(V8_USE_PERFETTO)
378
+ /**
379
+ * Called by TRACE_EVENT* macros, don't call this directly.
380
+ * The name parameter is a category group for example:
381
+ * TRACE_EVENT0("v8,parse", "V8.Parse")
382
+ * The pointer returned points to a value with zero or more of the bits
383
+ * defined in CategoryGroupEnabledFlags.
384
+ **/
385
+ virtual const uint8_t* GetCategoryGroupEnabled(const char* name) {
386
+ static uint8_t no = 0;
387
+ return &no;
388
+ }
389
+
390
+ /**
391
+ * Adds a trace event to the platform tracing system. These function calls are
392
+ * usually the result of a TRACE_* macro from trace_event_common.h when
393
+ * tracing and the category of the particular trace are enabled. It is not
394
+ * advisable to call these functions on their own; they are really only meant
395
+ * to be used by the trace macros. The returned handle can be used by
396
+ * UpdateTraceEventDuration to update the duration of COMPLETE events.
397
+ */
398
+ virtual uint64_t AddTraceEvent(
399
+ char phase, const uint8_t* category_enabled_flag, const char* name,
400
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
401
+ const char** arg_names, const uint8_t* arg_types,
402
+ const uint64_t* arg_values,
403
+ std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
404
+ unsigned int flags) {
405
+ return 0;
406
+ }
407
+ virtual uint64_t AddTraceEventWithTimestamp(
408
+ char phase, const uint8_t* category_enabled_flag, const char* name,
409
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
410
+ const char** arg_names, const uint8_t* arg_types,
411
+ const uint64_t* arg_values,
412
+ std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
413
+ unsigned int flags, int64_t timestamp) {
414
+ return 0;
415
+ }
416
+
417
+ /**
418
+ * Sets the duration field of a COMPLETE trace event. It must be called with
419
+ * the handle returned from AddTraceEvent().
420
+ **/
421
+ virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
422
+ const char* name, uint64_t handle) {}
423
+ #endif // !defined(V8_USE_PERFETTO)
424
+
425
+ class TraceStateObserver {
426
+ public:
427
+ virtual ~TraceStateObserver() = default;
428
+ virtual void OnTraceEnabled() = 0;
429
+ virtual void OnTraceDisabled() = 0;
430
+ };
431
+
432
+ /**
433
+ * Adds tracing state change observer.
434
+ * Does nothing in Perfetto SDK build (v8_use_perfetto = true).
435
+ */
436
+ virtual void AddTraceStateObserver(TraceStateObserver*) {}
437
+
438
+ /**
439
+ * Removes tracing state change observer.
440
+ * Does nothing in Perfetto SDK build (v8_use_perfetto = true).
441
+ */
442
+ virtual void RemoveTraceStateObserver(TraceStateObserver*) {}
443
+ };
444
+
445
+ /**
446
+ * A V8 memory page allocator.
447
+ *
448
+ * Can be implemented by an embedder to manage large host OS allocations.
449
+ */
450
+ class PageAllocator {
451
+ public:
452
+ virtual ~PageAllocator() = default;
453
+
454
+ /**
455
+ * Gets the page granularity for AllocatePages and FreePages. Addresses and
456
+ * lengths for those calls should be multiples of AllocatePageSize().
457
+ */
458
+ virtual size_t AllocatePageSize() = 0;
459
+
460
+ /**
461
+ * Gets the page granularity for SetPermissions and ReleasePages. Addresses
462
+ * and lengths for those calls should be multiples of CommitPageSize().
463
+ */
464
+ virtual size_t CommitPageSize() = 0;
465
+
466
+ /**
467
+ * Sets the random seed so that GetRandomMmapAddr() will generate repeatable
468
+ * sequences of random mmap addresses.
469
+ */
470
+ virtual void SetRandomMmapSeed(int64_t seed) = 0;
471
+
472
+ /**
473
+ * Returns a randomized address, suitable for memory allocation under ASLR.
474
+ * The address will be aligned to AllocatePageSize.
475
+ */
476
+ virtual void* GetRandomMmapAddr() = 0;
477
+
478
+ /**
479
+ * Memory permissions.
480
+ */
481
+ enum Permission {
482
+ kNoAccess,
483
+ kRead,
484
+ kReadWrite,
485
+ kReadWriteExecute,
486
+ kReadExecute,
487
+ // Set this when reserving memory that will later require kReadWriteExecute
488
+ // permissions. The resulting behavior is platform-specific, currently
489
+ // this is used to set the MAP_JIT flag on Apple Silicon.
490
+ // TODO(jkummerow): Remove this when Wasm has a platform-independent
491
+ // w^x implementation.
492
+ // TODO(saelo): Remove this once all JIT pages are allocated through the
493
+ // VirtualAddressSpace API.
494
+ kNoAccessWillJitLater
495
+ };
496
+
497
+ /**
498
+ * Allocates memory in range with the given alignment and permission.
499
+ */
500
+ virtual void* AllocatePages(void* address, size_t length, size_t alignment,
501
+ Permission permissions) = 0;
502
+
503
+ /**
504
+ * Frees memory in a range that was allocated by a call to AllocatePages.
505
+ */
506
+ virtual bool FreePages(void* address, size_t length) = 0;
507
+
508
+ /**
509
+ * Releases memory in a range that was allocated by a call to AllocatePages.
510
+ */
511
+ virtual bool ReleasePages(void* address, size_t length,
512
+ size_t new_length) = 0;
513
+
514
+ /**
515
+ * Sets permissions on pages in an allocated range.
516
+ */
517
+ virtual bool SetPermissions(void* address, size_t length,
518
+ Permission permissions) = 0;
519
+
520
+ /**
521
+ * Recommits discarded pages in the given range with given permissions.
522
+ * Discarded pages must be recommitted with their original permissions
523
+ * before they are used again.
524
+ */
525
+ virtual bool RecommitPages(void* address, size_t length,
526
+ Permission permissions) {
527
+ // TODO(v8:12797): make it pure once it's implemented on Chromium side.
528
+ return false;
529
+ }
530
+
531
+ /**
532
+ * Frees memory in the given [address, address + size) range. address and size
533
+ * should be operating system page-aligned. The next write to this
534
+ * memory area brings the memory transparently back. This should be treated as
535
+ * a hint to the OS that the pages are no longer needed. It does not guarantee
536
+ * that the pages will be discarded immediately or at all.
537
+ */
538
+ virtual bool DiscardSystemPages(void* address, size_t size) { return true; }
539
+
540
+ /**
541
+ * Decommits any wired memory pages in the given range, allowing the OS to
542
+ * reclaim them, and marks the region as inacessible (kNoAccess). The address
543
+ * range stays reserved and can be accessed again later by changing its
544
+ * permissions. However, in that case the memory content is guaranteed to be
545
+ * zero-initialized again. The memory must have been previously allocated by a
546
+ * call to AllocatePages. Returns true on success, false otherwise.
547
+ */
548
+ virtual bool DecommitPages(void* address, size_t size) = 0;
549
+
550
+ /**
551
+ * INTERNAL ONLY: This interface has not been stabilised and may change
552
+ * without notice from one release to another without being deprecated first.
553
+ */
554
+ class SharedMemoryMapping {
555
+ public:
556
+ // Implementations are expected to free the shared memory mapping in the
557
+ // destructor.
558
+ virtual ~SharedMemoryMapping() = default;
559
+ virtual void* GetMemory() const = 0;
560
+ };
561
+
562
+ /**
563
+ * INTERNAL ONLY: This interface has not been stabilised and may change
564
+ * without notice from one release to another without being deprecated first.
565
+ */
566
+ class SharedMemory {
567
+ public:
568
+ // Implementations are expected to free the shared memory in the destructor.
569
+ virtual ~SharedMemory() = default;
570
+ virtual std::unique_ptr<SharedMemoryMapping> RemapTo(
571
+ void* new_address) const = 0;
572
+ virtual void* GetMemory() const = 0;
573
+ virtual size_t GetSize() const = 0;
574
+ };
575
+
576
+ /**
577
+ * INTERNAL ONLY: This interface has not been stabilised and may change
578
+ * without notice from one release to another without being deprecated first.
579
+ *
580
+ * Reserve pages at a fixed address returning whether the reservation is
581
+ * possible. The reserved memory is detached from the PageAllocator and so
582
+ * should not be freed by it. It's intended for use with
583
+ * SharedMemory::RemapTo, where ~SharedMemoryMapping would free the memory.
584
+ */
585
+ virtual bool ReserveForSharedMemoryMapping(void* address, size_t size) {
586
+ return false;
587
+ }
588
+
589
+ /**
590
+ * INTERNAL ONLY: This interface has not been stabilised and may change
591
+ * without notice from one release to another without being deprecated first.
592
+ *
593
+ * Allocates shared memory pages. Not all PageAllocators need support this and
594
+ * so this method need not be overridden.
595
+ * Allocates a new read-only shared memory region of size |length| and copies
596
+ * the memory at |original_address| into it.
597
+ */
598
+ virtual std::unique_ptr<SharedMemory> AllocateSharedPages(
599
+ size_t length, const void* original_address) {
600
+ return {};
601
+ }
602
+
603
+ /**
604
+ * INTERNAL ONLY: This interface has not been stabilised and may change
605
+ * without notice from one release to another without being deprecated first.
606
+ *
607
+ * If not overridden and changed to return true, V8 will not attempt to call
608
+ * AllocateSharedPages or RemapSharedPages. If overridden, AllocateSharedPages
609
+ * and RemapSharedPages must also be overridden.
610
+ */
611
+ virtual bool CanAllocateSharedPages() { return false; }
612
+ };
613
+
614
+ /**
615
+ * An allocator that uses per-thread permissions to protect the memory.
616
+ *
617
+ * The implementation is platform/hardware specific, e.g. using pkeys on x64.
618
+ *
619
+ * INTERNAL ONLY: This interface has not been stabilised and may change
620
+ * without notice from one release to another without being deprecated first.
621
+ */
622
+ class ThreadIsolatedAllocator {
623
+ public:
624
+ virtual ~ThreadIsolatedAllocator() = default;
625
+
626
+ virtual void* Allocate(size_t size) = 0;
627
+
628
+ virtual void Free(void* object) = 0;
629
+
630
+ enum class Type {
631
+ kPkey,
632
+ };
633
+
634
+ virtual Type Type() const = 0;
635
+
636
+ /**
637
+ * Return the pkey used to implement the thread isolation if Type == kPkey.
638
+ */
639
+ virtual int Pkey() const { return -1; }
640
+
641
+ /**
642
+ * Per-thread permissions can be reset on signal handler entry. Even reading
643
+ * ThreadIsolated memory will segfault in that case.
644
+ * Call this function on signal handler entry to ensure that read permissions
645
+ * are restored.
646
+ */
647
+ static void SetDefaultPermissionsForSignalHandler();
648
+ };
649
+
650
+ // Opaque type representing a handle to a shared memory region.
651
+ using PlatformSharedMemoryHandle = intptr_t;
652
+ static constexpr PlatformSharedMemoryHandle kInvalidSharedMemoryHandle = -1;
653
+
654
+ // Conversion routines from the platform-dependent shared memory identifiers
655
+ // into the opaque PlatformSharedMemoryHandle type. These use the underlying
656
+ // types (e.g. unsigned int) instead of the typedef'd ones (e.g. mach_port_t)
657
+ // to avoid pulling in large OS header files into this header file. Instead,
658
+ // the users of these routines are expected to include the respecitve OS
659
+ // headers in addition to this one.
660
+ #if V8_OS_DARWIN
661
+ // Convert between a shared memory handle and a mach_port_t referencing a memory
662
+ // entry object.
663
+ inline PlatformSharedMemoryHandle SharedMemoryHandleFromMachMemoryEntry(
664
+ unsigned int port) {
665
+ return static_cast<PlatformSharedMemoryHandle>(port);
666
+ }
667
+ inline unsigned int MachMemoryEntryFromSharedMemoryHandle(
668
+ PlatformSharedMemoryHandle handle) {
669
+ return static_cast<unsigned int>(handle);
670
+ }
671
+ #elif V8_OS_FUCHSIA
672
+ // Convert between a shared memory handle and a zx_handle_t to a VMO.
673
+ inline PlatformSharedMemoryHandle SharedMemoryHandleFromVMO(uint32_t handle) {
674
+ return static_cast<PlatformSharedMemoryHandle>(handle);
675
+ }
676
+ inline uint32_t VMOFromSharedMemoryHandle(PlatformSharedMemoryHandle handle) {
677
+ return static_cast<uint32_t>(handle);
678
+ }
679
+ #elif V8_OS_WIN
680
+ // Convert between a shared memory handle and a Windows HANDLE to a file mapping
681
+ // object.
682
+ inline PlatformSharedMemoryHandle SharedMemoryHandleFromFileMapping(
683
+ void* handle) {
684
+ return reinterpret_cast<PlatformSharedMemoryHandle>(handle);
685
+ }
686
+ inline void* FileMappingFromSharedMemoryHandle(
687
+ PlatformSharedMemoryHandle handle) {
688
+ return reinterpret_cast<void*>(handle);
689
+ }
690
+ #else
691
+ // Convert between a shared memory handle and a file descriptor.
692
+ inline PlatformSharedMemoryHandle SharedMemoryHandleFromFileDescriptor(int fd) {
693
+ return static_cast<PlatformSharedMemoryHandle>(fd);
694
+ }
695
+ inline int FileDescriptorFromSharedMemoryHandle(
696
+ PlatformSharedMemoryHandle handle) {
697
+ return static_cast<int>(handle);
698
+ }
699
+ #endif
700
+
701
+ /**
702
+ * Possible permissions for memory pages.
703
+ */
704
+ enum class PagePermissions {
705
+ kNoAccess,
706
+ kRead,
707
+ kReadWrite,
708
+ kReadWriteExecute,
709
+ kReadExecute,
710
+ };
711
+
712
+ /**
713
+ * Class to manage a virtual memory address space.
714
+ *
715
+ * This class represents a contiguous region of virtual address space in which
716
+ * sub-spaces and (private or shared) memory pages can be allocated, freed, and
717
+ * modified. This interface is meant to eventually replace the PageAllocator
718
+ * interface, and can be used as an alternative in the meantime.
719
+ *
720
+ * This API is not yet stable and may change without notice!
721
+ */
722
+ class VirtualAddressSpace {
723
+ public:
724
+ using Address = uintptr_t;
725
+
726
+ VirtualAddressSpace(size_t page_size, size_t allocation_granularity,
727
+ Address base, size_t size,
728
+ PagePermissions max_page_permissions)
729
+ : page_size_(page_size),
730
+ allocation_granularity_(allocation_granularity),
731
+ base_(base),
732
+ size_(size),
733
+ max_page_permissions_(max_page_permissions) {}
734
+
735
+ virtual ~VirtualAddressSpace() = default;
736
+
737
+ /**
738
+ * The page size used inside this space. Guaranteed to be a power of two.
739
+ * Used as granularity for all page-related operations except for allocation,
740
+ * which use the allocation_granularity(), see below.
741
+ *
742
+ * \returns the page size in bytes.
743
+ */
744
+ size_t page_size() const { return page_size_; }
745
+
746
+ /**
747
+ * The granularity of page allocations and, by extension, of subspace
748
+ * allocations. This is guaranteed to be a power of two and a multiple of the
749
+ * page_size(). In practice, this is equal to the page size on most OSes, but
750
+ * on Windows it is usually 64KB, while the page size is 4KB.
751
+ *
752
+ * \returns the allocation granularity in bytes.
753
+ */
754
+ size_t allocation_granularity() const { return allocation_granularity_; }
755
+
756
+ /**
757
+ * The base address of the address space managed by this instance.
758
+ *
759
+ * \returns the base address of this address space.
760
+ */
761
+ Address base() const { return base_; }
762
+
763
+ /**
764
+ * The size of the address space managed by this instance.
765
+ *
766
+ * \returns the size of this address space in bytes.
767
+ */
768
+ size_t size() const { return size_; }
769
+
770
+ /**
771
+ * The maximum page permissions that pages allocated inside this space can
772
+ * obtain.
773
+ *
774
+ * \returns the maximum page permissions.
775
+ */
776
+ PagePermissions max_page_permissions() const { return max_page_permissions_; }
777
+
778
+ /**
779
+ * Whether the |address| is inside the address space managed by this instance.
780
+ *
781
+ * \returns true if it is inside the address space, false if not.
782
+ */
783
+ bool Contains(Address address) const {
784
+ return (address >= base()) && (address < base() + size());
785
+ }
786
+
787
+ /**
788
+ * Sets the random seed so that GetRandomPageAddress() will generate
789
+ * repeatable sequences of random addresses.
790
+ *
791
+ * \param The seed for the PRNG.
792
+ */
793
+ virtual void SetRandomSeed(int64_t seed) = 0;
794
+
795
+ /**
796
+ * Returns a random address inside this address space, suitable for page
797
+ * allocations hints.
798
+ *
799
+ * \returns a random address aligned to allocation_granularity().
800
+ */
801
+ virtual Address RandomPageAddress() = 0;
802
+
803
+ /**
804
+ * Allocates private memory pages with the given alignment and permissions.
805
+ *
806
+ * \param hint If nonzero, the allocation is attempted to be placed at the
807
+ * given address first. If that fails, the allocation is attempted to be
808
+ * placed elsewhere, possibly nearby, but that is not guaranteed. Specifying
809
+ * zero for the hint always causes this function to choose a random address.
810
+ * The hint, if specified, must be aligned to the specified alignment.
811
+ *
812
+ * \param size The size of the allocation in bytes. Must be a multiple of the
813
+ * allocation_granularity().
814
+ *
815
+ * \param alignment The alignment of the allocation in bytes. Must be a
816
+ * multiple of the allocation_granularity() and should be a power of two.
817
+ *
818
+ * \param permissions The page permissions of the newly allocated pages.
819
+ *
820
+ * \returns the start address of the allocated pages on success, zero on
821
+ * failure.
822
+ */
823
+ static constexpr Address kNoHint = 0;
824
+ virtual V8_WARN_UNUSED_RESULT Address
825
+ AllocatePages(Address hint, size_t size, size_t alignment,
826
+ PagePermissions permissions) = 0;
827
+
828
+ /**
829
+ * Frees previously allocated pages.
830
+ *
831
+ * This function will terminate the process on failure as this implies a bug
832
+ * in the client. As such, there is no return value.
833
+ *
834
+ * \param address The start address of the pages to free. This address must
835
+ * have been obtained through a call to AllocatePages.
836
+ *
837
+ * \param size The size in bytes of the region to free. This must match the
838
+ * size passed to AllocatePages when the pages were allocated.
839
+ */
840
+ virtual void FreePages(Address address, size_t size) = 0;
841
+
842
+ /**
843
+ * Sets permissions of all allocated pages in the given range.
844
+ *
845
+ * This operation can fail due to OOM, in which case false is returned. If
846
+ * the operation fails for a reason other than OOM, this function will
847
+ * terminate the process as this implies a bug in the client.
848
+ *
849
+ * \param address The start address of the range. Must be aligned to
850
+ * page_size().
851
+ *
852
+ * \param size The size in bytes of the range. Must be a multiple
853
+ * of page_size().
854
+ *
855
+ * \param permissions The new permissions for the range.
856
+ *
857
+ * \returns true on success, false on OOM.
858
+ */
859
+ virtual V8_WARN_UNUSED_RESULT bool SetPagePermissions(
860
+ Address address, size_t size, PagePermissions permissions) = 0;
861
+
862
+ /**
863
+ * Creates a guard region at the specified address.
864
+ *
865
+ * Guard regions are guaranteed to cause a fault when accessed and generally
866
+ * do not count towards any memory consumption limits. Further, allocating
867
+ * guard regions can usually not fail in subspaces if the region does not
868
+ * overlap with another region, subspace, or page allocation.
869
+ *
870
+ * \param address The start address of the guard region. Must be aligned to
871
+ * the allocation_granularity().
872
+ *
873
+ * \param size The size of the guard region in bytes. Must be a multiple of
874
+ * the allocation_granularity().
875
+ *
876
+ * \returns true on success, false otherwise.
877
+ */
878
+ virtual V8_WARN_UNUSED_RESULT bool AllocateGuardRegion(Address address,
879
+ size_t size) = 0;
880
+
881
+ /**
882
+ * Frees an existing guard region.
883
+ *
884
+ * This function will terminate the process on failure as this implies a bug
885
+ * in the client. As such, there is no return value.
886
+ *
887
+ * \param address The start address of the guard region to free. This address
888
+ * must have previously been used as address parameter in a successful
889
+ * invocation of AllocateGuardRegion.
890
+ *
891
+ * \param size The size in bytes of the guard region to free. This must match
892
+ * the size passed to AllocateGuardRegion when the region was created.
893
+ */
894
+ virtual void FreeGuardRegion(Address address, size_t size) = 0;
895
+
896
+ /**
897
+ * Allocates shared memory pages with the given permissions.
898
+ *
899
+ * \param hint Placement hint. See AllocatePages.
900
+ *
901
+ * \param size The size of the allocation in bytes. Must be a multiple of the
902
+ * allocation_granularity().
903
+ *
904
+ * \param permissions The page permissions of the newly allocated pages.
905
+ *
906
+ * \param handle A platform-specific handle to a shared memory object. See
907
+ * the SharedMemoryHandleFromX routines above for ways to obtain these.
908
+ *
909
+ * \param offset The offset in the shared memory object at which the mapping
910
+ * should start. Must be a multiple of the allocation_granularity().
911
+ *
912
+ * \returns the start address of the allocated pages on success, zero on
913
+ * failure.
914
+ */
915
+ virtual V8_WARN_UNUSED_RESULT Address
916
+ AllocateSharedPages(Address hint, size_t size, PagePermissions permissions,
917
+ PlatformSharedMemoryHandle handle, uint64_t offset) = 0;
918
+
919
+ /**
920
+ * Frees previously allocated shared pages.
921
+ *
922
+ * This function will terminate the process on failure as this implies a bug
923
+ * in the client. As such, there is no return value.
924
+ *
925
+ * \param address The start address of the pages to free. This address must
926
+ * have been obtained through a call to AllocateSharedPages.
927
+ *
928
+ * \param size The size in bytes of the region to free. This must match the
929
+ * size passed to AllocateSharedPages when the pages were allocated.
930
+ */
931
+ virtual void FreeSharedPages(Address address, size_t size) = 0;
932
+
933
+ /**
934
+ * Whether this instance can allocate subspaces or not.
935
+ *
936
+ * \returns true if subspaces can be allocated, false if not.
937
+ */
938
+ virtual bool CanAllocateSubspaces() = 0;
939
+
940
+ /*
941
+ * Allocate a subspace.
942
+ *
943
+ * The address space of a subspace stays reserved in the parent space for the
944
+ * lifetime of the subspace. As such, it is guaranteed that page allocations
945
+ * on the parent space cannot end up inside a subspace.
946
+ *
947
+ * \param hint Hints where the subspace should be allocated. See
948
+ * AllocatePages() for more details.
949
+ *
950
+ * \param size The size in bytes of the subspace. Must be a multiple of the
951
+ * allocation_granularity().
952
+ *
953
+ * \param alignment The alignment of the subspace in bytes. Must be a multiple
954
+ * of the allocation_granularity() and should be a power of two.
955
+ *
956
+ * \param max_page_permissions The maximum permissions that pages allocated in
957
+ * the subspace can obtain.
958
+ *
959
+ * \returns a new subspace or nullptr on failure.
960
+ */
961
+ virtual std::unique_ptr<VirtualAddressSpace> AllocateSubspace(
962
+ Address hint, size_t size, size_t alignment,
963
+ PagePermissions max_page_permissions) = 0;
964
+
965
+ //
966
+ // TODO(v8) maybe refactor the methods below before stabilizing the API. For
967
+ // example by combining them into some form of page operation method that
968
+ // takes a command enum as parameter.
969
+ //
970
+
971
+ /**
972
+ * Recommits discarded pages in the given range with given permissions.
973
+ * Discarded pages must be recommitted with their original permissions
974
+ * before they are used again.
975
+ *
976
+ * \param address The start address of the range. Must be aligned to
977
+ * page_size().
978
+ *
979
+ * \param size The size in bytes of the range. Must be a multiple
980
+ * of page_size().
981
+ *
982
+ * \param permissions The permissions for the range that the pages must have.
983
+ *
984
+ * \returns true on success, false otherwise.
985
+ */
986
+ virtual V8_WARN_UNUSED_RESULT bool RecommitPages(
987
+ Address address, size_t size, PagePermissions permissions) = 0;
988
+
989
+ /**
990
+ * Frees memory in the given [address, address + size) range. address and
991
+ * size should be aligned to the page_size(). The next write to this memory
992
+ * area brings the memory transparently back. This should be treated as a
993
+ * hint to the OS that the pages are no longer needed. It does not guarantee
994
+ * that the pages will be discarded immediately or at all.
995
+ *
996
+ * \returns true on success, false otherwise. Since this method is only a
997
+ * hint, a successful invocation does not imply that pages have been removed.
998
+ */
999
+ virtual V8_WARN_UNUSED_RESULT bool DiscardSystemPages(Address address,
1000
+ size_t size) {
1001
+ return true;
1002
+ }
1003
+ /**
1004
+ * Decommits any wired memory pages in the given range, allowing the OS to
1005
+ * reclaim them, and marks the region as inacessible (kNoAccess). The address
1006
+ * range stays reserved and can be accessed again later by changing its
1007
+ * permissions. However, in that case the memory content is guaranteed to be
1008
+ * zero-initialized again. The memory must have been previously allocated by a
1009
+ * call to AllocatePages.
1010
+ *
1011
+ * \returns true on success, false otherwise.
1012
+ */
1013
+ virtual V8_WARN_UNUSED_RESULT bool DecommitPages(Address address,
1014
+ size_t size) = 0;
1015
+
1016
+ private:
1017
+ const size_t page_size_;
1018
+ const size_t allocation_granularity_;
1019
+ const Address base_;
1020
+ const size_t size_;
1021
+ const PagePermissions max_page_permissions_;
1022
+ };
1023
+
1024
+ /**
1025
+ * V8 Allocator used for allocating zone backings.
1026
+ */
1027
+ class ZoneBackingAllocator {
1028
+ public:
1029
+ using MallocFn = void* (*)(size_t);
1030
+ using FreeFn = void (*)(void*);
1031
+
1032
+ virtual MallocFn GetMallocFn() const { return ::malloc; }
1033
+ virtual FreeFn GetFreeFn() const { return ::free; }
1034
+ };
1035
+
1036
+ /**
1037
+ * Observer used by V8 to notify the embedder about entering/leaving sections
1038
+ * with high throughput of malloc/free operations.
1039
+ */
1040
+ class HighAllocationThroughputObserver {
1041
+ public:
1042
+ virtual void EnterSection() {}
1043
+ virtual void LeaveSection() {}
1044
+ };
1045
+
1046
+ /**
1047
+ * V8 Platform abstraction layer.
1048
+ *
1049
+ * The embedder has to provide an implementation of this interface before
1050
+ * initializing the rest of V8.
1051
+ */
1052
+ class Platform {
1053
+ public:
1054
+ virtual ~Platform() = default;
1055
+
1056
+ /**
1057
+ * Allows the embedder to manage memory page allocations.
1058
+ * Returning nullptr will cause V8 to use the default page allocator.
1059
+ */
1060
+ virtual PageAllocator* GetPageAllocator() = 0;
1061
+
1062
+ /**
1063
+ * Allows the embedder to provide an allocator that uses per-thread memory
1064
+ * permissions to protect allocations.
1065
+ * Returning nullptr will cause V8 to disable protections that rely on this
1066
+ * feature.
1067
+ */
1068
+ virtual ThreadIsolatedAllocator* GetThreadIsolatedAllocator() {
1069
+ return nullptr;
1070
+ }
1071
+
1072
+ /**
1073
+ * Allows the embedder to specify a custom allocator used for zones.
1074
+ */
1075
+ virtual ZoneBackingAllocator* GetZoneBackingAllocator() {
1076
+ static ZoneBackingAllocator default_allocator;
1077
+ return &default_allocator;
1078
+ }
1079
+
1080
+ /**
1081
+ * Enables the embedder to respond in cases where V8 can't allocate large
1082
+ * blocks of memory. V8 retries the failed allocation once after calling this
1083
+ * method. On success, execution continues; otherwise V8 exits with a fatal
1084
+ * error.
1085
+ * Embedder overrides of this function must NOT call back into V8.
1086
+ */
1087
+ virtual void OnCriticalMemoryPressure() {}
1088
+
1089
+ /**
1090
+ * Gets the max number of worker threads that may be used to execute
1091
+ * concurrent work scheduled for any single TaskPriority by
1092
+ * Call(BlockingTask)OnWorkerThread() or PostJob(). This can be used to
1093
+ * estimate the number of tasks a work package should be split into. A return
1094
+ * value of 0 means that there are no worker threads available. Note that a
1095
+ * value of 0 won't prohibit V8 from posting tasks using |CallOnWorkerThread|.
1096
+ */
1097
+ virtual int NumberOfWorkerThreads() = 0;
1098
+
1099
+ /**
1100
+ * Returns a TaskRunner which can be used to post a task on the foreground.
1101
+ * The TaskRunner's NonNestableTasksEnabled() must be true. This function
1102
+ * should only be called from a foreground thread.
1103
+ * TODO(chromium:1448758): Deprecate once |GetForegroundTaskRunner(Isolate*,
1104
+ * TaskPriority)| is ready.
1105
+ */
1106
+ virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
1107
+ Isolate* isolate) {
1108
+ return GetForegroundTaskRunner(isolate, TaskPriority::kUserBlocking);
1109
+ }
1110
+
1111
+ /**
1112
+ * Returns a TaskRunner with a specific |priority| which can be used to post a
1113
+ * task on the foreground thread. The TaskRunner's NonNestableTasksEnabled()
1114
+ * must be true. This function should only be called from a foreground thread.
1115
+ * TODO(chromium:1448758): Make pure virtual once embedders implement it.
1116
+ */
1117
+ virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
1118
+ Isolate* isolate, TaskPriority priority) {
1119
+ return nullptr;
1120
+ }
1121
+
1122
+ /**
1123
+ * Schedules a task to be invoked on a worker thread.
1124
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1125
+ * CallOnWorkerThread().
1126
+ */
1127
+ void CallOnWorkerThread(
1128
+ std::unique_ptr<Task> task,
1129
+ const SourceLocation& location = SourceLocation::Current()) {
1130
+ PostTaskOnWorkerThreadImpl(TaskPriority::kUserVisible, std::move(task),
1131
+ location);
1132
+ }
1133
+
1134
+ /**
1135
+ * Schedules a task that blocks the main thread to be invoked with
1136
+ * high-priority on a worker thread.
1137
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1138
+ * CallBlockingTaskOnWorkerThread().
1139
+ */
1140
+ void CallBlockingTaskOnWorkerThread(
1141
+ std::unique_ptr<Task> task,
1142
+ const SourceLocation& location = SourceLocation::Current()) {
1143
+ // Embedders may optionally override this to process these tasks in a high
1144
+ // priority pool.
1145
+ PostTaskOnWorkerThreadImpl(TaskPriority::kUserBlocking, std::move(task),
1146
+ location);
1147
+ }
1148
+
1149
+ /**
1150
+ * Schedules a task to be invoked with low-priority on a worker thread.
1151
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1152
+ * CallLowPriorityTaskOnWorkerThread().
1153
+ */
1154
+ void CallLowPriorityTaskOnWorkerThread(
1155
+ std::unique_ptr<Task> task,
1156
+ const SourceLocation& location = SourceLocation::Current()) {
1157
+ // Embedders may optionally override this to process these tasks in a low
1158
+ // priority pool.
1159
+ PostTaskOnWorkerThreadImpl(TaskPriority::kBestEffort, std::move(task),
1160
+ location);
1161
+ }
1162
+
1163
+ /**
1164
+ * Schedules a task to be invoked on a worker thread after |delay_in_seconds|
1165
+ * expires.
1166
+ * Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of
1167
+ * CallDelayedOnWorkerThread().
1168
+ */
1169
+ void CallDelayedOnWorkerThread(
1170
+ std::unique_ptr<Task> task, double delay_in_seconds,
1171
+ const SourceLocation& location = SourceLocation::Current()) {
1172
+ PostDelayedTaskOnWorkerThreadImpl(TaskPriority::kUserVisible,
1173
+ std::move(task), delay_in_seconds,
1174
+ location);
1175
+ }
1176
+
1177
+ /**
1178
+ * Returns true if idle tasks are enabled for the given |isolate|.
1179
+ */
1180
+ virtual bool IdleTasksEnabled(Isolate* isolate) { return false; }
1181
+
1182
+ /**
1183
+ * Posts |job_task| to run in parallel. Returns a JobHandle associated with
1184
+ * the Job, which can be joined or canceled.
1185
+ * This avoids degenerate cases:
1186
+ * - Calling CallOnWorkerThread() for each work item, causing significant
1187
+ * overhead.
1188
+ * - Fixed number of CallOnWorkerThread() calls that split the work and might
1189
+ * run for a long time. This is problematic when many components post
1190
+ * "num cores" tasks and all expect to use all the cores. In these cases,
1191
+ * the scheduler lacks context to be fair to multiple same-priority requests
1192
+ * and/or ability to request lower priority work to yield when high priority
1193
+ * work comes in.
1194
+ * A canonical implementation of |job_task| looks like:
1195
+ * class MyJobTask : public JobTask {
1196
+ * public:
1197
+ * MyJobTask(...) : worker_queue_(...) {}
1198
+ * // JobTask:
1199
+ * void Run(JobDelegate* delegate) override {
1200
+ * while (!delegate->ShouldYield()) {
1201
+ * // Smallest unit of work.
1202
+ * auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
1203
+ * if (!work_item) return;
1204
+ * ProcessWork(work_item);
1205
+ * }
1206
+ * }
1207
+ *
1208
+ * size_t GetMaxConcurrency() const override {
1209
+ * return worker_queue_.GetSize(); // Thread safe.
1210
+ * }
1211
+ * };
1212
+ * auto handle = PostJob(TaskPriority::kUserVisible,
1213
+ * std::make_unique<MyJobTask>(...));
1214
+ * handle->Join();
1215
+ *
1216
+ * PostJob() and methods of the returned JobHandle/JobDelegate, must never be
1217
+ * called while holding a lock that could be acquired by JobTask::Run or
1218
+ * JobTask::GetMaxConcurrency -- that could result in a deadlock. This is
1219
+ * because [1] JobTask::GetMaxConcurrency may be invoked while holding
1220
+ * internal lock (A), hence JobTask::GetMaxConcurrency can only use a lock (B)
1221
+ * if that lock is *never* held while calling back into JobHandle from any
1222
+ * thread (A=>B/B=>A deadlock) and [2] JobTask::Run or
1223
+ * JobTask::GetMaxConcurrency may be invoked synchronously from JobHandle
1224
+ * (B=>JobHandle::foo=>B deadlock).
1225
+ * Embedders should override CreateJobImpl() instead of PostJob().
1226
+ */
1227
+ std::unique_ptr<JobHandle> PostJob(
1228
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1229
+ const SourceLocation& location = SourceLocation::Current()) {
1230
+ auto handle = CreateJob(priority, std::move(job_task), location);
1231
+ handle->NotifyConcurrencyIncrease();
1232
+ return handle;
1233
+ }
1234
+
1235
+ /**
1236
+ * Creates and returns a JobHandle associated with a Job. Unlike PostJob(),
1237
+ * this doesn't immediately schedules |worker_task| to run; the Job is then
1238
+ * scheduled by calling either NotifyConcurrencyIncrease() or Join().
1239
+ *
1240
+ * A sufficient CreateJob() implementation that uses the default Job provided
1241
+ * in libplatform looks like:
1242
+ * std::unique_ptr<JobHandle> CreateJob(
1243
+ * TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
1244
+ * return v8::platform::NewDefaultJobHandle(
1245
+ * this, priority, std::move(job_task), NumberOfWorkerThreads());
1246
+ * }
1247
+ *
1248
+ * Embedders should override CreateJobImpl() instead of CreateJob().
1249
+ */
1250
+ std::unique_ptr<JobHandle> CreateJob(
1251
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1252
+ const SourceLocation& location = SourceLocation::Current()) {
1253
+ return CreateJobImpl(priority, std::move(job_task), location);
1254
+ }
1255
+
1256
+ /**
1257
+ * Instantiates a ScopedBlockingCall to annotate a scope that may/will block.
1258
+ */
1259
+ virtual std::unique_ptr<ScopedBlockingCall> CreateBlockingScope(
1260
+ BlockingType blocking_type) {
1261
+ return nullptr;
1262
+ }
1263
+
1264
+ /**
1265
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
1266
+ * the past. This function is expected to return at least
1267
+ * millisecond-precision values. For this reason,
1268
+ * it is recommended that the fixed point be no further in the past than
1269
+ * the epoch.
1270
+ **/
1271
+ virtual double MonotonicallyIncreasingTime() = 0;
1272
+
1273
+ /**
1274
+ * Current wall-clock time in milliseconds since epoch. Use
1275
+ * CurrentClockTimeMillisHighResolution() when higher precision is
1276
+ * required.
1277
+ */
1278
+ virtual int64_t CurrentClockTimeMilliseconds() {
1279
+ return static_cast<int64_t>(floor(CurrentClockTimeMillis()));
1280
+ }
1281
+
1282
+ /**
1283
+ * This function is deprecated and will be deleted. Use either
1284
+ * CurrentClockTimeMilliseconds() or
1285
+ * CurrentClockTimeMillisecondsHighResolution().
1286
+ */
1287
+ virtual double CurrentClockTimeMillis() = 0;
1288
+
1289
+ /**
1290
+ * Same as CurrentClockTimeMilliseconds(), but with more precision.
1291
+ */
1292
+ virtual double CurrentClockTimeMillisecondsHighResolution() {
1293
+ return CurrentClockTimeMillis();
1294
+ }
1295
+
1296
+ typedef void (*StackTracePrinter)();
1297
+
1298
+ /**
1299
+ * Returns a function pointer that print a stack trace of the current stack
1300
+ * on invocation. Disables printing of the stack trace if nullptr.
1301
+ */
1302
+ virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }
1303
+
1304
+ /**
1305
+ * Returns an instance of a v8::TracingController. This must be non-nullptr.
1306
+ */
1307
+ virtual TracingController* GetTracingController() = 0;
1308
+
1309
+ /**
1310
+ * Tells the embedder to generate and upload a crashdump during an unexpected
1311
+ * but non-critical scenario.
1312
+ */
1313
+ virtual void DumpWithoutCrashing() {}
1314
+
1315
+ /**
1316
+ * Allows the embedder to observe sections with high throughput allocation
1317
+ * operations.
1318
+ */
1319
+ virtual HighAllocationThroughputObserver*
1320
+ GetHighAllocationThroughputObserver() {
1321
+ static HighAllocationThroughputObserver default_observer;
1322
+ return &default_observer;
1323
+ }
1324
+
1325
+ protected:
1326
+ /**
1327
+ * Default implementation of current wall-clock time in milliseconds
1328
+ * since epoch. Useful for implementing |CurrentClockTimeMillis| if
1329
+ * nothing special needed.
1330
+ */
1331
+ V8_EXPORT static double SystemClockTimeMillis();
1332
+
1333
+ /**
1334
+ * Creates and returns a JobHandle associated with a Job.
1335
+ */
1336
+ virtual std::unique_ptr<JobHandle> CreateJobImpl(
1337
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1338
+ const SourceLocation& location) = 0;
1339
+
1340
+ /**
1341
+ * Schedules a task with |priority| to be invoked on a worker thread.
1342
+ */
1343
+ virtual void PostTaskOnWorkerThreadImpl(TaskPriority priority,
1344
+ std::unique_ptr<Task> task,
1345
+ const SourceLocation& location) = 0;
1346
+
1347
+ /**
1348
+ * Schedules a task with |priority| to be invoked on a worker thread after
1349
+ * |delay_in_seconds| expires.
1350
+ */
1351
+ virtual void PostDelayedTaskOnWorkerThreadImpl(
1352
+ TaskPriority priority, std::unique_ptr<Task> task,
1353
+ double delay_in_seconds, const SourceLocation& location) = 0;
1354
+ };
1355
+
1356
+ } // namespace v8
1357
+
1358
+ #endif // V8_V8_PLATFORM_H_