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
This commit is contained in:
parent
502039a6bd
commit
106973c3d2
@ -1227,7 +1227,9 @@ void HConstant::PrintDataTo(StringStream* stream) {
|
||||
|
||||
|
||||
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> {
|
||||
class HArrayLiteral: public HMaterializedLiteral<1> {
|
||||
public:
|
||||
HArrayLiteral(HValue* context,
|
||||
Handle<JSObject> boilerplate_object,
|
||||
Handle<HeapObject> boilerplate_object,
|
||||
int length,
|
||||
int literal_index,
|
||||
int depth)
|
||||
@ -4237,9 +4237,12 @@ class HArrayLiteral: public HMaterializedLiteral<1> {
|
||||
|
||||
HValue* context() { return OperandAt(0); }
|
||||
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_; }
|
||||
|
||||
bool IsCopyOnWrite() const;
|
||||
@ -4253,7 +4256,7 @@ class HArrayLiteral: public HMaterializedLiteral<1> {
|
||||
|
||||
private:
|
||||
int length_;
|
||||
Handle<JSObject> boilerplate_object_;
|
||||
Handle<HeapObject> boilerplate_object_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -3464,14 +3464,22 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
|
||||
Handle<FixedArray> literals(environment()->closure()->literals());
|
||||
Handle<Object> raw_boilerplate(literals->get(expr->literal_index()));
|
||||
|
||||
// For now, no boilerplate causes a deopt.
|
||||
if (raw_boilerplate->IsUndefined()) {
|
||||
AddInstruction(new(zone()) HSoftDeoptimize);
|
||||
return ast_context()->ReturnValue(graph()->GetConstantUndefined());
|
||||
raw_boilerplate = Runtime::CreateArrayLiteralBoilerplate(
|
||||
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));
|
||||
ElementsKind boilerplate_elements_kind = boilerplate->GetElementsKind();
|
||||
Handle<JSObject> boilerplate = Handle<JSObject>::cast(raw_boilerplate);
|
||||
ElementsKind boilerplate_elements_kind =
|
||||
Handle<JSObject>::cast(boilerplate)->GetElementsKind();
|
||||
|
||||
HArrayLiteral* literal = new(zone()) HArrayLiteral(
|
||||
context,
|
||||
|
@ -434,7 +434,8 @@ static Handle<Object> CreateObjectLiteralBoilerplate(
|
||||
static const int kSmiOnlyLiteralMinimumLength = 1024;
|
||||
|
||||
|
||||
static Handle<Object> CreateArrayLiteralBoilerplate(
|
||||
// static
|
||||
Handle<Object> Runtime::CreateArrayLiteralBoilerplate(
|
||||
Isolate* isolate,
|
||||
Handle<FixedArray> literals,
|
||||
Handle<FixedArray> elements) {
|
||||
@ -536,7 +537,8 @@ static Handle<Object> CreateLiteralBoilerplate(
|
||||
false,
|
||||
kHasNoFunctionLiteral);
|
||||
case CompileTimeValue::ARRAY_LITERAL:
|
||||
return CreateArrayLiteralBoilerplate(isolate, literals, elements);
|
||||
return Runtime::CreateArrayLiteralBoilerplate(
|
||||
isolate, literals, elements);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return Handle<Object>::null();
|
||||
@ -606,7 +608,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) {
|
||||
// Check if boilerplate exists. If not, create it first.
|
||||
Handle<Object> boilerplate(literals->get(literals_index), isolate);
|
||||
if (*boilerplate == isolate->heap()->undefined_value()) {
|
||||
boilerplate = CreateArrayLiteralBoilerplate(isolate, literals, elements);
|
||||
boilerplate =
|
||||
Runtime::CreateArrayLiteralBoilerplate(isolate, literals, elements);
|
||||
if (boilerplate.is_null()) return Failure::Exception();
|
||||
// Update the functions literal and return the boilerplate.
|
||||
literals->set(literals_index, *boilerplate);
|
||||
@ -626,7 +629,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) {
|
||||
Handle<Object> boilerplate(literals->get(literals_index), isolate);
|
||||
if (*boilerplate == isolate->heap()->undefined_value()) {
|
||||
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();
|
||||
// Update the functions literal and return the boilerplate.
|
||||
literals->set(literals_index, *boilerplate);
|
||||
|
@ -679,6 +679,12 @@ class Runtime : public AllStatic {
|
||||
|
||||
// Helper functions used stubs.
|
||||
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) {
|
||||
assertEquals(1, array[1]);
|
||||
assertEquals(foo, array[2]);
|
||||
}
|
||||
|
||||
(function literals_after_osr() {
|
||||
var color = [0];
|
||||
// Trigger OSR.
|
||||
while (%GetOptimizationStatus(literals_after_osr) == 2) {}
|
||||
return [color[0]];
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user