osr-regex-id.js 1.37 KB
Newer Older
1 2 3 4
// Copyright 2015 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.

5
// Flags: --allow-natives-syntax --use-osr
6 7 8 9 10 11

function id(f) { return f; }

function foo(a) {
  var r = /\0/;
  for (var i = 0; i < 10; i++) {
12
    if (a) %OptimizeOsr();
13
    %PrepareFunctionForOptimization(foo);
14 15 16
  }
  return r;
}
17
%PrepareFunctionForOptimization(foo);
18 19 20

function bar(a) {
  for (var i = 0; i < 10; i++) {
21
    if (a) %OptimizeOsr();
22
    %PrepareFunctionForOptimization(bar);
23 24 25 26
    var r = /\0/;
  }
  return r;
}
27
%PrepareFunctionForOptimization(bar);
28 29 30

function baz(a) {
  for (var i = 0; i < 10; i++) {
31
    if (a) %OptimizeOsr();
32
    %PrepareFunctionForOptimization(baz);
33 34 35
  }
  return /\0/;
}
36
%PrepareFunctionForOptimization(baz);
37 38 39 40

function qux(a) {
  for (var i = 0; i < 10; i++) {
    if (i > 5 && a) {
41
      %OptimizeOsr();
42
      %PrepareFunctionForOptimization(qux);
43 44 45 46 47 48
    } else {
      var r = /\0/;
    }
  }
  return r;
}
49
%PrepareFunctionForOptimization(qux);
50 51 52 53

function test(f) {
  // Test the reference equality of regex's created in OSR'd function.
  var x = f(false);
54
  %PrepareFunctionForOptimization(f);
55
  assertEquals(x, f(true));
56
  %PrepareFunctionForOptimization(f);
57
  assertEquals(x, f(true));
58
  %PrepareFunctionForOptimization(f);
59 60 61 62 63 64 65
  assertEquals(x, f(true));
}

test(foo);
test(bar);
test(baz);
test(qux);