blob: 35b69a1ddc43dec96b2edb06798314a7abfba5cc [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"
Ben Murdoch097c5b22016-05-18 11:27:45 +010011#include "src/tracing/trace-event.h"
Steve Block6ded16b2010-05-10 14:33:55 +010012
13namespace v8 {
14namespace internal {
15
16//
17// VMState class implementation. A simple stack of VM states held by the
18// logger and partially threaded through the call stack. States are pushed by
19// VMState construction and popped by destruction.
20//
Steve Block6ded16b2010-05-10 14:33:55 +010021inline const char* StateToString(StateTag state) {
22 switch (state) {
23 case JS:
24 return "JS";
25 case GC:
26 return "GC";
27 case COMPILER:
28 return "COMPILER";
29 case OTHER:
30 return "OTHER";
Ben Murdochb0fe1622011-05-05 13:52:32 +010031 case EXTERNAL:
32 return "EXTERNAL";
Steve Block6ded16b2010-05-10 14:33:55 +010033 default:
34 UNREACHABLE();
35 return NULL;
36 }
37}
38
Steve Block44f0eee2011-05-26 01:26:41 +010039
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040template <StateTag Tag>
41VMState<Tag>::VMState(Isolate* isolate)
Steve Block44f0eee2011-05-26 01:26:41 +010042 : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
Ben Murdochda12d292016-06-02 14:46:10 +010043 if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
44 LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
Steve Block6ded16b2010-05-10 14:33:55 +010045 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046 isolate_->set_current_vm_state(Tag);
Steve Block6ded16b2010-05-10 14:33:55 +010047}
48
49
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050template <StateTag Tag>
51VMState<Tag>::~VMState() {
Ben Murdochda12d292016-06-02 14:46:10 +010052 if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
53 LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
Steve Block6ded16b2010-05-10 14:33:55 +010054 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 isolate_->set_current_vm_state(previous_tag_);
Steve Block6ded16b2010-05-10 14:33:55 +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),
Ben Murdochda12d292016-06-02 14:46:10 +010061 previous_scope_(isolate->external_callback_scope()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062#ifdef USE_SIMULATOR
63 scope_address_ = Simulator::current(isolate)->get_sp();
64#endif
65 isolate_->set_external_callback_scope(this);
Ben Murdochda12d292016-06-02 14:46:10 +010066 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
67 "V8.ExternalCallback");
Ben Murdochb0fe1622011-05-05 13:52:32 +010068}
69
70ExternalCallbackScope::~ExternalCallbackScope() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 isolate_->set_external_callback_scope(previous_scope_);
Ben Murdochda12d292016-06-02 14:46:10 +010072 TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
73 "V8.ExternalCallback");
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074}
75
76Address ExternalCallbackScope::scope_address() {
77#ifdef USE_SIMULATOR
78 return scope_address_;
79#else
80 return reinterpret_cast<Address>(this);
81#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +010082}
83
Ben Murdochb0fe1622011-05-05 13:52:32 +010084
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085} // namespace internal
86} // namespace v8
Steve Block6ded16b2010-05-10 14:33:55 +010087
88#endif // V8_VM_STATE_INL_H_