Hello, Xian,

On Mon, Nov 23, 2009 at 4:01 PM, Xiang <[email protected]> wrote:
>
> Hi, Anton,
>
> Thanks for your reply!
>
> But should v8 crash for this?
>
> I have already called v8::V8::IgnoreOutOfMemoryException(), I expect
> v8 should throw a v8::Exception, which we can catch using
> v8::TryCatch, and then we can continue to process next script.
>
> Am I wrong?

I see.  Sorry, I thought you was concerned why it exhaust the memory.

Now regarding if it should crash.  Alas, IgnoreOutOfMemoryException
won't protect you from all the errors (just grep for
FatalProcessOutOfMemory and you will see why).  Overall, recovery from
OOM errors is quite tricky and I think consensus is it's not worth it.

> If this "process out of memory" happens, v8 will become unusable
> anymore, It seems no chance that we can just ignore it and move on.

I don't think v8 as is now is able to solve this issue.  Might there
be any workarounds like starting separate process, etc.?  I am sure
you're aware of those, just asking.

yours,
anton.

> On Nov 23, 7:31 pm, Anton Muhin <[email protected]> wrote:
>> Xian,
>>
>> I think it's expected behaviour.  You first create an empty array.
>> Then you create an array with a single element which is this empty
>> array.  Next you wrap it once again thus creating an endless chain of
>> nested arrays:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > a = new Array()
>> > a.length
>> 0
>> > a = new Array(a)
>> > a.length
>> 1
>> > a[0].length
>> 0
>> > a = new Array(a)
>> > a.length
>> 1
>> > a[0].length
>> 1
>> > a[0][0].length
>> 0
>>
>> Eventually you exhaust the memory.
>>
>> yours,
>> anton.
>>
>>
>>
>> On Mon, Nov 23, 2009 at 12:51 PM, Xiang <[email protected]> wrote:
>>
>> > Test sample:
>> > ----------------------------
>>
>> > #include "v8.h"
>> > #include "stdio.h"
>>
>> > #ifndef CRASH
>> > #define CRASH() do { \
>> >    *(int *)(unsigned int *)0xbbadbeef = 0; \
>> >    ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
>> > } while(false)
>> > #endif
>>
>> > static void handleFatalErrorInV8()
>> > {
>> > //    CRASH();
>> > }
>>
>> > static void reportFatalErrorInV8(const char* location, const char*
>> > message)
>> > {
>> >    printf("V8 error: %s (%s)\n", message, location);
>> >    handleFatalErrorInV8();
>> > }
>>
>> > #define EXPECT(condition) if(!condition) printf("fail\n")
>>
>> > void TestRunScriptOutOfMemory()
>> > {
>> >    static const int K = 1024;
>> >    v8::ResourceConstraints constraints;
>> >    constraints.set_max_young_space_size(256 * K);
>> >    constraints.set_max_old_space_size(4 * K * K);
>> >    v8::SetResourceConstraints(&constraints);
>>
>> >    // Execute a script that causes out of memory.
>> >    v8::HandleScope scope;
>> >    v8::Persistent<v8::Context> context = v8::Context::New();
>> >    v8::Context::Scope contextScope(context);
>> >    v8::V8::IgnoreOutOfMemoryException();
>> >            v8::V8::SetFatalErrorHandler(reportFatalErrorInV8);
>> >    v8::Local<v8::Script> script =
>> >    v8::Script::Compile(v8::String::New("a = new Array(); while (1)
>> > { (a = new Array(a)).sort(); }"));
>> >    v8::Local<v8::Value> result = script->Run();
>> >    EXPECT(result.IsEmpty());
>> >    EXPECT(context->HasOutOfMemoryException());
>> >    context.Dispose();
>> > }
>>
>> > int main()
>> > {
>> >    TestRunScriptOutOfMemory();
>> >    return 0;
>> > }
> >
>

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

Reply via email to