osr-typing-debug-change.js 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// Copyright 2016 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.


var Debug = debug.Debug;

var changed = false;

function listenerSetJToResult(
    event, exec_state, event_data, data) {

  if (event == Debug.DebugEvent.Break) {
    var scope = exec_state.frame(1).scope(0);
    var newval = "result";
    try {
      scope.setVariableValue("j", newval);
      changed = true;
    } catch(e) {
      changed = false;
    }
  }
}

Debug.setListener(listenerSetJToResult);

function g() { debugger; }
%NeverOptimizeFunction(g);

function ChangeSmiConstantAndOsr() {
  var j = 1;
  for (var i = 0; i < 4; i++) {
    if (i == 2) {
      %OptimizeOsr();
      g();
    }
  }
  return j;
}
40
%PrepareFunctionForOptimization(ChangeSmiConstantAndOsr);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
var r1 = ChangeSmiConstantAndOsr();
if (changed) {
  assertEquals("result", r1);
} else {
  assertEquals(1, r1);
}

function ChangeFloatConstantAndOsr() {
  var j = 0.1;
  for (var i = 0; i < 4; i++) {
    if (i == 2) {
      %OptimizeOsr();
      g();
    }
  }
  return j;
}
58
%PrepareFunctionForOptimization(ChangeFloatConstantAndOsr);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
var r2 = ChangeFloatConstantAndOsr();
if (changed) {
  assertEquals("result", r2);
} else {
  assertEquals(0.1, r2);
}

function ChangeFloatVarAndOsr() {
  var j = 0.1;
  for (var i = 0; i < 4; i++) {
    j = j + 0.1;
    if (i == 2) {
      %OptimizeOsr();
      g();
    }
  }
  return j;
}
77
%PrepareFunctionForOptimization(ChangeFloatVarAndOsr);
78 79 80 81 82 83 84 85 86 87 88 89
var r3 = ChangeFloatVarAndOsr();
if (changed) {
  assertEquals("result0.1", r3);
} else {
  assertEquals(0.5, r3);
}

function listenerSetJToObject(
    event, exec_state, event_data, data) {
  if (event == Debug.DebugEvent.Break) {
    var scope = exec_state.frame(1).scope(0);
    try {
90
      scope.setVariableValue("j", 100);
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
      changed = true;
    } catch(e) {
      changed = false;
    }
  }
}

Debug.setListener(listenerSetJToObject);

function ChangeIntVarAndOsr() {
  var j = 1;
  for (var i = 0; i < 4; i++) {
    j = j + 1|0;
    if (i == 2) {
      %OptimizeOsr();
      g();
    }
  }
  return j;
}
111
%PrepareFunctionForOptimization(ChangeIntVarAndOsr);
112 113 114 115 116 117 118

var r4 = ChangeIntVarAndOsr();
if (changed) {
  assertEquals(101, r4);
} else {
  assertEquals(5, r4);
}