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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 disabled_ = false; | 68 disabled_ = false; |
69 #if !defined(ENABLE_HEAP_PROTECTION) | 69 #if !defined(ENABLE_HEAP_PROTECTION) |
70 // When not protecting the heap, there is no difference between | 70 // When not protecting the heap, there is no difference between |
71 // EXTERNAL and OTHER. As an optimization in that case, we will not | 71 // EXTERNAL and OTHER. As an optimization in that case, we will not |
72 // perform EXTERNAL->OTHER transitions through the API. We thus | 72 // perform EXTERNAL->OTHER transitions through the API. We thus |
73 // compress the two states into one. | 73 // compress the two states into one. |
74 if (state == EXTERNAL) state = OTHER; | 74 if (state == EXTERNAL) state = OTHER; |
75 #endif | 75 #endif |
76 state_ = state; | 76 state_ = state; |
77 // Save the previous state. | 77 // Save the previous state. |
78 previous_ = reinterpret_cast<VMState*>(current_state_); | 78 previous_ = Top::current_vm_state(); |
79 // Install the new state. | 79 // Install the new state. |
80 OS::ReleaseStore(¤t_state_, reinterpret_cast<AtomicWord>(this)); | 80 Top::set_current_vm_state(this); |
81 | 81 |
82 #ifdef ENABLE_LOGGING_AND_PROFILING | 82 #ifdef ENABLE_LOGGING_AND_PROFILING |
83 if (FLAG_log_state_changes) { | 83 if (FLAG_log_state_changes) { |
84 LOG(UncheckedStringEvent("Entering", StateToString(state_))); | 84 LOG(UncheckedStringEvent("Entering", StateToString(state_))); |
85 if (previous_ != NULL) { | 85 if (previous_ != NULL) { |
86 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); | 86 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); |
87 } | 87 } |
88 } | 88 } |
89 #endif | 89 #endif |
90 | 90 |
91 #ifdef ENABLE_HEAP_PROTECTION | 91 #ifdef ENABLE_HEAP_PROTECTION |
92 if (FLAG_protect_heap) { | 92 if (FLAG_protect_heap) { |
93 if (state_ == EXTERNAL) { | 93 if (state_ == EXTERNAL) { |
94 // We are leaving V8. | 94 // We are leaving V8. |
95 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); | 95 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); |
96 Heap::Protect(); | 96 Heap::Protect(); |
97 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { | 97 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { |
98 // We are entering V8. | 98 // We are entering V8. |
99 Heap::Unprotect(); | 99 Heap::Unprotect(); |
100 } | 100 } |
101 } | 101 } |
102 #endif | 102 #endif |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 VMState::~VMState() { | 106 VMState::~VMState() { |
107 if (disabled_) return; | 107 if (disabled_) return; |
108 // Return to the previous state. | 108 // Return to the previous state. |
109 OS::ReleaseStore(¤t_state_, reinterpret_cast<AtomicWord>(previous_)); | 109 Top::set_current_vm_state(previous_); |
110 | 110 |
111 #ifdef ENABLE_LOGGING_AND_PROFILING | 111 #ifdef ENABLE_LOGGING_AND_PROFILING |
112 if (FLAG_log_state_changes) { | 112 if (FLAG_log_state_changes) { |
113 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); | 113 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); |
114 if (previous_ != NULL) { | 114 if (previous_ != NULL) { |
115 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); | 115 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); |
116 } | 116 } |
117 } | 117 } |
118 #endif // ENABLE_LOGGING_AND_PROFILING | 118 #endif // ENABLE_LOGGING_AND_PROFILING |
119 | 119 |
120 #ifdef ENABLE_HEAP_PROTECTION | 120 #ifdef ENABLE_HEAP_PROTECTION |
121 if (FLAG_protect_heap) { | 121 if (FLAG_protect_heap) { |
122 if (state_ == EXTERNAL) { | 122 if (state_ == EXTERNAL) { |
123 // We are reentering V8. | 123 // We are reentering V8. |
124 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); | 124 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); |
125 Heap::Unprotect(); | 125 Heap::Unprotect(); |
126 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { | 126 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { |
127 // We are leaving V8. | 127 // We are leaving V8. |
128 Heap::Protect(); | 128 Heap::Protect(); |
129 } | 129 } |
130 } | 130 } |
131 #endif // ENABLE_HEAP_PROTECTION | 131 #endif // ENABLE_HEAP_PROTECTION |
132 } | 132 } |
133 #endif // ENABLE_VMSTATE_TRACKING | 133 #endif // ENABLE_VMSTATE_TRACKING |
134 | 134 |
135 } } // namespace v8::internal | 135 } } // namespace v8::internal |
136 | 136 |
137 #endif // V8_VM_STATE_INL_H_ | 137 #endif // V8_VM_STATE_INL_H_ |
OLD | NEW |