Reviewers: dcarney,

Message:
PTAL

Description:
Compute correct contextual load ICs in fullcodegen.

BUG=

Please review this at https://codereview.chromium.org/969733003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+58, -4 lines):
  M src/arm/full-codegen-arm.cc
  M src/arm64/full-codegen-arm64.cc
  M src/code-factory.h
  M src/code-factory.cc
  M src/full-codegen.h
  M src/full-codegen.cc
  M src/ia32/full-codegen-ia32.cc
  M src/ic/ic.h
  M src/ic/ic.cc
  M src/x64/full-codegen-x64.cc


Index: src/arm/full-codegen-arm.cc
diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc
index 5a5d91e92f0dccd94dbca112a07508f2beca1b12..d451c084771845e1b26ec6570be36d4a556934d9 100644
--- a/src/arm/full-codegen-arm.cc
+++ b/src/arm/full-codegen-arm.cc
@@ -1529,7 +1529,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
         __ mov(VectorLoadICDescriptor::SlotRegister(),
                Operand(SmiFromSlot(proxy->VariableFeedbackSlot())));
       }
-      CallLoadIC(CONTEXTUAL);
+      CallGlobalLoadIC(var->name());
       context()->Plug(r0);
       break;
     }
Index: src/arm64/full-codegen-arm64.cc
diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index 2c3c69335d560698ba8eb447d3d84402f7171e31..083a8350320c0d495ae696b4a4dd8ddda1f7b8a5 100644
--- a/src/arm64/full-codegen-arm64.cc
+++ b/src/arm64/full-codegen-arm64.cc
@@ -1508,7 +1508,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
         __ Mov(VectorLoadICDescriptor::SlotRegister(),
                SmiFromSlot(proxy->VariableFeedbackSlot()));
       }
-      CallLoadIC(CONTEXTUAL);
+      CallGlobalLoadIC(var->name());
       context()->Plug(x0);
       break;
     }
