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

Side by Side Diff: src/elements.cc

Issue 11818021: Allocation Info Tracking, continued. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: A partial delta against Toon's previous review Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/builtins.cc ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 JSArray* array, Arguments* args) { 1978 JSArray* array, Arguments* args) {
1979 Heap* heap = array->GetIsolate()->heap(); 1979 Heap* heap = array->GetIsolate()->heap();
1980 1980
1981 // Optimize the case where there is one argument and the argument is a 1981 // Optimize the case where there is one argument and the argument is a
1982 // small smi. 1982 // small smi.
1983 if (args->length() == 1) { 1983 if (args->length() == 1) {
1984 Object* obj = (*args)[0]; 1984 Object* obj = (*args)[0];
1985 if (obj->IsSmi()) { 1985 if (obj->IsSmi()) {
1986 int len = Smi::cast(obj)->value(); 1986 int len = Smi::cast(obj)->value();
1987 if (len > 0 && len < JSObject::kInitialMaxFastElementArray) { 1987 if (len > 0 && len < JSObject::kInitialMaxFastElementArray) {
1988 FixedArrayBase* fixed_array;
1989 ElementsKind elements_kind = array->GetElementsKind(); 1988 ElementsKind elements_kind = array->GetElementsKind();
1990 { 1989 MaybeObject* maybe_array = array->Initialize(len, len);
1991 MaybeObject* maybe_obj; 1990 if (maybe_array->IsFailure()) return maybe_array;
1992 if (IsFastDoubleElementsKind(elements_kind)) { 1991
1993 maybe_obj = heap->AllocateFixedDoubleArrayWithHoles(len);
1994 } else {
1995 maybe_obj = heap->AllocateFixedArrayWithHoles(len);
1996 }
1997 if (!maybe_obj->To(&fixed_array)) return maybe_obj;
1998 }
1999 if (!IsFastHoleyElementsKind(elements_kind)) { 1992 if (!IsFastHoleyElementsKind(elements_kind)) {
2000 elements_kind = GetHoleyElementsKind(elements_kind); 1993 elements_kind = GetHoleyElementsKind(elements_kind);
2001 MaybeObject* maybe_array = 1994 maybe_array = array->TransitionElementsKind(elements_kind);
2002 array->TransitionElementsKind(elements_kind);
2003 if (maybe_array->IsFailure()) return maybe_array; 1995 if (maybe_array->IsFailure()) return maybe_array;
2004 } 1996 }
2005 // We do not use SetContent to skip the unnecessary elements type check. 1997
2006 array->set_elements(fixed_array);
2007 array->set_length(Smi::cast(obj));
2008 return array; 1998 return array;
2009 } else if (len == 0) { 1999 } else if (len == 0) {
2010 return array->Initialize(JSArray::kPreallocatedArrayElements); 2000 return array->Initialize(JSArray::kPreallocatedArrayElements);
2011 } 2001 }
2012 } 2002 }
2003
2013 // Take the argument as the length. 2004 // Take the argument as the length.
2014 { MaybeObject* maybe_obj = array->Initialize(0); 2005 MaybeObject* maybe_obj = array->Initialize(0);
2015 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 2006 if (!maybe_obj->To(&obj)) return maybe_obj;
2016 } 2007
2017 return array->SetElementsLength((*args)[0]); 2008 return array->SetElementsLength((*args)[0]);
2018 } 2009 }
2019 2010
2020 // Optimize the case where there are no parameters passed. 2011 // Optimize the case where there are no parameters passed.
2021 if (args->length() == 0) { 2012 if (args->length() == 0) {
2022 return array->Initialize(JSArray::kPreallocatedArrayElements); 2013 return array->Initialize(JSArray::kPreallocatedArrayElements);
2023 } 2014 }
2024 2015
2025 // Set length and elements on the array. 2016 // Set length and elements on the array.
2026 int number_of_elements = args->length(); 2017 int number_of_elements = args->length();
2027 MaybeObject* maybe_object = 2018 MaybeObject* maybe_object =
2028 array->EnsureCanContainElements(args, 0, number_of_elements, 2019 array->EnsureCanContainElements(args, 0, number_of_elements,
2029 ALLOW_CONVERTED_DOUBLE_ELEMENTS); 2020 ALLOW_CONVERTED_DOUBLE_ELEMENTS);
2030 if (maybe_object->IsFailure()) return maybe_object; 2021 if (maybe_object->IsFailure()) return maybe_object;
2031 2022
2032
2033 // Allocate an appropriately typed elements array. 2023 // Allocate an appropriately typed elements array.
2034 MaybeObject* maybe_elms; 2024 MaybeObject* maybe_elms;
2035 ElementsKind elements_kind = array->GetElementsKind(); 2025 ElementsKind elements_kind = array->GetElementsKind();
2036 if (IsFastDoubleElementsKind(elements_kind)) { 2026 if (IsFastDoubleElementsKind(elements_kind)) {
2037 maybe_elms = heap->AllocateUninitializedFixedDoubleArray( 2027 maybe_elms = heap->AllocateUninitializedFixedDoubleArray(
2038 number_of_elements); 2028 number_of_elements);
2039 } else { 2029 } else {
2040 maybe_elms = heap->AllocateFixedArrayWithHoles(number_of_elements); 2030 maybe_elms = heap->AllocateFixedArrayWithHoles(number_of_elements);
2041 } 2031 }
2042 FixedArrayBase* elms; 2032 FixedArrayBase* elms;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 UNREACHABLE(); 2064 UNREACHABLE();
2075 break; 2065 break;
2076 } 2066 }
2077 2067
2078 array->set_elements(elms); 2068 array->set_elements(elms);
2079 array->set_length(Smi::FromInt(number_of_elements)); 2069 array->set_length(Smi::FromInt(number_of_elements));
2080 return array; 2070 return array;
2081 } 2071 }
2082 2072
2083 } } // namespace v8::internal 2073 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698