Commit 61e46799 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[code] Fix constant pool offset

If FLAG_enable_embedded_constant_pool is false, the field for the
builtin index would alias the field for the constant pool offset in the
code object. This makes constant_pool() return the builtin index, but it
also makes set_constant_pool() override the builtin index (and vice
versa).
This CL fixes this by making all constant_pool accessors honor that
flag.

R=mstarzinger@chromium.org

Change-Id: I88803a4f28bd5a2fe85a310708c7a365cc457339
Reviewed-on: https://chromium-review.googlesource.com/970586Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52076}
parent f52d0053
......@@ -959,6 +959,7 @@ void CodeDataContainer::CodeDataContainerVerify() {
}
void Code::CodeVerify() {
CHECK_LE(constant_pool_offset(), instruction_size());
CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
kCodeAlignment));
relocation_info()->ObjectVerify();
......
......@@ -14504,9 +14504,7 @@ void Code::Disassemble(const char* name, std::ostream& os, void* current_pc) {
int size = instruction_size();
int safepoint_offset =
has_safepoint_info() ? safepoint_table_offset() : size;
int constant_pool_offset = FLAG_enable_embedded_constant_pool
? this->constant_pool_offset()
: size;
int constant_pool_offset = this->constant_pool_offset();
// Stop before reaching any embedded tables
int code_size = Min(safepoint_offset, constant_pool_offset);
......
......@@ -175,7 +175,6 @@ void DependentCode::copy(int from, int to) {
INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset)
INT_ACCESSORS(Code, handler_table_offset, kHandlerTableOffsetOffset)
INT_ACCESSORS(Code, constant_pool_offset, kConstantPoolOffset)
#define CODE_ACCESSORS(name, type, offset) \
ACCESSORS_CHECKED2(Code, name, type, offset, true, \
!GetHeap()->InNewSpace(value))
......@@ -503,15 +502,24 @@ bool Code::is_stub() const { return kind() == STUB; }
bool Code::is_optimized_code() const { return kind() == OPTIMIZED_FUNCTION; }
bool Code::is_wasm_code() const { return kind() == WASM_FUNCTION; }
int Code::constant_pool_offset() const {
if (!FLAG_enable_embedded_constant_pool) return instruction_size();
return READ_INT_FIELD(this, kConstantPoolOffset);
}
void Code::set_constant_pool_offset(int value) {
if (!FLAG_enable_embedded_constant_pool) return;
WRITE_INT_FIELD(this, kConstantPoolOffset, value);
}
Address Code::constant_pool() {
Address constant_pool = nullptr;
if (FLAG_enable_embedded_constant_pool) {
int offset = constant_pool_offset();
if (offset < instruction_size()) {
constant_pool = FIELD_ADDR(this, kHeaderSize + offset);
return FIELD_ADDR(this, kHeaderSize + offset);
}
}
return constant_pool;
return nullptr;
}
Code* Code::GetCodeFromTargetAddress(Address address) {
......
......@@ -203,8 +203,14 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate,
#ifdef ENABLE_DISASSEMBLER
size_t instruction_size =
std::min(constant_pool_offset_, safepoint_table_offset_);
size_t instruction_size = body_size;
if (constant_pool_offset_ && constant_pool_offset_ < instruction_size) {
instruction_size = constant_pool_offset_;
}
if (safepoint_table_offset_ && safepoint_table_offset_ < instruction_size) {
instruction_size = safepoint_table_offset_;
}
DCHECK_LT(0, instruction_size);
os << "Instructions (size = " << instruction_size << ")\n";
// TODO(mtrofin): rework the dependency on isolate and code in
// Disassembler::Decode.
......
......@@ -164,7 +164,11 @@ class V8_EXPORT_PRIVATE WasmCode final {
safepoint_table_offset_(safepoint_table_offset),
handler_table_offset_(handler_table_offset),
protected_instructions_(std::move(protected_instructions)),
tier_(tier) {}
tier_(tier) {
DCHECK_LE(safepoint_table_offset, instructions.size());
DCHECK_LE(constant_pool_offset, instructions.size());
DCHECK_LE(handler_table_offset, instructions.size());
}
WasmCode(const WasmCode&) = delete;
WasmCode& operator=(const WasmCode&) = delete;
......
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