Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1441 context()->Plug(eax); | 1441 context()->Plug(eax); |
| 1442 } | 1442 } |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 | 1445 |
| 1446 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1446 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1447 Comment cmnt(masm_, "[ ArrayLiteral"); | 1447 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1448 | 1448 |
| 1449 ZoneList<Expression*>* subexprs = expr->values(); | 1449 ZoneList<Expression*>* subexprs = expr->values(); |
| 1450 int length = subexprs->length(); | 1450 int length = subexprs->length(); |
| 1451 Handle<FixedArray> constant_elements = expr->constant_elements(); | |
| 1452 ASSERT_EQ(2, constant_elements->length()); | |
| 1453 ElementsKind constant_elements_kind = | |
| 1454 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | |
| 1455 Handle<FixedArrayBase> constant_elements_values( | |
| 1456 FixedArrayBase::cast(constant_elements->get(1))); | |
| 1451 | 1457 |
| 1452 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1458 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1453 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1459 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1454 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1460 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1455 __ push(Immediate(expr->constant_elements())); | 1461 __ push(Immediate(constant_elements)); |
| 1456 if (expr->constant_elements()->map() == | 1462 if (constant_elements_values->map() == |
| 1457 isolate()->heap()->fixed_cow_array_map()) { | 1463 isolate()->heap()->fixed_cow_array_map()) { |
| 1458 ASSERT(expr->depth() == 1); | 1464 ASSERT(expr->depth() == 1); |
| 1459 FastCloneShallowArrayStub stub( | 1465 FastCloneShallowArrayStub stub( |
| 1460 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1466 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 1461 __ CallStub(&stub); | 1467 __ CallStub(&stub); |
| 1462 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | 1468 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
| 1463 } else if (expr->depth() > 1) { | 1469 } else if (expr->depth() > 1) { |
| 1464 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1470 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 1465 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1471 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1466 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1472 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 1467 } else { | 1473 } else { |
| 1468 FastCloneShallowArrayStub stub( | 1474 ASSERT(constant_elements_kind == FAST_ELEMENTS || FLAG_smi_only_arrays); |
| 1469 FastCloneShallowArrayStub::CLONE_ELEMENTS, length); | 1475 FastCloneShallowArrayStub::Mode mode = |
| 1476 constant_elements_kind == FAST_DOUBLE_ELEMENTS | |
| 1477 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | |
| 1478 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | |
| 1479 FastCloneShallowArrayStub stub(mode, length); | |
| 1470 __ CallStub(&stub); | 1480 __ CallStub(&stub); |
| 1471 } | 1481 } |
| 1472 | 1482 |
| 1473 bool result_saved = false; // Is the result saved to the stack? | 1483 bool result_saved = false; // Is the result saved to the stack? |
| 1474 | 1484 |
| 1475 // Emit code to evaluate all the non-constant subexpressions and to store | 1485 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1476 // them into the newly cloned array. | 1486 // them into the newly cloned array. |
| 1477 for (int i = 0; i < length; i++) { | 1487 for (int i = 0; i < length; i++) { |
| 1478 Expression* subexpr = subexprs->at(i); | 1488 Expression* subexpr = subexprs->at(i); |
| 1479 // If the subexpression is a literal or a simple materialized literal it | 1489 // If the subexpression is a literal or a simple materialized literal it |
| 1480 // is already set in the cloned array. | 1490 // is already set in the cloned array. |
| 1481 if (subexpr->AsLiteral() != NULL || | 1491 if (subexpr->AsLiteral() != NULL || |
| 1482 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1492 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1483 continue; | 1493 continue; |
| 1484 } | 1494 } |
| 1485 | 1495 |
| 1486 if (!result_saved) { | 1496 if (!result_saved) { |
| 1487 __ push(eax); | 1497 __ push(eax); |
| 1488 result_saved = true; | 1498 result_saved = true; |
| 1489 increment_stack_height(); | 1499 increment_stack_height(); |
| 1490 } | 1500 } |
| 1491 VisitForAccumulatorValue(subexpr); | 1501 VisitForAccumulatorValue(subexpr); |
| 1492 | 1502 |
| 1493 // Store the subexpression value in the array's elements. | 1503 // Store the subexpression value in the array's elements. |
| 1494 __ mov(ebx, Operand(esp, 0)); // Copy of array literal. | 1504 __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1505 __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); | |
| 1495 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | 1506 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1496 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1507 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1508 | |
| 1509 Label element_done; | |
| 1510 Label double_elements; | |
| 1511 Label smi_element; | |
| 1512 Label slow_elements; | |
| 1513 Label fast_elements; | |
| 1514 __ CheckFastElements(edi, &double_elements); | |
| 1515 | |
| 1516 // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS | |
| 1517 __ JumpIfSmi(result_register(), &smi_element); | |
| 1518 __ CheckFastSmiOnlyElements(edi, &fast_elements, Label::kNear); | |
| 1519 | |
| 1520 // Store into the array literal requires a elements transition. Call into | |
| 1521 // the runtime. | |
| 1522 __ bind(&slow_elements); | |
| 1523 __ push(Operand(esp, 0)); // Copy of array literal. | |
| 1524 __ push(Immediate(Smi::FromInt(i))); | |
| 1525 __ push(result_register()); | |
| 1526 __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes | |
| 1527 __ push(Immediate(Smi::FromInt(strict_mode_flag()))); // Strict mode. | |
| 1528 // Do tail-call to runtime routine. | |
|
Jakob Kummerow
2011/10/18 15:42:36
This is not a tail call.
danno
2011/10/19 11:36:39
Done.
| |
| 1529 __ CallRuntime(Runtime::kSetProperty, 5); | |
| 1530 __ jmp(&element_done); | |
| 1531 | |
| 1532 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS | |
|
Jakob Kummerow
2011/10/18 15:42:36
nit: missing dot at the end.
danno
2011/10/19 11:36:39
Done.
| |
| 1533 __ bind(&double_elements); | |
| 1534 __ mov(ecx, Immediate(Smi::FromInt(i))); | |
| 1535 __ StoreNumberToDoubleElements(result_register(), | |
| 1536 ebx, | |
| 1537 ecx, | |
| 1538 edx, | |
| 1539 xmm0, | |
| 1540 &slow_elements, | |
| 1541 false); | |
| 1542 __ jmp(&element_done); | |
| 1543 | |
| 1544 // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. | |
| 1545 __ bind(&fast_elements); | |
| 1497 __ mov(FieldOperand(ebx, offset), result_register()); | 1546 __ mov(FieldOperand(ebx, offset), result_register()); |
| 1498 | |
| 1499 Label no_map_change; | |
| 1500 __ JumpIfSmi(result_register(), &no_map_change); | |
| 1501 // Update the write barrier for the array store. | 1547 // Update the write barrier for the array store. |
| 1502 __ RecordWriteField(ebx, offset, result_register(), ecx, | 1548 __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1503 kDontSaveFPRegs, | 1549 kDontSaveFPRegs, |
| 1504 EMIT_REMEMBERED_SET, | 1550 EMIT_REMEMBERED_SET, |
| 1505 OMIT_SMI_CHECK); | 1551 OMIT_SMI_CHECK); |
| 1506 __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); | 1552 __ jmp(&element_done); |
| 1507 __ CheckFastSmiOnlyElements(edi, &no_map_change, Label::kNear); | 1553 |
| 1508 __ push(Operand(esp, 0)); | 1554 // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or |
| 1509 __ CallRuntime(Runtime::kNonSmiElementStored, 1); | 1555 // FAST_ELEMENTS, and value is Smi. |
| 1510 __ bind(&no_map_change); | 1556 __ bind(&smi_element); |
| 1557 __ mov(FieldOperand(ebx, offset), result_register()); | |
| 1558 // Fall through | |
| 1559 | |
| 1560 __ bind(&element_done); | |
| 1511 | 1561 |
| 1512 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1562 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
| 1513 } | 1563 } |
| 1514 | 1564 |
| 1515 if (result_saved) { | 1565 if (result_saved) { |
| 1516 context()->PlugTOS(); | 1566 context()->PlugTOS(); |
| 1517 } else { | 1567 } else { |
| 1518 context()->Plug(eax); | 1568 context()->Plug(eax); |
| 1519 } | 1569 } |
| 1520 } | 1570 } |
| (...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4335 *context_length = 0; | 4385 *context_length = 0; |
| 4336 return previous_; | 4386 return previous_; |
| 4337 } | 4387 } |
| 4338 | 4388 |
| 4339 | 4389 |
| 4340 #undef __ | 4390 #undef __ |
| 4341 | 4391 |
| 4342 } } // namespace v8::internal | 4392 } } // namespace v8::internal |
| 4343 | 4393 |
| 4344 #endif // V8_TARGET_ARCH_IA32 | 4394 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |