| OLD | NEW |
| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // Static state for stack guards. | 216 // Static state for stack guards. |
| 217 StackGuard::ThreadLocal StackGuard::thread_local_; | 217 StackGuard::ThreadLocal StackGuard::thread_local_; |
| 218 | 218 |
| 219 | 219 |
| 220 StackGuard::StackGuard() { | 220 StackGuard::StackGuard() { |
| 221 // NOTE: Overall the StackGuard code assumes that the stack grows towards | 221 // NOTE: Overall the StackGuard code assumes that the stack grows towards |
| 222 // lower addresses. | 222 // lower addresses. |
| 223 ExecutionAccess access; | 223 ExecutionAccess access; |
| 224 if (thread_local_.nesting_++ == 0) { | 224 if (thread_local_.nesting_++ == 0) { |
| 225 // Initial StackGuard is being set. We will set the stack limits based on | 225 // Initial StackGuard is being set. |
| 226 // the current stack pointer allowing the stack to grow kLimitSize from | |
| 227 // here. | |
| 228 | 226 |
| 229 // Ensure that either the stack limits are unset (kIllegalLimit) or that | 227 // Ensure that either the stack limits are unset (kIllegalLimit) or that |
| 230 // they indicate a pending interruption. The interrupt limit will be | 228 // they indicate a pending interruption. The interrupt limit will be |
| 231 // temporarily reset through the code below and reestablished if the | 229 // temporarily reset through the code below and reestablished if the |
| 232 // interrupt flags indicate that an interrupt is pending. | 230 // interrupt flags indicate that an interrupt is pending. |
| 233 ASSERT(thread_local_.jslimit_ == kIllegalLimit || | 231 ASSERT(thread_local_.jslimit_ == kIllegalLimit || |
| 234 (thread_local_.jslimit_ == kInterruptLimit && | 232 (thread_local_.jslimit_ == kInterruptLimit && |
| 235 thread_local_.interrupt_flags_ != 0)); | 233 thread_local_.interrupt_flags_ != 0)); |
| 236 ASSERT(thread_local_.climit_ == kIllegalLimit || | 234 ASSERT(thread_local_.climit_ == kIllegalLimit || |
| 237 (thread_local_.climit_ == kInterruptLimit && | 235 (thread_local_.climit_ == kInterruptLimit && |
| 238 thread_local_.interrupt_flags_ != 0)); | 236 thread_local_.interrupt_flags_ != 0)); |
| 239 | 237 |
| 240 uintptr_t limit = GENERATED_CODE_STACK_LIMIT(kLimitSize); | 238 if (thread_local_.initial_jslimit_ == kIllegalLimit || |
| 241 thread_local_.initial_jslimit_ = thread_local_.jslimit_ = limit; | 239 thread_local_.initial_climit_ == kIllegalLimit) { |
| 242 Heap::SetStackLimit(limit); | 240 CHECK(thread_local_.initial_jslimit_ == kIllegalLimit); |
| 243 // NOTE: The check for overflow is not safe as there is no guarantee that | 241 CHECK(thread_local_.initial_climit_ == kIllegalLimit); |
| 244 // the running thread has its stack in all memory up to address 0x00000000. | 242 |
| 245 thread_local_.initial_climit_ = thread_local_.climit_ = | 243 // No limit has been set with ResourceConstraints. We will set |
| 246 reinterpret_cast<uintptr_t>(this) >= kLimitSize ? | 244 // the stack limits based on the current stack pointer allowing |
| 247 reinterpret_cast<uintptr_t>(this) - kLimitSize : 0; | 245 // the stack to grow kLimitSize from here. |
| 246 uintptr_t limit = GENERATED_CODE_STACK_LIMIT(kLimitSize); |
| 247 thread_local_.initial_jslimit_ = limit; |
| 248 |
| 249 // NOTE: The check for overflow is not safe as there is no |
| 250 // guarantee that the running thread has its stack in all memory |
| 251 // up to address 0x00000000. |
| 252 thread_local_.initial_climit_ = |
| 253 reinterpret_cast<uintptr_t>(this) >= kLimitSize ? |
| 254 reinterpret_cast<uintptr_t>(this) - kLimitSize : 0; |
| 255 } |
| 256 thread_local_.jslimit_ = thread_local_.initial_jslimit_; |
| 257 thread_local_.climit_ = thread_local_.initial_climit_; |
| 258 Heap::SetStackLimit(thread_local_.jslimit_); |
| 248 | 259 |
| 249 if (thread_local_.interrupt_flags_ != 0) { | 260 if (thread_local_.interrupt_flags_ != 0) { |
| 250 set_limits(kInterruptLimit, access); | 261 set_limits(kInterruptLimit, access); |
| 251 } | 262 } |
| 252 } | 263 } |
| 253 // Ensure that proper limits have been set. | 264 // Ensure that proper limits have been set. |
| 254 ASSERT(thread_local_.jslimit_ != kIllegalLimit && | 265 ASSERT(thread_local_.jslimit_ != kIllegalLimit && |
| 255 thread_local_.climit_ != kIllegalLimit); | 266 thread_local_.climit_ != kIllegalLimit); |
| 256 ASSERT(thread_local_.initial_jslimit_ != kIllegalLimit && | 267 ASSERT(thread_local_.initial_jslimit_ != kIllegalLimit && |
| 257 thread_local_.initial_climit_ != kIllegalLimit); | 268 thread_local_.initial_climit_ != kIllegalLimit); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 276 void StackGuard::EnableInterrupts() { | 287 void StackGuard::EnableInterrupts() { |
| 277 ExecutionAccess access; | 288 ExecutionAccess access; |
| 278 if (IsSet(access)) { | 289 if (IsSet(access)) { |
| 279 set_limits(kInterruptLimit, access); | 290 set_limits(kInterruptLimit, access); |
| 280 } | 291 } |
| 281 } | 292 } |
| 282 | 293 |
| 283 | 294 |
| 284 void StackGuard::SetStackLimit(uintptr_t limit) { | 295 void StackGuard::SetStackLimit(uintptr_t limit) { |
| 285 ExecutionAccess access; | 296 ExecutionAccess access; |
| 286 // If the current limits are special (eg due to a pending interrupt) then | 297 CHECK(thread_local_.nesting_ == 0); |
| 287 // leave them alone. | |
| 288 if (thread_local_.jslimit_ == thread_local_.initial_jslimit_) { | |
| 289 thread_local_.jslimit_ = limit; | |
| 290 Heap::SetStackLimit(limit); | |
| 291 } | |
| 292 if (thread_local_.climit_ == thread_local_.initial_climit_) { | |
| 293 thread_local_.climit_ = limit; | |
| 294 } | |
| 295 thread_local_.initial_climit_ = limit; | 298 thread_local_.initial_climit_ = limit; |
| 296 thread_local_.initial_jslimit_ = limit; | 299 thread_local_.initial_jslimit_ = limit; |
| 297 } | 300 } |
| 298 | 301 |
| 299 | 302 |
| 300 void StackGuard::DisableInterrupts() { | 303 void StackGuard::DisableInterrupts() { |
| 301 ExecutionAccess access; | 304 ExecutionAccess access; |
| 302 reset_limits(access); | 305 reset_limits(access); |
| 303 } | 306 } |
| 304 | 307 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // All allocation spaces other than NEW_SPACE have the same effect. | 688 // All allocation spaces other than NEW_SPACE have the same effect. |
| 686 Heap::CollectAllGarbage(false); | 689 Heap::CollectAllGarbage(false); |
| 687 return v8::Undefined(); | 690 return v8::Undefined(); |
| 688 } | 691 } |
| 689 | 692 |
| 690 | 693 |
| 691 static GCExtension kGCExtension; | 694 static GCExtension kGCExtension; |
| 692 v8::DeclareExtension kGCExtensionDeclaration(&kGCExtension); | 695 v8::DeclareExtension kGCExtensionDeclaration(&kGCExtension); |
| 693 | 696 |
| 694 } } // namespace v8::internal | 697 } } // namespace v8::internal |
| OLD | NEW |