Line data Source code
1 : // Copyright 2016 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/heap/factory.h"
6 : #include "src/isolate.h"
7 : #include "src/objects-inl.h"
8 : #include "test/cctest/cctest.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 :
13 26644 : TEST(CodeLayoutWithoutUnwindingInfo) {
14 5 : CcTest::InitializeVM();
15 : HandleScope handle_scope(CcTest::i_isolate());
16 :
17 : // "Hello, World!" in ASCII.
18 : byte buffer_array[13] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20,
19 5 : 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21};
20 :
21 : byte* buffer = &buffer_array[0];
22 : int buffer_size = sizeof(buffer_array);
23 :
24 5 : CodeDesc code_desc;
25 5 : code_desc.buffer = buffer;
26 5 : code_desc.buffer_size = buffer_size;
27 5 : code_desc.instr_size = buffer_size;
28 5 : code_desc.safepoint_table_offset = buffer_size;
29 : code_desc.safepoint_table_size = 0;
30 5 : code_desc.handler_table_offset = buffer_size;
31 : code_desc.handler_table_size = 0;
32 5 : code_desc.constant_pool_offset = buffer_size;
33 : code_desc.constant_pool_size = 0;
34 5 : code_desc.code_comments_offset = buffer_size;
35 : code_desc.code_comments_size = 0;
36 5 : code_desc.reloc_offset = buffer_size;
37 : code_desc.reloc_size = 0;
38 : code_desc.unwinding_info = nullptr;
39 : code_desc.unwinding_info_size = 0;
40 : code_desc.origin = nullptr;
41 :
42 : Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
43 10 : code_desc, Code::STUB, Handle<Object>::null());
44 :
45 5 : CHECK(!code->has_unwinding_info());
46 5 : CHECK_EQ(code->raw_instruction_size(), buffer_size);
47 5 : CHECK_EQ(0, memcmp(reinterpret_cast<void*>(code->raw_instruction_start()),
48 : buffer, buffer_size));
49 10 : CHECK_EQ(code->raw_instruction_end() - code->address(),
50 : Code::kHeaderSize + buffer_size);
51 5 : }
52 :
53 26644 : TEST(CodeLayoutWithUnwindingInfo) {
54 5 : CcTest::InitializeVM();
55 : HandleScope handle_scope(CcTest::i_isolate());
56 :
57 : // "Hello, World!" in ASCII.
58 : byte buffer_array[13] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20,
59 5 : 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21};
60 :
61 : // "JavaScript" in ASCII.
62 : byte unwinding_info_array[10] = {0x4A, 0x61, 0x76, 0x61, 0x53,
63 5 : 0x63, 0x72, 0x69, 0x70, 0x74};
64 :
65 : byte* buffer = &buffer_array[0];
66 : int buffer_size = sizeof(buffer_array);
67 : byte* unwinding_info = &unwinding_info_array[0];
68 : int unwinding_info_size = sizeof(unwinding_info_array);
69 :
70 5 : CodeDesc code_desc;
71 5 : code_desc.buffer = buffer;
72 5 : code_desc.buffer_size = buffer_size;
73 5 : code_desc.instr_size = buffer_size;
74 5 : code_desc.safepoint_table_offset = buffer_size;
75 : code_desc.safepoint_table_size = 0;
76 5 : code_desc.handler_table_offset = buffer_size;
77 : code_desc.handler_table_size = 0;
78 5 : code_desc.constant_pool_offset = buffer_size;
79 : code_desc.constant_pool_size = 0;
80 5 : code_desc.code_comments_offset = buffer_size;
81 : code_desc.code_comments_size = 0;
82 5 : code_desc.reloc_offset = buffer_size;
83 : code_desc.reloc_size = 0;
84 5 : code_desc.unwinding_info = unwinding_info;
85 5 : code_desc.unwinding_info_size = unwinding_info_size;
86 : code_desc.origin = nullptr;
87 :
88 : Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
89 10 : code_desc, Code::STUB, Handle<Object>::null());
90 :
91 5 : CHECK(code->has_unwinding_info());
92 5 : CHECK_EQ(code->raw_instruction_size(), buffer_size);
93 5 : CHECK_EQ(0, memcmp(reinterpret_cast<void*>(code->raw_instruction_start()),
94 : buffer, buffer_size));
95 : CHECK(IsAligned(code->GetUnwindingInfoSizeOffset(), 8));
96 5 : CHECK_EQ(code->unwinding_info_size(), unwinding_info_size);
97 5 : CHECK(IsAligned(code->unwinding_info_start(), 8));
98 5 : CHECK_EQ(memcmp(reinterpret_cast<void*>(code->unwinding_info_start()),
99 : unwinding_info, unwinding_info_size),
100 : 0);
101 10 : CHECK_EQ(code->unwinding_info_end() - code->address(),
102 : Code::kHeaderSize + RoundUp(buffer_size, kInt64Size) + kInt64Size +
103 : unwinding_info_size);
104 5 : }
105 :
106 : } // namespace internal
107 79917 : } // namespace v8
|