1// Copyright 2010 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_VM_STATE_H_
6#define V8_VM_STATE_H_
7
8#include "src/allocation.h"
9#include "src/counters.h"
10#include "src/isolate.h"
11
12namespace v8 {
13namespace internal {
14
15// Logging and profiling.  A StateTag represents a possible state of
16// the VM. The logger maintains a stack of these. Creating a VMState
17// object enters a state by pushing on the stack, and destroying a
18// VMState object leaves a state by popping the current state from the
19// stack.
20template <StateTag Tag>
21class VMState BASE_EMBEDDED {
22 public:
23  explicit inline VMState(Isolate* isolate);
24  inline ~VMState();
25
26 private:
27  Isolate* isolate_;
28  StateTag previous_tag_;
29};
30
31
32class ExternalCallbackScope BASE_EMBEDDED {
33 public:
34  inline ExternalCallbackScope(Isolate* isolate, Address callback);
35  inline ~ExternalCallbackScope();
36  Address callback() { return callback_; }
37  Address* callback_entrypoint_address() {
38    if (callback_ == nullptr) return nullptr;
39#if USES_FUNCTION_DESCRIPTORS
40    return FUNCTION_ENTRYPOINT_ADDRESS(callback_);
41#else
42    return &callback_;
43#endif
44  }
45  ExternalCallbackScope* previous() { return previous_scope_; }
46  inline Address scope_address();
47
48 private:
49  Isolate* isolate_;
50  Address callback_;
51  ExternalCallbackScope* previous_scope_;
52#ifdef USE_SIMULATOR
53  Address scope_address_;
54#endif
55};
56
57}  // namespace internal
58}  // namespace v8
59
60
61#endif  // V8_VM_STATE_H_
62