Index: src/code-factory.cc
diff --git a/src/code-factory.cc b/src/code-factory.cc
index 6fa2e56a24a0bb067763ea7ceaa961ff25f652b9..d630786f25056e8e171b287c1316c3efa83ad1a2 100644
--- a/src/code-factory.cc
+++ b/src/code-factory.cc
@@ -12,6 +12,15 @@ namespace v8 {
 namespace internal {

 // static
+Callable CodeFactory::LoadGlobalIC(Isolate* isolate,
+                                   Handle<GlobalObject> global,
+                                   Handle<String> name) {
+  return Callable(LoadIC::load_global(isolate, global, name),
+                  LoadDescriptor(isolate));
+}
+
+
+// static
 Callable CodeFactory::LoadIC(Isolate* isolate, ContextualMode mode) {
   return Callable(
LoadIC::initialize_stub(isolate, LoadICState(mode).GetExtraICState()),
Index: src/code-factory.h
diff --git a/src/code-factory.h b/src/code-factory.h
index e1f2efa1f34218c691c34371c86e39b87d995da8..f8af73b18ea06650dde8b321cf2b950f7038ad21 100644
--- a/src/code-factory.h
+++ b/src/code-factory.h
@@ -32,6 +32,8 @@ class Callable FINAL BASE_EMBEDDED {
 class CodeFactory FINAL {
  public:
   // Initial states for ICs.
+ static Callable LoadGlobalIC(Isolate* isolate, Handle<GlobalObject> global,
+                               Handle<String> name);
   static Callable LoadIC(Isolate* isolate, ContextualMode mode);
static Callable LoadICInOptimizedCode(Isolate* isolate, ContextualMode mode, InlineCacheState initialization_state);
Index: src/full-codegen.cc
diff --git a/src/full-codegen.cc b/src/full-codegen.cc
index 80141db5729d6d7af72f9591527996c94b71fb60..4f1db4e99343a692b1f3dfe89a12f5614e1d3267 100644
--- a/src/full-codegen.cc
+++ b/src/full-codegen.cc
@@ -441,6 +441,14 @@ void FullCodeGenerator::CallLoadIC(ContextualMode contextual_mode,
 }


+void FullCodeGenerator::CallGlobalLoadIC(Handle<String> name) {
+  if (masm()->serializer_enabled()) return CallLoadIC(CONTEXTUAL);
+  Handle<Code> ic = CodeFactory::LoadGlobalIC(
+ isolate(), isolate()->global_object(), name).code();
+  CallIC(ic, TypeFeedbackId::None());
+}
+
+
 void FullCodeGenerator::CallStoreIC(TypeFeedbackId id) {
Handle<Code> ic = CodeFactory::StoreIC(isolate(), language_mode()).code();
   CallIC(ic, id);
Index: src/full-codegen.h
diff --git a/src/full-codegen.h b/src/full-codegen.h
index 60c3ac24b1c77ac8fd750421a48e20e2678536f2..84eb02c94c95b86f00200b1f9d3ef2bd16466c60 100644
--- a/src/full-codegen.h
+++ b/src/full-codegen.h
@@ -646,6 +646,7 @@ class FullCodeGenerator: public AstVisitor {

   void CallLoadIC(ContextualMode mode,
                   TypeFeedbackId id = TypeFeedbackId::None());
+  void CallGlobalLoadIC(Handle<String> name);
   void CallStoreIC(TypeFeedbackId id = TypeFeedbackId::None());

   void SetFunctionPosition(FunctionLiteral* fun);
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index 485bd9f34d615096c30a557e2b279369dec61e65..ce36f9ed07b0beac8bba413711da7b42473d44a1 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -1453,7 +1453,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
         __ mov(VectorLoadICDescriptor::SlotRegister(),
                Immediate(SmiFromSlot(proxy->VariableFeedbackSlot())));
       }
-      CallLoadIC(CONTEXTUAL);
+      CallGlobalLoadIC(var->name());
       context()->Plug(eax);
       break;
     }
Index: src/ic/ic.cc
diff --git a/src/ic/ic.cc b/src/ic/ic.cc
index fad3adb5591208eb2d0e8473431d50e1d0643293..4a0e6c8102820eb035bdf2262e1c1d1e73b2353f 100644
--- a/src/ic/ic.cc
+++ b/src/ic/ic.cc
@@ -949,6 +949,38 @@ Handle<Code> LoadIC::initialize_stub(Isolate* isolate,
 }


+Handle<Code> LoadIC::load_global(Isolate* isolate, Handle<GlobalObject> global,
+                                 Handle<String> name) {
+  Handle<ScriptContextTable> script_contexts(
+      global->native_context()->script_context_table());
+
+  ScriptContextTable::LookupResult lookup_result;
+  if (ScriptContextTable::Lookup(script_contexts, name, &lookup_result)) {
+ return initialize_stub(isolate, LoadICState(CONTEXTUAL).GetExtraICState());
+  }
+
+  Handle<Map> global_map(global->map());
+  Handle<Code> handler = PropertyHandlerCompiler::Find(
+      name, global_map, Code::LOAD_IC, kCacheOnReceiver, Code::NORMAL);
+  if (handler.is_null()) {
+    LookupIterator it(global, name);
+ if (!it.IsFound() || !it.GetHolder<JSObject>().is_identical_to(global) ||
+        it.state() != LookupIterator::DATA) {
+      return initialize_stub(isolate,
+                             LoadICState(CONTEXTUAL).GetExtraICState());
+    }
+    NamedLoadHandlerCompiler compiler(isolate, global_map, global,
+                                      kCacheOnReceiver);
+    Handle<PropertyCell> cell = it.GetPropertyCell();
+    handler = compiler.CompileLoadGlobal(cell, name, it.IsConfigurable());
+    Map::UpdateCodeCache(global_map, name, handler);
+  }
+  return PropertyICCompiler::ComputeMonomorphic(
+      Code::LOAD_IC, name, handle(global->map()), handler,
+      LoadICState(CONTEXTUAL).GetExtraICState());
+}
+
+
 Handle<Code> LoadIC::initialize_stub_in_optimized_code(
Isolate* isolate, ExtraICState extra_state, State initialization_state) {
   if (FLAG_vector_ics) {
Index: src/ic/ic.h
diff --git a/src/ic/ic.h b/src/ic/ic.h
index f12b5bdc1226bb5df40619f83addf78b117a73c9..a9eae10b3c8eb524e1c492a58e59b6994cc64c74 100644
--- a/src/ic/ic.h
+++ b/src/ic/ic.h
@@ -398,6 +398,8 @@ class LoadIC : public IC {
                                       ExtraICState extra_state);
   static Handle<Code> initialize_stub_in_optimized_code(
Isolate* isolate, ExtraICState extra_state, State initialization_state); + static Handle<Code> load_global(Isolate* isolate, Handle<GlobalObject> global,
+                                  Handle<String> name);

   MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
                                            Handle<Name> name);
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 85b0355a9bea16cf7395169fb8334022f829c672..6805b54b907076d849991d3c5af85023e426abd4 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -1489,7 +1489,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
         __ Move(VectorLoadICDescriptor::SlotRegister(),
                 SmiFromSlot(proxy->VariableFeedbackSlot()));
       }
-      CallLoadIC(CONTEXTUAL);
+      CallGlobalLoadIC(var->name());
       context()->Plug(rax);
       break;
     }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to