Permalink
Browse files

Fix that pesky stack bug

I was giving v8 the top of the stack instead of the bottom of the stack
so it couldn't figure out where to stop. This change fixes that. I
tested this using an infinite recussion function with really small
stacks (8kb) and large ones (512k) and I'm getting reasonable results.

Now the hard part is picking the right stack size. I'm going to go with
64k as it's the default stack node picked for libeio threads.
  • Loading branch information...
1 parent fc88cfc commit cfcc64e3042e0ed9f40a4f7040668245bd041717 @laverdet committed Feb 18, 2011
Showing with 4 additions and 4 deletions.
  1. +2 −2 src/coroutine.cc
  2. +2 −2 src/fibers.cc
View
@@ -13,7 +13,7 @@
// No matter what I give it, it seems the stack size is always the same. And then if the actual
// amount of memory allocated for the stack is too small it seg faults. It seems 265k is as low as
// I can go without fixing the underlying bug.
-#define STACK_SIZE (1024 * 265)
+#define STACK_SIZE (1024 * 64)
#define MAX_POOL_SIZE 120
#include <iostream>
@@ -228,7 +228,7 @@ void Coroutine::finish(Coroutine& next) {
}
void* Coroutine::bottom() const {
- return (char*)&stack[0] - STACK_SIZE;
+ return (char*)&stack[0];
}
size_t Coroutine::size() const {
View
@@ -334,9 +334,9 @@ class Fiber {
Locker locker;
HandleScope scope;
- // Set stack guard for this "thread"
+ // Set the stack guard for this "thread"; 512 bytes of padding (?)
ResourceConstraints constraints;
- constraints.set_stack_limit((uint32_t*)that.this_fiber->bottom());
+ constraints.set_stack_limit((uint32_t*)that.this_fiber->bottom() + 512);
SetResourceConstraints(&constraints);
TryCatch try_catch;

0 comments on commit cfcc64e

Please sign in to comment.