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 | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 43 | if (previous_tag_ != EXTERNAL && Tag == EXTERNAL) { |
| 44 | if (FLAG_log_timer_events) { |
| 45 | LOG(isolate_, TimerEvent(Logger::START, TimerEventExternal::name())); |
| 46 | } |
| 47 | TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("v8"), "V8.External"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 48 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 49 | isolate_->set_current_vm_state(Tag); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | template <StateTag Tag> |
| 54 | VMState<Tag>::~VMState() { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 55 | if (previous_tag_ != EXTERNAL && Tag == EXTERNAL) { |
| 56 | if (FLAG_log_timer_events) { |
| 57 | LOG(isolate_, TimerEvent(Logger::END, TimerEventExternal::name())); |
| 58 | } |
| 59 | TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("v8"), "V8.External"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 60 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | isolate_->set_current_vm_state(previous_tag_); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 62 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 63 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 64 | ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | : isolate_(isolate), |
| 66 | callback_(callback), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 67 | previous_scope_(isolate->external_callback_scope()), |
| 68 | timer_(&isolate->counters()->runtime_call_stats()->ExternalCallback, |
| 69 | isolate->counters()->runtime_call_stats()->current_timer()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 70 | #ifdef USE_SIMULATOR |
| 71 | scope_address_ = Simulator::current(isolate)->get_sp(); |
| 72 | #endif |
| 73 | isolate_->set_external_callback_scope(this); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 74 | if (FLAG_runtime_call_stats) { |
| 75 | isolate_->counters()->runtime_call_stats()->Enter(&timer_); |
| 76 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | ExternalCallbackScope::~ExternalCallbackScope() { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 80 | if (FLAG_runtime_call_stats) { |
| 81 | isolate_->counters()->runtime_call_stats()->Leave(&timer_); |
| 82 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 83 | isolate_->set_external_callback_scope(previous_scope_); |
| 84 | } |
| 85 | |
| 86 | Address ExternalCallbackScope::scope_address() { |
| 87 | #ifdef USE_SIMULATOR |
| 88 | return scope_address_; |
| 89 | #else |
| 90 | return reinterpret_cast<Address>(this); |
| 91 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 94 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | } // namespace internal |
| 96 | } // namespace v8 |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 97 | |
| 98 | #endif // V8_VM_STATE_INL_H_ |