Line data Source code
1 : // Copyright 2015 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 : // Test embedded constant pool builder code.
6 :
7 : #include "src/v8.h"
8 :
9 : #include "src/assembler.h"
10 : #include "test/cctest/cctest.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : const ConstantPoolEntry::Type kPtrType = ConstantPoolEntry::INTPTR;
16 : const ConstantPoolEntry::Type kDblType = ConstantPoolEntry::DOUBLE;
17 : const ConstantPoolEntry::Access kRegAccess = ConstantPoolEntry::REGULAR;
18 : const ConstantPoolEntry::Access kOvflAccess = ConstantPoolEntry::OVERFLOWED;
19 :
20 : const int kReachBits = 6; // Use reach of 64-bytes to test overflow.
21 : const int kReach = 1 << kReachBits;
22 :
23 :
24 23724 : TEST(ConstantPoolPointers) {
25 6 : ConstantPoolBuilder builder(kReachBits, kReachBits);
26 : const int kRegularCount = kReach / kPointerSize;
27 : ConstantPoolEntry::Access access;
28 : int pos = 0;
29 : intptr_t value = 0;
30 : bool sharing_ok = true;
31 :
32 6 : CHECK(builder.IsEmpty());
33 54 : while (builder.NextAccess(kPtrType) == kRegAccess) {
34 48 : access = builder.AddEntry(pos++, value++, sharing_ok);
35 48 : CHECK_EQ(access, kRegAccess);
36 : }
37 6 : CHECK(!builder.IsEmpty());
38 6 : CHECK_EQ(pos, kRegularCount);
39 :
40 : access = builder.AddEntry(pos, value, sharing_ok);
41 6 : CHECK_EQ(access, kOvflAccess);
42 6 : }
43 :
44 :
45 23724 : TEST(ConstantPoolDoubles) {
46 6 : ConstantPoolBuilder builder(kReachBits, kReachBits);
47 : const int kRegularCount = kReach / kDoubleSize;
48 : ConstantPoolEntry::Access access;
49 : int pos = 0;
50 : double value = 0.0;
51 :
52 6 : CHECK(builder.IsEmpty());
53 54 : while (builder.NextAccess(kDblType) == kRegAccess) {
54 48 : access = builder.AddEntry(pos++, value);
55 48 : value += 0.5;
56 48 : CHECK_EQ(access, kRegAccess);
57 : }
58 6 : CHECK(!builder.IsEmpty());
59 6 : CHECK_EQ(pos, kRegularCount);
60 :
61 : access = builder.AddEntry(pos, value);
62 6 : CHECK_EQ(access, kOvflAccess);
63 6 : }
64 :
65 :
66 23724 : TEST(ConstantPoolMixedTypes) {
67 6 : ConstantPoolBuilder builder(kReachBits, kReachBits);
68 : const int kRegularCount = (((kReach / (kDoubleSize + kPointerSize)) * 2) +
69 : ((kPointerSize < kDoubleSize) ? 1 : 0));
70 : ConstantPoolEntry::Type type = kPtrType;
71 : ConstantPoolEntry::Access access;
72 : int pos = 0;
73 : intptr_t ptrValue = 0;
74 : double dblValue = 0.0;
75 : bool sharing_ok = true;
76 :
77 6 : CHECK(builder.IsEmpty());
78 54 : while (builder.NextAccess(type) == kRegAccess) {
79 48 : if (type == kPtrType) {
80 24 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
81 : type = kDblType;
82 : } else {
83 24 : access = builder.AddEntry(pos++, dblValue);
84 24 : dblValue += 0.5;
85 : type = kPtrType;
86 : }
87 48 : CHECK_EQ(access, kRegAccess);
88 : }
89 6 : CHECK(!builder.IsEmpty());
90 6 : CHECK_EQ(pos, kRegularCount);
91 :
92 6 : access = builder.AddEntry(pos++, ptrValue, sharing_ok);
93 6 : CHECK_EQ(access, kOvflAccess);
94 : access = builder.AddEntry(pos, dblValue);
95 6 : CHECK_EQ(access, kOvflAccess);
96 6 : }
97 :
98 :
99 23724 : TEST(ConstantPoolMixedReach) {
100 : const int ptrReachBits = kReachBits + 2;
101 : const int ptrReach = 1 << ptrReachBits;
102 : const int dblReachBits = kReachBits;
103 : const int dblReach = kReach;
104 : const int dblRegularCount =
105 : Min(dblReach / kDoubleSize, ptrReach / (kDoubleSize + kPointerSize));
106 : const int ptrRegularCount =
107 : ((ptrReach - (dblRegularCount * (kDoubleSize + kPointerSize))) /
108 : kPointerSize) +
109 : dblRegularCount;
110 6 : ConstantPoolBuilder builder(ptrReachBits, dblReachBits);
111 : ConstantPoolEntry::Access access;
112 : int pos = 0;
113 : intptr_t ptrValue = 0;
114 : double dblValue = 0.0;
115 : bool sharing_ok = true;
116 : int ptrCount = 0;
117 : int dblCount = 0;
118 :
119 6 : CHECK(builder.IsEmpty());
120 54 : while (builder.NextAccess(kDblType) == kRegAccess) {
121 48 : access = builder.AddEntry(pos++, dblValue);
122 48 : dblValue += 0.5;
123 48 : dblCount++;
124 48 : CHECK_EQ(access, kRegAccess);
125 :
126 48 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
127 48 : ptrCount++;
128 48 : CHECK_EQ(access, kRegAccess);
129 : }
130 6 : CHECK(!builder.IsEmpty());
131 6 : CHECK_EQ(dblCount, dblRegularCount);
132 :
133 102 : while (ptrCount < ptrRegularCount) {
134 96 : access = builder.AddEntry(pos++, dblValue);
135 96 : dblValue += 0.5;
136 96 : CHECK_EQ(access, kOvflAccess);
137 :
138 96 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
139 96 : ptrCount++;
140 96 : CHECK_EQ(access, kRegAccess);
141 : }
142 6 : CHECK_EQ(builder.NextAccess(kPtrType), kOvflAccess);
143 :
144 6 : access = builder.AddEntry(pos++, ptrValue, sharing_ok);
145 6 : CHECK_EQ(access, kOvflAccess);
146 : access = builder.AddEntry(pos, dblValue);
147 6 : CHECK_EQ(access, kOvflAccess);
148 6 : }
149 :
150 :
151 23724 : TEST(ConstantPoolSharing) {
152 6 : ConstantPoolBuilder builder(kReachBits, kReachBits);
153 : const int kRegularCount = (((kReach / (kDoubleSize + kPointerSize)) * 2) +
154 : ((kPointerSize < kDoubleSize) ? 1 : 0));
155 : ConstantPoolEntry::Access access;
156 :
157 6 : CHECK(builder.IsEmpty());
158 :
159 : ConstantPoolEntry::Type type = kPtrType;
160 : int pos = 0;
161 : intptr_t ptrValue = 0;
162 : double dblValue = 0.0;
163 : bool sharing_ok = true;
164 54 : while (builder.NextAccess(type) == kRegAccess) {
165 48 : if (type == kPtrType) {
166 24 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
167 : type = kDblType;
168 : } else {
169 24 : access = builder.AddEntry(pos++, dblValue);
170 24 : dblValue += 0.5;
171 : type = kPtrType;
172 : }
173 48 : CHECK_EQ(access, kRegAccess);
174 : }
175 6 : CHECK(!builder.IsEmpty());
176 6 : CHECK_EQ(pos, kRegularCount);
177 :
178 : type = kPtrType;
179 : ptrValue = 0;
180 : dblValue = 0.0;
181 54 : while (pos < kRegularCount * 2) {
182 48 : if (type == kPtrType) {
183 24 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
184 : type = kDblType;
185 : } else {
186 24 : access = builder.AddEntry(pos++, dblValue);
187 24 : dblValue += 0.5;
188 : type = kPtrType;
189 : }
190 48 : CHECK_EQ(access, kRegAccess);
191 : }
192 :
193 6 : access = builder.AddEntry(pos++, ptrValue, sharing_ok);
194 6 : CHECK_EQ(access, kOvflAccess);
195 : access = builder.AddEntry(pos, dblValue);
196 6 : CHECK_EQ(access, kOvflAccess);
197 6 : }
198 :
199 :
200 23724 : TEST(ConstantPoolNoSharing) {
201 6 : ConstantPoolBuilder builder(kReachBits, kReachBits);
202 : const int kRegularCount = (((kReach / (kDoubleSize + kPointerSize)) * 2) +
203 : ((kPointerSize < kDoubleSize) ? 1 : 0));
204 : ConstantPoolEntry::Access access;
205 :
206 6 : CHECK(builder.IsEmpty());
207 :
208 : ConstantPoolEntry::Type type = kPtrType;
209 : int pos = 0;
210 : intptr_t ptrValue = 0;
211 : double dblValue = 0.0;
212 : bool sharing_ok = false;
213 54 : while (builder.NextAccess(type) == kRegAccess) {
214 48 : if (type == kPtrType) {
215 24 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
216 : type = kDblType;
217 : } else {
218 24 : access = builder.AddEntry(pos++, dblValue);
219 24 : dblValue += 0.5;
220 : type = kPtrType;
221 : }
222 48 : CHECK_EQ(access, kRegAccess);
223 : }
224 6 : CHECK(!builder.IsEmpty());
225 6 : CHECK_EQ(pos, kRegularCount);
226 :
227 : type = kPtrType;
228 : ptrValue = 0;
229 : dblValue = 0.0;
230 : sharing_ok = true;
231 54 : while (pos < kRegularCount * 2) {
232 48 : if (type == kPtrType) {
233 24 : access = builder.AddEntry(pos++, ptrValue++, sharing_ok);
234 : type = kDblType;
235 24 : CHECK_EQ(access, kOvflAccess);
236 : } else {
237 24 : access = builder.AddEntry(pos++, dblValue);
238 24 : dblValue += 0.5;
239 : type = kPtrType;
240 24 : CHECK_EQ(access, kRegAccess);
241 : }
242 : }
243 :
244 6 : access = builder.AddEntry(pos++, ptrValue, sharing_ok);
245 6 : CHECK_EQ(access, kOvflAccess);
246 : access = builder.AddEntry(pos, dblValue);
247 6 : CHECK_EQ(access, kOvflAccess);
248 6 : }
249 :
250 : } // namespace internal
251 71154 : } // namespace v8
|