| 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 14732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14743 isolate->MayNamedAccessWrapper(object, key, v8::ACCESS_HAS); | 14743 isolate->MayNamedAccessWrapper(object, key, v8::ACCESS_HAS); |
| 14744 } | 14744 } |
| 14745 return isolate->heap()->ToBoolean(access_allowed); | 14745 return isolate->heap()->ToBoolean(access_allowed); |
| 14746 } | 14746 } |
| 14747 | 14747 |
| 14748 | 14748 |
| 14749 static MaybeObject* ArrayConstructorCommon(Isolate* isolate, | 14749 static MaybeObject* ArrayConstructorCommon(Isolate* isolate, |
| 14750 Handle<JSFunction> constructor, | 14750 Handle<JSFunction> constructor, |
| 14751 Handle<AllocationSite> site, | 14751 Handle<AllocationSite> site, |
| 14752 Arguments* caller_args) { | 14752 Arguments* caller_args) { |
| 14753 Factory* factory = isolate->factory(); |
| 14754 |
| 14753 bool holey = false; | 14755 bool holey = false; |
| 14754 bool can_use_type_feedback = true; | 14756 bool can_use_type_feedback = true; |
| 14755 if (caller_args->length() == 1) { | 14757 if (caller_args->length() == 1) { |
| 14756 Object* argument_one = (*caller_args)[0]; | 14758 Handle<Object> argument_one = caller_args->at<Object>(0); |
| 14757 if (argument_one->IsSmi()) { | 14759 if (argument_one->IsSmi()) { |
| 14758 int value = Smi::cast(argument_one)->value(); | 14760 int value = Handle<Smi>::cast(argument_one)->value(); |
| 14759 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { | 14761 if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { |
| 14760 // the array is a dictionary in this case. | 14762 // the array is a dictionary in this case. |
| 14761 can_use_type_feedback = false; | 14763 can_use_type_feedback = false; |
| 14762 } else if (value != 0) { | 14764 } else if (value != 0) { |
| 14763 holey = true; | 14765 holey = true; |
| 14764 } | 14766 } |
| 14765 } else { | 14767 } else { |
| 14766 // Non-smi length argument produces a dictionary | 14768 // Non-smi length argument produces a dictionary |
| 14767 can_use_type_feedback = false; | 14769 can_use_type_feedback = false; |
| 14768 } | 14770 } |
| 14769 } | 14771 } |
| 14770 | 14772 |
| 14771 JSArray* array; | 14773 Handle<JSArray> array; |
| 14772 MaybeObject* maybe_array; | |
| 14773 if (!site.is_null() && can_use_type_feedback) { | 14774 if (!site.is_null() && can_use_type_feedback) { |
| 14774 ElementsKind to_kind = site->GetElementsKind(); | 14775 ElementsKind to_kind = site->GetElementsKind(); |
| 14775 if (holey && !IsFastHoleyElementsKind(to_kind)) { | 14776 if (holey && !IsFastHoleyElementsKind(to_kind)) { |
| 14776 to_kind = GetHoleyElementsKind(to_kind); | 14777 to_kind = GetHoleyElementsKind(to_kind); |
| 14777 // Update the allocation site info to reflect the advice alteration. | 14778 // Update the allocation site info to reflect the advice alteration. |
| 14778 site->SetElementsKind(to_kind); | 14779 site->SetElementsKind(to_kind); |
| 14779 } | 14780 } |
| 14780 | 14781 |
| 14781 // We should allocate with an initial map that reflects the allocation site | 14782 // We should allocate with an initial map that reflects the allocation site |
| 14782 // advice. Therefore we use AllocateJSObjectFromMap instead of passing | 14783 // advice. Therefore we use AllocateJSObjectFromMap instead of passing |
| 14783 // the constructor. | 14784 // the constructor. |
| 14784 Map* initial_map = constructor->initial_map(); | 14785 Handle<Map> initial_map(constructor->initial_map(), isolate); |
| 14785 if (to_kind != initial_map->elements_kind()) { | 14786 if (to_kind != initial_map->elements_kind()) { |
| 14786 MaybeObject* maybe_new_map = initial_map->AsElementsKind(to_kind); | 14787 initial_map = Map::AsElementsKind(initial_map, to_kind); |
| 14787 if (!maybe_new_map->To(&initial_map)) return maybe_new_map; | 14788 RETURN_IF_EMPTY_HANDLE(isolate, initial_map); |
| 14788 } | 14789 } |
| 14789 | 14790 |
| 14790 // If we don't care to track arrays of to_kind ElementsKind, then | 14791 // If we don't care to track arrays of to_kind ElementsKind, then |
| 14791 // don't emit a memento for them. | 14792 // don't emit a memento for them. |
| 14792 AllocationSite* allocation_site = | 14793 Handle<AllocationSite> allocation_site; |
| 14793 (AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE) | 14794 if (AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE) { |
| 14794 ? *site | 14795 allocation_site = site; |
| 14795 : NULL; | 14796 } |
| 14796 | 14797 |
| 14797 maybe_array = isolate->heap()->AllocateJSObjectFromMap(initial_map, | 14798 array = Handle<JSArray>::cast(factory->NewJSObjectFromMap( |
| 14798 NOT_TENURED, | 14799 initial_map, NOT_TENURED, true, allocation_site)); |
| 14799 true, | |
| 14800 allocation_site); | |
| 14801 if (!maybe_array->To(&array)) return maybe_array; | |
| 14802 } else { | 14800 } else { |
| 14803 maybe_array = isolate->heap()->AllocateJSObject(*constructor); | 14801 array = Handle<JSArray>::cast(factory->NewJSObject(constructor)); |
| 14804 if (!maybe_array->To(&array)) return maybe_array; | 14802 |
| 14805 // We might need to transition to holey | 14803 // We might need to transition to holey |
| 14806 ElementsKind kind = constructor->initial_map()->elements_kind(); | 14804 ElementsKind kind = constructor->initial_map()->elements_kind(); |
| 14807 if (holey && !IsFastHoleyElementsKind(kind)) { | 14805 if (holey && !IsFastHoleyElementsKind(kind)) { |
| 14808 kind = GetHoleyElementsKind(kind); | 14806 kind = GetHoleyElementsKind(kind); |
| 14809 maybe_array = array->TransitionElementsKind(kind); | 14807 JSObject::TransitionElementsKind(array, kind); |
| 14810 if (maybe_array->IsFailure()) return maybe_array; | |
| 14811 } | 14808 } |
| 14812 } | 14809 } |
| 14813 | 14810 |
| 14814 maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, | 14811 factory->NewJSArrayStorage(array, 0, 0, DONT_INITIALIZE_ARRAY_ELEMENTS); |
| 14815 DONT_INITIALIZE_ARRAY_ELEMENTS); | 14812 |
| 14816 if (maybe_array->IsFailure()) return maybe_array; | |
| 14817 ElementsKind old_kind = array->GetElementsKind(); | 14813 ElementsKind old_kind = array->GetElementsKind(); |
| 14818 maybe_array = ArrayConstructInitializeElements(array, caller_args); | 14814 RETURN_IF_EMPTY_HANDLE(isolate, |
| 14819 if (maybe_array->IsFailure()) return maybe_array; | 14815 ArrayConstructInitializeElements(array, caller_args)); |
| 14820 if (!site.is_null() && | 14816 if (!site.is_null() && |
| 14821 (old_kind != array->GetElementsKind() || | 14817 (old_kind != array->GetElementsKind() || |
| 14822 !can_use_type_feedback)) { | 14818 !can_use_type_feedback)) { |
| 14823 // The arguments passed in caused a transition. This kind of complexity | 14819 // The arguments passed in caused a transition. This kind of complexity |
| 14824 // can't be dealt with in the inlined hydrogen array constructor case. | 14820 // can't be dealt with in the inlined hydrogen array constructor case. |
| 14825 // We must mark the allocationsite as un-inlinable. | 14821 // We must mark the allocationsite as un-inlinable. |
| 14826 site->SetDoNotInlineCall(); | 14822 site->SetDoNotInlineCall(); |
| 14827 } | 14823 } |
| 14828 return array; | 14824 return *array; |
| 14829 } | 14825 } |
| 14830 | 14826 |
| 14831 | 14827 |
| 14832 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { | 14828 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) { |
| 14833 HandleScope scope(isolate); | 14829 HandleScope scope(isolate); |
| 14834 // If we get 2 arguments then they are the stub parameters (constructor, type | 14830 // If we get 2 arguments then they are the stub parameters (constructor, type |
| 14835 // info). If we get 4, then the first one is a pointer to the arguments | 14831 // info). If we get 4, then the first one is a pointer to the arguments |
| 14836 // passed by the caller, and the last one is the length of the arguments | 14832 // passed by the caller, and the last one is the length of the arguments |
| 14837 // passed to the caller (redundant, but useful to check on the deoptimizer | 14833 // passed to the caller (redundant, but useful to check on the deoptimizer |
| 14838 // with an assert). | 14834 // with an assert). |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14974 // Handle last resort GC and make sure to allow future allocations | 14970 // Handle last resort GC and make sure to allow future allocations |
| 14975 // to grow the heap without causing GCs (if possible). | 14971 // to grow the heap without causing GCs (if possible). |
| 14976 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14972 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14977 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14973 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14978 "Runtime::PerformGC"); | 14974 "Runtime::PerformGC"); |
| 14979 } | 14975 } |
| 14980 } | 14976 } |
| 14981 | 14977 |
| 14982 | 14978 |
| 14983 } } // namespace v8::internal | 14979 } } // namespace v8::internal |
| OLD | NEW |