OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #ifndef V8_LOG_INL_H_ | 28 #ifndef V8_LOG_INL_H_ |
29 #define V8_LOG_INL_H_ | 29 #define V8_LOG_INL_H_ |
30 | 30 |
31 #include "log.h" | 31 #include "log.h" |
32 #include "cpu-profiler.h" | 32 #include "cpu-profiler.h" |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 // | |
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. | |
41 // | |
42 #ifdef ENABLE_LOGGING_AND_PROFILING | 37 #ifdef ENABLE_LOGGING_AND_PROFILING |
43 inline const char* StateToString(StateTag state) { | |
44 switch (state) { | |
45 case JS: | |
46 return "JS"; | |
47 case GC: | |
48 return "GC"; | |
49 case COMPILER: | |
50 return "COMPILER"; | |
51 case OTHER: | |
52 return "OTHER"; | |
53 default: | |
54 UNREACHABLE(); | |
55 return NULL; | |
56 } | |
57 } | |
58 | |
59 VMState::VMState(StateTag state) | |
60 : disabled_(true), | |
61 state_(OTHER), | |
62 external_callback_(NULL) { | |
63 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) { | |
64 return; | |
65 } | |
66 | |
67 disabled_ = false; | |
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; | |
74 #endif | |
75 state_ = state; | |
76 previous_ = Logger::current_state_; | |
77 Logger::current_state_ = this; | |
78 | |
79 if (FLAG_log_state_changes) { | |
80 LOG(UncheckedStringEvent("Entering", StateToString(state_))); | |
81 if (previous_ != NULL) { | |
82 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); | |
83 } | |
84 } | |
85 | |
86 #ifdef ENABLE_HEAP_PROTECTION | |
87 if (FLAG_protect_heap && previous_ != NULL) { | |
88 if (state_ == EXTERNAL) { | |
89 // We are leaving V8. | |
90 ASSERT(previous_->state_ != EXTERNAL); | |
91 Heap::Protect(); | |
92 } else if (previous_->state_ == EXTERNAL) { | |
93 // We are entering V8. | |
94 Heap::Unprotect(); | |
95 } | |
96 } | |
97 #endif | |
98 } | |
99 | |
100 | |
101 VMState::~VMState() { | |
102 if (disabled_) return; | |
103 Logger::current_state_ = previous_; | |
104 | |
105 if (FLAG_log_state_changes) { | |
106 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); | |
107 if (previous_ != NULL) { | |
108 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); | |
109 } | |
110 } | |
111 | |
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); | |
117 Heap::Unprotect(); | |
118 } else if (previous_->state_ == EXTERNAL) { | |
119 // We are leaving V8. | |
120 Heap::Protect(); | |
121 } | |
122 } | |
123 #endif | |
124 } | |
125 | 38 |
126 Logger::LogEventsAndTags Logger::ToNativeByScript(Logger::LogEventsAndTags tag, | 39 Logger::LogEventsAndTags Logger::ToNativeByScript(Logger::LogEventsAndTags tag, |
127 Script* script) { | 40 Script* script) { |
128 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 41 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
129 if ((tag == FUNCTION_TAG || tag == LAZY_COMPILE_TAG || tag == SCRIPT_TAG) | 42 if ((tag == FUNCTION_TAG || tag == LAZY_COMPILE_TAG || tag == SCRIPT_TAG) |
130 && script->type()->value() == Script::TYPE_NATIVE) { | 43 && script->type()->value() == Script::TYPE_NATIVE) { |
131 switch (tag) { | 44 switch (tag) { |
132 case FUNCTION_TAG: return NATIVE_FUNCTION_TAG; | 45 case FUNCTION_TAG: return NATIVE_FUNCTION_TAG; |
133 case LAZY_COMPILE_TAG: return NATIVE_LAZY_COMPILE_TAG; | 46 case LAZY_COMPILE_TAG: return NATIVE_LAZY_COMPILE_TAG; |
134 case SCRIPT_TAG: return NATIVE_SCRIPT_TAG; | 47 case SCRIPT_TAG: return NATIVE_SCRIPT_TAG; |
135 default: return tag; | 48 default: return tag; |
136 } | 49 } |
137 } else { | 50 } else { |
138 return tag; | 51 return tag; |
139 } | 52 } |
140 #else | 53 #else |
141 return tag; | 54 return tag; |
142 #endif | 55 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
143 } | 56 } |
144 | 57 |
145 #endif | 58 #endif // ENABLE_LOGGING_AND_PROFILING |
146 | 59 |
147 | 60 |
148 } } // namespace v8::internal | 61 } } // namespace v8::internal |
149 | 62 |
150 #endif // V8_LOG_INL_H_ | 63 #endif // V8_LOG_INL_H_ |
OLD | NEW |