Revision: 3745
Author: [email protected]
Date: Fri Jan 29 04:41:11 2010
Log: Removing redundant stub for runtime native calls.
Review URL: http://codereview.chromium.org/543207
http://code.google.com/p/v8/source/detail?r=3745

Modified:
 /branches/bleeding_edge/src/arm/codegen-arm.cc
 /branches/bleeding_edge/src/arm/debug-arm.cc
 /branches/bleeding_edge/src/arm/macro-assembler-arm.cc
 /branches/bleeding_edge/src/code-stubs.h
 /branches/bleeding_edge/src/codegen.cc
 /branches/bleeding_edge/src/codegen.h
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/debug.h
 /branches/bleeding_edge/src/disassembler.cc
 /branches/bleeding_edge/src/full-codegen.cc
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/ia32/codegen-ia32.cc
 /branches/bleeding_edge/src/ia32/debug-ia32.cc
 /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc
 /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/runtime.h
 /branches/bleeding_edge/src/x64/codegen-x64.cc
 /branches/bleeding_edge/src/x64/debug-x64.cc
 /branches/bleeding_edge/src/x64/macro-assembler-x64.cc
 /branches/bleeding_edge/test/cctest/test-debug.cc

=======================================
--- /branches/bleeding_edge/src/arm/codegen-arm.cc      Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/arm/codegen-arm.cc      Fri Jan 29 04:41:11 2010
@@ -2286,7 +2286,8 @@
   Comment cmnt(masm_, "[ DebuggerStatament");
   CodeForStatementPosition(node);
 #ifdef ENABLE_DEBUGGER_SUPPORT
-  frame_->CallRuntime(Runtime::kDebugBreak, 0);
+  DebugerStatementStub ces;
+  frame_->CallStub(&ces, 0);
 #endif
   // Ignore the return value.
   ASSERT(frame_->height() == original_height);
=======================================
--- /branches/bleeding_edge/src/arm/debug-arm.cc        Mon Nov 30 07:09:49 2009
+++ /branches/bleeding_edge/src/arm/debug-arm.cc        Fri Jan 29 04:41:11 2010
@@ -98,7 +98,7 @@
   __ mov(r0, Operand(0));  // no arguments
   __ mov(r1, Operand(ExternalReference::debug_break()));

-  CEntryDebugBreakStub ceb;
+  CEntryStub ceb(1);
   __ CallStub(&ceb);

// Restore the register values containing object pointers from the expression
=======================================
--- /branches/bleeding_edge/src/arm/macro-assembler-arm.cc Thu Jan 21 04:10:56 2010 +++ /branches/bleeding_edge/src/arm/macro-assembler-arm.cc Fri Jan 29 04:41:11 2010
@@ -1035,9 +1035,13 @@
     return;
   }

-  Runtime::FunctionId function_id =
-      static_cast<Runtime::FunctionId>(f->stub_id);
-  RuntimeStub stub(function_id, num_arguments);
+  // TODO(1236192): Most runtime routines don't need the number of
+  // arguments passed in because it is constant. At some point we
+  // should remove this need and make the runtime routine entry code
+  // smarter.
+  mov(r0, Operand(num_arguments));
+  mov(r1, Operand(ExternalReference(f)));
+  CEntryStub stub(1);
   CallStub(&stub);
 }

=======================================
--- /branches/bleeding_edge/src/code-stubs.h    Fri Jan  8 03:58:15 2010
+++ /branches/bleeding_edge/src/code-stubs.h    Fri Jan 29 04:41:11 2010
@@ -55,9 +55,9 @@
   V(CounterOp)                           \
   V(ArgumentsAccess)                     \
   V(RegExpExec)                          \
-  V(Runtime)                             \
   V(CEntry)                              \
-  V(JSEntry)
+  V(JSEntry)                             \
+  V(DebuggerStatement)

 // List of code stubs only used on ARM platforms.
 #ifdef V8_TARGET_ARCH_ARM
=======================================
--- /branches/bleeding_edge/src/codegen.cc      Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/codegen.cc      Fri Jan 29 04:41:11 2010
@@ -450,11 +450,6 @@
     masm()->RecordPosition(pos);
   }
 }
-
-
-const char* RuntimeStub::GetName() {
-  return Runtime::FunctionForId(id_)->stub_name;
-}


 const char* GenericUnaryOpStub::GetName() {
@@ -472,14 +467,6 @@
       return "<unknown>";
   }
 }
-
-
-void RuntimeStub::Generate(MacroAssembler* masm) {
-  Runtime::Function* f = Runtime::FunctionForId(id_);
-  masm->TailCallRuntime(ExternalReference(f),
-                        num_arguments_,
-                        f->result_size);
-}


 void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
@@ -505,6 +492,12 @@
 void ApiGetterEntryStub::SetCustomCache(Code* value) {
   info()->set_load_stub_cache(value);
 }
+
+
+void DebugerStatementStub::Generate(MacroAssembler* masm) {
+  Runtime::Function* f = Runtime::FunctionForId(Runtime::kDebugBreak);
+  masm->TailCallRuntime(ExternalReference(f), 0, f->result_size);
+}


 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/codegen.h       Fri Jan 15 05:42:32 2010
+++ /branches/bleeding_edge/src/codegen.h       Fri Jan 29 04:41:11 2010
@@ -181,43 +181,6 @@
   DISALLOW_COPY_AND_ASSIGN(DeferredCode);
 };

-
-// RuntimeStub models code stubs calling entry points in the Runtime class.
-class RuntimeStub : public CodeStub {
- public:
-  explicit RuntimeStub(Runtime::FunctionId id, int num_arguments)
-      : id_(id), num_arguments_(num_arguments) { }
-
-  void Generate(MacroAssembler* masm);
-
-  // Disassembler support.  It is useful to be able to print the name
-  // of the runtime function called through this stub.
-  static const char* GetNameFromMinorKey(int minor_key) {
-    return Runtime::FunctionForId(IdField::decode(minor_key))->stub_name;
-  }
-
- private:
-  Runtime::FunctionId id_;
-  int num_arguments_;
-
-  class ArgumentField: public BitField<int,  0, 16> {};
- class IdField: public BitField<Runtime::FunctionId, 16, kMinorBits - 16> {};
-
-  Major MajorKey() { return Runtime; }
-  int MinorKey() {
-    return IdField::encode(id_) | ArgumentField::encode(num_arguments_);
-  }
-
-  const char* GetName();
-
-#ifdef DEBUG
-  void Print() {
-    PrintF("RuntimeStub (id %s)\n", Runtime::FunctionForId(id_)->name);
-  }
-#endif
-};
-
-
 class StackCheckStub : public CodeStub {
  public:
   StackCheckStub() { }
@@ -422,16 +385,18 @@
 };


-class CEntryDebugBreakStub : public CEntryStub {
+// Mark the debugger statemet to be recognized bu debugger (by the MajorKey)
+class DebugerStatementStub : public CodeStub {
  public:
-  CEntryDebugBreakStub() : CEntryStub(1) { }
-
-  void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
+  DebugerStatementStub() { }
+
+  void Generate(MacroAssembler* masm);

  private:
-  int MinorKey() { return 1; }
-
-  const char* GetName() { return "CEntryDebugBreakStub"; }
+  Major MajorKey() { return DebuggerStatement; }
+  int MinorKey() { return 0; }
+
+  const char* GetName() { return "DebugerStatementStub"; }
 };


=======================================
--- /branches/bleeding_edge/src/debug.cc        Fri Jan 29 01:52:51 2010
+++ /branches/bleeding_edge/src/debug.cc        Fri Jan 29 04:41:11 2010
@@ -75,9 +75,6 @@
                                              BreakLocatorType type) {
   debug_info_ = debug_info;
   type_ = type;
-  // Get the stub early to avoid possible GC during iterations. We may need
-  // this stub to detect debugger calls generated from debugger statements.
-  debug_break_stub_ = RuntimeStub(Runtime::kDebugBreak, 0).GetCode();
   reloc_iterator_ = NULL;
   reloc_iterator_original_ = NULL;
   Reset();  // Initialize the rest of the member variables.
@@ -461,9 +458,7 @@
     Code* code = Code::GetCodeFromTargetAddress(target);
     if (code->kind() == Code::STUB) {
       CodeStub::Major major_key = code->major_key();
-      if (major_key == CodeStub::Runtime) {
-        return (*debug_break_stub_ == code);
-      }
+      return (major_key == CodeStub::DebuggerStatement);
     }
   }
   return false;
