Skip to content

Commit 9b7a1b0

Browse files
addaleaxBethGriggs
authored andcommitted
deps: V8: cherry-pick e8ba5699c648
Original commit message: [tools] Add a VMState for Atomics.wait We will use this state in devtools via the inspector to indicate whether a thread is currently stuck polling in atomics.wait. VMState already distinguishes the important states we care about which are idle vs. running JS. We also want to know the state for atomics.wait(), which is commonly used in WebWorkers to poll the main page for work to do. This CL just adds and maintains the state and adds assertions in atomics tests. Another CL will emit inspector notifications when the VMState changes in a way that the inspector cares about. Re-flow comments as a drive-by cleanup. Bug: chromium:1025490 Change-Id: I961051bfb846aa20454a56214310370ea8e47d1c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2033168 Commit-Queue: Peter Marshall <petermarshall@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#66071} Refs: v8/v8@e8ba569 PR-URL: #32885 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent 1f02617 commit 9b7a1b0

File tree

8 files changed

+19
-11
lines changed

8 files changed

+19
-11
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Reset this number to 0 on major V8 upgrades.
3737
# Increment by one for each non-official patch applied to deps/v8.
38-
'v8_embedder_string': '-node.22',
38+
'v8_embedder_string': '-node.23',
3939

4040
##### V8 defaults for Node.js #####
4141

deps/v8/include/v8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,7 @@ enum StateTag {
21812181
COMPILER,
21822182
OTHER,
21832183
EXTERNAL,
2184+
ATOMICS_WAIT,
21842185
IDLE
21852186
};
21862187

deps/v8/src/execution/futex-emulation.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/base/macros.h"
1010
#include "src/base/platform/time.h"
1111
#include "src/execution/isolate.h"
12+
#include "src/execution/vm-state-inl.h"
1213
#include "src/handles/handles-inl.h"
1314
#include "src/numbers/conversions.h"
1415
#include "src/objects/bigint.h"
@@ -132,6 +133,7 @@ template <typename T>
132133
Object FutexEmulation::Wait(Isolate* isolate,
133134
Handle<JSArrayBuffer> array_buffer, size_t addr,
134135
T value, double rel_timeout_ms) {
136+
VMState<ATOMICS_WAIT> state(isolate);
135137
DCHECK_LT(addr, array_buffer->byte_length());
136138

137139
bool use_timeout = rel_timeout_ms != V8_INFINITY;

deps/v8/src/execution/vm-state-inl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
namespace v8 {
1515
namespace internal {
1616

17-
//
18-
// VMState class implementation. A simple stack of VM states held by the
19-
// logger and partially threaded through the call stack. States are pushed by
20-
// VMState construction and popped by destruction.
21-
//
17+
// VMState class implementation. A simple stack of VM states held by the logger
18+
// and partially threaded through the call stack. States are pushed by VMState
19+
// construction and popped by destruction.
2220
inline const char* StateToString(StateTag state) {
2321
switch (state) {
2422
case JS:
@@ -35,6 +33,8 @@ inline const char* StateToString(StateTag state) {
3533
return "OTHER";
3634
case EXTERNAL:
3735
return "EXTERNAL";
36+
case ATOMICS_WAIT:
37+
return "ATOMICS_WAIT";
3838
case IDLE:
3939
return "IDLE";
4040
}

deps/v8/src/execution/vm-state.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
namespace v8 {
1212
namespace internal {
1313

14-
// Logging and profiling. A StateTag represents a possible state of
15-
// the VM. The logger maintains a stack of these. Creating a VMState
16-
// object enters a state by pushing on the stack, and destroying a
17-
// VMState object leaves a state by popping the current state from the
18-
// stack.
14+
// Logging and profiling. A StateTag represents a possible state of the VM. The
15+
// logger maintains a stack of these. Creating a VMState object enters a state
16+
// by pushing on the stack, and destroying a VMState object leaves a state by
17+
// popping the current state from the stack.
1918
template <StateTag Tag>
2019
class VMState {
2120
public:

deps/v8/src/profiler/profile-generator.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
10141014
case PARSER:
10151015
case COMPILER:
10161016
case BYTECODE_COMPILER:
1017+
case ATOMICS_WAIT:
10171018
// DOM events handlers are reported as OTHER / EXTERNAL entries.
10181019
// To avoid confusing people, let's put all these entries into
10191020
// one bucket.

deps/v8/src/profiler/sampling-heap-profiler.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
178178
case IDLE:
179179
name = "(IDLE)";
180180
break;
181+
// Treat atomics wait as a normal JS event; we don't care about the
182+
// difference for allocations.
183+
case ATOMICS_WAIT:
181184
case JS:
182185
name = "(JS)";
183186
break;

deps/v8/test/cctest/test-api.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25979,6 +25979,8 @@ void AtomicsWaitCallbackForTesting(
2597925979
CHECK_EQ(timeout_in_ms, info->expected_timeout);
2598025980
CHECK_EQ(value, info->expected_value);
2598125981
CHECK_EQ(offset_in_bytes, info->expected_offset);
25982+
CHECK_EQ(v8::StateTag::ATOMICS_WAIT,
25983+
reinterpret_cast<i::Isolate*>(info->isolate)->current_vm_state());
2598225984

2598325985
auto ThrowSomething = [&]() {
2598425986
info->isolate->ThrowException(v8::Integer::New(info->isolate, 42));

0 commit comments

Comments
 (0)