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.
32 #include "cpu-profiler.h"
38 // VMState class implementation. A simple stack of VM states held by the
39 // logger and partially threaded through the call stack. States are pushed by
40 // VMState construction and popped by destruction.
42 #ifdef ENABLE_LOGGING_AND_PROFILING
43 inline const char* StateToString(StateTag state) {
59 VMState::VMState(StateTag state)
62 external_callback_(NULL) {
63 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) {
68 #if !defined(ENABLE_HEAP_PROTECTION)
69 // When not protecting the heap, there is no difference between
70 // EXTERNAL and OTHER. As an optimization in that case, we will not
71 // perform EXTERNAL->OTHER transitions through the API. We thus
72 // compress the two states into one.
73 if (state == EXTERNAL) state = OTHER;
76 previous_ = Logger::current_state_;
77 Logger::current_state_ = this;
79 if (FLAG_log_state_changes) {
80 LOG(UncheckedStringEvent("Entering", StateToString(state_)));
81 if (previous_ != NULL) {
82 LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
86 #ifdef ENABLE_HEAP_PROTECTION
87 if (FLAG_protect_heap && previous_ != NULL) {
88 if (state_ == EXTERNAL) {
90 ASSERT(previous_->state_ != EXTERNAL);
92 } else if (previous_->state_ == EXTERNAL) {
93 // We are entering V8.
101 VMState::~VMState() {
102 if (disabled_) return;
103 Logger::current_state_ = previous_;
105 if (FLAG_log_state_changes) {
106 LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
107 if (previous_ != NULL) {
108 LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
112 #ifdef ENABLE_HEAP_PROTECTION
113 if (FLAG_protect_heap && previous_ != NULL) {
114 if (state_ == EXTERNAL) {
115 // We are reentering V8.
116 ASSERT(previous_->state_ != EXTERNAL);
118 } else if (previous_->state_ == EXTERNAL) {
119 // We are leaving V8.
126 Logger::LogEventsAndTags Logger::ToNativeByScript(Logger::LogEventsAndTags tag,
128 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
129 if ((tag == FUNCTION_TAG || tag == LAZY_COMPILE_TAG || tag == SCRIPT_TAG)
130 && script->type()->value() == Script::TYPE_NATIVE) {
132 case FUNCTION_TAG: return NATIVE_FUNCTION_TAG;
133 case LAZY_COMPILE_TAG: return NATIVE_LAZY_COMPILE_TAG;
134 case SCRIPT_TAG: return NATIVE_SCRIPT_TAG;
148 } } // namespace v8::internal
150 #endif // V8_LOG_INL_H_