Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: src/runtime/runtime-scopes.cc

Issue 1676883002: [runtime] Optimize and unify rest parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/ast/scopeinfo.h" 9 #include "src/ast/scopeinfo.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); 581 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc);
582 for (int i = 0; i < argument_count; i++) { 582 for (int i = 0; i < argument_count; i++) {
583 array->set(i, parameters[i], mode); 583 array->set(i, parameters[i], mode);
584 } 584 }
585 result->set_elements(*array); 585 result->set_elements(*array);
586 } 586 }
587 return result; 587 return result;
588 } 588 }
589 589
590 590
591 template <typename T>
592 Handle<JSObject> NewRestArguments(Isolate* isolate, Handle<JSFunction> callee,
593 T parameters, int argument_count,
594 int start_index) {
595 int num_elements = std::max(0, argument_count - start_index);
596 Handle<JSObject> result = isolate->factory()->NewJSArray(
597 FAST_ELEMENTS, num_elements, num_elements, Strength::WEAK,
598 DONT_INITIALIZE_ARRAY_ELEMENTS);
599 {
600 DisallowHeapAllocation no_gc;
601 FixedArray* elements = FixedArray::cast(result->elements());
602 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
603 for (int i = 0; i < num_elements; i++) {
604 elements->set(i, parameters[i + start_index], mode);
605 }
606 }
607 return result;
608 }
609
610
611 class HandleArguments BASE_EMBEDDED { 591 class HandleArguments BASE_EMBEDDED {
612 public: 592 public:
613 explicit HandleArguments(Handle<Object>* array) : array_(array) {} 593 explicit HandleArguments(Handle<Object>* array) : array_(array) {}
614 Object* operator[](int index) { return *array_[index]; } 594 Object* operator[](int index) { return *array_[index]; }
615 595
616 private: 596 private:
617 Handle<Object>* array_; 597 Handle<Object>* array_;
618 }; 598 };
619 599
620 600
(...skipping 30 matching lines...) Expand all
651 // This generic runtime function can also be used when the caller has been 631 // This generic runtime function can also be used when the caller has been
652 // inlined, we use the slow but accurate {GetCallerArguments}. 632 // inlined, we use the slow but accurate {GetCallerArguments}.
653 int argument_count = 0; 633 int argument_count = 0;
654 base::SmartArrayPointer<Handle<Object>> arguments = 634 base::SmartArrayPointer<Handle<Object>> arguments =
655 GetCallerArguments(isolate, &argument_count); 635 GetCallerArguments(isolate, &argument_count);
656 HandleArguments argument_getter(arguments.get()); 636 HandleArguments argument_getter(arguments.get());
657 return *NewStrictArguments(isolate, callee, argument_getter, argument_count); 637 return *NewStrictArguments(isolate, callee, argument_getter, argument_count);
658 } 638 }
659 639
660 640
661 RUNTIME_FUNCTION(Runtime_NewRestArguments_Generic) { 641 RUNTIME_FUNCTION(Runtime_NewRestParameter) {
662 HandleScope scope(isolate); 642 HandleScope scope(isolate);
663 DCHECK(args.length() == 2); 643 DCHECK_EQ(1, args.length());
664 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0) 644 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0)
665 CONVERT_SMI_ARG_CHECKED(start_index, 1); 645 int start_index = callee->shared()->internal_formal_parameter_count();
666 // This generic runtime function can also be used when the caller has been 646 // This generic runtime function can also be used when the caller has been
667 // inlined, we use the slow but accurate {GetCallerArguments}. 647 // inlined, we use the slow but accurate {GetCallerArguments}.
668 int argument_count = 0; 648 int argument_count = 0;
669 base::SmartArrayPointer<Handle<Object>> arguments = 649 base::SmartArrayPointer<Handle<Object>> arguments =
670 GetCallerArguments(isolate, &argument_count); 650 GetCallerArguments(isolate, &argument_count);
671 HandleArguments argument_getter(arguments.get()); 651 int num_elements = std::max(0, argument_count - start_index);
672 return *NewRestArguments(isolate, callee, argument_getter, argument_count, 652 Handle<JSObject> result = isolate->factory()->NewJSArray(
673 start_index); 653 FAST_ELEMENTS, num_elements, num_elements, Strength::WEAK,
654 DONT_INITIALIZE_ARRAY_ELEMENTS);
655 {
656 DisallowHeapAllocation no_gc;
657 FixedArray* elements = FixedArray::cast(result->elements());
658 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
659 for (int i = 0; i < num_elements; i++) {
660 elements->set(i, *arguments[i + start_index], mode);
661 }
662 }
663 return *result;
674 } 664 }
675 665
676 666
677 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { 667 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) {
678 HandleScope scope(isolate); 668 HandleScope scope(isolate);
679 DCHECK(args.length() == 3); 669 DCHECK(args.length() == 3);
680 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 670 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
681 Object** parameters = reinterpret_cast<Object**>(args[1]); 671 Object** parameters = reinterpret_cast<Object**>(args[1]);
682 CONVERT_SMI_ARG_CHECKED(argument_count, 2); 672 CONVERT_SMI_ARG_CHECKED(argument_count, 2);
683 #ifdef DEBUG 673 #ifdef DEBUG
(...skipping 17 matching lines...) Expand all
701 // This runtime function does not materialize the correct arguments when the 691 // This runtime function does not materialize the correct arguments when the
702 // caller has been inlined, better make sure we are not hitting that case. 692 // caller has been inlined, better make sure we are not hitting that case.
703 JavaScriptFrameIterator it(isolate); 693 JavaScriptFrameIterator it(isolate);
704 DCHECK(!it.frame()->HasInlinedFrames()); 694 DCHECK(!it.frame()->HasInlinedFrames());
705 #endif // DEBUG 695 #endif // DEBUG
706 ParameterArguments argument_getter(parameters); 696 ParameterArguments argument_getter(parameters);
707 return *NewStrictArguments(isolate, callee, argument_getter, argument_count); 697 return *NewStrictArguments(isolate, callee, argument_getter, argument_count);
708 } 698 }
709 699
710 700
711 RUNTIME_FUNCTION(Runtime_NewRestParam) {
712 HandleScope scope(isolate);
713 DCHECK(args.length() == 3);
714 CONVERT_SMI_ARG_CHECKED(num_params, 0);
715 Object** parameters = reinterpret_cast<Object**>(args[1]);
716 CONVERT_SMI_ARG_CHECKED(rest_index, 2);
717 #ifdef DEBUG
718 // This runtime function does not materialize the correct arguments when the
719 // caller has been inlined, better make sure we are not hitting that case.
720 JavaScriptFrameIterator it(isolate);
721 DCHECK(!it.frame()->HasInlinedFrames());
722 #endif // DEBUG
723 Handle<JSFunction> callee;
724 ParameterArguments argument_getter(parameters);
725 return *NewRestArguments(isolate, callee, argument_getter, num_params,
726 rest_index);
727 }
728
729
730 RUNTIME_FUNCTION(Runtime_NewClosure) { 701 RUNTIME_FUNCTION(Runtime_NewClosure) {
731 HandleScope scope(isolate); 702 HandleScope scope(isolate);
732 DCHECK_EQ(1, args.length()); 703 DCHECK_EQ(1, args.length());
733 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); 704 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0);
734 Handle<Context> context(isolate->context(), isolate); 705 Handle<Context> context(isolate->context(), isolate);
735 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, 706 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context,
736 NOT_TENURED); 707 NOT_TENURED);
737 } 708 }
738 709
739 710
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 1223
1253 // Lookup in the initial Object.prototype object. 1224 // Lookup in the initial Object.prototype object.
1254 Handle<Object> result; 1225 Handle<Object> result;
1255 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1226 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1256 isolate, result, 1227 isolate, result,
1257 Object::GetProperty(isolate->initial_object_prototype(), key)); 1228 Object::GetProperty(isolate->initial_object_prototype(), key));
1258 return *result; 1229 return *result;
1259 } 1230 }
1260 } // namespace internal 1231 } // namespace internal
1261 } // namespace v8 1232 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698