Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_VM_STATE_INL_H_ |
| 6 | #define V8_VM_STATE_INL_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/vm-state.h" |
| 9 | #include "src/log.h" |
| 10 | #include "src/simulator.h" |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 11 | #include "src/tracing/trace-event.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 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 | // |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 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"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 31 | case EXTERNAL: |
| 32 | return "EXTERNAL"; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 33 | default: |
| 34 | UNREACHABLE(); |
| 35 | return NULL; |
| 36 | } |
| 37 | } |
| 38 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 39 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | template <StateTag Tag> |
| 41 | VMState<Tag>::VMState(Isolate* isolate) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 42 | : isolate_(isolate), previous_tag_(isolate->current_vm_state()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 43 | if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) { |
| 44 | LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 45 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | isolate_->set_current_vm_state(Tag); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | template <StateTag Tag> |
| 51 | VMState<Tag>::~VMState() { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 52 | if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && Tag == EXTERNAL) { |
| 53 | LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 54 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | isolate_->set_current_vm_state(previous_tag_); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 56 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 57 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 58 | ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | : isolate_(isolate), |
| 60 | callback_(callback), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 61 | previous_scope_(isolate->external_callback_scope()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | #ifdef USE_SIMULATOR |
| 63 | scope_address_ = Simulator::current(isolate)->get_sp(); |
| 64 | #endif |
| 65 | isolate_->set_external_callback_scope(this); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 66 | TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), |
| 67 | "V8.ExternalCallback"); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | ExternalCallbackScope::~ExternalCallbackScope() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | isolate_->set_external_callback_scope(previous_scope_); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 72 | TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8.runtime"), |
| 73 | "V8.ExternalCallback"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | Address ExternalCallbackScope::scope_address() { |
| 77 | #ifdef USE_SIMULATOR |
| 78 | return scope_address_; |
| 79 | #else |
| 80 | return reinterpret_cast<Address>(this); |
| 81 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 84 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 85 | } // namespace internal |
| 86 | } // namespace v8 |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 87 | |
| 88 | #endif // V8_VM_STATE_INL_H_ |