Faculty of Information Technology
Software Engineering Group

Ticket #186: libtool_fix_1_of_1_rev_ff14adbaf594_Issue__186__load_debugger_resources_in_separate_thread_to_avoid_stack_exhaustion.patch

File libtool_fix_1_of_1_rev_ff14adbaf594_Issue__186__load_debugger_resources_in_separate_thread_to_avoid_stack_exhaustion.patch, 2.1 KB (added by Jan Vrany, 2 years ago)
  • DebugView.st

    # HG changeset patch
    # User Jan Vrany <jan.vrany@fit.cvut.cz>
    # Date 1512725308 0
    #      Fri Dec 08 09:28:28 2017 +0000
    # Branch jv
    # Node ID ff14adbaf594993a7af38eef675ff42cfd91010b
    # Parent  4d8f7dd66c195cb0f4ab60b73f2ea3f1938f75b5
    Issue #186: load debugger resources in separate thread to avoid stack exhaustion
    
    When reading debugger resources, we need to be extra careful.
    Loading resources may take a lot of stack space (recursive
    parsing). In case debugger is opened due to a recursion
    interrupt, stack is very limited and exhausting it leads to
    hard termination of the process (at least on systems with
    fixed-sized stacks such as Windows or, IIUC, macOS).
    
    To mitigate this we load resources in another thread and
    hope we won't deadlock.
    
    diff -r 4d8f7dd66c19 -r ff14adbaf594 DebugView.st
    a b  
    18841884    "Modified: / 28-08-2013 / 20:23:35 / cg"
    18851885! !
    18861886
     1887!DebugView class methodsFor:'resources'!
     1888
     1889classResources
     1890    "If not already loaded, get the classes resourcePack and return it"
     1891
     1892    ClassResources isNil ifTrue:[
     1893        "/ Here we have to be really careful. We need to load resources
     1894        "/ but that takes a lot of stack space (recursive parsing). In case
     1895        "/ debugger is opened due to a recursion interrupt, stack is very
     1896        "/ limited and exhausting it leads to hard termination of the
     1897        "/ process (at least on systems with fixed-sized stacks such as
     1898        "/ Windows or, IIUC, macOS).
     1899        "/
     1900        "/ To mitigate this we load resources in another thread and hopr
     1901        "/ we won't deadlock. Sigh.
     1902
     1903        | loaded |
     1904
     1905        loaded := Semaphore new.
     1906        [
     1907            super classResources.
     1908            loaded signal.
     1909        ] forkAt: Processor activeProcess priority + 1.
     1910        loaded wait.
     1911    ].
     1912    ^ ClassResources
     1913
     1914    "
     1915    ClassResources := nil.
     1916    DebugView classResources
     1917    "
     1918
     1919    "Created: / 08-12-2017 / 09:15:00 / jv"
     1920! !
     1921
    18871922!DebugView class methodsFor:'utilities'!
    18881923
    18891924withOptionToIgnoreException:exceptionOrHandlerSet do:aBlock