11cb0ef41Sopenharmony_ci// Copyright 2010 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_EXECUTION_VM_STATE_H_
61cb0ef41Sopenharmony_ci#define V8_EXECUTION_VM_STATE_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "include/v8-unwinder.h"
91cb0ef41Sopenharmony_ci#include "src/common/globals.h"
101cb0ef41Sopenharmony_ci#include "src/logging/counters-scopes.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Logging and profiling. A StateTag represents a possible state of the VM. The
161cb0ef41Sopenharmony_ci// logger maintains a stack of these. Creating a VMState object enters a state
171cb0ef41Sopenharmony_ci// by pushing on the stack, and destroying a VMState object leaves a state by
181cb0ef41Sopenharmony_ci// popping the current state from the stack.
191cb0ef41Sopenharmony_citemplate <StateTag Tag>
201cb0ef41Sopenharmony_ciclass VMState {
211cb0ef41Sopenharmony_ci public:
221cb0ef41Sopenharmony_ci  explicit inline VMState(Isolate* isolate);
231cb0ef41Sopenharmony_ci  inline ~VMState();
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci private:
261cb0ef41Sopenharmony_ci  Isolate* isolate_;
271cb0ef41Sopenharmony_ci  StateTag previous_tag_;
281cb0ef41Sopenharmony_ci};
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciclass V8_NODISCARD ExternalCallbackScope {
311cb0ef41Sopenharmony_ci public:
321cb0ef41Sopenharmony_ci  inline ExternalCallbackScope(Isolate* isolate, Address callback);
331cb0ef41Sopenharmony_ci  inline ~ExternalCallbackScope();
341cb0ef41Sopenharmony_ci  Address callback() { return callback_; }
351cb0ef41Sopenharmony_ci  Address* callback_entrypoint_address() {
361cb0ef41Sopenharmony_ci    if (callback_ == kNullAddress) return nullptr;
371cb0ef41Sopenharmony_ci#if USES_FUNCTION_DESCRIPTORS
381cb0ef41Sopenharmony_ci    return FUNCTION_ENTRYPOINT_ADDRESS(callback_);
391cb0ef41Sopenharmony_ci#else
401cb0ef41Sopenharmony_ci    return &callback_;
411cb0ef41Sopenharmony_ci#endif
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci  ExternalCallbackScope* previous() { return previous_scope_; }
441cb0ef41Sopenharmony_ci  inline Address scope_address();
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci private:
471cb0ef41Sopenharmony_ci  Isolate* isolate_;
481cb0ef41Sopenharmony_ci  Address callback_;
491cb0ef41Sopenharmony_ci  ExternalCallbackScope* previous_scope_;
501cb0ef41Sopenharmony_ci  VMState<EXTERNAL> vm_state_;
511cb0ef41Sopenharmony_ci  PauseNestedTimedHistogramScope pause_timed_histogram_scope_;
521cb0ef41Sopenharmony_ci#ifdef USE_SIMULATOR
531cb0ef41Sopenharmony_ci  Address scope_address_;
541cb0ef41Sopenharmony_ci#endif
551cb0ef41Sopenharmony_ci};
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci}  // namespace internal
581cb0ef41Sopenharmony_ci}  // namespace v8
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#endif  // V8_EXECUTION_VM_STATE_H_
61