1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
37 // 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 // VMState construction and popped by destruction.
41 #ifdef ENABLE_LOGGING_AND_PROFILING
42 inline const char* StateToString(StateTag state) {
58 VMState::VMState(StateTag state) : disabled_(true) {
59 if (!Logger::is_logging()) {
64 #if !defined(ENABLE_HEAP_PROTECTION)
65 // When not protecting the heap, there is no difference between
66 // EXTERNAL and OTHER. As an optimization in that case, we will not
67 // perform EXTERNAL->OTHER transitions through the API. We thus
68 // compress the two states into one.
69 if (state == EXTERNAL) state = OTHER;
72 previous_ = Logger::current_state_;
73 Logger::current_state_ = this;
75 if (FLAG_log_state_changes) {
76 LOG(UncheckedStringEvent("Entering", StateToString(state_)));
77 if (previous_ != NULL) {
78 LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
82 #ifdef ENABLE_HEAP_PROTECTION
83 if (FLAG_protect_heap && previous_ != NULL) {
84 if (state_ == EXTERNAL) {
86 ASSERT(previous_->state_ != EXTERNAL);
88 } else if (previous_->state_ == EXTERNAL) {
89 // We are entering V8.
98 if (disabled_) return;
99 Logger::current_state_ = previous_;
101 if (FLAG_log_state_changes) {
102 LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
103 if (previous_ != NULL) {
104 LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
108 #ifdef ENABLE_HEAP_PROTECTION
109 if (FLAG_protect_heap && previous_ != NULL) {
110 if (state_ == EXTERNAL) {
111 // We are reentering V8.
112 ASSERT(previous_->state_ != EXTERNAL);
114 } else if (previous_->state_ == EXTERNAL) {
115 // We are leaving V8.
124 } } // namespace v8::internal
126 #endif // V8_LOG_INL_H_