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

Side by Side Diff: src/execution.h

Issue 264233005: Clean up stack guard interrupts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/debug.cc ('k') | src/execution.cc » ('j') | src/execution.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_EXECUTION_H_ 5 #ifndef V8_EXECUTION_H_
6 #define V8_EXECUTION_H_ 6 #define V8_EXECUTION_H_
7 7
8 #include "handles.h" 8 #include "handles.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 // Flag used to set the interrupt causes.
14 enum InterruptFlag {
15 INTERRUPT = 1 << 0,
16 DEBUGBREAK = 1 << 1,
17 DEBUGCOMMAND = 1 << 2,
18 PREEMPT = 1 << 3,
19 TERMINATE = 1 << 4,
20 GC_REQUEST = 1 << 5,
21 FULL_DEOPT = 1 << 6,
22 INSTALL_CODE = 1 << 7,
23 API_INTERRUPT = 1 << 8,
24 DEOPT_MARKED_ALLOCATION_SITES = 1 << 9
25 };
26
27
28 class Execution V8_FINAL : public AllStatic { 13 class Execution V8_FINAL : public AllStatic {
29 public: 14 public:
30 // Call a function, the caller supplies a receiver and an array 15 // Call a function, the caller supplies a receiver and an array
31 // of arguments. Arguments are Object* type. After function returns, 16 // of arguments. Arguments are Object* type. After function returns,
32 // pointers in 'args' might be invalid. 17 // pointers in 'args' might be invalid.
33 // 18 //
34 // *pending_exception tells whether the invoke resulted in 19 // *pending_exception tells whether the invoke resulted in
35 // a pending exception. 20 // a pending exception.
36 // 21 //
37 // When convert_receiver is set, and the receiver is not an object, 22 // When convert_receiver is set, and the receiver is not an object,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 Handle<FunctionTemplateInfo> data); 97 Handle<FunctionTemplateInfo> data);
113 MUST_USE_RESULT static MaybeHandle<JSObject> InstantiateObject( 98 MUST_USE_RESULT static MaybeHandle<JSObject> InstantiateObject(
114 Handle<ObjectTemplateInfo> data); 99 Handle<ObjectTemplateInfo> data);
115 MUST_USE_RESULT static MaybeHandle<Object> ConfigureInstance( 100 MUST_USE_RESULT static MaybeHandle<Object> ConfigureInstance(
116 Isolate* isolate, Handle<Object> instance, Handle<Object> data); 101 Isolate* isolate, Handle<Object> instance, Handle<Object> data);
117 static Handle<String> GetStackTraceLine(Handle<Object> recv, 102 static Handle<String> GetStackTraceLine(Handle<Object> recv,
118 Handle<JSFunction> fun, 103 Handle<JSFunction> fun,
119 Handle<Object> pos, 104 Handle<Object> pos,
120 Handle<Object> is_global); 105 Handle<Object> is_global);
121 106
122 static Object* DebugBreakHelper(Isolate* isolate); 107 static void DebugBreakHelper(Isolate* isolate);
123 static void ProcessDebugMessages(Isolate* isolate, bool debug_command_only); 108 static void ProcessDebugMessages(Isolate* isolate, bool debug_command_only);
124 109
125 // If the stack guard is triggered, but it is not an actual
126 // stack overflow, then handle the interruption accordingly.
127 static Object* HandleStackGuardInterrupt(Isolate* isolate);
128
129 // Get a function delegate (or undefined) for the given non-function 110 // Get a function delegate (or undefined) for the given non-function
130 // object. Used for support calling objects as functions. 111 // object. Used for support calling objects as functions.
131 static Handle<Object> GetFunctionDelegate(Isolate* isolate, 112 static Handle<Object> GetFunctionDelegate(Isolate* isolate,
132 Handle<Object> object); 113 Handle<Object> object);
133 MUST_USE_RESULT static MaybeHandle<Object> TryGetFunctionDelegate( 114 MUST_USE_RESULT static MaybeHandle<Object> TryGetFunctionDelegate(
134 Isolate* isolate, 115 Isolate* isolate,
135 Handle<Object> object); 116 Handle<Object> object);
136 117
137 // Get a function delegate (or undefined) for the given non-function 118 // Get a function delegate (or undefined) for the given non-function
138 // object. Used for support calling objects as constructors. 119 // object. Used for support calling objects as constructors.
(...skipping 25 matching lines...) Expand all
164 static int ArchiveSpacePerThread() { return sizeof(ThreadLocal); } 145 static int ArchiveSpacePerThread() { return sizeof(ThreadLocal); }
165 void FreeThreadResources(); 146 void FreeThreadResources();
166 // Sets up the default stack guard for this thread if it has not 147 // Sets up the default stack guard for this thread if it has not
167 // already been set up. 148 // already been set up.
168 void InitThread(const ExecutionAccess& lock); 149 void InitThread(const ExecutionAccess& lock);
169 // Clears the stack guard for this thread so it does not look as if 150 // Clears the stack guard for this thread so it does not look as if
170 // it has been set up. 151 // it has been set up.
171 void ClearThread(const ExecutionAccess& lock); 152 void ClearThread(const ExecutionAccess& lock);
172 153
173 bool IsStackOverflow(); 154 bool IsStackOverflow();
174 bool IsPreempted();
175 void Preempt();
176 bool IsInterrupted();
177 void Interrupt();
178 bool IsTerminateExecution();
179 void TerminateExecution();
180 void CancelTerminateExecution();
181 bool IsDebugBreak();
182 void DebugBreak();
183 bool IsDebugCommand();
184 void DebugCommand();
185 bool IsGCRequest();
186 void RequestGC();
187 bool IsInstallCodeRequest();
188 void RequestInstallCode();
189 bool IsFullDeopt();
190 void FullDeopt();
191 bool IsDeoptMarkedAllocationSites();
192 void DeoptMarkedAllocationSites();
193 void Continue(InterruptFlag after_what);
194 155
195 void RequestInterrupt(InterruptCallback callback, void* data); 156 #define INTERRUPT_LIST(V) \
196 void ClearInterrupt(); 157 V(DEBUGBREAK, DebugBreak) \
197 bool IsAPIInterrupt(); 158 V(DEBUGCOMMAND, DebugCommand) \
198 void InvokeInterruptCallback(); 159 V(TERMINATE_EXECUTION, TerminateExecution) \
160 V(GC_REQUEST, GC) \
161 V(FULL_DEOPT, FullDeopt) \
162 V(INSTALL_CODE, InstallCode) \
163 V(API_INTERRUPT, ApiInterrupt) \
164 V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites)
165
166 #define V(NAME, Name) \
167 inline bool Check##Name() { return CheckInterrupt(1 << NAME); } \
168 inline void Request##Name() { RequestInterrupt(1 << NAME); } \
169 inline void Clear##Name() { ClearInterrupt(1 << NAME); }
170 INTERRUPT_LIST(V)
171 #undef V
199 172
200 // This provides an asynchronous read of the stack limits for the current 173 // This provides an asynchronous read of the stack limits for the current
201 // thread. There are no locks protecting this, but it is assumed that you 174 // thread. There are no locks protecting this, but it is assumed that you
202 // have the global V8 lock if you are using multiple V8 threads. 175 // have the global V8 lock if you are using multiple V8 threads.
203 uintptr_t climit() { 176 uintptr_t climit() {
204 return thread_local_.climit_; 177 return thread_local_.climit_;
205 } 178 }
206 uintptr_t real_climit() { 179 uintptr_t real_climit() {
207 return thread_local_.real_climit_; 180 return thread_local_.real_climit_;
208 } 181 }
209 uintptr_t jslimit() { 182 uintptr_t jslimit() {
210 return thread_local_.jslimit_; 183 return thread_local_.jslimit_;
211 } 184 }
212 uintptr_t real_jslimit() { 185 uintptr_t real_jslimit() {
213 return thread_local_.real_jslimit_; 186 return thread_local_.real_jslimit_;
214 } 187 }
215 Address address_of_jslimit() { 188 Address address_of_jslimit() {
216 return reinterpret_cast<Address>(&thread_local_.jslimit_); 189 return reinterpret_cast<Address>(&thread_local_.jslimit_);
217 } 190 }
218 Address address_of_real_jslimit() { 191 Address address_of_real_jslimit() {
219 return reinterpret_cast<Address>(&thread_local_.real_jslimit_); 192 return reinterpret_cast<Address>(&thread_local_.real_jslimit_);
220 } 193 }
221 bool ShouldPostponeInterrupts(); 194
195 // If the stack guard is triggered, but it is not an actual
196 // stack overflow, then handle the interruption accordingly.
197 Object* HandleInterrupts();
222 198
223 private: 199 private:
224 StackGuard(); 200 StackGuard();
225 201
202 // Flag used to set the interrupt causes.
203 enum InterruptFlag {
204 #define V(NAME, Name) NAME,
205 INTERRUPT_LIST(V)
206 #undef V
207 NUMBER_OF_INTERRUPTS
208 };
209
210 bool CheckInterrupt(int flagbit);
211 void RequestInterrupt(int flagbit);
212 void ClearInterrupt(int flagbit);
213 bool CheckAndClearInterrupt(InterruptFlag flag, const ExecutionAccess& lock);
214
215 void InvokeApiInterruptCallback();
216
226 // You should hold the ExecutionAccess lock when calling this method. 217 // You should hold the ExecutionAccess lock when calling this method.
227 bool has_pending_interrupts(const ExecutionAccess& lock) { 218 bool has_pending_interrupts(const ExecutionAccess& lock) {
228 // Sanity check: We shouldn't be asking about pending interrupts 219 // Sanity check: We shouldn't be asking about pending interrupts
229 // unless we're not postponing them anymore. 220 // unless we're not postponing them anymore.
230 ASSERT(!should_postpone_interrupts(lock)); 221 ASSERT(!should_postpone_interrupts(lock));
231 return thread_local_.interrupt_flags_ != 0; 222 return thread_local_.interrupt_flags_ != 0;
232 } 223 }
233 224
234 // You should hold the ExecutionAccess lock when calling this method. 225 // You should hold the ExecutionAccess lock when calling this method.
235 bool should_postpone_interrupts(const ExecutionAccess& lock) { 226 bool should_postpone_interrupts(const ExecutionAccess& lock) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // fail. Both the generated code and the runtime system check against the 266 // fail. Both the generated code and the runtime system check against the
276 // one without the real_ prefix. 267 // one without the real_ prefix.
277 uintptr_t real_jslimit_; // Actual JavaScript stack limit set for the VM. 268 uintptr_t real_jslimit_; // Actual JavaScript stack limit set for the VM.
278 uintptr_t jslimit_; 269 uintptr_t jslimit_;
279 uintptr_t real_climit_; // Actual C++ stack limit set for the VM. 270 uintptr_t real_climit_; // Actual C++ stack limit set for the VM.
280 uintptr_t climit_; 271 uintptr_t climit_;
281 272
282 int nesting_; 273 int nesting_;
283 int postpone_interrupts_nesting_; 274 int postpone_interrupts_nesting_;
284 int interrupt_flags_; 275 int interrupt_flags_;
285
286 InterruptCallback interrupt_callback_;
287 void* interrupt_callback_data_;
288 }; 276 };
289 277
290 // TODO(isolates): Technically this could be calculated directly from a 278 // TODO(isolates): Technically this could be calculated directly from a
291 // pointer to StackGuard. 279 // pointer to StackGuard.
292 Isolate* isolate_; 280 Isolate* isolate_;
293 ThreadLocal thread_local_; 281 ThreadLocal thread_local_;
294 282
295 friend class Isolate; 283 friend class Isolate;
296 friend class StackLimitCheck; 284 friend class StackLimitCheck;
297 friend class PostponeInterruptsScope; 285 friend class PostponeInterruptsScope;
298 286
299 DISALLOW_COPY_AND_ASSIGN(StackGuard); 287 DISALLOW_COPY_AND_ASSIGN(StackGuard);
300 }; 288 };
301 289
302 } } // namespace v8::internal 290 } } // namespace v8::internal
303 291
304 #endif // V8_EXECUTION_H_ 292 #endif // V8_EXECUTION_H_
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/execution.cc » ('j') | src/execution.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698