HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
external
v8
src
debug
debug-coverage.cc
// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/debug/debug-coverage.h" #include "src/base/hashmap.h" #include "src/deoptimizer.h" #include "src/isolate.h" #include "src/objects-inl.h" #include "src/objects.h" namespace v8 { namespace internal { class SharedToCounterMap : public base::TemplateHashMapImpl
, base::DefaultAllocationPolicy> { public: typedef base::TemplateHashMapEntry
Entry; inline void Add(SharedFunctionInfo* key, uint32_t count) { Entry* entry = LookupOrInsert(key, Hash(key), []() { return 0; }); uint32_t old_count = entry->value; if (UINT32_MAX - count < old_count) { entry->value = UINT32_MAX; } else { entry->value = old_count + count; } } inline uint32_t Get(SharedFunctionInfo* key) { Entry* entry = Lookup(key, Hash(key)); if (entry == nullptr) return 0; return entry->value; } private: static uint32_t Hash(SharedFunctionInfo* key) { return static_cast
(reinterpret_cast
(key)); } DisallowHeapAllocation no_gc; }; namespace { int StartPosition(SharedFunctionInfo* info) { int start = info->function_token_position(); if (start == kNoSourcePosition) start = info->start_position(); return start; } bool CompareSharedFunctionInfo(SharedFunctionInfo* a, SharedFunctionInfo* b) { int a_start = StartPosition(a); int b_start = StartPosition(b); if (a_start == b_start) return a->end_position() > b->end_position(); return a_start < b_start; } } // anonymous namespace Coverage* Coverage::Collect(Isolate* isolate, bool reset_count) { SharedToCounterMap counter_map; // Feed invocation count into the counter map. if (isolate->IsCodeCoverageEnabled()) { // Feedback vectors are already listed to prevent losing them to GC. Handle
list = Handle
::cast(isolate->factory()->code_coverage_list()); for (int i = 0; i < list->Length(); i++) { FeedbackVector* vector = FeedbackVector::cast(list->Get(i)); SharedFunctionInfo* shared = vector->shared_function_info(); DCHECK(shared->IsSubjectToDebugging()); uint32_t count = static_cast
(vector->invocation_count()); if (reset_count) vector->clear_invocation_count(); counter_map.Add(shared, count); } } else { // Iterate the heap to find all feedback vectors and accumulate the // invocation counts into the map for each shared function info. HeapIterator heap_iterator(isolate->heap()); while (HeapObject* current_obj = heap_iterator.next()) { if (!current_obj->IsFeedbackVector()) continue; FeedbackVector* vector = FeedbackVector::cast(current_obj); SharedFunctionInfo* shared = vector->shared_function_info(); if (!shared->IsSubjectToDebugging()) continue; uint32_t count = static_cast
(vector->invocation_count()); if (reset_count) vector->clear_invocation_count(); counter_map.Add(shared, count); } } // Iterate shared function infos of every script and build a mapping // between source ranges and invocation counts. Coverage* result = new Coverage(); Script::Iterator scripts(isolate); while (Script* script = scripts.Next()) { // Dismiss non-user scripts. if (script->type() != Script::TYPE_NORMAL) continue; // Create and add new script data. Handle
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册