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 28342 : 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 : code_desc.constant_pool_size = 0;
28 5 : code_desc.instr_size = buffer_size;
29 : code_desc.reloc_size = 0;
30 : code_desc.origin = nullptr;
31 : code_desc.unwinding_info = nullptr;
32 : code_desc.unwinding_info_size = 0;
33 : code_desc.code_comments_size = 0;
34 :
35 : Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
36 10 : code_desc, Code::STUB, Handle<Object>::null());
37 :
38 5 : CHECK(!code->has_unwinding_info());
39 5 : CHECK_EQ(code->raw_instruction_size(), buffer_size);
40 5 : CHECK_EQ(0, memcmp(reinterpret_cast<void*>(code->raw_instruction_start()),
41 : buffer, buffer_size));
42 10 : CHECK_EQ(code->raw_instruction_end() - code->address(),
43 : Code::kHeaderSize + buffer_size);
44 5 : }
45 :
46 28342 : TEST(CodeLayoutWithUnwindingInfo) {
47 5 : CcTest::InitializeVM();
48 : HandleScope handle_scope(CcTest::i_isolate());
49 :
50 : // "Hello, World!" in ASCII.
51 : byte buffer_array[13] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20,
52 5 : 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21};
53 :
54 : // "JavaScript" in ASCII.
55 : byte unwinding_info_array[10] = {0x4A, 0x61, 0x76, 0x61, 0x53,
56 5 : 0x63, 0x72, 0x69, 0x70, 0x74};
57 :
58 : byte* buffer = &buffer_array[0];
59 : int buffer_size = sizeof(buffer_array);
60 : byte* unwinding_info = &unwinding_info_array[0];
61 : int unwinding_info_size = sizeof(unwinding_info_array);
62 :
63 5 : CodeDesc code_desc;
64 5 : code_desc.buffer = buffer;
65 5 : code_desc.buffer_size = buffer_size;
66 : code_desc.constant_pool_size = 0;
67 5 : code_desc.instr_size = buffer_size;
68 : code_desc.reloc_size = 0;
69 : code_desc.origin = nullptr;
70 5 : code_desc.unwinding_info = unwinding_info;
71 5 : code_desc.unwinding_info_size = unwinding_info_size;
72 : code_desc.code_comments_size = 0;
73 :
74 : Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
75 10 : code_desc, Code::STUB, Handle<Object>::null());
76 :
77 5 : CHECK(code->has_unwinding_info());
78 5 : CHECK_EQ(code->raw_instruction_size(), buffer_size);
79 5 : CHECK_EQ(0, memcmp(reinterpret_cast<void*>(code->raw_instruction_start()),
80 : buffer, buffer_size));
81 : CHECK(IsAligned(code->GetUnwindingInfoSizeOffset(), 8));
82 5 : CHECK_EQ(code->unwinding_info_size(), unwinding_info_size);
83 5 : CHECK(IsAligned(code->unwinding_info_start(), 8));
84 5 : CHECK_EQ(memcmp(reinterpret_cast<void*>(code->unwinding_info_start()),
85 : unwinding_info, unwinding_info_size),
86 : 0);
87 10 : CHECK_EQ(code->unwinding_info_end() - code->address(),
88 : Code::kHeaderSize + RoundUp(buffer_size, kInt64Size) + kInt64Size +
89 : unwinding_info_size);
90 5 : }
91 :
92 : } // namespace internal
93 85011 : } // namespace v8
|