• Ulan Degenbaev's avatar
    [heap] Instrument mark-compact to track retaining paths for debugging. · 40c34606
    Ulan Degenbaev authored
    This patch adds a new intrinsic: %DebugTrackRetainingPath(object).
    Calling the intrinsic in JS code saves a weak reference to the given
    object in GC internal table of tracked objects.
    
    Each subsequent full GC prints to stdout the retaining path for each
    tracked object (if it is still alive). The retaining path is the real
    path that the marker took from the root set to the tracked object.
    
    This is useful for investigating of memory leaks:
    1) Add %DebugTrackRetainingPath(leaking_object) in JS code.
    For example:
      function foo() {
        let x = { bar: "bar"};
        %DebugTrackRetainingPath(x);
        return () => { return x; }
      }
    
      let closure = foo();
      gc();
    
    2) Run d8 with --allow-natives-syntax --track-retaining-path --expose-gc.
    
    3) Check the retaining path in stdout.
    
    For more detailed inspection, run d8 in gdb and set breakpoint in
    
    v8: :internal::Heap::PrintRetainingPath.
    Change-Id: I01a0faac1e009bc6c321fa75613900b49d2b036f
    Reviewed-on: https://chromium-review.googlesource.com/575972
    Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
    Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#46766}
    40c34606
visitors.h 3.12 KB