Revision: 10671
Author:   [email protected]
Date:     Fri Feb 10 00:47:35 2012
Log:      Streamline throwing in the C entry stub.

Remove a gratuitous level of indirection in favor of direct calls to the
macro assembler, and eliminate some duplicated code for the uncatchable
case.

[email protected]
BUG=
TEST=

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

Modified:
 /branches/bleeding_edge/src/arm/code-stubs-arm.cc
 /branches/bleeding_edge/src/arm/macro-assembler-arm.cc
 /branches/bleeding_edge/src/arm/macro-assembler-arm.h
 /branches/bleeding_edge/src/code-stubs.h
 /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
 /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc
 /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h
 /branches/bleeding_edge/src/macro-assembler.h
 /branches/bleeding_edge/src/mips/code-stubs-mips.cc
 /branches/bleeding_edge/src/mips/macro-assembler-mips.cc
 /branches/bleeding_edge/src/mips/macro-assembler-mips.h
 /branches/bleeding_edge/src/x64/code-stubs-x64.cc
 /branches/bleeding_edge/src/x64/macro-assembler-x64.cc
 /branches/bleeding_edge/src/x64/macro-assembler-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Fri Feb 10 00:47:35 2012
@@ -3672,17 +3672,6 @@
   Handle<Code> code = stub.GetCode();
   code->set_is_pregenerated(true);
 }
-
-
-void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) {
-  __ Throw(r0);
-}
-
-
-void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm,
-                                          UncatchableExceptionType type) {
-  __ ThrowUncatchable(type, r0);
-}


 void CEntryStub::GenerateCore(MacroAssembler* masm,
@@ -3865,13 +3854,27 @@
                true);

   __ bind(&throw_out_of_memory_exception);
-  GenerateThrowUncatchable(masm, OUT_OF_MEMORY);
+  // Set external caught exception to false.
+  Isolate* isolate = masm->isolate();
+ ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
+                                    isolate);
+  __ mov(r0, Operand(false, RelocInfo::NONE));
+  __ mov(r2, Operand(external_caught));
+  __ str(r0, MemOperand(r2));
+
+  // Set pending exception and r0 to out of memory exception.
+  Failure* out_of_memory = Failure::OutOfMemoryException();
+  __ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory)));
+  __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
+                                       isolate)));
+  __ str(r0, MemOperand(r2));
+  // Fall through to the next label.

   __ bind(&throw_termination_exception);
-  GenerateThrowUncatchable(masm, TERMINATION);
+  __ ThrowUncatchable(r0);

   __ bind(&throw_normal_exception);
-  GenerateThrowTOS(masm);
+  __ Throw(r0);
 }


@@ -4912,10 +4915,10 @@
   Label termination_exception;
   __ b(eq, &termination_exception);

-  __ Throw(r0);  // Expects thrown value in r0.
+  __ Throw(r0);

   __ bind(&termination_exception);
-  __ ThrowUncatchable(TERMINATION, r0);  // Expects thrown value in r0.
+  __ ThrowUncatchable(r0);

   __ bind(&failure);
   // For failure and exception return null.
=======================================
--- /branches/bleeding_edge/src/arm/macro-assembler-arm.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/arm/macro-assembler-arm.cc Fri Feb 10 00:47:35 2012
@@ -1281,8 +1281,7 @@
 }


-void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type,
-                                      Register value) {
+void MacroAssembler::ThrowUncatchable(Register value) {
   // Adjust this code if not the case.
   STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
   STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
@@ -1292,24 +1291,9 @@
   STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);

   // The exception is expected in r0.
-  if (type == OUT_OF_MEMORY) {
-    // Set external caught exception to false.
- ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
-                                      isolate());
-    mov(r0, Operand(false, RelocInfo::NONE));
-    mov(r2, Operand(external_caught));
-    str(r0, MemOperand(r2));
-
-    // Set pending exception and r0 to out of memory exception.
-    Failure* out_of_memory = Failure::OutOfMemoryException();
-    mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory)));
-    mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
-                                      isolate())));
-    str(r0, MemOperand(r2));
-  } else if (!value.is(r0)) {
+  if (!value.is(r0)) {
     mov(r0, value);
   }
-
   // Drop the stack pointer to the top of the top stack handler.
   mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
   ldr(sp, MemOperand(r3));
=======================================
--- /branches/bleeding_edge/src/arm/macro-assembler-arm.h Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/arm/macro-assembler-arm.h Fri Feb 10 00:47:35 2012
@@ -588,12 +588,12 @@
   // Must preserve the result register.
   void PopTryHandler();

- // Passes thrown value (in r0) to the handler of top of the try handler chain.
+  // Passes thrown value to the handler of top of the try handler chain.
   void Throw(Register value);

// Propagates an uncatchable exception to the top of the current JS stack's
   // handler chain.
-  void ThrowUncatchable(UncatchableExceptionType type, Register value);
+  void ThrowUncatchable(Register value);

// ---------------------------------------------------------------------------
   // Inline caching support
=======================================
--- /branches/bleeding_edge/src/code-stubs.h    Fri Jan 27 08:09:20 2012
+++ /branches/bleeding_edge/src/code-stubs.h    Fri Feb 10 00:47:35 2012
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -632,9 +632,6 @@
                     Label* throw_out_of_memory_exception,
                     bool do_gc,
                     bool always_allocate_scope);
-  void GenerateThrowTOS(MacroAssembler* masm);
-  void GenerateThrowUncatchable(MacroAssembler* masm,
-                                UncatchableExceptionType type);

   // Number of pointers/values returned.
   const int result_size_;
=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Fri Feb 10 00:47:35 2012
@@ -3922,7 +3922,7 @@
   __ Throw(eax);

   __ bind(&throw_termination_exception);
-  __ ThrowUncatchable(TERMINATION, eax);
+  __ ThrowUncatchable(eax);

   __ bind(&failure);
   // For failure to match, return null.
@@ -4778,11 +4778,6 @@
   Handle<Code> code = stub.GetCode();
   code->set_is_pregenerated(true);
 }
-
-
-void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) {
-  __ Throw(eax);
-}


 void CEntryStub::GenerateCore(MacroAssembler* masm,
@@ -4901,12 +4896,6 @@
   // Retry.
   __ bind(&retry);
 }
-
-
-void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm,
-                                          UncatchableExceptionType type) {
-  __ ThrowUncatchable(type, eax);
-}


 void CEntryStub::Generate(MacroAssembler* masm) {
@@ -4962,13 +4951,24 @@
                true);

   __ bind(&throw_out_of_memory_exception);
-  GenerateThrowUncatchable(masm, OUT_OF_MEMORY);
+  // Set external caught exception to false.
+  Isolate* isolate = masm->isolate();
+ ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
+                                    isolate);
+  __ mov(Operand::StaticVariable(external_caught), Immediate(false));
+
+  // Set pending exception and eax to out of memory exception.
+  ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
+                                      isolate);
+  __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException()));
+  __ mov(Operand::StaticVariable(pending_exception), eax);
+  // Fall through to the next label.

   __ bind(&throw_termination_exception);
-  GenerateThrowUncatchable(masm, TERMINATION);
+  __ ThrowUncatchable(eax);

   __ bind(&throw_normal_exception);
-  GenerateThrowTOS(masm);
+  __ Throw(eax);
 }


=======================================
--- /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/ia32/macro-assembler-ia32.cc Fri Feb 10 00:47:35 2012
@@ -862,8 +862,7 @@
 }


-void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type,
-                                      Register value) {
+void MacroAssembler::ThrowUncatchable(Register value) {
   // Adjust this code if not the case.
   STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
   STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
@@ -873,21 +872,9 @@
   STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);

   // The exception is expected in eax.
-  if (type == OUT_OF_MEMORY) {
-    // Set external caught exception to false.
- ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
-                                      isolate());
-    mov(Operand::StaticVariable(external_caught), Immediate(false));
-
-    // Set pending exception and eax to out of memory exception.
-    ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
-                                        isolate());
-    mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException()));
-    mov(Operand::StaticVariable(pending_exception), eax);
-  } else if (!value.is(eax)) {
+  if (!value.is(eax)) {
     mov(eax, value);
   }
-
   // Drop the stack pointer to the top of the top stack handler.
   ExternalReference handler_address(Isolate::kHandlerAddress, isolate());
   mov(esp, Operand::StaticVariable(handler_address));
=======================================
--- /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/ia32/macro-assembler-ia32.h Fri Feb 10 00:47:35 2012
@@ -496,10 +496,11 @@
// Unlink the stack handler on top of the stack from the try handler chain.
   void PopTryHandler();

-  // Activate the top handler in the try hander chain.
+  // Throw to the top handler in the try hander chain.
   void Throw(Register value);

-  void ThrowUncatchable(UncatchableExceptionType type, Register value);
+  // Throw past all JS frames to the top JS entry frame.
+  void ThrowUncatchable(Register value);

// ---------------------------------------------------------------------------
   // Inline caching support
=======================================
--- /branches/bleeding_edge/src/macro-assembler.h       Thu Feb  9 01:43:37 2012
+++ /branches/bleeding_edge/src/macro-assembler.h       Fri Feb 10 00:47:35 2012
@@ -36,13 +36,6 @@
 };


-// Types of uncatchable exceptions.
-enum UncatchableExceptionType {
-  OUT_OF_MEMORY,
-  TERMINATION
-};
-
-
 // Invalid depth in prototype chain.
 const int kInvalidProtoDepth = -1;

=======================================
--- /branches/bleeding_edge/src/mips/code-stubs-mips.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/mips/code-stubs-mips.cc Fri Feb 10 00:47:35 2012
@@ -3830,17 +3830,6 @@
   Handle<Code> code = stub.GetCode();
   code->set_is_pregenerated(true);
 }
-
-
-void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) {
-  __ Throw(v0);
-}
-
-
-void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm,
-                                          UncatchableExceptionType type) {
-  __ ThrowUncatchable(type, v0);
-}


 void CEntryStub::GenerateCore(MacroAssembler* masm,
@@ -4033,13 +4022,27 @@
                true);

   __ bind(&throw_out_of_memory_exception);
-  GenerateThrowUncatchable(masm, OUT_OF_MEMORY);
+  // Set external caught exception to false.
+  Isolate* isolate = masm->isolate();
+ ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
+                                    isolate);
+  __ li(a0, Operand(false, RelocInfo::NONE));
+  __ li(a2, Operand(external_caught));
+  __ sw(a0, MemOperand(a2));
+
+  // Set pending exception and v0 to out of memory exception.
+  Failure* out_of_memory = Failure::OutOfMemoryException();
+  __ li(v0, Operand(reinterpret_cast<int32_t>(out_of_memory)));
+  __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
+                                      isolate)));
+  __ sw(v0, MemOperand(a2));
+  // Fall through to the next label.

   __ bind(&throw_termination_exception);
-  GenerateThrowUncatchable(masm, TERMINATION);
+  __ ThrowUncatchable(v0);

   __ bind(&throw_normal_exception);
-  GenerateThrowTOS(masm);
+  __ Throw(v0);
 }


@@ -5133,10 +5136,10 @@
   Label termination_exception;
   __ Branch(&termination_exception, eq, v0, Operand(a0));

-  __ Throw(v0);  // Expects thrown value in v0.
+  __ Throw(v0);

   __ bind(&termination_exception);
-  __ ThrowUncatchable(TERMINATION, v0);  // Expects thrown value in v0.
+  __ ThrowUncatchable(v0);

   __ bind(&failure);
   // For failure and exception return null.
=======================================
--- /branches/bleeding_edge/src/mips/macro-assembler-mips.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/mips/macro-assembler-mips.cc Fri Feb 10 00:47:35 2012
@@ -2679,8 +2679,7 @@
 }


-void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type,
-                                      Register value) {
+void MacroAssembler::ThrowUncatchable(Register value) {
   // Adjust this code if not the case.
   STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
   STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize);
@@ -2690,24 +2689,9 @@
   STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);

   // The exception is expected in v0.
-  if (type == OUT_OF_MEMORY) {
-    // Set external caught exception to false.
- ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
-                                      isolate());
-    li(a0, Operand(false, RelocInfo::NONE));
-    li(a2, Operand(external_caught));
-    sw(a0, MemOperand(a2));
-
-    // Set pending exception and v0 to out of memory exception.
-    Failure* out_of_memory = Failure::OutOfMemoryException();
-    li(v0, Operand(reinterpret_cast<int32_t>(out_of_memory)));
-    li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
-                                     isolate())));
-    sw(v0, MemOperand(a2));
-  } else if (!value.is(v0)) {
+  if (!value.is(v0)) {
     mov(v0, value);
   }
-
   // Drop the stack pointer to the top of the top stack handler.
   li(a3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate())));
   lw(sp, MemOperand(a3));
=======================================
--- /branches/bleeding_edge/src/mips/macro-assembler-mips.h Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/mips/macro-assembler-mips.h Fri Feb 10 00:47:35 2012
@@ -871,12 +871,12 @@
   // Must preserve the result register.
   void PopTryHandler();

- // Passes thrown value (in v0) to the handler of top of the try handler chain.
+  // Passes thrown value to the handler of top of the try handler chain.
   void Throw(Register value);

// Propagates an uncatchable exception to the top of the current JS stack's
   // handler chain.
-  void ThrowUncatchable(UncatchableExceptionType type, Register value);
+  void ThrowUncatchable(Register value);

   // Copies a fixed number of fields of heap objects from src to dst.
void CopyFields(Register dst, Register src, RegList temps, int field_count);
=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Fri Feb 10 00:47:35 2012
@@ -3054,7 +3054,7 @@
   __ Throw(rax);

   __ bind(&termination_exception);
-  __ ThrowUncatchable(TERMINATION, rax);
+  __ ThrowUncatchable(rax);

   // External string.  Short external strings have already been ruled out.
   // rdi: subject string (expected to be external)
@@ -3773,12 +3773,6 @@
   CEntryStub save_doubles(1, kSaveFPRegs);
   save_doubles.GetCode()->set_is_pregenerated(true);
 }
-
-
-void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) {
-  // Throw exception in eax.
-  __ Throw(rax);
-}


 void CEntryStub::GenerateCore(MacroAssembler* masm,
@@ -3919,12 +3913,6 @@
   // Retry.
   __ bind(&retry);
 }
-
-
-void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm,
-                                          UncatchableExceptionType type) {
-  __ ThrowUncatchable(type, rax);
-}


 void CEntryStub::Generate(MacroAssembler* masm) {
@@ -3990,13 +3978,25 @@
                true);

   __ bind(&throw_out_of_memory_exception);
-  GenerateThrowUncatchable(masm, OUT_OF_MEMORY);
+  // Set external caught exception to false.
+  Isolate* isolate = masm->isolate();
+ ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
+                                    isolate);
+  __ Set(rax, static_cast<int64_t>(false));
+  __ Store(external_caught, rax);
+
+  // Set pending exception and rax to out of memory exception.
+  ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
+                                      isolate);
+  __ movq(rax, Failure::OutOfMemoryException(), RelocInfo::NONE);
+  __ Store(pending_exception, rax);
+  // Fall through to the next label.

   __ bind(&throw_termination_exception);
-  GenerateThrowUncatchable(masm, TERMINATION);
+  __ ThrowUncatchable(rax);

   __ bind(&throw_normal_exception);
-  GenerateThrowTOS(masm);
+  __ Throw(rax);
 }


=======================================
--- /branches/bleeding_edge/src/x64/macro-assembler-x64.cc Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/x64/macro-assembler-x64.cc Fri Feb 10 00:47:35 2012
@@ -2552,8 +2552,7 @@
 }


-void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type,
-                                      Register value) {
+void MacroAssembler::ThrowUncatchable(Register value) {
   // Adjust this code if not the case.
   STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize);
   STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
@@ -2563,22 +2562,9 @@
   STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize);

   // The exception is expected in rax.
-  if (type == OUT_OF_MEMORY) {
-    // Set external caught exception to false.
- ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
-                                      isolate());
-    Set(rax, static_cast<int64_t>(false));
-    Store(external_caught, rax);
-
-    // Set pending exception and rax to out of memory exception.
-    ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
-                                        isolate());
-    movq(rax, Failure::OutOfMemoryException(), RelocInfo::NONE);
-    Store(pending_exception, rax);
-  } else if (!value.is(rax)) {
+  if (!value.is(rax)) {
     movq(rax, value);
   }
-
   // Drop the stack pointer to the top of the top stack handler.
   ExternalReference handler_address(Isolate::kHandlerAddress, isolate());
   Load(rsp, handler_address);
=======================================
--- /branches/bleeding_edge/src/x64/macro-assembler-x64.h Thu Feb 9 01:43:37 2012 +++ /branches/bleeding_edge/src/x64/macro-assembler-x64.h Fri Feb 10 00:47:35 2012
@@ -971,7 +971,7 @@
   void Throw(Register value);

   // Propagate an uncatchable exception out of the current JS stack.
-  void ThrowUncatchable(UncatchableExceptionType type, Register value);
+  void ThrowUncatchable(Register value);

// ---------------------------------------------------------------------------
   // Inline caching support

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

Reply via email to