Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: src/vm-state-inl.h

Issue 2852047: Fix concurrent access to VMState::current_state_. (Closed)
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/vm-state.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
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 previous_ = current_state_; // Save the previous state. 77 // Save the previous state.
78 current_state_ = this; // Install the new state. 78 previous_ = reinterpret_cast<VMState*>(current_state_);
79 // Install the new state.
80 OS::ReleaseStore(&current_state_, reinterpret_cast<AtomicWord>(this));
79 81
80 #ifdef ENABLE_LOGGING_AND_PROFILING 82 #ifdef ENABLE_LOGGING_AND_PROFILING
81 if (FLAG_log_state_changes) { 83 if (FLAG_log_state_changes) {
82 LOG(UncheckedStringEvent("Entering", StateToString(state_))); 84 LOG(UncheckedStringEvent("Entering", StateToString(state_)));
83 if (previous_ != NULL) { 85 if (previous_ != NULL) {
84 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); 86 LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
85 } 87 }
86 } 88 }
87 #endif 89 #endif
88 90
89 #ifdef ENABLE_HEAP_PROTECTION 91 #ifdef ENABLE_HEAP_PROTECTION
90 if (FLAG_protect_heap) { 92 if (FLAG_protect_heap) {
91 if (state_ == EXTERNAL) { 93 if (state_ == EXTERNAL) {
92 // We are leaving V8. 94 // We are leaving V8.
93 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); 95 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL));
94 Heap::Protect(); 96 Heap::Protect();
95 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { 97 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) {
96 // We are entering V8. 98 // We are entering V8.
97 Heap::Unprotect(); 99 Heap::Unprotect();
98 } 100 }
99 } 101 }
100 #endif 102 #endif
101 } 103 }
102 104
103 105
104 VMState::~VMState() { 106 VMState::~VMState() {
105 if (disabled_) return; 107 if (disabled_) return;
106 current_state_ = previous_; // Return to the previous state. 108 // Return to the previous state.
109 OS::ReleaseStore(&current_state_, reinterpret_cast<AtomicWord>(previous_));
107 110
108 #ifdef ENABLE_LOGGING_AND_PROFILING 111 #ifdef ENABLE_LOGGING_AND_PROFILING
109 if (FLAG_log_state_changes) { 112 if (FLAG_log_state_changes) {
110 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); 113 LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
111 if (previous_ != NULL) { 114 if (previous_ != NULL) {
112 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); 115 LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
113 } 116 }
114 } 117 }
115 #endif // ENABLE_LOGGING_AND_PROFILING 118 #endif // ENABLE_LOGGING_AND_PROFILING
116 119
117 #ifdef ENABLE_HEAP_PROTECTION 120 #ifdef ENABLE_HEAP_PROTECTION
118 if (FLAG_protect_heap) { 121 if (FLAG_protect_heap) {
119 if (state_ == EXTERNAL) { 122 if (state_ == EXTERNAL) {
120 // We are reentering V8. 123 // We are reentering V8.
121 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL)); 124 ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL));
122 Heap::Unprotect(); 125 Heap::Unprotect();
123 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) { 126 } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) {
124 // We are leaving V8. 127 // We are leaving V8.
125 Heap::Protect(); 128 Heap::Protect();
126 } 129 }
127 } 130 }
128 #endif // ENABLE_HEAP_PROTECTION 131 #endif // ENABLE_HEAP_PROTECTION
129 } 132 }
130 #endif // ENABLE_VMSTATE_TRACKING 133 #endif // ENABLE_VMSTATE_TRACKING
131 134
132 } } // namespace v8::internal 135 } } // namespace v8::internal
133 136
134 #endif // V8_VM_STATE_INL_H_ 137 #endif // V8_VM_STATE_INL_H_
OLDNEW
« no previous file with comments | « src/vm-state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698