Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2015 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Flags: --expose-debug-as debug
      6 
      7 // This test ensures that IC learning doesn't interfere with stepping into
      8 // property accessor. f1()'s ICs are allowed to learn to a monomorphic state,
      9 // and the breakpoints flooding get() are allowed to expire, then we ensure
     10 // that we can step into get() again later (when k == 1).
     11 function f1() {
     12   for (var k = 0; k < 2; k++) {     // Break 1
     13     var v10 = 0;                    // Line 2
     14     for (var i = 0; i < 10; i++) {  // Line 3
     15       var v12 = o.slappy;           // Line 4
     16       var v13 = 3                   // Line 5
     17     }                               // Line 6
     18     print("break here");            // Break 3
     19   }                                 // Line 8
     20   print("exiting f1");              // Line 9 (dummy break)
     21 }
     22 
     23 function get() {
     24   var g0 = 0;                       // Break 2
     25   var g1 = 1;
     26   return 3;
     27 }
     28 
     29 
     30 var o = {};
     31 Object.defineProperty(o, "slappy", { get : get });
     32 
     33 Debug = debug.Debug;
     34 var break_count = 0
     35 var exception = null;
     36 var bp_f1_line7;
     37 var bp_f1_line9;
     38 
     39 function listener(event, exec_state, event_data, data) {
     40   if (event != Debug.DebugEvent.Break) return;
     41   try {
     42     var line = exec_state.frame(0).sourceLineText();
     43     print(line);
     44     var match = line.match(/\/\/ Break (\d+)$/);
     45     assertEquals(2, match.length);
     46     var match_value = parseInt(match[1]);
     47 
     48     if (break_count >= 0 && break_count < 2) {
     49       // 0, 1: Keep stepping through frames.
     50       assertEquals(break_count, match_value);
     51       exec_state.prepareStep(Debug.StepAction.StepFrame);
     52     } else if (break_count === 2) {
     53       // 2: let the code run to a breakpoint we set. The load should
     54       // go monomorphic.
     55       assertEquals(break_count, match_value);
     56     } else if (break_count === 3) {
     57       // 3: back to frame stepping. Does the monomorphic slappy accessor
     58       // call still have the ability to break like before?
     59       assertEquals(break_count, match_value);
     60       Debug.clearBreakPoint(bp_f1_line7);
     61       exec_state.prepareStep(Debug.StepAction.StepFrame);
     62     } else {
     63       assertEquals(4, break_count);
     64       assertEquals(2, match_value);
     65       // Apparently we can still stop in the accessor even though we cleared
     66       // breakpoints earlier and there was a monomorphic step.
     67       // Allow running to completion now.
     68       Debug.clearBreakPoint(bp_f1_line9);
     69     }
     70 
     71     break_count++;
     72   } catch (e) {
     73     print(e + e.stack);
     74     exception = e;
     75   }
     76 }
     77 
     78 for (var j = 1; j < 3; j++) {
     79   break_count = 0;
     80   Debug.setListener(listener);
     81 
     82   // Breakpoints are added here rather than in the listener because their
     83   // addition causes a full (clearing) gc that clears type feedback when we
     84   // want to let it build up. Also, bp_f1_line9 is set simply because if we
     85   // handled then deleted bp_f1_line7, then the debugger clears DebugInfo from
     86   // f1 while we are still using it, again, resetting type feedback which is
     87   // undesirable.
     88   bp_f1_line7 = Debug.setBreakPoint(f1, 7);
     89   bp_f1_line9 = Debug.setBreakPoint(f1, 9);
     90 
     91   debugger;                         // Break 0
     92   f1();
     93   Debug.setListener(null);
     94   assertTrue(break_count === 5);
     95 }
     96 
     97 assertNull(exception);
     98