| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_VM_STATE_INL_H_ | 28 #ifndef V8_VM_STATE_INL_H_ |
| 29 #define V8_VM_STATE_INL_H_ | 29 #define V8_VM_STATE_INL_H_ |
| 30 | 30 |
| 31 #include "vm-state.h" | 31 #include "vm-state.h" |
| 32 #include "runtime-profiler.h" |
| 32 | 33 |
| 33 namespace v8 { | 34 namespace v8 { |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 // | 37 // |
| 37 // VMState class implementation. A simple stack of VM states held by the | 38 // VMState class implementation. A simple stack of VM states held by the |
| 38 // logger and partially threaded through the call stack. States are pushed by | 39 // logger and partially threaded through the call stack. States are pushed by |
| 39 // VMState construction and popped by destruction. | 40 // VMState construction and popped by destruction. |
| 40 // | 41 // |
| 41 #ifdef ENABLE_VMSTATE_TRACKING | 42 #ifdef ENABLE_VMSTATE_TRACKING |
| 42 inline const char* StateToString(StateTag state) { | 43 inline const char* StateToString(StateTag state) { |
| 43 switch (state) { | 44 switch (state) { |
| 44 case JS: | 45 case JS: |
| 45 return "JS"; | 46 return "JS"; |
| 46 case GC: | 47 case GC: |
| 47 return "GC"; | 48 return "GC"; |
| 48 case COMPILER: | 49 case COMPILER: |
| 49 return "COMPILER"; | 50 return "COMPILER"; |
| 50 case OTHER: | 51 case OTHER: |
| 51 return "OTHER"; | 52 return "OTHER"; |
| 53 case EXTERNAL: |
| 54 return "EXTERNAL"; |
| 52 default: | 55 default: |
| 53 UNREACHABLE(); | 56 UNREACHABLE(); |
| 54 return NULL; | 57 return NULL; |
| 55 } | 58 } |
| 56 } | 59 } |
| 57 | 60 |
| 58 VMState::VMState(Isolate* isolate, StateTag state) | |
| 59 : isolate_(isolate), | |
| 60 disabled_(true), | |
| 61 state_(OTHER), | |
| 62 external_callback_(NULL) { | |
| 63 ASSERT(isolate == Isolate::Current()); | |
| 64 | 61 |
| 62 VMState::VMState(Isolate* isolate, StateTag tag) |
| 63 : isolate_(isolate), previous_tag_(isolate->current_vm_state()) { |
| 65 #ifdef ENABLE_LOGGING_AND_PROFILING | 64 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 66 if (!isolate_->logger()->is_logging() && | 65 if (FLAG_log_state_changes) { |
| 67 !CpuProfiler::is_profiling(isolate_)) { | 66 LOG(UncheckedStringEvent("Entering", StateToString(tag))); |
| 68 return; | 67 LOG(UncheckedStringEvent("From", StateToString(previous_tag_))); |
| 69 } | 68 } |
| 70 #endif | 69 #endif |
| 71 | 70 |
| 72 disabled_ = false; | 71 isolate_->SetCurrentVMState(tag); |
| 73 #if !defined(ENABLE_HEAP_PROTECTION) | |
| 74 // When not protecting the heap, there is no difference between | |
| 75 // EXTERNAL and OTHER. As an optimization in that case, we will not | |
| 76 // perform EXTERNAL->OTHER transitions through the API. We thus | |
| 77 // compress the two states into one. | |
| 78 if (state == EXTERNAL) state = OTHER; | |
| 79 #endif | |
| 80 state_ = state; | |
| 81 // Save the previous state. | |
| 82 previous_ = isolate_->current_vm_state(); | |
| 83 // Install the new state. | |
| 84 isolate_->set_current_vm_state(this); | |
| 85 | |
| 86 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 87 if (FLAG_log_state_changes) { | |
| 88 LOG(UncheckedStringEvent("Entering", StateToString(state_))); | |
| 89 if (previous_ != NULL) { | |
| 90 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); | |
| 91 } | |
| 92 } | |
| 93 #endif | |
| 94 | 72 |
| 95 #ifdef ENABLE_HEAP_PROTECTION | 73 #ifdef ENABLE_HEAP_PROTECTION |
| 96 if (FLAG_protect_heap) { | 74 if (FLAG_protect_heap) { |
| 97 if (state_ == EXTERNAL) { | 75 if (tag == EXTERNAL) { |
| 98 // We are leaving V8. | 76 // We are leaving V8. |
| 99 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); | 77 ASSERT(previous_tag_ != EXTERNAL); |
| 100 isolate_->heap()->Protect(); | 78 isolate_->heap()->Protect(); |
| 101 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { | 79 } else if (previous_tag_ = EXTERNAL) { |
| 102 // We are entering V8. | 80 // We are entering V8. |
| 103 isolate_->heap()->Unprotect(); | 81 isolate_->heap()->Unprotect(); |
| 104 } | 82 } |
| 105 } | 83 } |
| 106 #endif | 84 #endif |
| 107 } | 85 } |
| 108 | 86 |
| 109 | 87 |
| 110 VMState::~VMState() { | 88 VMState::~VMState() { |
| 111 ASSERT(isolate_ == Isolate::Current()); | |
| 112 if (disabled_) return; | |
| 113 // Return to the previous state. | |
| 114 isolate_->set_current_vm_state(previous_); | |
| 115 | |
| 116 #ifdef ENABLE_LOGGING_AND_PROFILING | 89 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 117 if (FLAG_log_state_changes) { | 90 if (FLAG_log_state_changes) { |
| 118 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); | 91 LOG(UncheckedStringEvent("Leaving", |
| 119 if (previous_ != NULL) { | 92 StateToString(isolate_->current_vm_state()))); |
| 120 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); | 93 LOG(UncheckedStringEvent("To", StateToString(previous_tag_))); |
| 121 } | |
| 122 } | 94 } |
| 123 #endif // ENABLE_LOGGING_AND_PROFILING | 95 #endif // ENABLE_LOGGING_AND_PROFILING |
| 124 | 96 |
| 125 #ifdef ENABLE_HEAP_PROTECTION | 97 #ifdef ENABLE_HEAP_PROTECTION |
| 98 StateTag tag = isolate_->current_vm_state(); |
| 99 #endif |
| 100 |
| 101 isolate_->SetCurrentVMState(previous_tag_); |
| 102 |
| 103 #ifdef ENABLE_HEAP_PROTECTION |
| 126 if (FLAG_protect_heap) { | 104 if (FLAG_protect_heap) { |
| 127 if (state_ == EXTERNAL) { | 105 if (tag == EXTERNAL) { |
| 128 // We are reentering V8. | 106 // We are reentering V8. |
| 129 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); | 107 ASSERT(previous_tag_ != EXTERNAL); |
| 130 isolate_->heap()->Unprotect(); | 108 isolate_->heap()->Unprotect(); |
| 131 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { | 109 } else if (previous_tag_ == EXTERNAL) { |
| 132 // We are leaving V8. | 110 // We are leaving V8. |
| 133 isolate_->heap()->Protect(); | 111 isolate_->heap()->Protect(); |
| 134 } | 112 } |
| 135 } | 113 } |
| 136 #endif // ENABLE_HEAP_PROTECTION | 114 #endif // ENABLE_HEAP_PROTECTION |
| 137 } | 115 } |
| 116 |
| 138 #endif // ENABLE_VMSTATE_TRACKING | 117 #endif // ENABLE_VMSTATE_TRACKING |
| 139 | 118 |
| 119 |
| 120 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 121 |
| 122 ExternalCallbackScope::ExternalCallbackScope(Isolate* isolate, Address callback) |
| 123 : isolate_(isolate), previous_callback_(isolate->external_callback()) { |
| 124 isolate_->set_external_callback(callback); |
| 125 } |
| 126 |
| 127 ExternalCallbackScope::~ExternalCallbackScope() { |
| 128 isolate_->set_external_callback(previous_callback_); |
| 129 } |
| 130 |
| 131 #endif // ENABLE_LOGGING_AND_PROFILING |
| 132 |
| 133 |
| 140 } } // namespace v8::internal | 134 } } // namespace v8::internal |
| 141 | 135 |
| 142 #endif // V8_VM_STATE_INL_H_ | 136 #endif // V8_VM_STATE_INL_H_ |
| OLD | NEW |