Revision: 21908
Author:   [email protected]
Date:     Mon Jun 23 07:10:25 2014 UTC
Log:      Introduce intrinsic to expose debug state to generated code.

[email protected]

Review URL: https://codereview.chromium.org/332673002
http://code.google.com/p/v8/source/detail?r=21908

Added:
 /branches/bleeding_edge/test/mjsunit/debug-is-active.js
Modified:
 /branches/bleeding_edge/src/arm/full-codegen-arm.cc
 /branches/bleeding_edge/src/arm64/full-codegen-arm64.cc
 /branches/bleeding_edge/src/array.js
 /branches/bleeding_edge/src/assembler.cc
 /branches/bleeding_edge/src/assembler.h
 /branches/bleeding_edge/src/collection.js
 /branches/bleeding_edge/src/debug.h
 /branches/bleeding_edge/src/hydrogen-instructions.h
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
 /branches/bleeding_edge/src/macros.py
 /branches/bleeding_edge/src/runtime.h
 /branches/bleeding_edge/src/x64/full-codegen-x64.cc

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/debug-is-active.js Mon Jun 23 07:10:25 2014 UTC
@@ -0,0 +1,28 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+Debug = debug.Debug;
+
+function f() { return %_DebugIsActive() != 0; }
+
+assertFalse(f());
+assertFalse(f());
+Debug.setListener(function() {});
+assertTrue(f());
+Debug.setListener(null);
+assertFalse(f());
+
+%OptimizeFunctionOnNextCall(f);
+assertFalse(f());
+assertOptimized(f);
+
+Debug.setListener(function() {});
+assertTrue(f());
+assertOptimized(f);
+
+Debug.setListener(null);
+assertFalse(f());
+assertOptimized(f);
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Tue Jun 17 13:54:49 2014 UTC +++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Mon Jun 23 07:10:25 2014 UTC
@@ -4007,6 +4007,17 @@
   __ bind(&done);
   context()->Plug(r0);
 }
+
+
+void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
+  ASSERT(expr->arguments()->length() == 0);
+  ExternalReference debug_is_active =
+      ExternalReference::debug_is_active_address(isolate());
+  __ mov(ip, Operand(debug_is_active));
+  __ ldrb(r0, MemOperand(ip));
+  __ SmiTag(r0);
+  context()->Plug(r0);
+}


 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/arm64/full-codegen-arm64.cc Tue Jun 17 13:54:49 2014 UTC +++ /branches/bleeding_edge/src/arm64/full-codegen-arm64.cc Mon Jun 23 07:10:25 2014 UTC
@@ -3718,6 +3718,17 @@
   __ Bind(&done);
   context()->Plug(result);
 }
+
+
+void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
+  ASSERT(expr->arguments()->length() == 0);
+  ExternalReference debug_is_active =
+      ExternalReference::debug_is_active_address(isolate());
+  __ Mov(x10, debug_is_active);
+  __ Ldrb(x0, MemOperand(x10));
+  __ SmiTag(x0);
+  context()->Plug(x0);
+}


 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/array.js        Thu May 22 15:27:57 2014 UTC
+++ /branches/bleeding_edge/src/array.js        Mon Jun 23 07:10:25 2014 UTC
@@ -1128,7 +1128,7 @@
   var result = new $Array();
   var accumulator = new InternalArray();
   var accumulator_length = 0;
-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   for (var i = 0; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1161,7 +1161,7 @@
     receiver = ToObject(receiver);
   }

-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   for (var i = 0; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1192,7 +1192,7 @@
     receiver = ToObject(receiver);
   }

-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   for (var i = 0; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1222,7 +1222,7 @@
     receiver = ToObject(receiver);
   }

-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   for (var i = 0; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1253,7 +1253,7 @@

   var result = new $Array();
   var accumulator = new InternalArray(length);
-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   for (var i = 0; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1400,7 +1400,7 @@
   }

   var receiver = %GetDefaultReceiver(callback);
-  var stepping = %_DebugCallbackSupportsStepping(callback);
+ var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
   for (; i < length; i++) {
     if (i in array) {
       var element = array[i];
@@ -1437,7 +1437,7 @@
   }

   var receiver = %GetDefaultReceiver(callback);
-  var stepping = %_DebugCallbackSupportsStepping(callback);
+ var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
   for (; i >= 0; i--) {
     if (i in array) {
       var element = array[i];
=======================================
--- /branches/bleeding_edge/src/assembler.cc    Fri Jun 20 08:40:11 2014 UTC
+++ /branches/bleeding_edge/src/assembler.cc    Mon Jun 23 07:10:25 2014 UTC
@@ -1426,6 +1426,12 @@
   ASSERT(CpuFeatures::initialized_);
   return ExternalReference(&CpuFeatures::supported_);
 }
+
+
+ExternalReference ExternalReference::debug_is_active_address(
+    Isolate* isolate) {
+  return ExternalReference(isolate->debug()->is_active_address());
+}


 ExternalReference ExternalReference::debug_after_break_target_address(
=======================================
--- /branches/bleeding_edge/src/assembler.h     Tue Jun  3 08:12:43 2014 UTC
+++ /branches/bleeding_edge/src/assembler.h     Mon Jun 23 07:10:25 2014 UTC
@@ -911,6 +911,7 @@

   static ExternalReference cpu_features();

+  static ExternalReference debug_is_active_address(Isolate* isolate);
static ExternalReference debug_after_break_target_address(Isolate* isolate);
   static ExternalReference debug_restarter_frame_function_pointer_address(
       Isolate* isolate);
=======================================
--- /branches/bleeding_edge/src/collection.js   Tue Jun  3 00:34:01 2014 UTC
+++ /branches/bleeding_edge/src/collection.js   Mon Jun 23 07:10:25 2014 UTC
@@ -81,7 +81,7 @@

   var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
   var entry;
-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   while (!(entry = %SetIteratorNext(iterator)).done) {
     if (stepping) %DebugPrepareStepInIfStepping(f);
     %_CallFunction(receiver, entry.value, entry.value, this, f);
@@ -192,7 +192,7 @@

   var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES);
   var entry;
-  var stepping = %_DebugCallbackSupportsStepping(f);
+  var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
   while (!(entry = %MapIteratorNext(iterator)).done) {
     if (stepping) %DebugPrepareStepInIfStepping(f);
     %_CallFunction(receiver, entry.value[1], entry.value[0], this, f);
=======================================
--- /branches/bleeding_edge/src/debug.h Wed Jun 11 13:40:18 2014 UTC
+++ /branches/bleeding_edge/src/debug.h Mon Jun 23 07:10:25 2014 UTC
@@ -505,6 +505,10 @@
   int break_id() { return thread_local_.break_id_; }

   // Support for embedding into generated code.
+  Address is_active_address() {
+    return reinterpret_cast<Address>(&is_active_);
+  }
+
   Address after_break_target_address() {
     return reinterpret_cast<Address>(&after_break_target_);
   }
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Fri Jun 20 23:02:36 2014 UTC +++ /branches/bleeding_edge/src/hydrogen-instructions.h Mon Jun 23 07:10:25 2014 UTC
@@ -6119,6 +6119,11 @@
     return HObjectAccess(kExternalMemory, 0, Representation::Integer32(),
                          Handle<String>::null(), false, false);
   }
+
+  static HObjectAccess ForExternalUInteger8() {
+    return HObjectAccess(kExternalMemory, 0, Representation::UInteger8(),
+                         Handle<String>::null(), false, false);
+  }

   // Create an access to an offset in a fixed array header.
   static HObjectAccess ForFixedArrayHeader(int offset);
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Mon Jun 23 05:50:06 2014 UTC
+++ /branches/bleeding_edge/src/hydrogen.cc     Mon Jun 23 07:10:25 2014 UTC
@@ -11711,11 +11711,13 @@
 }


-void HOptimizedGraphBuilder::GenerateDebugCallbackSupportsStepping(
-    CallRuntime* call) {
-  ASSERT(call->arguments()->length() == 1);
-  // Debugging is not supported in optimized code.
-  return ast_context()->ReturnValue(graph()->GetConstantFalse());
+void HOptimizedGraphBuilder::GenerateDebugIsActive(CallRuntime* call) {
+  ASSERT(call->arguments()->length() == 0);
+  HValue* ref =
+ Add<HConstant>(ExternalReference::debug_is_active_address(isolate()));
+  HValue* value = Add<HLoadNamedField>(
+ ref, static_cast<HValue*>(NULL), HObjectAccess::ForExternalUInteger8());
+  return ast_context()->ReturnValue(value);
 }


=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Tue Jun 17 13:54:49 2014 UTC +++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Mon Jun 23 07:10:25 2014 UTC
@@ -3994,6 +3994,16 @@
   __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
   context()->Plug(eax);
 }
+
+
+void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
+  ASSERT(expr->arguments()->length() == 0);
+  ExternalReference debug_is_active =
+      ExternalReference::debug_is_active_address(isolate());
+  __ movzx_b(eax, Operand::StaticVariable(debug_is_active));
+  __ SmiTag(eax);
+  context()->Plug(eax);
+}


 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/macros.py       Tue Jun  3 00:34:01 2014 UTC
+++ /branches/bleeding_edge/src/macros.py       Mon Jun 23 07:10:25 2014 UTC
@@ -285,3 +285,6 @@
 const ITERATOR_KIND_KEYS = 1;
 const ITERATOR_KIND_VALUES = 2;
 const ITERATOR_KIND_ENTRIES = 3;
+
+# Check whether debug is active.
+const DEBUG_IS_ACTIVE = (%_DebugIsActive() != 0);
=======================================
--- /branches/bleeding_edge/src/runtime.h       Tue Jun 17 14:10:16 2014 UTC
+++ /branches/bleeding_edge/src/runtime.h       Mon Jun 23 07:10:25 2014 UTC
@@ -438,6 +438,7 @@
   F(DebugConstructedBy, 2, 1) \
   F(DebugGetPrototype, 1, 1) \
   F(DebugSetScriptSource, 2, 1) \
+  F(DebugCallbackSupportsStepping, 1, 1) \
   F(SystemBreak, 0, 1) \
   F(DebugDisassembleFunction, 1, 1) \
   F(DebugDisassembleConstructor, 1, 1) \
@@ -654,7 +655,8 @@
F(RegExpExec, 4, 1) \ F(RegExpConstructResult, 3, 1) \ F(GetFromCache, 2, 1) \
-  F(NumberToString, 1, 1)
+ F(NumberToString, 1, 1) \
+  F(DebugIsActive, 0, 1)


// ----------------------------------------------------------------------------
@@ -680,9 +682,7 @@
F(DoubleHi, 1, 1) \ F(DoubleLo, 1, 1) \ F(MathSqrtRT, 1, 1) \ - F(MathLogRT, 1, 1) \ - /* Debugger */ \
-  F(DebugCallbackSupportsStepping, 1, 1)
+  F(MathLogRT, 1, 1)


//---------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Tue Jun 17 13:54:49 2014 UTC +++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Mon Jun 23 07:10:25 2014 UTC
@@ -4002,6 +4002,17 @@
   __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
   context()->Plug(rax);
 }
+
+
+void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
+  ASSERT(expr->arguments()->length() == 0);
+  ExternalReference debug_is_active =
+      ExternalReference::debug_is_active_address(isolate());
+  __ Move(kScratchRegister, debug_is_active);
+  __ movzxbp(rax, Operand(kScratchRegister, 0));
+  __ Integer32ToSmi(rax, rax);
+  context()->Plug(rax);
+}


 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {

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