OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/coverage.h" | 5 #include "vm/coverage.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/json_stream.h" | 11 #include "vm/json_stream.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
13 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 DEFINE_FLAG(charp, coverage_dir, NULL, | 17 DEFINE_FLAG(charp, coverage_dir, NULL, |
18 "Enable writing coverage data into specified directory."); | 18 "Enable writing coverage data into specified directory."); |
19 | 19 |
20 | 20 |
21 void CodeCoverage::CompileAndAdd(const Function& function, | 21 void CodeCoverage::CompileAndAdd(const Function& function, |
22 const JSONArray& hits_arr) { | 22 const JSONArray& hits_arr) { |
23 if (!function.HasCode()) { | 23 if (!function.HasCode()) { |
24 if (Compiler::CompileFunction(function) != Error::null()) { | 24 // If the function should not be compiled or if the compilation failed, |
| 25 // then just skip this method. |
| 26 // TODO(iposva): Maybe we should skip synthesized methods in general too. |
| 27 if (function.is_abstract() || function.IsRedirectingFactory()) { |
| 28 return; |
| 29 } |
| 30 if (function.IsNonImplicitClosureFunction() && |
| 31 (function.context_scope() == ContextScope::null())) { |
| 32 // TODO(iposva): This can arise if we attempt to compile an inner function |
| 33 // before we have compiled its enclosing function or if the enclosing |
| 34 // function failed to compile. |
| 35 OS::Print("### Coverage skipped compiling: %s\n", function.ToCString()); |
| 36 return; |
| 37 } |
| 38 const Error& err = Error::Handle(Compiler::CompileFunction(function)); |
| 39 if (!err.IsNull()) { |
| 40 OS::Print("### Coverage failed compiling:\n%s\n", err.ToErrorCString()); |
25 return; | 41 return; |
26 } | 42 } |
27 } | 43 } |
28 ASSERT(function.HasCode()); | 44 ASSERT(function.HasCode()); |
29 | 45 |
30 Isolate* isolate = Isolate::Current(); | 46 Isolate* isolate = Isolate::Current(); |
31 // Print the hit counts for all IC datas. | 47 // Print the hit counts for all IC datas. |
32 const Script& script = Script::Handle(function.script()); | 48 const Script& script = Script::Handle(function.script()); |
33 const Code& code = Code::Handle(function.unoptimized_code()); | 49 const Code& code = Code::Handle(function.unoptimized_code()); |
34 const Array& ic_array = Array::Handle(code.ExtractTypeFeedbackArray()); | 50 const Array& ic_array = Array::Handle(code.ExtractTypeFeedbackArray()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void* file = (*file_open)(filename, true); | 180 void* file = (*file_open)(filename, true); |
165 if (file == NULL) { | 181 if (file == NULL) { |
166 OS::Print("Failed to write coverage file: %s\n", filename); | 182 OS::Print("Failed to write coverage file: %s\n", filename); |
167 return; | 183 return; |
168 } | 184 } |
169 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file); | 185 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file); |
170 (*file_close)(file); | 186 (*file_close)(file); |
171 } | 187 } |
172 | 188 |
173 } // namespace dart | 189 } // namespace dart |
OLD | NEW |