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