9#include <unordered_map>
20class ProfileDataFromFileInternal :
public ProfileDataFromFile {
24 void set_hash(
int hash) {
29 void AddHintToBlock(
size_t true_block_id,
size_t false_block_id,
32 block_hints_by_id.insert(std::make_pair(
33 std::make_pair(true_block_id, false_block_id), hint != 0));
36#ifdef LOG_BUILTIN_BLOCK_COUNT
37 void AddBlockExecutionCount(
size_t block_id, uint64_t executed_count) {
38 executed_count_.emplace(block_id, executed_count);
46const std::unordered_map<std::string, ProfileDataFromFileInternal>&
47EnsureInitProfileData() {
48 static base::LeakyObject<
49 std::unordered_map<std::string, ProfileDataFromFileInternal>>
51 static bool initialized =
false;
53 if (initialized)
return *data.get();
55#ifdef LOG_BUILTIN_BLOCK_COUNT
56 if (
v8_flags.turbo_log_builtins_count_input) {
57 std::ifstream raw_count_file(
58 v8_flags.turbo_log_builtins_count_input.value());
60 "Can't read raw count file for log builtin hotness.");
61 for (std::string line; std::getline(raw_count_file, line);) {
63 std::istringstream line_stream(line);
64 if (!std::getline(line_stream, token,
'\t'))
continue;
69 std::string builtin_name;
70 CHECK(std::getline(line_stream, builtin_name,
'\t'));
71 std::string block_id_str;
72 CHECK(std::getline(line_stream, block_id_str,
'\t'));
76 static_cast<uint32_t
>(strtoul(block_id_str.c_str(), &
end, 10));
78 std::string executed_count_str;
79 CHECK(std::getline(line_stream, executed_count_str,
'\t'));
80 uint64_t executed_count =
static_cast<uint64_t
>(
81 strtoul(executed_count_str.c_str(), &
end, 10));
82 CHECK(errno == 0 &&
end != token.c_str());
83 std::getline(line_stream, token,
'\t');
84 ProfileDataFromFileInternal& block_count = (*data.get())[builtin_name];
85 block_count.AddBlockExecutionCount(block_id, executed_count);
86 CHECK(line_stream.eof());
91 std::string builtin_name;
92 CHECK(std::getline(line_stream, builtin_name,
'\t'));
93 std::getline(line_stream, token,
'\t');
94 CHECK(line_stream.eof());
96 int hash =
static_cast<int>(strtol(token.c_str(), &
end, 0));
97 CHECK(errno == 0 &&
end != token.c_str());
98 ProfileDataFromFileInternal& block_count = (*data.get())[builtin_name];
99 CHECK_IMPLIES(block_count.hash_has_value(), block_count.hash() == hash);
100 block_count.set_hash(hash);
106 if (
filename ==
nullptr)
return *data.get();
109 for (std::string line; std::getline(file, line);) {
111 std::istringstream line_stream(line);
112 if (!std::getline(line_stream, token,
','))
continue;
117 std::string builtin_name;
118 CHECK(std::getline(line_stream, builtin_name,
','));
119 CHECK(std::getline(line_stream, token,
','));
122 uint32_t true_id =
static_cast<uint32_t
>(strtoul(token.c_str(), &
end, 0));
123 CHECK(errno == 0 &&
end != token.c_str());
124 CHECK(std::getline(line_stream, token,
','));
126 static_cast<uint32_t
>(strtoul(token.c_str(), &
end, 0));
127 CHECK(errno == 0 &&
end != token.c_str());
128 std::getline(line_stream, token,
',');
129 CHECK(line_stream.eof());
130 uint64_t hint = strtoul(token.c_str(), &
end, 10);
131 CHECK(errno == 0 &&
end != token.c_str());
132 ProfileDataFromFileInternal& hints_and_hash = (*data.get())[builtin_name];
134 hints_and_hash.AddHintToBlock(true_id, false_id, hint);
135 CHECK(line_stream.eof());
140 std::string builtin_name;
141 CHECK(std::getline(line_stream, builtin_name,
','));
142 std::getline(line_stream, token,
',');
143 CHECK(line_stream.eof());
145 int hash =
static_cast<int>(strtol(token.c_str(), &
end, 0));
146 CHECK(errno == 0 &&
end != token.c_str());
147 ProfileDataFromFileInternal& hints_and_hash = (*data.get())[builtin_name];
152 hints_and_hash.hash() == hash);
153 hints_and_hash.set_hash(hash);
156 for (
const auto& pair : *data.get()) {
158 CHECK(pair.second.hash_has_value());
166 const auto& data = EnsureInitProfileData();
167 auto it = data.find(name);
168 return it == data.end() ?
nullptr : &it->second;
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
static const ProfileDataFromFile * TryRead(const char *name)
static constexpr char kBuiltinHashMarker[]
static constexpr char kBlockCounterMarker[]
static constexpr char kBlockHintMarker[]
V8_EXPORT_PRIVATE FlagValues v8_flags
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation nullptr
#define CHECK_IMPLIES(lhs, rhs)
#define CHECK_LT(lhs, rhs)
#define CHECK_WITH_MSG(condition, message)