Commit 667187fc authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[codegen] Factor out safepoint table printing

The logic for printing a safepoint table is currently duplicated for
Wasm code and on-heap code, with slight differences.
This CL provides a central {SafepointTable::Print} method that is used
in both scenarios.
The format is slightly changed to explicitly specify which bitmap
corresponds to stack slots and which one to registers.

R=jkummerow@chromium.org

Bug: v8:12401
Change-Id: I67366b1f9a92450a6ebec4210ab4811800a54f34
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3306976
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78159}
parent 1976cbfb
......@@ -4,6 +4,8 @@
#include "src/codegen/safepoint-table.h"
#include <iomanip>
#include "src/codegen/assembler-inl.h"
#include "src/codegen/macro-assembler.h"
#include "src/deoptimizer/deoptimizer.h"
......@@ -71,11 +73,39 @@ SafepointEntry SafepointTable::FindEntry(Address pc) const {
UNREACHABLE();
}
void SafepointTable::PrintEntry(int index, std::ostream& os) const {
for (uint8_t bits : GetEntry(index).tagged_slots()) {
for (int bit = 0; bit < kBitsPerByte; ++bit) {
os << ((bits >> bit) & 1);
void SafepointTable::Print(std::ostream& os) const {
os << "Safepoints (entries = " << length_ << ", byte size = " << byte_size()
<< ")\n";
for (int index = 0; index < length_; index++) {
SafepointEntry entry = GetEntry(index);
os << reinterpret_cast<const void*>(instruction_start_ + entry.pc()) << " "
<< std::setw(6) << std::hex << entry.pc();
if (!entry.tagged_slots().empty()) {
os << " slots (sp->fp): ";
for (uint8_t bits : entry.tagged_slots()) {
for (int bit = 0; bit < kBitsPerByte; ++bit) {
os << ((bits >> bit) & 1);
}
}
}
if (entry.tagged_register_indexes() != 0) {
os << " registers: ";
uint32_t register_bits = entry.tagged_register_indexes();
int bits = 32 - base::bits::CountLeadingZeros32(register_bits);
for (int j = bits - 1; j >= 0; --j) {
os << ((register_bits >> j) & 1);
}
}
if (entry.has_deoptimization_index()) {
os << " deopt " << std::setw(6) << entry.deoptimization_index()
<< " trampoline: " << std::setw(6) << std::hex
<< entry.trampoline_pc();
}
os << "\n";
}
}
......
......@@ -139,7 +139,7 @@ class SafepointTable {
// Returns the entry for the given pc.
SafepointEntry FindEntry(Address pc) const;
void PrintEntry(int index, std::ostream& os) const;
void Print(std::ostream&) const;
private:
// Layout information.
......
......@@ -585,23 +585,7 @@ void Code::Disassemble(const char* name, std::ostream& os, Isolate* isolate,
if (has_safepoint_info()) {
SafepointTable table(isolate, current_pc, *this);
os << "Safepoints (entries = " << table.length()
<< ", byte size = " << table.byte_size() << ")\n";
for (int i = 0; i < table.length(); i++) {
SafepointEntry entry = table.GetEntry(i);
os << reinterpret_cast<const void*>(InstructionStart() + entry.pc())
<< " " << std::setw(6) << std::hex << entry.pc() << " ";
print_pc(os, entry.trampoline_pc());
os << std::dec << " ";
table.PrintEntry(i, os);
os << " (sp -> fp) ";
if (entry.has_deoptimization_index()) {
os << std::setw(6) << entry.deoptimization_index();
} else {
os << "<none>";
}
os << "\n";
}
table.Print(os);
os << "\n";
}
......
......@@ -436,28 +436,7 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
if (safepoint_table_offset_ > 0) {
SafepointTable table(this);
// TODO(clemensb): Unify with printing in code.cc.
os << "Safepoints (entries = " << table.length()
<< ", byte size = " << table.byte_size() << ")\n";
for (int i = 0; i < table.length(); i++) {
SafepointEntry entry = table.GetEntry(i);
os << reinterpret_cast<const void*>(instruction_start() + entry.pc())
<< " " << std::setw(6) << std::hex << entry.pc() << " ";
table.PrintEntry(i, os);
os << " (sp -> fp)";
if (entry.trampoline_pc() != SafepointEntry::kNoTrampolinePC) {
os << " trampoline: " << std::hex << entry.trampoline_pc() << std::dec;
}
if (entry.tagged_register_indexes() != 0) {
os << " registers: ";
uint32_t register_bits = entry.tagged_register_indexes();
int bits = 32 - base::bits::CountLeadingZeros32(register_bits);
for (int j = bits - 1; j >= 0; --j) {
os << ((register_bits >> j) & 1);
}
}
os << "\n";
}
table.Print(os);
os << "\n";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment