1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_CODEGEN_CODE_DESC_H_ 6 #define V8_CODEGEN_CODE_DESC_H_ 7 8 #include "src/common/globals.h" 9 10 namespace v8 { 11 namespace internal { 12 13 // A CodeDesc describes a buffer holding instructions and relocation 14 // information. The instructions start at the beginning of the buffer 15 // and grow forward, the relocation information starts at the end of 16 // the buffer and grows backward. Inlined metadata sections may exist 17 // at the end of the instructions. 18 // 19 // |<--------------- buffer_size ----------------------------------->| 20 // |<---------------- instr_size ------------->| |<-reloc_size->| 21 // |--------------+----------------------------+------+--------------| 22 // | instructions | data | free | reloc info | 23 // +--------------+----------------------------+------+--------------+ 24 25 // TODO(jgruber): Add a single chokepoint for specifying the instruction area 26 // layout (i.e. the order of inlined metadata fields). 27 // TODO(jgruber): Systematically maintain inlined metadata offsets and sizes 28 // to simplify CodeDesc initialization. 29 30 class CodeDesc { 31 public: 32 static void Initialize(CodeDesc* desc, Assembler* assembler, 33 int safepoint_table_offset, int handler_table_offset, 34 int constant_pool_offset, int code_comments_offset, 35 int reloc_info_offset); 36 37 #ifdef DEBUG 38 static void Verify(const CodeDesc* desc); 39 #else Verify(const CodeDesc * desc)40 inline static void Verify(const CodeDesc* desc) {} 41 #endif 42 43 public: 44 byte* buffer = nullptr; 45 int buffer_size = 0; 46 47 // The instruction area contains executable code plus inlined metadata. 48 49 int instr_size = 0; 50 51 // Metadata packed into the instructions area. 52 53 int safepoint_table_offset = 0; 54 int safepoint_table_size = 0; 55 56 int handler_table_offset = 0; 57 int handler_table_size = 0; 58 59 int constant_pool_offset = 0; 60 int constant_pool_size = 0; 61 62 int code_comments_offset = 0; 63 int code_comments_size = 0; 64 65 // TODO(jgruber,v8:11036): Remove these functions once CodeDesc fields have 66 // been made consistent with Code layout. body_size()67 int body_size() const { return instr_size + unwinding_info_size; } instruction_size()68 int instruction_size() const { return safepoint_table_offset; } metadata_size()69 int metadata_size() const { return body_size() - instruction_size(); } safepoint_table_offset_relative()70 int safepoint_table_offset_relative() const { 71 return safepoint_table_offset - instruction_size(); 72 } handler_table_offset_relative()73 int handler_table_offset_relative() const { 74 return handler_table_offset - instruction_size(); 75 } constant_pool_offset_relative()76 int constant_pool_offset_relative() const { 77 return constant_pool_offset - instruction_size(); 78 } code_comments_offset_relative()79 int code_comments_offset_relative() const { 80 return code_comments_offset - instruction_size(); 81 } 82 83 // Relocation info is located at the end of the buffer and not part of the 84 // instructions area. 85 86 int reloc_offset = 0; 87 int reloc_size = 0; 88 89 // Unwinding information. 90 91 byte* unwinding_info = nullptr; 92 int unwinding_info_size = 0; unwinding_info_offset_relative()93 int unwinding_info_offset_relative() const { 94 // TODO(jgruber,v8:11036): Remove this function once unwinding_info setup 95 // is more consistent with other metadata tables. 96 return code_comments_offset_relative() + code_comments_size; 97 } 98 99 Assembler* origin = nullptr; 100 }; 101 102 } // namespace internal 103 } // namespace v8 104 105 #endif // V8_CODEGEN_CODE_DESC_H_ 106