• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/codegen/code-desc.h"
6 
7 #include "src/codegen/assembler-inl.h"
8 
9 namespace v8 {
10 namespace internal {
11 
12 // static
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)13 void CodeDesc::Initialize(CodeDesc* desc, Assembler* assembler,
14                           int safepoint_table_offset, int handler_table_offset,
15                           int constant_pool_offset, int code_comments_offset,
16                           int reloc_info_offset) {
17   desc->buffer = assembler->buffer_start();
18   desc->buffer_size = assembler->buffer_size();
19   desc->instr_size = assembler->instruction_size();
20 
21   desc->code_comments_offset = code_comments_offset;
22   desc->code_comments_size = desc->instr_size - code_comments_offset;
23 
24   desc->constant_pool_offset = constant_pool_offset;
25   desc->constant_pool_size = desc->code_comments_offset - constant_pool_offset;
26 
27   desc->handler_table_offset = handler_table_offset;
28   desc->handler_table_size = desc->constant_pool_offset - handler_table_offset;
29 
30   desc->safepoint_table_offset = safepoint_table_offset;
31   desc->safepoint_table_size =
32       desc->handler_table_offset - safepoint_table_offset;
33 
34   desc->reloc_offset = reloc_info_offset;
35   desc->reloc_size = desc->buffer_size - reloc_info_offset;
36 
37   desc->unwinding_info_size = 0;
38   desc->unwinding_info = nullptr;
39 
40   desc->origin = assembler;
41 
42   CodeDesc::Verify(desc);
43 }
44 
45 #ifdef DEBUG
46 // static
Verify(const CodeDesc * desc)47 void CodeDesc::Verify(const CodeDesc* desc) {
48   // Zero-size code objects upset the system.
49   DCHECK_GT(desc->instr_size, 0);
50   DCHECK_NOT_NULL(desc->buffer);
51 
52   // Instruction area layout invariants.
53   DCHECK_GE(desc->safepoint_table_size, 0);
54   DCHECK_EQ(desc->safepoint_table_size + desc->safepoint_table_offset,
55             desc->handler_table_offset);
56   DCHECK_GE(desc->handler_table_size, 0);
57   DCHECK_EQ(desc->handler_table_size + desc->handler_table_offset,
58             desc->constant_pool_offset);
59   DCHECK_GE(desc->constant_pool_size, 0);
60   DCHECK_EQ(desc->constant_pool_size + desc->constant_pool_offset,
61             desc->code_comments_offset);
62   DCHECK_GE(desc->code_comments_size, 0);
63   DCHECK_EQ(desc->code_comments_size + desc->code_comments_offset,
64             desc->instr_size);
65 
66   DCHECK_GE(desc->reloc_offset, 0);
67   DCHECK_GE(desc->reloc_size, 0);
68   DCHECK_GE(desc->unwinding_info_size, 0);
69 }
70 #endif
71 
72 }  // namespace internal
73 }  // namespace v8
74