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 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 context()->Plug(rax); | 1410 context()->Plug(rax); |
1411 } | 1411 } |
1412 } | 1412 } |
1413 | 1413 |
1414 | 1414 |
1415 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1415 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1416 Comment cmnt(masm_, "[ ArrayLiteral"); | 1416 Comment cmnt(masm_, "[ ArrayLiteral"); |
1417 | 1417 |
1418 ZoneList<Expression*>* subexprs = expr->values(); | 1418 ZoneList<Expression*>* subexprs = expr->values(); |
1419 int length = subexprs->length(); | 1419 int length = subexprs->length(); |
| 1420 Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1421 ASSERT_EQ(2, constant_elements->length()); |
| 1422 ElementsKind constant_elements_kind = |
| 1423 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1424 Handle<FixedArrayBase> constant_elements_values( |
| 1425 FixedArrayBase::cast(constant_elements->get(1))); |
1420 | 1426 |
1421 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1427 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1422 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 1428 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
1423 __ Push(Smi::FromInt(expr->literal_index())); | 1429 __ Push(Smi::FromInt(expr->literal_index())); |
1424 __ Push(expr->constant_elements()); | 1430 __ Push(constant_elements); |
1425 if (expr->constant_elements()->map() == | 1431 if (constant_elements_values->map() == |
1426 isolate()->heap()->fixed_cow_array_map()) { | 1432 isolate()->heap()->fixed_cow_array_map()) { |
1427 FastCloneShallowArrayStub stub( | 1433 FastCloneShallowArrayStub stub( |
1428 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1434 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
1429 __ CallStub(&stub); | 1435 __ CallStub(&stub); |
1430 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | 1436 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
1431 } else if (expr->depth() > 1) { | 1437 } else if (expr->depth() > 1) { |
1432 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1438 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
1433 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1439 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
1434 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1440 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
1435 } else { | 1441 } else { |
1436 FastCloneShallowArrayStub stub( | 1442 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
1437 FastCloneShallowArrayStub::CLONE_ELEMENTS, length); | 1443 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
| 1444 FLAG_smi_only_arrays); |
| 1445 FastCloneShallowArrayStub::Mode mode = |
| 1446 constant_elements_kind == FAST_DOUBLE_ELEMENTS |
| 1447 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 1448 : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 1449 FastCloneShallowArrayStub stub(mode, length); |
1438 __ CallStub(&stub); | 1450 __ CallStub(&stub); |
1439 } | 1451 } |
1440 | 1452 |
1441 bool result_saved = false; // Is the result saved to the stack? | 1453 bool result_saved = false; // Is the result saved to the stack? |
1442 | 1454 |
1443 // Emit code to evaluate all the non-constant subexpressions and to store | 1455 // Emit code to evaluate all the non-constant subexpressions and to store |
1444 // them into the newly cloned array. | 1456 // them into the newly cloned array. |
1445 for (int i = 0; i < length; i++) { | 1457 for (int i = 0; i < length; i++) { |
1446 Expression* subexpr = subexprs->at(i); | 1458 Expression* subexpr = subexprs->at(i); |
1447 // If the subexpression is a literal or a simple materialized literal it | 1459 // If the subexpression is a literal or a simple materialized literal it |
1448 // is already set in the cloned array. | 1460 // is already set in the cloned array. |
1449 if (subexpr->AsLiteral() != NULL || | 1461 if (subexpr->AsLiteral() != NULL || |
1450 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1462 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
1451 continue; | 1463 continue; |
1452 } | 1464 } |
1453 | 1465 |
1454 if (!result_saved) { | 1466 if (!result_saved) { |
1455 __ push(rax); | 1467 __ push(rax); |
1456 result_saved = true; | 1468 result_saved = true; |
1457 } | 1469 } |
1458 VisitForAccumulatorValue(subexpr); | 1470 VisitForAccumulatorValue(subexpr); |
1459 | 1471 |
1460 // Store the subexpression value in the array's elements. | 1472 // Store the subexpression value in the array's elements. |
1461 __ movq(r8, Operand(rsp, 0)); // Copy of array literal. | 1473 __ movq(r8, Operand(rsp, 0)); // Copy of array literal. |
| 1474 __ movq(rdi, FieldOperand(r8, JSObject::kMapOffset)); |
1462 __ movq(rbx, FieldOperand(r8, JSObject::kElementsOffset)); | 1475 __ movq(rbx, FieldOperand(r8, JSObject::kElementsOffset)); |
1463 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1476 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1477 |
| 1478 Label element_done; |
| 1479 Label double_elements; |
| 1480 Label smi_element; |
| 1481 Label slow_elements; |
| 1482 Label fast_elements; |
| 1483 __ CheckFastElements(rdi, &double_elements); |
| 1484 |
| 1485 // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS |
| 1486 __ JumpIfSmi(result_register(), &smi_element); |
| 1487 __ CheckFastSmiOnlyElements(rdi, &fast_elements); |
| 1488 |
| 1489 // Store into the array literal requires a elements transition. Call into |
| 1490 // the runtime. |
| 1491 __ bind(&slow_elements); |
| 1492 __ push(r8); // Copy of array literal. |
| 1493 __ Push(Smi::FromInt(i)); |
| 1494 __ push(result_register()); |
| 1495 __ Push(Smi::FromInt(NONE)); // PropertyAttributes |
| 1496 __ Push(Smi::FromInt(strict_mode_flag())); // Strict mode. |
| 1497 // Do tail-call to runtime routine. |
| 1498 __ CallRuntime(Runtime::kSetProperty, 5); |
| 1499 __ jmp(&element_done); |
| 1500 |
| 1501 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS |
| 1502 __ bind(&double_elements); |
| 1503 __ movq(rcx, Immediate(i)); |
| 1504 __ StoreNumberToDoubleElements(result_register(), |
| 1505 rbx, |
| 1506 rcx, |
| 1507 xmm0, |
| 1508 &slow_elements); |
| 1509 __ jmp(&element_done); |
| 1510 |
| 1511 // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. |
| 1512 __ bind(&fast_elements); |
1464 __ movq(FieldOperand(rbx, offset), result_register()); | 1513 __ movq(FieldOperand(rbx, offset), result_register()); |
1465 | |
1466 Label no_map_change; | |
1467 __ JumpIfSmi(result_register(), &no_map_change); | |
1468 // Update the write barrier for the array store. | 1514 // Update the write barrier for the array store. |
1469 __ RecordWriteField(rbx, offset, result_register(), rcx, | 1515 __ RecordWriteField(rbx, offset, result_register(), rcx, |
1470 kDontSaveFPRegs, | 1516 kDontSaveFPRegs, |
1471 EMIT_REMEMBERED_SET, | 1517 EMIT_REMEMBERED_SET, |
1472 OMIT_SMI_CHECK); | 1518 OMIT_SMI_CHECK); |
1473 __ movq(rdi, FieldOperand(rbx, JSObject::kMapOffset)); | 1519 __ jmp(&element_done); |
1474 __ CheckFastSmiOnlyElements(rdi, &no_map_change, Label::kNear); | 1520 |
1475 __ push(r8); | 1521 // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or |
1476 __ CallRuntime(Runtime::kNonSmiElementStored, 1); | 1522 // FAST_ELEMENTS, and value is Smi. |
1477 __ bind(&no_map_change); | 1523 __ bind(&smi_element); |
| 1524 __ movq(FieldOperand(rbx, offset), result_register()); |
| 1525 // Fall through |
| 1526 |
| 1527 __ bind(&element_done); |
1478 | 1528 |
1479 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1529 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
1480 } | 1530 } |
1481 | 1531 |
1482 if (result_saved) { | 1532 if (result_saved) { |
1483 context()->PlugTOS(); | 1533 context()->PlugTOS(); |
1484 } else { | 1534 } else { |
1485 context()->Plug(rax); | 1535 context()->Plug(rax); |
1486 } | 1536 } |
1487 } | 1537 } |
(...skipping 2699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4187 *context_length = 0; | 4237 *context_length = 0; |
4188 return previous_; | 4238 return previous_; |
4189 } | 4239 } |
4190 | 4240 |
4191 | 4241 |
4192 #undef __ | 4242 #undef __ |
4193 | 4243 |
4194 } } // namespace v8::internal | 4244 } } // namespace v8::internal |
4195 | 4245 |
4196 #endif // V8_TARGET_ARCH_X64 | 4246 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |