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