[MacRuby] #1346: Segfault occurs when invoked a Module#attr within some threads.
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Test Script: {{{ #!ruby m1 = Module.new m2 = Module.new Thread.new { 100.times do |i| m1.instance_eval{ attr("test#{i}") } end } 100.times do |i| m2.instance_eval{ attr("test#{i}") } end }}} BackTrace: {{{ (gdb) t a a bt Thread 3 (process 18224): #0 0x0000000100164980 in rb_sym2id (sym=0) at symbol.c:198 #1 0x00000001000adb85 in rb_to_id (name=0) at string.c:6494 #2 0x0000000100052bac in rb_mod_attr_reader (klass=8590087520, sel=0x0, argc=1, argv=0x10177dd78) at object.c:2044 #3 0x0000000100052c86 in rb_mod_attr (klass=8590087520, sel=0x100fbf3a0, argc=1, argv=0x10177dd78) at object.c:2057 #4 0x000000010012e2b3 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:448 #5 0x000000010012e2b3 in rb_vm_dispatch () at dispatcher.cpp:872 #6 0x0000000101500764 in ?? () #7 0x00000001015012d0 in ?? () #8 0x0000000100135ddb in __rb_vm_bcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:98 #9 0x0000000100135ddb in vm_block_eval [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:1221 #10 0x0000000100135ddb in rb_vm_yield_under () at dispatcher.cpp:1321 #11 0x00000001000db958 in specific_eval (argc=0, argv=0x0, klass=8590087456, self=8590087520) at vm_eval.c:339 #12 0x00000001000dbee3 in rb_obj_instance_eval_imp (self=8590087520, sel=0x100fde130, top=8590062336, argc=0, argv=0x0) at vm_eval.c:507 #13 0x000000010012e366 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:457 #14 0x000000010012e366 in rb_vm_dispatch () at dispatcher.cpp:872 #15 0x0000000101500764 in ?? () #16 0x0000000101500fe3 in ?? () #17 0x0000000100134ccb in __rb_vm_bcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:100 #18 0x0000000100134ccb in vm_block_eval [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:1221 #19 0x0000000100134ccb in rb_vm_yield_args () at dispatcher.cpp:1278 #20 0x00000001000db2fd in rb_vm_yield (argc=1, argv=0x10177f928) at vm.h:697 #21 0x00000001000db2d0 in rb_yield (val=29) at vm_eval.c:183 #22 0x000000010004d1da in int_dotimes (num=401, sel=0x100fe7350) at numeric.c:3241 #23 0x000000010012e8b4 in __rb_vm_rcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:159 #24 0x000000010012e8b4 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:466 #25 0x000000010012e8b4 in rb_vm_dispatch () at dispatcher.cpp:872 #26 0x0000000101500764 in ?? () #27 0x0000000101500ca1 in ?? () #28 0x0000000100132c67 in __rb_vm_bcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:98 #29 0x0000000100132c67 in vm_block_eval [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:1221 #30 0x0000000100132c67 in rb_vm_block_eval (b=0x200020560, argc=0, argv=0x0) at dispatcher.cpp:1228 #31 0x000000010014d093 in rb_vm_thread_run (thread=8590066656) at vm.cpp:4856 #32 0x00007fff83cf9fd6 in _pthread_start () #33 0x00007fff83cf9e89 in thread_start () Thread 2 (process 18224): #0 0x00007fff83cdaa2a in __workq_kernreturn () #1 0x00007fff83cdae3c in _pthread_wqthread () #2 0x00007fff83cdaaa5 in start_wqthread () Thread 1 (process 18224): #0 0x00007fff83cc5762 in szone_malloc_should_clear () #1 0x00007fff83cc498a in malloc_zone_malloc () #2 0x00007fff83cc2c88 in malloc () #3 0x00007fff84c61f05 in operator new () #4 0x000000010015d185 in __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<objc_class* const, objc_selector*> > >::allocate (this=0x102068448, __n=1) at new_allocator.h:91 #5 0x000000010015d1aa in std::_Rb_tree<objc_class*, std::pair<objc_class* const, objc_selector*>, std::_Select1st<std::pair<objc_class* const, objc_selector*> >, std::less<objc_class*>, std::allocator<std::pair<objc_class* const, objc_selector*> >
::_M_get_node (this=0x102068448) at stl_tree.h:369 #6 0x000000010015d1c6 in std::_Rb_tree<objc_class*, std::pair<objc_class* const, objc_selector*>, std::_Select1st<std::pair<objc_class* const, objc_selector*> >, std::less<objc_class*>, std::allocator<std::pair<objc_class* const, objc_selector*> > ::_M_create_node (this=0x102068448, __x=@0x7fff5fbf9d30) at stl_tree.h:378 #7 0x0000000100160066 in std::_Rb_tree<objc_class*, std::pair<objc_class* const, objc_selector*>, std::_Select1st<std::pair<objc_class* const, objc_selector*> >, std::less<objc_class*>, std::allocator<std::pair<objc_class* const, objc_selector*> > >::_M_insert (this=0x102068448, __x=0x0, __p=0x103604290, __v=@0x7fff5fbf9d30) at stl_tree.h:840 #8 0x000000010016015a in std::_Rb_tree<objc_class*, std::pair<objc_class* const, objc_selector*>, std::_Select1st<std::pair<objc_class* const, objc_selector*> >, std::less<objc_class*>, std::allocator<std::pair<objc_class* const, objc_selector*> > ::_M_insert_equal (this=0x102068448, __v=@0x7fff5fbf9d30) at stl_tree.h:899 #9 0x000000010016017f in std::multimap<objc_class*, objc_selector*, std::less<objc_class*>, std::allocator<std::pair<objc_class* const, objc_selector*> > >::insert (this=0x102068448, __x=@0x7fff5fbf9d30) at stl_multimap.h:340 #10 0x000000010013c327 in RoxorCore::prepare_method (this=0x102068200, klass=0x200020520, sel=0x1036042d0, func=0x1036042f0, arity=@0x7fff5fbf9f88, flags=8) at vm.cpp:2095 #11 0x000000010014c58e in prepare_method (klass=0x200020520, dynamic_class=false, sel=0x1036042d0, data=0x1036042f0, arity=@0x7fff5fbf9f88, flags=8, precompiled=false, objc_imp_types=0x0) at vm.cpp:2203 #12 0x000000010014cbb1 in rb_vm_prepare_method (klass=0x200020520, dynamic_class=0 '\0', sel=0x1036042d0, func=0x1036042f0, arity={min = 0, max = 0, left_req = 0, real = 0}, flags=8) at vm.cpp:2276 #13 0x000000010014cd07 in rb_vm_define_attr (klass=0x200020520, name=0x200015800 "test7", read=true, write=false) at vm.cpp:2636 #14 0x00000001000d988d in rb_attr (klass=8590066976, id=12544, read=2, write=0, ex=2) at vm_method.c:136 #15 0x0000000100052bc8 in rb_mod_attr_reader (klass=8590066976, sel=0x0, argc=1, argv=0x7fff5fbfb0c8) at object.c:2044 #16 0x0000000100052c86 in rb_mod_attr (klass=8590066976, sel=0x100fbf3a0, argc=1, argv=0x7fff5fbfb0c8) at object.c:2057 #17 0x000000010012e2b3 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:448 #18 0x000000010012e2b3 in rb_vm_dispatch () at dispatcher.cpp:872 #19 0x0000000101500764 in ?? () #20 0x00000001015011c0 in ?? () #21 0x0000000100135ddb in __rb_vm_bcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:98 #22 0x0000000100135ddb in vm_block_eval [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:1221 #23 0x0000000100135ddb in rb_vm_yield_under () at dispatcher.cpp:1321 #24 0x00000001000db958 in specific_eval (argc=0, argv=0x0, klass=8590066912, self=8590066976) at vm_eval.c:339 #25 0x00000001000dbee3 in rb_obj_instance_eval_imp (self=8590066976, sel=0x100fde130, top=8590062336, argc=0, argv=0x0) at vm_eval.c:507 #26 0x000000010012e366 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:457 #27 0x000000010012e366 in rb_vm_dispatch () at dispatcher.cpp:872 #28 0x0000000101500764 in ?? () #29 0x0000000101500de3 in ?? () #30 0x0000000100134ccb in __rb_vm_bcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:100 #31 0x0000000100134ccb in vm_block_eval [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:1221 #32 0x0000000100134ccb in rb_vm_yield_args () at dispatcher.cpp:1278 #33 0x00000001000db2fd in rb_vm_yield (argc=1, argv=0x7fff5fbfcc78) at vm.h:697 #34 0x00000001000db2d0 in rb_yield (val=29) at vm_eval.c:183 #35 0x000000010004d1da in int_dotimes (num=401, sel=0x100fe7350) at numeric.c:3241 #36 0x000000010012e8b4 in __rb_vm_rcall [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:159 #37 0x000000010012e8b4 in ruby_dispatch [inlined] () at /Users/watson/src /macruby-master/dispatcher.cpp:466 #38 0x000000010012e8b4 in rb_vm_dispatch () at dispatcher.cpp:872 #39 0x0000000101500764 in ?? () #40 0x000000010150027b in ?? () #41 0x000000010014a072 in rb_vm_run (fname=0x2000a8cc0 "/Users/watson/tmp/t.rb", node=0x200024fe0, binding=0x0, inside_eval=false) at vm.cpp:4115 #42 0x000000010002898b in ruby_run_node (n=0x200024fe0) at eval.c:211 #43 0x0000000100000be3 in main (argc=2, argv=0x100f1c040, envp=0x7fff5fbfde58) at main.cpp:40 (gdb) }}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/1346> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): To fix this issue and #1347, at least, it looks like it needs the exclusive control for JIT compile. {{{ #!diff diff --git a/vm.cpp b/vm.cpp index abdf61b..947fb83 100644 --- a/vm.cpp +++ b/vm.cpp @@ -2630,14 +2630,18 @@ rb_vm_define_attr(Class klass, const char *name, bool read, bool write) ID iname = rb_intern(buf); if (read) { + GET_CORE()->lock(); Function *f = RoxorCompiler::shared->compile_read_attr(iname); + GET_CORE()->unlock(); SEL sel = sel_registerName(name); rb_vm_prepare_method(klass, false, sel, f, rb_vm_arity(0), VM_METHOD_FBODY); } if (write) { + GET_CORE()->unlock(); Function *f = RoxorCompiler::shared->compile_write_attr(iname); + GET_CORE()->unlock(); snprintf(buf, sizeof buf, "%s=:", name); SEL sel = sel_registerName(buf); rb_vm_prepare_method(klass, false, sel, f, rb_vm_arity(1), @@ -2734,8 +2738,10 @@ rb_vm_define_method3(Class klass, ID mid, rb_vm_block_t *block) const int arity = rb_vm_arity_n(block->arity); SEL sel = rb_vm_id_to_sel(mid, arity); + GET_CORE()->lock(); Function *func = RoxorCompiler::shared->compile_block_caller(block); IMP imp = GET_CORE()->compile(func); + GET_CORE()->unlock(); NODE *body = rb_vm_cfunc_node_from_imp(klass, arity < -1 ? -2 : arity, imp, 0); GC_RETAIN(body); GC_RETAIN(block); }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:1> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Looks good to me! -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:2> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by kouji@…): included typo. see below. {{{ if (write) { + GET_CORE()->lock(); Function *f = RoxorCompiler::shared->compile_write_attr(iname); + GET_CORE()->unlock(); snprintf(buf, sizeof buf, "%s=:", name); }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:3> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): Oops, indeed :( -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:4> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): (I need better glasses :)) -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:5> MacRuby <http://macruby.org/>
#1346: Segfault occurs when invoked a Module#attr within some threads. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.11 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------+----------------------------------------- Changes (by watson1978@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.11 Comment: I forgot to close this issue. Fixed with https://github.com/MacRuby/MacRuby/commit/d1d50ef583a1c7ab151f0e26dfa233bcf6... -- Ticket URL: <http://www.macruby.org/trac/ticket/1346#comment:6> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby