Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove dependency on wrapper-descriptor-based cpp heap #284

Closed
wants to merge 20 commits into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented May 20, 2024

As V8 is moving towards built-in CppHeap creation, change the management so that the automatic CppHeap creation on Node.js's end is also enforced at Isolate creation time.

  1. If embedder uses NewIsolate(), either they use IsolateSettings::cpp_heap to specify a CppHeap that will be owned by V8, or if it's not configured, Node.js will create a CppHeap that will be owned by V8.
  2. If the embedder uses SetIsolateUpForNode(), IsolateSettings::cpp_heap will be ignored (as V8 has deprecated attaching CppHeap post-isolate-creation). The embedders need to ensure that the v8::Isolate has a CppHeap attached while it's still used by Node.js, preferably using v8::CreateParams.

See https://issues.chromium.org/issues/42203693 for details. In future version of V8, this CppHeap will be created by V8 if not provided, and we can remove our own "if no CppHeap provided, create one" code in NewIsolate().

This also deprecates node::SetCppgcReference() in favor of v8::Object::Wrap() since the wrapper descriptor is no longer relevant. It is still kept as a compatibility layer for addons that need to also work on Node.js versions without v8::Object::Wrap().

Fixes: #283
Fixes: nodejs/node#52718

nodejs-github-bot and others added 18 commits May 20, 2024 06:03
Major V8 updates are usually API/ABI incompatible with previous
versions. This commit adapts NODE_MODULE_VERSION for V8 12.7.

Refs: https://github.com/nodejs/CTC/blob/master/meetings/2016-09-28.md
dllexport introduces issues when compiling with MSVC.

PR-URL: nodejs/node#47251
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
It introduces process hangs on some platforms because Node.js doesn't
tear down V8 correctly.
Disable it while we work on a solution.

Refs: nodejs/node#47297
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=13902
PR-URL: nodejs/node#47450
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
We are not ready to compile with C++20 support yet.
This is only a DCHECK that can be removed without affecting the behavior
of release builds.

PR-URL: nodejs/node#49639
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs/node#49639
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs/node#52293
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
After enabling -std:c++20 on Windows, patch is now much smaller.

PR-URL: nodejs/node#52465
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
On Windows debug builds, it is not allowed to dereference empty
iterators.

Refs: https://chromium-review.googlesource.com/c/v8/v8/+/5331688
PR-URL: nodejs/node#52465
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Namely:
  - `v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, ...);`
  - `v8::ObjectTemplate::SetNativeDataProperty` with `AccessControl`

Refs: v8/v8@46c241e
Refs: v8/v8@6ec8839
Co-authored-by: Michaël Zasso <[email protected]>
As V8 is moving towards built-in CppHeap creation, change the
management so that the automatic CppHeap creation on Node.js's end
is also enforced at Isolate creation time.

1. If embedder uses NewIsolate(), either they use
  IsolateSettings::cpp_heap to specify a CppHeap that will be owned
  by V8, or if it's not configured, Node.js will create a CppHeap
  that will be owned by V8.
2. If the embedder uses SetIsolateUpForNode(),
  IsolateSettings::cpp_heap will be ignored (as V8 has deprecated
  attaching CppHeap post-isolate-creation). The embedders need to
  ensure that the v8::Isolate has a CppHeap attached while it's
  still used by Node.js, preferably using v8::CreateParams.

See https://issues.chromium.org/issues/42203693 for details. In
future version of V8, this CppHeap will be created by V8 if not
provided, and we can remove our own "if no CppHeap provided,
create one" code in NewIsolate().
@joyeecheung
Copy link
Member Author

cc @codebytere @addaleax @legendecas

src/node.h Show resolved Hide resolved
src/env.cc Outdated Show resolved Hide resolved
test/cctest/test_cppgc.cc Show resolved Hide resolved
src/env.cc Outdated Show resolved Hide resolved
//
// See https://issues.chromium.org/issues/42203693. In future version
// of V8, this CppHeap will be created by V8 if not provided.
v8::CppHeap* cpp_heap = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a flag in IsolateSettingsFlags (similar to e.g. ALLOW_MODIFY_CODE_GENERATION_FROM_STRINGS_CALLBACK), as otherwise it's ABI-breaking? Or do you want to do that when backporting this change?

Copy link
Member Author

@joyeecheung joyeecheung May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new tracing mechanism is already ABI breaking (wrappers are now getting a new layout and a slot in their headers), so this can't be backported anyway?

Copy link
Member Author

@joyeecheung joyeecheung May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this is part of the migration that builds on top of the new v8::Object::Wrap/v8::Object::Unwrap APIs that are replacement of the deprecated APIs, which won't be available until 12.5 with https://issues.chromium.org/issues/328117814 (I suspect the series of changes are already ABI-breaking in themselves somehow....or it would be very difficult to backport all the related patches in a non-ABI breaking way to older releases), this PR is baking for the 12.5 upgrade, see #283

@targos
Copy link
Member

targos commented May 21, 2024

@joyeecheung The canary branch in this repo is updated/force-pushed automatically every day. We need to land canary patches on https://github.com/nodejs/node/tree/canary-base (I just updated it in case you need very recent V8 changes for your patch).

@joyeecheung
Copy link
Member Author

Thanks for the reminder, moving to nodejs/node#53086

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants