Revision: 24138
Author:   [email protected]
Date:     Tue Sep 23 08:46:18 2014 UTC
Log: [Turbofan] Insert nops for lazy bailout patching, fix translation of literals.

The code for EnsureSpaceForLazyDeopt is taken from lithium-codegen-*.

BUG=
[email protected]

Review URL: https://codereview.chromium.org/562033003
https://code.google.com/p/v8/source/detail?r=24138

Modified:
 /branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc
 /branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc
 /branches/bleeding_edge/src/compiler/code-generator.cc
 /branches/bleeding_edge/src/compiler/code-generator.h
 /branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc
 /branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc
 /branches/bleeding_edge/test/mjsunit/regress/string-set-char-deopt.js

=======================================
--- /branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc Mon Sep 22 13:56:03 2014 UTC +++ /branches/bleeding_edge/src/compiler/arm/code-generator-arm.cc Tue Sep 23 08:46:18 2014 UTC
@@ -137,6 +137,7 @@

   switch (ArchOpcodeField::decode(instr->opcode())) {
     case kArchCallCodeObject: {
+      EnsureSpaceForLazyDeopt();
       if (instr->InputAt(0)->IsImmediate()) {
         __ Call(Handle<Code>::cast(i.InputHeapObject(0)),
                 RelocInfo::CODE_TARGET);
@@ -150,6 +151,7 @@
       break;
     }
     case kArchCallJSFunction: {
+      EnsureSpaceForLazyDeopt();
       Register func = i.InputRegister(0);
       if (FLAG_debug_code) {
         // Check the function's context matches the context argument.
@@ -842,6 +844,27 @@
 void CodeGenerator::AddNopForSmiCodeInlining() {
   // On 32-bit ARM we do not insert nops for inlined Smi code.
 }
+
+
+void CodeGenerator::EnsureSpaceForLazyDeopt() {
+  int space_needed = Deoptimizer::patch_size();
+  if (!linkage()->info()->IsStub()) {
+    // Ensure that we have enough space after the previous lazy-bailout
+    // instruction for patching the code here.
+    int current_pc = masm()->pc_offset();
+    if (current_pc < last_lazy_deopt_pc_ + space_needed) {
+      // Block literal pool emission for duration of padding.
+ v8::internal::Assembler::BlockConstPoolScope block_const_pool(masm());
+      int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
+      DCHECK_EQ(0, padding_size % v8::internal::Assembler::kInstrSize);
+      while (padding_size > 0) {
+        __ nop();
+        padding_size -= v8::internal::Assembler::kInstrSize;
+      }
+    }
+  }
+  MarkLazyDeoptSite();
+}

 #undef __

=======================================
--- /branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc Mon Sep 22 13:56:03 2014 UTC +++ /branches/bleeding_edge/src/compiler/arm64/code-generator-arm64.cc Tue Sep 23 08:46:18 2014 UTC
@@ -132,6 +132,7 @@
   InstructionCode opcode = instr->opcode();
   switch (ArchOpcodeField::decode(opcode)) {
     case kArchCallCodeObject: {
+      EnsureSpaceForLazyDeopt();
       if (instr->InputAt(0)->IsImmediate()) {
         __ Call(Handle<Code>::cast(i.InputHeapObject(0)),
                 RelocInfo::CODE_TARGET);
@@ -144,6 +145,7 @@
       break;
     }
     case kArchCallJSFunction: {
+      EnsureSpaceForLazyDeopt();
       Register func = i.InputRegister(0);
       if (FLAG_debug_code) {
         // Check the function's context matches the context argument.
@@ -843,6 +845,29 @@


 void CodeGenerator::AddNopForSmiCodeInlining() { __ movz(xzr, 0); }
+
+
+void CodeGenerator::EnsureSpaceForLazyDeopt() {
+  int space_needed = Deoptimizer::patch_size();
+  if (!linkage()->info()->IsStub()) {
+    // Ensure that we have enough space after the previous lazy-bailout
+    // instruction for patching the code here.
+    intptr_t current_pc = masm()->pc_offset();
+
+    if (current_pc < (last_lazy_deopt_pc_ + space_needed)) {
+ intptr_t padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
+      DCHECK((padding_size % kInstructionSize) == 0);
+      InstructionAccurateScope instruction_accurate(
+          masm(), padding_size / kInstructionSize);
+
+      while (padding_size > 0) {
+        __ nop();
+        padding_size -= kInstructionSize;
+      }
+    }
+  }
+  MarkLazyDeoptSite();
+}

 #undef __

=======================================
--- /branches/bleeding_edge/src/compiler/code-generator.cc Thu Sep 18 08:56:52 2014 UTC +++ /branches/bleeding_edge/src/compiler/code-generator.cc Tue Sep 23 08:46:18 2014 UTC
@@ -21,7 +21,8 @@
       safepoints_(code->zone()),
       deoptimization_states_(code->zone()),
       deoptimization_literals_(code->zone()),
-      translations_(code->zone()) {}
+      translations_(code->zone()),
+      last_lazy_deopt_pc_(0) {}


 Handle<Code> CodeGenerator::GenerateCode() {
@@ -242,6 +243,7 @@
   }

   if (needs_frame_state) {
+    MarkLazyDeoptSite();
     // If the frame state is present, it starts at argument 1
     // (just after the code address).
     InstructionOperandConverter converter(this, instr);
@@ -387,8 +389,7 @@
             isolate()->factory()->NewNumberFromInt(constant.ToInt32());
         break;
       case Constant::kFloat64:
-        constant_object =
-            isolate()->factory()->NewHeapNumber(constant.ToFloat64());
+ constant_object = isolate()->factory()->NewNumber(constant.ToFloat64());
         break;
       case Constant::kHeapObject:
         constant_object = constant.ToHeapObject();
@@ -402,6 +403,11 @@
     UNREACHABLE();
   }
 }
+
+
+void CodeGenerator::MarkLazyDeoptSite() {
+  last_lazy_deopt_pc_ = masm()->pc_offset();
+}

 #if !V8_TURBOFAN_BACKEND

=======================================
--- /branches/bleeding_edge/src/compiler/code-generator.h Thu Sep 18 08:56:52 2014 UTC +++ /branches/bleeding_edge/src/compiler/code-generator.h Tue Sep 23 08:46:18 2014 UTC
@@ -98,8 +98,10 @@
void AddTranslationForOperand(Translation* translation, Instruction* instr,
                                 InstructionOperand* op);
   void AddNopForSmiCodeInlining();
+  void EnsureSpaceForLazyDeopt();
+  void MarkLazyDeoptSite();
+
// ===========================================================================
-
   struct DeoptimizationState : ZoneObject {
    public:
     BailoutId bailout_id() const { return bailout_id_; }
@@ -126,6 +128,7 @@
   ZoneDeque<DeoptimizationState*> deoptimization_states_;
   ZoneDeque<Handle<Object> > deoptimization_literals_;
   TranslationBuffer translations_;
+  int last_lazy_deopt_pc_;
 };

 }  // namespace compiler
=======================================
--- /branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc Mon Sep 22 13:56:03 2014 UTC +++ /branches/bleeding_edge/src/compiler/ia32/code-generator-ia32.cc Tue Sep 23 08:46:18 2014 UTC
@@ -112,6 +112,7 @@

   switch (ArchOpcodeField::decode(instr->opcode())) {
     case kArchCallCodeObject: {
+      EnsureSpaceForLazyDeopt();
       if (HasImmediateInput(instr, 0)) {
         Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0));
         __ call(code, RelocInfo::CODE_TARGET);
@@ -123,6 +124,7 @@
       break;
     }
     case kArchCallJSFunction: {
+      EnsureSpaceForLazyDeopt();
       Register func = i.InputRegister(0);
       if (FLAG_debug_code) {
         // Check the function's context matches the context argument.
@@ -931,6 +933,21 @@


 void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); }
+
+
+void CodeGenerator::EnsureSpaceForLazyDeopt() {
+  int space_needed = Deoptimizer::patch_size();
+  if (!linkage()->info()->IsStub()) {
+    // Ensure that we have enough space after the previous lazy-bailout
+    // instruction for patching the code here.
+    int current_pc = masm()->pc_offset();
+    if (current_pc < last_lazy_deopt_pc_ + space_needed) {
+      int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
+      __ Nop(padding_size);
+    }
+  }
+  MarkLazyDeoptSite();
+}

 #undef __

=======================================
--- /branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc Mon Sep 22 13:56:03 2014 UTC +++ /branches/bleeding_edge/src/compiler/x64/code-generator-x64.cc Tue Sep 23 08:46:18 2014 UTC
@@ -205,6 +205,7 @@

   switch (ArchOpcodeField::decode(instr->opcode())) {
     case kArchCallCodeObject: {
+      EnsureSpaceForLazyDeopt();
       if (HasImmediateInput(instr, 0)) {
         Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0));
         __ Call(code, RelocInfo::CODE_TARGET);
@@ -217,6 +218,7 @@
       break;
     }
     case kArchCallJSFunction: {
+      EnsureSpaceForLazyDeopt();
       Register func = i.InputRegister(0);
       if (FLAG_debug_code) {
         // Check the function's context matches the context argument.
@@ -990,6 +992,21 @@


 void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); }
+
+
+void CodeGenerator::EnsureSpaceForLazyDeopt() {
+  int space_needed = Deoptimizer::patch_size();
+  if (!linkage()->info()->IsStub()) {
+    // Ensure that we have enough space after the previous lazy-bailout
+    // instruction for patching the code here.
+    int current_pc = masm()->pc_offset();
+    if (current_pc < last_lazy_deopt_pc_ + space_needed) {
+      int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
+      __ Nop(padding_size);
+    }
+  }
+  MarkLazyDeoptSite();
+}

 #undef __

=======================================
--- /branches/bleeding_edge/test/mjsunit/regress/string-set-char-deopt.js Fri Sep 12 10:58:43 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/regress/string-set-char-deopt.js Tue Sep 23 08:46:18 2014 UTC
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// Flags: --allow-natives-syntax
+// Flags: --allow-natives-syntax --turbo-deoptimization

 (function OneByteSeqStringSetCharDeoptOsr() {
   function deopt() {

--
--
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