Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception stacks #28878

Merged
merged 16 commits into from
Oct 23, 2018
Merged

Exception stacks #28878

merged 16 commits into from
Oct 23, 2018

Commits on Oct 5, 2018

  1. Configuration menu
    Copy the full SHA
    38d1ba6 View commit details
    Browse the repository at this point in the history
  2. Consolidate _resetstkoflw handling

    The logic for this was repeated in three quite different ways, in
    JL_CATCH, interpreter and codegen but putting it into the runtime in
    jl_eh_restore_state should be sufficient.
    
    Also move jl_eh_restore_state out of main header - seems unnecessary to
    expose such implementation detail, and inconsistent with other eh
    functions.
    c42f committed Oct 5, 2018
    Configuration menu
    Copy the full SHA
    0e8811a View commit details
    Browse the repository at this point in the history
  3. Lowering for exception stacks

    * A new lowered expression head :pop_exc is introduced and emitted in any
      location where a catch block exits normally (either by stepping out,
      or using return, break, goto). The semantics of :pop_exc are to pop
      the exception stack back to the state of the associated enter.
    
    * Make Expr(:enter) return a token which may be consumed by :pop_exc,
      thereby allowing the interpreter and codegen to know which :enter
      state should be used to pop the exception stack.  I tried various
      alternatives for this association, but this was by far the nicest in
      terms of non-disruptive integration into the SSAIR processing code,
      and supporting both the interpreter and codegen.
    c42f committed Oct 5, 2018
    Configuration menu
    Copy the full SHA
    57b46e7 View commit details
    Browse the repository at this point in the history
  4. Add exception stack system to runtime

    Runtime
    -------
    
    * An exception stack type, `jl_exc_stack_t` and associated manipulation functions
      has been added. Conceptually this stores a stack of (exception,backtrace)
      pairs. It's stored in a contiguous buffer so we can avoid reallocating when
      throwing and catching the same exception or set of exceptions repeatedly. Space
      for the exception and backtrace is allocated on demand inside `throw_internal`,
      after changing GC mode. Several variations were tried for allocating this
      sgorage, including allocating up front with malloc on the thread local state
      and copying during task switching. Keeping everything on the task seemed the
      simplest as it involves the least copying and keeps track of the exception
      stack buffers in a unified way.
    
    * The exception in transit is no longer a single pointer in the thread local
      storage. It's stored in `ptls->current_task->exc_stack` instead, along with
      associated backtrace.
    
    * `jl_current_exception()` is now the method to retreive the current exception
      from within a `JL_CATCH` dynamic context.
    
    * Several places where manual restoration of the exception and backtrace was
      done are no longer necessary because the stack system handles these
      automatically. This code is removed, including
      `jl_apply_with_saved_exception_state`.
    
    * `jl_eh_restore_state` has become non-inline. It seemed good to get this out
      of the public header.
    
    * `jl_sig_throw` is now used with `jl_throw_in_ctx` from signal handlers, to
      make the special circumstances clear and to avoid conflation with rethrow
      which now simply rethrows the existing exception stack.
    
    * Make rethrow outside a catch block into an error.
    
    * Use `ptls->previous_exception` to support `jl_exception_occurred` in
      embedding API.
    
    * finally lowering no longer includes a `foreigncall`, so expressions
      using finally can now be interpreted.
    
    Interpreter / Codegen
    ---------------------
    
    Mostly small changes here, to track the `:enter` and `:pop_exc` association
    with the SSAValue token. The token SSAValue slot is ideal here for storing the
    state of the exception stack at the `:enter`.
    
    GC
    --
    
    Integrate exception and raw backtrace scanning as a special case into GC mark
    loop. This is necessary now that Task objects can refer to exception and
    backtrace data in raw form.
    c42f committed Oct 5, 2018
    3 Configuration menu
    Copy the full SHA
    31e76c2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    7407b3b View commit details
    Browse the repository at this point in the history

Commits on Oct 7, 2018

  1. Fix some GC rooting problems, add GC-SA annotations

    Add missing GC static analyzer annotations to exception stack functions
    and fix two problems found by the GC static analyser:
    * An early return with missing GC_POP
    * Missing root for the exception across a safe point in throw_internal
    c42f committed Oct 7, 2018
    Configuration menu
    Copy the full SHA
    c4132dc View commit details
    Browse the repository at this point in the history

Commits on Oct 10, 2018

  1. Configuration menu
    Copy the full SHA
    2fd3212 View commit details
    Browse the repository at this point in the history

Commits on Oct 11, 2018

  1. Workaround gcc-5 miscompilation with asserts and double return functions

    gcc-5 appears to miscompile jl_type_infer under special circumstances,
    leading to segfaults but gcc-7 and clang do fine on this.  The "special
    circumstances" are that assertions are enabled when preprocessing
    jl_svecref for use within jl_type_infer specifically.
    
    There are various ways to remove the segfaults and force a correct
    compilation:
    
    * The given rearrangement
    
    * Replacing jl_svecref in the last part of jl_type_infer with an
      equivalent function, but without the assertions.
    
    * Removing the JL_TRY / JL_CATCH further up.
    
    It's suspicious that the error only occurs when both the double-return
    __sigsetjmp() and the no-return __assert_fail() are present inside the
    function in sufficient quantities. Perhaps the compiler is failing to
    analyze the interaction between these.
    c42f committed Oct 11, 2018
    Configuration menu
    Copy the full SHA
    250571c View commit details
    Browse the repository at this point in the history

Commits on Oct 14, 2018

  1. Exception stack runtime cleanup

    * Use functions rather than macros for exception stack access
    * Use standard type check macro
    * More clearly document gc rooting of `jl_current_exception()`
    c42f committed Oct 14, 2018
    Configuration menu
    Copy the full SHA
    3453c27 View commit details
    Browse the repository at this point in the history
  2. Rename Expr(:pop_exc) to Expr(:pop_exception)

    Better be explicit here for something that's not commonly encountered.
    c42f committed Oct 14, 2018
    Configuration menu
    Copy the full SHA
    1753529 View commit details
    Browse the repository at this point in the history
  3. More comprehensive exception stack tests

    * Test try-catch-finally form
    * Add a few tests to do with exiting try blocks.
    * More explanatory comments
    c42f committed Oct 14, 2018
    Configuration menu
    Copy the full SHA
    ea7643a View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5cab916 View commit details
    Browse the repository at this point in the history

Commits on Oct 17, 2018

  1. Automated renaming exc_stack -> excstack

    cd src
    ag -l exc_stack  | xargs sed -i -e 's/exc_stack/excstack/g'
    ag -l excstk_raw | xargs sed -i -e 's/excstk_raw/excstack_raw/g'
    sed -i -e 's/jlcurrent_exception_func/jl_current_exception_func/g' codegen.cpp
    
    cd ../base
    ag -l exc_stack  | xargs sed -i -e 's/exc_stack/excstack/g'
    c42f committed Oct 17, 2018
    Configuration menu
    Copy the full SHA
    5b0ca63 View commit details
    Browse the repository at this point in the history

Commits on Oct 18, 2018

  1. Configuration menu
    Copy the full SHA
    48e8f0f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1eaf27a View commit details
    Browse the repository at this point in the history

Commits on Oct 22, 2018

  1. Configuration menu
    Copy the full SHA
    3577e33 View commit details
    Browse the repository at this point in the history