Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4e0fad3
src: read extra V8 flags from NODE_V8_FLAGS
maschwenk Nov 12, 2026
ae046d7
deps: V8: scan magic comment values in bulk, don't internalize long ones
maschwenk Nov 12, 2026
9a8cd71
deps: V8: slice long sourceMappingURL values out of the source
maschwenk Nov 12, 2026
c277466
test: cover long inline source map URLs
maschwenk Nov 12, 2026
dedc6b1
build: wire V8 builtins PGO into the gyp build
maschwenk Nov 12, 2026
71822f1
src: add opt-in huge page allocator for the V8 heap
maschwenk Nov 12, 2026
a07b7f6
src: add opt-in remap of executable text to huge pages
maschwenk Nov 12, 2026
6bd9ba1
src: optionally advise large V8 reservations to use huge pages
maschwenk Nov 12, 2026
58ba78b
src: produce the module compile cache after execution
maschwenk Nov 12, 2026
d009823
src: put pointer compression cages on huge pages
maschwenk Nov 12, 2026
4771e00
deps: add V8 hooks for forking a process with a live isolate
maschwenk Nov 12, 2026
8dd694e
deps: fix libuv in children forked from a running loop
maschwenk Nov 12, 2026
7466997
src: let the V8 platform's threads stop and restart around fork(2)
maschwenk Nov 12, 2026
4e23b0e
src,lib: add process.forkSelf()
maschwenk Nov 12, 2026
74afba0
test: add process.forkSelf() tests
maschwenk Nov 12, 2026
264c1bb
src: handle the CA certificate threads and unknown threads in forkSelf()
maschwenk Nov 12, 2026
cc396e4
deps: make V8's fork optimization switchable, reopen perf maps
maschwenk Nov 12, 2026
072d2f5
src: restore fast spawns after forkSelf(), reopen perf maps in children
maschwenk Nov 12, 2026
38945eb
doc: document process.forkSelf()
maschwenk Nov 12, 2026
af8bc23
src: watch SIGCHLD before the first forkSelf() child exists
maschwenk Nov 12, 2026
cff75a2
deps: V8: add --large-objects-at-cage-top
maschwenk Nov 12, 2026
a3dbb1e
test: run the forkSelf() perf map test in a temporary directory
maschwenk Nov 12, 2026
4abb2e7
src: park V8 platform workers for fork instead of letting them exit
maschwenk Nov 12, 2026
c9bdf77
src: keep large objects and sparse regions off cage huge pages
maschwenk Nov 12, 2026
bea1c1b
deps: V8: leave --large-objects-at-cage-top out of the flag hash
maschwenk Nov 12, 2026
6a2ec87
lib: load the forkSelf() module on first use
maschwenk Nov 12, 2026
63b6444
src: wait for the SIGUSR1 watchdog thread to be named
maschwenk Nov 12, 2026
bce6d4f
test: check that forkSelf() refuses while an unknown thread runs
maschwenk Nov 12, 2026
1385179
test: test the compile cache produced after execution
maschwenk Nov 12, 2026
773cd54
doc: document when the module compile cache is produced
maschwenk Nov 12, 2026
e6265bf
src: refresh a sample of accepted compile cache entries
maschwenk Nov 12, 2026
7c23f2a
Merge branch 'smap' into ci-build
maschwenk Nov 12, 2026
5f130fd
Merge branch 'ccache-post-exec' into ci-build
maschwenk Nov 12, 2026
374ed38
Merge branch 'heap-hugepages-cage' into ci-build
maschwenk Nov 12, 2026
64cca9a
Merge branch 'build-flags' into ci-build
maschwenk Nov 12, 2026
21c8ead
Merge branch 'fork-self' into ci-build
maschwenk Nov 12, 2026
1bd2bcc
src: let huge page arenas be inherited by fork
maschwenk Nov 12, 2026
c364940
doc: add the new compile cache variables to the man page
maschwenk Nov 12, 2026
69fe699
Merge remote-tracking branch 'fork/ccache-post-exec' into ci-build
maschwenk Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,22 @@
default=None,
help=f"Disable V8's Maglev compiler. {maglev_enabled_by_default_help}")

