OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 18 matching lines...) Expand all Loading... |
29 #define V8_TEST_CCTEST_TYPES_H_ | 29 #define V8_TEST_CCTEST_TYPES_H_ |
30 | 30 |
31 #include "src/base/utils/random-number-generator.h" | 31 #include "src/base/utils/random-number-generator.h" |
32 #include "src/factory.h" | 32 #include "src/factory.h" |
33 #include "src/isolate.h" | 33 #include "src/isolate.h" |
34 #include "src/v8.h" | 34 #include "src/v8.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 | |
40 class Types { | 39 class Types { |
41 public: | 40 public: |
42 Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng) | 41 Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng) |
43 : zone_(zone), isolate_(isolate), rng_(rng) { | 42 : zone_(zone), rng_(rng) { |
44 #define DECLARE_TYPE(name, value) \ | 43 #define DECLARE_TYPE(name, value) \ |
45 name = Type::name(); \ | 44 name = Type::name(); \ |
46 types.push_back(name); | 45 types.push_back(name); |
47 PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) | 46 PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) |
48 #undef DECLARE_TYPE | 47 #undef DECLARE_TYPE |
49 | 48 |
50 SignedSmall = Type::SignedSmall(); | 49 SignedSmall = Type::SignedSmall(); |
51 UnsignedSmall = Type::UnsignedSmall(); | 50 UnsignedSmall = Type::UnsignedSmall(); |
52 | 51 |
53 object_map = isolate->factory()->NewMap( | 52 object_map = isolate->factory()->NewMap( |
54 JS_OBJECT_TYPE, JSObject::kHeaderSize); | 53 JS_OBJECT_TYPE, JSObject::kHeaderSize); |
55 array_map = isolate->factory()->NewMap( | |
56 JS_ARRAY_TYPE, JSArray::kSize); | |
57 number_map = isolate->factory()->NewMap( | |
58 HEAP_NUMBER_TYPE, HeapNumber::kSize); | |
59 uninitialized_map = isolate->factory()->uninitialized_map(); | |
60 ObjectClass = Type::Class(object_map, zone); | |
61 ArrayClass = Type::Class(array_map, zone); | |
62 NumberClass = Type::Class(number_map, zone); | |
63 UninitializedClass = Type::Class(uninitialized_map, zone); | |
64 | |
65 maps.push_back(object_map); | |
66 maps.push_back(array_map); | |
67 maps.push_back(uninitialized_map); | |
68 for (MapVector::iterator it = maps.begin(); it != maps.end(); ++it) { | |
69 types.push_back(Type::Class(*it, zone)); | |
70 } | |
71 | 54 |
72 smi = handle(Smi::FromInt(666), isolate); | 55 smi = handle(Smi::FromInt(666), isolate); |
73 signed32 = isolate->factory()->NewHeapNumber(0x40000000); | 56 signed32 = isolate->factory()->NewHeapNumber(0x40000000); |
74 object1 = isolate->factory()->NewJSObjectFromMap(object_map); | 57 object1 = isolate->factory()->NewJSObjectFromMap(object_map); |
75 object2 = isolate->factory()->NewJSObjectFromMap(object_map); | 58 object2 = isolate->factory()->NewJSObjectFromMap(object_map); |
76 array = isolate->factory()->NewJSArray(20); | 59 array = isolate->factory()->NewJSArray(20); |
77 uninitialized = isolate->factory()->uninitialized_value(); | 60 uninitialized = isolate->factory()->uninitialized_value(); |
78 SmiConstant = Type::Constant(smi, zone); | 61 SmiConstant = Type::Constant(smi, zone); |
79 Signed32Constant = Type::Constant(signed32, zone); | 62 Signed32Constant = Type::Constant(signed32, zone); |
80 | 63 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 NumberFunction1 = Type::Function(Number, Number, zone); | 97 NumberFunction1 = Type::Function(Number, Number, zone); |
115 NumberFunction2 = Type::Function(Number, Number, Number, zone); | 98 NumberFunction2 = Type::Function(Number, Number, Number, zone); |
116 MethodFunction = Type::Function(String, Object, 0, zone); | 99 MethodFunction = Type::Function(String, Object, 0, zone); |
117 | 100 |
118 for (int i = 0; i < 30; ++i) { | 101 for (int i = 0; i < 30; ++i) { |
119 types.push_back(Fuzz()); | 102 types.push_back(Fuzz()); |
120 } | 103 } |
121 } | 104 } |
122 | 105 |
123 Handle<i::Map> object_map; | 106 Handle<i::Map> object_map; |
124 Handle<i::Map> array_map; | |
125 Handle<i::Map> number_map; | |
126 Handle<i::Map> uninitialized_map; | |
127 | 107 |
128 Handle<i::Smi> smi; | 108 Handle<i::Smi> smi; |
129 Handle<i::HeapNumber> signed32; | 109 Handle<i::HeapNumber> signed32; |
130 Handle<i::JSObject> object1; | 110 Handle<i::JSObject> object1; |
131 Handle<i::JSObject> object2; | 111 Handle<i::JSObject> object2; |
132 Handle<i::JSArray> array; | 112 Handle<i::JSArray> array; |
133 Handle<i::Oddball> uninitialized; | 113 Handle<i::Oddball> uninitialized; |
134 | 114 |
135 #define DECLARE_TYPE(name, value) Type* name; | 115 #define DECLARE_TYPE(name, value) Type* name; |
136 PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) | 116 PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) |
137 #undef DECLARE_TYPE | 117 #undef DECLARE_TYPE |
138 | 118 |
139 #define DECLARE_TYPE(name, value) Type* Mask##name##ForTesting; | 119 #define DECLARE_TYPE(name, value) Type* Mask##name##ForTesting; |
140 MASK_BITSET_TYPE_LIST(DECLARE_TYPE) | 120 MASK_BITSET_TYPE_LIST(DECLARE_TYPE) |
141 #undef DECLARE_TYPE | 121 #undef DECLARE_TYPE |
142 Type* SignedSmall; | 122 Type* SignedSmall; |
143 Type* UnsignedSmall; | 123 Type* UnsignedSmall; |
144 | 124 |
145 Type* ObjectClass; | |
146 Type* ArrayClass; | |
147 Type* NumberClass; | |
148 Type* UninitializedClass; | |
149 | |
150 Type* SmiConstant; | 125 Type* SmiConstant; |
151 Type* Signed32Constant; | 126 Type* Signed32Constant; |
152 Type* ObjectConstant1; | 127 Type* ObjectConstant1; |
153 Type* ObjectConstant2; | 128 Type* ObjectConstant2; |
154 Type* ArrayConstant; | 129 Type* ArrayConstant; |
155 Type* UninitializedConstant; | 130 Type* UninitializedConstant; |
156 | 131 |
157 Type* Integer; | 132 Type* Integer; |
158 | 133 |
159 Type* NumberArray; | 134 Type* NumberArray; |
160 Type* StringArray; | 135 Type* StringArray; |
161 Type* AnyArray; | 136 Type* AnyArray; |
162 | 137 |
163 Type* SignedFunction1; | 138 Type* SignedFunction1; |
164 Type* NumberFunction1; | 139 Type* NumberFunction1; |
165 Type* NumberFunction2; | 140 Type* NumberFunction2; |
166 Type* MethodFunction; | 141 Type* MethodFunction; |
167 | 142 |
168 typedef std::vector<Type*> TypeVector; | 143 typedef std::vector<Type*> TypeVector; |
169 typedef std::vector<Handle<i::Map> > MapVector; | |
170 typedef std::vector<Handle<i::Object> > ValueVector; | 144 typedef std::vector<Handle<i::Object> > ValueVector; |
171 | 145 |
172 TypeVector types; | 146 TypeVector types; |
173 MapVector maps; | |
174 ValueVector values; | 147 ValueVector values; |
175 ValueVector integers; // "Integer" values used for range limits. | 148 ValueVector integers; // "Integer" values used for range limits. |
176 | 149 |
177 Type* Of(Handle<i::Object> value) { return Type::Of(value, zone_); } | 150 Type* Of(Handle<i::Object> value) { return Type::Of(value, zone_); } |
178 | 151 |
179 Type* NowOf(Handle<i::Object> value) { return Type::NowOf(value, zone_); } | |
180 | |
181 Type* Class(Handle<i::Map> map) { return Type::Class(map, zone_); } | |
182 | |
183 Type* Constant(Handle<i::Object> value) { | 152 Type* Constant(Handle<i::Object> value) { |
184 return Type::Constant(value, zone_); | 153 return Type::Constant(value, zone_); |
185 } | 154 } |
186 | 155 |
187 Type* Range(double min, double max) { return Type::Range(min, max, zone_); } | 156 Type* Range(double min, double max) { return Type::Range(min, max, zone_); } |
188 | 157 |
189 Type* Context(Type* outer) { return Type::Context(outer, zone_); } | 158 Type* Context(Type* outer) { return Type::Context(outer, zone_); } |
190 | 159 |
191 Type* Array1(Type* element) { return Type::Array(element, zone_); } | 160 Type* Array1(Type* element) { return Type::Array(element, zone_); } |
192 | 161 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } else { \ | 203 } else { \ |
235 result = tmp; \ | 204 result = tmp; \ |
236 continue; \ | 205 continue; \ |
237 } \ | 206 } \ |
238 } | 207 } |
239 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE) | 208 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE) |
240 #undef PICK_BITSET_TYPE | 209 #undef PICK_BITSET_TYPE |
241 } | 210 } |
242 return result; | 211 return result; |
243 } | 212 } |
244 case 1: { // class | 213 case 1: { // constant |
245 int i = rng_->NextInt(static_cast<int>(maps.size())); | |
246 return Type::Class(maps[i], zone_); | |
247 } | |
248 case 2: { // constant | |
249 int i = rng_->NextInt(static_cast<int>(values.size())); | 214 int i = rng_->NextInt(static_cast<int>(values.size())); |
250 return Type::Constant(values[i], zone_); | 215 return Type::Constant(values[i], zone_); |
251 } | 216 } |
252 case 3: { // range | 217 case 2: { // range |
253 int i = rng_->NextInt(static_cast<int>(integers.size())); | 218 int i = rng_->NextInt(static_cast<int>(integers.size())); |
254 int j = rng_->NextInt(static_cast<int>(integers.size())); | 219 int j = rng_->NextInt(static_cast<int>(integers.size())); |
255 double min = integers[i]->Number(); | 220 double min = integers[i]->Number(); |
256 double max = integers[j]->Number(); | 221 double max = integers[j]->Number(); |
257 if (min > max) std::swap(min, max); | 222 if (min > max) std::swap(min, max); |
258 return Type::Range(min, max, zone_); | 223 return Type::Range(min, max, zone_); |
259 } | 224 } |
260 case 4: { // context | 225 case 3: { // context |
261 int depth = rng_->NextInt(3); | 226 int depth = rng_->NextInt(3); |
262 Type* type = Type::Internal(); | 227 Type* type = Type::Internal(); |
263 for (int i = 0; i < depth; ++i) type = Type::Context(type, zone_); | 228 for (int i = 0; i < depth; ++i) type = Type::Context(type, zone_); |
264 return type; | 229 return type; |
265 } | 230 } |
266 case 5: { // array | 231 case 4: { // array |
267 Type* element = Fuzz(depth / 2); | 232 Type* element = Fuzz(depth / 2); |
268 return Type::Array(element, zone_); | 233 return Type::Array(element, zone_); |
269 } | 234 } |
270 case 6: | 235 case 5: |
271 case 7: { // function | 236 case 6: { // function |
272 Type* result = Fuzz(depth / 2); | 237 Type* result = Fuzz(depth / 2); |
273 Type* receiver = Fuzz(depth / 2); | 238 Type* receiver = Fuzz(depth / 2); |
274 int arity = rng_->NextInt(3); | 239 int arity = rng_->NextInt(3); |
275 Type* type = Type::Function(result, receiver, arity, zone_); | 240 Type* type = Type::Function(result, receiver, arity, zone_); |
276 for (int i = 0; i < type->AsFunction()->Arity(); ++i) { | 241 for (int i = 0; i < type->AsFunction()->Arity(); ++i) { |
277 Type* parameter = Fuzz(depth / 2); | 242 Type* parameter = Fuzz(depth / 2); |
278 type->AsFunction()->InitParameter(i, parameter); | 243 type->AsFunction()->InitParameter(i, parameter); |
279 } | 244 } |
280 return type; | 245 return type; |
281 } | 246 } |
282 case 8: { // simd | |
283 static const int num_simd_types = | |
284 #define COUNT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) +1 | |
285 SIMD128_TYPES(COUNT_SIMD_TYPE); | |
286 #undef COUNT_SIMD_TYPE | |
287 Type* (*simd_constructors[num_simd_types])(Isolate*, Zone*) = { | |
288 #define COUNT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ | |
289 &Type::Name, | |
290 SIMD128_TYPES(COUNT_SIMD_TYPE) | |
291 #undef COUNT_SIMD_TYPE | |
292 }; | |
293 return simd_constructors[rng_->NextInt(num_simd_types)](isolate_, | |
294 zone_); | |
295 } | |
296 default: { // union | 247 default: { // union |
297 int n = rng_->NextInt(10); | 248 int n = rng_->NextInt(10); |
298 Type* type = None; | 249 Type* type = None; |
299 for (int i = 0; i < n; ++i) { | 250 for (int i = 0; i < n; ++i) { |
300 Type* operand = Fuzz(depth - 1); | 251 Type* operand = Fuzz(depth - 1); |
301 type = Type::Union(type, operand, zone_); | 252 type = Type::Union(type, operand, zone_); |
302 } | 253 } |
303 return type; | 254 return type; |
304 } | 255 } |
305 } | 256 } |
306 UNREACHABLE(); | 257 UNREACHABLE(); |
307 } | 258 } |
308 | 259 |
309 Zone* zone() { return zone_; } | 260 Zone* zone() { return zone_; } |
310 | 261 |
311 private: | 262 private: |
312 Zone* zone_; | 263 Zone* zone_; |
313 Isolate* isolate_; | |
314 v8::base::RandomNumberGenerator* rng_; | 264 v8::base::RandomNumberGenerator* rng_; |
315 }; | 265 }; |
316 | 266 |
317 | 267 |
318 } // namespace internal | 268 } // namespace internal |
319 } // namespace v8 | 269 } // namespace v8 |
320 | 270 |
321 #endif | 271 #endif |
OLD | NEW |