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 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 | 1475 |
1476 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1476 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1477 Comment cmnt(masm_, "[ ArrayLiteral"); | 1477 Comment cmnt(masm_, "[ ArrayLiteral"); |
1478 | 1478 |
1479 ZoneList<Expression*>* subexprs = expr->values(); | 1479 ZoneList<Expression*>* subexprs = expr->values(); |
1480 int length = subexprs->length(); | 1480 int length = subexprs->length(); |
1481 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1481 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1482 ASSERT_EQ(2, constant_elements->length()); | 1482 ASSERT_EQ(2, constant_elements->length()); |
1483 ElementsKind constant_elements_kind = | 1483 ElementsKind constant_elements_kind = |
1484 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1484 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1485 bool has_constant_fast_elements = constant_elements_kind == FAST_ELEMENTS; |
1485 Handle<FixedArrayBase> constant_elements_values( | 1486 Handle<FixedArrayBase> constant_elements_values( |
1486 FixedArrayBase::cast(constant_elements->get(1))); | 1487 FixedArrayBase::cast(constant_elements->get(1))); |
1487 | 1488 |
1488 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1489 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1489 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 1490 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
1490 __ Push(Smi::FromInt(expr->literal_index())); | 1491 __ Push(Smi::FromInt(expr->literal_index())); |
1491 __ Push(constant_elements); | 1492 __ Push(constant_elements); |
1492 if (constant_elements_values->map() == | 1493 Heap* heap = isolate()->heap(); |
1493 isolate()->heap()->fixed_cow_array_map()) { | 1494 if (has_constant_fast_elements && |
| 1495 constant_elements_values->map() == heap->fixed_cow_array_map()) { |
| 1496 // If the elements are already FAST_ELEMENTS, the boilerplate cannot |
| 1497 // change, so it's possible to specialize the stub in advance. |
| 1498 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
1494 FastCloneShallowArrayStub stub( | 1499 FastCloneShallowArrayStub stub( |
1495 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1500 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1501 length); |
1496 __ CallStub(&stub); | 1502 __ CallStub(&stub); |
1497 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | |
1498 } else if (expr->depth() > 1) { | 1503 } else if (expr->depth() > 1) { |
1499 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1504 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
1500 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1505 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
1501 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1506 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
1502 } else { | 1507 } else { |
1503 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1508 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
1504 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | 1509 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
1505 FLAG_smi_only_arrays); | 1510 FLAG_smi_only_arrays); |
1506 FastCloneShallowArrayStub::Mode mode = | 1511 // If the elements are already FAST_ELEMENTS, the boilerplate cannot |
1507 constant_elements_kind == FAST_DOUBLE_ELEMENTS | 1512 // change, so it's possible to specialize the stub in advance. |
1508 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 1513 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements |
1509 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | 1514 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
| 1515 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
1510 FastCloneShallowArrayStub stub(mode, length); | 1516 FastCloneShallowArrayStub stub(mode, length); |
1511 __ CallStub(&stub); | 1517 __ CallStub(&stub); |
1512 } | 1518 } |
1513 | 1519 |
1514 bool result_saved = false; // Is the result saved to the stack? | 1520 bool result_saved = false; // Is the result saved to the stack? |
1515 | 1521 |
1516 // Emit code to evaluate all the non-constant subexpressions and to store | 1522 // Emit code to evaluate all the non-constant subexpressions and to store |
1517 // them into the newly cloned array. | 1523 // them into the newly cloned array. |
1518 for (int i = 0; i < length; i++) { | 1524 for (int i = 0; i < length; i++) { |
1519 Expression* subexpr = subexprs->at(i); | 1525 Expression* subexpr = subexprs->at(i); |
(...skipping 2787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4307 *context_length = 0; | 4313 *context_length = 0; |
4308 return previous_; | 4314 return previous_; |
4309 } | 4315 } |
4310 | 4316 |
4311 | 4317 |
4312 #undef __ | 4318 #undef __ |
4313 | 4319 |
4314 } } // namespace v8::internal | 4320 } } // namespace v8::internal |
4315 | 4321 |
4316 #endif // V8_TARGET_ARCH_X64 | 4322 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |