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

deps: backport a8f6869 from upstream V8 #22122

Closed
wants to merge 4 commits into from

Conversation

benjamn
Copy link
Contributor

@benjamn benjamn commented Aug 4, 2018

Refs: v8/v8@a8f6869

Original commit message:

[debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

I have a project that embeds V8 and uses a single `Isolate` from multiple
threads. The program runs just fine, but sometimes the inspector doesn't
stop on the correct line after stepping over a statement that switches
threads behind the scenes, even though the original thread is restored by
the time the next statement is executed.

After some digging, I discovered that the `Debug::ArchiveDebug` and
`Debug::RestoreDebug` methods, which should be responsible for
saving/restoring this `ThreadLocal` information when switching threads,
currently don't do anything.

This commit implements those methods using MemCopy, in the style of other
Archive/Restore methods in the V8 codebase.

Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

R=yangguo@chromium.org,jgruber@chromium.org
CC=info@bnoordhuis.nl

Bug: v8:7230
Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
Reviewed-on: https://chromium-review.googlesource.com/833260
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54902}

Once this PR is approved/merged, I will also submit a PR to backport it to v8.x-staging so that it can be included in Node 8.12.0, if all goes smoothly.

Thanks again to @hashseed for working with me on the V8 side.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added (implementation detail)
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the v8 engine Issues and PRs related to the V8 dependency. label Aug 4, 2018
@mscdex
Copy link
Contributor

mscdex commented Aug 4, 2018

The v8 embedder string in common.gypi needs to be updated as well I believe.

@targos
Copy link
Member

targos commented Aug 4, 2018

Yes and V8_PATCH_LEVEL should not be updated

@benjamn
Copy link
Contributor Author

benjamn commented Aug 4, 2018

@mscdex Thanks, will do!

@targos I noticed that, and I did not recall making that change myself. Apparently it was introduced by the v8/tools/node/backport_node.py script here. Happy to revert.

@targos
Copy link
Member

targos commented Aug 4, 2018

@benjamn I didn't know about that script.
Our doc about updating V8 is here: https://github.com/nodejs/node/blob/master/doc/guides/maintaining-V8.md#maintenance-process

It is a little bit outdated because update-v8 was merged with node-core-utils, but the command is roughly the same: git node v8 backport <SHA>. It takes care of updating the embedder string and writing the commit message.

@hashseed
Copy link
Member

hashseed commented Aug 4, 2018

Yeah the backport_node script is a bit outdated wrt updating embedded string.

@benjamn
Copy link
Contributor Author

benjamn commented Aug 6, 2018

What's the next step here?

@joyeecheung
Copy link
Member

cc @nodejs/v8-update

@MylesBorins
Copy link
Contributor

@benjamn
Copy link
Contributor Author

benjamn commented Aug 8, 2018

Thanks @MylesBorins, this is useful feedback.

It looks like SetDebugDelegate(debug::DebugDelegate* delegate, bool pass_ownership) was simplified to just SetDebugDelegate(debug::DebugDelegate* delegate) in v8/v8@37dcd83, but the extra pass_ownership parameter is still there in the current version of node/deps/v8. I should be able to fix those tests by passing false for pass_ownership.

Also, the DebugDelegate::BreakProgramRequested method lost a parameter in v8/v8@e404670, but it's not a parameter I was using in my test, so there shouldn't be any harm in adding the exec_state parameter back to BreakProgramRequested (and continuing to ignore it).

I'm not sure why ninja -C out/Debug didn't catch these errors before. Maybe they only show up in release builds? Or maybe node/deps/v8/test/cctest/test-debug.cc just wasn't built before? 🤔

@benjamn
Copy link
Contributor Author

benjamn commented Aug 8, 2018

The only test failure I'm seeing (after rebasing against master) seems to be unrelated?

not ok 1844 parallel/test-tls-server-verify
  ---
  duration_ms: 0.845
  severity: fail
  exitcode: 1
  stack: |-
    0 0   connecting with agent1
    0 1   connecting with agent2
    0 2   connecting with agent3
    0 3   connecting with nocert
    1 0   connecting with agent1
    1 1   connecting with agent2
    1 2   connecting with agent3
    1 3   connecting with nocert
    2 0   connecting with agent1
    2 1   connecting with agent2
    2 2   connecting with agent3
    2 3   connecting with nocert
    3 0   connecting with agent1
    3 1   connecting with agent2
    3 2   connecting with agent3
    3 3   connecting with nocert
    4 0   connecting with agent1
    4 1   connecting with agent2
    4 2   connecting with agent3
    4 3   connecting with nocert
    5 0   connecting with agent1
    5 1   connecting with agent2
    5 2   connecting with agent3
    5 3   connecting with agent4
    5 4   connecting with nocert
    0 Running 'Do not request certs. Everyone is unauthorized.'
    0 - unauthed connection: null
    0 - unauthed connection: null
    0 - unauthed connection: null
    0 0   * unauthed
    0 1   * unauthed
    0 2   * unauthed
    0 - unauthed connection: null
    0 3   * unauthed
    1 Running 'Allow both authed and unauthed connections with CA1'
    1 - authed connection: agent1
    1 - unauthed connection: DEPTH_ZERO_SELF_SIGNED_CERT
    1 1   * unauthed
    1 0   * authed
    1 - unauthed connection: UNABLE_TO_VERIFY_LEAF_SIGNATURE
    1 2   * unauthed
    1 - unauthed connection: UNABLE_TO_GET_ISSUER_CERT
    1 3   * unauthed
    2 Running 'Do not request certs at connection. Do that later'
    2 - connected, renegotiating
    2 - authed connection: agent1
    2 0   * authed
    2 - unauthed connection: null
    2 1   * unauthed
    2 - unauthed connection: null
    2 2   * unauthed
    2 - unauthed connection: null
    2 3   * unauthed
    3 Running 'Allow only authed connections with CA1'
    3 - authed connection: agent1
    3 0   * authed
    4 Running 'Allow only authed connections with CA1 and CA2'
    4 - authed connection: agent1
    4 0   * authed
    4 - authed connection: agent3
    4 2   * authed
    5 Running 'Allow only certs signed by CA2 but not in the CRL'
    assert.js:84
      throw new AssertionError(obj);
      ^
AssertionError [ERR_ASSERTION]: 5 2 agent3 rejected, but should NOT have been
    at ChildProcess.<anonymous> (/home/travis/build/nodejs/node/test/parallel/test-tls-server-verify.js:232:14)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)

@MylesBorins
Copy link
Contributor

@benjamn that's a known failure right now 😄

#22182

@MylesBorins
Copy link
Contributor

@MylesBorins MylesBorins self-assigned this Aug 8, 2018
@MylesBorins
Copy link
Contributor

Lots of failures, please dig in to the results

@richardlau
Copy link
Member

test-trace-event-promises.js failures will be fixed by #22200.

@MylesBorins
Copy link
Contributor

@benjamn
Copy link
Contributor Author

benjamn commented Aug 8, 2018

Lots of test suite failures, but not many different tests failing. As far as I can tell, all the node-test-* failures should be fixed by #22200.

Regarding the V8 failures, those same tests are passing on V8 master with my change applied, so I would guess these failures are specific to the back-porting. I'll keep digging into that!

@benjamn
Copy link
Contributor Author

benjamn commented Aug 8, 2018

Just rebased to include #22200 (d7e1847). I have not done anything to address the V8 failures, yet.

https://ci.nodejs.org/job/node-test-commit-linux/nodes=ubuntu1604-32/20546/ seems to be from the previous test run (old revision, test-trace-event-promises still failing), fwiw. Perhaps I should have merged master into my branch instead of force-pushing a new revision?

@MylesBorins
Copy link
Contributor

@MylesBorins
Copy link
Contributor

@benjamingr our CI will auto rebase against master when you run the job 😄

@benjamn
Copy link
Contributor Author

benjamn commented Aug 9, 2018

I think I've tracked down the cause of the V8 test failures, and I've submitted a possible solution as another V8 change request: https://chromium-review.googlesource.com/c/v8/v8/+/1168449

I could make those changes locally, though it might be better to get them landed in V8 first?

@benjamn
Copy link
Contributor Author

benjamn commented Aug 9, 2018

Ok, I've provisionally cherry-picked my local commit to fix the V8 test failures, even though it has not landed upstream yet (I submitted it for review just last night). If the tests pass here, that would be a good sign that it's a safe and useful change. I will keep working on https://chromium-review.googlesource.com/c/v8/v8/+/1168449 with @hashseed and anyone else who's interested.

@benjamn
Copy link
Contributor Author

benjamn commented Aug 13, 2018

It looks like my follow-up fix may not be necessary for recent versions of V8 (according to @hashseed here), but is definitely necessary for Node's current version of V8, so I'm unsure how to proceed.

Should we land an unnecessary change upstream just so Node's copy of V8 does not diverge from upstream, or should we just make the change locally, as I did above? Has this kind of situation ever happened before, @MylesBorins?

Ben Newman added 3 commits September 3, 2018 19:59
It looks like

  SetDebugDelegate(debug::DebugDelegate* delegate, bool pass_ownership)

was simplified to just

  SetDebugDelegate(debug::DebugDelegate* delegate)

in v8/v8@37dcd83,
but the extra `pass_ownership` parameter is still there in the current
version of `node/deps/v8`. I should be able to fix those tests by passing
`false` for `pass_ownership`.

Also, the `DebugDelegate::BreakProgramRequested` method lost a parameter
in v8/v8@e404670,
but it's not a parameter I was using in my test, so there shouldn't be any
harm in adding the `exec_state` parameter back to `BreakProgramRequested`
(and continuing to ignore it).

I'm not sure why `ninja -C out/Debug` didn't catch these errors
before. Maybe they only show up in release builds?
A simpler version of the changes I proposed upstream in this V8 change
request: https://chromium-review.googlesource.com/c/v8/v8/+/1168449

In this version, Debug::RestoreDebug never attempts to enter a new
DebugScope, but merely reuses the previous one, if we're returning to a
thread that was previously in a DebugScope. If the thread was not
previously in a DebugScope, I believe it does not need to have any
debugging state restored with ClearOneShot and PrepareStep.

The tests from https://chromium-review.googlesource.com/c/v8/v8/+/833260
still pass, and the failing V8-CI tests are now passing locally for me:
https://ci.nodejs.org/job/node-test-commit-v8-linux/1601/
@targos
Copy link
Member

targos commented Sep 3, 2018

@targos
Copy link
Member

targos commented Sep 4, 2018

@targos
Copy link
Member

targos commented Sep 4, 2018

Landed in bb35752

@targos targos closed this Sep 4, 2018
targos pushed a commit that referenced this pull request Sep 4, 2018
Original commit message:

  [debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

  I have a project that embeds V8 and uses a single `Isolate` from multiple
  threads. The program runs just fine, but sometimes the inspector doesn't
  stop on the correct line after stepping over a statement that switches
  threads behind the scenes, even though the original thread is restored by
  the time the next statement is executed.

  After some digging, I discovered that the `Debug::ArchiveDebug` and
  `Debug::RestoreDebug` methods, which should be responsible for
  saving/restoring this `ThreadLocal` information when switching threads,
  currently don't do anything.

  This commit implements those methods using MemCopy, in the style of other
  Archive/Restore methods in the V8 codebase.

  Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

  R=yangguo@chromium.org,jgruber@chromium.org
  CC=info@bnoordhuis.nl

  Bug: v8:7230
  Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
  Reviewed-on: https://chromium-review.googlesource.com/833260
  Commit-Queue: Yang Guo <yangguo@chromium.org>
  Reviewed-by: Yang Guo <yangguo@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#54902}

Refs: v8/v8@a8f6869

Fix build errors by matching older V8 APIs used by Node.

It looks like

  SetDebugDelegate(debug::DebugDelegate* delegate, bool pass_ownership)

was simplified to just

  SetDebugDelegate(debug::DebugDelegate* delegate)

in v8/v8@37dcd83,
but the extra `pass_ownership` parameter is still there in the current
version of `node/deps/v8`. I should be able to fix those tests by passing
`false` for `pass_ownership`.

Also, the `DebugDelegate::BreakProgramRequested` method lost a parameter
in v8/v8@e404670,
but it's not a parameter I was using in my test, so there shouldn't be any
harm in adding the `exec_state` parameter back to `BreakProgramRequested`
(and continuing to ignore it).

Skip restoring debug state unless thread previously in DebugScope.

A simpler version of the changes I proposed upstream in this V8 change
request: https://chromium-review.googlesource.com/c/v8/v8/+/1168449

In this version, Debug::RestoreDebug never attempts to enter a new
DebugScope, but merely reuses the previous one, if we're returning to a
thread that was previously in a DebugScope. If the thread was not
previously in a DebugScope, I believe it does not need to have any
debugging state restored with ClearOneShot and PrepareStep.

The tests from https://chromium-review.googlesource.com/c/v8/v8/+/833260
still pass, and the failing V8-CI tests are now passing locally for me.

PR-URL: #22122
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 5, 2018
Original commit message:

  [debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

  I have a project that embeds V8 and uses a single `Isolate` from multiple
  threads. The program runs just fine, but sometimes the inspector doesn't
  stop on the correct line after stepping over a statement that switches
  threads behind the scenes, even though the original thread is restored by
  the time the next statement is executed.

  After some digging, I discovered that the `Debug::ArchiveDebug` and
  `Debug::RestoreDebug` methods, which should be responsible for
  saving/restoring this `ThreadLocal` information when switching threads,
  currently don't do anything.

  This commit implements those methods using MemCopy, in the style of other
  Archive/Restore methods in the V8 codebase.

  Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

  R=yangguo@chromium.org,jgruber@chromium.org
  CC=info@bnoordhuis.nl

  Bug: v8:7230
  Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
  Reviewed-on: https://chromium-review.googlesource.com/833260
  Commit-Queue: Yang Guo <yangguo@chromium.org>
  Reviewed-by: Yang Guo <yangguo@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#54902}

Refs: v8/v8@a8f6869

Fix build errors by matching older V8 APIs used by Node.

It looks like

  SetDebugDelegate(debug::DebugDelegate* delegate, bool pass_ownership)

was simplified to just

  SetDebugDelegate(debug::DebugDelegate* delegate)

in v8/v8@37dcd83,
but the extra `pass_ownership` parameter is still there in the current
version of `node/deps/v8`. I should be able to fix those tests by passing
`false` for `pass_ownership`.

Also, the `DebugDelegate::BreakProgramRequested` method lost a parameter
in v8/v8@e404670,
but it's not a parameter I was using in my test, so there shouldn't be any
harm in adding the `exec_state` parameter back to `BreakProgramRequested`
(and continuing to ignore it).

Skip restoring debug state unless thread previously in DebugScope.

A simpler version of the changes I proposed upstream in this V8 change
request: https://chromium-review.googlesource.com/c/v8/v8/+/1168449

In this version, Debug::RestoreDebug never attempts to enter a new
DebugScope, but merely reuses the previous one, if we're returning to a
thread that was previously in a DebugScope. If the thread was not
previously in a DebugScope, I believe it does not need to have any
debugging state restored with ClearOneShot and PrepareStep.

The tests from https://chromium-review.googlesource.com/c/v8/v8/+/833260
still pass, and the failing V8-CI tests are now passing locally for me.

PR-URL: #22122
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Sep 6, 2018
Original commit message:

  [debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

  I have a project that embeds V8 and uses a single `Isolate` from multiple
  threads. The program runs just fine, but sometimes the inspector doesn't
  stop on the correct line after stepping over a statement that switches
  threads behind the scenes, even though the original thread is restored by
  the time the next statement is executed.

  After some digging, I discovered that the `Debug::ArchiveDebug` and
  `Debug::RestoreDebug` methods, which should be responsible for
  saving/restoring this `ThreadLocal` information when switching threads,
  currently don't do anything.

  This commit implements those methods using MemCopy, in the style of other
  Archive/Restore methods in the V8 codebase.

  Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

  R=yangguo@chromium.org,jgruber@chromium.org
  CC=info@bnoordhuis.nl

  Bug: v8:7230
  Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
  Reviewed-on: https://chromium-review.googlesource.com/833260
  Commit-Queue: Yang Guo <yangguo@chromium.org>
  Reviewed-by: Yang Guo <yangguo@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#54902}

Refs: v8/v8@a8f6869

Fix build errors by matching older V8 APIs used by Node.

It looks like

  SetDebugDelegate(debug::DebugDelegate* delegate, bool pass_ownership)

was simplified to just

  SetDebugDelegate(debug::DebugDelegate* delegate)

in v8/v8@37dcd83,
but the extra `pass_ownership` parameter is still there in the current
version of `node/deps/v8`. I should be able to fix those tests by passing
`false` for `pass_ownership`.

Also, the `DebugDelegate::BreakProgramRequested` method lost a parameter
in v8/v8@e404670,
but it's not a parameter I was using in my test, so there shouldn't be any
harm in adding the `exec_state` parameter back to `BreakProgramRequested`
(and continuing to ignore it).

Skip restoring debug state unless thread previously in DebugScope.

A simpler version of the changes I proposed upstream in this V8 change
request: https://chromium-review.googlesource.com/c/v8/v8/+/1168449

In this version, Debug::RestoreDebug never attempts to enter a new
DebugScope, but merely reuses the previous one, if we're returning to a
thread that was previously in a DebugScope. If the thread was not
previously in a DebugScope, I believe it does not need to have any
debugging state restored with ClearOneShot and PrepareStep.

The tests from https://chromium-review.googlesource.com/c/v8/v8/+/833260
still pass, and the failing V8-CI tests are now passing locally for me.

PR-URL: #22122
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
benjamn pushed a commit to benjamn/node that referenced this pull request Oct 23, 2018
The upstream V8 commit a8f68691 was originally cherry-picked onto
nodejs/node master as commit bb35752, then backported to v10.x-staging
and released in Node.js v10.10.0 as 5e9ed6d. This commit cherry-picks
that commit back to the v8.x-staging branch.

Refs: v8/v8@a8f6869
Refs: nodejs#22122
Refs: nodejs@bb35752
Refs: nodejs@5e9ed6d

Original commit message:

  [debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

  I have a project that embeds V8 and uses a single `Isolate` from multiple
  threads. The program runs just fine, but sometimes the inspector doesn't
  stop on the correct line after stepping over a statement that switches
  threads behind the scenes, even though the original thread is restored by
  the time the next statement is executed.

  After some digging, I discovered that the `Debug::ArchiveDebug` and
  `Debug::RestoreDebug` methods, which should be responsible for
  saving/restoring this `ThreadLocal` information when switching threads,
  currently don't do anything.

  This commit implements those methods using MemCopy, in the style of other
  Archive/Restore methods in the V8 codebase.

  Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

  R=yangguo@chromium.org,jgruber@chromium.org
  CC=info@bnoordhuis.nl

  Bug: v8:7230
  Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
  Reviewed-on: https://chromium-review.googlesource.com/833260
  Commit-Queue: Yang Guo <yangguo@chromium.org>
  Reviewed-by: Yang Guo <yangguo@chromium.org>
  Cr-Commit-Position: refs/heads/master@{nodejs#54902}

PR-URL: nodejs#22714

ADDITIONAL CHANGES:

Support optional boolean argument to DisableBreak constructor.

This allows a stack-allocated DisableBreak object to re-enable breakpoints
temporarily, rather than always disabling them.

This functionality anticipates an upstream change that will be introduced
in V8 6.7.176: v8/v8@cc9736a

More immediately, these changes should fix a cctest compile error in this
backport PR: nodejs#22714 (comment)
MylesBorins pushed a commit that referenced this pull request Oct 31, 2018
The upstream V8 commit a8f68691 was originally cherry-picked onto
nodejs/node master as commit bb35752, then backported to v10.x-staging
and released in Node.js v10.10.0 as 5e9ed6d. This commit cherry-picks
that commit back to the v8.x-staging branch.

Additionally this commit supports optional boolean argument to
DisableBreak constructor.

This allows a stack-allocated DisableBreak object to re-enable
breakpoints temporarily, rather than always disabling them.

This functionality anticipates an upstream change that will be
introduced in V8 6.7.176:

v8/v8@cc9736a

Original commit message:

  [debug] Fully implement Debug::ArchiveDebug and Debug::RestoreDebug.

  I have a project that embeds V8 and uses a single `Isolate` from multiple
  threads. The program runs just fine, but sometimes the inspector doesn't
  stop on the correct line after stepping over a statement that switches
  threads behind the scenes, even though the original thread is restored by
  the time the next statement is executed.

  After some digging, I discovered that the `Debug::ArchiveDebug` and
  `Debug::RestoreDebug` methods, which should be responsible for
  saving/restoring this `ThreadLocal` information when switching threads,
  currently don't do anything.

  This commit implements those methods using MemCopy, in the style of other
  Archive/Restore methods in the V8 codebase.

  Related: https://groups.google.com/forum/#!topic/v8-users/_Qf2rwljRk8

  R=yangguo@chromium.org,jgruber@chromium.org
  CC=info@bnoordhuis.nl

  Bug: v8:7230
  Change-Id: Id517c873eb81cd53f7216c7efd441b956cf7f943
  Reviewed-on: https://chromium-review.googlesource.com/833260
  Commit-Queue: Yang Guo <yangguo@chromium.org>
  Reviewed-by: Yang Guo <yangguo@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#54902}

PR-URL: #22714
Refs: v8/v8@a8f6869
Refs: #22122
Refs: bb35752
Refs: 5e9ed6d
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants