在运行V8代码的时候或者Nodejs等依赖于V8的时候,可能遇到如下错误:
Maximum call stack size exceeded
这个错误是由于V8的堆栈溢出了,V8默认的堆栈大小是512k,如果超过了就会溢出。
在运行Nodejs的时候,我遇到了这个问题,从下面的文章找到了线索:
http://semoon1314.blog.163.com/blog/static/13665733520117315324304/
说明:
这个文章说需要修改V8的代码,重新编译,其实是不需要的,nodejs的node提供了一个选项--max-stack-size就是用于设置V8的堆栈大小的,在node.cc中可以找到相关代码的实现。
转http://fw.hardijzer.nl/?p=97:
V8 crashing with ‘Uncaught RangeError: Maximum call stack size exceeded’ While working with V8 in another process, it kept crashing at initialization with the message ‘Uncaught RangeError: Maximum call stack size exceeded’. I wasn’t doing anything big, just initialization. After about 3 hour of debugging, I found out what was wrong. Normally, V8 will assume that you have no more than 512KB of stack space. To prevent stack overflows, it will take a stack address, substract 512kb from it, and remember that address. If it ever passes that address, it’ll throw a RangeError. The problem lies in the fact that the program I was working with had a stack somewhere around 0×60000 or 384kb. V8 then substracts 512 from that, but instead of getting a nice stack-boundary, it ends up with an incredibly big number due to integer underflow. The next time it checks the stack, it compares the stack address (still somewhere around 0×60000) with it’s calculated stack limited (which, due to the underflow, is about 0xFFFE0000), and assumes it has a stack overflow. To fix this, I had to manually set the stack limit. Basically, the following code takes a random stack address, divides it by 2, and uses that as the lower-limit to the stack: v8::ResourceConstraints rc; rc.set_stack_limit((uint32_t *)(((uint32_t)&rc)/2)); v8::SetResourceConstraints(&rc);
articles:
http://www.cnblogs.com/sweetwxh/archive/2011/09/11/2173596.html
http://fw.hardijzer.nl/?p=97
http://semoon1314.blog.163.com/blog/static/13665733520117315324304/