Fetch global object from jsproxy prototype instead of embedding it in StoreGlobal.
authorulan <ulan@chromium.org>
Mon, 2 Feb 2015 17:56:29 +0000 (09:56 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 2 Feb 2015 17:56:49 +0000 (17:56 +0000)
BUG=v8:3629
LOG=N

Review URL: https://codereview.chromium.org/892213003

Cr-Commit-Position: refs/heads/master@{#26385}

src/code-stubs-hydrogen.cc
src/code-stubs.h
src/ic/ic.cc

index c679d4c..826c1dd 100644 (file)
@@ -1313,16 +1313,25 @@ HValue* CodeStubGraphBuilder<StoreGlobalStub>::BuildCodeInitializedStub() {
   Handle<Object> placeholer_value(Smi::FromInt(0), isolate());
   Handle<PropertyCell> placeholder_cell =
       isolate()->factory()->NewPropertyCell(placeholer_value);
-
   HParameter* value = GetParameter(StoreDescriptor::kValueIndex);
-
   if (stub->check_global()) {
     // Check that the map of the global has not changed: use a placeholder map
     // that will be replaced later with the global object's map.
+    HParameter* proxy = GetParameter(StoreDescriptor::kReceiverIndex);
+    HValue* proxy_map =
+        Add<HLoadNamedField>(proxy, nullptr, HObjectAccess::ForMap());
+    HValue* global =
+        Add<HLoadNamedField>(proxy_map, nullptr, HObjectAccess::ForPrototype());
     Handle<Map> placeholder_map = isolate()->factory()->meta_map();
-    HValue* global = Add<HConstant>(
-        StoreGlobalStub::global_placeholder(isolate()));
-    Add<HCheckMaps>(global, placeholder_map);
+    HValue* cell = Add<HConstant>(Map::WeakCellForMap(placeholder_map));
+    HValue* expected_map =
+        Add<HLoadNamedField>(cell, nullptr, HObjectAccess::ForWeakCellValue());
+    HValue* map =
+        Add<HLoadNamedField>(global, nullptr, HObjectAccess::ForMap());
+    IfBuilder map_check(this);
+    map_check.IfNot<HCompareObjectEqAndBranch>(expected_map, map);
+    map_check.ThenDeopt("Unknown map");
+    map_check.End();
   }
 
   HValue* cell = Add<HConstant>(placeholder_cell);
index a0ffd12..f8009a2 100644 (file)
@@ -1092,8 +1092,8 @@ class StoreGlobalStub : public HandlerStub {
                                        Handle<PropertyCell> cell) {
     if (check_global()) {
       Code::FindAndReplacePattern pattern;
-      pattern.Add(Handle<Map>(global_placeholder(isolate())->map()), global);
-      pattern.Add(isolate()->factory()->meta_map(), Handle<Map>(global->map()));
+      pattern.Add(isolate()->factory()->meta_map(),
+                  Map::WeakCellForMap(Handle<Map>(global->map())));
       pattern.Add(isolate()->factory()->global_property_cell_map(), cell);
       return CodeStub::GetCodeCopy(pattern);
     } else {
index 17d4ee2..68c1159 100644 (file)
@@ -1747,6 +1747,8 @@ Handle<Code> StoreIC::CompileHandler(LookupIterator* lookup,
         if (holder->IsGlobalObject()) {
           Handle<PropertyCell> cell = lookup->GetPropertyCell();
           Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value);
+          DCHECK(holder.is_identical_to(receiver) ||
+                 receiver->map()->prototype() == *holder);
           StoreGlobalStub stub(isolate(), union_type->IsConstant(),
                                receiver->IsJSGlobalProxy());
           Handle<Code> code = stub.GetCodeCopyFromTemplate(