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

Side by Side Diff: src/execution.h

Issue 242074: Fix the stack limits setting API so it is usable. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 2 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/compiler.cc ('k') | src/execution.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 // Get a function delegate (or undefined) for the given non-function 135 // Get a function delegate (or undefined) for the given non-function
136 // object. Used for support calling objects as constructors. 136 // object. Used for support calling objects as constructors.
137 static Handle<Object> GetConstructorDelegate(Handle<Object> object); 137 static Handle<Object> GetConstructorDelegate(Handle<Object> object);
138 }; 138 };
139 139
140 140
141 class ExecutionAccess; 141 class ExecutionAccess;
142 142
143 143
144 // Stack guards are used to limit the number of nested invocations of 144 // StackGuard contains the handling of the limits that are used to limit the
145 // JavaScript and the stack size used in each invocation. 145 // number of nested invocations of JavaScript and the stack size used in each
146 class StackGuard BASE_EMBEDDED { 146 // invocation.
147 class StackGuard : public AllStatic {
147 public: 148 public:
148 StackGuard(); 149 // Pass the address beyond which the stack should not grow. The stack
149 150 // is assumed to grow downwards.
150 ~StackGuard();
151
152 static void SetStackLimit(uintptr_t limit); 151 static void SetStackLimit(uintptr_t limit);
153 152
154 static Address address_of_jslimit() { 153 static Address address_of_jslimit() {
155 return reinterpret_cast<Address>(&thread_local_.jslimit_); 154 return reinterpret_cast<Address>(&thread_local_.jslimit_);
156 } 155 }
157 156
158 // Threading support. 157 // Threading support.
159 static char* ArchiveStackGuard(char* to); 158 static char* ArchiveStackGuard(char* to);
160 static char* RestoreStackGuard(char* from); 159 static char* RestoreStackGuard(char* from);
161 static int ArchiveSpacePerThread(); 160 static int ArchiveSpacePerThread();
162 static void FreeThreadResources(); 161 static void FreeThreadResources();
162 // Sets up the default stack guard for this thread if it has not
163 // already been set up.
164 static void InitThread(const ExecutionAccess& lock);
165 // Clears the stack guard for this thread so it does not look as if
166 // it has been set up.
167 static void ClearThread(const ExecutionAccess& lock);
163 168
164 static bool IsStackOverflow(); 169 static bool IsStackOverflow();
165 static bool IsPreempted(); 170 static bool IsPreempted();
166 static void Preempt(); 171 static void Preempt();
167 static bool IsInterrupted(); 172 static bool IsInterrupted();
168 static void Interrupt(); 173 static void Interrupt();
169 static bool IsTerminateExecution(); 174 static bool IsTerminateExecution();
170 static void TerminateExecution(); 175 static void TerminateExecution();
171 #ifdef ENABLE_DEBUGGER_SUPPORT 176 #ifdef ENABLE_DEBUGGER_SUPPORT
172 static bool IsDebugBreak(); 177 static bool IsDebugBreak();
173 static void DebugBreak(); 178 static void DebugBreak();
174 static bool IsDebugCommand(); 179 static bool IsDebugCommand();
175 static void DebugCommand(); 180 static void DebugCommand();
176 #endif 181 #endif
177 static void Continue(InterruptFlag after_what); 182 static void Continue(InterruptFlag after_what);
178 183
184 // This provides an asynchronous read of the stack limit for the current
185 // thread. There are no locks protecting this, but it is assumed that you
186 // have the global V8 lock if you are using multiple V8 threads.
187 static uintptr_t climit() {
188 return thread_local_.climit_;
189 }
190
179 static uintptr_t jslimit() { 191 static uintptr_t jslimit() {
180 return thread_local_.jslimit_; 192 return thread_local_.jslimit_;
181 } 193 }
182 194
183 private: 195 private:
184 // You should hold the ExecutionAccess lock when calling this method. 196 // You should hold the ExecutionAccess lock when calling this method.
185 static bool IsSet(const ExecutionAccess& lock); 197 static bool IsSet(const ExecutionAccess& lock);
186 198
187 // This provides an asynchronous read of the stack limit for the current
188 // thread. There are no locks protecting this, but it is assumed that you
189 // have the global V8 lock if you are using multiple V8 threads.
190 static uintptr_t climit() {
191 return thread_local_.climit_;
192 }
193
194 // You should hold the ExecutionAccess lock when calling this method. 199 // You should hold the ExecutionAccess lock when calling this method.
195 static void set_limits(uintptr_t value, const ExecutionAccess& lock) { 200 static void set_limits(uintptr_t value, const ExecutionAccess& lock) {
196 Heap::SetStackLimit(value); 201 Heap::SetStackLimit(value);
197 thread_local_.jslimit_ = value; 202 thread_local_.jslimit_ = value;
198 thread_local_.climit_ = value; 203 thread_local_.climit_ = value;
199 } 204 }
200 205
201 // Reset limits to initial values. For example after handling interrupt. 206 // Reset limits to initial values. For example after handling interrupt.
202 // You should hold the ExecutionAccess lock when calling this method. 207 // You should hold the ExecutionAccess lock when calling this method.
203 static void reset_limits(const ExecutionAccess& lock) { 208 static void reset_limits(const ExecutionAccess& lock) {
204 if (thread_local_.nesting_ == 0) { 209 thread_local_.jslimit_ = thread_local_.initial_jslimit_;
205 // No limits have been set yet. 210 Heap::SetStackLimit(thread_local_.jslimit_);
206 set_limits(kIllegalLimit, lock); 211 thread_local_.climit_ = thread_local_.initial_climit_;
207 } else {
208 thread_local_.jslimit_ = thread_local_.initial_jslimit_;
209 Heap::SetStackLimit(thread_local_.jslimit_);
210 thread_local_.climit_ = thread_local_.initial_climit_;
211 }
212 } 212 }
213 213
214 // Enable or disable interrupts. 214 // Enable or disable interrupts.
215 static void EnableInterrupts(); 215 static void EnableInterrupts();
216 static void DisableInterrupts(); 216 static void DisableInterrupts();
217 217
218 static const uintptr_t kLimitSize = kPointerSize * 128 * KB; 218 static const uintptr_t kLimitSize = kPointerSize * 128 * KB;
219 #ifdef V8_TARGET_ARCH_X64 219 #ifdef V8_TARGET_ARCH_X64
220 static const uintptr_t kInterruptLimit = V8_UINT64_C(0xfffffffffffffffe); 220 static const uintptr_t kInterruptLimit = V8_UINT64_C(0xfffffffffffffffe);
221 static const uintptr_t kIllegalLimit = V8_UINT64_C(0xffffffffffffffff); 221 static const uintptr_t kIllegalLimit = V8_UINT64_C(0xfffffffffffffff8);
222 #else 222 #else
223 static const uintptr_t kInterruptLimit = 0xfffffffe; 223 static const uintptr_t kInterruptLimit = 0xfffffffe;
224 static const uintptr_t kIllegalLimit = 0xffffffff; 224 static const uintptr_t kIllegalLimit = 0xfffffff8;
225 #endif 225 #endif
226 226
227 class ThreadLocal { 227 class ThreadLocal {
228 public: 228 public:
229 ThreadLocal() 229 ThreadLocal() { Clear(); }
230 : initial_jslimit_(kIllegalLimit), 230 // You should hold the ExecutionAccess lock when you call Initialize or
231 jslimit_(kIllegalLimit), 231 // Clear.
232 initial_climit_(kIllegalLimit), 232 void Initialize();
233 climit_(kIllegalLimit), 233 void Clear();
234 nesting_(0),
235 postpone_interrupts_nesting_(0),
236 interrupt_flags_(0) {
237 Heap::SetStackLimit(kIllegalLimit);
238 }
239 uintptr_t initial_jslimit_; 234 uintptr_t initial_jslimit_;
240 uintptr_t jslimit_; 235 uintptr_t jslimit_;
241 uintptr_t initial_climit_; 236 uintptr_t initial_climit_;
242 uintptr_t climit_; 237 uintptr_t climit_;
243 int nesting_; 238 int nesting_;
244 int postpone_interrupts_nesting_; 239 int postpone_interrupts_nesting_;
245 int interrupt_flags_; 240 int interrupt_flags_;
246 }; 241 };
247 242
248 static ThreadLocal thread_local_; 243 static ThreadLocal thread_local_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 v8::Handle<v8::String> name); 287 v8::Handle<v8::String> name);
293 static v8::Handle<v8::Value> GC(const v8::Arguments& args); 288 static v8::Handle<v8::Value> GC(const v8::Arguments& args);
294 private: 289 private:
295 static const char* kSource; 290 static const char* kSource;
296 }; 291 };
297 292
298 293
299 } } // namespace v8::internal 294 } } // namespace v8::internal
300 295
301 #endif // V8_EXECUTION_H_ 296 #endif // V8_EXECUTION_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698