11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_CODE_DESC_H_ 61cb0ef41Sopenharmony_ci#define V8_CODEGEN_CODE_DESC_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// A CodeDesc describes a buffer holding instructions and relocation 141cb0ef41Sopenharmony_ci// information. The instructions start at the beginning of the buffer 151cb0ef41Sopenharmony_ci// and grow forward, the relocation information starts at the end of 161cb0ef41Sopenharmony_ci// the buffer and grows backward. Inlined metadata sections may exist 171cb0ef41Sopenharmony_ci// at the end of the instructions. 181cb0ef41Sopenharmony_ci// 191cb0ef41Sopenharmony_ci// |<--------------- buffer_size ----------------------------------->| 201cb0ef41Sopenharmony_ci// |<---------------- instr_size ------------->| |<-reloc_size->| 211cb0ef41Sopenharmony_ci// |--------------+----------------------------+------+--------------| 221cb0ef41Sopenharmony_ci// | instructions | data | free | reloc info | 231cb0ef41Sopenharmony_ci// +--------------+----------------------------+------+--------------+ 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci// TODO(jgruber): Add a single chokepoint for specifying the instruction area 261cb0ef41Sopenharmony_ci// layout (i.e. the order of inlined metadata fields). 271cb0ef41Sopenharmony_ci// TODO(jgruber): Systematically maintain inlined metadata offsets and sizes 281cb0ef41Sopenharmony_ci// to simplify CodeDesc initialization. 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciclass CodeDesc { 311cb0ef41Sopenharmony_ci public: 321cb0ef41Sopenharmony_ci static void Initialize(CodeDesc* desc, Assembler* assembler, 331cb0ef41Sopenharmony_ci int safepoint_table_offset, int handler_table_offset, 341cb0ef41Sopenharmony_ci int constant_pool_offset, int code_comments_offset, 351cb0ef41Sopenharmony_ci int reloc_info_offset); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci#ifdef DEBUG 381cb0ef41Sopenharmony_ci static void Verify(const CodeDesc* desc); 391cb0ef41Sopenharmony_ci#else 401cb0ef41Sopenharmony_ci inline static void Verify(const CodeDesc* desc) {} 411cb0ef41Sopenharmony_ci#endif 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci public: 441cb0ef41Sopenharmony_ci byte* buffer = nullptr; 451cb0ef41Sopenharmony_ci int buffer_size = 0; 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci // The instruction area contains executable code plus inlined metadata. 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci int instr_size = 0; 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci // Metadata packed into the instructions area. 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci int safepoint_table_offset = 0; 541cb0ef41Sopenharmony_ci int safepoint_table_size = 0; 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci int handler_table_offset = 0; 571cb0ef41Sopenharmony_ci int handler_table_size = 0; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci int constant_pool_offset = 0; 601cb0ef41Sopenharmony_ci int constant_pool_size = 0; 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci int code_comments_offset = 0; 631cb0ef41Sopenharmony_ci int code_comments_size = 0; 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci // TODO(jgruber,v8:11036): Remove these functions once CodeDesc fields have 661cb0ef41Sopenharmony_ci // been made consistent with Code layout. 671cb0ef41Sopenharmony_ci int body_size() const { return instr_size + unwinding_info_size; } 681cb0ef41Sopenharmony_ci int instruction_size() const { return safepoint_table_offset; } 691cb0ef41Sopenharmony_ci int metadata_size() const { return body_size() - instruction_size(); } 701cb0ef41Sopenharmony_ci int safepoint_table_offset_relative() const { 711cb0ef41Sopenharmony_ci return safepoint_table_offset - instruction_size(); 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci int handler_table_offset_relative() const { 741cb0ef41Sopenharmony_ci return handler_table_offset - instruction_size(); 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci int constant_pool_offset_relative() const { 771cb0ef41Sopenharmony_ci return constant_pool_offset - instruction_size(); 781cb0ef41Sopenharmony_ci } 791cb0ef41Sopenharmony_ci int code_comments_offset_relative() const { 801cb0ef41Sopenharmony_ci return code_comments_offset - instruction_size(); 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci // Relocation info is located at the end of the buffer and not part of the 841cb0ef41Sopenharmony_ci // instructions area. 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci int reloc_offset = 0; 871cb0ef41Sopenharmony_ci int reloc_size = 0; 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci // Unwinding information. 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci byte* unwinding_info = nullptr; 921cb0ef41Sopenharmony_ci int unwinding_info_size = 0; 931cb0ef41Sopenharmony_ci int unwinding_info_offset_relative() const { 941cb0ef41Sopenharmony_ci // TODO(jgruber,v8:11036): Remove this function once unwinding_info setup 951cb0ef41Sopenharmony_ci // is more consistent with other metadata tables. 961cb0ef41Sopenharmony_ci return code_comments_offset_relative() + code_comments_size; 971cb0ef41Sopenharmony_ci } 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ci Assembler* origin = nullptr; 1001cb0ef41Sopenharmony_ci}; 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci} // namespace internal 1031cb0ef41Sopenharmony_ci} // namespace v8 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci#endif // V8_CODEGEN_CODE_DESC_H_ 106