Revision: 13458
Author:   [email protected]
Date:     Mon Jan 21 09:17:02 2013
Log:      Migrate ArrayLength (Keyed|Named)LoadIC to CodeStub

Review URL: https://chromiumcodereview.appspot.com/11938013
http://code.google.com/p/v8/source/detail?r=13458

Modified:
 /branches/bleeding_edge/src/arm/code-stubs-arm.cc
 /branches/bleeding_edge/src/arm/ic-arm.cc
 /branches/bleeding_edge/src/arm/stub-cache-arm.cc
 /branches/bleeding_edge/src/ast.cc
 /branches/bleeding_edge/src/builtins.cc
 /branches/bleeding_edge/src/builtins.h
 /branches/bleeding_edge/src/code-stubs.h
 /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
 /branches/bleeding_edge/src/ia32/ic-ia32.cc
 /branches/bleeding_edge/src/ia32/stub-cache-ia32.cc
 /branches/bleeding_edge/src/ic.cc
 /branches/bleeding_edge/src/stub-cache.cc
 /branches/bleeding_edge/src/stub-cache.h
 /branches/bleeding_edge/src/x64/code-stubs-x64.cc
 /branches/bleeding_edge/src/x64/ic-x64.cc
 /branches/bleeding_edge/src/x64/stub-cache-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Mon Jan 21 09:17:02 2013
@@ -4501,6 +4501,35 @@
     __ Ret(HasArgsInRegisters() ? 0 : 2);
   }
 }
+
+
+void ArrayLengthStub::Generate(MacroAssembler* masm) {
+  Label miss;
+  Register receiver;
+  if (kind() == Code::KEYED_LOAD_IC) {
+    // ----------- S t a t e -------------
+    //  -- lr    : return address
+    //  -- r0    : key
+    //  -- r1    : receiver
+    // -----------------------------------
+    __ cmp(r0, Operand(masm->isolate()->factory()->length_symbol()));
+    __ b(ne, &miss);
+    receiver = r1;
+  } else {
+    ASSERT(kind() == Code::LOAD_IC);
+    // ----------- S t a t e -------------
+    //  -- r2    : name
+    //  -- lr    : return address
+    //  -- r0    : receiver
+    //  -- sp[0] : receiver
+    // -----------------------------------
+    receiver = r0;
+  }
+
+  StubCompiler::GenerateLoadArrayLength(masm, receiver, r3, &miss);
+  __ bind(&miss);
+  StubCompiler::GenerateLoadMiss(masm, kind());
+}


 void StringLengthStub::Generate(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/arm/ic-arm.cc   Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/arm/ic-arm.cc   Mon Jan 21 09:17:02 2013
@@ -211,21 +211,6 @@
   __ RecordWrite(
       elements, scratch2, scratch1, kLRHasNotBeenSaved, kDontSaveFPRegs);
 }
-
-
-void LoadIC::GenerateArrayLength(MacroAssembler* masm) {
-  // ----------- S t a t e -------------
-  //  -- r2    : name
-  //  -- lr    : return address
-  //  -- r0    : receiver
-  //  -- sp[0] : receiver
-  // -----------------------------------
-  Label miss;
-
-  StubCompiler::GenerateLoadArrayLength(masm, r0, r3, &miss);
-  __ bind(&miss);
-  StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC);
-}


 void LoadIC::GenerateFunctionPrototype(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/arm/stub-cache-arm.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/arm/stub-cache-arm.cc Mon Jan 21 09:17:02 2013
@@ -3205,27 +3205,6 @@

   return GetCode(Code::INTERCEPTOR, name);
 }
-
-
-Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
-    Handle<String> name) {
-  // ----------- S t a t e -------------
-  //  -- lr    : return address
-  //  -- r0    : key
-  //  -- r1    : receiver
-  // -----------------------------------
-  Label miss;
-
-  // Check the key is the cached one.
-  __ cmp(r0, Operand(name));
-  __ b(ne, &miss);
-
-  GenerateLoadArrayLength(masm(), r1, r2, &miss);
-  __ bind(&miss);
-  GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
-
-  return GetCode(Code::CALLBACKS, name);
-}


 Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(
=======================================
--- /branches/bleeding_edge/src/ast.cc  Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/ast.cc  Mon Jan 21 09:17:02 2013
@@ -413,8 +413,9 @@
   is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this);
   receiver_types_.Clear();
   if (key()->IsPropertyName()) {
+    ArrayLengthStub array_stub(Code::LOAD_IC);
     StringLengthStub string_stub(Code::LOAD_IC, false);
-    if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) {
+    if (oracle->LoadIsStub(this, &array_stub)) {
       is_array_length_ = true;
     } else if (oracle->LoadIsStub(this, &string_stub)) {
       is_string_length_ = true;
=======================================
--- /branches/bleeding_edge/src/builtins.cc     Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/builtins.cc     Mon Jan 21 09:17:02 2013
@@ -1451,11 +1451,6 @@
 BUILTIN(HandleApiCallAsConstructor) {
   return HandleApiCallAsFunctionOrConstructor(isolate, true, args);
 }
-
-
-static void Generate_LoadIC_ArrayLength(MacroAssembler* masm) {
-  LoadIC::GenerateArrayLength(masm);
-}


 static void Generate_LoadIC_FunctionPrototype(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/builtins.h      Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/builtins.h      Mon Jan 21 09:17:02 2013
@@ -134,8 +134,6 @@
                                     Code::kNoExtraICState)              \
   V(LoadIC_Normal,                  LOAD_IC, MONOMORPHIC,               \
                                     Code::kNoExtraICState)              \
-  V(LoadIC_ArrayLength,             LOAD_IC, MONOMORPHIC,               \
-                                    Code::kNoExtraICState)              \
   V(LoadIC_FunctionPrototype,       LOAD_IC, MONOMORPHIC,               \
                                     Code::kNoExtraICState)              \
   V(LoadIC_Megamorphic,             LOAD_IC, MEGAMORPHIC,               \
=======================================
--- /branches/bleeding_edge/src/code-stubs.h    Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/code-stubs.h    Mon Jan 21 09:17:02 2013
@@ -47,6 +47,7 @@
   V(Compare)                             \
   V(CompareIC)                           \
   V(MathPow)                             \
+  V(ArrayLength)                         \
   V(StringLength)                        \
   V(RecordWrite)                         \
   V(StoreBufferOverflow)                 \
@@ -556,12 +557,26 @@
     code->set_stub_info(MinorKey());
   }
   Code::Kind kind() { return kind_; }
+
+  virtual int MinorKey() {
+    return KindBits::encode(kind_);
+  }

  private:
   Code::Kind kind_;
 };


+class ArrayLengthStub: public ICStub {
+ public:
+  explicit ArrayLengthStub(Code::Kind kind) : ICStub(kind) { }
+  virtual void Generate(MacroAssembler* masm);
+
+ private:
+  virtual CodeStub::Major MajorKey() { return ArrayLength; }
+};
+
+
 class StringLengthStub: public ICStub {
  public:
   StringLengthStub(Code::Kind kind, bool support_wrapper)
=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Mon Jan 21 09:17:02 2013
@@ -3257,6 +3257,25 @@
     __ ret(0);
   }
 }
+
+
+void ArrayLengthStub::Generate(MacroAssembler* masm) {
+  // ----------- S t a t e -------------
+  //  -- ecx    : name
+  //  -- edx    : receiver
+  //  -- esp[0] : return address
+  // -----------------------------------
+  Label miss;
+
+  if (kind() == Code::KEYED_LOAD_IC) {
+    __ cmp(ecx, Immediate(masm->isolate()->factory()->length_symbol()));
+    __ j(not_equal, &miss);
+  }
+
+  StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss);
+  __ bind(&miss);
+  StubCompiler::GenerateLoadMiss(masm, kind());
+}


 void StringLengthStub::Generate(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/ia32/ic-ia32.cc Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/ia32/ic-ia32.cc Mon Jan 21 09:17:02 2013
@@ -214,20 +214,6 @@
   __ mov(r1, value);
   __ RecordWrite(elements, r0, r1, kDontSaveFPRegs);
 }
-
-
-void LoadIC::GenerateArrayLength(MacroAssembler* masm) {
-  // ----------- S t a t e -------------
-  //  -- ecx    : name
-  //  -- edx    : receiver
-  //  -- esp[0] : return address
-  // -----------------------------------
-  Label miss;
-
-  StubCompiler::GenerateLoadArrayLength(masm, edx, eax, &miss);
-  __ bind(&miss);
-  StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC);
-}


 void LoadIC::GenerateFunctionPrototype(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/ia32/stub-cache-ia32.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/ia32/stub-cache-ia32.cc Mon Jan 21 09:17:02 2013
@@ -3313,32 +3313,6 @@
   // Return the generated code.
   return GetCode(Code::INTERCEPTOR, name);
 }
