| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 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 21 matching lines...) Expand all Loading... |
| 32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
| 33 #include "global-handles.h" | 33 #include "global-handles.h" |
| 34 #include "log.h" | 34 #include "log.h" |
| 35 #include "macro-assembler.h" | 35 #include "macro-assembler.h" |
| 36 #include "serialize.h" | 36 #include "serialize.h" |
| 37 #include "string-stream.h" | 37 #include "string-stream.h" |
| 38 | 38 |
| 39 namespace v8 { | 39 namespace v8 { |
| 40 namespace internal { | 40 namespace internal { |
| 41 | 41 |
| 42 // |
| 43 // VMState class implementation. A simple stack of VM states held by the |
| 44 // logger and partially threaded through the call stack. States are pushed by |
| 45 // VMState construction and popped by destruction. |
| 46 // |
| 47 |
| 42 #ifdef ENABLE_LOGGING_AND_PROFILING | 48 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 43 | 49 |
| 50 static const char* StateToString(StateTag state) { |
| 51 switch (state) { |
| 52 case JS: |
| 53 return "JS"; |
| 54 case GC: |
| 55 return "GC"; |
| 56 case COMPILER: |
| 57 return "COMPILER"; |
| 58 case OTHER: |
| 59 return "OTHER"; |
| 60 default: |
| 61 UNREACHABLE(); |
| 62 return NULL; |
| 63 } |
| 64 } |
| 65 |
| 66 |
| 67 void VMState::Initialize(StateTag state) { |
| 68 ASSERT(Logger::is_logging()); |
| 69 |
| 70 disabled_ = false; |
| 71 #if !defined(ENABLE_HEAP_PROTECTION) |
| 72 // When not protecting the heap, there is no difference between |
| 73 // EXTERNAL and OTHER. As an optimization in that case, we will not |
| 74 // perform EXTERNAL->OTHER transitions through the API. We thus |
| 75 // compress the two states into one. |
| 76 if (state == EXTERNAL) state = OTHER; |
| 77 #endif |
| 78 state_ = state; |
| 79 previous_ = Logger::current_state_; |
| 80 Logger::current_state_ = this; |
| 81 |
| 82 if (FLAG_log_state_changes) { |
| 83 LOG(UncheckedStringEvent("Entering", StateToString(state_))); |
| 84 if (previous_ != NULL) { |
| 85 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); |
| 86 } |
| 87 } |
| 88 |
| 89 #ifdef ENABLE_HEAP_PROTECTION |
| 90 if (FLAG_protect_heap && previous_ != NULL) { |
| 91 if (state_ == EXTERNAL) { |
| 92 // We are leaving V8. |
| 93 ASSERT(previous_->state_ != EXTERNAL); |
| 94 Heap::Protect(); |
| 95 } else if (previous_->state_ == EXTERNAL) { |
| 96 // We are entering V8. |
| 97 Heap::Unprotect(); |
| 98 } |
| 99 } |
| 100 #endif |
| 101 } |
| 102 |
| 103 |
| 104 void VMState::Destroy() { |
| 105 ASSERT(!disabled_); |
| 106 Logger::current_state_ = previous_; |
| 107 |
| 108 if (FLAG_log_state_changes) { |
| 109 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); |
| 110 if (previous_ != NULL) { |
| 111 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); |
| 112 } |
| 113 } |
| 114 |
| 115 #ifdef ENABLE_HEAP_PROTECTION |
| 116 if (FLAG_protect_heap && previous_ != NULL) { |
| 117 if (state_ == EXTERNAL) { |
| 118 // We are reentering V8. |
| 119 ASSERT(previous_->state_ != EXTERNAL); |
| 120 Heap::Unprotect(); |
| 121 } else if (previous_->state_ == EXTERNAL) { |
| 122 // We are leaving V8. |
| 123 Heap::Protect(); |
| 124 } |
| 125 } |
| 126 #endif |
| 127 } |
| 128 |
| 44 // | 129 // |
| 45 // Sliding state window. Updates counters to keep track of the last | 130 // Sliding state window. Updates counters to keep track of the last |
| 46 // window of kBufferSize states. This is useful to track where we | 131 // window of kBufferSize states. This is useful to track where we |
| 47 // spent our time. | 132 // spent our time. |
| 48 // | 133 // |
| 49 class SlidingStateWindow { | 134 class SlidingStateWindow { |
| 50 public: | 135 public: |
| 51 SlidingStateWindow(); | 136 SlidingStateWindow(); |
| 52 ~SlidingStateWindow(); | 137 ~SlidingStateWindow(); |
| 53 void AddState(StateTag state); | 138 void AddState(StateTag state); |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 // Otherwise, if the sliding state window computation has not been | 1617 // Otherwise, if the sliding state window computation has not been |
| 1533 // started we do it now. | 1618 // started we do it now. |
| 1534 if (sliding_state_window_ == NULL) { | 1619 if (sliding_state_window_ == NULL) { |
| 1535 sliding_state_window_ = new SlidingStateWindow(); | 1620 sliding_state_window_ = new SlidingStateWindow(); |
| 1536 } | 1621 } |
| 1537 #endif | 1622 #endif |
| 1538 } | 1623 } |
| 1539 | 1624 |
| 1540 | 1625 |
| 1541 } } // namespace v8::internal | 1626 } } // namespace v8::internal |
| OLD | NEW |