• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_VM_STATE_INL_H_
6 #define V8_VM_STATE_INL_H_
7 
8 #include "src/vm-state.h"
9 #include "src/log.h"
10 #include "src/simulator.h"
11 #include "src/tracing/trace-event.h"
12 
13 namespace v8 {
14 namespace 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 //
StateToString(StateTag state)21 inline 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";
31     case EXTERNAL:
32       return "EXTERNAL";
33     default:
34       UNREACHABLE();
35       return NULL;
36   }
37 }
38 
39 
40 template <StateTag Tag>
VMState(Isolate * isolate)41 VMState<Tag>::VMState(Isolate* isolate)
42     : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
43   if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
44     LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
45   }
46   isolate_->set_current_vm_state(Tag);
47 }
48 
49 
50 template <StateTag Tag>
~VMState()51 VMState<Tag>::~VMState() {
52   if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
53     LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
54   }
55   isolate_->set_current_vm_state(previous_tag_);
56 }
57 
ExternalCallbackScope(Isolate * isolate,Address callback)58 ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
59     : 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);
66   TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
67                      "V8.ExternalCallback");
68 }
69 
~ExternalCallbackScope()70 ExternalCallbackScope::~ExternalCallbackScope() {
71   isolate_->set_external_callback_scope(previous_scope_);
72   TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
73                    "V8.ExternalCallback");
74 }
75 
scope_address()76 Address ExternalCallbackScope::scope_address() {
77 #ifdef USE_SIMULATOR
78   return scope_address_;
79 #else
80   return reinterpret_cast<Address>(this);
81 #endif
82 }
83 
84 
85 }  // namespace internal
86 }  // namespace v8
87 
88 #endif  // V8_VM_STATE_INL_H_
89