On Sun, Oct 26, 2008 at 10:05:21PM -0700, Vasily Chekalkin wrote:
> Exception handling in parrot doesn't unwind used stack frames.
> 
> Simple example:
> 
> .sub 'main'
>      .local pmc i
>      i = new 'Integer'
>    do_loop:
>      say i
>      push_eh do_inc
>      $P0 = find_method i, "succ"
>      i.$P0()
>      pop_eh
>    do_inc:
>      inc i
>      goto do_loop
> .end

Exception handling doesn't really use a stack (in spite of the
opcode names "push_eh" and "pop_eh").  As discussed in #parrotsketch
earlier today and summarized at [1], the correct form of the
above loop would have the "pop_eh" line after the do_inc label,
so that every exception handler created in the loop is removed
before going on to the next loop iteration.

With the following example (and the other patches to 
Parrot_ex_throw_from_op_args added by NotFound++), I'm able
to run the following version and get to 250,000 without any
difficulty.  

    $ cat x.pir
    .sub 'main'
         .local pmc i
         i = new 'Integer'
       do_loop:
         say i
         push_eh do_inc
         $P0 = find_method i, "succ"
         i.$P0()
       do_inc:
         pop_eh
         inc i
         goto do_loop
    .end
    $ ./parrot x.pir 
    0
    1
    2
    3
    4
    ...
    249997
    249998
    249999
    250000
    250001
    250002
    ^C

(The top(1) command on my machine seems to indicate a small memory leak
in the above, but it does run a significant ways, and I didn't
investigate further.)

Pm

Reply via email to