Hi! Just returning to this list after having been unsubscribed for a while.

We're using V8 to permit custom scripting in a sandboxed environment,
and I discovered today that certain situations result in the process
dying with a SIGTRAP. My current test code is:

var a="a";
while (1) a=a+a;


Obviously this will fail memory allocation after a handful of
iterations. What is best-practice for handling this? I'm okay with
catching a signal if that's the best method, but it looks as though
the SIGTRAP isn't meant to be the standard OOM handler. Is there a
proper API for it? I've poked around without finding any.

In tinkering and testing, too, I came across another oddity. I'm
running this inside gdb, and examining memory usage with 'top' for the
process both before running the code (but after initializing V8 and
compiling the code) and after the process SIGTRAPs to the debugger. If
the allocations happen too fast, memory usage barely goes up - maybe a
few KB, nothing significant. But if I add just one character at a time
(a=a+"a"), the system consumes heaps of memory, all of which is
retained as long as the process is alive. Is this a problem with my
measurement method? I can't imagine it could be anything else, yet
'top' is usually my go-to information source of this nature, and I'd
normally expect it to be right.

Using V8 built from source, straight from svn as at rev 11670
(probably a bit old by now, I built it earlier this year).
Running on Debian Squeeze (6.0.6) 64-bit, Linux kernel 2.6.32-5,
fairly standard.
V8 and my application built using gcc "Debian 4.4.5-8"

Here's the test code I've been using:

#include <v8.h>
using namespace v8;
Persistent<Context> ctx;
#include <unistd.h>

int main()
{
        HandleScope hsc;
        Persistent<Context> newctx=Context::New();
        Context::Scope scope(newctx);
        Handle<String> compileme=String::New("var a=\"a\",b=[]; while (1)
b.push(a+=a);");
        Handle<Script> script=Script::Compile(compileme);
        printf("Waiting...\n"); fflush(stdout);
        sleep(10);
        printf("Bombing.\n"); fflush(stdout);
        if (!script.IsEmpty()) script->Run();
        printf("Successful!\n");
        return 0;
}

I compile using -fPIC -lrt -std=gnu++0x if that makes any difference.

ChrisA

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to