Chromium Code Reviews| 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 14646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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<Object> type_info, |
| 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 Handle<AllocationSite> site; | |
|
Toon Verwaest
2013/11/06 16:42:44
Can we just declare it below, right above the if w
mvstanton
2013/11/07 16:34:05
Done.
| |
| 14667 if (caller_args->length() == 1) { | 14668 if (caller_args->length() == 1) { |
| 14668 Object* argument_one = (*caller_args)[0]; | 14669 Object* argument_one = (*caller_args)[0]; |
| 14669 if (argument_one->IsSmi()) { | 14670 if (argument_one->IsSmi()) { |
| 14670 int value = Smi::cast(argument_one)->value(); | 14671 int value = Smi::cast(argument_one)->value(); |
| 14671 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { | 14672 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { |
| 14672 // the array is a dictionary in this case. | 14673 // the array is a dictionary in this case. |
| 14673 can_use_type_feedback = false; | 14674 can_use_type_feedback = false; |
| 14674 } else if (value != 0) { | 14675 } else if (value != 0) { |
| 14675 holey = true; | 14676 holey = true; |
| 14676 } | 14677 } |
| 14677 } else { | 14678 } else { |
| 14678 // Non-smi length argument produces a dictionary | 14679 // Non-smi length argument produces a dictionary |
| 14679 can_use_type_feedback = false; | 14680 can_use_type_feedback = false; |
| 14680 } | 14681 } |
| 14681 } | 14682 } |
| 14682 | 14683 |
| 14684 if (!type_info.is_null() && | |
| 14685 *type_info != isolate->heap()->undefined_value() && | |
| 14686 Cell::cast(*type_info)->value()->IsAllocationSite()) { | |
| 14687 site = Handle<AllocationSite>( | |
| 14688 AllocationSite::cast(Cell::cast(*type_info)->value()), isolate); | |
| 14689 } | |
| 14690 | |
| 14691 if (!site.is_null() && !can_use_type_feedback) { | |
|
Toon Verwaest
2013/11/06 16:42:44
I find all these !site.is_null() a bit hard to rea
mvstanton
2013/11/07 16:34:05
I pulled out turning the type_info into an allocat
| |
| 14692 // Mark the allocation site as un-inlinable. | |
| 14693 site->SetDoNotInlineCall(); | |
| 14694 } | |
| 14695 | |
| 14683 JSArray* array; | 14696 JSArray* array; |
| 14684 MaybeObject* maybe_array; | 14697 MaybeObject* maybe_array; |
| 14685 if (!type_info.is_null() && | 14698 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()); | 14699 ASSERT(!site->SitePointsToLiteral()); |
| 14693 ElementsKind to_kind = site->GetElementsKind(); | 14700 ElementsKind to_kind = site->GetElementsKind(); |
| 14694 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14701 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 14695 to_kind = GetHoleyElementsKind(to_kind); | 14702 to_kind = GetHoleyElementsKind(to_kind); |
| 14696 // Update the allocation site info to reflect the advice alteration. | 14703 // Update the allocation site info to reflect the advice alteration. |
| 14697 site->SetElementsKind(to_kind); | 14704 site->SetElementsKind(to_kind); |
| 14698 } | 14705 } |
| 14699 | 14706 |
| 14700 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( | 14707 maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite( |
| 14701 *constructor, site); | 14708 *constructor, site); |
| 14702 if (!maybe_array->To(&array)) return maybe_array; | 14709 if (!maybe_array->To(&array)) return maybe_array; |
| 14703 } else { | 14710 } else { |
| 14704 maybe_array = isolate->heap()->AllocateJSObject(*constructor); | 14711 maybe_array = isolate->heap()->AllocateJSObject(*constructor); |
| 14705 if (!maybe_array->To(&array)) return maybe_array; | 14712 if (!maybe_array->To(&array)) return maybe_array; |
| 14706 // We might need to transition to holey | 14713 // We might need to transition to holey |
| 14707 ElementsKind kind = constructor->initial_map()->elements_kind(); | 14714 ElementsKind kind = constructor->initial_map()->elements_kind(); |
| 14708 if (holey && !IsFastHoleyElementsKind(kind)) { | 14715 if (holey && !IsFastHoleyElementsKind(kind)) { |
| 14709 kind = GetHoleyElementsKind(kind); | 14716 kind = GetHoleyElementsKind(kind); |
| 14710 maybe_array = array->TransitionElementsKind(kind); | 14717 maybe_array = array->TransitionElementsKind(kind); |
| 14711 if (maybe_array->IsFailure()) return maybe_array; | 14718 if (maybe_array->IsFailure()) return maybe_array; |
| 14712 } | 14719 } |
| 14713 } | 14720 } |
| 14714 | 14721 |
| 14715 maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, | 14722 maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, |
| 14716 DONT_INITIALIZE_ARRAY_ELEMENTS); | 14723 DONT_INITIALIZE_ARRAY_ELEMENTS); |
| 14717 if (maybe_array->IsFailure()) return maybe_array; | 14724 if (maybe_array->IsFailure()) return maybe_array; |
| 14725 ElementsKind old_kind = array->GetElementsKind(); | |
| 14718 maybe_array = ArrayConstructInitializeElements(array, caller_args); | 14726 maybe_array = ArrayConstructInitializeElements(array, caller_args); |
| 14719 if (maybe_array->IsFailure()) return maybe_array; | 14727 if (maybe_array->IsFailure()) return maybe_array; |
| 14728 if (old_kind != array->GetElementsKind() && !site.is_null()) { | |
| 14729 // The arguments passed in caused a transition. This kind of complexity | |
| 14730 // can't be dealt with in the inlined hydrogen array constructor case. | |
| 14731 // We must mark the allocationsite as un-inlinable. | |
| 14732 site->SetDoNotInlineCall(); | |
| 14733 } | |
| 14720 return array; | 14734 return array; |
| 14721 } | 14735 } |
| 14722 | 14736 |
| 14723 | 14737 |
| 14724 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { | 14738 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { |
| 14725 HandleScope scope(isolate); | 14739 HandleScope scope(isolate); |
| 14726 // If we get 2 arguments then they are the stub parameters (constructor, type | 14740 // 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 | 14741 // info). If we get 3, then the first one is a pointer to the arguments |
| 14728 // passed by the caller. | 14742 // passed by the caller. |
| 14729 Arguments empty_args(0, NULL); | 14743 Arguments empty_args(0, NULL); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14838 // Handle last resort GC and make sure to allow future allocations | 14852 // Handle last resort GC and make sure to allow future allocations |
| 14839 // to grow the heap without causing GCs (if possible). | 14853 // to grow the heap without causing GCs (if possible). |
| 14840 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14854 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14841 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14855 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14842 "Runtime::PerformGC"); | 14856 "Runtime::PerformGC"); |
| 14843 } | 14857 } |
| 14844 } | 14858 } |
| 14845 | 14859 |
| 14846 | 14860 |
| 14847 } } // namespace v8::internal | 14861 } } // namespace v8::internal |
| OLD | NEW |