Create missing boilerplate for array literals instead of deoptimizing

BUG=107370
TEST=new additions to mjsunit/array-literal-transitions

Review URL: http://codereview.chromium.org/8914006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10255 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 502039a6
...@@ -1227,7 +1227,9 @@ void HConstant::PrintDataTo(StringStream* stream) { ...@@ -1227,7 +1227,9 @@ void HConstant::PrintDataTo(StringStream* stream) {
bool HArrayLiteral::IsCopyOnWrite() const { bool HArrayLiteral::IsCopyOnWrite() const {
return boilerplate_object_->elements()->map() == HEAP->fixed_cow_array_map(); if (!boilerplate_object_->IsJSObject()) return false;
return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() ==
HEAP->fixed_cow_array_map();
} }
......
...@@ -4225,7 +4225,7 @@ class HMaterializedLiteral: public HTemplateInstruction<V> { ...@@ -4225,7 +4225,7 @@ class HMaterializedLiteral: public HTemplateInstruction<V> {
class HArrayLiteral: public HMaterializedLiteral<1> { class HArrayLiteral: public HMaterializedLiteral<1> {
public: public:
HArrayLiteral(HValue* context, HArrayLiteral(HValue* context,
Handle<JSObject> boilerplate_object, Handle<HeapObject> boilerplate_object,
int length, int length,
int literal_index, int literal_index,
int depth) int depth)
...@@ -4237,9 +4237,12 @@ class HArrayLiteral: public HMaterializedLiteral<1> { ...@@ -4237,9 +4237,12 @@ class HArrayLiteral: public HMaterializedLiteral<1> {
HValue* context() { return OperandAt(0); } HValue* context() { return OperandAt(0); }
ElementsKind boilerplate_elements_kind() const { ElementsKind boilerplate_elements_kind() const {
return boilerplate_object_->GetElementsKind(); if (!boilerplate_object_->IsJSObject()) {
return FAST_ELEMENTS;
}
return Handle<JSObject>::cast(boilerplate_object_)->GetElementsKind();
} }
Handle<JSObject> boilerplate_object() const { return boilerplate_object_; } Handle<HeapObject> boilerplate_object() const { return boilerplate_object_; }
int length() const { return length_; } int length() const { return length_; }
bool IsCopyOnWrite() const; bool IsCopyOnWrite() const;
...@@ -4253,7 +4256,7 @@ class HArrayLiteral: public HMaterializedLiteral<1> { ...@@ -4253,7 +4256,7 @@ class HArrayLiteral: public HMaterializedLiteral<1> {
private: private:
int length_; int length_;
Handle<JSObject> boilerplate_object_; Handle<HeapObject> boilerplate_object_;
}; };
......
...@@ -3464,14 +3464,22 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -3464,14 +3464,22 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
Handle<FixedArray> literals(environment()->closure()->literals()); Handle<FixedArray> literals(environment()->closure()->literals());
Handle<Object> raw_boilerplate(literals->get(expr->literal_index())); Handle<Object> raw_boilerplate(literals->get(expr->literal_index()));
// For now, no boilerplate causes a deopt.
if (raw_boilerplate->IsUndefined()) { if (raw_boilerplate->IsUndefined()) {
AddInstruction(new(zone()) HSoftDeoptimize); raw_boilerplate = Runtime::CreateArrayLiteralBoilerplate(
return ast_context()->ReturnValue(graph()->GetConstantUndefined()); isolate(), literals, expr->constant_elements());
if (raw_boilerplate.is_null()) {
return Bailout("array boilerplate creation failed");
}
literals->set(expr->literal_index(), *raw_boilerplate);
if (JSObject::cast(*raw_boilerplate)->elements()->map() ==
isolate()->heap()->fixed_cow_array_map()) {
isolate()->counters()->cow_arrays_created_runtime()->Increment();
}
} }
Handle<JSObject> boilerplate(Handle<JSObject>::cast(raw_boilerplate)); Handle<JSObject> boilerplate = Handle<JSObject>::cast(raw_boilerplate);
ElementsKind boilerplate_elements_kind = boilerplate->GetElementsKind(); ElementsKind boilerplate_elements_kind =
Handle<JSObject>::cast(boilerplate)->GetElementsKind();
HArrayLiteral* literal = new(zone()) HArrayLiteral( HArrayLiteral* literal = new(zone()) HArrayLiteral(
context, context,
......
...@@ -434,7 +434,8 @@ static Handle<Object> CreateObjectLiteralBoilerplate( ...@@ -434,7 +434,8 @@ static Handle<Object> CreateObjectLiteralBoilerplate(
static const int kSmiOnlyLiteralMinimumLength = 1024; static const int kSmiOnlyLiteralMinimumLength = 1024;
static Handle<Object> CreateArrayLiteralBoilerplate( // static
Handle<Object> Runtime::CreateArrayLiteralBoilerplate(
Isolate* isolate, Isolate* isolate,
Handle<FixedArray> literals, Handle<FixedArray> literals,
Handle<FixedArray> elements) { Handle<FixedArray> elements) {
...@@ -536,7 +537,8 @@ static Handle<Object> CreateLiteralBoilerplate( ...@@ -536,7 +537,8 @@ static Handle<Object> CreateLiteralBoilerplate(
false, false,
kHasNoFunctionLiteral); kHasNoFunctionLiteral);
case CompileTimeValue::ARRAY_LITERAL: case CompileTimeValue::ARRAY_LITERAL:
return CreateArrayLiteralBoilerplate(isolate, literals, elements); return Runtime::CreateArrayLiteralBoilerplate(
isolate, literals, elements);
default: default:
UNREACHABLE(); UNREACHABLE();
return Handle<Object>::null(); return Handle<Object>::null();
...@@ -606,7 +608,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { ...@@ -606,7 +608,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) {
// Check if boilerplate exists. If not, create it first. // Check if boilerplate exists. If not, create it first.
Handle<Object> boilerplate(literals->get(literals_index), isolate); Handle<Object> boilerplate(literals->get(literals_index), isolate);
if (*boilerplate == isolate->heap()->undefined_value()) { if (*boilerplate == isolate->heap()->undefined_value()) {
boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements); boilerplate =
Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements);
if (boilerplate.is_null()) return Failure::Exception(); if (boilerplate.is_null()) return Failure::Exception();
// Update the functions literal and return the boilerplate. // Update the functions literal and return the boilerplate.
literals->set(literals_index, *boilerplate); literals->set(literals_index, *boilerplate);
...@@ -626,7 +629,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { ...@@ -626,7 +629,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) {
Handle<Object> boilerplate(literals->get(literals_index), isolate); Handle<Object> boilerplate(literals->get(literals_index), isolate);
if (*boilerplate == isolate->heap()->undefined_value()) { if (*boilerplate == isolate->heap()->undefined_value()) {
ASSERT(*elements != isolate->heap()->empty_fixed_array()); ASSERT(*elements != isolate->heap()->empty_fixed_array());
boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements); boilerplate =
Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements);
if (boilerplate.is_null()) return Failure::Exception(); if (boilerplate.is_null()) return Failure::Exception();
// Update the functions literal and return the boilerplate. // Update the functions literal and return the boilerplate.
literals->set(literals_index, *boilerplate); literals->set(literals_index, *boilerplate);
......
...@@ -679,6 +679,12 @@ class Runtime : public AllStatic { ...@@ -679,6 +679,12 @@ class Runtime : public AllStatic {
// Helper functions used stubs. // Helper functions used stubs.
static void PerformGC(Object* result); static void PerformGC(Object* result);
// Used in runtime.cc and hydrogen's VisitArrayLiteral.
static Handle<Object> CreateArrayLiteralBoilerplate(
Isolate* isolate,
Handle<FixedArray> literals,
Handle<FixedArray> elements);
}; };
......
...@@ -201,3 +201,10 @@ if (support_smi_only_arrays) { ...@@ -201,3 +201,10 @@ if (support_smi_only_arrays) {
assertEquals(1, array[1]); assertEquals(1, array[1]);
assertEquals(foo, array[2]); assertEquals(foo, array[2]);
} }
(function literals_after_osr() {
var color = [0];
// Trigger OSR.
while (%GetOptimizationStatus(literals_after_osr) == 2) {}
return [color[0]];
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment