Commit 46ca8255 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Avoid repeated rewrites of global store to constant IC due to store of same value.

R=mvstanton@chromium.org

Review URL: https://chromiumcodereview.appspot.com/19663007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15806 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a6c0ae41
...@@ -850,23 +850,25 @@ HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() { ...@@ -850,23 +850,25 @@ HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
HParameter* receiver = GetParameter(0); HParameter* receiver = GetParameter(0);
HParameter* value = GetParameter(2); HParameter* value = GetParameter(2);
if (stub->is_constant()) { // Check that the map of the global has not changed: use a placeholder map
// Assume every store to a constant value changes it. // that will be replaced later with the global object's map.
current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); Handle<Map> placeholder_map = isolate()->factory()->meta_map();
set_current_block(NULL); AddInstruction(HCheckMaps::New(receiver, placeholder_map, zone()));
} else {
HValue* cell = Add<HConstant>(placeholder_cell, Representation::Tagged());
// Check that the map of the global has not changed: use a placeholder map HValue* cell = Add<HConstant>(placeholder_cell, Representation::Tagged());
// that will be replaced later with the global object's map. HObjectAccess access(HObjectAccess::ForCellPayload(isolate()));
Handle<Map> placeholder_map = isolate()->factory()->meta_map(); HValue* cell_contents = Add<HLoadNamedField>(cell, access);
AddInstruction(HCheckMaps::New(receiver, placeholder_map, zone()));
if (stub->is_constant()) {
IfBuilder builder(this);
builder.If<HCompareObjectEqAndBranch>(cell_contents, value);
builder.Then();
builder.ElseDeopt();
builder.End();
} else {
// Load the payload of the global parameter cell. A hole indicates that the // Load the payload of the global parameter cell. A hole indicates that the
// property has been deleted and that the store must be handled by the // property has been deleted and that the store must be handled by the
// runtime. // runtime.
HObjectAccess access(HObjectAccess::ForCellPayload(isolate()));
HValue* cell_contents = Add<HLoadNamedField>(cell, access);
IfBuilder builder(this); IfBuilder builder(this);
HValue* hole_value = Add<HConstant>(hole, Representation::Tagged()); HValue* hole_value = Add<HConstant>(hole, Representation::Tagged());
builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value); builder.If<HCompareObjectEqAndBranch>(cell_contents, hole_value);
...@@ -876,6 +878,7 @@ HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() { ...@@ -876,6 +878,7 @@ HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
Add<HStoreNamedField>(cell, access, value); Add<HStoreNamedField>(cell, access, value);
builder.End(); builder.End();
} }
return value; return value;
} }
......
...@@ -563,16 +563,15 @@ Handle<Code> StubCache::ComputeStoreGlobal(Handle<Name> name, ...@@ -563,16 +563,15 @@ Handle<Code> StubCache::ComputeStoreGlobal(Handle<Name> name,
Code::STORE_IC, Code::NORMAL, stub.GetExtraICState()); Code::STORE_IC, Code::NORMAL, stub.GetExtraICState());
if (!code.is_null()) return code; if (!code.is_null()) return code;
if (is_constant) return stub.GetCode(isolate_);
// Replace the placeholder cell and global object map with the actual global // Replace the placeholder cell and global object map with the actual global
// cell and receiver map. // cell and receiver map.
Handle<Map> cell_map(isolate_->heap()->global_property_cell_map());
Handle<Map> meta_map(isolate_->heap()->meta_map()); Handle<Map> meta_map(isolate_->heap()->meta_map());
Handle<Object> receiver_map(receiver->map(), isolate_); Handle<Object> receiver_map(receiver->map(), isolate_);
code = stub.GetCodeCopyFromTemplate(isolate_); code = stub.GetCodeCopyFromTemplate(isolate_);
code->ReplaceNthObject(1, *meta_map, *receiver_map); code->ReplaceNthObject(1, *meta_map, *receiver_map);
Handle<Map> cell_map(isolate_->heap()->global_property_cell_map());
code->ReplaceNthObject(1, *cell_map, *cell); code->ReplaceNthObject(1, *cell_map, *cell);
JSObject::UpdateMapCodeCache(receiver, name, code); JSObject::UpdateMapCodeCache(receiver, name, code);
return code; return code;
......
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