Skip to content

Commit e8ba569

Browse files
psmarshallCommit Bot
authored and
Commit Bot
committed
[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 <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#66071}
1 parent a6cf73e commit e8ba569

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

include/v8.h

+1
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,7 @@ enum StateTag {
21992199
COMPILER,
22002200
OTHER,
22012201
EXTERNAL,
2202+
ATOMICS_WAIT,
22022203
IDLE
22032204
};
22042205

src/execution/futex-emulation.cc

+2
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;

src/execution/vm-state-inl.h

+5-5
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
}

src/execution/vm-state.h

+4-5
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:

src/profiler/profile-generator.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
10071007
case PARSER:
10081008
case COMPILER:
10091009
case BYTECODE_COMPILER:
1010+
case ATOMICS_WAIT:
10101011
// DOM events handlers are reported as OTHER / EXTERNAL entries.
10111012
// To avoid confusing people, let's put all these entries into
10121013
// one bucket.

src/profiler/sampling-heap-profiler.cc

+3
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;

test/cctest/test-api.cc

+2
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)