=======================================
--- /branches/bleeding_edge/src/debug.h Fri Jan 29 01:52:51 2010
+++ /branches/bleeding_edge/src/debug.h Fri Jan 29 04:41:11 2010
@@ -132,7 +132,6 @@
   int position_;
   int statement_position_;
   Handle<DebugInfo> debug_info_;
-  Handle<Code> debug_break_stub_;
   RelocIterator* reloc_iterator_;
   RelocIterator* reloc_iterator_original_;

=======================================
--- /branches/bleeding_edge/src/disassembler.cc Wed Nov 11 01:50:06 2009
+++ /branches/bleeding_edge/src/disassembler.cc Fri Jan 29 04:41:11 2010
@@ -266,13 +266,7 @@
               case CodeStub::CallFunction:
                 out.AddFormatted("argc = %d", minor_key);
                 break;
-              case CodeStub::Runtime: {
-                const char* name =
-                    RuntimeStub::GetNameFromMinorKey(minor_key);
-                out.AddFormatted("%s", name);
-                break;
-              }
-              default:
+            default:
                 out.AddFormatted("minor: %d", minor_key);
             }
           }
=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Thu Jan 28 00:15:00 2010
+++ /branches/bleeding_edge/src/full-codegen.cc Fri Jan 29 04:41:11 2010
@@ -998,7 +998,9 @@
 #ifdef ENABLE_DEBUGGER_SUPPORT
   Comment cmnt(masm_, "[ DebuggerStatement");
   SetStatementPosition(stmt);
-  __ CallRuntime(Runtime::kDebugBreak, 0);
+
+  DebugerStatementStub ces;
+  __ CallStub(&ces);
   // Ignore the return value.
 #endif
 }
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Jan 29 03:46:55 2010
+++ /branches/bleeding_edge/src/heap.cc Fri Jan 29 04:41:11 2010
@@ -1499,7 +1499,7 @@


 void Heap::CreateCEntryDebugBreakStub() {
-  CEntryDebugBreakStub stub;
+  DebugerStatementStub stub;
   set_c_entry_debug_break_code(*stub.GetCode());
 }

@@ -1526,7 +1526,7 @@
   // {  CEntryStub stub;
   //    c_entry_code_ = *stub.GetCode();
   // }
-  // {  CEntryDebugBreakStub stub;
+  // {  DebugerStatementStub stub;
   //    c_entry_debug_break_code_ = *stub.GetCode();
   // }
   // To workaround the problem, make separate functions without inlining.
=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.cc Fri Jan 29 03:55:40 2010 +++ /branches/bleeding_edge/src/ia32/codegen-ia32.cc Fri Jan 29 04:41:11 2010
@@ -3901,7 +3901,9 @@
 #ifdef ENABLE_DEBUGGER_SUPPORT
   // Spill everything, even constants, to the frame.
   frame_->SpillAll();
-  frame_->CallRuntime(Runtime::kDebugBreak, 0);
+
+  DebugerStatementStub ces;
+  frame_->CallStub(&ces, 0);
   // Ignore the return value.
 #endif
 }
=======================================
--- /branches/bleeding_edge/src/ia32/debug-ia32.cc      Mon Nov 30 07:09:49 2009
+++ /branches/bleeding_edge/src/ia32/debug-ia32.cc      Fri Jan 29 04:41:11 2010
@@ -94,7 +94,7 @@
   __ Set(eax, Immediate(0));  // no arguments
   __ mov(ebx, Immediate(ExternalReference::debug_break()));

-  CEntryDebugBreakStub ceb;
+  CEntryStub ceb(1);
   __ CallStub(&ceb);

// Restore the register values containing object pointers from the expression
=======================================
--- /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc Thu Jan 21 04:10:56 2010 +++ /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc Fri Jan 29 04:41:11 2010
@@ -1098,10 +1098,14 @@
     return;
   }

-  Runtime::FunctionId function_id =
-      static_cast<Runtime::FunctionId>(f->stub_id);
-  RuntimeStub stub(function_id, num_arguments);
-  CallStub(&stub);
+  // TODO(1236192): Most runtime routines don't need the number of
+  // arguments passed in because it is constant. At some point we
+  // should remove this need and make the runtime routine entry code
+  // smarter.
+  Set(eax, Immediate(num_arguments));
+  mov(ebx, Immediate(ExternalReference(f)));
+  CEntryStub ces(1);
+  CallStub(&ces);
 }


@@ -1114,10 +1118,14 @@
     return Heap::undefined_value();
   }

-  Runtime::FunctionId function_id =
-      static_cast<Runtime::FunctionId>(f->stub_id);
-  RuntimeStub stub(function_id, num_arguments);
-  return TryCallStub(&stub);
+  // TODO(1236192): Most runtime routines don't need the number of
+  // arguments passed in because it is constant. At some point we
+  // should remove this need and make the runtime routine entry code
+  // smarter.
+  Set(eax, Immediate(num_arguments));
+  mov(ebx, Immediate(ExternalReference(f)));
+  CEntryStub ces(1);
+  return TryCallStub(&ces);
 }


=======================================
--- /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h Thu Jan 21 04:10:56 2010 +++ /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h Fri Jan 29 04:41:11 2010
@@ -331,7 +331,7 @@
   // Eventually this should be used for all C calls.
   void CallRuntime(Runtime::Function* f, int num_arguments);

-  // Call a runtime function, returning the RuntimeStub object called.
+  // Call a runtime function, returning the CodeStub object called.
   // Try to generate the stub code if necessary.  Do not perform a GC
   // but instead return a retry after GC failure.
   Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Fri Jan 29 03:46:55 2010
+++ /branches/bleeding_edge/src/runtime.cc      Fri Jan 29 04:41:11 2010
@@ -8130,12 +8130,12 @@
 // Implementation of Runtime

 #define F(name, nargs, ressize)                                           \
-  { #name, "RuntimeStub_" #name, FUNCTION_ADDR(Runtime_##name), nargs, \
+  { #name, FUNCTION_ADDR(Runtime_##name), nargs, \
     static_cast<int>(Runtime::k##name), ressize },

 static Runtime::Function Runtime_functions[] = {
   RUNTIME_FUNCTION_LIST(F)
-  { NULL, NULL, NULL, 0, -1, 0 }
+  { NULL, NULL, 0, -1, 0 }
 };

 #undef F
=======================================
--- /branches/bleeding_edge/src/runtime.h       Tue Jan 19 04:56:36 2010
+++ /branches/bleeding_edge/src/runtime.h       Fri Jan 29 04:41:11 2010
@@ -373,9 +373,6 @@
     // The JS name of the function.
     const char* name;

-    // The name of the stub that calls the runtime function.
-    const char* stub_name;
-
     // The C++ (native) entry point.
     byte* entry;

=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.cc      Fri Jan 29 03:55:40 2010
+++ /branches/bleeding_edge/src/x64/codegen-x64.cc      Fri Jan 29 04:41:11 2010
@@ -2212,7 +2212,9 @@
 #ifdef ENABLE_DEBUGGER_SUPPORT
   // Spill everything, even constants, to the frame.
   frame_->SpillAll();
-  frame_->CallRuntime(Runtime::kDebugBreak, 0);
+
+  DebugerStatementStub ces;
+  frame_->CallStub(&ces, 0);
   // Ignore the return value.
 #endif
 }
@@ -7337,9 +7339,7 @@
 #ifdef _WIN64
   // Simple results returned in rax (using default code).
   // Complex results must be written to address passed as first argument.
-  // Use even numbers for minor keys, reserving the odd numbers for
-  // CEntryDebugBreakStub.
-  return (result_size_ < 2) ? 0 : result_size_ * 2;
+  return (result_size_ < 2) ? 0 : 1;
 #else
// Single results returned in rax (both AMD64 and Win64 calling conventions) // and a struct of two pointers in rax+rdx (AMD64 calling convention only)
=======================================
--- /branches/bleeding_edge/src/x64/debug-x64.cc        Mon Nov 30 07:09:49 2009
+++ /branches/bleeding_edge/src/x64/debug-x64.cc        Fri Jan 29 04:41:11 2010
@@ -68,7 +68,7 @@
   __ xor_(rax, rax);  // No arguments (argc == 0).
   __ movq(rbx, ExternalReference::debug_break());

-  CEntryDebugBreakStub ceb;
+  CEntryStub ceb(1);
   __ CallStub(&ceb);

// Restore the register values containing object pointers from the expression
=======================================
--- /branches/bleeding_edge/src/x64/macro-assembler-x64.cc Fri Jan 29 02:33:27 2010 +++ /branches/bleeding_edge/src/x64/macro-assembler-x64.cc Fri Jan 29 04:41:11 2010
@@ -344,10 +344,14 @@
     return;
   }

-  Runtime::FunctionId function_id =
-      static_cast<Runtime::FunctionId>(f->stub_id);
-  RuntimeStub stub(function_id, num_arguments);
-  CallStub(&stub);
+  // TODO(1236192): Most runtime routines don't need the number of
+  // arguments passed in because it is constant. At some point we
+  // should remove this need and make the runtime routine entry code
+  // smarter.
+  movq(rax, Immediate(num_arguments));
+  movq(rbx, ExternalReference(f));
+  CEntryStub ces(f->result_size);
+  CallStub(&ces);
 }


=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Tue Jan 26 00:44:50 2010 +++ /branches/bleeding_edge/test/cctest/test-debug.cc Fri Jan 29 04:41:11 2010
@@ -2045,6 +2045,33 @@
   v8::Debug::SetDebugEventListener(NULL);
   CheckDebuggerUnloaded();
 }
+
+
+// Test setting a breakpoint on the  debugger statement.
+TEST(DebuggerStatementBreakpoint) {
+    break_point_hit_count = 0;
+    v8::HandleScope scope;
+    DebugLocalContext env;
+    v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
+                                     v8::Undefined());
+ v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run();
+    v8::Local<v8::Function> foo =
+ v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
+
+    // The debugger statement triggers breakpint hit
+    foo->Call(env->Global(), 0, NULL);
+    CHECK_EQ(1, break_point_hit_count);
+
+    int bp = SetBreakPoint(foo, 0);
+
+    // Set breakpoint does not duplicate hits
+    foo->Call(env->Global(), 0, NULL);
+    CHECK_EQ(2, break_point_hit_count);
+
+    ClearBreakPoint(bp);
+    v8::Debug::SetDebugEventListener(NULL);
+    CheckDebuggerUnloaded();
+}


// Thest that the evaluation of expressions when a break point is hit generates

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

Reply via email to