| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope()); | 244 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope()); |
| 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 ic_slot_or_count_(FeedbackVectorICSlot::Invalid().ToInt()), |
| 254 kind_(kind), | 255 kind_(kind), |
| 255 emit_store_(true), | 256 emit_store_(true), |
| 256 is_static_(is_static), | 257 is_static_(is_static), |
| 257 is_computed_name_(is_computed_name) {} | 258 is_computed_name_(is_computed_name) {} |
| 258 | 259 |
| 259 | 260 |
| 260 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, | 261 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, |
| 261 Expression* key, Expression* value, | 262 Expression* key, Expression* value, |
| 262 bool is_static, | 263 bool is_static, |
| 263 bool is_computed_name) | 264 bool is_computed_name) |
| 264 : key_(key), | 265 : key_(key), |
| 265 value_(value), | 266 value_(value), |
| 267 ic_slot_or_count_(FeedbackVectorICSlot::Invalid().ToInt()), |
| 266 emit_store_(true), | 268 emit_store_(true), |
| 267 is_static_(is_static), | 269 is_static_(is_static), |
| 268 is_computed_name_(is_computed_name) { | 270 is_computed_name_(is_computed_name) { |
| 269 if (!is_computed_name && | 271 if (!is_computed_name && |
| 270 key->AsLiteral()->raw_value()->EqualsString( | 272 key->AsLiteral()->raw_value()->EqualsString( |
| 271 ast_value_factory->proto_string())) { | 273 ast_value_factory->proto_string())) { |
| 272 kind_ = PROTOTYPE; | 274 kind_ = PROTOTYPE; |
| 273 } else if (value_->AsMaterializedLiteral() != NULL) { | 275 } else if (value_->AsMaterializedLiteral() != NULL) { |
| 274 kind_ = MATERIALIZED_LITERAL; | 276 kind_ = MATERIALIZED_LITERAL; |
| 275 } else if (value_->IsLiteral()) { | 277 } else if (value_->IsLiteral()) { |
| 276 kind_ = CONSTANT; | 278 kind_ = CONSTANT; |
| 277 } else { | 279 } else { |
| 278 kind_ = COMPUTED; | 280 kind_ = COMPUTED; |
| 279 } | 281 } |
| 280 } | 282 } |
| 281 | 283 |
| 282 | 284 |
| 283 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements( | 285 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements( |
| 284 Isolate* isolate, const ICSlotCache* cache) { | 286 Isolate* isolate, const ICSlotCache* cache) { |
| 285 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); | 287 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); |
| 286 | 288 |
| 287 // This logic that computes the number of slots needed for vector store | 289 // This logic that computes the number of slots needed for vector store |
| 288 // ICs must mirror FullCodeGenerator::VisitClassLiteral. | 290 // ICs must mirror FullCodeGenerator::VisitClassLiteral. |
| 289 int ic_slots = 0; | 291 int ic_slots = 0; |
| 292 if (NeedsProxySlot()) { |
| 293 ic_slots++; |
| 294 } |
| 295 |
| 290 for (int i = 0; i < properties()->length(); i++) { | 296 for (int i = 0; i < properties()->length(); i++) { |
| 291 ObjectLiteral::Property* property = properties()->at(i); | 297 ObjectLiteral::Property* property = properties()->at(i); |
| 292 | 298 |
| 293 Expression* value = property->value(); | 299 Expression* value = property->value(); |
| 294 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 300 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 301 property->set_ic_slot_count(1); |
| 302 ic_slots++; |
| 303 } |
| 295 } | 304 } |
| 296 | 305 |
| 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); | 306 return FeedbackVectorRequirements(0, ic_slots); |
| 307 } | 307 } |
| 308 | 308 |
| 309 | 309 |
| 310 FeedbackVectorICSlot ClassLiteral::SlotForHomeObject(Expression* value, | 310 void ClassLiteral::LayoutFeedbackSlots() { |
| 311 int* slot_index) const { | 311 int base_slot = slot_.ToInt(); |
| 312 if (FLAG_vector_stores && FunctionLiteral::NeedsHomeObject(value)) { | 312 if (NeedsProxySlot()) base_slot++; |
| 313 DCHECK(slot_index != NULL && *slot_index >= 0 && *slot_index < slot_count_); | 313 |
| 314 FeedbackVectorICSlot slot = GetNthSlot(*slot_index); | 314 for (int i = 0; i < properties()->length(); i++) { |
| 315 *slot_index += 1; | 315 ObjectLiteral::Property* property = properties()->at(i); |
| 316 return slot; | 316 base_slot += property->set_base_slot(base_slot); |
| 317 } | 317 } |
| 318 return FeedbackVectorICSlot::Invalid(); | |
| 319 } | 318 } |
| 320 | 319 |
| 321 | 320 |
| 322 bool ObjectLiteral::Property::IsCompileTimeValue() { | 321 bool ObjectLiteral::Property::IsCompileTimeValue() { |
| 323 return kind_ == CONSTANT || | 322 return kind_ == CONSTANT || |
| 324 (kind_ == MATERIALIZED_LITERAL && | 323 (kind_ == MATERIALIZED_LITERAL && |
| 325 CompileTimeValue::IsCompileTimeValue(value_)); | 324 CompileTimeValue::IsCompileTimeValue(value_)); |
| 326 } | 325 } |
| 327 | 326 |
| 328 | 327 |
| 329 void ObjectLiteral::Property::set_emit_store(bool emit_store) { | 328 void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
| 330 emit_store_ = emit_store; | 329 emit_store_ = emit_store; |
| 331 } | 330 } |
| 332 | 331 |
| 333 | 332 |
| 334 bool ObjectLiteral::Property::emit_store() { | 333 bool ObjectLiteral::Property::emit_store() { |
| 335 return emit_store_; | 334 return emit_store_; |
| 336 } | 335 } |
| 337 | 336 |
| 338 | 337 |
| 338 void ObjectLiteral::LayoutFeedbackSlots() { |
| 339 int base_slot = slot_.ToInt(); |
| 340 for (int i = 0; i < properties()->length(); i++) { |
| 341 ObjectLiteral::Property* property = properties()->at(i); |
| 342 base_slot += property->set_base_slot(base_slot); |
| 343 } |
| 344 } |
| 345 |
| 346 |
| 339 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements( | 347 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements( |
| 340 Isolate* isolate, const ICSlotCache* cache) { | 348 Isolate* isolate, const ICSlotCache* cache) { |
| 341 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); | 349 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); |
| 342 | 350 |
| 343 // This logic that computes the number of slots needed for vector store | 351 // This logic that computes the number of slots needed for vector store |
| 344 // ics must mirror FullCodeGenerator::VisitObjectLiteral. | 352 // ics must mirror FullCodeGenerator::VisitObjectLiteral. |
| 345 int ic_slots = 0; | 353 int property_index = 0; |
| 346 bool saw_computed_name = false; | 354 for (; property_index < properties()->length(); property_index++) { |
| 347 for (int i = 0; i < properties()->length(); i++) { | 355 ObjectLiteral::Property* property = properties()->at(property_index); |
| 348 ObjectLiteral::Property* property = properties()->at(i); | 356 if (property->is_computed_name()) break; |
| 349 if (property->IsCompileTimeValue()) continue; | 357 if (property->IsCompileTimeValue()) continue; |
| 350 saw_computed_name |= property->is_computed_name(); | 358 |
| 359 Literal* key = property->key()->AsLiteral(); |
| 360 Expression* value = property->value(); |
| 361 switch (property->kind()) { |
| 362 case ObjectLiteral::Property::CONSTANT: |
| 363 UNREACHABLE(); |
| 364 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 365 // Fall through. |
| 366 case ObjectLiteral::Property::COMPUTED: |
| 367 // It is safe to use [[Put]] here because the boilerplate already |
| 368 // contains computed properties with an uninitialized value. |
| 369 if (key->value()->IsInternalizedString()) { |
| 370 if (property->emit_store()) { |
| 371 int slot_count = 1; |
| 372 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 373 slot_count++; |
| 374 } |
| 375 property->set_ic_slot_count(slot_count); |
| 376 } |
| 377 break; |
| 378 } |
| 379 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) { |
| 380 property->set_ic_slot_count(1); |
| 381 } |
| 382 break; |
| 383 case ObjectLiteral::Property::PROTOTYPE: |
| 384 break; |
| 385 case ObjectLiteral::Property::GETTER: |
| 386 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) { |
| 387 property->set_ic_slot_count(1); |
| 388 } |
| 389 break; |
| 390 case ObjectLiteral::Property::SETTER: |
| 391 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) { |
| 392 property->set_ic_slot_count(1); |
| 393 } |
| 394 break; |
| 395 } |
| 396 } |
| 397 |
| 398 for (; property_index < properties()->length(); property_index++) { |
| 399 ObjectLiteral::Property* property = properties()->at(property_index); |
| 351 | 400 |
| 352 Expression* value = property->value(); | 401 Expression* value = property->value(); |
| 353 if (saw_computed_name && | 402 if (property->kind() != ObjectLiteral::Property::PROTOTYPE) { |
| 354 property->kind() != ObjectLiteral::Property::PROTOTYPE) { | 403 if (FunctionLiteral::NeedsHomeObject(value)) { |
| 355 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | 404 property->set_ic_slot_count(1); |
| 356 } else if (property->emit_store()) { | |
| 357 if (property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || | |
| 358 property->kind() == ObjectLiteral::Property::COMPUTED) { | |
| 359 Literal* key = property->key()->AsLiteral(); | |
| 360 if (key->value()->IsInternalizedString()) ic_slots++; | |
| 361 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | |
| 362 } else if (property->kind() == ObjectLiteral::Property::GETTER || | |
| 363 property->kind() == ObjectLiteral::Property::SETTER) { | |
| 364 // We might need a slot for the home object. | |
| 365 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; | |
| 366 } | 405 } |
| 367 } | 406 } |
| 368 } | 407 } |
| 369 | 408 |
| 370 #ifdef DEBUG | 409 // How many slots did we allocate? |
| 371 // FullCodeGenerator::VisitObjectLiteral verifies that it consumes slot_count_ | 410 int ic_slots = 0; |
| 372 // slots. | 411 for (int i = 0; i < properties()->length(); i++) { |
| 373 slot_count_ = ic_slots; | 412 ObjectLiteral::Property* property = properties()->at(i); |
| 374 #endif | 413 ic_slots += property->ic_slot_count(); |
| 414 } |
| 415 |
| 375 return FeedbackVectorRequirements(0, ic_slots); | 416 return FeedbackVectorRequirements(0, ic_slots); |
| 376 } | 417 } |
| 377 | 418 |
| 378 | 419 |
| 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) { | 420 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
| 392 const auto GETTER = ObjectLiteral::Property::GETTER; | 421 const auto GETTER = ObjectLiteral::Property::GETTER; |
| 393 const auto SETTER = ObjectLiteral::Property::SETTER; | 422 const auto SETTER = ObjectLiteral::Property::SETTER; |
| 394 | 423 |
| 395 ZoneAllocationPolicy allocator(zone); | 424 ZoneAllocationPolicy allocator(zone); |
| 396 | 425 |
| 397 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, | 426 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
| 398 allocator); | 427 allocator); |
| 399 for (int i = properties()->length() - 1; i >= 0; i--) { | 428 for (int i = properties()->length() - 1; i >= 0; i--) { |
| 400 ObjectLiteral::Property* property = properties()->at(i); | 429 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) { | 1182 bool Literal::Match(void* literal1, void* literal2) { |
| 1154 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1183 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
| 1155 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1184 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
| 1156 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1185 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
| 1157 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1186 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
| 1158 } | 1187 } |
| 1159 | 1188 |
| 1160 | 1189 |
| 1161 } // namespace internal | 1190 } // namespace internal |
| 1162 } // namespace v8 | 1191 } // namespace v8 |
| OLD | NEW |