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

Unified Diff: src/builtins.cc

Issue 7901016: Basic support for tracking smi-only arrays on ia32. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ready to land Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 4af5b3a7aa355496ee0c95e0b47cd34bf0c20b7f..591904ef17366e9544f4c03ec33357c2ee1b5f75 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -203,7 +203,7 @@ BUILTIN(ArrayCodeGeneric) {
}
// 'array' now contains the JSArray we should initialize.
- ASSERT(array->HasFastElements());
+ ASSERT(array->HasFastTypeElements());
// Optimize the case where there is one argument and the argument is a
// small smi.
@@ -216,7 +216,8 @@ BUILTIN(ArrayCodeGeneric) {
{ MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(len);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
- array->SetContent(FixedArray::cast(obj));
+ MaybeObject* maybe_obj = array->SetContent(FixedArray::cast(obj));
+ if (maybe_obj->IsFailure()) return maybe_obj;
return array;
}
}
@@ -240,6 +241,13 @@ BUILTIN(ArrayCodeGeneric) {
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
+ // Set length and elements on the array.
+ if (FLAG_smi_only_arrays) {
+ MaybeObject* maybe_object =
+ array->EnsureCanContainElements(FixedArray::cast(obj));
+ if (maybe_object->IsFailure()) return maybe_object;
+ }
+
AssertNoAllocation no_gc;
FixedArray* elms = FixedArray::cast(obj);
WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
@@ -248,7 +256,6 @@ BUILTIN(ArrayCodeGeneric) {
elms->set(index, args[index+1], mode);
}
- // Set length and elements on the array.
array->set_elements(FixedArray::cast(obj));
array->set_length(len);
@@ -486,9 +493,11 @@ BUILTIN(ArrayPush) {
FillWithHoles(heap, new_elms, new_length, capacity);
elms = new_elms;
- array->set_elements(elms);
}
+ MaybeObject* maybe = array->EnsureCanContainElements(&args, 1, to_add);
+ if (maybe->IsFailure()) return maybe;
+
// Add the provided values.
AssertNoAllocation no_gc;
WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
@@ -496,6 +505,10 @@ BUILTIN(ArrayPush) {
elms->set(index + len, args[index + 1], mode);
}
+ if (elms != array->elements()) {
+ array->set_elements(elms);
+ }
+
// Set the length.
array->set_length(Smi::FromInt(new_length));
return Smi::FromInt(new_length);
@@ -550,7 +563,7 @@ BUILTIN(ArrayShift) {
}
FixedArray* elms = FixedArray::cast(elms_obj);
JSArray* array = JSArray::cast(receiver);
- ASSERT(array->HasFastElements());
+ ASSERT(array->HasFastTypeElements());
int len = Smi::cast(array->length())->value();
if (len == 0) return heap->undefined_value();
@@ -592,7 +605,7 @@ BUILTIN(ArrayUnshift) {
}
FixedArray* elms = FixedArray::cast(elms_obj);
JSArray* array = JSArray::cast(receiver);
- ASSERT(array->HasFastElements());
+ ASSERT(array->HasFastTypeElements());
int len = Smi::cast(array->length())->value();
int to_add = args.length() - 1;
@@ -601,6 +614,12 @@ BUILTIN(ArrayUnshift) {
// we should never hit this case.
ASSERT(to_add <= (Smi::kMaxValue - len));
+ if (FLAG_smi_only_arrays) {
+ MaybeObject* maybe_object =
+ array->EnsureCanContainElements(&args, 1, to_add);
+ if (maybe_object->IsFailure()) return maybe_object;
+ }
+
if (new_length > elms->length()) {
// New backing storage is needed.
int capacity = new_length + (new_length >> 1) + 16;
@@ -609,13 +628,11 @@ BUILTIN(ArrayUnshift) {
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
FixedArray* new_elms = FixedArray::cast(obj);
-
AssertNoAllocation no_gc;
if (len > 0) {
CopyElements(heap, &no_gc, new_elms, to_add, elms, 0, len);
}
FillWithHoles(heap, new_elms, new_length, capacity);
-
elms = new_elms;
array->set_elements(elms);
} else {
@@ -730,6 +747,12 @@ BUILTIN(ArraySlice) {
}
FixedArray* result_elms = FixedArray::cast(result);
+ if (FLAG_smi_only_arrays) {
+ MaybeObject* maybe_object =
+ result_array->EnsureCanContainElements(result_elms);
+ if (maybe_object->IsFailure()) return maybe_object;
+ }
+
AssertNoAllocation no_gc;
CopyElements(heap, &no_gc, result_elms, 0, elms, k, result_len);
@@ -757,7 +780,7 @@ BUILTIN(ArraySplice) {
}
FixedArray* elms = FixedArray::cast(elms_obj);
JSArray* array = JSArray::cast(receiver);
- ASSERT(array->HasFastElements());
+ ASSERT(array->HasFastTypeElements());
int len = Smi::cast(array->length())->value();
@@ -835,8 +858,14 @@ BUILTIN(ArraySplice) {
int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
+ if (FLAG_smi_only_arrays) {
+ MaybeObject* maybe = array->EnsureCanContainElements(&args, 3, item_count);
+ if (maybe->IsFailure()) return maybe;
+ }
+
int new_length = len - actual_delete_count + item_count;
+ bool elms_changed = false;
if (item_count < actual_delete_count) {
// Shrink the array.
const bool trim_array = !heap->lo_space()->Contains(elms) &&
@@ -851,7 +880,8 @@ BUILTIN(ArraySplice) {
}
elms = LeftTrimFixedArray(heap, elms, delta);
- array->set_elements(elms);
+
+ elms_changed = true;
} else {
AssertNoAllocation no_gc;
MoveElements(heap, &no_gc,
@@ -891,7 +921,7 @@ BUILTIN(ArraySplice) {
FillWithHoles(heap, new_elms, new_length, capacity);
elms = new_elms;
- array->set_elements(elms);
+ elms_changed = true;
} else {
AssertNoAllocation no_gc;
MoveElements(heap, &no_gc,
@@ -907,6 +937,10 @@ BUILTIN(ArraySplice) {
elms->set(k, args[3 + k - actual_start], mode);
}
+ if (elms_changed) {
+ array->set_elements(elms);
+ }
+
// Set the length.
array->set_length(Smi::FromInt(new_length));
@@ -965,6 +999,19 @@ BUILTIN(ArrayConcat) {
}
FixedArray* result_elms = FixedArray::cast(result);
+ if (FLAG_smi_only_arrays) {
+ for (int i = 0; i < n_arguments; i++) {
+ JSArray* array = JSArray::cast(args[i]);
+ int len = Smi::cast(array->length())->value();
+ if (len > 0) {
+ FixedArray* elms = FixedArray::cast(array->elements());
+ MaybeObject* maybe_object =
+ result_array->EnsureCanContainElements(elms);
+ if (maybe_object->IsFailure()) return maybe_object;
+ }
+ }
+ }
+
// Copy data.
AssertNoAllocation no_gc;
int start_pos = 0;
« src/bootstrapper.cc ('K') | « src/bootstrapper.cc ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698