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

Side by Side Diff: src/runtime.cc

Issue 55933002: Inline array constructor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment response, inline tracing, and making HForceRepresentation idef Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 14642 matching lines...) Expand 10 before | Expand all | Expand 10 after
14653 } else { 14653 } else {
14654 access_allowed = isolate->MayNamedAccess(*object, *key, v8::ACCESS_GET) && 14654 access_allowed = isolate->MayNamedAccess(*object, *key, v8::ACCESS_GET) &&
14655 isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS); 14655 isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS);
14656 } 14656 }
14657 return isolate->heap()->ToBoolean(access_allowed); 14657 return isolate->heap()->ToBoolean(access_allowed);
14658 } 14658 }
14659 14659
14660 14660
14661 static MaybeObject* ArrayConstructorCommon(Isolate* isolate, 14661 static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
14662 Handle<JSFunction> constructor, 14662 Handle<JSFunction> constructor,
14663 Handle<Object> type_info, 14663 Handle<AllocationSite> site,
14664 Arguments* caller_args) { 14664 Arguments* caller_args) {
14665 bool holey = false; 14665 bool holey = false;
14666 bool can_use_type_feedback = true; 14666 bool can_use_type_feedback = true;
14667 if (caller_args->length() == 1) { 14667 if (caller_args->length() == 1) {
14668 Object* argument_one = (*caller_args)[0]; 14668 Object* argument_one = (*caller_args)[0];
14669 if (argument_one->IsSmi()) { 14669 if (argument_one->IsSmi()) {
14670 int value = Smi::cast(argument_one)->value(); 14670 int value = Smi::cast(argument_one)->value();
14671 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { 14671 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) {
14672 // the array is a dictionary in this case. 14672 // the array is a dictionary in this case.
14673 can_use_type_feedback = false; 14673 can_use_type_feedback = false;
14674 } else if (value != 0) { 14674 } else if (value != 0) {
14675 holey = true; 14675 holey = true;
14676 } 14676 }
14677 } else { 14677 } else {
14678 // Non-smi length argument produces a dictionary 14678 // Non-smi length argument produces a dictionary
14679 can_use_type_feedback = false; 14679 can_use_type_feedback = false;
14680 } 14680 }
14681 } 14681 }
14682 14682
14683 JSArray* array; 14683 JSArray* array;
14684 MaybeObject* maybe_array; 14684 MaybeObject* maybe_array;
14685 if (!type_info.is_null() && 14685 if (!site.is_null() && can_use_type_feedback) {
14686 *type_info != isolate->heap()->undefined_value() &&
14687 Cell::cast(*type_info)->value()->IsAllocationSite() &&
14688 can_use_type_feedback) {
14689 Handle<Cell> cell = Handle<Cell>::cast(type_info);
14690 Handle<AllocationSite> site = Handle<AllocationSite>(
14691 AllocationSite::cast(cell->value()), isolate);
14692 ASSERT(!site->SitePointsToLiteral());
14693 ElementsKind to_kind = site->GetElementsKind(); 14686 ElementsKind to_kind = site->GetElementsKind();
14694 if (holey && !IsFastHoleyElementsKind(to_kind)) { 14687 if (holey && !IsFastHoleyElementsKind(to_kind)) {
14695 to_kind = GetHoleyElementsKind(to_kind); 14688 to_kind = GetHoleyElementsKind(to_kind);
14696 // Update the allocation site info to reflect the advice alteration. 14689 // Update the allocation site info to reflect the advice alteration.
14697 site->SetElementsKind(to_kind); 14690 site->SetElementsKind(to_kind);
14698 } 14691 }
14699 14692
14700 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( 14693 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite(
14701 *constructor, site); 14694 *constructor, site);
14702 if (!maybe_array->To(&array)) return maybe_array; 14695 if (!maybe_array->To(&array)) return maybe_array;
14703 } else { 14696 } else {
14704 maybe_array = isolate->heap()->AllocateJSObject(*constructor); 14697 maybe_array = isolate->heap()->AllocateJSObject(*constructor);
14705 if (!maybe_array->To(&array)) return maybe_array; 14698 if (!maybe_array->To(&array)) return maybe_array;
14706 // We might need to transition to holey 14699 // We might need to transition to holey
14707 ElementsKind kind = constructor->initial_map()->elements_kind(); 14700 ElementsKind kind = constructor->initial_map()->elements_kind();
14708 if (holey && !IsFastHoleyElementsKind(kind)) { 14701 if (holey && !IsFastHoleyElementsKind(kind)) {
14709 kind = GetHoleyElementsKind(kind); 14702 kind = GetHoleyElementsKind(kind);
14710 maybe_array = array->TransitionElementsKind(kind); 14703 maybe_array = array->TransitionElementsKind(kind);
14711 if (maybe_array->IsFailure()) return maybe_array; 14704 if (maybe_array->IsFailure()) return maybe_array;
14712 } 14705 }
14713 } 14706 }
14714 14707
14715 maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, 14708 maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0,
14716 DONT_INITIALIZE_ARRAY_ELEMENTS); 14709 DONT_INITIALIZE_ARRAY_ELEMENTS);
14717 if (maybe_array->IsFailure()) return maybe_array; 14710 if (maybe_array->IsFailure()) return maybe_array;
14711 ElementsKind old_kind = array->GetElementsKind();
14718 maybe_array = ArrayConstructInitializeElements(array, caller_args); 14712 maybe_array = ArrayConstructInitializeElements(array, caller_args);
14719 if (maybe_array->IsFailure()) return maybe_array; 14713 if (maybe_array->IsFailure()) return maybe_array;
14714 if (!site.is_null() &&
14715 (old_kind != array->GetElementsKind() ||
14716 !can_use_type_feedback)) {
14717 // The arguments passed in caused a transition. This kind of complexity
14718 // can't be dealt with in the inlined hydrogen array constructor case.
14719 // We must mark the allocationsite as un-inlinable.
14720 site->SetDoNotInlineCall();
14721 }
14720 return array; 14722 return array;
14721 } 14723 }
14722 14724
14723 14725
14724 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { 14726 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) {
14725 HandleScope scope(isolate); 14727 HandleScope scope(isolate);
14726 // If we get 2 arguments then they are the stub parameters (constructor, type 14728 // If we get 2 arguments then they are the stub parameters (constructor, type
14727 // info). If we get 3, then the first one is a pointer to the arguments 14729 // info). If we get 3, then the first one is a pointer to the arguments
14728 // passed by the caller. 14730 // passed by the caller.
14729 Arguments empty_args(0, NULL); 14731 Arguments empty_args(0, NULL);
14730 bool no_caller_args = args.length() == 2; 14732 bool no_caller_args = args.length() == 2;
14731 ASSERT(no_caller_args || args.length() == 3); 14733 ASSERT(no_caller_args || args.length() == 3);
14732 int parameters_start = no_caller_args ? 0 : 1; 14734 int parameters_start = no_caller_args ? 0 : 1;
14733 Arguments* caller_args = no_caller_args 14735 Arguments* caller_args = no_caller_args
14734 ? &empty_args 14736 ? &empty_args
14735 : reinterpret_cast<Arguments*>(args[0]); 14737 : reinterpret_cast<Arguments*>(args[0]);
14736 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); 14738 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start);
14737 CONVERT_ARG_HANDLE_CHECKED(Object, type_info, parameters_start + 1); 14739 CONVERT_ARG_HANDLE_CHECKED(Object, type_info, parameters_start + 1);
14738 14740
14741 Handle<AllocationSite> site;
14742 if (!type_info.is_null() &&
14743 *type_info != isolate->heap()->undefined_value() &&
14744 Cell::cast(*type_info)->value()->IsAllocationSite()) {
14745 site = Handle<AllocationSite>(
14746 AllocationSite::cast(Cell::cast(*type_info)->value()), isolate);
14747 ASSERT(!site->SitePointsToLiteral());
14748 }
14749
14739 return ArrayConstructorCommon(isolate, 14750 return ArrayConstructorCommon(isolate,
14740 constructor, 14751 constructor,
14741 type_info, 14752 site,
14742 caller_args); 14753 caller_args);
14743 } 14754 }
14744 14755
14745 14756
14746 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalArrayConstructor) { 14757 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalArrayConstructor) {
14747 HandleScope scope(isolate); 14758 HandleScope scope(isolate);
14748 Arguments empty_args(0, NULL); 14759 Arguments empty_args(0, NULL);
14749 bool no_caller_args = args.length() == 1; 14760 bool no_caller_args = args.length() == 1;
14750 ASSERT(no_caller_args || args.length() == 2); 14761 ASSERT(no_caller_args || args.length() == 2);
14751 int parameters_start = no_caller_args ? 0 : 1; 14762 int parameters_start = no_caller_args ? 0 : 1;
14752 Arguments* caller_args = no_caller_args 14763 Arguments* caller_args = no_caller_args
14753 ? &empty_args 14764 ? &empty_args
14754 : reinterpret_cast<Arguments*>(args[0]); 14765 : reinterpret_cast<Arguments*>(args[0]);
14755 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); 14766 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start);
14756 14767
14757 return ArrayConstructorCommon(isolate, 14768 return ArrayConstructorCommon(isolate,
14758 constructor, 14769 constructor,
14759 Handle<Object>::null(), 14770 Handle<AllocationSite>::null(),
14760 caller_args); 14771 caller_args);
14761 } 14772 }
14762 14773
14763 14774
14764 // ---------------------------------------------------------------------------- 14775 // ----------------------------------------------------------------------------
14765 // Implementation of Runtime 14776 // Implementation of Runtime
14766 14777
14767 #define F(name, number_of_args, result_size) \ 14778 #define F(name, number_of_args, result_size) \
14768 { Runtime::k##name, Runtime::RUNTIME, #name, \ 14779 { Runtime::k##name, Runtime::RUNTIME, #name, \
14769 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, 14780 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size },
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
14838 // Handle last resort GC and make sure to allow future allocations 14849 // Handle last resort GC and make sure to allow future allocations
14839 // to grow the heap without causing GCs (if possible). 14850 // to grow the heap without causing GCs (if possible).
14840 isolate->counters()->gc_last_resort_from_js()->Increment(); 14851 isolate->counters()->gc_last_resort_from_js()->Increment();
14841 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14852 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14842 "Runtime::PerformGC"); 14853 "Runtime::PerformGC");
14843 } 14854 }
14844 } 14855 }
14845 14856
14846 14857
14847 } } // namespace v8::internal 14858 } } // namespace v8::internal
OLDNEW
« src/objects-inl.h ('K') | « src/objects-printer.cc ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698