v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
basic-block-profiler.h
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#ifndef V8_DIAGNOSTICS_BASIC_BLOCK_PROFILER_H_
6#define V8_DIAGNOSTICS_BASIC_BLOCK_PROFILER_H_
7
8#include <iosfwd>
9#include <list>
10#include <memory>
11#include <string>
12#include <vector>
13
14#include "src/base/macros.h"
16#include "src/common/globals.h"
18
19namespace v8 {
20namespace internal {
21
22class OnHeapBasicBlockProfilerData;
23
25 public:
26 explicit BasicBlockProfilerData(size_t n_blocks);
29 Isolate* isolate);
32
35
36 size_t n_blocks() const {
37 DCHECK_EQ(block_ids_.size(), counts_.size());
38 return block_ids_.size();
39 }
40 const uint32_t* counts() const { return &counts_[0]; }
41
42 void SetCode(const std::ostringstream& os);
43 void SetFunctionName(std::unique_ptr<char[]> name);
44 void SetSchedule(const std::ostringstream& os);
45 void SetBlockId(size_t offset, int32_t id);
46 void SetHash(int hash);
47 void AddBranch(int32_t true_block_id, int32_t false_block_id);
48
49 // Copy the data from this object into an equivalent object stored on the JS
50 // heap, so that it can survive snapshotting and relocation. This must
51 // happen on the main thread during finalization of the compilation.
53
54 void Log(Isolate* isolate, std::ostream& os);
55
56 private:
57 friend class BasicBlockProfiler;
58 friend std::ostream& operator<<(std::ostream& os,
59 const BasicBlockProfilerData& s);
60
62
64
65 // These vectors are indexed by reverse post-order block number.
66 std::vector<int32_t> block_ids_;
67 std::vector<uint32_t> counts_;
68 std::vector<std::pair<int32_t, int32_t>> branches_;
69 std::string function_name_;
70 std::string schedule_;
71 std::string code_;
72 int hash_ = 0;
73};
74
76 public:
77 using DataList = std::list<std::unique_ptr<BasicBlockProfilerData>>;
78
79 BasicBlockProfiler() = default;
83
85 BasicBlockProfilerData* NewData(size_t n_blocks);
87 V8_EXPORT_PRIVATE bool HasData(Isolate* isolate);
88 V8_EXPORT_PRIVATE void Print(Isolate* isolate, std::ostream& os);
89 V8_EXPORT_PRIVATE void Log(Isolate* isolate, std::ostream& os);
90
91 // Coverage bitmap in this context includes only on heap BasicBlockProfiler
92 // data. It is used to export coverage of builtins function loaded from
93 // snapshot.
94 V8_EXPORT_PRIVATE std::vector<bool> GetCoverageBitmap(Isolate* isolate);
95
96 const DataList* data_list() { return &data_list_; }
97
98 private:
101};
102
103std::ostream& operator<<(std::ostream& os, const BasicBlockProfilerData& s);
104
105// This struct comprises all callee inside a block.
106using BlockCallees = std::set<Builtin>;
107// This struct describes a call inside a caller, the key is block id, the value
108// is a set of callee builtins.
109using BuiltinCallees = std::unordered_map<int32_t, BlockCallees>;
110// This struct describes a map for all builtins which will call other builtin.
111using BuiltinCallMap = std::unordered_map<Builtin, BuiltinCallees>;
112
132
133} // namespace internal
134} // namespace v8
135
136#endif // V8_DIAGNOSTICS_BASIC_BLOCK_PROFILER_H_
BasicBlockProfilerData(const BasicBlockProfilerData &)=delete
void SetFunctionName(std::unique_ptr< char[]> name)
DirectHandle< OnHeapBasicBlockProfilerData > CopyToJSHeap(Isolate *isolate)
BasicBlockProfilerData & operator=(const BasicBlockProfilerData &)=delete
void SetCode(const std::ostringstream &os)
void SetBlockId(size_t offset, int32_t id)
std::vector< std::pair< int32_t, int32_t > > branches_
void CopyFromJSHeap(Tagged< OnHeapBasicBlockProfilerData > js_heap_data)
void SetSchedule(const std::ostringstream &os)
friend std::ostream & operator<<(std::ostream &os, const BasicBlockProfilerData &s)
void AddBranch(int32_t true_block_id, int32_t false_block_id)
void Log(Isolate *isolate, std::ostream &os)
V8_EXPORT_PRIVATE bool HasData(Isolate *isolate)
static V8_EXPORT_PRIVATE BasicBlockProfiler * Get()
BasicBlockProfilerData * NewData(size_t n_blocks)
BasicBlockProfiler & operator=(const BasicBlockProfiler &)=delete
V8_EXPORT_PRIVATE void Log(Isolate *isolate, std::ostream &os)
std::list< std::unique_ptr< BasicBlockProfilerData > > DataList
V8_EXPORT_PRIVATE std::vector< bool > GetCoverageBitmap(Isolate *isolate)
V8_EXPORT_PRIVATE void ResetCounts(Isolate *isolate)
V8_EXPORT_PRIVATE void Print(Isolate *isolate, std::ostream &os)
BasicBlockProfiler(const BasicBlockProfiler &)=delete
const BuiltinCallees * GetBuiltinCallees(Builtin builtin)
void AddBuiltinCall(Builtin caller, Builtin callee, int32_t block_id)
V8_INLINE void set_all_hash_matched(bool all_hash_matched)
V8_INLINE bool all_hash_matched() const
static BuiltinsCallGraph * Get()
BuiltinsCallGraph(const BuiltinsCallGraph &)=delete
BuiltinsCallGraph & operator=(const BuiltinsCallGraph &)=delete
int32_t offset
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
std::unordered_map< Builtin, BuiltinCallees > BuiltinCallMap
std::set< Builtin > BlockCallees
std::unordered_map< int32_t, BlockCallees > BuiltinCallees
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_INLINE
Definition v8config.h:500