-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flambda-backend: Add [Obj.uniquely_reachable_words] (#1705)
* Add [Obj.uniqely_reachable_words] This function takes in a list of objects and for each one computes the number of words of memory that can be reachabed from that object, but no others in the list. * Fix implementation of [Obj.reachable_words] The previous changes to [caml_obj_reachable_words_once] were not compatible with the current usage in [Obj.reachable_words] but were overlooked. * Fix incorrect use of hashtable when adding roots Previously, we simply hashed the value instead of using [extern_lookup_position]. However, this doesn't appropriately guard against collisions and can cause our state to be inconsistent. Test case which gave incorrect, non-determinstic input before the fix ``` let data = List.init 10 (fun _ -> List.init 1 (fun i -> i)) let direct = List.map Obj.repr data @ [ Obj.repr data ] let print_s xs = List.map string_of_int xs |> String.concat "," |> print_endline let () = print_s (Obj.uniquely_reachable_words direct) let () = print_s (List.map Obj.reachable_words direct) ``` * Address code review - Move array iteration into C - Give meaningful names to constants in traversal code - Other minor changes * Make [tests/lib-obj/uniquely_reachable_words.ml] more robust Instead of relying on an exact number of words used which can differ slightly with the backend due to different optimizations, we deduce what objects are reachable bases on the sum of their sizes. * Optimize algorithm to only require a single iteration through the roots * Clean up code following review suggestions * Code style improvements * Additionally return the total size of shared memory This enables easier evaluation of the retainer profiling functionality as we can quantify how much memory we were able to assign uniquely to a root.
- Loading branch information
Showing
4 changed files
with
313 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.