Line data Source code
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 : //
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>
41 636616340 : VMState<Tag>::VMState(Isolate* isolate)
42 189605030 : : isolate_(isolate), previous_tag_(isolate->current_vm_state()) {
43 94802515 : if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
44 0 : LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name()));
45 : }
46 94802515 : isolate_->set_current_vm_state(Tag);
47 94802515 : }
48 :
49 :
50 : template <StateTag Tag>
51 94802513 : VMState<Tag>::~VMState() {
52 94802513 : if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) {
53 0 : LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name()));
54 : }
55 94802513 : isolate_->set_current_vm_state(previous_tag_);
56 94802513 : }
57 :
58 189059864 : ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback)
59 : : isolate_(isolate),
60 : callback_(callback),
61 189059864 : 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 189059864 : TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
67 : "V8.ExternalCallback");
68 94529932 : }
69 :
70 94529933 : ExternalCallbackScope::~ExternalCallbackScope() {
71 94529933 : isolate_->set_external_callback_scope(previous_scope_);
72 189059866 : TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"),
73 : "V8.ExternalCallback");
74 94529933 : }
75 :
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_
|