vm-state-inl.h 3.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef V8_VM_STATE_INL_H_
#define V8_VM_STATE_INL_H_

#include "vm-state.h"
32 33
#include "log.h"
#include "simulator.h"
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

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";
53 54
    case EXTERNAL:
      return "EXTERNAL";
55 56 57 58 59 60
    default:
      UNREACHABLE();
      return NULL;
  }
}

61

62 63
template <StateTag Tag>
VMState<Tag>::VMState(Isolate* isolate)
64
    : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
65 66 67
  if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
    LOG(isolate_,
        TimerEvent(Logger::START, Logger::TimerEventScope::v8_external));
68
  }
69
  isolate_->set_current_vm_state(Tag);
70 71 72
}


73 74 75
template <StateTag Tag>
VMState<Tag>::~VMState() {
  if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
76
    LOG(isolate_,
77
        TimerEvent(Logger::END, Logger::TimerEventScope::v8_external));
78
  }
79
  isolate_->set_current_vm_state(previous_tag_);
80
}
81 82


83
ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
84 85 86 87 88 89 90 91
    : isolate_(isolate),
      callback_(callback),
      previous_scope_(isolate->external_callback_scope()) {
#ifdef USE_SIMULATOR
  int32_t sp = Simulator::current(isolate)->get_register(Simulator::sp);
  scope_address_ = reinterpret_cast<Address>(static_cast<intptr_t>(sp));
#endif
  isolate_->set_external_callback_scope(this);
92 93 94
}

ExternalCallbackScope::~ExternalCallbackScope() {
95 96 97 98 99 100 101 102 103
  isolate_->set_external_callback_scope(previous_scope_);
}

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


107 108 109
} }  // namespace v8::internal

#endif  // V8_VM_STATE_INL_H_