45 if (
module_->lazily_generated_names.Has(
import.index))
continue;
50 if (
module_->lazily_generated_names.Has(ex.
index))
continue;
62 switch (
import.
kind) {
110static constexpr char kIdentifierChar[] = {
111 '_',
'!',
'_',
'#',
'$',
'%',
'&',
'\'',
112 '_',
'_',
'*',
'+',
'_',
'-',
'.',
'/',
113 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
114 '8',
'9',
':',
'_',
'<',
'=',
'>',
'?',
115 '@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
116 'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
117 'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
118 'X',
'Y',
'Z',
'_',
'\\',
'_',
'^',
'_',
119 '`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
120 'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
121 'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
122 'x',
'y',
'z',
'_',
'|',
'_',
'~',
'_',
129void SanitizeUnicodeName(StringBuilder& out,
const uint8_t* utf8_src,
131 if (length == 0)
return;
134 std::vector<uint16_t> utf16(decoder.utf16_length());
135 decoder.Decode(utf16.data(), utf8_data);
136 for (uint16_t c : utf16) {
137 if (c < 32 || c >= 127) {
140 out << kIdentifierChar[c - 32];
147 std::map<uint32_t, std::string>& target) {
148 const uint8_t* mod_start =
wire_bytes_.
begin() +
import.module_name.offset();
149 size_t mod_length =
import.module_name.length();
150 const uint8_t* field_start =
wire_bytes_.
begin() +
import.field_name.offset();
151 size_t field_length =
import.field_name.length();
154 SanitizeUnicodeName(buffer, mod_start, mod_length);
156 SanitizeUnicodeName(buffer, field_start, field_length);
157 target[
import.index] = std::string(buffer.
start(), buffer.
length());
161 std::map<uint32_t, std::string>& target) {
162 if (target.find(ex.
index) != target.end())
return;
164 if (length == 0)
return;
175 if (add_comment) out <<
" (;" << index <<
";)";
185 uint32_t function_index,
196 MaybeAddComment(out, function_index, index_as_comment);
214 MaybeAddComment(out, function_index, index_as_comment);
216 out <<
"$func" << function_index;
227 uint32_t inner_index) {
229 if (!inner)
return {};
230 return Get(*inner, inner_index);
234 uint32_t local_index,
242 MaybeAddComment(out, local_index, index_as_comment);
244 out <<
"$var" << local_index;
249 uint32_t label_index,
250 uint32_t fallback_index) {
258 out <<
"$label" << fallback_index;
269 return MaybeAddComment(out, type_index, index_as_comment);
271 out <<
"$type" << type_index;
281 return MaybeAddComment(out, table_index, index_as_comment);
287 return MaybeAddComment(out, table_index, index_as_comment);
289 out <<
"$table" << table_index;
299 return MaybeAddComment(out, memory_index, index_as_comment);
305 return MaybeAddComment(out, memory_index, index_as_comment);
308 out <<
"$memory" << memory_index;
318 return MaybeAddComment(out, global_index, index_as_comment);
324 return MaybeAddComment(out, global_index, index_as_comment);
327 out <<
"$global" << global_index;
331 uint32_t element_segment_index,
339 MaybeAddComment(out, element_segment_index, index_as_comment);
341 out <<
"$elem" << element_segment_index;
346 uint32_t data_segment_index,
354 MaybeAddComment(out, data_segment_index, index_as_comment);
356 out <<
"$data" << data_segment_index;
361 uint32_t field_index,
369 return MaybeAddComment(out, field_index, index_as_comment);
371 out <<
"$field" << field_index;
381 return MaybeAddComment(out,
tag_index, index_as_comment);
386 return MaybeAddComment(out,
tag_index, index_as_comment);
392 if (type.is_index()) {
393 if (type.is_exact()) out <<
"exact ";
401 if (type.has_index()) {
402 out << (type.is_nullable() ?
"(ref null " :
"(ref ");
403 if (type.is_exact()) out <<
"exact ";
412size_t StringMapSize(
const std::map<uint32_t, std::string>& map) {
414 for (
const auto& entry : map) {
415 result += entry.second.size();
427 result += names->label_names_.EstimateCurrentMemoryConsumption();
428 result += names->type_names_.EstimateCurrentMemoryConsumption();
429 result += names->table_names_.EstimateCurrentMemoryConsumption();
430 result += names->memory_names_.EstimateCurrentMemoryConsumption();
431 result += names->global_names_.EstimateCurrentMemoryConsumption();
432 result += names->element_segment_names_.EstimateCurrentMemoryConsumption();
433 result += names->data_segment_names_.EstimateCurrentMemoryConsumption();
434 result += names->field_names_.EstimateCurrentMemoryConsumption();
435 result += names->tag_names_.EstimateCurrentMemoryConsumption();
445 if (
v8_flags.trace_wasm_offheap_memory) {
456 const std::vector<StringT>& vec = entry.second;
459 if (
v8_flags.trace_wasm_offheap_memory) {
475 module->canonical_typenames_decoded = true;
478 if (name_section.
is_empty())
return;
479 size_t added_size = 0;
488 uint32_t index = type_index.
index;
495 out <<
"$canon" <<
index;
500 out.write(name.data(), name.size());
501 MaybeAddComment(out, index, index_as_comment);
506 switch (type.kind()) {
509 if (type.encoding_needs_heap_type()) {
510 out << (type.kind() ==
kRef ?
"(ref " :
"(ref null ");
511 if (type.is_exact()) out <<
"exact ";
512 if (type.has_index()) {
529 uint32_t field_index) {
530 uint32_t index = struct_index.
index;
535 std::vector<StringT>& field_names = per_type->second;
536 if (field_index < field_names.size() && !field_names[field_index].empty()) {
537 const StringT& name = field_names[field_index];
539 out.write(name.data(), name.size());
543 out <<
"$field" << field_index;
550 for (
size_t i = 0;
i < 32;
i++) {
551 std::string
s(
i,
'c');
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
constexpr bool empty() const
constexpr T * begin() const
size_t EstimateCurrentMemoryConsumption() const
const Value * Get(uint32_t key) const
void PrintValueType(StringBuilder &out, CanonicalValueType type)
std::vector< StringT > type_names_
void PrintFieldName(StringBuilder &out, CanonicalTypeIndex struct_index, uint32_t field_index)
base::OwnedVector< char > StringT
void PrintTypeName(StringBuilder &out, CanonicalTypeIndex type_index, NamesProvider::IndexAsComment index_as_comment=NamesProvider::kDontPrintIndex)
std::map< uint32_t, std::vector< StringT > > field_names_
size_t payload_size_estimate_
size_t DetectInlineStringThreshold()
void DecodeNames(NativeModule *native_module)
size_t EstimateCurrentMemoryConsumption() const
void DecodeNameSections()
IndirectNameMap local_names_
std::map< uint32_t, std::string > import_export_function_names_
std::map< uint32_t, std::string > import_export_memory_names_
void ComputeNamesFromImportsExports()
void PrintLabelName(StringBuilder &out, uint32_t function_index, uint32_t label_index, uint32_t fallback_index)
base::Vector< const uint8_t > wire_bytes_
void ComputeFunctionNamesFromImportsExports()
void PrintGlobalName(StringBuilder &out, uint32_t global_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintTagName(StringBuilder &out, uint32_t tag_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintDataSegmentName(StringBuilder &out, uint32_t data_segment_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintLocalName(StringBuilder &out, uint32_t function_index, uint32_t local_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintValueType(StringBuilder &out, ValueType type)
void PrintTypeName(StringBuilder &out, uint32_t type_index, IndexAsComment index_as_comment=kDontPrintIndex)
std::unique_ptr< DecodedNameSection > name_section_names_
void DecodeNamesIfNotYetDone()
void PrintFunctionName(StringBuilder &out, uint32_t function_index, FunctionNamesBehavior behavior=kWasmInternal, IndexAsComment index_as_comment=kDontPrintIndex)
const WasmModule * module_
bool has_computed_import_names_
NamesProvider(const WasmModule *module, base::Vector< const uint8_t > wire_bytes)
void PrintHeapType(StringBuilder &out, HeapType type)
void PrintFieldName(StringBuilder &out, uint32_t struct_index, uint32_t field_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintMemoryName(StringBuilder &out, uint32_t memory_index, IndexAsComment index_as_comment=kDontPrintIndex)
void ComputeExportName(const WasmExport &ex, std::map< uint32_t, std::string > &target)
void PrintElementSegmentName(StringBuilder &out, uint32_t element_segment_index, IndexAsComment index_as_comment=kDontPrintIndex)
void PrintTableName(StringBuilder &out, uint32_t table_index, IndexAsComment index_as_comment=kDontPrintIndex)
void ComputeImportName(const WasmImport &import, std::map< uint32_t, std::string > &target)
std::map< uint32_t, std::string > import_export_table_names_
void WriteRef(StringBuilder &out, WireBytesRef ref)
size_t EstimateCurrentMemoryConsumption() const
std::map< uint32_t, std::string > import_export_global_names_
std::map< uint32_t, std::string > import_export_tag_names_
bool has_computed_function_import_names_
const WasmModule * module() const
base::Vector< const uint8_t > wire_bytes() const
const char * start() const
void DecodeAllNameSections(CanonicalTypeNamesProvider *target)
ZoneVector< RpoNumber > & result
const base::Vector< const uint8_t > wire_bytes_
void DecodeCanonicalTypeNames(base::Vector< const uint8_t > wire_bytes, const WasmModule *module, std::vector< base::OwnedVector< char > > &typenames, std::map< uint32_t, std::vector< base::OwnedVector< char > > > &fieldnames, size_t *total_allocated_size)
TypeCanonicalizer * GetTypeCanonicalizer()
constexpr const char * name(ValueKind kind)
size_t ContentSize(const std::vector< T > &vector)
WireBytesRef Get(const NameMap &map, uint32_t index)
WasmEngine * GetWasmEngine()
void PrintF(const char *format,...)
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK(condition)
#define UPDATE_WHEN_CLASS_CHANGES(classname, size)
ImportExportKindCode kind
std::atomic< bool > canonical_typenames_decoded
const wasm::WasmModule * module_