Debian Codegraph @

js/src/doc/HazardAnalysis/running.md

raw
1 # Running the Rooting Hazard Analysis
2
3 The `js/src/devtools/rootAnalysis` directory contains scripts for running Brian
4 Hackett's static GC rooting and thread heap write safety analyses on a JS
5 source directory.
6
7 To run the analysis on SpiderMonkey:
8
9 1. Unset your $MOZCONFIG
10
11 unset MOZCONFIG
12
13 2. Install prerequisites.
14
15 mach hazards bootstrap
16
17 3. Build the shell to run the analysis.
18
19 mach hazards build-shell
20
21 4. Compile all the code to gather info.
22
23 mach hazards gather --project=js
24
25 5. Analyze the gathered info.
26
27 mach hazards analyze --project=js
28
29 Output goes to `$srctop/haz-js/hazards.txt`. This will run the analysis on the js/src
30 tree only; if you wish to analyze the full browser, use
31
32 --project=browser
33
34 (or leave it off; `--project=browser` is the default)
35
36 6. (optional) View the resulting hazards.
37
38 mach hazards view --project=js
39
40 After running the analysis once, you can reuse the `*.xdb` database files
41 generated, using modified analysis scripts, by running either the `mach hazards
42 analyze` command above, or by adding on `mach hazards analyze <step>` to
43 run a subset of the analysis steps; `mach hazards analyze -- --list` to see
44 step names.
45
46 Also, you can pass `-- -v` to get exact command lines to cut & paste for running
47 the various stages, which is helpful for running under a debugger.
48
49 ## Incremental Analyses
50
51 Once you have an analysis, you can make code changes and rebuild with `mach hazards gather`. This will add to the existing `*.xdb` files, which will *usually* work ok, but sometimes older compilations will have left around information that will get in the way. A typical example is with lambda functions: you may get hazards reported due to lambdas that no longer exist, but the newer compile will not replace them. Although this could be fixed with some amount of effort, you're fighting against something of a fundamental problem where the analysis is depending on certain things *NOT* happening (eg calls to the GC) and incremental compilation only adds and replaces existing information. It does not remove information unless it is replacing it with something of a matching name (and things like lambdas have autogenerated numbers in their names that vary between compiles.)
52
53 In short: for development speed, feel free to use incremental analyses but don't trust them. If the hazard analysis starts claiming the impossible is happening, try `mach hazards clobber` and do a full rebuild.
54
55 ## Overview of what is going on here
56
57 So what does this actually do?
58
59 1. It downloads a GCC compiler and plugin ("sixgill") from Mozilla servers.
60
61 2. It runs `run_complete`, a script that builds the target codebase with the
62 downloaded GCC, generating a few database files containing control flow
63 graphs of the full compile, along with type information etc.
64
65 3. Then it runs `analyze.py`, a Python script, which runs all the scripts
66 which actually perform the analysis -- the tricky parts.
67 (Those scripts are written in JS.)
68
69 The easiest way to get this running is to not try to do the instrumented
70 compilation locally. Instead, grab the relevant files from a try server push
71 and analyze them locally.
72
73 ## Local Analysis of Downloaded Intermediate Files
74
75 Another useful path is to let the continuous integration system do the hard
76 work of generating the intermediate files and analyze them locally. This is
77 particularly useful if you are working on the analysis itself.
78
79 * Do a try push with "--upload-xdbs" appended to the try: ..." line.
80
81 mach try fuzzy -q "'haz" --upload-xdbs
82
83 * Create an empty directory to run the analysis.
84
85 * When the try job is complete, download the resulting `src_body.xdb.bz2`,
86 `src_comp.xdb.bz2`, and `file_source.xdb.bz2` files into your directory.
87
88 * Fetch a compiler and sixgill plugin to use:
89
90 mach hazards bootstrap
91
92 If you are on osx, these will not be available. Instead, build sixgill manually
93 (these directions are a little stale):
94
95 hg clone https://hg.mozilla.org/users/sfink_mozilla.com/sixgill
96 cd sixgill
97 CC=$HOME/.mozbuild/hazard-tools/gcc/bin/gcc ./release.sh --build # This will fail horribly.
98 make bin/xdb.so CXX=clang++
99
100 * Build an optimized JS shell with ctypes. Note that this does not need to
101 match the source you are analyzing in any way; in fact, you pretty much never
102 need to update this once you've built it. (Though I reserve the right to use
103 any new JS features implemented in Spidermonkey in the future...)
104
105 mach hazards build-shell
106
107 The shell will be placed by default in `$topsrcdir/obj-haz-shell`.
108
109 * Make a defaults.py file containing the following, with your own paths filled in:
110
111 js = "<objdir>/dist/bin/js"
112 sixgill_bin = "<sixgill-dir>/bin"
113
114 * For the rooting analysis, run
115
116 python <srcdir>/js/src/devtools/rootAnalysis/analyze.py gcTypes
117
118 * For the heap write analysis, run
119
120 python <srcdir>/js/src/devtools/rootAnalysis/analyze.py heapwrites
121
122 Also, you may wish to run with -v (aka --verbose) to see the exact commands
123 executed that you can cut & paste if needed. (I use them to run under the JS
124 debugger when I'm working on the analysis.)