| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 // rdi: constructor (built-in Array function) | 1280 // rdi: constructor (built-in Array function) |
| 1281 // rax: argc | 1281 // rax: argc |
| 1282 // rsp[0]: return address | 1282 // rsp[0]: return address |
| 1283 // rsp[8]: last argument | 1283 // rsp[8]: last argument |
| 1284 // This function is used for both construct and normal calls of Array. The only | 1284 // This function is used for both construct and normal calls of Array. The only |
| 1285 // difference between handling a construct call and a normal call is that for a | 1285 // difference between handling a construct call and a normal call is that for a |
| 1286 // construct call the constructor function in rdi needs to be preserved for | 1286 // construct call the constructor function in rdi needs to be preserved for |
| 1287 // entering the generic code. In both cases argc in rax needs to be preserved. | 1287 // entering the generic code. In both cases argc in rax needs to be preserved. |
| 1288 // Both registers are preserved by this code so no need to differentiate between | 1288 // Both registers are preserved by this code so no need to differentiate between |
| 1289 // a construct call and a normal call. | 1289 // a construct call and a normal call. |
| 1290 static void ArrayNativeCode(MacroAssembler* masm, | 1290 void ArrayNativeCode(MacroAssembler* masm, Label* call_generic_code) { |
| 1291 Label* call_generic_code) { | |
| 1292 Label argc_one_or_more, argc_two_or_more, empty_array, not_empty_array, | 1291 Label argc_one_or_more, argc_two_or_more, empty_array, not_empty_array, |
| 1293 has_non_smi_element, finish, cant_transition_map, not_double; | 1292 has_non_smi_element, finish, cant_transition_map, not_double; |
| 1294 | 1293 |
| 1295 // Check for array construction with zero arguments. | 1294 // Check for array construction with zero arguments. |
| 1296 __ testq(rax, rax); | 1295 __ testq(rax, rax); |
| 1297 __ j(not_zero, &argc_one_or_more); | 1296 __ j(not_zero, &argc_one_or_more); |
| 1298 | 1297 |
| 1299 __ bind(&empty_array); | 1298 __ bind(&empty_array); |
| 1300 // Handle construction of an empty array. | 1299 // Handle construction of an empty array. |
| 1301 AllocateEmptyJSArray(masm, | 1300 AllocateEmptyJSArray(masm, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 | 1514 |
| 1516 // Jump to the generic array code in case the specialized code cannot handle | 1515 // Jump to the generic array code in case the specialized code cannot handle |
| 1517 // the construction. | 1516 // the construction. |
| 1518 __ bind(&generic_array_code); | 1517 __ bind(&generic_array_code); |
| 1519 Handle<Code> array_code = | 1518 Handle<Code> array_code = |
| 1520 masm->isolate()->builtins()->ArrayCodeGeneric(); | 1519 masm->isolate()->builtins()->ArrayCodeGeneric(); |
| 1521 __ Jump(array_code, RelocInfo::CODE_TARGET); | 1520 __ Jump(array_code, RelocInfo::CODE_TARGET); |
| 1522 } | 1521 } |
| 1523 | 1522 |
| 1524 | 1523 |
| 1525 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { | 1524 void Builtins::Generate_CommonArrayConstructCode(MacroAssembler* masm) { |
| 1526 // ----------- S t a t e ------------- | 1525 // ----------- S t a t e ------------- |
| 1527 // -- rax : argc | 1526 // -- rax : argc |
| 1528 // -- rdi : constructor | 1527 // -- rdi : constructor |
| 1529 // -- rsp[0] : return address | 1528 // -- rsp[0] : return address |
| 1530 // -- rsp[8] : last argument | 1529 // -- rsp[8] : last argument |
| 1531 // ----------------------------------- | 1530 // ----------------------------------- |
| 1532 if (FLAG_debug_code) { | 1531 if (FLAG_debug_code) { |
| 1533 // The array construct code is only set for the builtin and internal | 1532 // The array construct code is only set for the builtin and internal |
| 1534 // Array functions which always have a map. | 1533 // Array functions which always have a map. |
| 1535 | 1534 |
| 1536 // Initial map for the builtin Array function should be a map. | 1535 // Initial map for the builtin Array function should be a map. |
| 1537 __ movq(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | 1536 __ movq(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1538 // Will both indicate a NULL and a Smi. | 1537 // Will both indicate a NULL and a Smi. |
| 1539 STATIC_ASSERT(kSmiTag == 0); | 1538 STATIC_ASSERT(kSmiTag == 0); |
| 1540 Condition not_smi = NegateCondition(masm->CheckSmi(rcx)); | 1539 Condition not_smi = NegateCondition(masm->CheckSmi(rcx)); |
| 1541 __ Check(not_smi, "Unexpected initial map for Array function"); | 1540 __ Check(not_smi, "Unexpected initial map for Array function"); |
| 1542 __ CmpObjectType(rcx, MAP_TYPE, rcx); | 1541 __ CmpObjectType(rcx, MAP_TYPE, rcx); |
| 1543 __ Check(equal, "Unexpected initial map for Array function"); | 1542 __ Check(equal, "Unexpected initial map for Array function"); |
| 1544 | |
| 1545 if (FLAG_optimize_constructed_arrays) { | |
| 1546 // We should either have undefined in ebx or a valid jsglobalpropertycell | |
| 1547 Label okay_here; | |
| 1548 Handle<Object> undefined_sentinel( | |
| 1549 masm->isolate()->factory()->undefined_value()); | |
| 1550 Handle<Map> global_property_cell_map( | |
| 1551 masm->isolate()->heap()->global_property_cell_map()); | |
| 1552 __ Cmp(rbx, undefined_sentinel); | |
| 1553 __ j(equal, &okay_here); | |
| 1554 __ Cmp(FieldOperand(rbx, 0), global_property_cell_map); | |
| 1555 __ Assert(equal, "Expected property cell in register rbx"); | |
| 1556 __ bind(&okay_here); | |
| 1557 } | |
| 1558 } | 1543 } |
| 1559 | 1544 |
| 1560 if (FLAG_optimize_constructed_arrays) { | 1545 Label generic_constructor; |
| 1561 Label not_zero_case, not_one_case; | 1546 // Run the native code for the Array function called as constructor. |
| 1562 __ testq(rax, rax); | 1547 ArrayNativeCode(masm, &generic_constructor); |
| 1563 __ j(not_zero, ¬_zero_case); | 1548 // Jump to the generic construct code in case the specialized code cannot |
| 1564 ArrayNoArgumentConstructorStub no_argument_stub; | 1549 // handle the construction. |
| 1565 __ TailCallStub(&no_argument_stub); | 1550 __ bind(&generic_constructor); |
| 1551 Handle<Code> generic_construct_stub = |
| 1552 masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 1553 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 1554 } |
| 1566 | 1555 |
| 1567 __ bind(¬_zero_case); | |
| 1568 __ cmpq(rax, Immediate(1)); | |
| 1569 __ j(greater, ¬_one_case); | |
| 1570 ArraySingleArgumentConstructorStub single_argument_stub; | |
| 1571 __ TailCallStub(&single_argument_stub); | |
| 1572 | |
| 1573 __ bind(¬_one_case); | |
| 1574 ArrayNArgumentsConstructorStub n_argument_stub; | |
| 1575 __ TailCallStub(&n_argument_stub); | |
| 1576 } else { | |
| 1577 Label generic_constructor; | |
| 1578 // Run the native code for the Array function called as constructor. | |
| 1579 ArrayNativeCode(masm, &generic_constructor); | |
| 1580 | |
| 1581 // Jump to the generic construct code in case the specialized code cannot | |
| 1582 // handle the construction. | |
| 1583 __ bind(&generic_constructor); | |
| 1584 Handle<Code> generic_construct_stub = | |
| 1585 masm->isolate()->builtins()->JSConstructStubGeneric(); | |
| 1586 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); | |
| 1587 } | |
| 1588 } | |
| 1589 | 1556 |
| 1590 | 1557 |
| 1591 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { | 1558 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
| 1592 // ----------- S t a t e ------------- | 1559 // ----------- S t a t e ------------- |
| 1593 // -- rax : number of arguments | 1560 // -- rax : number of arguments |
| 1594 // -- rdi : constructor function | 1561 // -- rdi : constructor function |
| 1595 // -- rsp[0] : return address | 1562 // -- rsp[0] : return address |
| 1596 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) | 1563 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) |
| 1597 // -- rsp[(argc + 1) * 8] : receiver | 1564 // -- rsp[(argc + 1) * 8] : receiver |
| 1598 // ----------------------------------- | 1565 // ----------------------------------- |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); | 1831 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); |
| 1865 generator.Generate(); | 1832 generator.Generate(); |
| 1866 } | 1833 } |
| 1867 | 1834 |
| 1868 | 1835 |
| 1869 #undef __ | 1836 #undef __ |
| 1870 | 1837 |
| 1871 } } // namespace v8::internal | 1838 } } // namespace v8::internal |
| 1872 | 1839 |
| 1873 #endif // V8_TARGET_ARCH_X64 | 1840 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |