Commit 10e46019 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Move CodeDesc to dedicated file

Bug: v8:8758
Change-Id: Ifd0c66f27ab5fb33032b243d3a33c0b797b9af17
Reviewed-on: https://chromium-review.googlesource.com/c/1442644
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59205}
parent ea526196
......@@ -1621,6 +1621,8 @@ v8_source_set("v8_base") {
"src/checks.h",
"src/code-comments.cc",
"src/code-comments.h",
"src/code-desc.cc",
"src/code-desc.h",
"src/code-events.h",
"src/code-factory.cc",
"src/code-factory.h",
......
......@@ -297,66 +297,5 @@ int Assembler::WriteCodeComments() {
return size;
}
// TODO(jgruber): Move to dedicated codedesc.cc file.
// static
void CodeDesc::Initialize(CodeDesc* desc, Assembler* assembler,
int safepoint_table_offset, int handler_table_offset,
int constant_pool_offset, int code_comments_offset,
int reloc_info_offset) {
desc->buffer = assembler->buffer_start();
desc->buffer_size = assembler->buffer_size();
desc->instr_size = assembler->instruction_size();
desc->code_comments_offset = code_comments_offset;
desc->code_comments_size = desc->instr_size - code_comments_offset;
desc->constant_pool_offset = constant_pool_offset;
desc->constant_pool_size = desc->code_comments_offset - constant_pool_offset;
desc->handler_table_offset = handler_table_offset;
desc->handler_table_size = desc->constant_pool_offset - handler_table_offset;
desc->safepoint_table_offset = safepoint_table_offset;
desc->safepoint_table_size =
desc->handler_table_offset - safepoint_table_offset;
desc->reloc_offset = reloc_info_offset;
desc->reloc_size = desc->buffer_size - reloc_info_offset;
desc->unwinding_info_size = 0;
desc->unwinding_info = nullptr;
desc->origin = assembler;
CodeDesc::Verify(desc);
}
#ifdef DEBUG
// TODO(jgruber): Move to dedicated codedesc.cc file.
// static
void CodeDesc::Verify(const CodeDesc* desc) {
// Zero-size code objects upset the system.
DCHECK_GT(desc->instr_size, 0);
DCHECK_NOT_NULL(desc->buffer);
// Instruction area layout invariants.
DCHECK_GE(desc->safepoint_table_size, 0);
DCHECK_EQ(desc->safepoint_table_size + desc->safepoint_table_offset,
desc->handler_table_offset);
DCHECK_GE(desc->handler_table_size, 0);
DCHECK_EQ(desc->handler_table_size + desc->handler_table_offset,
desc->constant_pool_offset);
DCHECK_GE(desc->constant_pool_size, 0);
DCHECK_EQ(desc->constant_pool_size + desc->constant_pool_offset,
desc->code_comments_offset);
DCHECK_GE(desc->code_comments_size, 0);
DCHECK_EQ(desc->code_comments_size + desc->code_comments_offset,
desc->instr_size);
DCHECK_GE(desc->reloc_offset, 0);
DCHECK_GE(desc->reloc_size, 0);
DCHECK_GE(desc->unwinding_info_size, 0);
}
#endif
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/code-desc.h"
#include "src/assembler-inl.h"
namespace v8 {
namespace internal {
// static
void CodeDesc::Initialize(CodeDesc* desc, Assembler* assembler,
int safepoint_table_offset, int handler_table_offset,
int constant_pool_offset, int code_comments_offset,
int reloc_info_offset) {
desc->buffer = assembler->buffer_start();
desc->buffer_size = assembler->buffer_size();
desc->instr_size = assembler->instruction_size();
desc->code_comments_offset = code_comments_offset;
desc->code_comments_size = desc->instr_size - code_comments_offset;
desc->constant_pool_offset = constant_pool_offset;
desc->constant_pool_size = desc->code_comments_offset - constant_pool_offset;
desc->handler_table_offset = handler_table_offset;
desc->handler_table_size = desc->constant_pool_offset - handler_table_offset;
desc->safepoint_table_offset = safepoint_table_offset;
desc->safepoint_table_size =
desc->handler_table_offset - safepoint_table_offset;
desc->reloc_offset = reloc_info_offset;
desc->reloc_size = desc->buffer_size - reloc_info_offset;
desc->unwinding_info_size = 0;
desc->unwinding_info = nullptr;
desc->origin = assembler;
CodeDesc::Verify(desc);
}
#ifdef DEBUG
// static
void CodeDesc::Verify(const CodeDesc* desc) {
// Zero-size code objects upset the system.
DCHECK_GT(desc->instr_size, 0);
DCHECK_NOT_NULL(desc->buffer);
// Instruction area layout invariants.
DCHECK_GE(desc->safepoint_table_size, 0);
DCHECK_EQ(desc->safepoint_table_size + desc->safepoint_table_offset,
desc->handler_table_offset);
DCHECK_GE(desc->handler_table_size, 0);
DCHECK_EQ(desc->handler_table_size + desc->handler_table_offset,
desc->constant_pool_offset);
DCHECK_GE(desc->constant_pool_size, 0);
DCHECK_EQ(desc->constant_pool_size + desc->constant_pool_offset,
desc->code_comments_offset);
DCHECK_GE(desc->code_comments_size, 0);
DCHECK_EQ(desc->code_comments_size + desc->code_comments_offset,
desc->instr_size);
DCHECK_GE(desc->reloc_offset, 0);
DCHECK_GE(desc->reloc_size, 0);
DCHECK_GE(desc->unwinding_info_size, 0);
}
#endif
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CODE_DESC_H_
#define V8_CODE_DESC_H_
#include "src/globals.h"
namespace v8 {
namespace internal {
// A CodeDesc describes a buffer holding instructions and relocation
// information. The instructions start at the beginning of the buffer
// and grow forward, the relocation information starts at the end of
// the buffer and grows backward. Inlined metadata sections may exist
// at the end of the instructions.
//
// │<--------------- buffer_size ----------------------------------->│
// │<---------------- instr_size ------------->│ │<-reloc_size->│
// ├───────────────────────────────────────────┼──────┼──────────────┤
// │ instructions │ data │ free │ reloc info │
// ├───────────────────────────────────────────┴──────┴──────────────┘
// TODO(jgruber): Remove safepoint and handler table offset parameters passed
// around for Code creation methods and rely on CodeDesc exclusively.
// TODO(jgruber): Likewise for WasmCompilationResult.
// TODO(jgruber): Change Code::safepoint_table_offset() semantics to always
// contain a real offset, and add has_safepoint_table() and
// safepoint_table_size() helpers. Likewise for other inlined metadata.
// TODO(jgruber): Update documentation about inlined metadata in code.h.
// TODO(jgruber): Add a single chokepoint for specifying the instruction area
// layout (i.e. the order of inlined metadata fields).
// TODO(jgruber): Systematically maintain inlined metadata offsets and sizes
// to simplify CodeDesc initialization.
class CodeDesc {
public:
static void Initialize(CodeDesc* desc, Assembler* assembler,
int safepoint_table_offset, int handler_table_offset,
int constant_pool_offset, int code_comments_offset,
int reloc_info_offset);
#ifdef DEBUG
static void Verify(const CodeDesc* desc);
#else
inline static void Verify(const CodeDesc* desc) {}
#endif
public:
byte* buffer = nullptr;
int buffer_size = 0;
// The instruction area contains executable code plus inlined metadata.
int instr_size = 0;
// Metadata packed into the instructions area.
int safepoint_table_offset = 0;
int safepoint_table_size = 0;
int handler_table_offset = 0;
int handler_table_size = 0;
int constant_pool_offset = 0;
int constant_pool_size = 0;
int code_comments_offset = 0;
int code_comments_size = 0;
// Relocation info is located at the end of the buffer and not part of the
// instructions area.
int reloc_offset = 0;
int reloc_size = 0;
// Unwinding information.
// TODO(jgruber,mstarzinger): Pack this into the inlined metadata section.
byte* unwinding_info = nullptr;
int unwinding_info_size = 0;
Assembler* origin = nullptr;
};
} // namespace internal
} // namespace v8
#endif // V8_CODE_DESC_H_
......@@ -7,6 +7,8 @@
#include <iomanip>
#include <ostream>
#include "src/code-desc.h"
#if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM) && \
!defined(V8_TARGET_ARCH_ARM64)
......
......@@ -14,6 +14,8 @@
namespace v8 {
namespace internal {
class CodeDesc;
class V8_EXPORT_PRIVATE EhFrameConstants final
: public NON_EXPORTED_BASE(AllStatic) {
public:
......
......@@ -765,80 +765,6 @@ enum ParseRestriction {
ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
};
// A CodeDesc describes a buffer holding instructions and relocation
// information. The instructions start at the beginning of the buffer
// and grow forward, the relocation information starts at the end of
// the buffer and grows backward. Inlined metadata sections may exist
// at the end of the instructions.
//
// │<--------------- buffer_size ----------------------------------->│
// │<---------------- instr_size ------------->│ │<-reloc_size->│
// ├───────────────────────────────────────────┼──────┼──────────────┤
// │ instructions │ data │ free │ reloc info │
// ├───────────────────────────────────────────┴──────┴──────────────┘
// TODO(jgruber): Remove safepoint and handler table offset parameters passed
// around for Code creation methods and rely on CodeDesc exclusively.
// TODO(jgruber): Likewise for WasmCompilationResult.
// TODO(jgruber): Change Code::safepoint_table_offset() semantics to always
// contain a real offset, and add has_safepoint_table() and
// safepoint_table_size() helpers. Likewise for other inlined metadata.
// TODO(jgruber): Update documentation about inlined metadata in code.h.
// TODO(jgruber): Add a single chokepoint for specifying the instruction area
// layout (i.e. the order of inlined metadata fields).
// TODO(jgruber): Systematically maintain inlined metadata offsets and sizes
// to simplify CodeDesc initialization.
class CodeDesc {
public:
static void Initialize(CodeDesc* desc, Assembler* assembler,
int safepoint_table_offset, int handler_table_offset,
int constant_pool_offset, int code_comments_offset,
int reloc_info_offset);
#ifdef DEBUG
static void Verify(const CodeDesc* desc);
#else
inline static void Verify(const CodeDesc* desc) {}
#endif
public:
byte* buffer = nullptr;
int buffer_size = 0;
// The instruction area contains executable code plus inlined metadata.
int instr_size = 0;
// Metadata packed into the instructions area.
int safepoint_table_offset = 0;
int safepoint_table_size = 0;
int handler_table_offset = 0;
int handler_table_size = 0;
int constant_pool_offset = 0;
int constant_pool_size = 0;
int code_comments_offset = 0;
int code_comments_size = 0;
// Relocation info is located at the end of the buffer and not part of the
// instructions area.
int reloc_offset = 0;
int reloc_size = 0;
// Unwinding information.
// TODO(jgruber,mstarzinger): Pack this into the inlined metadata section.
byte* unwinding_info = nullptr;
int unwinding_info_size = 0;
Assembler* origin = nullptr;
};
// State for inline cache call sites. Aliased as IC::State.
enum InlineCacheState {
// No feedback will be collected.
......
......@@ -7,6 +7,7 @@
#include "src/objects/code.h"
#include "src/code-desc.h"
#include "src/interpreter/bytecode-register.h"
#include "src/isolate.h"
#include "src/objects/dictionary.h"
......
......@@ -21,6 +21,7 @@ namespace internal {
class ByteArray;
class BytecodeArray;
class CodeDataContainer;
class CodeDesc;
class MaybeObject;
namespace interpreter {
......
......@@ -5,6 +5,7 @@
#ifndef V8_WASM_FUNCTION_COMPILER_H_
#define V8_WASM_FUNCTION_COMPILER_H_
#include "src/code-desc.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/compilation-environment.h"
#include "src/wasm/function-body-decoder.h"
......
......@@ -4,6 +4,7 @@
#include "include/v8.h"
#include "src/code-desc.h"
#include "src/handles-inl.h"
#include "src/isolate.h"
#include "test/cctest/cctest.h"
......
......@@ -6,6 +6,7 @@
#define V8_TEST_COMMON_ASSEMBLER_TESTER_H_
#include "src/assembler.h"
#include "src/code-desc.h"
namespace v8 {
namespace internal {
......
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