vm-state-inl.h 2.23 KB
Newer Older
1
// Copyright 2010 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_EXECUTION_VM_STATE_INL_H_
#define V8_EXECUTION_VM_STATE_INL_H_
7

8 9 10
#include "src/execution/isolate.h"
#include "src/execution/simulator.h"
#include "src/execution/vm-state.h"
11
#include "src/logging/log.h"
12
#include "src/tracing/trace-event.h"
13 14 15 16

namespace v8 {
namespace internal {

17 18 19
// VMState class implementation. A simple stack of VM states held by the logger
// and partially threaded through the call stack. States are pushed by VMState
// construction and popped by destruction.
20 21 22 23 24 25
inline const char* StateToString(StateTag state) {
  switch (state) {
    case JS:
      return "JS";
    case GC:
      return "GC";
26 27 28 29
    case PARSER:
      return "PARSER";
    case BYTECODE_COMPILER:
      return "BYTECODE_COMPILER";
30 31 32 33
    case COMPILER:
      return "COMPILER";
    case OTHER:
      return "OTHER";
34 35
    case EXTERNAL:
      return "EXTERNAL";
36 37
    case ATOMICS_WAIT:
      return "ATOMICS_WAIT";
38 39
    case IDLE:
      return "IDLE";
40 41 42
  }
}

43 44
template <StateTag Tag>
VMState<Tag>::VMState(Isolate* isolate)
45
    : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
46
  isolate_->set_current_vm_state(Tag);
47 48
}

49 50 51
template <StateTag Tag>
VMState<Tag>::~VMState() {
  isolate_->set_current_vm_state(previous_tag_);
52
}
53

54
ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
55 56
    : isolate_(isolate),
      callback_(callback),
57
      previous_scope_(isolate->external_callback_scope()) {
58
#ifdef USE_SIMULATOR
59
  scope_address_ = Simulator::current(isolate)->get_sp();
60 61
#endif
  isolate_->set_external_callback_scope(this);
62 63
  TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
                     "V8.ExternalCallback");
64 65 66
}

ExternalCallbackScope::~ExternalCallbackScope() {
67
  isolate_->set_external_callback_scope(previous_scope_);
68 69
  TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
                   "V8.ExternalCallback");
70 71 72 73 74 75 76 77
}

Address ExternalCallbackScope::scope_address() {
#ifdef USE_SIMULATOR
  return scope_address_;
#else
  return reinterpret_cast<Address>(this);
#endif
78 79
}

80 81
}  // namespace internal
}  // namespace v8
82

83
#endif  // V8_EXECUTION_VM_STATE_INL_H_