Reviewers: Jakob,
Message:
ptal
Description:
Optimize array literal boilerplate copy for fast cases.
[email protected]
BUG=none
TEST=none
Please review this at http://codereview.chromium.org/8590026/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/ia32/full-codegen-ia32.cc
M src/x64/full-codegen-x64.cc
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index
10a3422ea1d429f899bd4ee8ae056e1ee244ee31..c329dc72f85964da164b98f251c74000e4372a01
100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -1477,6 +1477,8 @@ void
FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
int length = subexprs->length();
Handle<FixedArray> constant_elements = expr->constant_elements();
ASSERT_EQ(2, constant_elements->length());
+ ElementsKind constant_elements_kind =
+
static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
Handle<FixedArrayBase> constant_elements_values(
FixedArrayBase::cast(constant_elements->get(1)));
@@ -1497,8 +1499,19 @@ void
FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
__ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(),
1);
}
- FastCloneShallowArrayStub stub(
- FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS, length);
+ FastCloneShallowArrayStub::Mode mode =
+ FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS;
+ if (constant_elements_kind == FAST_ELEMENTS) {
+ // If the elements are already FAST_ELEMENTS, the boilerplate cannot
+ // change, so it's possible to specialize the stub in advance.
+ if (constant_elements_values->map() ==
+ isolate()->heap()->fixed_cow_array_map()) {
+ mode = FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS;
+ } else {
+ mode = FastCloneShallowArrayStub::CLONE_ELEMENTS;
+ }
+ }
+ FastCloneShallowArrayStub stub(mode, length);
__ CallStub(&stub);
}
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index
9a001266c9f3b8b56d888058792584cac25d87e7..83888cf9345c925ad0fabca788829df5bc84db13
100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -1502,8 +1502,19 @@ void
FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
__ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(),
1);
}
- FastCloneShallowArrayStub stub(
- FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS, length);
+ FastCloneShallowArrayStub::Mode mode =
+ FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS;
+ if (constant_elements_kind == FAST_ELEMENTS) {
+ // If the elements are already FAST_ELEMENTS, the boilerplate cannot
+ // change, so it's possible to specialize the stub in advance.
+ if (constant_elements_values->map() ==
+ isolate()->heap()->fixed_cow_array_map()) {
+ mode = FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS;
+ } else {
+ mode = FastCloneShallowArrayStub::CLONE_ELEMENTS;
+ }
+ }
+ FastCloneShallowArrayStub stub(mode, length);
__ CallStub(&stub);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev