Skip to content

Commit 32e90c4

Browse files
vmutafovNathanWalker
authored andcommitted
feat: v8_static 10.3.22
1 parent 21de81d commit 32e90c4

File tree

339 files changed

+25252
-73615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

339 files changed

+25252
-73615
lines changed

.gitattributes

Whitespace-only changes.

NativeScript/NativeScript.mm

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Foundation/Foundation.h>
22
#include "NativeScript.h"
3-
#include "inspector/JsV8InspectorClient.h"
3+
// #include "inspector/JsV8InspectorClient.h"
44
#include "runtime/RuntimeConfig.h"
55
#include "runtime/Helpers.h"
66
#include "runtime/Runtime.h"
@@ -45,14 +45,14 @@ - (instancetype)initWithConfig:(Config*)config {
4545
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
4646
printf("Runtime initialization took %llims\n", duration);
4747

48-
if (config.IsDebug) {
49-
Isolate::Scope isolate_scope(isolate);
50-
HandleScope handle_scope(isolate);
51-
v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient(runtime_.get());
52-
inspectorClient->init();
53-
inspectorClient->registerModules();
54-
inspectorClient->connect([config ArgumentsCount], [config Arguments]);
55-
}
48+
// if (config.IsDebug) {
49+
// Isolate::Scope isolate_scope(isolate);
50+
// HandleScope handle_scope(isolate);
51+
// v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient(runtime_.get());
52+
// inspectorClient->init();
53+
// inspectorClient->registerModules();
54+
// inspectorClient->connect([config ArgumentsCount], [config Arguments]);
55+
// }
5656
}
5757

5858
return self;

NativeScript/include/APIDesign.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# The V8 public C++ API
2+
3+
# Overview
4+
5+
The V8 public C++ API aims to support four use cases:
6+
7+
1. Enable applications that embed V8 (called the embedder) to configure and run
8+
one or more instances of V8.
9+
2. Expose ECMAScript-like capabilities to the embedder.
10+
3. Enable the embedder to interact with ECMAScript by exposing API objects.
11+
4. Provide access to the V8 debugger (inspector).
12+
13+
# Configuring and running an instance of V8
14+
15+
V8 requires access to certain OS-level primitives such as the ability to
16+
schedule work on threads, or allocate memory.
17+
18+
The embedder can define how to access those primitives via the v8::Platform
19+
interface. While V8 bundles a basic implementation, embedders are highly
20+
encouraged to implement v8::Platform themselves.
21+
22+
Currently, the v8::ArrayBuffer::Allocator is passed to the v8::Isolate factory
23+
method, however, conceptually it should also be part of the v8::Platform since
24+
all instances of V8 should share one allocator.
25+
26+
Once the v8::Platform is configured, an v8::Isolate can be created. All
27+
further interactions with V8 should explicitly reference the v8::Isolate they
28+
refer to. All API methods should eventually take an v8::Isolate parameter.
29+
30+
When a given instance of V8 is no longer needed, it can be destroyed by
31+
disposing the respective v8::Isolate. If the embedder wishes to free all memory
32+
associated with the v8::Isolate, it has to first clear all global handles
33+
associated with that v8::Isolate.
34+
35+
# ECMAScript-like capabilities
36+
37+
In general, the C++ API shouldn't enable capabilities that aren't available to
38+
scripts running in V8. Experience has shown that it's not possible to maintain
39+
such API methods in the long term. However, capabilities also available to
40+
scripts, i.e., ones that are defined in the ECMAScript standard are there to
41+
stay, and we can safely expose them to embedders.
42+
43+
The C++ API should also be pleasant to use, and not require learning new
44+
paradigms. Similarly to how the API exposed to scripts aims to provide good
45+
ergonomics, we should aim to provide a reasonable developer experience for this
46+
API surface.
47+
48+
ECMAScript makes heavy use of exceptions, however, V8's C++ code doesn't use
49+
C++ exceptions. Therefore, all API methods that can throw exceptions should
50+
indicate so by returning a v8::Maybe&lt;&gt; or v8::MaybeLocal&lt;&gt; result,
51+
and by taking a v8::Local&lt;v8::Context&gt; parameter that indicates in which
52+
context a possible exception should be thrown.
53+
54+
# API objects
55+
56+
V8 allows embedders to define special objects that expose additional
57+
capabilities and APIs to scripts. The most prominent example is exposing the
58+
HTML DOM in Blink. Other examples are e.g. node.js. It is less clear what kind
59+
of capabilities we want to expose via this API surface. As a rule of thumb, we
60+
want to expose operations as defined in the WebIDL and HTML spec: we
61+
assume that those requirements are somewhat stable, and that they are a
62+
superset of the requirements of other embedders including node.js.
63+
64+
Ideally, the API surfaces defined in those specs hook into the ECMAScript spec
65+
which in turn guarantees long-term stability of the API.
66+
67+
# The V8 inspector
68+
69+
All debugging capabilities of V8 should be exposed via the inspector protocol.
70+
The exception to this are profiling features exposed via v8-profiler.h.
71+
Changes to the inspector protocol need to ensure backwards compatibility and
72+
commitment to maintain.

NativeScript/include/DEPS

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include_rules = [
2+
# v8-inspector-protocol.h depends on generated files under include/inspector.
3+
"+inspector",
4+
"+cppgc/common.h",
5+
# Used by v8-cppgc.h to bridge to cppgc.
6+
"+cppgc/custom-space.h",
7+
"+cppgc/heap-statistics.h",
8+
"+cppgc/internal/write-barrier.h",
9+
"+cppgc/visitor.h",
10+
]

NativeScript/include/DIR_METADATA

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Metadata information for this directory.
2+
#
3+
# For more information on DIR_METADATA files, see:
4+
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
5+
#
6+
# For the schema of this file, see Metadata message:
7+
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
8+
9+
monorail {
10+
component: "Blink>JavaScript>API"
11+
}

NativeScript/include/OWNERS

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
4+
5+
6+
7+
8+
per-file *DEPS=file:../COMMON_OWNERS
9+
per-file v8-internal.h=file:../COMMON_OWNERS
10+
11+
per-file v8-debug.h=file:../src/debug/OWNERS
12+
13+
per-file js_protocol.pdl=file:../src/inspector/OWNERS
14+
per-file v8-inspector*=file:../src/inspector/OWNERS
15+
per-file v8-inspector*=file:../src/inspector/OWNERS
16+
17+
# Needed by the auto_tag builder
18+
per-file v8-version.h=v8-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com
19+
20+
# For branch updates:
21+
per-file v8-version.h=file:../INFRA_OWNERS
22+
23+

NativeScript/include/cppgc/DEPS

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include_rules = [
2+
"-include",
3+
"+v8config.h",
4+
"+v8-platform.h",
5+
"+cppgc",
6+
"-src",
7+
"+libplatform/libplatform.h",
8+
]

NativeScript/include/cppgc/OWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+

NativeScript/include/cppgc/README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Oilpan: C++ Garbage Collection
2+
3+
Oilpan is an open-source garbage collection library for C++ that can be used stand-alone or in collaboration with V8's JavaScript garbage collector.
4+
Oilpan implements mark-and-sweep garbage collection (GC) with limited compaction (for a subset of objects).
5+
6+
**Key properties**
7+
8+
- Trace-based garbage collection;
9+
- Incremental and concurrent marking;
10+
- Incremental and concurrent sweeping;
11+
- Precise on-heap memory layout;
12+
- Conservative on-stack memory layout;
13+
- Allows for collection with and without considering stack;
14+
- Non-incremental and non-concurrent compaction for selected spaces;
15+
16+
See the [Hello World](https://chromium.googlesource.com/v8/v8/+/main/samples/cppgc/hello-world.cc) example on how to get started using Oilpan to manage C++ code.
17+
18+
Oilpan follows V8's project organization, see e.g. on how we accept [contributions](https://v8.dev/docs/contribute) and [provide a stable API](https://v8.dev/docs/api).
19+
20+
## Threading model
21+
22+
Oilpan features thread-local garbage collection and assumes heaps are not shared among threads.
23+
In other words, objects are accessed and ultimately reclaimed by the garbage collector on the same thread that allocates them.
24+
This allows Oilpan to run garbage collection in parallel with mutators running in other threads.
25+
26+
References to objects belonging to another thread's heap are modeled using cross-thread roots.
27+
This is even true for on-heap to on-heap references.
28+
29+
## Heap partitioning
30+
31+
Oilpan's heaps are partitioned into spaces.
32+
The space for an object is chosen depending on a number of criteria, e.g.:
33+
34+
- Objects over 64KiB are allocated in a large object space
35+
- Objects can be assigned to a dedicated custom space.
36+
Custom spaces can also be marked as compactable.
37+
- Other objects are allocated in one of the normal page spaces bucketed depending on their size.
38+
39+
## Precise and conservative garbage collection
40+
41+
Oilpan supports two kinds of GCs:
42+
43+
1. **Conservative GC.**
44+
A GC is called conservative when it is executed while the regular native stack is not empty.
45+
In this case, the native stack might contain references to objects in Oilpan's heap, which should be kept alive.
46+
The GC scans the native stack and treats the pointers discovered via the native stack as part of the root set.
47+
This kind of GC is considered imprecise because values on stack other than references may accidentally appear as references to on-heap object, which means these objects will be kept alive despite being in practice unreachable from the application as an actual reference.
48+
49+
2. **Precise GC.**
50+
A precise GC is triggered at the end of an event loop, which is controlled by an embedder via a platform.
51+
At this point, it is guaranteed that there are no on-stack references pointing to Oilpan's heap.
52+
This means there is no risk of confusing other value types with references.
53+
Oilpan has precise knowledge of on-heap object layouts, and so it knows exactly where pointers lie in memory.
54+
Oilpan can just start marking from the regular root set and collect all garbage precisely.
55+
56+
## Atomic, incremental and concurrent garbage collection
57+
58+
Oilpan has three modes of operation:
59+
60+
1. **Atomic GC.**
61+
The entire GC cycle, including all its phases (e.g. see [Marking](#Marking-phase) and [Sweeping](#Sweeping-phase)), are executed back to back in a single pause.
62+
This mode of operation is also known as Stop-The-World (STW) garbage collection.
63+
It results in the most jank (due to a single long pause), but is overall the most efficient (e.g. no need for write barriers).
64+
65+
2. **Incremental GC.**
66+
Garbage collection work is split up into multiple steps which are interleaved with the mutator, i.e. user code chunked into tasks.
67+
Each step is a small chunk of work that is executed either as dedicated tasks between mutator tasks or, as needed, during mutator tasks.
68+
Using incremental GC introduces the need for write barriers that record changes to the object graph so that a consistent state is observed and no objects are accidentally considered dead and reclaimed.
69+
The incremental steps are followed by a smaller atomic pause to finalize garbage collection.
70+
The smaller pause times, due to smaller chunks of work, helps with reducing jank.
71+
72+
3. **Concurrent GC.**
73+
This is the most common type of GC.
74+
It builds on top of incremental GC and offloads much of the garbage collection work away from the mutator thread and on to background threads.
75+
Using concurrent GC allows the mutator thread to spend less time on GC and more on the actual mutator.
76+
77+
## Marking phase
78+
79+
The marking phase consists of the following steps:
80+
81+
1. Mark all objects in the root set.
82+
83+
2. Mark all objects transitively reachable from the root set by calling `Trace()` methods defined on each object.
84+
85+
3. Clear out all weak handles to unreachable objects and run weak callbacks.
86+
87+
The marking phase can be executed atomically in a stop-the-world manner, in which all 3 steps are executed one after the other.
88+
89+
Alternatively, it can also be executed incrementally/concurrently.
90+
With incremental/concurrent marking, step 1 is executed in a short pause after which the mutator regains control.
91+
Step 2 is repeatedly executed in an interleaved manner with the mutator.
92+
When the GC is ready to finalize, i.e. step 2 is (almost) finished, another short pause is triggered in which step 2 is finished and step 3 is performed.
93+
94+
To prevent a user-after-free (UAF) issues it is required for Oilpan to know about all edges in the object graph.
95+
This means that all pointers except on-stack pointers must be wrapped with Oilpan's handles (i.e., Persistent<>, Member<>, WeakMember<>).
96+
Raw pointers to on-heap objects create an edge that Oilpan cannot observe and cause UAF issues
97+
Thus, raw pointers shall not be used to reference on-heap objects (except for raw pointers on native stacks).
98+
99+
## Sweeping phase
100+
101+
The sweeping phase consists of the following steps:
102+
103+
1. Invoke pre-finalizers.
104+
At this point, no destructors have been invoked and no memory has been reclaimed.
105+
Pre-finalizers are allowed to access any other on-heap objects, even those that may get destructed.
106+
107+
2. Sweeping invokes destructors of the dead (unreachable) objects and reclaims memory to be reused by future allocations.
108+
109+
Assumptions should not be made about the order and the timing of their execution.
110+
There is no guarantee on the order in which the destructors are invoked.
111+
That's why destructors must not access any other on-heap objects (which might have already been destructed).
112+
If some destructor unavoidably needs to access other on-heap objects, it will have to be converted to a pre-finalizer.
113+
The pre-finalizer is allowed to access other on-heap objects.
114+
115+
The mutator is resumed before all destructors have ran.
116+
For example, imagine a case where X is a client of Y, and Y holds a list of clients.
117+
If the code relies on X's destructor removing X from the list, there is a risk that Y iterates the list and calls some method of X which may touch other on-heap objects.
118+
This causes a use-after-free.
119+
Care must be taken to make sure that X is explicitly removed from the list before the mutator resumes its execution in a way that doesn't rely on X's destructor (e.g. a pre-finalizer).
120+
121+
Similar to marking, sweeping can be executed in either an atomic stop-the-world manner or incrementally/concurrently.
122+
With incremental/concurrent sweeping, step 2 is interleaved with mutator.
123+
Incremental/concurrent sweeping can be atomically finalized in case it is needed to trigger another GC cycle.
124+
Even with concurrent sweeping, destructors are guaranteed to run on the thread the object has been allocated on to preserve C++ semantics.
125+
126+
Notes:
127+
128+
* Weak processing runs only when the holder object of the WeakMember outlives the pointed object.
129+
If the holder object and the pointed object die at the same time, weak processing doesn't run.
130+
It is wrong to write code assuming that the weak processing always runs.
131+
132+
* Pre-finalizers are heavy because the thread needs to scan all pre-finalizers at each sweeping phase to determine which pre-finalizers should be invoked (the thread needs to invoke pre-finalizers of dead objects).
133+
Adding pre-finalizers to frequently created objects should be avoided.

0 commit comments

Comments
 (0)