JS_newObject API崩溃,可能是垃圾收集器问题

时间:2015-10-16 19:05:25

标签: javascript garbage-collection thread-safety spidermonkey

所以我试图在64版平台上运行代码。我正在使用spidemonkey 1.8.5。以下代码在JS_NewObject()行崩溃。我的猜测是它与API中触发的GC有关。我尝试过其他做同样事情的API,我也尝试过BeginRequest和EndRequest。他们都没有帮助。

链接到Spidermonkey 1.7时,相同的代码可以正常工作。

 int InitJS()
{   
m_jsRunTime = JS_NewRuntime(JS_RUN_TIME_MEM);
if ( NULL == m_jsRunTime )
{           
    return 0;
}

m_jsContext = JS_NewContext(m_jsRunTime, JS_CONTEXT_MEM);
if ( NULL == m_jsContext )
{
    return 0;
}    

//JS_BeginRequest(m_jsConetxt);//just to test no help
//ASSERT(m_jsContext);ASSERT(&JS_GLOBAL_CLASS);//these are fine. no null pointer
//JSObject *myObject = JS_NewObject(m_jsContext, &JS_GLOBAL_CLASS, NULL, NULL);//just to test->this also carshes
//m_jsGlobalObject = JS_NewObjectwithGivenProto(m_jsContext, &JS_GLOBAL_CLASS, NULL, NULL);//just to test ->identifeir not found
//m_jsGlobalObject = JS_ConstructObject(m_jsContext, &JS_GLOBAL_CLASS, NULL, NULL);//just to test->crashes


m_jsGlobalObject = JS_NewObject(m_jsContext, &JS_GLOBAL_CLASS, NULL, NULL);//the original line
if ( NULL == m_jsGlobalObject)
{
     return 0;
}

if ( !JS_InitStandardClasses(m_jsContext, m_jsGlobalObject) )
{
return 0;
}
JS_EndRequest(m_jsContext);//just to test
return 1;

}

核心转储文件指向jsgcinlines.h中的这一行

inline JSObject *

js_NewGCObject(JSContext *cx, js::gc::FinalizeKind kind)

{

    JS_ASSERT(kind >= js::gc::FINALIZE_OBJECT0 && kind  
<=js::gc::FINALIZE_OBJECT_LAST);

    JSObject *obj = NewFinalizableGCThing<JSObject>(cx, kind);

    if (obj)

        obj->capacity = js::gc::GetGCKindSlots(kind);

    return obj;

}

0 个答案:

没有答案