Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 2610683003: [ignition] Only initialize [[HomeObject]] for class constructors if needed (Closed)
Patch Set: Fix bytecode expectations Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/compile-time-value.h" 7 #include "src/ast/compile-time-value.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/builtins/builtins-constructor.h" 9 #include "src/builtins/builtins-constructor.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 1404
1405 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { 1405 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1406 uint8_t flags = CreateClosureFlags::Encode(expr->pretenure(), 1406 uint8_t flags = CreateClosureFlags::Encode(expr->pretenure(),
1407 scope()->is_function_scope()); 1407 scope()->is_function_scope());
1408 size_t entry = builder()->AllocateConstantPoolEntry(); 1408 size_t entry = builder()->AllocateConstantPoolEntry();
1409 builder()->CreateClosure(entry, flags); 1409 builder()->CreateClosure(entry, flags);
1410 function_literals_.push_back(std::make_pair(expr, entry)); 1410 function_literals_.push_back(std::make_pair(expr, entry));
1411 } 1411 }
1412 1412
1413 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { 1413 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
1414 VisitClassLiteralForRuntimeDefinition(expr); 1414 Register constructor = VisitForRegisterValue(expr->constructor());
1415 {
1416 RegisterAllocationScope register_scope(this);
1417 RegisterList args = register_allocator()->NewRegisterList(4);
1418 VisitForAccumulatorValueOrTheHole(expr->extends());
1419 builder()
1420 ->StoreAccumulatorInRegister(args[0])
1421 .MoveRegister(constructor, args[1])
1422 .LoadLiteral(Smi::FromInt(expr->start_position()))
1423 .StoreAccumulatorInRegister(args[2])
1424 .LoadLiteral(Smi::FromInt(expr->end_position()))
1425 .StoreAccumulatorInRegister(args[3])
1426 .CallRuntime(Runtime::kDefineClass, args);
1427 }
1428 Register prototype = register_allocator()->NewRegister();
1429 builder()->StoreAccumulatorInRegister(prototype);
1415 1430
1416 // Load the "prototype" from the constructor. 1431 if (FunctionLiteral::NeedsHomeObject(expr->constructor())) {
1417 Register literal = register_allocator()->NewRegister(); 1432 // Prototype is already in the accumulator.
1418 Register prototype = register_allocator()->NewRegister(); 1433 builder()->StoreNamedProperty(constructor, home_object_symbol(),
1419 FeedbackVectorSlot slot = expr->PrototypeSlot(); 1434 feedback_index(expr->HomeObjectSlot()),
1420 builder() 1435 language_mode());
1421 ->StoreAccumulatorInRegister(literal) 1436 }
1422 .LoadNamedProperty(literal, prototype_string(), feedback_index(slot))
1423 .StoreAccumulatorInRegister(prototype);
1424 1437
1425 VisitClassLiteralProperties(expr, literal, prototype); 1438 VisitClassLiteralProperties(expr, constructor, prototype);
1426 BuildClassLiteralNameProperty(expr, literal); 1439 BuildClassLiteralNameProperty(expr, constructor);
1427 builder()->CallRuntime(Runtime::kToFastProperties, literal); 1440 builder()->CallRuntime(Runtime::kToFastProperties, constructor);
1428 // Assign to class variable. 1441 // Assign to class variable.
1429 if (expr->class_variable_proxy() != nullptr) { 1442 if (expr->class_variable_proxy() != nullptr) {
1430 VariableProxy* proxy = expr->class_variable_proxy(); 1443 VariableProxy* proxy = expr->class_variable_proxy();
1431 FeedbackVectorSlot slot = expr->NeedsProxySlot() 1444 FeedbackVectorSlot slot = expr->NeedsProxySlot()
1432 ? expr->ProxySlot() 1445 ? expr->ProxySlot()
1433 : FeedbackVectorSlot::Invalid(); 1446 : FeedbackVectorSlot::Invalid();
1434 BuildVariableAssignment(proxy->var(), Token::INIT, slot, 1447 BuildVariableAssignment(proxy->var(), Token::INIT, slot,
1435 HoleCheckMode::kElided); 1448 HoleCheckMode::kElided);
1436 } 1449 }
1437 } 1450 }
1438 1451
1439 void BytecodeGenerator::VisitClassLiteralForRuntimeDefinition(
1440 ClassLiteral* expr) {
1441 RegisterAllocationScope register_scope(this);
1442 RegisterList args = register_allocator()->NewRegisterList(4);
1443 VisitForAccumulatorValueOrTheHole(expr->extends());
1444 builder()->StoreAccumulatorInRegister(args[0]);
1445 VisitForRegisterValue(expr->constructor(), args[1]);
1446 builder()
1447 ->LoadLiteral(Smi::FromInt(expr->start_position()))
1448 .StoreAccumulatorInRegister(args[2])
1449 .LoadLiteral(Smi::FromInt(expr->end_position()))
1450 .StoreAccumulatorInRegister(args[3])
1451 .CallRuntime(Runtime::kDefineClass, args);
1452 }
1453
1454 void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr, 1452 void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr,
1455 Register literal, 1453 Register constructor,
1456 Register prototype) { 1454 Register prototype) {
1457 RegisterAllocationScope register_scope(this); 1455 RegisterAllocationScope register_scope(this);
1458 RegisterList args = register_allocator()->NewRegisterList(4); 1456 RegisterList args = register_allocator()->NewRegisterList(4);
1459 Register receiver = args[0], key = args[1], value = args[2], attr = args[3]; 1457 Register receiver = args[0], key = args[1], value = args[2], attr = args[3];
1460 1458
1461 bool attr_assigned = false; 1459 bool attr_assigned = false;
1462 Register old_receiver = Register::invalid_value(); 1460 Register old_receiver = Register::invalid_value();
1463 1461
1464 // Create nodes to store method values into the literal. 1462 // Create nodes to store method values into the literal.
1465 for (int i = 0; i < expr->properties()->length(); i++) { 1463 for (int i = 0; i < expr->properties()->length(); i++) {
1466 ClassLiteral::Property* property = expr->properties()->at(i); 1464 ClassLiteral::Property* property = expr->properties()->at(i);
1467 1465
1468 // Set-up receiver. 1466 // Set-up receiver.
1469 Register new_receiver = property->is_static() ? literal : prototype; 1467 Register new_receiver = property->is_static() ? constructor : prototype;
1470 if (new_receiver != old_receiver) { 1468 if (new_receiver != old_receiver) {
1471 builder()->MoveRegister(new_receiver, receiver); 1469 builder()->MoveRegister(new_receiver, receiver);
1472 old_receiver = new_receiver; 1470 old_receiver = new_receiver;
1473 } 1471 }
1474 1472
1475 VisitForAccumulatorValue(property->key()); 1473 VisitForAccumulatorValue(property->key());
1476 builder()->ConvertAccumulatorToName(key); 1474 builder()->ConvertAccumulatorToName(key);
1477 1475
1478 if (property->is_static() && property->is_computed_name()) { 1476 if (property->is_static() && property->is_computed_name()) {
1479 // The static prototype property is read only. We handle the non computed 1477 // The static prototype property is read only. We handle the non computed
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
3309 } 3307 }
3310 3308
3311 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { 3309 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() {
3312 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict 3310 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
3313 : Runtime::kStoreKeyedToSuper_Sloppy; 3311 : Runtime::kStoreKeyedToSuper_Sloppy;
3314 } 3312 }
3315 3313
3316 } // namespace interpreter 3314 } // namespace interpreter
3317 } // namespace internal 3315 } // namespace internal
3318 } // namespace v8 3316 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698