OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast.h" | 5 #include "src/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject(); | 245 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject(); |
246 } | 246 } |
247 | 247 |
248 | 248 |
249 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, | 249 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, |
250 Kind kind, bool is_static, | 250 Kind kind, bool is_static, |
251 bool is_computed_name) | 251 bool is_computed_name) |
252 : key_(key), | 252 : key_(key), |
253 value_(value), | 253 value_(value), |
254 kind_(kind), | 254 kind_(kind), |
| 255 ic_slot_(FeedbackVectorICSlot::Invalid()), |
| 256 ic_slot_count_(0), |
255 emit_store_(true), | 257 emit_store_(true), |
256 is_static_(is_static), | 258 is_static_(is_static), |
257 is_computed_name_(is_computed_name) {} | 259 is_computed_name_(is_computed_name) {} |
258 | 260 |
259 | 261 |
260 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, | 262 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, |
261 Expression* key, Expression* value, | 263 Expression* key, Expression* value, |
262 bool is_static, | 264 bool is_static, |
263 bool is_computed_name) | 265 bool is_computed_name) |
264 : key_(key), | 266 : key_(key), |
265 value_(value), | 267 value_(value), |
| 268 ic_slot_(FeedbackVectorICSlot::Invalid()), |
| 269 ic_slot_count_(0), |
266 emit_store_(true), | 270 emit_store_(true), |
267 is_static_(is_static), | 271 is_static_(is_static), |
268 is_computed_name_(is_computed_name) { | 272 is_computed_name_(is_computed_name) { |
269 if (!is_computed_name && | 273 if (!is_computed_name && |
270 key->AsLiteral()->raw_value()->EqualsString( | 274 key->AsLiteral()->raw_value()->EqualsString( |
271 ast_value_factory->proto_string())) { | 275 ast_value_factory->proto_string())) { |
272 kind_ = PROTOTYPE; | 276 kind_ = PROTOTYPE; |
273 } else if (value_->AsMaterializedLiteral() != NULL) { | 277 } else if (value_->AsMaterializedLiteral() != NULL) { |
274 kind_ = MATERIALIZED_LITERAL; | 278 kind_ = MATERIALIZED_LITERAL; |
275 } else if (value_->IsLiteral()) { | 279 } else if (value_->IsLiteral()) { |
276 kind_ = CONSTANT; | 280 kind_ = CONSTANT; |
277 } else { | 281 } else { |
278 kind_ = COMPUTED; | 282 kind_ = COMPUTED; |
279 } | 283 } |
280 } | 284 } |
281 | 285 |
282 | 286 |
283 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements( | 287 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements( |
284 Isolate* isolate, const ICSlotCache* cache) { | 288 Isolate* isolate, const ICSlotCache* cache) { |
285 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); | 289 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); |
286 | 290 |
287 // This logic that computes the number of slots needed for vector store | 291 // This logic that computes the number of slots needed for vector store |
288 // ICs must mirror FullCodeGenerator::VisitClassLiteral. | 292 // ICs must mirror FullCodeGenerator::VisitClassLiteral. |
289 int ic_slots = 0; | 293 int ic_slots = 0; |
| 294 if (NeedsProxySlot()) { |
| 295 ic_slots++; |
| 296 } |
| 297 |
290 for (int i = 0; i < properties()->length(); i++) { | 298 for (int i = 0; i < properties()->length(); i++) { |
291 ObjectLiteral::Property* property = properties()->at(i); | 299 ObjectLiteral::Property* property = properties()->at(i); |
292 | 300 |
293 Expression* value = property->value(); | 301 Expression* value = property->value(); |
294 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 302 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 303 property->set_ic_slot_count(1); |
| 304 ic_slots++; |
| 305 } |
295 } | 306 } |
296 | 307 |
297 if (scope() != NULL && class_variable_proxy()->var()->IsUnallocated()) { | |
298 ic_slots++; | |
299 } | |
300 | |
301 #ifdef DEBUG | |
302 // FullCodeGenerator::VisitClassLiteral verifies that it consumes slot_count_ | |
303 // slots. | |
304 slot_count_ = ic_slots; | |
305 #endif | |
306 return FeedbackVectorRequirements(0, ic_slots); | 308 return FeedbackVectorRequirements(0, ic_slots); |
307 } | 309 } |
308 | 310 |
309 | 311 |
310 FeedbackVectorICSlot ClassLiteral::SlotForHomeObject(Expression* value, | 312 void ClassLiteral::LayoutFeedbackSlots() { |
311 int* slot_index) const { | 313 int base_slot = slot_.ToInt(); |
312 if (FLAG_vector_stores && FunctionLiteral::NeedsHomeObject(value)) { | 314 if (NeedsProxySlot()) base_slot++; |
313 DCHECK(slot_index != NULL && *slot_index >= 0 && *slot_index < slot_count_); | 315 |
314 FeedbackVectorICSlot slot = GetNthSlot(*slot_index); | 316 for (int i = 0; i < properties()->length(); i++) { |
315 *slot_index += 1; | 317 ObjectLiteral::Property* property = properties()->at(i); |
316 return slot; | 318 int count = property->ic_slot_count(); |
| 319 if (count > 0) { |
| 320 property->set_base_slot(base_slot); |
| 321 base_slot += property->ic_slot_count(); |
| 322 } |
317 } | 323 } |
318 return FeedbackVectorICSlot::Invalid(); | |
319 } | 324 } |
320 | 325 |
321 | 326 |
322 bool ObjectLiteral::Property::IsCompileTimeValue() { | 327 bool ObjectLiteral::Property::IsCompileTimeValue() { |
323 return kind_ == CONSTANT || | 328 return kind_ == CONSTANT || |
324 (kind_ == MATERIALIZED_LITERAL && | 329 (kind_ == MATERIALIZED_LITERAL && |
325 CompileTimeValue::IsCompileTimeValue(value_)); | 330 CompileTimeValue::IsCompileTimeValue(value_)); |
326 } | 331 } |
327 | 332 |
328 | 333 |
329 void ObjectLiteral::Property::set_emit_store(bool emit_store) { | 334 void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
330 emit_store_ = emit_store; | 335 emit_store_ = emit_store; |
331 } | 336 } |
332 | 337 |
333 | 338 |
334 bool ObjectLiteral::Property::emit_store() { | 339 bool ObjectLiteral::Property::emit_store() { |
335 return emit_store_; | 340 return emit_store_; |
336 } | 341 } |
337 | 342 |
338 | 343 |
| 344 void ObjectLiteral::LayoutFeedbackSlots() { |
| 345 int base_slot = slot_.ToInt(); |
| 346 for (int i = 0; i < properties()->length(); i++) { |
| 347 ObjectLiteral::Property* property = properties()->at(i); |
| 348 property->set_base_slot(base_slot); |
| 349 int count = property->ic_slot_count(); |
| 350 if (count > 0) { |
| 351 property->set_base_slot(base_slot); |
| 352 base_slot += property->ic_slot_count(); |
| 353 } |
| 354 } |
| 355 } |
| 356 |
| 357 |
339 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements( | 358 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements( |
340 Isolate* isolate, const ICSlotCache* cache) { | 359 Isolate* isolate, const ICSlotCache* cache) { |
341 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); | 360 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); |
342 | 361 |
343 // This logic that computes the number of slots needed for vector store | 362 // This logic that computes the number of slots needed for vector store |
344 // ics must mirror FullCodeGenerator::VisitObjectLiteral. | 363 // ics must mirror FullCodeGenerator::VisitObjectLiteral. |
345 int ic_slots = 0; | |
346 bool saw_computed_name = false; | 364 bool saw_computed_name = false; |
347 for (int i = 0; i < properties()->length(); i++) { | 365 for (int i = 0; i < properties()->length(); i++) { |
348 ObjectLiteral::Property* property = properties()->at(i); | 366 ObjectLiteral::Property* property = properties()->at(i); |
349 if (property->IsCompileTimeValue()) continue; | 367 if (property->IsCompileTimeValue()) continue; |
350 saw_computed_name |= property->is_computed_name(); | 368 saw_computed_name |= property->is_computed_name(); |
351 | 369 |
352 Expression* value = property->value(); | 370 Expression* value = property->value(); |
353 if (saw_computed_name && | 371 if (saw_computed_name && |
354 property->kind() != ObjectLiteral::Property::PROTOTYPE) { | 372 property->kind() != ObjectLiteral::Property::PROTOTYPE) { |
355 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 373 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 374 property->set_ic_slot_count(1); |
| 375 } |
356 } else if (property->emit_store()) { | 376 } else if (property->emit_store()) { |
357 if (property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || | 377 if (property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || |
358 property->kind() == ObjectLiteral::Property::COMPUTED) { | 378 property->kind() == ObjectLiteral::Property::COMPUTED) { |
359 Literal* key = property->key()->AsLiteral(); | 379 Literal* key = property->key()->AsLiteral(); |
360 if (key->value()->IsInternalizedString()) ic_slots++; | 380 int slot_count = 0; |
361 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 381 if (key->value()->IsInternalizedString()) slot_count++; |
| 382 if (FunctionLiteral::NeedsHomeObject(value)) slot_count++; |
| 383 property->set_ic_slot_count(slot_count); |
362 } else if (property->kind() == ObjectLiteral::Property::GETTER || | 384 } else if (property->kind() == ObjectLiteral::Property::GETTER || |
363 property->kind() == ObjectLiteral::Property::SETTER) { | 385 property->kind() == ObjectLiteral::Property::SETTER) { |
364 // We might need a slot for the home object. | 386 // We might need a slot for the home object. |
365 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 387 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 388 property->set_ic_slot_count(1); |
| 389 } |
366 } | 390 } |
367 } | 391 } |
368 } | 392 } |
369 | 393 |
370 #ifdef DEBUG | 394 // How many slots did we allocate? |
371 // FullCodeGenerator::VisitObjectLiteral verifies that it consumes slot_count_ | 395 int ic_slots = 0; |
372 // slots. | 396 for (int i = 0; i < properties()->length(); i++) { |
373 slot_count_ = ic_slots; | 397 ObjectLiteral::Property* property = properties()->at(i); |
374 #endif | 398 ic_slots += property->ic_slot_count(); |
| 399 } |
| 400 |
375 return FeedbackVectorRequirements(0, ic_slots); | 401 return FeedbackVectorRequirements(0, ic_slots); |
376 } | 402 } |
377 | 403 |
378 | 404 |
379 FeedbackVectorICSlot ObjectLiteral::SlotForHomeObject(Expression* value, | |
380 int* slot_index) const { | |
381 if (FLAG_vector_stores && FunctionLiteral::NeedsHomeObject(value)) { | |
382 DCHECK(slot_index != NULL && *slot_index >= 0 && *slot_index < slot_count_); | |
383 FeedbackVectorICSlot slot = GetNthSlot(*slot_index); | |
384 *slot_index += 1; | |
385 return slot; | |
386 } | |
387 return FeedbackVectorICSlot::Invalid(); | |
388 } | |
389 | |
390 | |
391 void ObjectLiteral::CalculateEmitStore(Zone* zone) { | 405 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
392 const auto GETTER = ObjectLiteral::Property::GETTER; | 406 const auto GETTER = ObjectLiteral::Property::GETTER; |
393 const auto SETTER = ObjectLiteral::Property::SETTER; | 407 const auto SETTER = ObjectLiteral::Property::SETTER; |
394 | 408 |
395 ZoneAllocationPolicy allocator(zone); | 409 ZoneAllocationPolicy allocator(zone); |
396 | 410 |
397 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, | 411 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
398 allocator); | 412 allocator); |
399 for (int i = properties()->length() - 1; i >= 0; i--) { | 413 for (int i = properties()->length() - 1; i >= 0; i--) { |
400 ObjectLiteral::Property* property = properties()->at(i); | 414 ObjectLiteral::Property* property = properties()->at(i); |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 bool Literal::Match(void* literal1, void* literal2) { | 1167 bool Literal::Match(void* literal1, void* literal2) { |
1154 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1168 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
1155 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1169 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
1156 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1170 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
1157 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1171 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
1158 } | 1172 } |
1159 | 1173 |
1160 | 1174 |
1161 } // namespace internal | 1175 } // namespace internal |
1162 } // namespace v8 | 1176 } // namespace v8 |
OLD | NEW |