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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 context()->Plug(r0); | 1460 context()->Plug(r0); |
| 1461 } | 1461 } |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 | 1464 |
| 1465 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1465 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1466 Comment cmnt(masm_, "[ ArrayLiteral"); | 1466 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1467 | 1467 |
| 1468 ZoneList<Expression*>* subexprs = expr->values(); | 1468 ZoneList<Expression*>* subexprs = expr->values(); |
| 1469 int length = subexprs->length(); | 1469 int length = subexprs->length(); |
| 1470 Handle<FixedArray> constant_elements = expr->constant_elements(); | |
| 1471 ASSERT_EQ(2, constant_elements->length()); | |
| 1472 ElementsKind constant_elements_kind = | |
| 1473 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | |
| 1474 Handle<FixedArrayBase> constant_elements_values( | |
| 1475 FixedArrayBase::cast(constant_elements->get(1))); | |
| 1470 | 1476 |
| 1471 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 1477 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1472 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); | 1478 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 1473 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); | 1479 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); |
| 1474 __ mov(r1, Operand(expr->constant_elements())); | 1480 __ mov(r1, Operand(constant_elements)); |
| 1475 __ Push(r3, r2, r1); | 1481 __ Push(r3, r2, r1); |
| 1476 if (expr->constant_elements()->map() == | 1482 if (constant_elements_values->map() == |
| 1477 isolate()->heap()->fixed_cow_array_map()) { | 1483 isolate()->heap()->fixed_cow_array_map()) { |
| 1478 FastCloneShallowArrayStub stub( | 1484 FastCloneShallowArrayStub stub( |
| 1479 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1485 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 1480 __ CallStub(&stub); | 1486 __ CallStub(&stub); |
| 1481 __ IncrementCounter( | 1487 __ IncrementCounter( |
| 1482 isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); | 1488 isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); |
| 1483 } else if (expr->depth() > 1) { | 1489 } else if (expr->depth() > 1) { |
| 1484 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1490 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 1485 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1491 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1486 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1492 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 1487 } else { | 1493 } else { |
| 1488 FastCloneShallowArrayStub stub( | 1494 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
| 1489 FastCloneShallowArrayStub::CLONE_ELEMENTS, length); | 1495 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
| 1496 FLAG_smi_only_arrays); | |
| 1497 FastCloneShallowArrayStub::Mode mode = | |
| 1498 constant_elements_kind == FAST_DOUBLE_ELEMENTS | |
| 1499 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | |
| 1500 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | |
| 1501 FastCloneShallowArrayStub stub(mode, length); | |
| 1490 __ CallStub(&stub); | 1502 __ CallStub(&stub); |
| 1491 } | 1503 } |
| 1492 | 1504 |
| 1493 bool result_saved = false; // Is the result saved to the stack? | 1505 bool result_saved = false; // Is the result saved to the stack? |
| 1494 | 1506 |
| 1495 // Emit code to evaluate all the non-constant subexpressions and to store | 1507 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1496 // them into the newly cloned array. | 1508 // them into the newly cloned array. |
| 1497 for (int i = 0; i < length; i++) { | 1509 for (int i = 0; i < length; i++) { |
| 1498 Expression* subexpr = subexprs->at(i); | 1510 Expression* subexpr = subexprs->at(i); |
| 1499 // If the subexpression is a literal or a simple materialized literal it | 1511 // If the subexpression is a literal or a simple materialized literal it |
| 1500 // is already set in the cloned array. | 1512 // is already set in the cloned array. |
| 1501 if (subexpr->AsLiteral() != NULL || | 1513 if (subexpr->AsLiteral() != NULL || |
| 1502 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1514 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1503 continue; | 1515 continue; |
| 1504 } | 1516 } |
| 1505 | 1517 |
| 1506 if (!result_saved) { | 1518 if (!result_saved) { |
| 1507 __ push(r0); | 1519 __ push(r0); |
| 1508 result_saved = true; | 1520 result_saved = true; |
| 1509 } | 1521 } |
| 1510 VisitForAccumulatorValue(subexpr); | 1522 VisitForAccumulatorValue(subexpr); |
| 1511 | 1523 |
| 1512 // Store the subexpression value in the array's elements. | |
| 1513 __ ldr(r6, MemOperand(sp)); // Copy of array literal. | 1524 __ ldr(r6, MemOperand(sp)); // Copy of array literal. |
| 1514 __ ldr(r1, FieldMemOperand(r6, JSObject::kElementsOffset)); | 1525 __ ldr(r1, FieldMemOperand(r6, JSObject::kElementsOffset)); |
| 1526 __ ldr(r2, FieldMemOperand(r6, JSObject::kMapOffset)); | |
| 1515 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1527 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1528 | |
| 1529 Label element_done; | |
| 1530 Label double_elements; | |
| 1531 Label smi_element; | |
| 1532 Label slow_elements; | |
| 1533 Label fast_elements; | |
| 1534 __ CheckFastElements(r2, r3, &double_elements); | |
|
Kevin Millikin (Chromium)
2011/10/19 08:10:45
This code checks the element kind for every stored
danno
2011/10/19 11:36:40
Agreed. I will factor this stuff out into a shared
| |
| 1535 | |
| 1536 // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS | |
| 1537 __ JumpIfSmi(result_register(), &smi_element); | |
| 1538 __ CheckFastSmiOnlyElements(r2, r3, &fast_elements); | |
|
Kevin Millikin (Chromium)
2011/10/19 08:10:45
It's a bit confusing (to me) that the label is for
danno
2011/10/19 11:36:40
I modelled this after CheckMap, which also has a s
| |
| 1539 | |
| 1540 // Store into the array literal requires a elements transition. Call into | |
| 1541 // the runtime. | |
| 1542 __ bind(&slow_elements); | |
| 1543 __ push(r6); // Copy of array literal. | |
| 1544 __ mov(r1, Operand(Smi::FromInt(i))); | |
| 1545 __ mov(r2, Operand(Smi::FromInt(NONE))); // PropertyAttributes | |
| 1546 __ mov(r3, Operand(Smi::FromInt(strict_mode_flag()))); // Strict mode. | |
| 1547 __ Push(r1, result_register(), r2, r3); | |
| 1548 | |
| 1549 // Do tail-call to runtime routine. | |
| 1550 __ CallRuntime(Runtime::kSetProperty, 5); | |
|
Kevin Millikin (Chromium)
2011/10/19 08:10:45
Save this for a future CL, but I think that it wou
danno
2011/10/19 11:36:40
Agreed. Next CL.
On 2011/10/19 08:10:45, Kevin Mil
| |
| 1551 __ b(&element_done); | |
| 1552 | |
| 1553 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS | |
| 1554 __ bind(&double_elements); | |
| 1555 __ mov(r3, Operand(Smi::FromInt(i))); | |
| 1556 __ StoreNumberToDoubleElements(result_register(), | |
|
Kevin Millikin (Chromium)
2011/10/19 08:10:45
My biggest concern is that this is a lot of genera
danno
2011/10/19 11:36:40
I'll refactor this stuff into a separate stub in a
| |
| 1557 r3, | |
| 1558 r6, | |
| 1559 r1, | |
| 1560 r4, | |
| 1561 r5, | |
| 1562 r9, | |
| 1563 r7, | |
| 1564 &slow_elements); | |
| 1565 __ b(&element_done); | |
| 1566 | |
| 1567 // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. | |
| 1568 __ bind(&fast_elements); | |
| 1516 __ str(result_register(), FieldMemOperand(r1, offset)); | 1569 __ str(result_register(), FieldMemOperand(r1, offset)); |
| 1517 | 1570 // Update the write barrier for the array store. |
| 1518 Label no_map_change; | |
| 1519 __ JumpIfSmi(result_register(), &no_map_change); | |
| 1520 // Update the write barrier for the array store with r0 as the scratch | |
| 1521 // register. | |
| 1522 __ RecordWriteField( | 1571 __ RecordWriteField( |
| 1523 r1, offset, result_register(), r2, kLRHasBeenSaved, kDontSaveFPRegs, | 1572 r1, offset, result_register(), r2, kLRHasBeenSaved, kDontSaveFPRegs, |
| 1524 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | 1573 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 1525 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); | 1574 __ b(&element_done); |
| 1526 __ CheckFastSmiOnlyElements(r3, r2, &no_map_change); | 1575 |
| 1527 __ push(r6); // Copy of array literal. | 1576 // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or |
| 1528 __ CallRuntime(Runtime::kNonSmiElementStored, 1); | 1577 // FAST_ELEMENTS, and value is Smi. |
| 1529 __ bind(&no_map_change); | 1578 __ bind(&smi_element); |
| 1579 __ str(result_register(), FieldMemOperand(r1, offset)); | |
| 1580 // Fall through | |
| 1581 | |
| 1582 __ bind(&element_done); | |
| 1530 | 1583 |
| 1531 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1584 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
| 1532 } | 1585 } |
| 1533 | 1586 |
| 1534 if (result_saved) { | 1587 if (result_saved) { |
| 1535 context()->PlugTOS(); | 1588 context()->PlugTOS(); |
| 1536 } else { | 1589 } else { |
| 1537 context()->Plug(r0); | 1590 context()->Plug(r0); |
| 1538 } | 1591 } |
| 1539 } | 1592 } |
| (...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4260 *context_length = 0; | 4313 *context_length = 0; |
| 4261 return previous_; | 4314 return previous_; |
| 4262 } | 4315 } |
| 4263 | 4316 |
| 4264 | 4317 |
| 4265 #undef __ | 4318 #undef __ |
| 4266 | 4319 |
| 4267 } } // namespace v8::internal | 4320 } } // namespace v8::internal |
| 4268 | 4321 |
| 4269 #endif // V8_TARGET_ARCH_ARM | 4322 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |