blob: ac3941ea84beb31815d8222c4a442a1c31a95c07 [file] [log] [blame]
Steve Block6ded16b2010-05-10 14:33:55 +01001// Copyright 2010 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Block6ded16b2010-05-10 14:33:55 +01004
5#ifndef V8_VM_STATE_INL_H_
6#define V8_VM_STATE_INL_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/vm-state.h"
9#include "src/log.h"
10#include "src/simulator.h"
Steve Block6ded16b2010-05-10 14:33:55 +010011
12namespace v8 {
13namespace internal {
14
15//
16// VMState class implementation. A simple stack of VM states held by the
17// logger and partially threaded through the call stack. States are pushed by
18// VMState construction and popped by destruction.
19//
Steve Block6ded16b2010-05-10 14:33:55 +010020inline const char* StateToString(StateTag state) {
21 switch (state) {
22 case JS:
23 return "JS";
24 case GC:
25 return "GC";
26 case COMPILER:
27 return "COMPILER";
28 case OTHER:
29 return "OTHER";
Ben Murdochb0fe1622011-05-05 13:52:32 +010030 case EXTERNAL:
31 return "EXTERNAL";
Steve Block6ded16b2010-05-10 14:33:55 +010032 default:
33 UNREACHABLE();
34 return NULL;
35 }
36}
37
Steve Block44f0eee2011-05-26 01:26:41 +010038
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039template <StateTag Tag>
40VMState<Tag>::VMState(Isolate* isolate)
Steve Block44f0eee2011-05-26 01:26:41 +010041 : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
43 LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
Steve Block6ded16b2010-05-10 14:33:55 +010044 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 isolate_->set_current_vm_state(Tag);
Steve Block6ded16b2010-05-10 14:33:55 +010046}
47
48
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049template <StateTag Tag>
50VMState<Tag>::~VMState() {
51 if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
52 LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
Steve Block6ded16b2010-05-10 14:33:55 +010053 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054 isolate_->set_current_vm_state(previous_tag_);
Steve Block6ded16b2010-05-10 14:33:55 +010055}
Ben Murdochb0fe1622011-05-05 13:52:32 +010056
Ben Murdochb0fe1622011-05-05 13:52:32 +010057
Steve Block44f0eee2011-05-26 01:26:41 +010058ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 : isolate_(isolate),
60 callback_(callback),
61 previous_scope_(isolate->external_callback_scope()) {
62#ifdef USE_SIMULATOR
63 scope_address_ = Simulator::current(isolate)->get_sp();
64#endif
65 isolate_->set_external_callback_scope(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +010066}
67
68ExternalCallbackScope::~ExternalCallbackScope() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 isolate_->set_external_callback_scope(previous_scope_);
70}
71
72Address ExternalCallbackScope::scope_address() {
73#ifdef USE_SIMULATOR
74 return scope_address_;
75#else
76 return reinterpret_cast<Address>(this);
77#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +010078}
79
Ben Murdochb0fe1622011-05-05 13:52:32 +010080
Steve Block6ded16b2010-05-10 14:33:55 +010081} } // namespace v8::internal
82
83#endif // V8_VM_STATE_INL_H_