Repository navigation
refactor: move electron::api::GlobalShortcut to cppgc - #50192
Conversation
😠 |
|
I saw the crash in this PR before the recent change, it hints to me as a bug in V8. Logging the header in const bool header_is_large =
header.IsLargeObject<AccessMode::kNonAtomic>();
if (V8_LIKELY(header_is_large == page.is_large())) return;
const char* object_name =
header
.GetName(HeapObjectNameForUnnamedObject::kUseClassNameIfSupported)
.value;
v8::base::OS::PrintError(
"\n<--- cppgc header/page mismatch --->\n"
"header_is_large=%d page_is_large=%d "
"allocated_size=%zu gc_info_index=%u in_construction=%d marked=%d "
"object_name=%s\n",
header_is_large, page.is_large(),
header.AllocatedSize<AccessMode::kAtomic>(),
static_cast<unsigned>(header.GetGCInfoIndex<AccessMode::kAtomic>()),
header.IsInConstruction<AccessMode::kAtomic>(),
header.IsMarked<AccessMode::kAtomic>(), object_name);Results in,
|
bca3c2b to
8032a0a
Compare
|
This needs some more work to reconcile with the weak ptr references introduced in this week's Chromium roll. Working on this today. |
8032a0a to
575c2c1
Compare
I worked on this more today and it keeps getting more interesting. 😄 The crashes in CI now are, I think, due to the callbacks being registered: they are managed by JS via the gin_helper converter's SafeV8Function which uses V8::Global, ie is managed by JS. But the cppgc-managed GlobalShortcut C++ object has a std::map that holds onto it. I'm looking at V8::TracedReference to see if there's something that can be done there. I'm also considering splitting the callbacks into two pieces -- a cppgc-managed side that emits a signal, and a JS-managed side that listens for the signal and invokes the JS-managed callback. 😵 |
|
Note: also it looks like maybe GlobalShortcut doesn't work on Wayland? GlobalAcceleratorListener::GetInstance() calls GlboalAcceleratorListenerOzone::Create() which only returns non-nullptr if it can create a listener that has a valid This is consistent with my findings when I run the GloablShortcut tests locally on Wayland -- all the calls to |
That would be right way to go, it will also simplify the refcounted management v8_function_ since we have cppgc::persistent to prepare a GC root and multiple copies of the SafeV8Function can create their own roots leaving V8 to manage the lifetime via the traced reference instead of us having to manage it. |
|
@ckerr is the crash you are seeing with callback ? |
|
Nvm I was on a older version of this branch, pushing a lifetime fix. |
|
Spent an entire weekend debugging the different DCHECKs we are hitting in this PR during the incremental mark and atomic pause. Got through the weeds of unified heap, expect some interesting writeup today. |
a29a6de to
19f4f38
Compare
|
V8 team member mentioned that the inheritance rule and other cppgc related compile time verifications are enforced via the clang plugin https://source.chromium.org/chromium/chromium/src/+/main:tools/clang/blink_gc_plugin/ . I will remove the patch as followup once the plugin is enabled. |
|
Okay the blink_gc_plugin is built into the default clang build https://source.chromium.org/chromium/chromium/src/+/main:tools/clang/scripts/build.py;l=1263-1265 (good we don;t need to build our own clang binary). I will enable the plugin before merging this change. |
3fa35aa to
5bfdcc7
Compare
copy the lazy-create idom used by electron::api::Screen
safeguard against the callback changing the map, invalidating `cb`
fix: must Trace() the weak cell factory
- Setup isolate dispose observer to run destruction sequences and remove self persistent reference - Skip NOTREACHED check during destruction, it can happen as a result of plaform listeners scheduling callbacks when Unregister is invoked. - Fix the order of unregistration in GlobalShortcut::Unregister - Add GlobalShortcut::UnregisterAllInternal to avoid any callsites that can re-enter V8
7b453f6 to
8ca48f1
Compare
|
No Release Notes |
|
I was unable to backport this PR to "42-x-y" cleanly; |
Ref: 53bf94f Co-Authored-By: Claude <[email protected]> Co-Authored-By: Charles Kerr <[email protected]>
|
@VerteDinde has manually backported this PR to "42-x-y", please check out #52974 |
refactor: move `electron::api::GlobalShortcut` to cppgc (#50192) * refactor: migrate electron::api::GlobalShortcut to cppgc * refactor: lazy-create electron::api::GlobalShortcut copy the lazy-create idom used by electron::api::Screen * refactor: use gin::WeakCellFactory in GlobalCallbacks * fix: make a copy of `callback` before running it safeguard against the callback changing the map, invalidating `cb` * chore: reduce unnecessary diffs with main * fixup! refactor: use gin::WeakCellFactory in GlobalCallbacks fix: must Trace() the weak cell factory * fix: destruction order - Setup isolate dispose observer to run destruction sequences and remove self persistent reference - Skip NOTREACHED check during destruction, it can happen as a result of plaform listeners scheduling callbacks when Unregister is invoked. - Fix the order of unregistration in GlobalShortcut::Unregister - Add GlobalShortcut::UnregisterAllInternal to avoid any callsites that can re-enter V8 * fix: crash during gc from incorrect cppgc object headers * chore: update patches * chore: cleanup * chore: fix lint --------- (cherry picked from commit 53bf94f) Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: deepak1556 <[email protected]>
Description of Change
Migrate
electron::api::GlobalShortcutfromgin_helper::DeprecatedWrappabletogin::Wrappable.Part of #47922.
This is probably going to jinx CI, but... this is one of the easier refactors so far.
CC @deepak1556 @codebytere
Checklist
npm testpassesRelease Notes
Notes: none.