-
-
-Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
-    Handle<String> name) {
-  // ----------- S t a t e -------------
-  //  -- ecx    : key
-  //  -- edx    : receiver
-  //  -- esp[0] : return address
-  // -----------------------------------
-  Label miss;
-
-  Counters* counters = isolate()->counters();
-  __ IncrementCounter(counters->keyed_load_array_length(), 1);
-
-  // Check that the name has not changed.
-  __ cmp(ecx, Immediate(name));
-  __ j(not_equal, &miss);
-
-  GenerateLoadArrayLength(masm(), edx, eax, &miss);
-  __ bind(&miss);
-  __ DecrementCounter(counters->keyed_load_array_length(), 1);
-  GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
-
-  // Return the generated code.
-  return GetCode(Code::CALLBACKS, name);
-}


 Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(
=======================================
--- /branches/bleeding_edge/src/ic.cc   Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/ic.cc   Mon Jan 21 09:17:02 2013
@@ -868,6 +868,29 @@
     *result = Smi::FromInt(String::cast(*string)->length());
     return true;
   }
+
+  // Use specialized code for getting the length of arrays.
+ if (object->IsJSArray() && name->Equals(isolate()->heap()->length_symbol())) {
+    Handle<Code> stub;
+    if (state == UNINITIALIZED) {
+      stub = pre_monomorphic_stub();
+    } else if (state == PREMONOMORPHIC) {
+      ArrayLengthStub array_length_stub(kind());
+      stub = array_length_stub.GetCode();
+    } else if (state != MEGAMORPHIC) {
+      ASSERT(state != GENERIC);
+      stub = megamorphic_stub();
+    }
+    if (!stub.is_null()) {
+      set_target(*stub);
+#ifdef DEBUG
+      if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n");
+#endif
+    }
+    *result = JSArray::cast(*object)->length();
+    return true;
+  }
+
   return false;
 }

@@ -886,27 +909,6 @@
     if (HandleLoad(state, object, name, &result)) {
       return result;
     }
-
-    // Use specialized code for getting the length of arrays.
-    if (object->IsJSArray() &&
-        name->Equals(isolate()->heap()->length_symbol())) {
-      Handle<Code> stub;
-      if (state == UNINITIALIZED) {
-        stub = pre_monomorphic_stub();
-      } else if (state == PREMONOMORPHIC) {
-        stub = isolate()->builtins()->LoadIC_ArrayLength();
-      } else if (state != MEGAMORPHIC) {
-        ASSERT(state != GENERIC);
-        stub = megamorphic_stub();
-      }
-      if (!stub.is_null()) {
-        set_target(*stub);
-#ifdef DEBUG
-        if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n");
-#endif
-      }
-      return JSArray::cast(*object)->length();
-    }

     // Use specialized code for getting prototype of functions.
     if (object->IsJSFunction() &&
@@ -1175,18 +1177,6 @@
       }

       // TODO(1073): don't ignore the current stub state.
-      // Use specialized code for getting the length of arrays.
-      if (object->IsJSArray() &&
-          name->Equals(isolate()->heap()->length_symbol())) {
-        Handle<JSArray> array = Handle<JSArray>::cast(object);
-        Handle<Code> code =
- isolate()->stub_cache()->ComputeKeyedLoadArrayLength(name, array);
-        ASSERT(!code.is_null());
-        set_target(*code);
-        TRACE_IC("KeyedLoadIC", name, state, target());
-        return array->length();
-      }
-
       // Use specialized code for getting prototype of functions.
       if (object->IsJSFunction() &&
           name->Equals(isolate()->heap()->prototype_symbol()) &&
=======================================
--- /branches/bleeding_edge/src/stub-cache.cc   Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/stub-cache.cc   Mon Jan 21 09:17:02 2013
@@ -346,23 +346,6 @@
   JSObject::UpdateMapCodeCache(receiver, name, code);
   return code;
 }
-
-
-Handle<Code> StubCache::ComputeKeyedLoadArrayLength(Handle<String> name,
- Handle<JSArray> receiver) {
-  Code::Flags flags =
-      Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, Code::CALLBACKS);
-  Handle<Object> probe(receiver->map()->FindInCodeCache(*name, flags),
-                       isolate_);
-  if (probe->IsCode()) return Handle<Code>::cast(probe);
-
-  KeyedLoadStubCompiler compiler(isolate_);
-  Handle<Code> code = compiler.CompileLoadArrayLength(name);
- PROFILE(isolate_, CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, *code, *name));
-  GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, *name, *code));
-  JSObject::UpdateMapCodeCache(receiver, name, code);
-  return code;
-}


 Handle<Code> StubCache::ComputeKeyedLoadFunctionPrototype(
=======================================
--- /branches/bleeding_edge/src/stub-cache.h    Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/stub-cache.h    Mon Jan 21 09:17:02 2013
@@ -133,9 +133,6 @@
                                            Handle<JSObject> receiver,
                                            Handle<JSObject> holder);

-  Handle<Code> ComputeKeyedLoadArrayLength(Handle<String> name,
-                                           Handle<JSArray> receiver);
-
   Handle<Code> ComputeKeyedLoadFunctionPrototype(Handle<String> name,
Handle<JSFunction> receiver);

@@ -667,8 +664,6 @@
                                       Handle<JSObject> holder,
                                       Handle<String> name);

-  Handle<Code> CompileLoadArrayLength(Handle<String> name);
-
   Handle<Code> CompileLoadFunctionPrototype(Handle<String> name);

   Handle<Code> CompileLoadElement(Handle<Map> receiver_map);
=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Mon Jan 21 09:17:02 2013
@@ -2358,6 +2358,33 @@
     __ ret(0);
   }
 }
+
+
+void ArrayLengthStub::Generate(MacroAssembler* masm) {
+  Label miss;
+  Register receiver;
+  if (kind() == Code::KEYED_LOAD_IC) {
+    // ----------- S t a t e -------------
+    //  -- rax    : key
+    //  -- rdx    : receiver
+    //  -- rsp[0] : return address
+    // -----------------------------------
+    __ Cmp(rax, masm->isolate()->factory()->length_symbol());
+    receiver = rdx;
+  } else {
+    ASSERT(kind() == Code::LOAD_IC);
+    // ----------- S t a t e -------------
+    //  -- rax    : receiver
+    //  -- rcx    : name
+    //  -- rsp[0] : return address
+    // -----------------------------------
+    receiver = rax;
+  }
+
+  StubCompiler::GenerateLoadArrayLength(masm, receiver, r8, &miss);
+  __ bind(&miss);
+  StubCompiler::GenerateLoadMiss(masm, kind());
+}


 void StringLengthStub::Generate(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/x64/ic-x64.cc   Mon Jan 21 06:53:29 2013
+++ /branches/bleeding_edge/src/x64/ic-x64.cc   Mon Jan 21 09:17:02 2013
@@ -222,20 +222,6 @@
   __ movq(scratch0, value);
   __ RecordWrite(elements, scratch1, scratch0, kDontSaveFPRegs);
 }
-
-
-void LoadIC::GenerateArrayLength(MacroAssembler* masm) {
-  // ----------- S t a t e -------------
-  //  -- rax    : receiver
-  //  -- rcx    : name
-  //  -- rsp[0] : return address
-  // -----------------------------------
-  Label miss;
-
-  StubCompiler::GenerateLoadArrayLength(masm, rax, rdx, &miss);
-  __ bind(&miss);
-  StubCompiler::GenerateLoadMiss(masm, Code::LOAD_IC);
-}


 void LoadIC::GenerateFunctionPrototype(MacroAssembler* masm) {
=======================================
--- /branches/bleeding_edge/src/x64/stub-cache-x64.cc Mon Jan 21 06:53:29 2013 +++ /branches/bleeding_edge/src/x64/stub-cache-x64.cc Mon Jan 21 09:17:02 2013
@@ -3126,32 +3126,6 @@
   // Return the generated code.
   return GetCode(Code::INTERCEPTOR, name);
 }
-
-
-Handle<Code> KeyedLoadStubCompiler::CompileLoadArrayLength(
-    Handle<String> name) {
-  // ----------- S t a t e -------------
-  //  -- rax    : key
-  //  -- rdx    : receiver
-  //  -- rsp[0]  : return address
-  // -----------------------------------
-  Label miss;
-
-  Counters* counters = isolate()->counters();
-  __ IncrementCounter(counters->keyed_load_array_length(), 1);
-
-  // Check that the name has not changed.
-  __ Cmp(rax, name);
-  __ j(not_equal, &miss);
-
-  GenerateLoadArrayLength(masm(), rdx, rcx, &miss);
-  __ bind(&miss);
-  __ DecrementCounter(counters->keyed_load_array_length(), 1);
-  GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
-
-  // Return the generated code.
-  return GetCode(Code::CALLBACKS, name);
-}


 Handle<Code> KeyedLoadStubCompiler::CompileLoadFunctionPrototype(

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to