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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // a0: argc | 310 // a0: argc |
311 // a1: constructor (built-in Array function) | 311 // a1: constructor (built-in Array function) |
312 // ra: return address | 312 // ra: return address |
313 // sp[0]: last argument | 313 // sp[0]: last argument |
314 // This function is used for both construct and normal calls of Array. The only | 314 // This function is used for both construct and normal calls of Array. The only |
315 // difference between handling a construct call and a normal call is that for a | 315 // difference between handling a construct call and a normal call is that for a |
316 // construct call the constructor function in a1 needs to be preserved for | 316 // construct call the constructor function in a1 needs to be preserved for |
317 // entering the generic code. In both cases argc in a0 needs to be preserved. | 317 // entering the generic code. In both cases argc in a0 needs to be preserved. |
318 // Both registers are preserved by this code so no need to differentiate between | 318 // Both registers are preserved by this code so no need to differentiate between |
319 // construct call and normal call. | 319 // construct call and normal call. |
320 static void ArrayNativeCode(MacroAssembler* masm, | 320 void ArrayNativeCode(MacroAssembler* masm, Label* call_generic_code) { |
321 Label* call_generic_code) { | |
322 Counters* counters = masm->isolate()->counters(); | 321 Counters* counters = masm->isolate()->counters(); |
323 Label argc_one_or_more, argc_two_or_more, not_empty_array, empty_array, | 322 Label argc_one_or_more, argc_two_or_more, not_empty_array, empty_array, |
324 has_non_smi_element, finish, cant_transition_map, not_double; | 323 has_non_smi_element, finish, cant_transition_map, not_double; |
325 | 324 |
326 // Check for array construction with zero arguments or one. | 325 // Check for array construction with zero arguments or one. |
327 __ Branch(&argc_one_or_more, ne, a0, Operand(zero_reg)); | 326 __ Branch(&argc_one_or_more, ne, a0, Operand(zero_reg)); |
328 // Handle construction of an empty array. | 327 // Handle construction of an empty array. |
329 __ bind(&empty_array); | 328 __ bind(&empty_array); |
330 AllocateEmptyJSArray(masm, | 329 AllocateEmptyJSArray(masm, |
331 a1, | 330 a1, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 // Jump to the generic array code if the specialized code cannot handle | 538 // Jump to the generic array code if the specialized code cannot handle |
540 // the construction. | 539 // the construction. |
541 __ bind(&generic_array_code); | 540 __ bind(&generic_array_code); |
542 | 541 |
543 Handle<Code> array_code = | 542 Handle<Code> array_code = |
544 masm->isolate()->builtins()->ArrayCodeGeneric(); | 543 masm->isolate()->builtins()->ArrayCodeGeneric(); |
545 __ Jump(array_code, RelocInfo::CODE_TARGET); | 544 __ Jump(array_code, RelocInfo::CODE_TARGET); |
546 } | 545 } |
547 | 546 |
548 | 547 |
549 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { | 548 void Builtins::Generate_CommonArrayConstructCode(MacroAssembler* masm) { |
550 // ----------- S t a t e ------------- | 549 // ----------- S t a t e ------------- |
551 // -- a0 : number of arguments | 550 // -- a0 : number of arguments |
552 // -- a1 : constructor function | 551 // -- a1 : constructor function |
553 // -- a2 : type info cell | 552 // -- a2 : type info cell |
554 // -- ra : return address | 553 // -- ra : return address |
555 // -- sp[...]: constructor arguments | 554 // -- sp[...]: constructor arguments |
556 // ----------------------------------- | 555 // ----------------------------------- |
557 | 556 |
558 if (FLAG_debug_code) { | 557 if (FLAG_debug_code) { |
559 // The array construct code is only set for the builtin and internal | 558 // The array construct code is only set for the builtin and internal |
560 // Array functions which always have a map. | 559 // Array functions which always have a map. |
561 // Initial map for the builtin Array function should be a map. | 560 // Initial map for the builtin Array function should be a map. |
562 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); | 561 __ lw(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
563 __ And(t0, a3, Operand(kSmiTagMask)); | 562 __ And(t0, a3, Operand(kSmiTagMask)); |
564 __ Assert(ne, "Unexpected initial map for Array function (3)", | 563 __ Assert(ne, "Unexpected initial map for Array function (3)", |
565 t0, Operand(zero_reg)); | 564 t0, Operand(zero_reg)); |
566 __ GetObjectType(a3, a3, t0); | 565 __ GetObjectType(a3, a3, t0); |
567 __ Assert(eq, "Unexpected initial map for Array function (4)", | 566 __ Assert(eq, "Unexpected initial map for Array function (4)", |
568 t0, Operand(MAP_TYPE)); | 567 t0, Operand(MAP_TYPE)); |
| 568 } |
| 569 Label generic_constructor; |
| 570 // Run the native code for the Array function called as a constructor. |
| 571 ArrayNativeCode(masm, &generic_constructor); |
569 | 572 |
570 if (FLAG_optimize_constructed_arrays) { | 573 // Jump to the generic construct code in case the specialized code cannot |
571 // We should either have undefined in a2 or a valid jsglobalpropertycell | 574 // handle the construction. |
572 Label okay_here; | 575 __ bind(&generic_constructor); |
573 Handle<Object> undefined_sentinel( | 576 Handle<Code> generic_construct_stub = |
574 masm->isolate()->heap()->undefined_value(), masm->isolate()); | 577 masm->isolate()->builtins()->JSConstructStubGeneric(); |
575 Handle<Map> global_property_cell_map( | 578 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
576 masm->isolate()->heap()->global_property_cell_map()); | |
577 __ Branch(&okay_here, eq, a2, Operand(undefined_sentinel)); | |
578 __ lw(a3, FieldMemOperand(a2, 0)); | |
579 __ Assert(eq, "Expected property cell in register a3", | |
580 a3, Operand(global_property_cell_map)); | |
581 __ bind(&okay_here); | |
582 } | |
583 } | |
584 | |
585 if (FLAG_optimize_constructed_arrays) { | |
586 Label not_zero_case, not_one_case; | |
587 __ Branch(¬_zero_case, ne, a0, Operand(zero_reg)); | |
588 ArrayNoArgumentConstructorStub no_argument_stub; | |
589 __ TailCallStub(&no_argument_stub); | |
590 | |
591 __ bind(¬_zero_case); | |
592 __ Branch(¬_one_case, gt, a0, Operand(1)); | |
593 ArraySingleArgumentConstructorStub single_argument_stub; | |
594 __ TailCallStub(&single_argument_stub); | |
595 | |
596 __ bind(¬_one_case); | |
597 ArrayNArgumentsConstructorStub n_argument_stub; | |
598 __ TailCallStub(&n_argument_stub); | |
599 } else { | |
600 Label generic_constructor; | |
601 // Run the native code for the Array function called as a constructor. | |
602 ArrayNativeCode(masm, &generic_constructor); | |
603 | |
604 // Jump to the generic construct code in case the specialized code cannot | |
605 // handle the construction. | |
606 __ bind(&generic_constructor); | |
607 Handle<Code> generic_construct_stub = | |
608 masm->isolate()->builtins()->JSConstructStubGeneric(); | |
609 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); | |
610 } | |
611 } | 579 } |
612 | 580 |
613 | 581 |
614 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { | 582 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
615 // ----------- S t a t e ------------- | 583 // ----------- S t a t e ------------- |
616 // -- a0 : number of arguments | 584 // -- a0 : number of arguments |
617 // -- a1 : constructor function | 585 // -- a1 : constructor function |
618 // -- ra : return address | 586 // -- ra : return address |
619 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) | 587 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
620 // -- sp[argc * 4] : receiver | 588 // -- sp[argc * 4] : receiver |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 __ bind(&dont_adapt_arguments); | 1916 __ bind(&dont_adapt_arguments); |
1949 __ Jump(a3); | 1917 __ Jump(a3); |
1950 } | 1918 } |
1951 | 1919 |
1952 | 1920 |
1953 #undef __ | 1921 #undef __ |
1954 | 1922 |
1955 } } // namespace v8::internal | 1923 } } // namespace v8::internal |
1956 | 1924 |
1957 #endif // V8_TARGET_ARCH_MIPS | 1925 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |