Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: tools/gcmole/gcmole.lua

Issue 6812002: Add GCMole to the repository. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« tools/gcmole/gcmole.cc ('K') | « tools/gcmole/gcmole.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 -- Copyright 2011 the V8 project authors. All rights reserved.
Søren Thygesen Gjesse 2011/04/07 08:20:28 I don't have the Lua stule quide at hand but it wo
2 -- Redistribution and use in source and binary forms, with or without
3 -- modification, are permitted provided that the following conditions are
4 -- met:
5 --
6 -- * Redistributions of source code must retain the above copyright
7 -- notice, this list of conditions and the following disclaimer.
8 -- * Redistributions in binary form must reproduce the above
9 -- copyright notice, this list of conditions and the following
10 -- disclaimer in the documentation and/or other materials provided
11 -- with the distribution.
12 -- * Neither the name of Google Inc. nor the names of its
13 -- contributors may be used to endorse or promote products derived
14 -- from this software without specific prior written permission.
15 --
16 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 -- This is main driver for gcmole tool. See README for more details.
29 -- Usage: CLANG_BIN=clang-bin-dir lua tools/gcmole/gcmole.lua [arm|ia32|x64]
30
31 local DIR = arg[0]:match("^(.+)/[^/]+$")
32
33 local ARCHS = arg[1] and { arg[1] } or { 'ia32', 'arm', 'x64' }
34
35 local io = require "io"
36 local os = require "os"
37
38 function log(...)
39 io.stderr:write(string.format(...))
40 io.stderr:write "\n"
41 end
42
43 -------------------------------------------------------------------------------
44 -- Clang invocation
45
46 local CLANG_BIN = os.getenv "CLANG_BIN"
47
48 if not CLANG_BIN or CLANG_BIN == "" then
49 error "CLANG_BIN not set"
50 end
51
52 local function MakeClangCommandLine(plugin, triple, arch_define)
53 return CLANG_BIN .. "/clang -cc1 -load " .. DIR .. "/libgcmole.so"
54 .. " -plugin " .. plugin
55 .. " -triple " .. triple
56 .. " -D" .. arch_define
57 .. " -DENABLE_VMSTATE_TRACKING"
58 .. " -DENABLE_LOGGING_AND_PROFILING"
59 .. " -DENABLE_DEBUGGER_SUPPORT"
60 .. " -Isrc"
61 end
62
63 function InvokeClangPluginForEachFile(filenames, cfg, func)
64 local cmd_line = MakeClangCommandLine(cfg.plugin, cfg.triple, cfg.arch_define )
65
66 for _, filename in ipairs(filenames) do
67 log("-- %s", filename)
68
69 local action = cmd_line .. " src/" .. filename .. " 2>&1"
70
71 local pipe = io.popen(action)
72 func(filename, pipe:lines())
73 pipe:close()
74 end
75 end
76
77 -------------------------------------------------------------------------------
78 -- SConscript parsing
79
80 local function ParseSConscript()
81 local f = assert(io.open("src/SConscript"), "failed to open SConscript")
82 local sconscript = f:read('*a')
83 f:close()
84
85 local SOURCES = sconscript:match "SOURCES = {(.-)}";
86
87 local sources = {}
88
89 for condition, list in SOURCES:gmatch "'([^']-)': Split%(\"\"\"(.-)\"\"\"%)" do
90 local files = {}
91 for file in list:gmatch "[^%s]+" do table.insert(files, file) end
92 sources[condition] = files
93
94 end
95
96 for condition, list in SOURCES:gmatch "'([^']-)': %[(.-)%]" do
97 local files = {}
98 for file in list:gmatch "'([^']-)'" do table.insert(files, file) end
99 sources[condition] = files
100 end
101
102 return sources
103 end
104
105 local function EvaluateCondition(cond, props)
106 if cond == 'all' then return true end
107
108 local p, v = cond:match "(%w+):(%w+)"
109
110 assert(p and v, "failed to parse condition: " .. cond)
111 assert(props[p] ~= nil, "undefined configuration property: " .. p)
112
113 return props[p] == v
114 end
115
116 local function BuildFileList(sources, props)
117 local list = {}
118 for condition, files in pairs(sources) do
119 if EvaluateCondition(condition, props) then
120 for i = 1, #files do table.insert(list, files[i]) end
121 end
122 end
123 return list
124 end
125
126 local sources = ParseSConscript()
127
128 local function FilesForArch(arch)
129 return BuildFileList(sources, { os = 'linux', arch = arch, mode = 'debug', si mulator = ''})
130 end
131
132 local mtConfig = {}
133
134 mtConfig.__index = mtConfig
135
136 local function config (t) return setmetatable(t, mtConfig) end
137
138 function mtConfig:extend(t)
139 local e = {}
140 for k, v in pairs(self) do e[k] = v end
141 for k, v in pairs(t) do e[k] = v end
142 return config(e)
143 end
144
145 local ARCHITECTURES = {
146 ia32 = config { triple = "i586-unknown-linux", arch_define = "V8_TARGET_ARCH_ IA32" },
147 arm = config { triple = "i586-unknown-linux", arch_define = "V8_TARGET_ARCH_A RM" },
148 x64 = config { triple = "x86_64-unknown-linux", arch_define = "V8_TARGET_ARCH _X64" }
149 }
150
151 -------------------------------------------------------------------------------
152 -- GCSuspects Generation
153
154 local gc = {}
155 local funcs = {}
156
157 local function resolve(name)
158 local f = funcs[name]
159
160 if not f then
161 f = {}
162 funcs[name] = f
163
164 if name:match "Collect.*Garbage" then gc[name] = true end
165 end
166
167 return f
168 end
169
170 local function parse (filename, lines)
171 local scope
172
173 for funcname in lines do
174 if funcname:sub(1, 1) ~= '\t' then
175 resolve(funcname)
176 scope = funcname
177 else
178 local name = funcname:sub(2)
179 resolve(name)[scope] = true
180 end
181 end
182 end
183
184 local function propagate ()
185 log "** Propagating GC information"
186
187 local function mark(callers)
188 for caller, _ in pairs(callers) do
189 if not gc[caller] then
190 gc[caller] = true
191 mark(funcs[caller])
192 end
193 end
194 end
195
196 for funcname, callers in pairs(funcs) do
197 if gc[funcname] then mark(callers) end
198 end
199 end
200
201 local function GenerateGCSuspects(arch, files, cfg)
202 log ("** Building GC Suspects for %s", arch)
203 InvokeClangPluginForEachFile (files,
204 cfg:extend { plugin = "dump-callees" },
205 parse)
206
207 propagate()
208
209 local out = assert(io.open("gcsuspects", "w"))
210 for name, _ in pairs(gc) do out:write (name, '\n') end
211 out:close()
212 log ("** GCSuspects generated for %s", arch)
213 end
214
215 -------------------------------------------------------------------------------
216 -- Analysis
217
218 local function CheckCorrectnessForArch(arch)
219 local files = FilesForArch(arch)
220 local cfg = ARCHITECTURES[arch]
221
222 GenerateGCSuspects(arch, files, cfg)
223
224 local processed_files = 0
225 local errors_found = false
226 local function SearchForErrors(filename, lines)
227 processed_files = processed_files + 1
228 local err = false
229 for l in lines do
230 if l:match "^[^:]+:%d+:%d+:" or l:match "error" or l:match "warning" th en
231 errors_found = true
232 end
233 print(l)
234 end
235 end
236
237 log("** Searching for evaluation order problems for %s", arch)
238 InvokeClangPluginForEachFile(files,
239 cfg:extend { plugin = "find-problems" },
240 SearchForErrors)
241 log("** Done processing %d files. %s",
242 processed_files,
243 errors_found and "Errors found" or "No errors found")
244
245 return errors_found
246 end
247
248 local function SafeCheckCorrectnessForArch(arch)
249 local status, errors = pcall(CheckCorrectnessForArch, arch)
250 if not status then
251 print(string.format("There was an error: %s", errors))
252 errors = true
253 end
254 return errors
255 end
256
257 local errors = false
258
259 for _, arch in ipairs(ARCHS) do
260 if not ARCHITECTURES[arch] then
261 error ("Unknown arch: " .. arch)
262 end
263
264 errors = SafeCheckCorrectnessForArch(arch, report) or errors
265 end
266
267 os.exit(errors and 1 or 0)
OLDNEW
« tools/gcmole/gcmole.cc ('K') | « tools/gcmole/gcmole.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698