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

Side by Side Diff: src/runtime/runtime-debug.cc

Issue 2882973002: [coverage] Block coverage with support for IfStatements (Closed)
Patch Set: Address comments Created 3 years, 6 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
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/code-coverage-block.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/debug/debug-coverage.h" 9 #include "src/debug/debug-coverage.h"
10 #include "src/debug/debug-evaluate.h" 10 #include "src/debug/debug-evaluate.h"
11 #include "src/debug/debug-frames.h" 11 #include "src/debug/debug-frames.h"
12 #include "src/debug/debug-scopes.h" 12 #include "src/debug/debug-scopes.h"
13 #include "src/debug/debug.h" 13 #include "src/debug/debug.h"
14 #include "src/debug/liveedit.h" 14 #include "src/debug/liveedit.h"
15 #include "src/frames-inl.h" 15 #include "src/frames-inl.h"
16 #include "src/globals.h" 16 #include "src/globals.h"
17 #include "src/interpreter/bytecodes.h" 17 #include "src/interpreter/bytecodes.h"
18 #include "src/interpreter/interpreter.h" 18 #include "src/interpreter/interpreter.h"
19 #include "src/isolate-inl.h" 19 #include "src/isolate-inl.h"
20 #include "src/objects/debug-objects-inl.h"
20 #include "src/runtime/runtime.h" 21 #include "src/runtime/runtime.h"
21 #include "src/wasm/wasm-module.h" 22 #include "src/wasm/wasm-module.h"
22 #include "src/wasm/wasm-objects.h" 23 #include "src/wasm/wasm-objects.h"
23 24
24 namespace v8 { 25 namespace v8 {
25 namespace internal { 26 namespace internal {
26 27
27 RUNTIME_FUNCTION(Runtime_DebugBreak) { 28 RUNTIME_FUNCTION(Runtime_DebugBreak) {
28 SealHandleScope shs(isolate); 29 SealHandleScope shs(isolate);
29 DCHECK_EQ(1, args.length()); 30 DCHECK_EQ(1, args.length());
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 RUNTIME_FUNCTION(Runtime_DebugIsActive) { 1914 RUNTIME_FUNCTION(Runtime_DebugIsActive) {
1914 SealHandleScope shs(isolate); 1915 SealHandleScope shs(isolate);
1915 return Smi::FromInt(isolate->debug()->is_active()); 1916 return Smi::FromInt(isolate->debug()->is_active());
1916 } 1917 }
1917 1918
1918 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 1919 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
1919 UNIMPLEMENTED(); 1920 UNIMPLEMENTED();
1920 return NULL; 1921 return NULL;
1921 } 1922 }
1922 1923
1924 namespace {
1925 Handle<JSObject> MakeRangeObject(Isolate* isolate, const CoverageBlock& range) {
1926 Factory* factory = isolate->factory();
1927
1928 Handle<String> start_string = factory->InternalizeUtf8String("start");
1929 Handle<String> end_string = factory->InternalizeUtf8String("end");
1930 Handle<String> count_string = factory->InternalizeUtf8String("count");
1931
1932 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto();
1933 JSObject::AddProperty(range_obj, start_string,
1934 factory->NewNumberFromInt(range.start), NONE);
1935 JSObject::AddProperty(range_obj, end_string,
1936 factory->NewNumberFromInt(range.end), NONE);
1937 JSObject::AddProperty(range_obj, count_string,
1938 factory->NewNumberFromUint(range.count), NONE);
1939
1940 return range_obj;
1941 }
1942 } // namespace
1943
1923 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { 1944 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) {
1924 HandleScope scope(isolate); 1945 HandleScope scope(isolate);
1925 DCHECK_EQ(0, args.length()); 1946 DCHECK_EQ(0, args.length());
1926 // Collect coverage data. 1947 // Collect coverage data.
1927 std::unique_ptr<Coverage> coverage; 1948 std::unique_ptr<Coverage> coverage;
1928 if (isolate->is_best_effort_code_coverage()) { 1949 if (isolate->is_best_effort_code_coverage()) {
1929 coverage.reset(Coverage::CollectBestEffort(isolate)); 1950 coverage.reset(Coverage::CollectBestEffort(isolate));
1930 } else { 1951 } else {
1931 coverage.reset(Coverage::CollectPrecise(isolate)); 1952 coverage.reset(Coverage::CollectPrecise(isolate));
1932 } 1953 }
1933 Factory* factory = isolate->factory(); 1954 Factory* factory = isolate->factory();
1934 // Turn the returned data structure into JavaScript. 1955 // Turn the returned data structure into JavaScript.
1935 // Create an array of scripts. 1956 // Create an array of scripts.
1936 int num_scripts = static_cast<int>(coverage->size()); 1957 int num_scripts = static_cast<int>(coverage->size());
1937 // Prepare property keys. 1958 // Prepare property keys.
1938 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); 1959 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts);
1939 Handle<String> script_string = factory->NewStringFromStaticChars("script"); 1960 Handle<String> script_string = factory->NewStringFromStaticChars("script");
1940 Handle<String> start_string = factory->NewStringFromStaticChars("start");
1941 Handle<String> end_string = factory->NewStringFromStaticChars("end");
1942 Handle<String> count_string = factory->NewStringFromStaticChars("count");
1943 for (int i = 0; i < num_scripts; i++) { 1961 for (int i = 0; i < num_scripts; i++) {
1944 const auto& script_data = coverage->at(i); 1962 const auto& script_data = coverage->at(i);
1945 HandleScope inner_scope(isolate); 1963 HandleScope inner_scope(isolate);
1964
1965 std::vector<CoverageBlock> ranges;
1946 int num_functions = static_cast<int>(script_data.functions.size()); 1966 int num_functions = static_cast<int>(script_data.functions.size());
1947 Handle<FixedArray> functions_array = factory->NewFixedArray(num_functions);
1948 for (int j = 0; j < num_functions; j++) { 1967 for (int j = 0; j < num_functions; j++) {
1949 const auto& function_data = script_data.functions[j]; 1968 const auto& function_data = script_data.functions[j];
1950 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); 1969 ranges.emplace_back(function_data.start, function_data.end,
1951 JSObject::AddProperty(range_obj, start_string, 1970 function_data.count);
1952 factory->NewNumberFromInt(function_data.start), 1971 for (size_t k = 0; k < function_data.blocks.size(); k++) {
1953 NONE); 1972 const auto& block_data = function_data.blocks[k];
1954 JSObject::AddProperty(range_obj, end_string, 1973 ranges.emplace_back(block_data.start, block_data.end, block_data.count);
1955 factory->NewNumberFromInt(function_data.end), NONE); 1974 }
1956 JSObject::AddProperty(range_obj, count_string,
1957 factory->NewNumberFromUint(function_data.count),
1958 NONE);
1959 functions_array->set(j, *range_obj);
1960 } 1975 }
1976
1977 int num_ranges = static_cast<int>(ranges.size());
1978 Handle<FixedArray> ranges_array = factory->NewFixedArray(num_ranges);
1979 for (int j = 0; j < num_ranges; j++) {
1980 Handle<JSObject> range_object = MakeRangeObject(isolate, ranges[j]);
1981 ranges_array->set(j, *range_object);
1982 }
1983
1961 Handle<JSArray> script_obj = 1984 Handle<JSArray> script_obj =
1962 factory->NewJSArrayWithElements(functions_array, FAST_ELEMENTS); 1985 factory->NewJSArrayWithElements(ranges_array, FAST_ELEMENTS);
1963 Handle<JSObject> wrapper = Script::GetWrapper(script_data.script); 1986 Handle<JSObject> wrapper = Script::GetWrapper(script_data.script);
1964 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); 1987 JSObject::AddProperty(script_obj, script_string, wrapper, NONE);
1965 scripts_array->set(i, *script_obj); 1988 scripts_array->set(i, *script_obj);
1966 } 1989 }
1967 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); 1990 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS);
1968 } 1991 }
1969 1992
1970 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { 1993 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) {
1971 SealHandleScope shs(isolate); 1994 SealHandleScope shs(isolate);
1972 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); 1995 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0);
1973 Coverage::SelectMode(isolate, enable ? debug::Coverage::kPreciseCount 1996 Coverage::SelectMode(isolate, enable ? debug::Coverage::kPreciseCount
1974 : debug::Coverage::kBestEffort); 1997 : debug::Coverage::kBestEffort);
1975 return isolate->heap()->undefined_value(); 1998 return isolate->heap()->undefined_value();
1976 } 1999 }
1977 2000
2001 RUNTIME_FUNCTION(Runtime_DebugToggleBlockCoverage) {
2002 SealHandleScope shs(isolate);
2003 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0);
2004 Coverage::SelectMode(isolate, enable ? debug::Coverage::kBlockCount
2005 : debug::Coverage::kBestEffort);
2006 return isolate->heap()->undefined_value();
2007 }
2008
2009 RUNTIME_FUNCTION(Runtime_IncBlockCounter) {
2010 SealHandleScope scope(isolate);
2011 DCHECK_EQ(2, args.length());
2012 CONVERT_ARG_CHECKED(JSFunction, function, 0);
2013 CONVERT_SMI_ARG_CHECKED(coverage_array_slot_index, 1);
2014
2015 DCHECK(FLAG_block_coverage);
2016
2017 DebugInfo* debug_info = function->shared()->GetDebugInfo();
2018 CoverageInfo* coverage_info = CoverageInfo::cast(debug_info->coverage_info());
2019 coverage_info->IncrementBlockCount(coverage_array_slot_index);
2020
2021 return isolate->heap()->undefined_value();
2022 }
2023
1978 } // namespace internal 2024 } // namespace internal
1979 } // namespace v8 2025 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/mjsunit/code-coverage-block.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698