parser.add_argument('--v8-enable-builtins-profiling',
action='store_true',
dest='v8_enable_builtins_profiling',
default=None,
help='Instrument the embedded builtins with basic block counters. Run the '
'resulting binary with --turbo-profiling-output=<file> to collect them, '
'then turn them into branch hints with '
'deps/v8/tools/builtins-pgo/get_hints.py.')

parser.add_argument('--v8-builtins-profiling-log-file',
action='store',
dest='v8_builtins_profiling_log_file',
default=None,
help='Branch hints file for the embedded builtins (builtins PGO), as made by '
'deps/v8/tools/builtins-pgo/get_hints.py from a profiling build.')

parser.add_argument('--v8-enable-short-builtin-calls',
action='store_true',
dest='v8_enable_short_builtin_calls',
Expand Down Expand Up @@ -2292,6 +2308,15 @@ def configure_v8(o, configs):
if flavor != 'linux' and options.v8_enable_hugepage:
raise Exception('--v8-enable-hugepage is supported only on linux.')
o['variables']['v8_enable_hugepage'] = 1 if options.v8_enable_hugepage else 0
if options.v8_enable_builtins_profiling and options.v8_builtins_profiling_log_file:
raise Exception('--v8-enable-builtins-profiling and '
'--v8-builtins-profiling-log-file are mutually exclusive.')
o['variables']['v8_enable_builtins_profiling'] = 1 if options.v8_enable_builtins_profiling else 0
if options.v8_builtins_profiling_log_file:
log_file = os.path.abspath(options.v8_builtins_profiling_log_file)
if not os.path.isfile(log_file):
raise Exception(f'Builtins profile not found: {log_file}')
o['variables']['v8_builtins_profiling_log_file'] = log_file
if options.v8_enable_short_builtin_calls or o['variables']['target_arch'] == 'x64':
o['variables']['v8_enable_short_builtin_calls'] = 1
if options.v8_enable_snapshot_compression:
Expand Down
9 changes: 9 additions & 0 deletions deps/uv/src/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ static void init_threads(void) {
static void reset_once(void) {
uv_once_t child_once = UV_ONCE_INIT;
memcpy(&once, &child_once, sizeof(child_once));
/* The worker threads do not exist in the child. Forget them, or
* uv__threadpool_cleanup() (uv_library_shutdown()) would try to join them
* and wait forever. The next uv__work_submit() starts new ones. The array is
* leaked when it was allocated: it is not safe to call free() here.
*/
threads = NULL;
nthreads = 0;
idle_threads = 0;
slow_io_work_running = 0;
}
#endif

Expand Down
43 changes: 41 additions & 2 deletions deps/uv/src/unix/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,21 +654,47 @@ int uv__platform_loop_init(uv_loop_t* loop) {
}


struct uv__invalidate;
static void uv__io_fork_invalidate_events(uv_loop_t* loop);

int uv__io_fork(uv_loop_t* loop) {
int err;
int old_fd;
struct watcher_list* root;

root = uv__inotify_watchers(loop)->rbh_root;

uv__close(loop->backend_fd);
/* fork() may have been called from a callback that uv__io_poll() is
* dispatching. The rest of the events that the parent's epoll_pwait()
* returned are the parent's: don't let the child dispatch them.
*/
uv__io_fork_invalidate_events(loop);

old_fd = loop->backend_fd;
loop->backend_fd = -1;

/* TODO(bnoordhuis) Loses items from the submission and completion rings. */
uv__platform_loop_delete(loop);

err = uv__platform_loop_init(loop);
if (err)
if (err) {
uv__close(old_fd);
return err;
}

/* Give the new epoll instance the old file descriptor number. A
* uv__io_poll() call that is still on the stack (fork() from a callback)
* keeps using the number it read on entry; with a new number, that could
* by then be another loop's epoll instance (another thread's), or any
* other file.
*/
if (dup3(loop->backend_fd, old_fd, O_CLOEXEC) == -1) {
err = UV__ERR(errno);
uv__close(old_fd);
return err;
}
uv__close(loop->backend_fd);
loop->backend_fd = old_fd;

return uv__inotify_fork(loop, root);
}
Expand Down Expand Up @@ -696,6 +722,19 @@ struct uv__invalidate {
};


static void uv__io_fork_invalidate_events(uv_loop_t* loop) {
uv__loop_internal_fields_t* lfields;
struct uv__invalidate* inv;
int i;

lfields = uv__get_internal_fields(loop);
inv = lfields->inv;
if (inv != NULL)
for (i = 0; i < inv->nfds; i++)
inv->events[i].data.fd = -1;
}


void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
uv__loop_internal_fields_t* lfields;
struct uv__invalidate* inv;
Expand Down
54 changes: 54 additions & 0 deletions deps/v8/include/v8-fork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2026 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef INCLUDE_V8_FORK_H_
#define INCLUDE_V8_FORK_H_

#include "v8config.h" // NOLINT(build/include_directory)

namespace v8 {

class Isolate;

/**
* Experimental, for embedders that fork(2) a process with a live isolate.
*
* Reseeds the isolate's random number generator from fresh entropy and resets
* the Math.random() state of every native context of the isolate, so that the
* next Math.random() call in each context starts a new sequence. Without this,
* a forked child produces the same Math.random() sequences as its parent and
* its siblings. Does nothing when --random-seed is set (the embedder asked for
* reproducible sequences). Must be called on the isolate's thread.
*/
V8_EXPORT void ReseedRandomNumberGeneratorsAfterFork(Isolate* isolate);

/**
* Experimental, for embedders that fork(2) a process with a live isolate.
*
* Built with v8_enable_private_mapping_fork_optimization (the Linux default in
* Node.js), V8 marks the memory it maps MADV_DONTFORK, so that fork+exec does
* not copy the page tables of the heap; a forked child then has no heap.
* MakeMappingsForkable() clears that mark on every mapping V8 holds, and new
* mappings are not marked until MakeMappingsUnforkable() marks them all
* again; call that before a fork that is followed by exec. Each call that
* changes the state costs one madvise() per mapping; calls that do not
* change it are cheap. The state is inherited by forked children.
* Thread-safe. Do nothing where the optimization is not built in.
*/
V8_EXPORT void MakeMappingsForkable();
V8_EXPORT void MakeMappingsUnforkable();

/**
* Experimental, for embedders that fork(2) a process with a live isolate.
*
* With --perf-basic-prof (or --perf-basic-prof-only-functions), call this in
* the child: it copies the parent's perf-<pid>.map, which describes the code
* the child inherited, to the child's own perf-<pid>.map and writes new
* entries there. Does nothing otherwise. --perf-prof (jitdump) is not handled.
*/
V8_EXPORT void ReopenPerfMapAfterFork();

} // namespace v8

#endif // INCLUDE_V8_FORK_H_
48 changes: 48 additions & 0 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "include/v8-extension.h"
#include "include/v8-external-memory-accounter.h"
#include "include/v8-fast-api-calls.h"
#include "include/v8-fork.h"
#include "include/v8-function.h"
#include "include/v8-json.h"
#include "include/v8-locker.h"
Expand Down Expand Up @@ -89,6 +90,7 @@
#include "src/objects/api-callbacks.h"
#include "src/objects/backing-store.h"
#include "src/objects/contexts.h"
#include "src/numbers/math-random.h"
#include "src/objects/cpp-heap-object-wrapper-inl.h"
#include "src/objects/embedder-data-array-inl.h"
#include "src/objects/embedder-data-slot-inl.h"
Expand Down Expand Up @@ -10725,6 +10727,52 @@ void Isolate::Freeze(bool is_frozen) {
i_isolate->Freeze(is_frozen);
}

#if V8_OS_POSIX
namespace base {
// Defined in src/base/platform/platform-posix.cc.
void MakeMappingsForkable();
void MakeMappingsUnforkable();
} // namespace base
#endif

void MakeMappingsForkable() {
#if V8_OS_POSIX
base::MakeMappingsForkable();
#endif
}

void MakeMappingsUnforkable() {
#if V8_OS_POSIX
base::MakeMappingsUnforkable();
#endif
}

namespace internal {
// Defined in src/logging/log.cc.
void ReopenPerfBasicLogAfterFork();
} // namespace internal

void ReopenPerfMapAfterFork() { i::ReopenPerfBasicLogAfterFork(); }

void ReseedRandomNumberGeneratorsAfterFork(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
// With a fixed seed the embedder asked for reproducible sequences.
if (i::v8_flags.random_seed != 0) return;
// A default-constructed generator draws its seed from the embedder's
// entropy source (or the OS), not from state copied from the parent.
base::RandomNumberGenerator fresh;
i_isolate->random_number_generator()->SetSeed(fresh.NextInt64());
// Math.random() reseeds a context from the generator above when it finds a
// zero state, see MathRandom::RefillCache().
i::DisallowGarbageCollection no_gc;
i::Tagged<i::Object> context = i_isolate->heap()->native_contexts_list();
while (!i::IsUndefined(context, i_isolate)) {
i::Tagged<i::Context> native_context = i::Cast<i::Context>(context);
i::MathRandom::ResetContext(native_context);
context = native_context->next_context_link();
}
}

void Isolate::IncreaseHeapLimitForDebugging() {
// No-op.
}
Expand Down
30 changes: 30 additions & 0 deletions deps/v8/src/base/bounded-page-allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ void* BoundedPageAllocator::AllocatePages(size_t size, size_t alignment,
return nullptr;
}

void* BoundedPageAllocator::AllocatePagesFromTop(
size_t size, PageAllocator::Permission access) {
MutexGuard guard(&mutex_);
DCHECK(IsAligned(size, allocate_page_size_));

Address address = region_allocator_.AllocateRegionFromTop(size);
if (address == RegionAllocator::kAllocationFailure) {
allocation_status_ = AllocationStatus::kRanOutOfReservation;
return nullptr;
}

void* ptr = reinterpret_cast<void*>(address);
if (access == PageAllocator::kNoAccess ||
access == PageAllocator::kNoAccessWillJitLater) {
allocation_status_ = AllocationStatus::kSuccess;
return ptr;
}
bool committed =
page_initialization_mode_ == PageInitializationMode::kRecommitOnly
? page_allocator_->RecommitPages(ptr, size, access)
: page_allocator_->SetPermissions(ptr, size, access);
if (committed) {
allocation_status_ = AllocationStatus::kSuccess;
return ptr;
}
CHECK_EQ(region_allocator_.FreeRegion(address), size);
allocation_status_ = AllocationStatus::kFailedToCommit;
return nullptr;
}

bool BoundedPageAllocator::AllocatePagesAt(Address address, size_t size,
PageAllocator::Permission access) {
MutexGuard guard(&mutex_);
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/base/bounded-page-allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class V8_BASE_EXPORT BoundedPageAllocator : public v8::PageAllocator {
// Allocates pages at given address, returns true on success.
bool AllocatePagesAt(Address address, size_t size, Permission access);

// Allocates pages at the highest address where they fit, keeping them
// apart from the allocations that fill the range from the bottom.
void* AllocatePagesFromTop(size_t size, Permission access);

bool ResizeAllocationAt(void* address, size_t old_size, size_t new_size,
Permission access) override;

Expand Down
Loading