summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testApplyArrayInline.js
blob: 52cc840372b39414450b1108f7b9edd84c1004cd (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// |jit-test| skip-if: !this.getJitCompilerOptions() || !getJitCompilerOptions()['ion.enable']

// Test inlining in Ion of fun.apply(..., array).

setJitCompilerOption("ion.warmup.trigger", 50);
setJitCompilerOption("offthread-compilation.enable", 0);
gcPreserveCode();

var itercount = 1000;
var warmup = 100;

// Force Ion to do something predictable without having to wait
// forever for it.

if (getJitCompilerOptions()["ion.warmup.trigger"] > warmup)
    setJitCompilerOption("ion.warmup.trigger", warmup);

setJitCompilerOption("offthread-compilation.enable", 0);

function g(a, b, c, d) {
    return a + b + c + (d === undefined);
}

var g_inIonInLoop = false;
var g_inIonAtEnd = false;

function f(xs) {
    var sum = 0;
    var inIonInLoop = 0;
    for ( var i=0 ; i < itercount ; i++ ) {
	inIonInLoop |= inIon();
	sum += g.apply(null, xs);
    }
    g_ionAtEnd = inIon();
    g_inIonInLoop = !!inIonInLoop;
    return sum;
}

// Basic test

assertEq(f([1,2,3,4]), 6*itercount);

// Attempt to detect a botched optimization: either we ion-compiled
// the loop, or we did not ion-compile the function (ion not actually
// effective at all, this can happen).

assertEq(g_inIonInLoop || !g_inIonAtEnd, true);

// If Ion is inert just leave.

if (!g_inIonInLoop) {
    print("Leaving early - ion not kicking in at all");
    quit(0);
}

// Test that we get the correct argument value even if the array has
// fewer initialized members than its length.

var headroom = [1,2,3];
headroom.length = 13;
assertEq(f(headroom), 7*itercount);

// Test that we throw when the array is too long.

var thrown = false;
try {
    var long = [];
    long.length = getMaxArgs() + 1;
    f(long);
}
catch (e) {
    thrown = true;
    assertEq(e instanceof RangeError, true);
}
assertEq(thrown, true);