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_EXECUTION_VM_STATE_INL_H_ 6 #define V8_EXECUTION_VM_STATE_INL_H_ 7 8 #include "src/execution/isolate.h" 9 #include "src/execution/simulator.h" 10 #include "src/execution/vm-state.h" 11 #include "src/logging/log.h" 12 #include "src/tracing/trace-event.h" 13 14 namespace v8 { 15 namespace internal { 16 17 // VMState class implementation. A simple stack of VM states held by the logger 18 // and partially threaded through the call stack. States are pushed by VMState 19 // construction and popped by destruction. StateToString(StateTag state)20inline const char* StateToString(StateTag state) { 21 switch (state) { 22 case JS: 23 return "JS"; 24 case GC: 25 return "GC"; 26 case PARSER: 27 return "PARSER"; 28 case BYTECODE_COMPILER: 29 return "BYTECODE_COMPILER"; 30 case COMPILER: 31 return "COMPILER"; 32 case OTHER: 33 return "OTHER"; 34 case EXTERNAL: 35 return "EXTERNAL"; 36 case ATOMICS_WAIT: 37 return "ATOMICS_WAIT"; 38 case IDLE: 39 return "IDLE"; 40 } 41 } 42 43 template <StateTag Tag> VMState(Isolate * isolate)44VMState<Tag>::VMState(Isolate* isolate) 45 : isolate_(isolate), previous_tag_(isolate->current_vm_state()) { 46 isolate_->set_current_vm_state(Tag); 47 } 48 49 template <StateTag Tag> ~VMState()50VMState<Tag>::~VMState() { 51 isolate_->set_current_vm_state(previous_tag_); 52 } 53 ExternalCallbackScope(Isolate * isolate,Address callback)54ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback) 55 : isolate_(isolate), 56 callback_(callback), 57 previous_scope_(isolate->external_callback_scope()) { 58 #ifdef USE_SIMULATOR 59 scope_address_ = Simulator::current(isolate)->get_sp(); 60 #endif 61 isolate_->set_external_callback_scope(this); 62 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), 63 "V8.ExternalCallback"); 64 } 65 ~ExternalCallbackScope()66ExternalCallbackScope::~ExternalCallbackScope() { 67 isolate_->set_external_callback_scope(previous_scope_); 68 TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), 69 "V8.ExternalCallback"); 70 } 71 scope_address()72Address ExternalCallbackScope::scope_address() { 73 #ifdef USE_SIMULATOR 74 return scope_address_; 75 #else 76 return reinterpret_cast<Address>(this); 77 #endif 78 } 79 80 } // namespace internal 81 } // namespace v8 82 83 #endif // V8_EXECUTION_VM_STATE_INL_H_ 84