nashorn/test/script/basic/JDK-8046905.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 26067 b32ccc3a76c9
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     1
/*
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
     4
 *
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
     8
 *
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    13
 * accompanied this code).
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
    14
 *
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
    18
 *
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    21
 * questions.
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    22
 */
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    23
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    24
/**
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    25
 * JDK-8046905: apply on apply is broken
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    26
 *
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    27
 * @test
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    28
 * @run
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    29
 */
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    30
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    31
var apply = Function.prototype.apply;
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    32
var call = Function.prototype.call;
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    33
var sort = Array.prototype.sort;
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    34
var join = Array.prototype.join;
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    35
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    36
// Running three times so that we test an already linked call site too:
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    37
// i==0: linking initially with assumed optimistic returned type int.
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    38
// i==1: linking after deoptimization with returned type Object.
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
    39
// i==2: re-running code linked in previous iteration. This will
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    40
//       properly exercise the guards too.
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    41
print("1 level of apply")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    42
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    43
    print(sort.apply([4,3,2,1]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    44
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    45
print("2 levels of apply")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    46
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    47
    print(apply.apply(sort,[[4,3,2,1]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    48
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    49
print("3 levels of apply")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    50
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    51
    print(apply.apply(apply,[sort,[[4,3,2,1]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    52
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    53
print("4 levels of apply")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    54
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    55
    print(apply.apply(apply,[apply,[sort,[[4,3,2,1]]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    56
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    57
print("5 levels of apply")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    58
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    59
    print(apply.apply(apply,[apply,[apply,[sort,[[4,3,2,1]]]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    60
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    61
print("Many levels of apply!")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    62
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    63
    print(apply.apply(apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[sort,[[4,3,2,1]]]]]]]]]]]]]]]]]]]]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    64
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    65
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    66
print("different invocations that'll trigger relinking")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    67
var invocation = [sort,[[4,3,2,1]]];
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    68
for(i = 0; i < 4; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    69
    print(apply.apply(apply,[apply,invocation]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    70
    // First change after i==1, so it relinks an otherwise stable linkage
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    71
    if(i == 1) {
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 25237
diff changeset
    72
    invocation = [sort,[[8,7,6,5]]];
25237
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    73
    } else if(i == 2) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    74
        invocation = [join,[[8,7,6,5],["-"]]];
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    75
    }
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    76
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    77
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    78
print("Many levels of call!")
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    79
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    80
    print(call.call(call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,sort,[4,3,2,1]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    81
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    82
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    83
print("call apply call apply call... a lot");
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    84
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    85
    print(apply.call(call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [sort, [4,3,2,1]]]]]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    86
}
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    87
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    88
print("apply call apply call apply... a lot");
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    89
for(i = 0; i < 3; ++i) {
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    90
    print(call.apply(apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, sort, [[4,3,2,1]]]]]]]]]))
bf5efe0a93ba 8046905: apply on apply is broken
attila
parents:
diff changeset
    91
}