Commit 92e3975d authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

Add primitives-based constructor for SafepointTable

This allows SafepointTables to be reused by the upcoming WasmCode
(wasm out of the GC heap), and integrate with the stack iterator.

Bug: v8:6876
Change-Id: I24ff78a073fa99aeabe12a0c5a12709f5b1461a2
Reviewed-on: https://chromium-review.googlesource.com/764370Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49307}
parent 85e25df6
......@@ -34,11 +34,13 @@ bool SafepointEntry::HasRegisterAt(int reg_index) const {
return (bits_[byte_index] & (1 << bit_index)) != 0;
}
SafepointTable::SafepointTable(Code* code) {
DCHECK(code->is_turbofanned());
code_ = code;
Address header = code->instruction_start() + code->safepoint_table_offset();
SafepointTable::SafepointTable(Address instruction_start,
size_t safepoint_table_offset,
uint32_t stack_slots, bool has_deopt)
: instruction_start_(instruction_start),
stack_slots_(stack_slots),
has_deopt_(has_deopt) {
Address header = instruction_start_ + safepoint_table_offset;
length_ = Memory::uint32_at(header + kLengthOffset);
entry_size_ = Memory::uint32_at(header + kEntrySizeOffset);
pc_and_deoptimization_indexes_ = header + kHeaderSize;
......@@ -48,6 +50,12 @@ SafepointTable::SafepointTable(Code* code) {
Safepoint::kNoDeoptimizationIndex);
}
SafepointTable::SafepointTable(Code* code)
: SafepointTable(code->instruction_start(), code->safepoint_table_offset(),
code->stack_slots(), true) {
DCHECK(code->is_turbofanned());
}
unsigned SafepointTable::find_return_pc(unsigned pc_offset) {
for (unsigned i = 0; i < length(); i++) {
if (GetTrampolinePcOffset(i) == static_cast<int>(pc_offset)) {
......@@ -61,7 +69,7 @@ unsigned SafepointTable::find_return_pc(unsigned pc_offset) {
}
SafepointEntry SafepointTable::FindEntry(Address pc) const {
unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start());
unsigned pc_offset = static_cast<unsigned>(pc - instruction_start_);
// We use kMaxUInt32 as sentinel value, so check that we don't hit that.
DCHECK_NE(kMaxUInt32, pc_offset);
unsigned len = length();
......@@ -70,7 +78,8 @@ SafepointEntry SafepointTable::FindEntry(Address pc) const {
for (unsigned i = 0; i < len; i++) {
// TODO(kasperl): Replace the linear search with binary search.
if (GetPcOffset(i) == pc_offset ||
GetTrampolinePcOffset(i) == static_cast<int>(pc_offset)) {
(has_deopt_ &&
GetTrampolinePcOffset(i) == static_cast<int>(pc_offset))) {
return GetEntry(i);
}
}
......@@ -91,7 +100,7 @@ void SafepointTable::PrintEntry(unsigned index,
const int first = kNumSafepointRegisters >> kBitsPerByteLog2;
int last = entry_size_ - 1;
for (int i = first; i < last; i++) PrintBits(os, bits[i], kBitsPerByte);
int last_bits = code_->stack_slots() - ((last - first) * kBitsPerByte);
int last_bits = stack_slots_ - ((last - first) * kBitsPerByte);
PrintBits(os, bits[last], last_bits);
// Print the registers (if any).
......
......@@ -90,6 +90,9 @@ class SafepointEntry BASE_EMBEDDED {
class SafepointTable BASE_EMBEDDED {
public:
explicit SafepointTable(Code* code);
explicit SafepointTable(Address instruction_start,
size_t safepoint_table_offset, uint32_t stack_slots,
bool has_deopt = false);
int size() const {
return kHeaderSize + (length_ * (kFixedEntrySize + entry_size_));
......@@ -113,7 +116,8 @@ class SafepointTable BASE_EMBEDDED {
DCHECK(index < length_);
unsigned info = Memory::uint32_at(GetInfoLocation(index));
uint8_t* bits = &Memory::uint8_at(entries_ + (index * entry_size_));
int trampoline_pc = Memory::int_at(GetTrampolineLocation(index));
int trampoline_pc =
has_deopt_ ? Memory::int_at(GetTrampolineLocation(index)) : -1;
return SafepointEntry(info, bits, trampoline_pc);
}
......@@ -151,12 +155,14 @@ class SafepointTable BASE_EMBEDDED {
uint8_t byte, int digits);
DisallowHeapAllocation no_allocation_;
Code* code_;
Address instruction_start_;
uint32_t stack_slots_;
unsigned length_;
unsigned entry_size_;
Address pc_and_deoptimization_indexes_;
Address entries_;
bool has_deopt_;
friend class SafepointTableBuilder;
friend class SafepointEntry;
......
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