| 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 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 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 #if DEBUG | |
| 1481 ElementsKind constant_elements_kind = | 1480 ElementsKind constant_elements_kind = |
| 1482 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1481 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1483 #endif | 1482 bool has_constant_fast_elements = constant_elements_kind == FAST_ELEMENTS; |
| 1484 Handle<FixedArrayBase> constant_elements_values( | 1483 Handle<FixedArrayBase> constant_elements_values( |
| 1485 FixedArrayBase::cast(constant_elements->get(1))); | 1484 FixedArrayBase::cast(constant_elements->get(1))); |
| 1486 | 1485 |
| 1487 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1486 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1488 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1487 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1489 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1488 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1490 __ push(Immediate(constant_elements)); | 1489 __ push(Immediate(constant_elements)); |
| 1491 if (expr->depth() > 1) { | 1490 Heap* heap = isolate()->heap(); |
| 1491 if (has_constant_fast_elements && |
| 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); |
| 1496 FastCloneShallowArrayStub stub( |
| 1497 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1498 length); |
| 1499 __ CallStub(&stub); |
| 1500 } else if (expr->depth() > 1) { |
| 1492 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1501 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 1493 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1502 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1494 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1503 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 1495 } else { | 1504 } else { |
| 1496 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1505 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
| 1497 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | 1506 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
| 1498 FLAG_smi_only_arrays); | 1507 FLAG_smi_only_arrays); |
| 1499 if (constant_elements_values->map() == | 1508 // If the elements are already FAST_ELEMENTS, the boilerplate cannot |
| 1500 isolate()->heap()->fixed_cow_array_map()) { | 1509 // change, so it's possible to specialize the stub in advance. |
| 1501 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), | 1510 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements |
| 1502 1); | 1511 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
| 1503 } | 1512 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
| 1504 FastCloneShallowArrayStub stub( | 1513 FastCloneShallowArrayStub stub(mode, length); |
| 1505 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS, length); | |
| 1506 __ CallStub(&stub); | 1514 __ CallStub(&stub); |
| 1507 } | 1515 } |
| 1508 | 1516 |
| 1509 bool result_saved = false; // Is the result saved to the stack? | 1517 bool result_saved = false; // Is the result saved to the stack? |
| 1510 | 1518 |
| 1511 // 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 |
| 1512 // them into the newly cloned array. | 1520 // them into the newly cloned array. |
| 1513 for (int i = 0; i < length; i++) { | 1521 for (int i = 0; i < length; i++) { |
| 1514 Expression* subexpr = subexprs->at(i); | 1522 Expression* subexpr = subexprs->at(i); |
| 1515 // If the subexpression is a literal or a simple materialized literal it | 1523 // If the subexpression is a literal or a simple materialized literal it |
| (...skipping 2824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4340 *context_length = 0; | 4348 *context_length = 0; |
| 4341 return previous_; | 4349 return previous_; |
| 4342 } | 4350 } |
| 4343 | 4351 |
| 4344 | 4352 |
| 4345 #undef __ | 4353 #undef __ |
| 4346 | 4354 |
| 4347 } } // namespace v8::internal | 4355 } } // namespace v8::internal |
| 4348 | 4356 |
| 4349 #endif // V8_TARGET_ARCH_IA32 | 4357 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |