vm-state-inl.h 2.32 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 7

#ifndef V8_VM_STATE_INL_H_
#define V8_VM_STATE_INL_H_

8 9 10
#include "src/vm-state.h"
#include "src/log.h"
#include "src/simulator.h"
11
#include "src/tracing/trace-event.h"
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

namespace v8 {
namespace internal {

//
// 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.
//
inline const char* StateToString(StateTag state) {
  switch (state) {
    case JS:
      return "JS";
    case GC:
      return "GC";
    case COMPILER:
      return "COMPILER";
    case OTHER:
      return "OTHER";
31 32
    case EXTERNAL:
      return "EXTERNAL";
33 34 35 36 37 38
    default:
      UNREACHABLE();
      return NULL;
  }
}

39

40 41
template <StateTag Tag>
VMState<Tag>::VMState(Isolate* isolate)
42
    : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
43 44
  if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
    LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
45
  }
46
  isolate_->set_current_vm_state(Tag);
47 48 49
}


50 51
template <StateTag Tag>
VMState<Tag>::~VMState() {
52 53
  if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
    LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
54
  }
55
  isolate_->set_current_vm_state(previous_tag_);
56
}
57

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

ExternalCallbackScope::~ExternalCallbackScope() {
71
  isolate_->set_external_callback_scope(previous_scope_);
72 73
  TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
                   "V8.ExternalCallback");
74 75 76 77 78 79 80 81
}

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


85 86
}  // namespace internal
}  // namespace v8
87 88

#endif  // V8_VM_STATE_INL_H_