4 years later, I have the same question and the code in the original question doesn't match the current API.
When I create an object in a FunctionTemplate called as a constructor, how do I get a handle I can call SetWeak on and then properly clean it up when the weak reference callback is called? I've tried with globals and persistents on the stack and heap, but can't get around the # # Fatal error in ../src/global-handles.cc, line 349 # Check failed: state() != NEAR_DEATH. # check. The persistentbase object doesn't seem to be available, just a Local handle and my custom data where I'm passing in my heap-allocated c++ object pointer. Do I need to pass in a tuple and include the persistentbase handle to call Dispose() on? Thank you. --Zac On Friday, March 11, 2011 at 1:53:35 PM UTC-8, Stephan Beal wrote: > > Hello, v8 gurus, > > i'm having a particularly interesting problem on 64-bit builds of an app, > which i am not seeing on 32-bit compiles of the same code. In short, at the > end of my app i'm using idle notification to force GC, which in turn forces > my destructors. When this happens i'm seeing the following: > > gdb ... > ... > demo.cpp:40:test1_callback(): Calling NewInstance() > ConvertDemo.hpp:42:BoundNative(): @0x61cc70 is constructing. > ConvertDemo.hpp:153:BoundSubNative(): @0x61cc70 is constructing > demo.cpp:42:test1_callback(): Called NewInstance() > demo.cpp:44:test1_callback(): NewInstance() == @0x61cc70 > ... > demo.cpp:256:v8_main(): Trying to force GC... This will likely take 5-10 > seconds... wait for it to see the weak pointer callbacks in action... > ON SOME MACHINES THIS IS CRASHING ON ME IN V8 at some point... > demo.cpp:262:v8_main(): sleeping briefly before trying again... > demo.cpp:262:v8_main(): sleeping briefly before trying again... > demo.cpp:262:v8_main(): sleeping briefly before trying again... > demo.cpp:262:v8_main(): sleeping briefly before trying again... > demo.cpp:262:v8_main(): sleeping briefly before trying again... > ConvertDemo.hpp:157:~BoundSubNative(): @0x61cc70 is destructing > ConvertDemo.hpp:51:~BoundNative(): @0x61cc70 is destructing. > > > # > # Fatal error in src/global-handles.cc, line 195 > # CHECK(state_ != NEAR_DEATH) failed > # > > > Program received signal SIGABRT, Aborted. > 0x00007ffff6a7dba5 in raise (sig=<value optimized out>) at > ../nptl/sysdeps/unix/sysv/linux/raise.c:64 > 64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. > in ../nptl/sysdeps/unix/sysv/linux/raise.c > (gdb) bt > #0 0x00007ffff6a7dba5 in raise (sig=<value optimized out>) at > ../nptl/sysdeps/unix/sysv/linux/raise.c:64 > #1 0x00007ffff6a816b0 in abort () at abort.c:92 > #2 0x00007ffff781f8c5 in v8::internal::OS::Abort () at > src/platform-linux.cc:296 > #3 0x00007ffff76caf8e in V8_Fatal (file=0x7ffff79dfe55 > "src/global-handles.cc", line=195, > format=0x7ffff79dfcf0 "CHECK(%s) failed") at src/checks.cc:58 > #4 0x00007ffff7723940 in CheckHelper (file=0x7ffff79dfe55 > "src/global-handles.cc", line=195, > source=0x7ffff79dffe2 "state_ != NEAR_DEATH", condition=false) at > src/checks.h:60 > #5 0x00007ffff7724ff7 in > v8::internal::GlobalHandles::Node::PostGarbageCollectionProcessing > (this=0x7ffff7faa130) > at src/global-handles.cc:195 > #6 0x00007ffff7723dd7 in > v8::internal::GlobalHandles::PostGarbageCollectionProcessing () at > src/global-handles.cc:403 > #7 0x00007ffff773bfb0 in v8::internal::Heap::PerformGarbageCollection > (collector=v8::internal::MARK_COMPACTOR, > tracer=0x7fffffffe120) at src/heap.cc:777 > #8 0x00007ffff773b76c in v8::internal::Heap::CollectGarbage > (space=v8::internal::OLD_POINTER_SPACE, > collector=v8::internal::MARK_COMPACTOR) at src/heap.cc:509 > #9 0x00007ffff76d1d41 in v8::internal::Heap::CollectGarbage > (space=v8::internal::OLD_POINTER_SPACE) at src/heap-inl.h:412 > #10 0x00007ffff773b640 in v8::internal::Heap::CollectAllGarbage > (force_compaction=false) at src/heap.cc:451 > #11 0x00007ffff77434f3 in v8::internal::Heap::IdleNotification () at > src/heap.cc:3781 > #12 0x00007ffff78d9f97 in v8::internal::V8::IdleNotification () at > src/v8.cc:242 > #13 0x00007ffff7690f60 in v8::V8::IdleNotification () at src/api.cc:3385 > #14 0x000000000040802d in v8_main (argc=1, argv=0x7fffffffe4f8) at > demo.cpp:260 > #15 0x0000000000408181 in main (argc=1, argv=0x7fffffffe4f8) at > demo.cpp:274 > > > > What's happening there is that i'm instantiating native objects v8 JS > calls, in the context of an InvocationCallback. in my weak ptr callback i'm > calling (delete theNativeObject) and then calling Clear() on its containing > persistent handle (calling Dispose() is causing double calls to my weak ptr > callback). We see from the debug output that one dtor (with base and > subclass parts) is being called. But in the stack trace i'm not seeing a > call to my weak ptr callback. The implication is, it seems, that this is > happening after my weak callback returns. (i have instantiated only one > native object in the vm, so am expecting only one dtor call.) My idle > notification loop is simply: > > while( !v8::V8::IdleNotification() ) { > CERR << "sleeping briefly before trying again...\n"; > do_sleep(1); > } > > Any ideas what i can do to work around this? Am i mis-using the persistent > handle? > > The most relevant code (the parts which muck with the persistent handle) > is here: > > > http://code.google.com/p/v8-juice/source/browse/convert/include/v8/convert/ClassCreator.hpp#451 > (binds the p-handle) > > > http://code.google.com/p/v8-juice/source/browse/convert/include/v8/convert/ClassCreator.hpp#388 > (unbinds the p-handle) > > i'm using the bleeding edge branch, updated about 30 minutes ago, but i've > seen this on older versions as well. gcc 4.4.5 on Ubuntu 10.10 x86/64. On > x86/32 i am not seeing this problem, interestingly enough. > > -- > ----- stephan beal > http://wanderinghorse.net/home/stephan/ > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.