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

Side by Side Diff: src/runtime.cc

Issue 416403002: Keep new arrays allocated with 'new Array(N)' in fast mode (revisited) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 6 years, 5 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/runtime.h ('k') | test/fuzz-natives/base.js » ('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 // 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 10535 matching lines...) Expand 10 before | Expand all | Expand 10 after
10546 JSObject::ResetElements(from); 10546 JSObject::ResetElements(from);
10547 from->set_length(Smi::FromInt(0)); 10547 from->set_length(Smi::FromInt(0));
10548 10548
10549 JSObject::ValidateElements(to); 10549 JSObject::ValidateElements(to);
10550 return *to; 10550 return *to;
10551 } 10551 }
10552 10552
10553 10553
10554 // How many elements does this object/array have? 10554 // How many elements does this object/array have?
10555 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) { 10555 RUNTIME_FUNCTION(Runtime_EstimateNumberOfElements) {
10556 HandleScope scope(isolate);
10557 ASSERT(args.length() == 1);
10558 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
10559 Handle<FixedArrayBase> elements(array->elements(), isolate);
10556 SealHandleScope shs(isolate); 10560 SealHandleScope shs(isolate);
10557 ASSERT(args.length() == 1);
10558 CONVERT_ARG_CHECKED(JSArray, object, 0);
10559 HeapObject* elements = object->elements();
10560 if (elements->IsDictionary()) { 10561 if (elements->IsDictionary()) {
10561 int result = SeededNumberDictionary::cast(elements)->NumberOfElements(); 10562 int result =
10563 Handle<SeededNumberDictionary>::cast(elements)->NumberOfElements();
10562 return Smi::FromInt(result); 10564 return Smi::FromInt(result);
10563 } else { 10565 } else {
10564 return object->length(); 10566 ASSERT(array->length()->IsSmi());
10567 // For packed elements, we know the exact number of elements
10568 int length = elements->length();
10569 ElementsKind kind = array->GetElementsKind();
10570 if (IsFastPackedElementsKind(kind)) {
10571 return Smi::FromInt(length);
10572 }
10573 // For holey elements, take samples from the buffer checking for holes
10574 // to generate the estimate.
10575 const int kNumberOfHoleCheckSamples = 97;
10576 int increment = (length < kNumberOfHoleCheckSamples)
10577 ? 1
10578 : static_cast<int>(length / kNumberOfHoleCheckSamples);
10579 ElementsAccessor* accessor = array->GetElementsAccessor();
10580 int holes = 0;
10581 for (int i = 0; i < length; i += increment) {
10582 if (!accessor->HasElement(array, array, i, elements)) {
10583 ++holes;
10584 }
10585 }
10586 int estimate = static_cast<int>((kNumberOfHoleCheckSamples - holes) /
10587 kNumberOfHoleCheckSamples * length);
10588 return Smi::FromInt(estimate);
10565 } 10589 }
10566 } 10590 }
10567 10591
10568 10592
10569 // Returns an array that tells you where in the [0, length) interval an array 10593 // Returns an array that tells you where in the [0, length) interval an array
10570 // might have elements. Can either return an array of keys (positive integers 10594 // might have elements. Can either return an array of keys (positive integers
10571 // or undefined) or a number representing the positive length of an interval 10595 // or undefined) or a number representing the positive length of an interval
10572 // starting at index 0. 10596 // starting at index 0.
10573 // Intervals can span over some keys that are not in the object. 10597 // Intervals can span over some keys that are not in the object.
10574 RUNTIME_FUNCTION(Runtime_GetArrayKeys) { 10598 RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
(...skipping 4349 matching lines...) Expand 10 before | Expand all | Expand 10 after
14924 ASSERT(arg_count == caller_args->length()); 14948 ASSERT(arg_count == caller_args->length());
14925 } 14949 }
14926 #endif 14950 #endif
14927 return ArrayConstructorCommon(isolate, 14951 return ArrayConstructorCommon(isolate,
14928 constructor, 14952 constructor,
14929 Handle<AllocationSite>::null(), 14953 Handle<AllocationSite>::null(),
14930 caller_args); 14954 caller_args);
14931 } 14955 }
14932 14956
14933 14957
14958 RUNTIME_FUNCTION(Runtime_NormalizeElements) {
14959 HandleScope scope(isolate);
14960 ASSERT(args.length() == 1);
14961 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0);
14962 JSObject::NormalizeElements(array);
14963 return *array;
14964 }
14965
14966
14934 RUNTIME_FUNCTION(Runtime_MaxSmi) { 14967 RUNTIME_FUNCTION(Runtime_MaxSmi) {
14935 ASSERT(args.length() == 0); 14968 ASSERT(args.length() == 0);
14936 return Smi::FromInt(Smi::kMaxValue); 14969 return Smi::FromInt(Smi::kMaxValue);
14937 } 14970 }
14938 14971
14939 14972
14940 // ---------------------------------------------------------------------------- 14973 // ----------------------------------------------------------------------------
14941 // Implementation of Runtime 14974 // Implementation of Runtime
14942 14975
14943 #define F(name, number_of_args, result_size) \ 14976 #define F(name, number_of_args, result_size) \
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
14995 } 15028 }
14996 return NULL; 15029 return NULL;
14997 } 15030 }
14998 15031
14999 15032
15000 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15033 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15001 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15034 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15002 } 15035 }
15003 15036
15004 } } // namespace v8::internal 15037 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/fuzz-natives/base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698