开发者

V8 Android, creating the context causes ASSERT ... CHECK(object->IsJSFunction()) failed

I've successfully compiled V8 javascript engine for Android as a static lib (libv8arm.a), and I can statically link it into my android native C++ app (using ndk-r5b).

On Android, when the V8 context is created I get this runtime assert ...

// Initialize the V8 context.

Local globals = ObjectTemplate::New();

context = Context::New( NULL, globals );

Fatal error in v8/src/objects-inl.h, line 1581

CHECK(object->IsJSFunction()) failed

When I embed V8 into the MacOSX version of my app, everything runs fine and I can execute javascript without any problems. I've spent many hours diffing code and also looking at gcc command line args for building V8 for Android. I'm stuck, and very near to hacking V8 code to pieces to figure it out.

Does anyone know what things V8 runtime initialization needs to get past Context::New() asserting?

Thanks.


UPDATE:

I'm attempting to trap this problem by modifying the CAST_ACCESSOR macro...

extern int __cast_accessor_count /* = 0 */;

// in the cpp file where Context::New() is called 
//namespace v8 { namespace internal {
//int __cast_accessor_count = 0;
//}; };

#define CAST_ACCESSOR(type)                     \
  type* type::cast(Object* object) {            \
    __cast_accessor_count++;                    \
    if( !object->Is##type() ) { OS::Print( "CAST_ACCESSOR %d %s\n",     __cast_accessor_count, #type );  object->ShortPrint(); } \
    ASSERT(object->Is##type());                 \
    return reinterpret_cast<type*>(object);     \
  }  

... and printing the value before and after calling Context::New() ...

printf( "__cast_accessor_count=%d\n", v8::internal::__cast_accessor_count );

// Create a new context.
Persistent<Context> context = Context::New();

printf( "__cast_accessor_count=%d\n", v8::internal::__cast_accessor_count );

in my MacOSX test app, the output is

__cast_accessor_count=0  
(gdb) continue  
__cast_accessor_count=272875  

on Android the output before hitting the assert is

__cast_accessor_count=0  
CAST_ACCESSOR 101980 JSFunction  
0x486c4135 <undefined>  

searched through the V8 code to find where object->ShortPrint() is outputing "undefined" and I found this...

case ODDBALL_TYPE: {
  if (IsUndefined())
    accumulator->Add("<undefined>");

I'm wondering if ODDBALL_TYPE is emitted by the codegen, and its different for IA32 assembly and ARM assembly. That might explain different initialization on each platform.


UPDATE2:

finally got a valid callstack...

0x001e3b4e:                PAUL_DEBUG_BREAK + 0x002e
0x0023d916:_ZN2v88internal10JSFunction4castEPNS0_6ObjectE + 0x0056
0x00251594:_ZN2v88internal7Genesis17InstallJSBuiltinsENS0_6HandleINS0_16JSBuiltinsObjectEEE + 0x0048
0x00250e6c:_ZN2v88internal7Genesis14InstallNativesEv + 0x05e8
0x0025241c:_ZN2v88internal7GenesisC1ENS0_6HandleINS0_6ObjectEEENS_6HandleINS_14ObjectTemplateEEEPNS_22ExtensionCo开发者_运维百科nfigurationE + 0x01c4
0x0024ed5a:_ZN2v88internal12Bootstrapper17CreateEnvironmentENS0_6HandleINS0_6ObjectEEENS_6HandleINS_14ObjectTemplateEEEPNS_22ExtensionConfigurationE + 0x0022
0x00247a46:_ZN2v87Context3NewEPNS_22ExtensionConfigurationENS_6HandleINS_14ObjectTemplateEEENS3_INS_5ValueEEE + 0x017e
0x001e3c02:    _ZN16JavascriptEngine4InitEv + 0x007a

arm-eabi-c++filt

v8::internal::JSFunction::cast(v8::internal::Object*)
v8::internal::Genesis::InstallJSBuiltins(v8::internal::Handle<v8::internal::JSBuiltinsObject>)
v8::internal::Genesis::InstallNatives()
v8::internal::Genesis::Genesis(v8::internal::Handle<v8::internal::Object>,     v8::Handle<v8::ObjectTemplate>, v8::ExtensionConfiguration*)
v8::internal::Bootstrapper::CreateEnvironment(v8::internal::Handle<v8::internal::Object>,     v8::Handle<v8::ObjectTemplate>, v8::ExtensionConfiguration*)
v8::Context::New(v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>,     v8::Handle<v8::Value>)
JavascriptEngine::Init()  


libraries.cc is the answer.

On android, I was using the libraries.cc file which was generated for the macosx build. I fixed the problem on android by using the js2c.py tool to generate a new libraries.cc file for android.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