#ifndef V8_EXECUTION_VM_STATE_INL_H_
#define V8_EXECUTION_VM_STATE_INL_H_
#include "src/execution/vm-state.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/simulator.h"
#include "src/logging/log.h"
#include "src/tracing/trace-event.h"
namespace v8 {
namespace internal {
constexpr const char* ToString(StateTag state) {
switch (state) {
case JS:
return "JS";
case GC:
return "GC";
case PARSER:
return "PARSER";
case BYTECODE_COMPILER:
return "BYTECODE_COMPILER";
case COMPILER:
return "COMPILER";
case OTHER:
return "OTHER";
case EXTERNAL:
return "EXTERNAL";
case ATOMICS_WAIT:
return "ATOMICS_WAIT";
case IDLE:
return "IDLE";
case IDLE_EXTERNAL:
return "IDLE_EXTERNAL";
case LOGGING:
return "LOGGING";
}
}
inline std::ostream& operator<<(std::ostream& os, StateTag kind) {
return os << ToString(kind);
}
template <StateTag Tag>
VMState<Tag>::VMState(Isolate* isolate)
: isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
isolate_->set_current_vm_state(Tag);
}
template <StateTag Tag>
VMState<Tag>::~VMState() {
isolate_->set_current_vm_state(previous_tag_);
}
ExternalCallbackScope::ExternalCallbackScope(
Isolate* isolate, Address callback, v8::ExceptionContext exception_context,
const void* callback_info)
: callback_(callback),
callback_info_(callback_info),
previous_scope_(isolate->external_callback_scope()),
vm_state_(isolate),
exception_context_(exception_context),
pause_timed_histogram_scope_(isolate->counters()->execute()) {
#if USE_SIMULATOR || V8_USE_ADDRESS_SANITIZER || V8_USE_SAFE_STACK
js_stack_comparable_address_ =
i::SimulatorStack::RegisterJSStackComparableAddress(isolate);
#endif
vm_state_.isolate_->set_external_callback_scope(this);
#ifdef V8_RUNTIME_CALL_STATS
TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
"V8.ExternalCallback");
#endif
vm_state_.isolate_->clear_topmost_script_having_context();
}
ExternalCallbackScope::~ExternalCallbackScope() {
vm_state_.isolate_->set_external_callback_scope(previous_scope_);
vm_state_.isolate_->clear_topmost_script_having_context();
#ifdef V8_RUNTIME_CALL_STATS
TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
"V8.ExternalCallback");
#endif
#if USE_SIMULATOR || V8_USE_ADDRESS_SANITIZER || V8_USE_SAFE_STACK
i::SimulatorStack::UnregisterJSStackComparableAddress(vm_state_.isolate_);
#endif
}
Address ExternalCallbackScope::JSStackComparableAddress() {
#if USE_SIMULATOR || V8_USE_ADDRESS_SANITIZER || V8_USE_SAFE_STACK
return js_stack_comparable_address_;
#else
return reinterpret_cast<Address>(this);
#endif
}
}
}
#endif